chiark / gitweb /
WIP actual useful structure
[ypp-sc-tools.web-live.git] / pctb / convert.c
1
2 #include "convert.h"
3
4
5 void debug_flush(void) {
6   eassert(!fflush(debug));
7   eassert(!ferror(debug));
8 }
9
10
11 const char *get_vardir(void) { return "."; }
12
13
14 static enum { mode_all=03, mode_screenshot=01, mode_analyse=02 }
15     o_mode= mode_all;
16 static char *o_screenshots_fn;
17 static int o_single_page;
18
19 FILE *screenshots_file;
20
21 int main(int argc, char **argv) {
22   const char *arg;
23   int r;
24
25   while ((arg=*++argv)) {
26     if (!strcmp(arg,"--screenshots-only"))
27       o_mode= mode_screenshot;
28     else if (!strcmp(arg,"--analyse-only"))
29       o_mode= mode_analyse;
30     else if (!strcmp(arg,"--single-page"))
31       o_single_page= 1;
32     else if (!strcmp(arg,"--screenshots-file"))
33       eassert( o_screenshots_fn= *++argv );
34     else if (!strcmp(arg,"--window-id")) {
35       char *ep;
36       eassert((arg=*++argv));
37       unsigned long windowid= strtoul(arg,&ep,0);
38       eassert(!*ep);
39       set_yppclient_window(windowid);
40     } else
41       eassert(!"bad option");
42   }
43   
44   if (!o_screenshots_fn) {
45     r= asprintf(&o_screenshots_fn,"%s/#pages#.ppm",get_vardir());
46     eassert(r>=0);  eassert(o_screenshots_fn);
47   }
48
49   if (o_mode & mode_screenshot) {
50     screenshot_startup();
51     find_yppclient_window();
52     screenshots_file= fopen(o_screenshots_fn, "w"); eassert(screenshots_file);
53     if (o_single_page)
54       take_one_screenshot();
55     else
56       take_screenshots();
57   } else {
58     screenshots_file= fopen(o_screenshots_fn, "r"); eassert(screenshots_file);
59     read_screenshots();
60   }
61   if (o_mode & mode_analyse) {
62     analyse();
63     //output_tsv();
64   }
65   return 0;
66 }