| 1 | #include <stdlib.h> |
|---|
| 2 | #include <ctype.h> |
|---|
| 3 | #include "../lib/iotools.h" |
|---|
| 4 | //do wyrzucenia - definicja w Makefile! #define _CMDLINE_FILE "../cor/cmdline.h" |
|---|
| 5 | #include "../common/common.h" |
|---|
| 6 | #include "common_cor.h" |
|---|
| 7 | #include "corr.hh" |
|---|
| 8 | #include "cmdline.h" |
|---|
| 9 | #include <locale.h> |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | int main(int argc, char** argv) { |
|---|
| 13 | |
|---|
| 14 | // setlocale(LC_CTYPE,""); |
|---|
| 15 | // setlocale(LC_COLLATE,""); |
|---|
| 16 | |
|---|
| 17 | gengetopt_args_info args; |
|---|
| 18 | |
|---|
| 19 | if(cmdline_parser(argc, argv, &args) != 0) |
|---|
| 20 | exit(1); |
|---|
| 21 | |
|---|
| 22 | process_config_files(&args,argv[0]); |
|---|
| 23 | process_common_options(&args,argv[0]); |
|---|
| 24 | process_cor_options(&args); |
|---|
| 25 | |
|---|
| 26 | Corr cor; |
|---|
| 27 | |
|---|
| 28 | cor.load(dictionary); |
|---|
| 29 | cor.t=args.distance_arg; |
|---|
| 30 | |
|---|
| 31 | char line[MAX_LINE+1]; |
|---|
| 32 | long line_count = 0; |
|---|
| 33 | |
|---|
| 34 | Segment seg; |
|---|
| 35 | Words tab; |
|---|
| 36 | char form1[MAX_LINE]; |
|---|
| 37 | char* form; |
|---|
| 38 | int formcasing; |
|---|
| 39 | char corfield[MAX_LINE]=""; |
|---|
| 40 | |
|---|
| 41 | while (fgets(line, MAX_LINE, inputf)) |
|---|
| 42 | { |
|---|
| 43 | // strcpy(outline,line); |
|---|
| 44 | ++line_count; |
|---|
| 45 | |
|---|
| 46 | // if(!seg.parse(line)) |
|---|
| 47 | // { |
|---|
| 48 | // fprintf(stderr,"Input error in line %d.\n",line_count); |
|---|
| 49 | // exit(1); |
|---|
| 50 | // } |
|---|
| 51 | |
|---|
| 52 | char outline[128]; |
|---|
| 53 | //printf("Starting cor... searching for %d fields\n", args.input_field_given); |
|---|
| 54 | //for (int i=0; i<args.input_field_given; ++i) { |
|---|
| 55 | // printf("\t%d. %s\n", i, args.input_field_arg[i]); |
|---|
| 56 | //} |
|---|
| 57 | |
|---|
| 58 | if (!process_seg(line, args)) |
|---|
| 59 | fputs(line, outputf); |
|---|
| 60 | else |
|---|
| 61 | { |
|---|
| 62 | char form[MAX_FORM]; |
|---|
| 63 | |
|---|
| 64 | tab.clear(); |
|---|
| 65 | getfield(line,input_field_prefix,form); |
|---|
| 66 | if (form==NULL) continue; |
|---|
| 67 | |
|---|
| 68 | formcasing=3; |
|---|
| 69 | cor.correct(form, tab); |
|---|
| 70 | |
|---|
| 71 | if( tab.count() == 0 ) |
|---|
| 72 | { |
|---|
| 73 | formcasing=casing(form); |
|---|
| 74 | if( formcasing == 1 || formcasing == 2) |
|---|
| 75 | tolowers(form, form1), cor.correct(form1, tab); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | if ( tab.count() == 0) |
|---|
| 79 | fputs(line, failedf); |
|---|
| 80 | else |
|---|
| 81 | { |
|---|
| 82 | if(args.replace_flag) |
|---|
| 83 | { |
|---|
| 84 | char corfield[128]; |
|---|
| 85 | strcpy(corfield, input_field_prefix); |
|---|
| 86 | strcat(corfield, form); |
|---|
| 87 | seg.aux[seg.auxn]=corfield; |
|---|
| 88 | ++seg.auxn; |
|---|
| 89 | for(int i=0; i<tab.count(); ++i) |
|---|
| 90 | { |
|---|
| 91 | seg.form=tab[i].form(); |
|---|
| 92 | restorecasing(seg.form,seg.form,formcasing); |
|---|
| 93 | seg.print(outline); |
|---|
| 94 | fputs(outline, outputf); |
|---|
| 95 | } |
|---|
| 96 | --seg.auxn; |
|---|
| 97 | } |
|---|
| 98 | else |
|---|
| 99 | { |
|---|
| 100 | if(one_line) |
|---|
| 101 | { |
|---|
| 102 | char* p=corfield; |
|---|
| 103 | for(int i=0; i<tab.count(); ++i) |
|---|
| 104 | { |
|---|
| 105 | restorecasing(tab[i].form(),tab[i].form(),formcasing); |
|---|
| 106 | p += sprintf(p," %s%s",output_field_prefix,tab[i].form()); |
|---|
| 107 | } |
|---|
| 108 | sprintf(p,"\n"); |
|---|
| 109 | |
|---|
| 110 | strcpy(outline,line); |
|---|
| 111 | outline[strlen(outline)-1]='\0'; |
|---|
| 112 | strcat(outline,corfield); |
|---|
| 113 | fputs(outline, outputf); |
|---|
| 114 | } |
|---|
| 115 | else if(one_field) |
|---|
| 116 | { |
|---|
| 117 | char* p=corfield; |
|---|
| 118 | p += sprintf(p," %s",output_field_prefix); |
|---|
| 119 | for(int i=0; i<tab.count(); ++i) |
|---|
| 120 | { |
|---|
| 121 | restorecasing(tab[i].form(),tab[i].form(),formcasing); |
|---|
| 122 | p += sprintf(p,(i==0)?"%s":";%s",tab[i].form()); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | sprintf(p,"\n"); |
|---|
| 126 | |
|---|
| 127 | strcpy(outline,line); |
|---|
| 128 | outline[strlen(outline)-1]='\0'; |
|---|
| 129 | strcat(outline,corfield); |
|---|
| 130 | fputs(outline, outputf); |
|---|
| 131 | } |
|---|
| 132 | else |
|---|
| 133 | { |
|---|
| 134 | for(int i=0; i<tab.count(); ++i) |
|---|
| 135 | { |
|---|
| 136 | restorecasing(tab[i].form(),tab[i].form(),formcasing); |
|---|
| 137 | sprintf(corfield," %s%s\n",output_field_prefix,tab[i].form()); |
|---|
| 138 | strcpy(outline,line); |
|---|
| 139 | outline[strlen(outline)-1]='\0'; |
|---|
| 140 | strcat(outline,corfield); |
|---|
| 141 | fputs(outline, outputf); |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | if(args.interactive_flag) |
|---|
| 149 | { |
|---|
| 150 | fflush(outputf); |
|---|
| 151 | fflush(failedf); |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | cmdline_parser_free(&args); |
|---|
| 155 | } |
|---|