#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);
}
