Allow setting type of Real at compilation time
[ipdf/code.git] / src / main.cpp
1 #include "main.h"
2 #include <unistd.h> // Because we can.
3 int main(int argc, char ** argv)
4 {       
5         Debug("Compiled with REAL = %d => \"%s\"", REAL, g_real_name[REAL]);
6
7         Document doc;
8         srand(time(NULL));
9
10         enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
11         
12         
13         Colour c(0,0,0,1);
14         const char * input_bmp = NULL;
15         const char * output_bmp = NULL;
16         const char * input_filename = NULL;
17         float b[4] = {0,0,1,1};
18
19         int i = 0;
20         while (++i < argc)
21         {
22                 if (argv[i][0] != '-')
23                 {
24                         input_filename = argv[i];
25                         continue;               
26                 }
27                 switch (argv[i][1])
28                 {
29                         case 'o':
30                                 mode = OUTPUT_TO_BMP;
31                                 if (++i >= argc)
32                                         Fatal("No input argument following -o switch");
33                                 input_bmp = argv[i];
34                                 if (++i >= argc)
35                                         Fatal("No output argument following -o switch");
36                                 output_bmp = argv[i];
37
38                                 break;
39                         case 'c':
40                         {
41                                 Debug("Reading paint colour");
42                                 for (int j = 1; j <= 4; ++j)
43                                 {
44                                         if (i+j >= argc)
45                                                 Fatal("No %d colour component following -c switch", j);
46                                         char * e;
47                                         float * comp = (j == 1) ? (&c.r) : ((j == 2) ? (&c.g) : ((j == 3) ? (&c.b) : &(c.a)));
48                                         *comp = strtof(argv[i+j], &e);
49                                         if (*e != '\0')
50                                                 Fatal("Colour component %d not a valid float", j); 
51                                 }
52                                 i += 4;
53                                 break;
54                         }
55                         case 'b':
56                         {
57                                 Debug("Reading view bounds");
58                                 for (int j = 1; j <= 4; ++j)
59                                 {
60                                         if (i+j >= argc)
61                                                 Fatal("No %d bounds component following -b switch", j);
62                                         char * e;
63                                         b[j-1] = strtof(argv[i+j], &e);
64                                         if (*e != '\0')
65                                                 Fatal("Bounds component %d not a valid float", j); 
66                                 }
67                                 i += 4;
68                                 break;
69                         }
70                 }       
71         }
72
73         if (input_filename != NULL)
74         {
75                 doc.Load(input_filename);
76         }
77         else 
78         {
79                 doc.Add(RECT_OUTLINE, Rect(0.5,0.5,1,1));
80         }
81         Rect bounds(b[0],b[1],b[2],b[3]);
82
83         if (mode == LOOP)
84                 MainLoop(doc, bounds, c);
85         else if (mode == OUTPUT_TO_BMP)
86                 OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
87         return 0;
88 }

UCC git Repository :: git.ucc.asn.au