5 void debug_flush(void) {
6 eassert(!fflush(debug));
7 eassert(!ferror(debug));
11 const char *get_vardir(void) { return "."; }
25 static char *o_screenshots_fn;
26 static int o_single_page, o_quiet;
28 FILE *screenshots_file;
30 int main(int argc, char **argv) {
34 while ((arg=*++argv)) {
35 if (!strcmp(arg,"--find-window-only"))
36 o_mode= mode_findwindow;
37 else if (!strcmp(arg,"--screenshot-only"))
38 o_mode= mode_screenshot;
39 else if (!strcmp(arg,"--analyse-only"))
41 else if (!strcmp(arg,"--single-page"))
43 else if (!strcmp(arg,"--quiet"))
45 else if (!strcmp(arg,"--screenshots-file"))
46 eassert( o_screenshots_fn= *++argv );
48 else if (!strcmp(arg,"-D" #f)) \
49 debug_flags |= dbg_##f;
52 else if (!strcmp(arg,"--window-id")) {
54 eassert((arg=*++argv));
55 unsigned long windowid= strtoul(arg,&ep,0);
57 set_yppclient_window(windowid);
59 eassert(!"bad option");
62 if (!o_screenshots_fn) {
63 r= asprintf(&o_screenshots_fn,"%s/#pages#.ppm",get_vardir());
64 eassert(r>=0); eassert(o_screenshots_fn);
67 if (o_mode & mf_findwindow) {
69 find_yppclient_window();
71 if (o_mode & mf_screenshot) {
72 screenshots_file= fopen(o_screenshots_fn, "w"); eassert(screenshots_file);
74 take_one_screenshot();
78 screenshots_file= fopen(o_screenshots_fn, "r"); eassert(screenshots_file);
81 if (o_mode & mf_analyse) {
91 DEFINE_VWRAPPERF(, progress)
92 DEFINE_VWRAPPERF(, progress_log)
94 static int last_progress_len;
96 void vprogress(const char *fmt, va_list al) {
100 if (!isatty(2)) return;
102 if (last_progress_len)
105 r= vfprintf(stderr,fmt,al);
108 if (r < last_progress_len) {
109 fprintf(stderr,"%*s", last_progress_len - r, "");
110 if (!r) putc('\r', stderr);
111 else while (last_progress_len-- > r) putc('\b',stderr);
113 last_progress_len= r;
117 void vprogress_log(const char *fmt, va_list al) {
121 vfprintf(stderr,fmt,al);