#ifndef __COMMON_H #define __COMMON_H #include #include #include #include #include "../lib/const.h" #ifndef _CMDLINE_FILE #error _CMDLINE_FILE constant not defined! #else #include _CMDLINE_FILE #endif /************************************************** * Stale dotyczace wejscia/wyjscia */ #define EMPTYFORM '*' #define INFIELD_SEP ':' #define MAXAUX 16 #define FIELD_SEP " \t\n" // katalogi z plikami konfiguracyjnymi // nowe // stare - do wyrzucenia // #define CONFIG_DIR ".utt/conf" // nazwa zmiennej okreslajaca sciezke do danych // #define UTT_DIR_VAR "UTT_DIR" // sciezka do plikow z danymi (np UTT_DIR/pliki) wzgledem $HOME! // #define UTT_DIR_DEFAULT ".utt/pl/" /**************************************************/ extern FILE* inputf; extern FILE* outputf; extern FILE* failedf; extern char* input_filename; extern char* output_filename; extern char* failed_filename; extern bool one_line; extern bool one_field; extern char input_field_prefix[]; extern char output_field_prefix[]; extern bool copy_processed; extern bool append_output; extern bool append_failed; //sciezka do katalogu z danymi extern char utt_dir[]; extern void process_common_options(gengetopt_args_info* args, char* argv0); extern void process_config_files(gengetopt_args_info* args, char* argv0); extern int expand_path(char* inpath, char* outpath); extern int fieldprefix(char *name, char *prefix); /************************************************** * problems with casing */ // sprawdzenie wielkosci liter // wartość zwracana: // 0 - wszystkie małe litery // 1 - pierwsza wielka, reszta male // 2 - wszystkie wielkie // 3 - inne inline int casing(char* s) { int ret = isupper(*s) ? 1 : 0; while(*++s != '\0') { if(isupper(*s)) { if(ret==1) ret=2; else if(ret==0) ret=3; } else { if(ret==2) ret=3; } } return ret; } // inline void tolowers(char* s, char* d) { *d=tolower(*s); while(*s != '\0') * ++d = tolower(* ++s); } // przepisuje s do d // nadajac wielkość liter zgodnie z wartością casing // casing - wartość zwracana przez casing() // jeśli casing==3 przepisuje bez zmian (za mało informacji) inline void restorecasing(char *s, char *d, int casing) { switch(casing) { case 0: case 3: *d=*s; while(*s != '\0') * ++d = * ++s; break; case 1: *d=toupper(*s); while(*s != '\0') * ++d = * ++s; break; case 2: *d=toupper(*s); while(*s != '\0') * ++d = toupper(* ++s); break; } } /**************************************************/ /* parameters: -seg - segment -pref - field name or "1", "2", "3", "4" for the first four fields +val - field contents return value: 1 if specified field exists, 0 otherwise */ inline int getfield(char* seg, const char* pref, char* val) { char* p=seg; char* p0; while(isspace(*p)) ++p; // field "1" p0=p; while(isdigit(*p)) ++p; if(*pref=='1') if(p!=p0) { strncpy(val,p0,p-p0); val[p-p0]='\0'; return 1; } else return 0; while(isspace(*p)) ++p; // field "2" p0=p; while(isdigit(*p)) ++p; if(*pref=='2') if(p!=p0) { strncpy(val,p0,p-p0); val[p-p0]='\0'; return 1; } else return 0; while(isspace(*p)) ++p; // field "3" p0=p; while(isgraph(*p)) ++p; if(*pref=='3') if(p!=p0) { strncpy(val,p0,p-p0); val[p-p0]='\0'; return 1; } else return 0; while(isspace(*p)) ++p; // field "4" p0=p; while(isgraph(*p)) ++p; if(*pref=='4') if(p!=p0) { strncpy(val,p0,p-p0); val[p-p0]='\0'; return 1; } else return 0; while(isspace(*p)) ++p; // annotation fields 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; } } inline bool process_seg(char* seg, gengetopt_args_info& args) { char buf[256]; bool ret = !args.process_given; if(args.process_given) { getfield(seg,"3",buf); for(int i=0; i= MAX_LINE) return 0; // bezpieczniej, ale wolniej int seglen=strlen(seg); sprintf(seg+(seglen-1)," %s%s\n",pref,val); return 1; } /**************************************************/ struct Seg { 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(); }; /**************************************************/ /* 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