chiark / gitweb /
b44c294bd212a7072afa7ffabee6905350d10223
[ypp-sc-tools.db-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 {
15   mf_findwindow=    01,
16   mf_screenshot=    02,
17   mf_analyse=       04,
18   
19   mode_findwindow=  01,
20   mode_screenshot=  03,
21   mode_analyse=     04,
22
23   mode_all=         07,
24 } o_mode= mode_all;
25
26 static char *o_screenshots_fn;
27 static int o_single_page;
28
29 FILE *screenshots_file;
30
31 int main(int argc, char **argv) {
32   const char *arg;
33   int r;
34
35   while ((arg=*++argv)) {
36     if (!strcmp(arg,"--find-window-only"))
37       o_mode= mode_findwindow;
38     else if (!strcmp(arg,"--screenshot-only"))
39       o_mode= mode_screenshot;
40     else if (!strcmp(arg,"--analyse-only"))
41       o_mode= mode_analyse;
42     else if (!strcmp(arg,"--single-page"))
43       o_single_page= 1;
44     else if (!strcmp(arg,"--screenshots-file"))
45       eassert( o_screenshots_fn= *++argv );
46 #define DF(f)                                   \
47     else if (!strcmp(arg,"-D" #f))              \
48       debug_flags |= dbg_##f;
49     DEBUG_FLAG_LIST
50 #undef DF
51     else if (!strcmp(arg,"--window-id")) {
52       char *ep;
53       eassert((arg=*++argv));
54       unsigned long windowid= strtoul(arg,&ep,0);
55       eassert(!*ep);
56       set_yppclient_window(windowid);
57     } else
58       eassert(!"bad option");
59   }
60   
61   if (!o_screenshots_fn) {
62     r= asprintf(&o_screenshots_fn,"%s/#pages#.ppm",get_vardir());
63     eassert(r>=0);  eassert(o_screenshots_fn);
64   }
65
66   if (o_mode & mf_findwindow) {
67     screenshot_startup();
68     find_yppclient_window();
69   }
70   if (o_mode & mf_screenshot) {
71     screenshots_file= fopen(o_screenshots_fn, "w"); eassert(screenshots_file);
72     if (o_single_page)
73       take_one_screenshot();
74     else
75       take_screenshots();
76   } else {
77     screenshots_file= fopen(o_screenshots_fn, "r"); eassert(screenshots_file);
78     read_screenshots();
79   }
80   if (o_mode & mf_analyse) {
81     analyse();
82     //output_tsv();
83   }
84   return 0;
85 }