Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/mty-makai/special.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 260 - (hide annotations) (download) (as text)
Wed Jan 12 09:00:49 2011 UTC (13 years, 3 months ago) by notanpe
File MIME type: text/x-csrc
File size: 6057 byte(s)
特殊検索を実装。
gettid() をちょっとマシにした。
1 notanpe 260 #include <stdio.h>
2     #include <stdlib.h>
3     #include <string.h>
4    
5     #include "special.h"
6     #include "util.h"
7    
8     #define TRIP_LEN 10
9    
10     #define ST_ALLN 1 /* 全数 */
11     #define ST_NIKO 1<<0x1 /* 二構 */
12     #define ST_BUOO 1<<0x8 /* ぶお */
13     #define ST_DOSU 1<<0x9 /* 怒数 */
14     #define ST_CHIN 1<<0xb /* ちん */
15     #define ST_EROI 1<<0xc /* エロ */
16     #define ST_HREN 1<<0xd /* 飛連 */
17     #define ST_YAKU 1<<0xe /* 八雲 */
18    
19     int special;
20    
21     static FILE *nfp; /* 全数 */
22     #define LOGNUM "lognum.txt"
23     static FILE *cfp; /* ち */
24     #define LOGCHI "logchi.txt"
25     static FILE *tfp; /* ↑以外の特殊検索 */
26     #define LOGSPE "logspe.txt"
27    
28     void
29     dispSpecial()
30     {
31     printf( "特殊検索オプション : " );
32     if ( special & ST_DOSU ) {
33     printf( "怒数 " );
34     } else {
35     if ( special & ST_ALLN ) {
36     printf( "全数 " );
37     }
38     }
39     if ( special & ST_EROI ) {
40     printf( "エロ " );
41     }
42     if ( special & ST_NIKO ) {
43     printf( "二構 " );
44     }
45     if ( special & ST_BUOO ) {
46     printf( "ぶお " );
47     }
48     if ( special & ST_CHIN ) {
49     printf( "ちん " );
50     }
51     if ( special & ST_HREN ) {
52     printf( "飛連 " );
53     }
54     if ( special & ST_YAKU ) {
55     printf( "八雲 " );
56     }
57     if ( special ) {
58     printf( "オン!\n" );
59     } else {
60     printf( "オールオフ!\n" );
61     }
62     }
63    
64     void
65     initSpecial()
66     {
67     special = 0;
68    
69     if ( (tfp = fopen( LOGSPE, "at" )) == NULL ) {
70     perror( LOGSPE );
71     exit( 1 );
72     }
73     setvbuf( tfp, NULL, _IONBF, BUFSIZ );
74    
75     if ( (nfp = fopen( LOGNUM, "at" )) == NULL ) {
76     perror( LOGNUM );
77     exit( 1 );
78     }
79     setvbuf( nfp, NULL, _IONBF, BUFSIZ );
80    
81     if ( (cfp = fopen( LOGCHI, "at" )) == NULL ) {
82     perror( LOGCHI );
83     exit( 1 );
84     }
85     setvbuf( cfp, NULL, _IONBF, BUFSIZ );
86     }
87    
88     void
89     comment( str )
90     char *str;
91     {
92     if ( strlen( str ) >= 4 ) {
93     if ( str[1] == '[' && str[3] == ']' ) {
94     switch ( str[2] ) {
95     case '0': special |= ST_ALLN; break;
96     case '1': special |= ST_NIKO; break;
97     case '8': special |= ST_BUOO; break;
98     case '9': special |= (ST_DOSU | ST_ALLN); break;
99     case 'd': special |= ST_HREN; break;
100     case 'e': special |= ST_YAKU; break;
101     case 'Y': special |= ST_CHIN; break;
102     case 'Z': special |= ST_EROI; break;
103     #if 0
104     #ifdef KEYLOG
105     case 'K': keyLog = MAKAI_TRUE; break;
106     #endif /* KEYLOG */
107     case 'S':
108     seedOffset = atoi( str + 4 );
109     if ( seedOffset < MIN_SOFF || seedOffset > MAX_SOFF ) {
110     fprintf( stderr, "乱数の種のオフセットは、%d 以上 %d 以下で指定してね。\n", MIN_SOFF, MAX_SOFF );
111     fprintf( stderr, "%d は範囲外なので無視します。\n", seedOffset );
112     seedOffset = 0;
113     }
114     break;
115     #endif /* 0 */
116     }
117     }
118     }
119     }
120    
121     /* ヒット時には出力ファイルへのポインタを返す */
122     FILE *
123     checkSpecial( trip, kind )
124     char *trip;
125     unsigned char *kind;
126     {
127     OLDPRINT( "trip %s\n", trip );
128    
129     if ( special & ST_CHIN ) {
130     /* ^Chi(r */
131     if ( trip[0] == 'C' && trip[1] == 'h' && trip[2] == 'i' &&
132     trip[3] == 'n' && trip[4] == 'k' && trip[5] == 'o' ) {
133     strcpy( kind, "ち" );
134     return( cfp );
135     }
136     }
137    
138     if ( special & ST_BUOO ) {
139     /* ぶお [A-Za-z]aoo[A-Za-z]uoo$ */
140     if ( trip[3] == 'a' && trip[4] == 'o' && trip[5] == 'o' &&
141     trip[7] == 'u' && trip[8] == 'o' && trip[9] == 'o' &&
142     isalpha( trip[2] ) && isalpha( trip[6] ) ) {
143     strcpy( kind, "ぶ" );
144     return( tfp );
145     }
146     }
147    
148     if ( special & ST_EROI ) {
149     int i;
150     /* エロい人型二構 その 1 looooloooo */
151     if ( trip[0] == trip[5] &&
152     trip[1] == trip[2] && trip[1] == trip[3] && trip[1] == trip[4] &&
153     trip[1] == trip[6] && trip[1] == trip[7] && trip[1] == trip[8] &&
154     trip[1] == trip[9] ) {
155     strcpy( kind, "エ" );
156     return( tfp );
157     }
158     /* エロい人型二構 その 2 [./] */
159     for ( i = 0; i < TRIP_LEN; i++ ) {
160     if ( trip[i] != '.' && trip[i] != '/' ) {
161     goto NOEROI;
162     }
163     }
164     strcpy( kind, "エ" );
165     return( tfp );
166     }
167     NOEROI:
168    
169     if ( special & ST_NIKO ) {
170     /* 二構 */
171     int i;
172     char ch1, ch2;
173     ch1 = trip[0];
174     for ( i = 1; i < TRIP_LEN; i++ ) {
175     if ( trip[i] != ch1 ) break;
176     }
177     ch2 = trip[i];
178     for ( ; i < TRIP_LEN; i++ ) {
179     if ( trip[i] != ch1 && trip[i] != ch2 ) goto NONIKO;
180     }
181     strcpy( kind, "二" );
182     return( tfp );
183     }
184     NONIKO:
185    
186     if ( special & ST_YAKU ) {
187     /* 八雲 */
188     if ( trip[0] == trip[1] && trip[0] == trip[2] &&
189     trip[3] == trip[4] && trip[3] == trip[5] &&
190     trip[6] == trip[7] && trip[6] == trip[8] && trip[9] == '.' ) {
191     strcpy( kind, "八" );
192     return( tfp );
193     }
194     }
195    
196     /* 飛連関連のコードは、セロリン ◆Celeron/rc 作 */
197     if ( special & ST_HREN ) {
198     /* 飛連 */
199     int w, x = 0, y = 0;
200     for ( w = 0; w < TRIP_LEN; w++ ) {
201     if ( trip[w] == trip[0] ) x += 1;
202     if ( trip[w] == trip[1] ) y += 1;
203     if ( x >= 8 || y >= 8 ) {
204     strcpy( kind, "飛" );
205     return( tfp );
206     }
207     }
208     }
209    
210     if ( special & ST_ALLN ) {
211     /* 全数 か 怒数 */
212     if ( isdigit( trip[0] ) && isdigit( trip[1] ) && isdigit( trip[2] ) &&
213     isdigit( trip[3] ) && isdigit( trip[4] ) && isdigit( trip[5] ) &&
214     isdigit( trip[6] ) && isdigit( trip[7] ) && isdigit( trip[8] ) &&
215     isdigit( trip[9] ) ) {
216     if ( special & ST_DOSU ) {
217     /* 全数 & 回文 */
218     if ( trip[0] == trip[9] && trip[1] == trip[8] && trip[2] == trip[7] &&
219     trip[3] == trip[6] && trip[4] == trip[5] ) {
220     strcpy( kind, "怒" );
221     return( tfp );
222     }
223     /* 全数 & 双連 */
224     if ( trip[0] == trip[1] && trip[2] == trip[3] && trip[4] == trip[5] &&
225     trip[6] == trip[7] && trip[8] == trip[9] ) {
226     strcpy( kind, "怒" );
227     return( tfp );
228     }
229     /* 全数 & 山彦 */
230     if ( trip[0] == trip[5] && trip[1] == trip[6] && trip[2] == trip[7] &&
231     trip[3] == trip[8] && trip[4] == trip[9] ) {
232     strcpy( kind, "怒" );
233     return( tfp );
234     }
235     /* 最大と最小は、純 8 連で出るので削除 */
236     } else {
237     strcpy( kind, "数" );
238     return( nfp );
239     }
240     }
241     }
242    
243     return( NULL );
244     }

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