Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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