File: preproc.c

package info (click to toggle)
xpaint 2.9.1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,552 kB
  • sloc: ansic: 73,017; sh: 492; yacc: 247; lex: 126; sed: 43; makefile: 10
file content (68 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download | duplicates (9)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#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;
static char i18n_file[] = "share/messages/Messages";
static char i18n_version_string[] = "# XPaint Messages version ";

    fd = fopen(i18n_file, "r");
    if (!fd) {
       fprintf(stderr, "Cannot open language file %s !!\n", i18n_file);
       exit(-1);
    }

    /* get version string from first line */
    ptr = fgets(buf, 510, fd);
    l = strlen(i18n_version_string);
    if (strncmp(ptr, i18n_version_string, l)) {
       fprintf(stderr, "Language file %s does not begin with required version "
         "string !!\n", i18n_file);
       exit(-1);
    }
    ptr += l;
    l = strlen(ptr)-1;
    if (ptr[l]=='\n') {
       ptr[l] = '\0';
       --l;
    }
    while(l>=0 && isspace(ptr[l])) {
       ptr[l] = '\0';
       --l;
    }
    printf("#define MESSAGES_VERSION \"%s\"\n", ptr);

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