598de7262a8814a41b5cabcfaec413044aecb27d
[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         Document doc;
6         srand(time(NULL));
7
8         enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
9         
10         Rect bounds(0,0,1,1);
11         Colour c(0,0,0,1);
12         const char * output_to_bmp = NULL;
13         const char * input_filename = NULL;
14
15         int i = 0;
16         while (++i < argc)
17         {
18                 if (argv[i][0] != '-')
19                 {
20                         input_filename = argv[i];
21                         continue;               
22                 }
23                 switch (argv[i][1])
24                 {
25                         case 'o':
26                                 mode = OUTPUT_TO_BMP;
27                                 if (++i >= argc)
28                                         Fatal("No argument following -o switch");
29                                 output_to_bmp = argv[i];
30                                 break;
31                         case 'c':
32                         {
33                                 Debug("Reading paint colour");
34                                 for (int j = 1; j <= 4; ++j)
35                                 {
36                                         if (i+j >= argc)
37                                                 Fatal("No %d colour component following -c switch", j);
38                                         char * e;
39                                         float * comp = (j == 1) ? (&c.r) : ((j == 2) ? (&c.g) : ((j == 3) ? (&c.b) : &(c.a)));
40                                         *comp = strtof(argv[i+j], &e);
41                                         if (*e != '\0')
42                                                 Fatal("Colour component %d not a valid float", j); 
43                                 }
44                                 i += 4;
45                                 break;
46                         }
47                 }       
48         }
49
50         if (input_filename != NULL)
51         {
52                 doc.Load(input_filename);
53         }
54         else
55         {
56                 doc.Add(RECT_FILLED, Rect(0.2,0.2,0.6,0.6));
57         }
58
59         if (mode == LOOP)
60                 MainLoop(doc, bounds, c);
61         else if (mode == OUTPUT_TO_BMP)
62                 OverlayBMP(doc, output_to_bmp, bounds, c);
63         return 0;
64 }

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