Browse Subversion Repository
Contents of /trunk/triplib/triplib.c
Parent Directory
| Revision Log
Revision 228 -
( show annotations)
( download)
( as text)
Fri Aug 7 10:16:11 2009 UTC
(14 years, 9 months ago)
by notanpe
File MIME type: text/x-csrc
File size: 9543 byte(s)
SHA-1 新方式への対応
| 1 |
#include <stdio.h> |
| 2 |
|
| 3 |
#ifdef __MINGW32__ |
| 4 |
#include <windows.h> |
| 5 |
#endif /* __MINGW32__ */ |
| 6 |
|
| 7 |
#include "triplib.h" |
| 8 |
|
| 9 |
/* トリップとして有効な文字 ? */ |
| 10 |
int istrip[] = { |
| 11 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 14 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 15 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 16 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, |
| 17 |
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 18 |
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 19 |
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 20 |
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 21 |
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 22 |
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 23 |
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 24 |
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 25 |
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 26 |
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 27 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 28 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 29 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 30 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 31 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 32 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 33 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 34 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 35 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 36 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 37 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 38 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 39 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 40 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 41 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 42 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 43 |
}; |
| 44 |
|
| 45 |
/* トリップの末尾文字として有効な文字 ? */ |
| 46 |
int istail[] = { |
| 47 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 48 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 49 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 50 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 51 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 52 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 53 |
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 54 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 55 |
0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 56 |
0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 57 |
0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 58 |
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 59 |
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, |
| 60 |
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, |
| 61 |
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, |
| 62 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 63 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 64 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 65 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 66 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 67 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 68 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 69 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 70 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 71 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 72 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 73 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 74 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 75 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 76 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 77 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 78 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 79 |
}; |
| 80 |
|
| 81 |
/* トリップの末尾文字として有効な文字 ? ignore case */ |
| 82 |
int istailic[] = { |
| 83 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 84 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 85 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 86 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 87 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 88 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 89 |
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 90 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 91 |
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, |
| 92 |
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, |
| 93 |
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, |
| 94 |
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 95 |
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, |
| 96 |
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, |
| 97 |
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, |
| 98 |
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 99 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 100 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 101 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 102 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 103 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 104 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 105 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 106 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 107 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 108 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 109 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 110 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 111 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 112 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 113 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 114 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 115 |
}; |
| 116 |
|
| 117 |
unsigned char saltTable[] = |
| 118 |
"................" /* 0x00 - 0x0f */ |
| 119 |
"................" /* 0x10 - 0x1f */ |
| 120 |
".............../" /* 0x20 - 0x2f !"#$%&'()*+,-./ */ |
| 121 |
"0123456789ABCDEF" /* 0x30 - 0x3f 0123456789:;<=>? */ |
| 122 |
"GABCDEFGHIJKLMNO" /* 0x40 - 0x4f @ABCDEFGHIJKLMNO */ |
| 123 |
"PQRSTUVWXYZabcde" /* 0x50 - 0x5f PQRSTUVWXYZ[\]^_ */ |
| 124 |
"fabcdefghijklmno" /* 0x60 - 0x6f `abcdefghijklmno */ |
| 125 |
"pqrstuvwxyz....." /* 0x70 - 0x7f pqrstuvwxyz{|}~ */ |
| 126 |
"................" /* 0x80 - 0x8f */ |
| 127 |
"................" /* 0x90 - 0x9f */ |
| 128 |
"................" /* 0xa0 - 0xaf 。「」、・ヲァィゥェォャュョッ */ |
| 129 |
"................" /* 0xb0 - 0xbf ーアイウエオカキクケコサシスセソ */ |
| 130 |
"................" /* 0xc0 - 0xcf タチツテトナニヌネノハヒフヘホマ */ |
| 131 |
"................" /* 0xd0 - 0xdf ミムメモヤユヨラリルレロワン゙゚ */ |
| 132 |
"................" /* 0xe0 - 0xef */ |
| 133 |
"................" /* 0xf0 - 0xff */ |
| 134 |
; |
| 135 |
|
| 136 |
static unsigned char *toAllLower( unsigned char * ); |
| 137 |
static unsigned char *toAllUpper( unsigned char * ); |
| 138 |
static unsigned char *toHeadUpper( unsigned char * ); |
| 139 |
static unsigned char *toTailUpper( unsigned char * ); |
| 140 |
|
| 141 |
#ifdef __MINGW32__ |
| 142 |
void |
| 143 |
setPriority( priority ) |
| 144 |
int priority; |
| 145 |
{ |
| 146 |
DWORD prioClass; |
| 147 |
|
| 148 |
switch ( priority ) { |
| 149 |
case PRIO_REAL: prioClass = REALTIME_PRIORITY_CLASS; break; |
| 150 |
case PRIO_HIGH: prioClass = HIGH_PRIORITY_CLASS; break; |
| 151 |
case PRIO_ABOVE: prioClass = ABOVE_NORMAL_PRIORITY_CLASS; break; |
| 152 |
case PRIO_NORM: prioClass = NORMAL_PRIORITY_CLASS; break; |
| 153 |
case PRIO_BELOW: prioClass = BELOW_NORMAL_PRIORITY_CLASS; break; |
| 154 |
case PRIO_IDLE: prioClass = IDLE_PRIORITY_CLASS; break; |
| 155 |
default: |
| 156 |
fprintf( stderr, "優先度がおかしいよ。\n" ); |
| 157 |
exit( 1 ); |
| 158 |
} |
| 159 |
SetPriorityClass( GetCurrentProcess(), prioClass ); |
| 160 |
} |
| 161 |
#endif /* __MINGW32__ */ |
| 162 |
|
| 163 |
/* 末尾の改行を削除して、文字列長を返す */ |
| 164 |
int |
| 165 |
delCr( line ) |
| 166 |
unsigned char *line; |
| 167 |
{ |
| 168 |
int lineLen; |
| 169 |
|
| 170 |
lineLen = strlen( line ); |
| 171 |
if ( lineLen >= 2 ) { |
| 172 |
if ( line[lineLen - 2] == 0x0d ) { |
| 173 |
lineLen -= 2; |
| 174 |
line[lineLen] = '\0'; |
| 175 |
} |
| 176 |
} |
| 177 |
if ( lineLen >= 1 ) { |
| 178 |
if ( line[lineLen - 1] == 0x0a ) { |
| 179 |
lineLen--; |
| 180 |
line[lineLen] = '\0'; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
return( lineLen ); |
| 185 |
} |
| 186 |
|
| 187 |
/* + 展開 */ |
| 188 |
void |
| 189 |
make3Pattern( org, pat ) |
| 190 |
unsigned char *org; |
| 191 |
unsigned char *pat[3]; |
| 192 |
{ |
| 193 |
pat[0] = toAllLower( org ); |
| 194 |
pat[1] = toHeadUpper( org ); |
| 195 |
pat[2] = toAllUpper( org ); |
| 196 |
} |
| 197 |
|
| 198 |
/* + 展開 (逆読み) */ |
| 199 |
void |
| 200 |
make3PatternR( org, pat ) |
| 201 |
unsigned char *org; |
| 202 |
unsigned char *pat[3]; |
| 203 |
{ |
| 204 |
pat[0] = toAllLower( org ); |
| 205 |
pat[1] = toTailUpper( org ); |
| 206 |
pat[2] = toAllUpper( org ); |
| 207 |
#ifdef OLDDEBUG |
| 208 |
printf( "make3PatternR <%s>\n", pat[1] ); |
| 209 |
#endif /* DEBUG */ |
| 210 |
} |
| 211 |
|
| 212 |
/* アルファベットを全て小文字に */ |
| 213 |
static |
| 214 |
unsigned char * |
| 215 |
toAllLower( string ) |
| 216 |
unsigned char *string; |
| 217 |
{ |
| 218 |
static unsigned char allLower[EXP_BUF_LEN]; |
| 219 |
int i; |
| 220 |
|
| 221 |
for ( i = 0; string[i] != '\0'; i++ ) { |
| 222 |
allLower[i] = tolower( string[i] ); |
| 223 |
} |
| 224 |
allLower[i] = '\0'; |
| 225 |
if ( strcmp( string, allLower ) == 0 ) { |
| 226 |
return( NULL ); |
| 227 |
} else { |
| 228 |
return( allLower ); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
/* アルファベットを全て大文字に */ |
| 233 |
static |
| 234 |
unsigned char * |
| 235 |
toAllUpper( string ) |
| 236 |
unsigned char *string; |
| 237 |
{ |
| 238 |
static unsigned char allUpper[EXP_BUF_LEN]; |
| 239 |
int i; |
| 240 |
|
| 241 |
for ( i = 0; string[i] != '\0'; i++ ) { |
| 242 |
allUpper[i] = toupper( string[i] ); |
| 243 |
} |
| 244 |
allUpper[i] = '\0'; |
| 245 |
if ( strcmp( string, allUpper ) == 0 ) { |
| 246 |
return( NULL ); |
| 247 |
} else { |
| 248 |
return( allUpper ); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
/* 最初のアルファベットだけ大文字 */ |
| 253 |
static |
| 254 |
unsigned char * |
| 255 |
toHeadUpper( string ) |
| 256 |
unsigned char *string; |
| 257 |
{ |
| 258 |
static unsigned char headUpper[EXP_BUF_LEN]; |
| 259 |
int i; |
| 260 |
|
| 261 |
for ( i = 0; string[i] != '\0'; i++ ) { |
| 262 |
if ( isalpha( string[i] ) ) { |
| 263 |
headUpper[i] = toupper( string[i] ); |
| 264 |
i++; |
| 265 |
break; |
| 266 |
} else { |
| 267 |
headUpper[i] = string[i]; |
| 268 |
} |
| 269 |
} |
| 270 |
for ( ; string[i] != '\0'; i++ ) { |
| 271 |
headUpper[i] = tolower( string[i] ); |
| 272 |
} |
| 273 |
headUpper[i] = '\0'; |
| 274 |
if ( strcmp( string, headUpper ) == 0 ) { |
| 275 |
return( NULL ); |
| 276 |
} else { |
| 277 |
return( headUpper ); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
/* 最後のアルファベットだけ大文字 */ |
| 282 |
static |
| 283 |
unsigned char * |
| 284 |
toTailUpper( string ) |
| 285 |
unsigned char *string; |
| 286 |
{ |
| 287 |
static unsigned char tailUpper[EXP_BUF_LEN]; |
| 288 |
int i, strLen; |
| 289 |
|
| 290 |
strLen = strlen( string ); |
| 291 |
tailUpper[strLen] = '\0'; |
| 292 |
for ( i = strLen - 1; i >= 0; i-- ) { |
| 293 |
if ( isalpha( string[i] ) ) { |
| 294 |
tailUpper[i] = toupper( string[i] ); |
| 295 |
i--; |
| 296 |
break; |
| 297 |
} else { |
| 298 |
tailUpper[i] = string[i]; |
| 299 |
} |
| 300 |
} |
| 301 |
for ( ; i >= 0; i-- ) { |
| 302 |
tailUpper[i] = tolower( string[i] ); |
| 303 |
} |
| 304 |
if ( strcmp( string, tailUpper ) == 0 ) { |
| 305 |
return( NULL ); |
| 306 |
} else { |
| 307 |
return( tailUpper ); |
| 308 |
} |
| 309 |
} |
Properties
| svn:eol-style |
native
|
| svn:keywords |
Author Date Id Rev URL
|
| |