From 28e9ae0020002f67cf91ba795ab44945930c0e98 Mon Sep 17 00:00:00 2001 From: obrebski Date: Wed, 30 Apr 2008 11:19:17 +0000 Subject: [PATCH] dgp korzysta z normalnego common.cc i bierze wspolne parametry z cmdline_common.ggo git-svn-id: svn://atos.wmid.amu.edu.pl/utt@35 e293616e-ec6a-49c2-aa92-f4a8b91c5d16 --- app/src/dgp/Makefile | 20 ++- app/src/dgp/cmdline.ggo | 42 ------ app/src/dgp/cmdline_dgp.ggo | 42 ++++++ app/src/dgp/common.cc | 39 ----- app/src/dgp/common.h | 277 ------------------------------------ app/src/dgp/main.cc | 4 +- app/src/dgp/mgraph.cc | 1 - app/src/dgp/mgraph.hh | 2 +- 8 files changed, 61 insertions(+), 366 deletions(-) delete mode 100644 app/src/dgp/cmdline.ggo create mode 100644 app/src/dgp/cmdline_dgp.ggo delete mode 100644 app/src/dgp/common.cc delete mode 100644 app/src/dgp/common.h diff --git a/app/src/dgp/Makefile b/app/src/dgp/Makefile index 03666c7..bdf9646 100644 --- a/app/src/dgp/Makefile +++ b/app/src/dgp/Makefile @@ -2,13 +2,16 @@ SHELL = /bin/sh LIB_PATH=../../lib +COMMON_PATH=../common +CMDLINE_FILE='"../dgp/cmdline.h"' + #vpath %.o . CXXFLAGS = -O2 -static sources = main.cc grammar.cc symbol.cc mgraph.cc sgraph.cc dgp0.cc cmdline.cc \ - common.cc global.cc + $(COMMON_PATH)/common.cc global.cc bin = dgp @@ -21,15 +24,24 @@ ${bin}: ${objs} include $(sources:.cc=.d) %.o: %.cc - ${CXX} -c ${CXXFLAGS} -o $@ $< + ${CXX} -D _CMDLINE_FILE=$(CMDLINE_FILE) -c ${CXXFLAGS} -o $@ $< %.d: %.cc $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ -cmdline.cc cmdline.h : cmdline.ggo - gengetopt --c-extension=cc -i cmdline.ggo +# stare: +# cmdline.cc cmdline.h : cmdline.ggo +# gengetopt --c-extension=cc -i cmdline.ggo +# nowe +cmdline.cc cmdline.h: cmdline.ggo + gengetopt -i cmdline.ggo --c-extension=cc --conf-parser + +cmdline.ggo: cmdline_dgp.ggo ../common/cmdline_common.ggo + cat cmdline_dgp.ggo ../common/cmdline_common.ggo > cmdline.ggo +# endnowe + clean: rm ${bin} ${objs} cmdline.cc cmdline.h diff --git a/app/src/dgp/cmdline.ggo b/app/src/dgp/cmdline.ggo deleted file mode 100644 index 27dee3c..0000000 --- a/app/src/dgp/cmdline.ggo +++ /dev/null @@ -1,42 +0,0 @@ -package "dgp" -version "0.1" - -option "process" p "Process segments with this tag." - string no multiple - -option "select" s "Select only segments with this field. [Not implemented.]" - string no multiple - -option "ignore" S "Select only segments without this field. [Not implemented]" - string no multiple - -option "input" f "Input file" - string typestr="filename" no - -option "output" o "Output file" - string typestr="filename" no - -option "failed" e "Fail file" - string typestr="filename" no - -option "copy" c "Copy unprocessed" - flag off - -option "grammar" g "Grammar file" - string typestr="filename" default="dgp.dg" - -option "long" l "Long output" - flag off - -option "interactive" - "Interactive use." - flag off - -option "debug" d "Debug mode." - flag off - -option "info" i "Print info. -h - heads d - dependents -s - sets -c - constraints n - node/arc counts t - parse time -" - string default="gh" diff --git a/app/src/dgp/cmdline_dgp.ggo b/app/src/dgp/cmdline_dgp.ggo new file mode 100644 index 0000000..3b61bbd --- /dev/null +++ b/app/src/dgp/cmdline_dgp.ggo @@ -0,0 +1,42 @@ +package "dgp" +version "0.1" + +#option "process" p "Process segments with this tag." +# string no multiple + +#option "select" s "Select only segments with this field. [Not implemented.]" +# string no multiple + +#option "ignore" S "Select only segments without this field. [Not implemented]" +# string no multiple + +#option "input" f "Input file" +# string typestr="filename" no + +#option "output" o "Output file" +# string typestr="filename" no + +#option "failed" e "Fail file" +# string typestr="filename" no + +#option "copy" c "Copy unprocessed" +# flag off + +option "grammar" g "Grammar file" + string typestr="filename" default="dgp.dg" + +option "long" l "Long output" + flag off + +#option "interactive" - "Interactive use." +# flag off + +option "debug" d "Debug mode." + flag off + +option "info" - "Print info. +h - heads d - dependents +s - sets +c - constraints n - node/arc counts t - parse time +" + string default="gh" diff --git a/app/src/dgp/common.cc b/app/src/dgp/common.cc deleted file mode 100644 index f5eb6a5..0000000 --- a/app/src/dgp/common.cc +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include "common.h" - -FILE* inputf=stdin; -FILE* outputf=stdout; -FILE* failedf=stdout; -bool copy_processed=0; - -void process_common_options(gengetopt_args_info args) -{ - if(args.help_given) - cmdline_parser_print_help (); - - if(args.input_given) - if(!(inputf=fopen(args.input_arg,"r"))) - { - fprintf(stderr,"No such file: %s.\n", args.input_arg); - exit(1); - } - - if(args.output_given) - if(!(outputf=fopen(args.output_arg,"w"))) - { - fprintf(stderr,"Cannot open output file: %s.\n", args.output_arg); - exit(1); - } - - if(args.failed_given) - if(!(failedf=fopen(args.failed_arg,"w"))) - { - fprintf(stderr,"Cannot open output file: %s.\n", args.failed_arg); - exit(1); - } - - - if(args.copy_given) - copy_processed=true; -} diff --git a/app/src/dgp/common.h b/app/src/dgp/common.h deleted file mode 100644 index a64bf34..0000000 --- a/app/src/dgp/common.h +++ /dev/null @@ -1,277 +0,0 @@ -#ifndef __COMMON_H -#define __COMMON_H - -#include -#include - -#include "cmdline.h" -#include "const.hh" - - -/************************************************** - * Stale dotyczace wejscia/wyjscia - */ - -#define EMPTYFORM '*' -#define INFIELD_SEP ':' -#define MAXAUX 64 -#define FIELD_SEP " \t\n" - -/**************************************************/ - - -extern FILE* inputf; -extern FILE* outputf; -extern FILE* failedf; - -extern char* input_filename; -extern char* output_filename; -extern char* failed_filename; - -extern bool copy_processed; -extern bool append_output; -extern bool append_failed; - -extern void process_common_options(gengetopt_args_info args); - - - -/**************************************************/ -/* -parameters: - -seg - segment - -name - field name - +val - field contents -return value: - 1 if specified field exists, 0 otherwise -*/ - -inline int getfield(const char* seg, const char* pref, char* val) -{ - const char* p=seg; - - while(*p==' ') ++p; - - pos: - if(isdigit(*p) or *p=='*') - if(*pref=='1') return sscanf(p,"%s",val); else while(*p!=' ') ++p; - else - if(*pref=='1') return 0; else goto type; - - while(*p==' ') ++p; - - len: - if(isdigit(*p) or *p=='*') - if(*pref=='2') return sscanf(p,"%s",val); else while(*p!=' ') ++p; - else - if(*pref=='2') return 0; else goto type; - - while(*p==' ') ++p; - - type: - - if(*pref=='3') return sscanf(p,"%s",val); else while(*p!=' ') ++p; - - while(*p==' ') ++p; - - form: - if(*pref=='4') return sscanf(p,"%s",val); else while(*p!=' ') ++p; - - while(*p==' ') ++p; - - annotation: - do p=strstr(p,pref); while(p!=NULL && *(p-1)!=' ' && *(p-1)!='\t'); - - if(p==NULL) return 0; - else - { - p+=strlen(pref); - int len=strcspn(p,FIELD_SEP "\n\r\f\0"); - strncpy(val,p,len); - val[len]='\0'; - return 1; - } -} - - -/* -parameters: - +seg - segment - -pref - prefix of the new field - -val - contents of the new field -return value: - 1 - success, 0 - fail (limit on segment length exceeded) -*/ -inline int addfield(char *seg, const char *pref, const char *val) - // zalozenie, ze seg konczy sie znakiem \n -{ - if(strlen(seg)+strlen(pref)+strlen(val) >= MAXLINE) return 0; // bezpieczniej, ale wolniej - - int seglen=strlen(seg); - sprintf(seg+(seglen-1)," %s%s\n",pref,val); - return 1; -} - - -inline -bool processseg(const char* s, gengetopt_args_info& args) -{ - bool ret = !args.process_given; - char field[MAXAUX]; - - if(args.process_given) - { - getfield(s,"3",field); - for(int i=0; i diff --git a/app/src/dgp/mgraph.hh b/app/src/dgp/mgraph.hh index bfe6897..373eac2 100644 --- a/app/src/dgp/mgraph.hh +++ b/app/src/dgp/mgraph.hh @@ -5,7 +5,7 @@ #include "const.hh" #include "thesymbols.hh" -#include "common.h" +#include "../common/common.h" class MNode {