1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
FILE *fd;
char *ptr;
char buf[512];
int num, i, l;
char i18n_file[] = "share/messages/Messages";
fd = fopen(i18n_file, "r");
if (!fd) {
fprintf(stderr, "Cannot open language file %s !!\n", i18n_file);
exit(-1);
}
num = 0;
while ((ptr = fgets(buf, 510, fd))) {
l = strlen(ptr)-1;
if (ptr[l]=='\n') {
ptr[l] = '\0';
--l;
}
while(l>=0 && isspace(ptr[l])) {
ptr[l] = '\0';
--l;
}
if (l<0) continue;
if (*ptr=='#') {
for (i=0; i<=l; i++) {
if (isspace(ptr[i])) {
ptr[i] = '\0';
break;
}
}
printf("#define %s %d\n", ptr+1, num);
} else
++num;
if (!strncmp(ptr, "#END_OF_I18N_FILE", 17)) break;
}
fclose(fd);
printf("\nextern String *msgText;\nextern int msgNum;\n");
exit(0);
}
|