[25ae32e] | 1 | #include "../lib/iotools.h" |
---|
[13a8a67] | 2 | //do wyrzucenia - definicja w Makefile! #define _CMDLINE_FILE "../lem/cmdline.h" |
---|
[25ae32e] | 3 | #include "../common/common.h" |
---|
| 4 | #include "common_lem.h" |
---|
| 5 | #include "lem.h" |
---|
| 6 | #include "cmdline.h" |
---|
| 7 | #include <locale.h> |
---|
| 8 | |
---|
| 9 | int main(int argc, char** argv) { |
---|
| 10 | |
---|
| 11 | // setlocale(LC_CTYPE,""); //PO CO TO? |
---|
| 12 | // setlocale(LC_COLLATE,""); // |
---|
| 13 | |
---|
| 14 | gengetopt_args_info args; |
---|
| 15 | |
---|
| 16 | if(cmdline_parser(argc, argv, &args) != 0) |
---|
| 17 | exit(1); |
---|
| 18 | |
---|
| 19 | process_config_files(&args,argv[0]); |
---|
| 20 | process_common_options(&args,argv[0]); |
---|
| 21 | process_lem_options(&args); |
---|
| 22 | |
---|
| 23 | char line[MAX_LINE+1]; |
---|
| 24 | char outline[MAX_LINE+1]; |
---|
| 25 | char parms[MAX_LINE+1], desc[MAX_LINE+1], lemma[MAX_LINE+1]; |
---|
| 26 | long line_count = 0; |
---|
| 27 | |
---|
| 28 | Lem* lem; |
---|
| 29 | |
---|
| 30 | if(strcmp(dictionary+strlen(dictionary)-4,".bin")==0) |
---|
| 31 | lem = new Lem(dictionary); |
---|
| 32 | else if(strcmp(dictionary+strlen(dictionary)-4,".dic")==0) |
---|
| 33 | lem = new AuxLem(dictionary); |
---|
| 34 | else |
---|
| 35 | fprintf(stderr,"lem: Invalid dictionary file extension.\n"); |
---|
| 36 | |
---|
| 37 | Words tab; |
---|
| 38 | // Segment seg; |
---|
| 39 | |
---|
| 40 | while (fgets(line, MAX_LINE, inputf)) |
---|
| 41 | { |
---|
| 42 | ++line_count; |
---|
| 43 | int start, len; |
---|
| 44 | |
---|
| 45 | if (!process_seg(line, args)) // TO POWINNO BYC WCZESNIEJ ZABEZPIECZONE |
---|
| 46 | fputs(line, outputf); |
---|
| 47 | else |
---|
| 48 | { |
---|
| 49 | char form[MAX_FORM]; |
---|
| 50 | |
---|
| 51 | tab.clear(); |
---|
| 52 | getfield(line,input_field_prefix,form); |
---|
[8abee07] | 53 | if (form==NULL) continue;//BZDURA |
---|
[25ae32e] | 54 | |
---|
| 55 | lem->ana(form, tab); |
---|
| 56 | if(tab.count()==0) |
---|
| 57 | { |
---|
| 58 | char form1[MAX_FORM]; // tymczasowo tak, trzeba zmienic ana |
---|
| 59 | char* p; |
---|
| 60 | strcpy(form1,form); |
---|
| 61 | for(p=form1;*p;++p) *p=tolower(*p); |
---|
| 62 | p=form1; |
---|
| 63 | lem->ana(p,tab); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | if (tab.count() == 0) |
---|
| 67 | fputs(line, failedf); |
---|
| 68 | else |
---|
| 69 | { // mamy jakies opisy w slowniku |
---|
| 70 | |
---|
| 71 | if(one_line) |
---|
| 72 | { |
---|
| 73 | char* descp=desc; |
---|
| 74 | for (int i=0; i< tab.count(); ++i) |
---|
| 75 | { |
---|
| 76 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 77 | } |
---|
| 78 | strcpy(outline,line); |
---|
| 79 | outline[strlen(outline)-1]='\0'; |
---|
| 80 | strcat(outline,desc); |
---|
| 81 | strcat(outline,"\n"); |
---|
| 82 | fputs(outline, outputf); |
---|
| 83 | if (copy_processed) |
---|
| 84 | fputs(line,outputf); |
---|
| 85 | } |
---|
| 86 | else if(one_field) |
---|
| 87 | { |
---|
| 88 | char* descp=desc; |
---|
| 89 | for (int i=0; i< tab.count(); ++i) |
---|
| 90 | if(i==0) |
---|
| 91 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 92 | else |
---|
| 93 | { |
---|
| 94 | if(strcmp(tab[i].lemma(),tab[i-1].lemma())==0) |
---|
| 95 | descp += sprintf(descp,",%s",tab[i].descr()); |
---|
| 96 | else |
---|
| 97 | descp += sprintf(descp,";%s,%s",tab[i].lemma(),tab[i].descr()); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | strcpy(outline,line); |
---|
| 101 | outline[strlen(outline)-1]='\0'; |
---|
| 102 | strcat(outline,desc); |
---|
| 103 | strcat(outline,"\n"); |
---|
| 104 | fputs(outline, outputf); |
---|
| 105 | if (copy_processed) |
---|
| 106 | fputs(line,outputf); |
---|
| 107 | } |
---|
| 108 | else |
---|
| 109 | { |
---|
| 110 | for (int i=0; i< tab.count(); ++i) |
---|
| 111 | { |
---|
| 112 | // kolejne opisy - kolejne linie. |
---|
| 113 | sprintf(desc, " %s%s,%s\n", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 114 | strcpy(outline,line); |
---|
| 115 | outline[strlen(outline)-1]='\0'; |
---|
| 116 | strcat(outline,desc); |
---|
| 117 | fputs(outline, outputf); |
---|
| 118 | } |
---|
| 119 | if (copy_processed) |
---|
| 120 | fputs(line,outputf); |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | if(args.interactive_flag) |
---|
| 126 | fflush(outputf), fflush(failedf); |
---|
| 127 | |
---|
| 128 | } |
---|
| 129 | cmdline_parser_free(&args); |
---|
| 130 | } |
---|