[5f4d9c3] | 1 | #include "../lib/iotools.h" |
---|
| 2 | //do wyrzucenia - definicja w Makefile! #define _CMDLINE_FILE "../lem/cmdline.h" |
---|
| 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 |
---|
[cfdf333] | 35 | fprintf(stderr,"lem: Dictionary file not found.\n"); |
---|
[5f4d9c3] | 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); |
---|
| 53 | |
---|
| 54 | if (form==NULL) continue;//BZDURA |
---|
| 55 | |
---|
| 56 | lem->ana(form, tab); |
---|
| 57 | if(tab.count()==0) |
---|
| 58 | { |
---|
| 59 | char form1[MAX_FORM]; // tymczasowo tak, trzeba zmienic ana |
---|
| 60 | char* p; |
---|
| 61 | strcpy(form1,form); |
---|
| 62 | for(p=form1;*p;++p) *p=tolower(*p); |
---|
| 63 | p=form1; |
---|
| 64 | lem->ana(p,tab); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | if (tab.count() == 0) |
---|
[e0cd003] | 68 | fputs(line, outputf); |
---|
[5f4d9c3] | 69 | else |
---|
| 70 | { // mamy jakies opisy w slowniku |
---|
| 71 | |
---|
| 72 | if(one_line) |
---|
| 73 | { |
---|
| 74 | char* descp=desc; |
---|
| 75 | for (int i=0; i< tab.count(); ++i) |
---|
| 76 | { |
---|
| 77 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 78 | } |
---|
| 79 | strcpy(outline,line); |
---|
| 80 | outline[strlen(outline)-1]='\0'; |
---|
| 81 | strcat(outline,desc); |
---|
| 82 | strcat(outline,"\n"); |
---|
| 83 | fputs(outline, outputf); |
---|
| 84 | if (copy_processed) |
---|
| 85 | fputs(line,outputf); |
---|
| 86 | } |
---|
| 87 | else if(one_field) |
---|
| 88 | { |
---|
| 89 | char* descp=desc; |
---|
| 90 | for (int i=0; i< tab.count(); ++i) |
---|
| 91 | if(i==0) |
---|
| 92 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 93 | else |
---|
| 94 | { |
---|
| 95 | if(strcmp(tab[i].lemma(),tab[i-1].lemma())==0) |
---|
| 96 | descp += sprintf(descp,",%s",tab[i].descr()); |
---|
| 97 | else |
---|
| 98 | descp += sprintf(descp,";%s,%s",tab[i].lemma(),tab[i].descr()); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | strcpy(outline,line); |
---|
| 102 | outline[strlen(outline)-1]='\0'; |
---|
| 103 | strcat(outline,desc); |
---|
| 104 | strcat(outline,"\n"); |
---|
| 105 | fputs(outline, outputf); |
---|
| 106 | if (copy_processed) |
---|
| 107 | fputs(line,outputf); |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
| 111 | for (int i=0; i< tab.count(); ++i) |
---|
| 112 | { |
---|
| 113 | // kolejne opisy - kolejne linie. |
---|
| 114 | sprintf(desc, " %s%s,%s\n", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 115 | strcpy(outline,line); |
---|
| 116 | outline[strlen(outline)-1]='\0'; |
---|
| 117 | strcat(outline,desc); |
---|
| 118 | fputs(outline, outputf); |
---|
| 119 | } |
---|
| 120 | if (copy_processed) |
---|
| 121 | fputs(line,outputf); |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
[e0cd003] | 126 | if(args.interactive_flag) fflush(outputf); |
---|
[5f4d9c3] | 127 | |
---|
| 128 | } |
---|
| 129 | cmdline_parser_free(&args); |
---|
| 130 | } |
---|