Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/w2t/w2t.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 215 - (show annotations) (download) (as text)
Thu Jan 29 14:40:13 2009 UTC (15 years, 4 months ago) by notanpe
File MIME type: text/x-csrc
File size: 25398 byte(s)
繰り返し埋めを追加
1 /*
2 todo
3 */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <strings.h>
7 #include <ctype.h>
8 #include <libgen.h>
9
10 #include "triplib.h"
11
12 #define IGNORE_FILE_NAME "ignore.txt" /* トリップとして有効でない分の出力先 */
13
14 #define MHCMARK "#MHC" /* mhc 用のマーク */
15
16 #define MAX_LINE_LEN 1000 /* 行の最大 */
17
18 #define MINTARG_DEF 7 /* ターゲットの最小文字数のデフォルト */
19 #define MINTARG_MIN 1 /* ターゲットの最小文字数の最小 */
20 #define MINTARG_MAX 10 /* ターゲットの最小文字数の最大 */
21
22 #define MAXTARG_DEF 10 /* ターゲットの最大文字数のデフォルト */
23 #define MAXTARG_MIN 1 /* ターゲットの最大文字数の最小 */
24 #define MAXTARG_MAX 10 /* ターゲットの最大文字数の最大 */
25
26 #define MINTANGO_DEF 3 /* 単語とみなす最小文字数のデフォルト */
27 #define MINTANGO_MIN 1 /* 単語とみなす最小文字数の最小 */
28 #define MINTANGO_MAX 10 /* 単語とみなす最小文字数の最大 */
29
30 #define MINIC_MIN 1 /* 強制的に区別なしにする最小文字数の最小 */
31 #define MINIC_MAX 10 /* 強制的に区別なしにする最小文字数の最大 */
32
33 int pattern; /* 展開指定 */
34 int location; /* 位置指定 */
35 int headUpper; /* 最初のアルファベットを大文字に、以降は小文字に */
36 int tobiMode; /* 飛石埋め */
37 int yamaMode; /* 山彦埋め */
38 int sourenMode; /* 双連埋め */
39 int makeIgnore; /* トリップとして有効でない分の出力 */
40 int noSlash; /* / を空白とみなす */
41 int noDot; /* . を空白とみなす */
42 int verbose; /* 饒舌モード */
43 int minTarg; /* ターゲットの最小文字数 */
44 int maxTarg; /* ターゲットの最大文字数 */
45 int minTango; /* 単語とみなす最小文字数 */
46 int minIC; /* 強制的に区別なしにする最小文字数 999 なら無効 */
47 int yokiMode; /* < >, <->, <'> などをよきにはからう */
48 int doorMode; /* ./ 埋めをした分は、全大文字のみに */
49 int inwall; /* wallChar で囲む */
50 int wallChar; /* 囲みに使う文字 */
51 int reverse; /* 逆読み */
52 int mhcMark; /* mhc 用マークの付加 */
53 int repeatUme; /* 最後の文字で埋め Baka -> Bakaaaaa */
54
55 unsigned char *inputFileName;
56 FILE *inputFile;
57
58 FILE *ignoreFile;
59
60 int lineNo;
61
62 #define MAX_MARK_PI_LEN 100
63 unsigned char mark[MAX_MARK_PI_LEN];
64 unsigned char postit[MAX_MARK_PI_LEN];
65
66 #define TOSEEK 0
67 #define TOTARGET 1
68 #define TOL2R 2
69 int kind;
70
71 void
72 usage()
73 {
74 switch ( kind ) {
75 case TOSEEK:
76 fprintf( stderr, "word2seek 1.9\n" );
77 fprintf( stderr, "w2s [-e num] [-c num] [-w num] [-g num] [-u] [-s {2|4|5}] [-/] [-f] [-i] [-t] [-r] [-n] [-y] [-d {/|.}] [-m mark] [-p postit] [-R] [-k] [-v] [-h] [-?] [ifile]\n" );
78 break;
79 case TOTARGET:
80 fprintf( stderr, "word2target 1.8\n" );
81 fprintf( stderr, "w2t [-e num] [-c num] [-w num] [-g num] [-u] [-s {2|4|5}] [-/] [-f] [-i] [-t] [-r] [-n] [-y] [-d {/|.}] [-a] [-m mark] [-M] [-R] [-k] [-v] [-h] [-?] [ifile]\n" );
82 break;
83 case TOL2R:
84 fprintf( stderr, "word2l2r 1.4\n" );
85 fprintf( stderr, "w2l [-e num] [-c num] [-w num] [-u] [-s {2|4|5}] [-/] [-f] [-r] [-n] [-y] [-d {/|.}] [-R] [-k] [-v] [-h] [-?] [ifile]\n" );
86 break;
87 }
88 fprintf( stderr, "何もオプションを指定しない場合、先頭指定で完全一致 + 3 パターン展開となります。\n" );
89 fprintf( stderr, " -e num : ターゲットの最小文字数 (%d 〜 %d 、デフォルトは %d)\n",
90 MINTARG_MIN, MINTARG_MAX, MINTARG_DEF );
91 fprintf( stderr, " -c num : ターゲットの最大文字数 (%d 〜 %d 、デフォルトは %d)\n",
92 MAXTARG_MIN, MAXTARG_MAX, MAXTARG_DEF );
93 fprintf( stderr, " -w num : 単語とみなす最小文字数 (%d 〜 %d 、デフォルトは %d)\n",
94 MINTANGO_MIN, MINTANGO_MAX, MINTANGO_DEF );
95 if ( kind != TOL2R ) {
96 fprintf( stderr, " -g num : 強制的に区別なしにする最小文字数 (%d 〜 %d 、デフォルトではしない)\n",
97 MINIC_MIN, MINIC_MAX );
98 }
99 fprintf( stderr, " -u : 先頭のアルファベットを大文字に、残りを小文字に\n" );
100 fprintf( stderr, " -s 2 : 飛石埋め\n" );
101 fprintf( stderr, " -s 4 : 山彦埋め\n" );
102 fprintf( stderr, " -s 5 : 双連埋め\n" );
103 fprintf( stderr, " -/ : 単語を / で囲む\n" );
104 fprintf( stderr, " -. : 単語を . で囲む\n" );
105 fprintf( stderr, " ( -/ と -. は排他)\n" );
106 fprintf( stderr, " -f : 完全一致\n" );
107 if ( kind != TOL2R ) {
108 fprintf( stderr, " -i : 大文字小文字区別なし\n" );
109 fprintf( stderr, " -t : 後方指定\n" );
110 }
111 fprintf( stderr, " -r : 位置指定なし\n" );
112 fprintf( stderr, " -n : トリップとして有効でない分を %s に出力\n", IGNORE_FILE_NAME );
113 fprintf( stderr, " -y : 1 エントリ / 1 行とみなして、いろいろとよきにはからう\n" );
114 fprintf( stderr, " -d / : 読み込んだ / を空白とみなす\n" );
115 fprintf( stderr, " -d . : 読み込んだ . を空白とみなす\n" );
116 if ( kind == TOTARGET ) {
117 fprintf( stderr, " -a : ./ で埋めた時は、全大文字のみに\n" );
118 }
119 if ( kind == TOSEEK ) {
120 fprintf( stderr, " -m mark : Unified Tripper 対応のマーク\n" );
121 fprintf( stderr, " -p postit : Unified Tripper 対応の付箋\n" );
122 }
123 if ( kind == TOTARGET ) {
124 fprintf( stderr, " -m mark : まあ、待て屋。ログマネージャ対応のマーク\n" );
125 fprintf( stderr, " -M : まあ、待て屋。ヒットチェッカー用マークを付加\n" );
126 }
127 fprintf( stderr, " -R : 逆読み\n" );
128 fprintf( stderr, " -k : 最後の文字繰り返し埋め\n" );
129 fprintf( stderr, " -v : 饒舌モード\n" );
130 fprintf( stderr, " -h : これを表示\n" );
131 fprintf( stderr, " -? : これを表示\n" );
132 fprintf( stderr, " ifile : 単語ファイル (省略時には、標準入力から)\n" );
133 }
134
135 void
136 getOption( ac, av )
137 int ac;
138 char *av[];
139 {
140 extern char *optarg;
141 extern int optind, opterr, optopt;
142 int optChar;
143
144 pattern = PAT_3;
145 location = LOC_HEAD;
146 minTarg = MINTARG_DEF;
147 maxTarg = MAXTARG_DEF;
148 headUpper = TL_FALSE;
149 tobiMode = TL_FALSE;
150 yamaMode = TL_FALSE;
151 sourenMode = TL_FALSE;
152 minTango = MINTANGO_DEF;
153 verbose = TL_FALSE;
154 makeIgnore = TL_FALSE;
155 noSlash = TL_FALSE;
156 noDot = TL_FALSE;
157 yokiMode = TL_FALSE;
158 doorMode = TL_FALSE;
159 inwall = TL_FALSE;
160 wallChar = ' ';
161 reverse = TL_FALSE;
162 mark[0] = '\0';
163 postit[0] = '\0';
164 minIC = 999;
165 mhcMark = TL_FALSE;
166 repeatUme = TL_FALSE;
167 while ( (optChar = getopt(ac, av, "e:c:w:g:us:/.fitrnyd:am:Mp:Rkvh?")) != EOF ) {
168 switch ( optChar ) {
169 case 'e':
170 minTarg = atoi( optarg );
171 if ( minTarg < MINTARG_MIN || minTarg > MINTARG_MAX ) {
172 usage();
173 exit( 1 );
174 }
175 break;
176 case 'c':
177 maxTarg = atoi( optarg );
178 if ( maxTarg < MAXTARG_MIN || maxTarg > MAXTARG_MAX ) {
179 usage();
180 exit( 1 );
181 }
182 break;
183 case 'w':
184 minTango = atoi( optarg );
185 if ( minTango < MINTANGO_MIN || minTango > MINTANGO_MAX ) {
186 usage();
187 exit( 1 );
188 }
189 break;
190 case 'g':
191 minIC = atoi( optarg );
192 if ( minIC < MINIC_MIN || minIC > MINIC_MAX ) {
193 usage();
194 exit( 1 );
195 }
196 if ( kind == TOL2R ) {
197 usage();
198 exit( 1 );
199 }
200 break;
201 case 'u': headUpper = TL_TRUE; break;
202 case 's':
203 switch ( optarg[0] ) {
204 case '2': tobiMode = TL_TRUE; break;
205 case '4': yamaMode = TL_TRUE; break;
206 case '5': sourenMode = TL_TRUE; break;
207 default:
208 usage();
209 exit( 1 );
210 }
211 break;
212 case '/':
213 if ( wallChar == '.' ) {
214 usage();
215 exit( 1 );
216 }
217 inwall = TL_TRUE;
218 wallChar = '/';
219 break;
220 case '.':
221 if ( wallChar == '/' ) {
222 usage();
223 exit( 1 );
224 }
225 inwall = TL_TRUE;
226 wallChar = '.';
227 break;
228 case 'f': pattern = PAT_PERF; break;
229 case 'i':
230 pattern = PAT_ANY;
231 if ( kind == TOL2R ) {
232 usage();
233 exit( 1 );
234 }
235 break;
236 case 't':
237 location = LOC_TAIL;
238 if ( kind == TOL2R ) {
239 usage();
240 exit( 1 );
241 }
242 break;
243 case 'r': location = LOC_ANY; break;
244 case 'n': makeIgnore = TL_TRUE; break;
245 case 'y': yokiMode = TL_TRUE; break;
246 case 'd':
247 switch ( optarg[0] ) {
248 case '/': noSlash = TL_TRUE; break;
249 case '.': noDot = TL_TRUE; break;
250 }
251 break;
252 case 'a':
253 if ( kind != TOTARGET ) {
254 usage();
255 exit( 1 );
256 }
257 doorMode = TL_TRUE;
258 break;
259 case 'm':
260 if ( kind != TOSEEK && kind != TOTARGET ) {
261 usage();
262 exit( 1 );
263 }
264 strcpy( mark, optarg );
265 break;
266 case 'M':
267 if ( kind != TOTARGET ) {
268 usage();
269 exit( 1 );
270 }
271 mhcMark = TL_TRUE;
272 break;
273 case 'p':
274 if ( kind != TOSEEK ) {
275 usage();
276 exit( 1 );
277 }
278 strcpy( postit, optarg );
279 break;
280 case 'R': reverse = TL_TRUE; break;
281 case 'k': repeatUme = TL_TRUE; break;
282 case 'v': verbose = TL_TRUE; break;
283 case 'h': case '?': usage(); exit( 0 ); break;
284 }
285 }
286
287 switch ( ac - optind) {
288 case 0:
289 inputFileName = NULL;
290 break;
291 case 1:
292 inputFileName = av[optind];
293 break;
294 default:
295 usage();
296 exit( 1 );
297 }
298
299 if ( verbose ) {
300 fprintf( stderr, "ターゲットの最小文字数 : %d\n", minTarg );
301 fprintf( stderr, "ターゲットの最大文字数 : %d\n", maxTarg );
302 fprintf( stderr, "単語とみなす最小文字数 : %d\n", minTango );
303 if ( headUpper ) {
304 fprintf( stderr, "先頭大文字、残りを小文字に変換\n" );
305 }
306 if ( tobiMode ) {
307 fprintf( stderr, "飛石埋め\n" );
308 }
309 if ( yamaMode ) {
310 fprintf( stderr, "山彦埋め\n" );
311 }
312 if ( sourenMode ) {
313 fprintf( stderr, "双連埋め\n" );
314 }
315 switch ( pattern ) {
316 case PAT_PERF: fprintf( stderr, "完全一致\n" ); break;
317 case PAT_ANY: fprintf( stderr, "大文字小文字区別なし\n" ); break;
318 case PAT_3: fprintf( stderr, "完全一致 + 3 パターン展開\n" ); break;
319 }
320 switch ( location ) {
321 case LOC_HEAD: fprintf( stderr, "先頭指定\n" ); break;
322 case LOC_ANY: fprintf( stderr, "位置指定なし\n" ); break;
323 case LOC_TAIL: fprintf( stderr, "末尾指定\n" ); break;
324 }
325 if ( kind == TOSEEK || kind == TOTARGET ) {
326 if ( mark[0] != '\0' ) {
327 fprintf( stderr, "マークとして、%s を使用\n", mark );
328 }
329 if ( postit[0] != '\0' ) {
330 fprintf( stderr, "付箋として、%s を使用\n", postit );
331 }
332 if ( mhcMark ) {
333 /* target の場合のみだけど、seek なら mhcMark は偽なのでおk */
334 fprintf( stderr, "mhc 用マークを付加\n" );
335 }
336 }
337 if ( makeIgnore ) {
338 fprintf( stderr, "トリップとして有効でない分は、%s ファイルへ出力\n",
339 IGNORE_FILE_NAME );
340 }
341 if ( noSlash ) {
342 fprintf( stderr, "読み込んだ / は空白とみなす\n" );
343 }
344 if ( noDot ) {
345 fprintf( stderr, "読み込んだ . は空白とみなす\n" );
346 }
347 if ( yokiMode ) {
348 fprintf( stderr, "読み込んだ空白と - と ' を適切に処理\n" );
349 }
350 if ( doorMode ) {
351 fprintf( stderr, "./ で埋めた時には、全大文字のみに\n" );
352 }
353 if ( inwall ) {
354 fprintf( stderr, "%c で囲む\n", wallChar );
355 }
356 if ( reverse ) {
357 fprintf( stderr, "逆読み (マニア向けw)\n" );
358 }
359 if ( repeatUme ) {
360 fprintf( stderr, "最後の文字繰り返し埋め\n" );
361 }
362 }
363 }
364
365 void
366 writeL2r( word )
367 unsigned char *word;
368 {
369 static int firstCall = TL_TRUE;
370 static unsigned char head[2];
371
372 if ( firstCall ) {
373 firstCall = TL_FALSE;
374 head[1] = '\0';
375 switch ( location ) {
376 case LOC_HEAD:
377 switch ( pattern ) {
378 case PAT_PERF: head[0] = '&'; break;
379 case PAT_3: head[0] = '^'; break;
380 }
381 break;
382 case LOC_ANY:
383 switch ( pattern ) {
384 case PAT_PERF: head[0] = '@'; break;
385 case PAT_3: head[0] = '\0'; break;
386 }
387 break;
388 }
389 }
390
391 printf( "%s%s\n", head, word );
392 }
393
394 void
395 writeSeek( word )
396 unsigned char *word;
397 {
398 static int firstCall = TL_TRUE;
399 static unsigned char loc[2], pat[2];
400 int wordLen;
401
402 if ( firstCall ) {
403 firstCall = TL_FALSE;
404 loc[1] = '\0';
405 switch ( location ) {
406 case LOC_HEAD: loc[0] = '^'; break;
407 case LOC_ANY: loc[0] = '\0'; break;
408 case LOC_TAIL: loc[0] = '>'; break;
409 }
410 pat[1] = '\0';
411 switch ( pattern ) {
412 case PAT_PERF: pat[0] = '*'; break;
413 case PAT_ANY: pat[0] = '\0'; break;
414 case PAT_3: pat[0] = '+'; break;
415 }
416 }
417
418 wordLen = strlen( word );
419 if ( minIC <= wordLen ) {
420 printf( "%s%s", loc, word );
421 } else {
422 printf( "%s%s%s", loc, word, pat );
423 }
424 if ( mark[0] != '\0' ) {
425 printf( "\t/M%s", mark );
426 }
427 if ( postit[0] != '\0' ) {
428 printf( "\t/P%s", postit );
429 }
430 printf( "\n" );
431 }
432
433 void
434 writeTarget( word )
435 unsigned char *word;
436 {
437 static int firstCall = TL_TRUE;
438 static unsigned char head[2], tail[2];
439 unsigned char *threePat[3];
440 int wordLen;
441 int i;
442 int needTailCheck;
443 unsigned char tailChar;
444
445 if ( firstCall ) {
446 firstCall = TL_FALSE;
447 head[1] = '\0';
448 tail[1] = '\0';
449 switch ( location ) {
450 case LOC_HEAD: head[0] = '^'; tail[0] = '\0'; break;
451 case LOC_ANY: head[0] = '\0'; tail[0] = '\0'; break;
452 case LOC_TAIL: head[0] = '\0'; tail[0] = '$'; break;
453 }
454 }
455
456 wordLen = strlen( word );
457 tailChar = word[wordLen - 1];
458 needTailCheck = (location == LOC_TAIL || wordLen == TRIP_LEN);
459
460 if ( minIC <= wordLen || pattern == PAT_ANY ) {
461 /* 区別なし */
462 if ( needTailCheck && !istailic[word[wordLen - 1]] ) {
463 return;
464 }
465 printf( "%s", head );
466 for ( i = 0; i < wordLen - 1; i++ ) {
467 if ( isalpha( word[i] ) ) {
468 printf( "[%c%c]", tolower( word[i] ), toupper( word[i] ) );
469 } else {
470 putchar( word[i] );
471 }
472 }
473 /* 最後の一文字は、末尾かどうかで処理が変わる */
474 if ( needTailCheck ) {
475 if ( istail[tolower( tailChar )] ) {
476 putchar( tolower( tailChar ) );
477 } else {
478 putchar( toupper( tailChar ) );
479 }
480 } else {
481 if ( isalpha( tailChar ) ) {
482 printf( "[%c%c]", tolower( tailChar ), toupper( tailChar ) );
483 } else {
484 putchar( tailChar );
485 }
486 }
487 printf( "%s", tail );
488 if ( mark[0] != '\0' ) {
489 printf( "\t#%s", mark );
490 }
491 if ( mhcMark ) {
492 printf( "\t%s", MHCMARK );
493 }
494 printf( "\n" );
495 } else if ( pattern == PAT_PERF ) {
496 /* 完全 */
497 if ( (needTailCheck && istail[tailChar]) || !needTailCheck ) {
498 printf( "%s%s%s", head, word, tail );
499 if ( mark[0] != '\0' ) {
500 printf( "\t#%s", mark );
501 }
502 if ( mhcMark ) {
503 printf( "\t%s", MHCMARK );
504 }
505 printf( "\n" );
506 }
507 } else if ( pattern == PAT_3 ) {
508 /* 3 パターン */
509 /* オリジナルが全小/全大/先大のどれかなら出力しない */
510 /* 全大とまとめられる場合もあるけど、まいっか */
511 if ( !doorMode ) {
512 if ( (needTailCheck && istail[tailChar]) || !needTailCheck ) {
513 if ( reverse ) {
514 make3PatternR( word, threePat );
515 } else {
516 make3Pattern( word, threePat );
517 }
518 for ( i = 0; i < 3; i++ ) {
519 if ( threePat[i] == NULL ) {
520 goto NEXT;
521 }
522 }
523 printf( "%s%s%s", head, word, tail );
524 if ( mark[0] != '\0' ) {
525 printf( "\t#%s", mark );
526 }
527 if ( mhcMark ) {
528 printf( "\t%s", MHCMARK );
529 }
530 printf( "\n" );
531 }
532 NEXT:
533 /* 9[aA]bcd : 最初に現れるアルファベットのみ大小、残り小 */
534 /* 逆読みの場合は、最後に現れる(r */
535 if ( (needTailCheck && istail[tolower(tailChar)]) || !needTailCheck ) {
536 int alphaIdx;
537 printf( "%s", head );
538 if ( reverse ) {
539 for ( alphaIdx = wordLen - 1; alphaIdx >= 0; alphaIdx-- ) {
540 if ( isalpha( word[alphaIdx] ) ) { break; }
541 }
542 } else {
543 for ( alphaIdx = 0; alphaIdx < wordLen; alphaIdx++ ) {
544 if ( isalpha( word[alphaIdx] ) ) { break; }
545 }
546 }
547 for ( i = 0; i < wordLen; i++ ) {
548 if ( i == alphaIdx ) {
549 putchar( '[' );
550 putchar( tolower( word[i] ) );
551 putchar( toupper( word[i] ) );
552 putchar( ']' );
553 } else {
554 putchar( tolower( word[i] ) );
555 }
556 }
557 printf( "%s", tail );
558 if ( mark[0] != '\0' ) {
559 printf( "\t#%s", mark );
560 }
561 if ( mhcMark ) {
562 printf( "\t%s", MHCMARK );
563 }
564 printf( "\n" );
565 }
566 }
567 /* ABCD : 全大 */
568 if ( (needTailCheck && istail[toupper(tailChar)]) || !needTailCheck ) {
569 printf( "%s", head );
570 for ( i = 0; i < wordLen; i++ ) {
571 putchar( toupper( word[i] ) );
572 }
573 printf( "%s", tail );
574 if ( mark[0] != '\0' ) {
575 printf( "\t#%s", mark );
576 }
577 if ( mhcMark ) {
578 printf( "\t%s", MHCMARK );
579 }
580 printf( "\n" );
581 }
582 }
583 }
584
585 void
586 writeIt( word )
587 unsigned char *word;
588 {
589 unsigned char tmpWord[MAX_LINE_LEN];
590 int wordLen;
591
592 strcpy( tmpWord, word );
593 tmpWord[maxTarg] = '\0';
594 wordLen = strlen( tmpWord );
595 if ( wordLen == TRIP_LEN ) {
596 if ( pattern == PAT_PERF ) {
597 if ( !istail[tmpWord[TRIP_LEN - 1]] ) {
598 return;
599 }
600 } else {
601 if ( !istailic[tmpWord[TRIP_LEN - 1]] ) {
602 return;
603 }
604 }
605 }
606
607 switch ( kind ) {
608 case TOSEEK:
609 writeSeek( tmpWord );
610 break;
611 case TOTARGET:
612 writeTarget( tmpWord );
613 break;
614 case TOL2R:
615 writeL2r( tmpWord );
616 break;
617 }
618 }
619
620 void
621 ume( line, delim )
622 unsigned char *line;
623 unsigned char delim;
624 {
625 int i;
626 unsigned char ume[MAX_LINE_LEN];
627
628 for ( i = 0; line[i] != '\0'; i++ ) {
629 ume[i] = line[i];
630 }
631 for ( ; i < minTarg; i++ ) {
632 ume[i] = delim;
633 }
634 ume[i] = '\0';
635 writeIt( ume );
636 }
637
638 void
639 tobi( line, delim )
640 unsigned char *line;
641 unsigned char delim;
642 {
643 int i, j;
644 unsigned char tobi1[MAX_LINE_LEN], tobi2[MAX_LINE_LEN];
645
646 j = 0;
647 for ( i = 0; line[i] != '\0'; i++ ) {
648 tobi1[j] = delim;
649 tobi2[j] = line[i];
650 j++;
651 tobi1[j] = line[i];
652 tobi2[j] = delim;
653 j++;
654 }
655 tobi2[j] = '\0';
656 tobi1[j++] = delim;
657 tobi1[j] = '\0';
658 tobi1[10] = '\0';
659 ume( tobi1, delim );
660 if ( delim != '/' ) {
661 ume( tobi2, delim );
662 } else {
663 if ( strlen( line ) <= 4 ) {
664 j = 0;
665 for ( i = 0; line[i] != '\0'; i++ ) {
666 tobi1[j++] = line[i];
667 tobi1[j++] = '.';
668 tobi1[j++] = '.';
669 }
670 tobi1[j] = '\0';
671 tobi1[10] = '\0';
672 ume( tobi1, delim );
673 }
674 }
675 }
676
677 void
678 yamaSub( yama )
679 unsigned char *yama;
680 {
681 ume( yama, '.' );
682 if ( strlen( yama ) < minTarg ) {
683 ume( yama, '/' );
684 }
685 }
686
687 void
688 yama( line )
689 unsigned char *line;
690 {
691 unsigned char yama[MAX_LINE_LEN];
692 int wordLen;
693
694 strcpy( yama, line );
695 strcat( yama, line );
696 yamaSub( yama );
697
698 wordLen = strlen( line );
699 switch ( wordLen ) {
700 case 2:
701 strcpy( yama, line );
702 strcat( yama, line );
703 strcat( yama, line );
704 strcat( yama, line );
705 yamaSub( yama );
706 break;
707 case 3:
708 strcpy( yama, line );
709 strcat( yama, line );
710 strcat( yama, line );
711 yamaSub( yama );
712 break;
713 }
714 }
715
716 void
717 souren( line )
718 unsigned char *line;
719 {
720 int i, j;
721 unsigned char souren[MAX_LINE_LEN];
722
723 j = 0;
724 for ( i = 0; line[i] != '\0'; i++ ) {
725 souren[j++] = line[i];
726 souren[j++] = line[i];
727 }
728 souren[j] = '\0';
729 ume( souren, '.' );
730 if ( strlen( souren ) < minTarg ) {
731 ume( souren, '/' );
732 }
733 }
734
735 void
736 addWord( word )
737 unsigned char *word;
738 {
739 int i;
740 int wordLen;
741
742 wordLen = strlen( word );
743 if ( wordLen < minTango || wordLen > TRIP_LEN ) {
744 if ( makeIgnore ) {
745 fprintf( ignoreFile, "%d : %s (文字数)\n", lineNo, word );
746 }
747 return;
748 }
749 if ( wordLen == TRIP_LEN ) {
750 if ( pattern == PAT_PERF ) {
751 if ( !istail[word[TRIP_LEN - 1]] ) {
752 if ( makeIgnore ) {
753 fprintf( ignoreFile, "%d : %s (末尾文字)\n", lineNo, word );
754 }
755 return;
756 }
757 } else {
758 if ( !istailic[word[TRIP_LEN - 1]] ) {
759 if ( makeIgnore ) {
760 fprintf( ignoreFile, "%d : %s (末尾文字)\n", lineNo, word );
761 }
762 return;
763 }
764 }
765 }
766
767 if ( headUpper ) {
768 for ( i = 0; word[i] != '\0'; i++ ) {
769 if ( isalpha( word[i] ) ) {
770 word[i] = toupper( word[i] );
771 break;
772 }
773 }
774 i++;
775 for ( ; word[i] != '\0'; i++ ) {
776 word[i] = tolower( word[i] );
777 }
778 }
779 if ( tobiMode || yamaMode || sourenMode ) {
780 if ( wordLen <= (TRIP_LEN / 2) ) {
781 if ( tobiMode ) {
782 tobi( word, '.' );
783 tobi( word, '/' );
784 }
785 if ( yamaMode ) {
786 yama( word );
787 }
788 if ( sourenMode ) {
789 souren( word );
790 }
791 }
792 } else {
793 if ( wordLen < minTarg ) {
794 if ( repeatUme ) {
795 ume( word, word[wordLen - 1] );
796 } else {
797 ume( word, '.' );
798 ume( word, '/' );
799 }
800 } else {
801 writeIt( word );
802 }
803 }
804 }
805
806 void
807 makeIt()
808 {
809 int i, j, wordIndex1, wordIndex3;
810 int toUpper;
811 int lineLen;
812 unsigned char line[MAX_LINE_LEN], tmpLine[MAX_LINE_LEN],
813 tmpWord[MAX_LINE_LEN],
814 word1[MAX_LINE_LEN], word2[MAX_LINE_LEN], word3[MAX_LINE_LEN];
815 unsigned char *linePtr, *strHead;
816
817 if ( inputFileName == NULL ) {
818 inputFile = stdin;
819 } else {
820 if ( (inputFile = fopen( inputFileName, "r" )) == NULL ) {
821 fprintf( stderr, "%s が読めません。\n", inputFileName );
822 exit( 1 );
823 }
824 }
825 if ( makeIgnore ) {
826 if ( (ignoreFile = fopen( IGNORE_FILE_NAME, "w" )) == NULL ) {
827 fprintf( stderr, "%s に書けません。\n", IGNORE_FILE_NAME );
828 exit( 1 );
829 }
830 }
831
832 lineNo = 0;
833 while ( fgets( line, MAX_LINE_LEN, inputFile ) != NULL ) {
834 lineNo++;
835 if ( line[0] == '#' ) {
836 /* 先頭が # の行はコメントとして無視 */
837 continue;
838 }
839 lineLen = delCr( line );
840
841 /*
842 先頭の空白を捨てつつ、連続する空白を一個にまとめて、末尾の空白も捨てる
843 */
844 i = 0;
845 j = 0;
846 while ( i < lineLen ) {
847 if ( line[i] == ' ' || line[i] == '\t' ) {
848 tmpLine[j++] = ' ';
849 #if 0
850 if ( j != 0 ) {
851 if ( tmpLine[j-1] != '.' ) {
852 tmpLine[j++] = ' ';
853 }
854 }
855 #endif /* 0 */
856 while ( line[i] == ' ' || line[i] == '\t' ) {
857 i++;
858 }
859 } else {
860 tmpLine[j++] = line[i++];
861 }
862 }
863 if ( tmpLine[j-1] == ' ' ) {
864 j--;
865 }
866 tmpLine[j] = '\0';
867 strcpy( line, tmpLine );
868 lineLen = j;
869 #ifdef OLDDEBUG
870 printf( "line = <%s>, lineLen = %d\n", line, lineLen );
871 exit( 0 );
872 #endif /* DEBUG */
873
874 if ( reverse ) {
875 unsigned char work;
876 #ifdef OLDDEBUG
877 printf( "reverse before : <%s>\n", line );
878 #endif /* DEBUG */
879 /*
880 abc 0,2
881 abcd 0,3 1,2
882 */
883 for ( i = 0; i < lineLen / 2; i++ ) {
884 work = line[i];
885 line[i] = line[lineLen - i - 1];
886 line[lineLen - i - 1] = work;
887 }
888 #ifdef OLDDEBUG
889 printf( "reverse after : <%s>\n", line );
890 #endif /* DEBUG */
891 }
892 if ( inwall ) {
893 line[lineLen+1] = wallChar;
894 line[lineLen+2] = '\0';
895 for ( i = lineLen; i > 0; i-- ) {
896 line[i] = line[i-1];
897 }
898 line[0] = wallChar;
899 lineLen += 2;
900 }
901 #ifdef OLDDEBUG
902 printf( "line = <%s>\n", line );
903 #endif /* DEBUG */
904 if ( yokiMode ) {
905 int needYoki;
906 needYoki = TL_FALSE;
907 for ( i = 0; i < lineLen; i++ ) {
908 if ( line[i] == '-' || line[i] == ' ' ||
909 line[i] == '\'' || line[i] == ',' ) {
910 needYoki = TL_TRUE;
911 break;
912 } else {
913 if ( !istrip[line[i]] ) {
914 fprintf( stderr, "トリップとして有効でない文字 (%c) が %d 行目に。\n",
915 line[i], lineNo );
916 needYoki = TL_TRUE;
917 break;
918 }
919 }
920 }
921 if ( needYoki ) {
922 /* ' と , は捨てる。. の後ろのスペースも捨てる。!istrip[] な文字も捨てる */
923 wordIndex1 = 0;
924 for ( i = 0; line[i] != '\0'; i++ ) {
925 if ( line[i] != '\'' && line[i] != ',' ) {
926 if ( line[i] == ' ' ) {
927 if ( wordIndex1 != 0 ) {
928 if ( tmpWord[wordIndex1-1] != '.' ) {
929 tmpWord[wordIndex1] = line[i];
930 wordIndex1++;
931 }
932 }
933 } else {
934 if ( istrip[line[i]] ) {
935 tmpWord[wordIndex1] = line[i];
936 wordIndex1++;
937 }
938 }
939 }
940 }
941 tmpWord[wordIndex1] = '\0';
942 #ifdef OLDDEBUG
943 printf( "after del <'> : tmpWord = <%s>\n", tmpWord );
944 #endif /* DEBUG */
945 /* <->, < > : . / 無 (先大) */
946 wordIndex1 = wordIndex3 = 0;
947 toUpper = TL_TRUE;
948 for ( i = 0; tmpWord[i] != '\0'; i++ ) {
949 if ( tmpWord[i] == '-' || tmpWord[i] == ' ' ) {
950 word1[wordIndex1] = '.';
951 word2[wordIndex1] = '/';
952 wordIndex1++;
953 toUpper = TL_TRUE;
954 } else {
955 if ( toUpper ) {
956 word1[wordIndex1] = toupper( tmpWord[i] );
957 word2[wordIndex1] = toupper( tmpWord[i] );
958 word3[wordIndex3] = toupper( tmpWord[i] );
959 toUpper = TL_FALSE;
960 } else {
961 word1[wordIndex1] = tmpWord[i];
962 word2[wordIndex1] = tmpWord[i];
963 word3[wordIndex3] = tmpWord[i];
964 }
965 wordIndex1++;
966 wordIndex3++;
967 }
968 }
969 word1[wordIndex1] = '\0';
970 word2[wordIndex1] = '\0';
971 word3[wordIndex3] = '\0';
972 addWord( word1 );
973 if ( strcmp( word1, word2 ) != 0 ) {
974 addWord( word2 );
975 addWord( word3 );
976 }
977 #ifdef OLDDEBUG
978 printf( "word1 = <%s>, word2 = <%s>, word3 = <%s>\n",
979 word1, word2, word3 );
980 #endif /* DEBUG */
981 } else {
982 addWord( line );
983 }
984 } else {
985 for ( linePtr = line + lineLen - 1; linePtr >= line; linePtr-- ) {
986 if ( !istrip[*linePtr] ) {
987 *linePtr = '\0';
988 }
989 if ( noSlash && *linePtr == '/' ) {
990 *linePtr = '\0';
991 }
992 if ( noDot && *linePtr == '.' ) {
993 *linePtr = '\0';
994 }
995 }
996 for ( i = 0; i < lineLen; i++ ) {
997 if ( line[i] != '\0' ) {
998 #ifdef OLDDEBUG
999 printf( "word = <%s>\n", line + i );
1000 #endif /* DEBUG */
1001 addWord( line + i );
1002 for ( ; i < lineLen; i++ ) {
1003 if ( line[i] == '\0' ) {
1004 break;
1005 }
1006 }
1007 }
1008 }
1009 }
1010 }
1011
1012 if ( makeIgnore ) {
1013 fclose( ignoreFile );
1014 }
1015 fclose( inputFile );
1016 }
1017
1018 main( ac, av )
1019 int ac;
1020 char *av[];
1021 {
1022 char *myName;
1023
1024 myName = basename( av[0] );
1025 switch ( myName[2] ) {
1026 case 't': /* w2t */
1027 kind = TOTARGET; break;
1028 case 's': /* w2s */
1029 kind = TOSEEK; break;
1030 case 'l': /* w2l */
1031 kind = TOL2R; break;
1032 default:
1033 fprintf( stderr, "ここはだれ?わたしはどこ?\n" );
1034 exit( 1 );
1035 }
1036 #ifdef OLDDEBUG
1037 printf( "myName = <%s>, kind = %d\n", myName, kind );
1038 #endif /* DEBUG */
1039
1040 getOption( ac, av );
1041
1042 makeIt();
1043
1044 exit( 0 );
1045 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Rev URL

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26