Skip to content

Commit

Permalink
- turn cheap.cpp/print-grammar and -pg into a useful function
Browse files Browse the repository at this point in the history
- fix type addenda problem when using same coreference names (closes ticket #16)
- fix wrong \returns keywords for doxygen
- rename lex-tdl.cpp/optional to consume_if
- minor code restructuring in parse-tdl.cpp
- remove as many #include from flop.h as possible
- found error concerning two or more corefs in one conjunction at type
  definition (opened ticket #17)
- removed zillions of deprecation warnings concerning the use of 
  char * literals as non-const char *, although not all


git-svn-id: https://pet.opendfki.de/repos/pet/main@445 4200e16c-5112-0410-ac55-d7fb557a720a
  • Loading branch information
beki01 committed Aug 12, 2008
1 parent 1d2faa3 commit 7f595ac
Show file tree
Hide file tree
Showing 39 changed files with 584 additions and 680 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
v0.99.??
- turn cheap.cpp/print-grammar and -pg into a useful function
- fix type addenda problem when using same coreference names (closes
ticket #16)
- fix wrong \returns keywords for doxygen
- rename lex-tdl.cpp/optional to consume_if
- minor code restructuring in parse-tdl.cpp
- remove as many #include from flop.h as possible
- found error concerning two or more corefs in one conjunction at type
definition (opened ticket #17)
- removed zillions of deprecation warnings concerning the use of
char * literals as non-const char *, although not all
- implemented new printing functions for items and dags that use visitor
objects (ItemPrinter and DagPrinter) and C++ streams instead of FILE *.
Old functions are still in-place and have to be removed. This is a
Expand Down
64 changes: 34 additions & 30 deletions cheap/cheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
#include "eclpreprocessor.h"
#endif

char * version_string = VERSION ;
char * version_change_string = VERSION_CHANGE " " VERSION_DATETIME ;
const char * version_string = VERSION ;
const char * version_change_string = VERSION_CHANGE " " VERSION_DATETIME ;

FILE *ferr, *fstatus, *flog;

Expand Down Expand Up @@ -277,37 +277,41 @@ void interactive_morphology() {
} // interactive_morphology()


void dump_glbs(FILE *f) {
int i, j;
for(i = 0; i < nstatictypes; i++) {
prune_glbcache();
for(j = 0; j < i; j++)
if(glb(i,j) != -1) fprintf(f, "%d %d %d\n", i, j, glb(i,j));
}
}
void print_grammar(int what, ostream &out) {
if(what == 1 || what == 4) {
out << ";; TYPE NAMES (PRINT NAMES) ==========================" << endl;
for(int i = 0; i < nstatictypes; i++) {
out << i << "\t" << type_name(i) << " (" << print_name(i) << ")" << endl;
}

void print_symbol_tables(FILE *f) {
fprintf(f, "type names (print names)\n");
for(int i = 0; i < nstatictypes; i++) {
fprintf(f, "%d\t%s (%s)\n", i, type_name(i), print_name(i));
out << ";; ATTRIBUTE NAMES ===================================" << endl;
for(int i = 0; i < nattrs; i++) {
out << i << "\t" << attrname[i] << endl;
}
}

fprintf(f, "attribute names\n");
for(int i = 0; i < nattrs; i++) {
fprintf(f, "%d\t%s\n", i, attrname[i]);

out << ";; GLBs ================================================" << endl;
if(what == 2 || what == 4) {
int i, j;
for(i = 0; i < nstatictypes; i++) {
prune_glbcache();
for(j = 0; j < i; j++)
if(glb(i,j) != -1) out << i << ' ' << j << ' ' << glb(i,j) << endl;
}
}
}

void print_grammar(FILE *f) {
if(verbosity > 10)
dump_glbs(f);

print_symbol_tables(f);

for(int i = 0; i < nstatictypes; i++) {
fprintf(f, "\n%d\t%s:\n", i, print_name(i));
// \todo this has to be replaced, but too much for now
//dag_print_safe(f, type_dag(i), false, 0);
if(what == 3 || what == 4) {
out << endl << " ;; TYPE DAGS ================================" << endl;
ReadableDagPrinter dp;
for(int i = 0; i < nstatictypes; i++) {
out << '(' << i << ") " ;
if (type_name(i)[0] == '$')
out << "[" << type_name(i) << ']' << endl ;
dp.print(out, type_dag(i));
out << endl;
// \todo this has to be replaced, but too much for now
//dag_print_safe(f, type_dag(i), false, 0);
}
}
}

Expand Down Expand Up @@ -460,7 +464,7 @@ void process(const char *s) {
fflush(fstatus);

if(opt_pg) {
print_grammar(stdout);
print_grammar(opt_pg, cout);
}
else {
initialize_version();
Expand Down
2 changes: 1 addition & 1 deletion cheap/grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class grammar_rule
{
public:
/** Constructor for grammar rules.
* \returns If the feature structure of the given type is not a valid rule
* \return If the feature structure of the given type is not a valid rule
* (no or empty \c ARGS path), this method returns \c NULL, a grammar rule
* for the given type otherwise.
*/
Expand Down
39 changes: 24 additions & 15 deletions cheap/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

bool opt_shrink_mem, opt_shaping, opt_default_les,
opt_filter, opt_print_failure,
opt_hyper, opt_derivation, opt_rulestatistics, opt_pg,
opt_hyper, opt_derivation, opt_rulestatistics,
opt_linebreaks, opt_chart_man, opt_interactive_morph, opt_lattice,
opt_online_morph, opt_fullform_morph, opt_partial,
opt_compute_qc_unif, opt_compute_qc_subs;
Expand All @@ -40,7 +40,7 @@ bool opt_yy;
int opt_nth_meaning;
#endif

int opt_nsolutions, opt_nqc_unif, opt_nqc_subs, verbosity, pedgelimit, opt_key, opt_server, opt_nresults, opt_predict_les, opt_timeout;
int opt_nsolutions, opt_nqc_unif, opt_nqc_subs, verbosity, pedgelimit, opt_key, opt_server, opt_nresults, opt_predict_les, opt_timeout, opt_pg;
int opt_tsdb;
long int memlimit;
char *grammar_file_name = 0;
Expand Down Expand Up @@ -103,7 +103,7 @@ void usage(FILE *f)
fprintf(f, " `-failure-print' --- print failure paths\n");
fprintf(f, " `-interactive-online-morph' --- morphology only\n");
fprintf(f, " `-no-fullform-morph' --- disable full form morphology\n");
fprintf(f, " `-pg' --- print grammar in ASCII form\n");
fprintf(f, " `-pg[=what]' --- print grammar in ASCII form ('s'ymbols, 'g'lbs, 't'ypes(fs), 'a'll)\n");
fprintf(f, " `-packing[=n]' --- "
"set packing to n (bit coded; default: 15)\n");
fprintf(f, " `-log=[+]file' --- "
Expand Down Expand Up @@ -188,7 +188,7 @@ void init_options()
opt_rulestatistics = false;
opt_default_les = false;
opt_server = 0;
opt_pg = false;
opt_pg = 0;
opt_chart_man = true;
opt_interactive_morph = false;
opt_lattice = false;
Expand Down Expand Up @@ -244,7 +244,7 @@ bool parse_options(int argc, char* argv[])
#endif
{"server", optional_argument, 0, OPTION_SERVER},
{"log", required_argument, 0, OPTION_LOG},
{"pg", no_argument, 0, OPTION_PG},
{"pg", optional_argument, 0, OPTION_PG},
{"interactive-online-morphology", no_argument, 0, OPTION_INTERACTIVE_MORPH},
{"lattice", no_argument, 0, OPTION_LATTICE},
{"no-online-morph", no_argument, 0, OPTION_NO_ONLINE_MORPH},
Expand Down Expand Up @@ -324,32 +324,41 @@ bool parse_options(int argc, char* argv[])
break;
case OPTION_COMPUTE_QC:
if(optarg != NULL)
opt_compute_qc = strdup(optarg);
opt_compute_qc = strdup(optarg);
else
opt_compute_qc = "/tmp/qc.tdl";
opt_compute_qc = strdup("/tmp/qc.tdl");
opt_compute_qc_unif = true;
opt_compute_qc_subs = true;
break;
case OPTION_COMPUTE_QC_UNIF:
if(optarg != NULL)
opt_compute_qc = strdup(optarg);
opt_compute_qc = strdup(optarg);
else
opt_compute_qc = "/tmp/qc.tdl";
opt_compute_qc = strdup("/tmp/qc.tdl");
opt_compute_qc_unif = true;
break;
case OPTION_COMPUTE_QC_SUBS:
if(optarg != NULL)
opt_compute_qc = strdup(optarg);
opt_compute_qc = strdup(optarg);
else
opt_compute_qc = "/tmp/qc.tdl";
opt_compute_qc = strdup("/tmp/qc.tdl");
opt_compute_qc_subs = true;
break;
case OPTION_PRINT_FAILURE:
opt_print_failure = true;
break;
case OPTION_PG:
opt_pg = true;
break;
opt_pg = 1;
if(optarg != NULL) {
const char *what = "sgta";
char *pos = strchr(what, optarg[0]);
if(pos != NULL) {
opt_pg = 1 + (pos - what);
} else {
fprintf(ferr,"Invalid argument to -pg, printing only symbols\n");
}
}
break;
case OPTION_INTERACTIVE_MORPH:
opt_interactive_morph = true;
break;
Expand Down Expand Up @@ -406,9 +415,9 @@ bool parse_options(int argc, char* argv[])
break;
case OPTION_MRS:
if(optarg != NULL)
opt_mrs = strdup(optarg);
opt_mrs = strdup(optarg);
else
opt_mrs = "simple";
opt_mrs = strdup("simple");
break;
case OPTION_TSDB_DUMP:
opt_tsdb_dir = optarg;
Expand Down
4 changes: 2 additions & 2 deletions cheap/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@

extern bool opt_shrink_mem, opt_shaping, opt_default_les,
opt_filter, opt_print_failure,
opt_hyper, opt_derivation, opt_rulestatistics, opt_pg,
opt_hyper, opt_derivation, opt_rulestatistics,
opt_linebreaks, opt_chart_man, opt_interactive_morph, opt_lattice,
opt_partial, opt_compute_qc_unif, opt_compute_qc_subs;
#ifdef YY
extern bool opt_yy;
extern int opt_nth_meaning;
#endif
extern int opt_nsolutions, verbosity, pedgelimit, opt_nqc_unif, opt_nqc_subs, opt_key, opt_server, opt_nresults, opt_predict_les, opt_timeout;
extern int opt_nsolutions, verbosity, pedgelimit, opt_nqc_unif, opt_nqc_subs, opt_key, opt_server, opt_nresults, opt_predict_les, opt_timeout, opt_pg;
extern int opt_tsdb;

extern long int memlimit;
Expand Down
2 changes: 1 addition & 1 deletion cheap/petecl.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ecl_decode_vector_int(cl_object x) {

/** Evaluate the given string \a form in the lisp listener
* \pre \a form must be a valid s-expression
* \returns the object returned by the evaluation
* \return the object returned by the evaluation
*/
cl_object
ecl_eval_sexpr(char *form) {
Expand Down
2 changes: 1 addition & 1 deletion cheap/petecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int * ecl_decode_vector_int(cl_object x);

/** Evaluate the given string \a form in the lisp listener
* \pre \a form must be a valid s-expression
* \returns the object returned by the evaluation
* \return the object returned by the evaluation
*/
cl_object ecl_eval_sexpr(char *form);

Expand Down
6 changes: 3 additions & 3 deletions cheap/psqllex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void tPSQLLex::read_slot_specs(const char *mode) {
/** Massage a string from the database into a list of strings.
* \param ws_separated_strings The character string coming from the database, a
* whitespace separated list of strings
* \returns a list of words as strings
* \return a list of words as strings
* \todo remove eventual SQL escape sequences
*/
list<string> tPSQLLex::split_ws(const char *ws_separated_strings) {
Expand Down Expand Up @@ -436,8 +436,8 @@ dag_node *dag_add_path(dag_node *root, list_int *path, dag_node *value) {
* \param row_no the row number to be treated now
* \param col the column number of the first non-fixed
* (i.e. grammar-specified) retrieved column
* \returns a permanent feature structure containing the paths and value types
* specific for this lexicon entry
* \return a permanent feature structure containing the paths and value types
* specific for this lexicon entry
*/
dag_node *
tPSQLLex::build_instance_fs(PGresult *res, int row_no, int col) {
Expand Down
6 changes: 3 additions & 3 deletions cheap/psqllex.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class tPSQLLex {
/** Massage a string from the database into a list of strings.
* \param ws_separated_strings The character string coming from the database,
* a whitespace separated list of strings
* \returns a list of strings
* \return a list of strings
* \todo remove eventual SQL escape sequences
*/
list<string> split_ws(const char *ws_separated_strings);
Expand All @@ -141,8 +141,8 @@ class tPSQLLex {
* \param row_no the row number to be treated now
* \param startcol the column number of the first non-fixed
* (i.e. grammar-specified) retrieved column
* \returns a modlist containing the paths and the value types to be added
* to the lexicon entry
* \return a modlist containing the paths and the value types to be added
* to the lexicon entry
*/
dag_node *build_instance_fs(PGresult *res, int row_no, int startcol);

Expand Down
2 changes: 1 addition & 1 deletion cheap/sm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ void
tMEM::readModel(const string &fileName)
{
push_file(fileName, "reading ME model");
char *sv = lexer_idchars;
const char *sv = lexer_idchars;
lexer_idchars = "_+-*?$";
parseModel();
lexer_idchars = sv;
Expand Down
4 changes: 2 additions & 2 deletions cheap/xmlparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ using XERCES_CPP_NAMESPACE_QUALIFIER AttributeList;
/** Parse an XML file using the given SAX Document Handler.
* \param inp The XML input source (stdin or file input)
* \param dochandler The document handler to use (for different file contents).
* \returns \c true, if no fatal error occurred, \c false otherwise.
*/
* \return \c true, if no fatal error occurred, \c false otherwise.
*/
bool parse_file(XERCES_CPP_NAMESPACE_QUALIFIER InputSource &inp
, XERCES_CPP_NAMESPACE_QUALIFIER HandlerBase *dochandler);

Expand Down
2 changes: 1 addition & 1 deletion common/grammar-dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "grammar-dump.h"

void
dump_header(dumper *f, char *desc)
dump_header(dumper *f, const char *desc)
{
f->dump_int(DUMP_MAGIC);
f->dump_int(DUMP_VERSION);
Expand Down
2 changes: 1 addition & 1 deletion common/grammar-dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ using namespace std;
* which should be a string describing the grammar and grammar version.
*/
/*@{*/
void dump_header(dumper *f, char *description);
void dump_header(dumper *f, const char *description);
char *undump_header(dumper *f, int &version);
/*@}*/

Expand Down
6 changes: 3 additions & 3 deletions common/lex-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ lex_file *CURR;

int total_lexed_lines = 0;

struct lex_location *new_location(char *fname, int linenr, int colnr)
struct lex_location *new_location(const char *fname, int linenr, int colnr)
{
struct lex_location *loc = (struct lex_location *) malloc(sizeof(struct lex_location));

Expand All @@ -63,7 +63,7 @@ struct lex_location *new_location(char *fname, int linenr, int colnr)
return loc;
}

void push_file(const string &fname, char *info) {
void push_file(const string &fname, const char *info) {
lex_file f;
struct stat statbuf;

Expand Down Expand Up @@ -108,7 +108,7 @@ void push_file(const string &fname, char *info) {

f.pos = 0;
f.linenr = 1; f.colnr = 1;
f.info = info;
f.info = (info != NULL ? strdup(info) : NULL);

file_stack[file_nest++] = f;

Expand Down
6 changes: 3 additions & 3 deletions common/lex-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ typedef struct
struct lex_location
{
/** The file name */
char *fname;
const char *fname;
/** line nr */
int linenr;
/** column nr */
int colnr;
};

/** Build a new location object with the given parameters. */
struct lex_location *new_location(char *fname, int linenr, int colnr);
struct lex_location *new_location(const char *fname, int linenr, int colnr);

/*@{*/
/** File streams for error and status messages */
Expand All @@ -68,7 +68,7 @@ extern FILE *ferr, *fstatus;
/** Push file \a fname onto include stack, where \a info provides a hint in
* which context the function is used.
*/
void push_file(const std::string &fname, char *info);
void push_file(const std::string &fname, const char *info);
/** Pop file from include stack
* \return nonzero if there are still open files, zero otherwise.
*/
Expand Down
Loading

0 comments on commit 7f595ac

Please sign in to comment.