| 1 |
/* |
| 2 |
** CharsetDecoder.m |
| 3 |
** |
| 4 |
** Copyright (c) 2001-2004 |
| 5 |
** |
| 6 |
** Author: Ludovic Marcotte <[email protected]> |
| 7 |
** |
| 8 |
** This program is free software; you can redistribute it and/or modify |
| 9 |
** it under the terms of the GNU General Public License as published by |
| 10 |
** the Free Software Foundation; either version 2 of the License, or |
| 11 |
** (at your option) any later version. |
| 12 |
** |
| 13 |
** This program is distributed in the hope that it will be useful, |
| 14 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
** GNU General Public License for more details. |
| 17 |
** |
| 18 |
** You should have received a copy of the GNU General Public License |
| 19 |
** along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#import "CharsetDecoder.h" |
| 23 |
|
| 24 |
@implementation CharsetDecoder |
| 25 |
@end |
| 26 |
|
| 27 |
int main(int argc, const char *argv[], char *env[]) |
| 28 |
{ |
| 29 |
CREATE_AUTORELEASE_POOL(pool); |
| 30 |
FILE *stream; |
| 31 |
char *aLine; |
| 32 |
char *basename,*c; |
| 33 |
char *charsetname; |
| 34 |
int i; |
| 35 |
|
| 36 |
int code; |
| 37 |
unichar value[2]; |
| 38 |
char buf[80]; |
| 39 |
|
| 40 |
if (argc != 2) |
| 41 |
{ |
| 42 |
printf("\nUsage: openapp CharsetDecoder.app filename.txt\n\n"); |
| 43 |
RELEASE(pool); |
| 44 |
exit(0); |
| 45 |
} |
| 46 |
|
| 47 |
basename=strdup(argv[1]); |
| 48 |
for (c=basename;*c!='.';c++) |
| 49 |
{ |
| 50 |
*c=toupper(*c); |
| 51 |
if (*c=='-') *c='_'; |
| 52 |
} |
| 53 |
*c=0; |
| 54 |
|
| 55 |
charsetname=strdup(argv[1]); |
| 56 |
*strchr(charsetname,'.')=0; |
| 57 |
if (!strncmp(charsetname,"iso",3)) |
| 58 |
{ |
| 59 |
memmove(&charsetname[4],&charsetname[3],strlen(charsetname)-3+1); |
| 60 |
charsetname[3]='-'; |
| 61 |
} |
| 62 |
|
| 63 |
aLine = (char*)malloc(sizeof(char)*1024); |
| 64 |
value[1] = 0; |
| 65 |
|
| 66 |
stream = fopen(argv[1], "r"); |
| 67 |
|
| 68 |
printf( |
| 69 |
"#include <Pantomime/%s.h>\n" /* basename */ |
| 70 |
"\n" |
| 71 |
"static struct charset_code code_table[]={", |
| 72 |
basename); |
| 73 |
|
| 74 |
i=0; |
| 75 |
while (fgets(aLine, 128, stream) != NULL) |
| 76 |
{ |
| 77 |
if (!i++) printf("\n"); |
| 78 |
if (i==5) i=0; |
| 79 |
sscanf(aLine, "=%02x\tU+%04x\t%s", &code, value, buf); |
| 80 |
printf("{0x%02x,0x%04x}, ",code,value[0]); |
| 81 |
} |
| 82 |
|
| 83 |
printf( |
| 84 |
"};\n" |
| 85 |
"\n" |
| 86 |
"@implementation %s\n" /* basename */ |
| 87 |
"\n" |
| 88 |
"- (id) init\n" |
| 89 |
"{\n" |
| 90 |
"\treturn [super initWithCodeCharTable: code_table length: sizeof(code_table)/sizeof(code_table[0])];\n" |
| 91 |
"}\n\n" |
| 92 |
"- (NSString *) name\n" |
| 93 |
"{\n" |
| 94 |
"\treturn @\"%s\";\n" /* charsetname */ |
| 95 |
"}\n" |
| 96 |
"\n" |
| 97 |
"@end\n" |
| 98 |
"\n",basename,charsetname); |
| 99 |
|
| 100 |
free(aLine); |
| 101 |
|
| 102 |
RELEASE(pool); |
| 103 |
exit(0); |
| 104 |
} |