]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/nls/parsecode.c
Initial revision
[netatalk.git] / etc / afpd / nls / parsecode.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5
6 #include <netatalk/endian.h>
7 #include "codepage.h"
8
9 int main(int argc, char **argv)
10 {
11   unsigned char name[255 + 1], buf[CODEPAGE_FILE_HEADER_SIZE];
12   unsigned char quantum, rules;
13   u_int16_t id;
14   FILE *fp;
15
16   if (argc != 2) {
17     fprintf(stderr, "%s <codepage>\n", *argv);
18     return -1;
19   }
20     
21   if ((fp = fopen(argv[1], "r")) == NULL) {
22     fprintf(stderr, "%s: can't open file.\n", *argv);
23     return -1;
24   }
25
26   if (fread(buf, CODEPAGE_FILE_HEADER_SIZE, 1, fp) != 1) {
27     fprintf(stderr, "%s: can't get header.\n", *argv);
28     goto fail_end;
29   }
30
31   /* id */
32   memcpy(&id, buf, sizeof(id));
33   id = ntohs(id);
34   if (id != CODEPAGE_FILE_ID) {
35     fprintf(stderr, "%s: wrong file type.\n", *argv);
36     goto fail_end;
37   }
38
39   /* version */
40   if (*(buf + 2) != CODEPAGE_FILE_VERSION) {
41     fprintf(stderr, "%s: wrong file version.\n", *argv);
42     goto fail_end;
43   }
44     
45   /* size of name */
46   id = *(buf + 3);
47
48   /* quantum and rules */
49   quantum = *(buf + 4);
50   rules = *(buf + 5);
51
52   fread(name, id, 1, fp);
53   if (name[id - 1] != '\0') /* name isn't null-padded */
54     name[id] = '\0';
55   printf("codepage: %s [", name);
56
57   /* move to the data */
58   memcpy(&id, buf + 6, sizeof(id));
59   id = ntohs(id);
60   fseek(fp, id, SEEK_SET);
61
62   /* size of data */
63   memcpy(&id, buf + 8, sizeof(id));
64   id = ntohs(id);
65   printf("size=%d]\n", id);
66   printf("---------\n");
67
68   while (fread(buf, 1 + 2*quantum, 1, fp) == 1) {
69     printf("0x%02x: 0x%02X 0x%02X\n", buf[0], buf[1], buf[1 + quantum]);
70   }
71   fclose(fp);
72   return 0;
73
74 fail_end:
75   fclose(fp);
76   return -1;
77 }