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 <cwchar> |
---|
8 | #include <clocale> |
---|
9 | #include <wctype.h> |
---|
10 | |
---|
11 | int main(int argc, char** argv) { |
---|
12 | |
---|
13 | setlocale(LC_CTYPE,""); |
---|
14 | |
---|
15 | gengetopt_args_info args; |
---|
16 | |
---|
17 | if(cmdline_parser(argc, argv, &args) != 0) |
---|
18 | exit(1); |
---|
19 | |
---|
20 | process_config_files(&args,argv[0]); |
---|
21 | process_common_options(&args,argv[0]); |
---|
22 | process_lem_options(&args); |
---|
23 | |
---|
24 | wchar_t line[MAX_LINE+1]; |
---|
25 | wchar_t outline[MAX_LINE+1]; |
---|
26 | wchar_t parms[MAX_LINE+1], desc[MAX_LINE+1], lemma[MAX_LINE+1]; |
---|
27 | long line_count = 0; |
---|
28 | |
---|
29 | Lem* lem; |
---|
30 | |
---|
31 | if(strcmp(dictionary+strlen(dictionary)-4,".bin")==0) |
---|
32 | lem = new Lem(dictionary); |
---|
33 | else if(strcmp(dictionary+strlen(dictionary)-4,".dic")==0) |
---|
34 | lem = new AuxLem(dictionary); |
---|
35 | else |
---|
36 | fprintf(stderr,"lem: Invalid dictionary file extension.\n"); |
---|
37 | |
---|
38 | Words tab; |
---|
39 | // Segment seg; |
---|
40 | |
---|
41 | while (fgetws(line, MAX_LINE, inputf)) |
---|
42 | { |
---|
43 | ++line_count; |
---|
44 | int start, len; |
---|
45 | |
---|
46 | char linechar[MAX_LINE+1]; |
---|
47 | wcstombs(linechar, line, MAX_LINE+1); |
---|
48 | if (!process_seg(linechar, args)) // TO POWINNO BYC WCZESNIEJ ZABEZPIECZONE |
---|
49 | fputws(line, outputf); |
---|
50 | else |
---|
51 | { |
---|
52 | wchar_t form[MAX_FORM+1]; |
---|
53 | |
---|
54 | tab.clear(); |
---|
55 | wchar_t winput_field_prefix[MAX_LINE+1]; |
---|
56 | mbstowcs(winput_field_prefix, input_field_prefix, MAX_LINE+1); |
---|
57 | getfield(line,winput_field_prefix,form); /// SEGMENTATION FAULT!!! |
---|
58 | /* W trakcie uzupelniania pola "4" nastepuje cos dziwnego... */ |
---|
59 | if (form==NULL) continue;//BZDURA |
---|
60 | lem->ana(form, tab); |
---|
61 | if(tab.count()==0) |
---|
62 | { |
---|
63 | |
---|
64 | wchar_t form1[MAX_FORM]; // tymczasowo tak, trzeba zmienic ana |
---|
65 | wchar_t* p; |
---|
66 | wcscpy(form1,form); |
---|
67 | for(p=form1;*p;++p) *p=towlower(*p); |
---|
68 | p=form1; |
---|
69 | lem->ana(p,tab); |
---|
70 | } |
---|
71 | if (tab.count() == 0) { |
---|
72 | fputws(line, outputf); |
---|
73 | } |
---|
74 | |
---|
75 | else |
---|
76 | { // mamy jakies opisy w slowniku |
---|
77 | if(one_line) |
---|
78 | { |
---|
79 | wchar_t* descp=desc; |
---|
80 | //wchar_t woutput_field_prefix[MAX_LINE+1]; |
---|
81 | //mbstowcs(woutput_field_prefix, output_field_prefix, MAX_LINE+1); |
---|
82 | wprintf(L"tab.count() in one-line: %d prefix: %s", tab.count(), output_field_prefix); |
---|
83 | for (int i=0; i< tab.count(); ++i) |
---|
84 | { |
---|
85 | descp += swprintf(descp,MAX_LINE, L" %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
86 | wprintf(L"for %d lemma '%s' descr '%s'", i, tab[i].lemma(), tab[i].descr()); |
---|
87 | } |
---|
88 | wprintf(L"descp: %ls", descp); |
---|
89 | wcscpy(outline,line); |
---|
90 | outline[wcslen(outline)-1]='\0'; |
---|
91 | wcscat(outline,descp); |
---|
92 | wcscat(outline,L"\n"); |
---|
93 | fputws(outline, outputf); |
---|
94 | if (copy_processed) |
---|
95 | fputws(line,outputf); |
---|
96 | } |
---|
97 | else if(one_field) |
---|
98 | { |
---|
99 | wchar_t* descp=desc; |
---|
100 | for (int i=0; i< tab.count(); ++i) |
---|
101 | if(i==0) |
---|
102 | descp += swprintf(descp,MAX_LINE,L" %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
103 | else |
---|
104 | { |
---|
105 | if(strcmp(tab[i].lemma(),tab[i-1].lemma())==0) |
---|
106 | descp += swprintf(descp,MAX_LINE,L",%s",tab[i].descr()); |
---|
107 | else |
---|
108 | descp += swprintf(descp,MAX_LINE,L";%s,%s",tab[i].lemma(),tab[i].descr()); |
---|
109 | } |
---|
110 | |
---|
111 | wcscpy(outline,line); |
---|
112 | wprintf(L"%ls \n", line); |
---|
113 | outline[wcslen(outline)-1]=L'\0'; |
---|
114 | wcscat(outline,desc); |
---|
115 | wcscat(outline,L"\n"); |
---|
116 | fputws(outline, outputf); |
---|
117 | |
---|
118 | if (copy_processed) fputws(line,outputf); |
---|
119 | } |
---|
120 | else |
---|
121 | { |
---|
122 | for (int i=0; i< tab.count(); ++i) |
---|
123 | { |
---|
124 | swprintf(desc,MAX_LINE,L" %s%s,%s \n", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
125 | wcscpy(outline,line); |
---|
126 | outline[wcslen(outline)-1]='\0'; |
---|
127 | wcscat(outline,desc); |
---|
128 | fputws(outline, outputf); |
---|
129 | } |
---|
130 | if (copy_processed) fputws(line,outputf); |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | if (args.interactive_flag) fflush(outputf); |
---|
136 | |
---|
137 | } |
---|
138 | cmdline_parser_free(&args); |
---|
139 | } |
---|