• R/O
  • SSH
  • HTTPS

l2r: コミット


コミットメタ情報

リビジョン11 (tree)
日時2007-05-11 21:53:31
作者notanpe

ログメッセージ

展開部分を書き直し。

変更サマリ

差分

--- l2.c (revision 10)
+++ l2.c (revision 11)
@@ -33,6 +33,9 @@
3333 最低 7 文字
3434 */
3535
36+#define MINLENPAD 7 /* 水増し後の最小文字数 */
37+#define MINLENCUT 6 /* 水増し前の最小文字数 */
38+
3639 struct bintrip {
3740 uint64_t btrip;
3841 uint64_t bmask;
@@ -70,13 +73,14 @@
7073 enum types { ALL, CAP, LEAD, CAPLEAD };
7174
7275 static void hit( uint64_t bin, unsigned char *key, uint64_t targ );
73-static void bin2trip( uint64_t bin, char *trip );
74-static void trip2bin( uint64_t *bin, char *trip );
76+static void bin2trip( uint64_t bin, unsigned char *trip );
77+static void trip2bin( uint64_t *bin, unsigned char *trip );
7578 static void signalHandler( int sig );
76-static int checkTrip( char *trip, unsigned int tripLen );
77-static void addTrip( char *trip );
78-static void mkvarSub();
79-static void mkvarSub2();
79+static int checkTrip( unsigned char *trip, unsigned int tripLen );
80+static void addTrip( unsigned char *trip );
81+static void mkvar( unsigned char *trip, enum types vtype );
82+static void mkvarSub( unsigned char *org, enum types vtype, unsigned int nq );
83+static void mkvarSub2( unsigned char *org, enum types vtype, unsigned int pad );
8084
8185 #ifdef DUMPTARGET
8286 static void dumpTargets();
@@ -109,7 +113,7 @@
109113 void
110114 bin2trip( bin, trip )
111115 uint64_t bin;
112-char *trip;
116+unsigned char *trip;
113117 {
114118 int i;
115119 unsigned int c;
@@ -138,7 +142,7 @@
138142 void
139143 trip2bin( bin, trip )
140144 uint64_t *bin;
141-char *trip;
145+unsigned char *trip;
142146 {
143147 int i, j;
144148
@@ -215,7 +219,7 @@
215219 static
216220 int
217221 checkTrip( trip, tripLen )
218-char *trip;
222+unsigned char *trip;
219223 unsigned int tripLen;
220224 {
221225 unsigned int i;
@@ -294,7 +298,7 @@
294298 static
295299 void
296300 addTrip( tripv )
297-char *tripv;
301+unsigned char *tripv;
298302 {
299303 uint64_t out;
300304 unsigned long idx;
@@ -303,7 +307,7 @@
303307 unsigned int i;
304308
305309 tLen = strlen( tripv );
306- if ( tLen < 7 ) {
310+ if ( tLen < MINLENPAD || tLen > TRIP_LEN ) {
307311 return;
308312 }
309313 if ( checkTrip( tripv, tLen ) != 0 ) {
@@ -351,211 +355,107 @@
351355
352356 static
353357 void
354-mkvarSub( org, lower, lead, upper, vtype )
355-unsigned char *org, *lower, *lead, *upper;
358+mkvarSub( org, vtype, nq )
359+unsigned char *org;
356360 enum types vtype;
361+unsigned int nq;
357362 {
358-#ifdef OLDDEBUG
359- printf( "mkvarSub : vtype = %d, org = <%s>, lower =<%s>, lead = <%s>, upper = <%s>\n",
360- vtype, org, lower, lead, upper );
361-#endif /* DEBUG */
363+ unsigned int i, j, k;
364+ unsigned char *pat[3];
365+ unsigned char work[30];
366+ unsigned char *workPtr;
362367
363- addTrip( org );
364- if ( vtype == CAPLEAD || vtype == CAP ) {
365- return;
368+/*
369+@ : CAP 大小固定
370+& : CAPLEAD 大小先頭固定
371+^ : LEAD 先頭固定
372+*/
373+ if ( vtype == LEAD || vtype == CAPLEAD ) {
374+ nq = 0;
366375 }
367- if ( strcmp( org, lower ) != 0 ) {
368- addTrip( lower );
376+
377+ for ( i = 0; i <= nq; i++ ) {
378+ workPtr = work;
379+ for ( j = 0; j < i; j++ ) {
380+ *workPtr = '?';
381+ workPtr++;
382+ }
383+ strcpy( workPtr, org );
384+ addTrip( work );
385+ if ( vtype != CAPLEAD && vtype != CAP ) {
386+ make3Pattern( work, pat );
387+ for ( k = 0; k < 3; k++ ) {
388+ if ( pat[k] != NULL ) {
389+ addTrip( pat[k] );
390+ }
391+ }
392+ }
369393 }
370- if ( strcmp( org, lead ) != 0 ) {
371- addTrip( lead );
372- }
373- if ( strcmp( org, upper ) != 0 ) {
374- addTrip( upper );
375- }
376394 }
377395
378396 static
379397 void
380-mkvarSub2( tmpTrip, lower, lead, upper, vtype, repeat )
381-unsigned char *tmpTrip, *lower, *lead, *upper;
398+mkvarSub2( org, vtype, pad )
399+unsigned char *org;
382400 enum types vtype;
383-int repeat;
401+unsigned int pad;
384402 {
385- unsigned int i, j;
386- unsigned char delm[3], delms[10];
387- unsigned char org[20], lower2[20], lead2[20], upper2[20];
403+ unsigned int i, j, len;
404+ unsigned char delm[3];
405+ unsigned char work[30];
406+ unsigned char *workPtr;
388407
389-#ifdef OLDDEBUG
390- printf( "mkvarSub2 : \n" );
391-#endif /* DEBUG */
392-
393408 delm[0] = '.';
394409 delm[1] = '/';
395410 delm[2] = '\0';
396411
412+ len = strlen( org );
413+ strcpy( work, org );
397414 for ( i = 0; delm[i] != '\0'; i++ ) {
398- for ( j = 0; j < repeat; j++ ) {
399- delms[j] = delm[i];
415+ workPtr = work + len;
416+ for ( j = 0; j < pad; j++ ) {
417+ *workPtr = delm[i];
418+ workPtr++;
400419 }
401- delms[j] = '\0';
402- sprintf( org, "%s%s", tmpTrip, delms );
403- sprintf( lower2, "%s%s", lower, delms );
404- sprintf( lead2, "%s%s", lead, delms );
405- sprintf( upper2, "%s%s", upper, delms );
406- mkvarSub( org, lower2, lead2, upper2, vtype );
407- if ( vtype != LEAD && vtype != CAPLEAD ) {
408- sprintf( org, "?%s%s", tmpTrip, delms );
409- sprintf( lower2, "?%s%s", lower, delms );
410- sprintf( lead2, "?%s%s", lead, delms );
411- sprintf( upper2, "?%s%s", upper, delms );
412- mkvarSub( org, lower2, lead2, upper2, vtype );
413- sprintf( org, "??%s%s", tmpTrip, delms );
414- sprintf( lower2, "??%s%s", lower, delms );
415- sprintf( lead2, "??%s%s", lead, delms );
416- sprintf( upper2, "??%s%s", upper, delms );
417- mkvarSub( org, lower2, lead2, upper2, vtype );
418- sprintf( org, "???%s%s", tmpTrip, delms );
419- sprintf( lower2, "???%s%s", lower, delms );
420- sprintf( lead2, "???%s%s", lead, delms );
421- sprintf( upper2, "???%s%s", upper, delms );
422- mkvarSub( org, lower2, lead2, upper2, vtype );
423- }
420+ *workPtr = '\0';
421+ mkvarSub( work, vtype, TRIP_LEN - len );
422+#ifdef OLDDEBUG
423+ printf( "mkvarSub2 : <%s>\n", work );
424+#endif /* DEBUG */
424425 }
425426 }
426427
427428 static
428429 void
429-mkvar( tmpTrip, tmpTripLen, vtype )
430-char *tmpTrip;
431-unsigned int tmpTripLen;
430+mkvar( tmpTrip, vtype )
431+unsigned char *tmpTrip;
432432 enum types vtype;
433433 {
434- unsigned int i;
435- unsigned char lower[20], lead[20], upper[20];
436- unsigned char org[20], lower2[20], lead2[20], upper2[20];
434+ unsigned int tmpTripLen;
437435
438- lower[0] = '\0';
439- lead[0] = '\0';
440- upper[0] = '\0';
441-
442- /* 全小文字に変換 */
443- for ( i = 0; tmpTrip[i] != '\0'; i++ ) {
444- if ( isupper( tmpTrip[i] ) ) {
445- lower[i] = tolower( tmpTrip[i] );
446- } else {
447- lower[i] = tmpTrip[i];
448- }
436+ tmpTripLen = strlen( tmpTrip );
437+ if ( tmpTripLen > TRIP_LEN ) {
438+ return;
449439 }
450- lower[i] = '\0';
451-
452- /* 先頭のみ大文字に変換 */
453- if ( islower( lower[0] ) ) {
454- lead[0] = toupper( lower[0] );
455- for ( i = 1; lower[i] != '\0'; i++ ) {
456- lead[i] = lower[i];
457- }
458- lead[i] = '\0';
440+ if ( tmpTripLen >= MINLENPAD ) {
441+ mkvarSub( tmpTrip, vtype, TRIP_LEN - tmpTripLen );
442+ return;
459443 }
460-
461- /* 全大文字に変換 */
462- for ( i = 0; tmpTrip[i] != '\0'; i++ ) {
463- if ( islower( lower[i] ) ) {
464- upper[i] = toupper( lower[i] );
465- } else {
466- upper[i] = lower[i];
467- }
444+ if ( tmpTripLen >= MINLENCUT ) {
445+ mkvarSub2( tmpTrip, vtype, MINLENPAD - tmpTripLen );
446+ return;
468447 }
469- upper[i] = '\0';
470- if ( strcmp( lower, upper ) == 0 || strcmp( lead, upper ) == 0 ) {
471- upper[0] = '\0';
472- }
473-
474-#ifdef OLDDEBUG
475- printf( "\norg = <%s:%d> %d ( 0:ALL, 1:CAP, 2:LEAD, 3:CAPLEAD )\n",
476- tmpTrip, strlen( tmpTrip ), vtype );
477- printf( "\norg = <%s> %d ( 0:ALL, 1:CAP, 2:LEAD, 3:CAPLEAD )\nlower = <%s>\nlead = <%s>\nupper = <%s>\n",
478- tmpTrip, vtype, lower, lead, upper );
479-#endif /* DEBUG */
480-
481- if ( tmpTripLen >= 7 ) {
482- }
483- switch ( tmpTripLen ) {
484- case 10:
485- mkvarSub( tmpTrip, lower, lead, upper, vtype );
486- if ( vtype != LEAD && vtype != CAPLEAD ) {
487- for ( i = 0; i < 10 - tmpTripLen; i++ ) {
488- }
489- }
490- break;
491- case 9:
492- mkvarSub( tmpTrip, lower, lead, upper, vtype );
493- if ( vtype != LEAD && vtype != CAPLEAD ) {
494- sprintf( org, "?%s", tmpTrip );
495- sprintf( lower2, "?%s", lower );
496- sprintf( lead2, "?%s", lead );
497- sprintf( upper2, "?%s", upper );
498- mkvarSub( org, lower2, lead2, upper2, vtype );
499- }
500- break;
501- case 8:
502- mkvarSub( tmpTrip, lower, lead, upper, vtype );
503- if ( vtype != LEAD && vtype != CAPLEAD ) {
504- sprintf( org, "?%s", tmpTrip );
505- sprintf( lower2, "?%s", lower );
506- sprintf( lead2, "?%s", lead );
507- sprintf( upper2, "?%s", upper );
508- mkvarSub( org, lower2, lead2, upper2, vtype );
509- sprintf( org, "??%s", tmpTrip );
510- sprintf( lower2, "??%s", lower );
511- sprintf( lead2, "??%s", lead );
512- sprintf( upper2, "??%s", upper );
513- mkvarSub( org, lower2, lead2, upper2, vtype );
514- }
515- break;
516- case 7:
517- mkvarSub( tmpTrip, lower, lead, upper, vtype );
518- if ( vtype != LEAD && vtype != CAPLEAD ) {
519- sprintf( org, "?%s", tmpTrip );
520- sprintf( lower2, "?%s", lower );
521- sprintf( lead2, "?%s", lead );
522- sprintf( upper2, "?%s", upper );
523- mkvarSub( org, lower2, lead2, upper2, vtype );
524- sprintf( org, "??%s", tmpTrip );
525- sprintf( lower2, "??%s", lower );
526- sprintf( lead2, "??%s", lead );
527- sprintf( upper2, "??%s", upper );
528- mkvarSub( org, lower2, lead2, upper2, vtype );
529- sprintf( org, "???%s", tmpTrip );
530- sprintf( lower2, "???%s", lower );
531- sprintf( lead2, "???%s", lead );
532- sprintf( upper2, "???%s", upper );
533- mkvarSub( org, lower2, lead2, upper2, vtype );
534- }
535- break;
536- case 6:
537- mkvarSub2( tmpTrip, lower, lead, upper, vtype, 1 );
538- break;
539- #ifdef NOTDEF
540- case 5:
541- mkvarSub2( tmpTrip, lower, lead, upper, vtype, 2 );
542- break;
543- case 4:
544- mkvarSub2( tmpTrip, lower, lead, upper, vtype, 3 );
545- break;
546- #endif /* NOTDEF */
547- }
548448 }
549449
550450 void
551451 readList()
552452 {
553- unsigned int tmpTripLen;
554453 unsigned int i;
555454 unsigned int lineNo;
556455 enum types vtype;
557456 FILE *tripFile;
558- char tmpTrip[LIST_LINE_LEN];
457+ unsigned char tmpTrip[LIST_LINE_LEN];
458+ unsigned char *tmpTripPtr;
559459
560460 for ( i = 0; i < NKIND; i++ ) {
561461 tripNum[i] = 0;
@@ -570,6 +470,7 @@
570470 lineNo = 0;
571471 while ( fgets( tmpTrip, LIST_LINE_LEN, tripFile ) != NULL ) {
572472 lineNo++;
473+ tmpTripPtr = tmpTrip;
573474 for ( i = 0; tmpTrip[i] != '\0'; i++ ) {
574475 if ( tmpTrip[i] == '\n' || tmpTrip[i] == '\r' ||
575476 tmpTrip[i] == ' ' || tmpTrip[i] == '\t' ) {
@@ -577,43 +478,42 @@
577478 break;
578479 }
579480 }
481+#ifdef OLDDEBUG
482+ printf( "readList : <%s>\n", tmpTrip );
483+#endif /* DEBUG */
580484 if ( tmpTrip[0] != '#' && tmpTrip[0] != '\0' ) {
581- tmpTripLen = strlen( tmpTrip );
582485 switch ( tmpTrip[0] ) {
583486 case '&' :
584487 vtype = CAPLEAD;
585- strcpy( tmpTrip, tmpTrip + 1 );
586- tmpTripLen--;
488+ tmpTripPtr++;
587489 break;
588490 case '@' :
589491 vtype = CAP;
590- strcpy( tmpTrip, tmpTrip + 1 );
591- tmpTripLen--;
492+ tmpTripPtr++;
592493 break;
593494 case '^' :
594495 vtype = LEAD;
595- strcpy( tmpTrip, tmpTrip + 1 );
596- tmpTripLen--;
496+ tmpTripPtr++;
597497 break;
598498 default :
599499 vtype = ALL;
600500 break;
601501 }
602- mkvar( tmpTrip, tmpTripLen, vtype );
502+ mkvar( tmpTripPtr, vtype );
603503 }
604504 }
505+ fclose( tripFile );
506+
605507 printf( "Pattern : %d\n", tripCount );
606508
607- fclose( tripFile );
608-
609- #ifdef DUMPPAT
509+#ifdef DUMPPAT
610510 exit( 0 );
611- #endif /* DUMPPAT */
511+#endif /* DUMPPAT */
612512
613- #ifdef DUMPTARGET
513+#ifdef DUMPTARGET
614514 dumpTargets();
615515 exit( 0 );
616- #endif /* DUMPTARGET */
516+#endif /* DUMPTARGET */
617517
618518 #ifdef HASHCHECK
619519 hashCheck();
旧リポジトリブラウザで表示