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
This commit is contained in:
obrebski 2008-04-30 11:19:17 +00:00
parent 12d8443b2c
commit 28e9ae0020
8 changed files with 61 additions and 366 deletions

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -1,39 +0,0 @@
#include <stdlib.h>
#include <string.h>
#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;
}

View File

@ -1,277 +0,0 @@
#ifndef __COMMON_H
#define __COMMON_H
#include <stdio.h>
#include <ctype.h>
#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<args.process_given; ++i)
if(strcmp(args.process_arg[i],field)==0)
{
ret=true;
break;
}
}
for(int i=0; i<args.select_given; ++i)
if(! getfield(s,args.select_arg[i],field))
ret=false;
for(int i=0; i<args.ignore_given; ++i)
if(getfield(s,args.ignore_arg[i],field))
ret=false;
return ret;
}
/* DEPRICATED */
/* definicja struktury wejscia/wyjscia
*/
struct Segment
{
int filepos, len;
char* tag;
char* form;
char* aux[MAXAUX];
int auxn;
bool parse(char* line);
char* getfield(char* fieldname);
void print(char* line);
bool addfield(char* s);
bool clearfields();
};
/*
* Sprawdza czy nalezy przetwarzac dany segment.
*/
inline
bool process_seg(Segment& s, gengetopt_args_info& args)
{
bool ret = !args.process_given;
for(int i=0; i<args.process_given; ++i)
if(strcmp(args.process_arg[i],s.tag)==0)
{
ret=true;
break;
}
for(int i=0; i<args.select_given; ++i)
if(! s.getfield(args.select_arg[i]))
ret=false;
for(int i=0; i<args.ignore_given; ++i)
if(s.getfield(args.ignore_arg[i]))
ret=false;
return ret;
}
/*
* FUNKCJE OBSLUGUJACE WEJSCIE/WYJSCIE
*/
// napisy zostaj na miejscu (w line), tylko wskazniki sa ustawian
// i zara dopisywane zera s dopisywane
inline
bool Segment::parse(char* line)
{
auxn=0;
char* field;
if((field=strtok(line,FIELD_SEP))!=NULL)
filepos=atoi(field); // nie sprawdzana poprawnosc
else
return false;
if((field=strtok(NULL,FIELD_SEP))!=NULL)
len=atoi(field); // nie sprawdzana poprawnosc
else return false;
if((tag=strtok(NULL,FIELD_SEP))==NULL) return false;
if((form=strtok(NULL,FIELD_SEP))==NULL)
return false;
/* else */
/* if(form[0] == EMPTYFORM && form[1] =='\0') */
/* form=NULL; */
while((aux[auxn]=strtok(NULL,FIELD_SEP))!=NULL) ++auxn;
return true;
}
inline char* Segment::getfield(char* f)
{
int flen=strlen(f);
for(int i=0; i<auxn; ++i)
if(strncmp(aux[i],f,flen)==0 && aux[i][flen]==INFIELD_SEP)
return aux[i]+flen+1;
return NULL;
}
inline bool Segment::clearfields() {
for (int i=0; i<auxn; ++i) {
// free(aux[i]);
aux[i] = NULL;
}
auxn=0;
return true;
}
inline // NIEEFEKTYWNE
void Segment::print(char* line)
{
sprintf(line,"%04d %02d %s", filepos, len, tag);
if(form)
{
strcat(line," ");
strcat(line,form);
}
else
if(auxn)
strcat(line," *");
for(int i=0; i<auxn; ++i)
{
strcat(line," ");
strcat(line,aux[i]);
}
strcat(line,"\n");
}
inline
bool Segment::addfield(char* s)
{
if(auxn<MAXAUX)
{
aux[auxn++]=s;
return true;
}
else
return false;
}
#endif

View File

@ -12,7 +12,7 @@
#include "sgraph.hh"
#include "grammar.hh"
#include "dgp0.hh"
#include "common.h"
#include "../common/common.h"
#define MAXSEGMENTS 500
@ -74,7 +74,7 @@ main(int argc, char* argv[])
char segtype[80];
seg_mnode[segcount] = processseg(line, args) ? mgraph.add_node(line) : -1;
seg_mnode[segcount] = process_seg(line, args) ? mgraph.add_node(line) : -1;
segcount++;

View File

@ -2,7 +2,6 @@
#include "mgraph.hh"
#include "thesymbols.hh"
#include "const.hh"
#include "common.h"
#include <stdio.h>

View File

@ -5,7 +5,7 @@
#include "const.hh"
#include "thesymbols.hh"
#include "common.h"
#include "../common/common.h"
class MNode
{