chiark / gitweb /
New --show-charset mode
[ypp-sc-tools.web-live.git] / pctb / convert.c
index 433b043a3dadd5a043f7f9087733c21262e12160..61901a5924854c967d9fc981a63406d6af89f66d 100644 (file)
@@ -37,16 +37,18 @@ const char *get_libdir(void) { return "."; }
 
 
 enum mode {
-  mf_findwindow=      0001,
-  mf_screenshot=      0010,
-  mf_readscreenshot=  0020,
-  mf_analyse=         0100,
+  mf_findwindow=      00001,
+  mf_screenshot=      00010,
+  mf_readscreenshot=  00020,
+  mf_analyse=         00100,
+  mfm_special=        07000,
   
-  mode_findwindow=    0001,
-  mode_screenshot=    0011,
-  mode_analyse=       0120,
+  mode_findwindow=    00001,
+  mode_screenshot=    00011,
+  mode_analyse=       00120,
+  mode_showcharset=   01000,
 
-  mode_all=           0111,
+  mode_all=           00111,
 };
 
 enum outmodekind {
@@ -184,6 +186,7 @@ int main(int argc, char **argv) {
   while ((arg=*++argv)) {
     if (IS("--find-window-only"))      o_mode= mode_findwindow;
     else if (IS("--screenshot-only"))  o_mode= mode_screenshot;
+    else if (IS("--show-charset"))     o_mode= mode_showcharset;
     else if (IS("--analyse-only") ||
             IS("--same"))             o_mode= mode_analyse;
     else if (IS("--everything"))       o_mode= mode_all;
@@ -226,8 +229,14 @@ int main(int argc, char **argv) {
   /* Consequential changes to options */
 
   if (o_mode & mf_analyse) {
-    if (!o_outmode_kind)
-      o_outmode_kind= (o_flags & ff_printisland) ? omk_none : omk_str;
+    if (!o_outmode_kind) {
+      if (o_flags & ff_printisland) {
+       o_outmode_kind= omk_none;
+       o_flags |= ff_singlepage;
+      } else {
+       o_outmode_kind= omk_upload;
+      }
+    }
 
     if (o_outmode_kind==omk_upload) {
       o_flags |= ffs_upload;
@@ -264,19 +273,26 @@ int main(int argc, char **argv) {
   if (!ocean)  ocean=  o_ocean;
   if (!pirate) pirate= o_pirate;
   
-  if (o_flags & ff_needisland) {
+  if (o_flags & ff_needisland)
     if (!ocean)
-      badusage("need --ocean option when replaying images"
+      badusage("need --ocean option when not using actual YPP client window"
               " (consider supplying --pirate too)");
+  if (ocean)
     sysassert(! setenv("YPPSC_OCEAN",ocean,1) );
-  }
   if (pirate && (o_flags & ff_dict_pirate))
     sysassert(! setenv("YPPSC_PIRATE",pirate,1) );
 
+  switch (o_mode & mfm_special) {
+  case 0:                                      break;
+  case mode_showcharset:  ocr_showcharsets();  exit(0);
+  default:                                     abort();
+  }
+
   if (o_mode & mf_screenshot) {
     open_screenshot_file("w");
     if (o_flags & ff_singlepage) take_one_screenshot();
     else take_screenshots();
+    progress_log("OK for you to move the mouse now.");
   }
   if (o_mode & mf_readscreenshot) {
     open_screenshot_file("r");
@@ -285,9 +301,10 @@ int main(int argc, char **argv) {
   }
   if (o_mode & mf_analyse) {
     if (o_flags & ff_needisland) {
-      find_islandname();
+      find_islandname(page0_rgbimage);
       if (o_flags & ff_printisland)
        printf("%s, %s\n", archipelago, island);
+      sysassert(! setenv("YPPSC_ISLAND",island,1) );
     }
     switch (o_outmode_kind) {
     case omk_upload: case omk_str:   run_analysis();        break;