Remove usage of argv[0]
[pal.git] / main.c
1 #include <stdio.h>
2
3 #include "pal.h"
4
5
6 int main(int argc, char ** argv)
7 {
8         FILE * in = NULL;
9         struct pal pallete;
10         struct pal_optional optional;
11         int error = 0;
12         int i = 0;
13
14         if (argc <= 1) {
15                 puts("Fallout 1 PAL reader");
16                 printf("\n\tUsage: ./pal INPUT\n\n");
17                 return 0;
18         }
19         
20         in = fopen(argv[1], "rb");
21         
22         if (pal_read(in, &pallete)) {
23                 perror("Error when reading PAL data");
24                 return 1;
25         }
26         
27         for (i = 0; i < 256; i++) {
28                 printf("%d) R: %d, G: %d, B: %d\n",
29                         i,
30                         pallete.colors[i].r,
31                         pallete.colors[i].g,
32                         pallete.colors[i].b
33                 );
34         }
35         for (i = 0; i < 32768; i++) {
36                 printf("%d) ELEMENT: %d\n",
37                         i,
38                         pallete.element[i]
39                 );
40         }
41         
42         if ((error = pal_read_optional(in, &optional)) == PAL_READ_OK) {
43                 int t;
44                 for (t = 0; t < 3; t++) {
45                         for (i = 0; i < 65536; i++) {
46                                 printf("%d) table1: %d\n", i, optional.table[t][i]);
47                         }
48                 }
49         }
50         else if (error == PAL_READ_ERROR) {
51                 perror("Errors when reading PAL file");
52         }
53         else if (error == PAL_READ_NOOPT) {
54                 printf("File does not contain optional data\n");
55         }
56         
57         fclose(in);
58
59         return 0;
60 }