# these ras hack tweaks to sane-backends-master-e13b80fa scanimage.c
#
# note: based on sun microsystems solaris 10 sparc with gcc 4.9
#
# fixes
#    @  '-Bbuffersize' which works but is not whitespace delimited
#       change allows either whitespace or no delimiting.
#
#    @  possibly corrected a comment cut+paste typo
#       SANE_UNIT_PERCENT: us        //methinks this is wrong
#
# adds
#    @  typesetting points (pt) (eg 1/72") to dimensions of scan area
#
#    @  acceptance of tif and jpg for format designations
#
# updates
#    @  scanimage --help output revisions based on above changes
#
#    @  minor warning text tweakage related to argument value rounding
#
===================================================================
RCS file: frontend/scanimage.c,v
retrieving revision 1.1
diff -uBitwb -r1.1 frontend/scanimage.c
--- frontend/scanimage.c        2019/05/30 17:49:45     1.1
+++ frontend/scanimage.c        2019/06/04 18:18:49
@@ -97,7 +97,7 @@
   {"test", no_argument, NULL, 'T'},
   {"all-options", no_argument, NULL, 'A'},
   {"version", no_argument, NULL, 'V'},
-  {"buffer-size", optional_argument, NULL, 'B'},
+  {"buffer-size", required_argument, NULL, 'B'},
   {"batch", optional_argument, NULL, 'b'},
   {"batch-count", required_argument, NULL, OPTION_BATCH_COUNT},
   {"batch-start", required_argument, NULL, OPTION_BATCH_START_AT},
@@ -118,7 +118,7 @@
 #define OUTPUT_PNG      3
 #define OUTPUT_JPEG     4
 
-#define BASE_OPTSTRING  "d:hi:Lf:o:B::nvVTAbp"
+#define BASE_OPTSTRING  "d:hi:Lf:o:B:nvVTAbp"
 #define STRIP_HEIGHT    256     /* # lines we increment image height */
 
 static struct option *all_options;
@@ -676,10 +676,12 @@
      SANE_UNIT_NONE:
      SANE_UNIT_PIXEL:   pel
      SANE_UNIT_BIT:     b (bit), B (byte)
-     SANE_UNIT_MM:      mm (millimeter), cm (centimeter), in or " (inches),
+     SANE_UNIT_MM:      mm (millimeter), cm (centimeter),
+                        pt (points 1/72"), in or " (inches),
      SANE_UNIT_DPI:     dpi
      SANE_UNIT_PERCENT: %
-     SANE_UNIT_PERCENT: us
+     SANE_UNIT_PERCENT: us        //methinks this is wrong
+     SANE_UNIT_MICROSECOND:     us
  */
 static const char *
 parse_scalar (const SANE_Option_Descriptor * opt, const char *str,
@@ -732,6 +734,14 @@
             ++str;
           v *= 25.4;            /* 25.4 mm/inch */
         }
+      /* ras hack add digital typesetting point unit
+         (eg 1/72" 0.13888" [0.35277mm]
+      */
+      else if (strcmp (str, "pt") == 0)
+        {
+          str += sizeof ("pt") - 1;
+          v *= ( 25.4 / 72 );           /* 0.35277mm/point */
+        }
       else
         {
           fprintf (stderr,
@@ -1030,10 +1040,10 @@
   if ((info & SANE_INFO_INEXACT) && opt->size == sizeof (SANE_Word))
     {
       if (opt->type == SANE_TYPE_INT)
-        fprintf (stderr, "%s: rounded value of %s from %d to %d\n",
+        fprintf (stderr, "%s: rounded int value of %s from %d to %d\n",
                  prog_name, opt->name, orig, *(SANE_Word *) valuep);
       else if (opt->type == SANE_TYPE_FIXED)
-        fprintf (stderr, "%s: rounded value of %s from %g to %g\n",
+        fprintf (stderr, "%s: rounded fixed value of %s from %g to %g\n",
                  prog_name, opt->name,
                  SANE_UNFIX (orig), SANE_UNFIX (*(SANE_Word *) valuep));
     }
@@ -2111,7 +2151,8 @@
           batch = 1;
           break;
         case OPTION_FORMAT:
-          if (strcmp (optarg, "tiff") == 0)
+          if ( strcmp (optarg, "tiff") == 0
+             || strcmp (optarg, "tif") == 0 )
             output_format = OUTPUT_TIFF;
           else if (strcmp (optarg, "png") == 0)
             {
@@ -2122,7 +2163,8 @@
               exit(1);
 #endif
             }
-          else if (strcmp (optarg, "jpeg") == 0)
+          else if ( strcmp (optarg, "jpeg") == 0
+                  || strcmp (optarg, "jpg") == 0 )
             {
 #ifdef HAVE_LIBJPEG
               output_format = OUTPUT_JPEG;
@@ -2138,12 +2180,12 @@
           else
             {
               fprintf(stderr, "Unknown output image format '%s'.\n", optarg);
-              fprintf(stderr, "Supported formats: pnm, tiff");
+              fprintf(stderr, "Supported formats: pnm, tiff|tif");
 #ifdef HAVE_LIBPNG
               fprintf(stderr, ", png");
 #endif
 #ifdef HAVE_LIBJPEG
-              fprintf(stderr, ", jpeg");
+              fprintf(stderr, ", jpeg|jpg");
 #endif
               fprintf(stderr, ".\n");
               exit(1);
@@ -2283,8 +2325,10 @@
 \n\
 Parameters are separated by a blank from single-character options (e.g.\n\
 -d epson) and by a \"=\" from multi-character options (e.g. --device-name=epson).\n\
+\n\
 -d, --device-name=DEVICE   use a given scanner device (e.g. hp:/dev/scanner)\n\
     --format=pnm|tiff|png|jpeg  file format of output file\n\
+                                ras hack will also accept 'tif' and 'jpg'\n\
 -i, --icc-profile=PROFILE  include this ICC profile into TIFF file\n", prog_name);
       printf ("\
 -L, --list-devices         show available scanner devices\n\
@@ -2292,9 +2336,10 @@
                            can be specified: %%d (device name), %%v (vendor),\n\
                            %%m (model), %%t (type), %%i (index number), and\n\
                            %%n (newline)\n\
--b, --batch[=FORMAT]       working in batch mode, FORMAT is `out%%d.pnm' `out%%d.tif'\n\
-                           `out%%d.png' or `out%%d.jpg' by default depending on --format\n\
-                           This option is incompatible with --output-file.");
+-b, --batch[=FORMAT]       working in batch mode, FORMAT is `out%%d.pnm'\n\
+                           `out%%d.tif' `out%%d.png' or `out%%d.jpg' by default\n\
+                           depending on --format.\n\
+                           This option is incompatible with --output-file.\n");
       printf ("\
     --batch-start=#        page number to start naming files with\n\
     --batch-count=#        how many pages to scan in batch mode\n\
@@ -2307,9 +2352,14 @@
     --accept-md5-only      only accept authorization requests using md5\n\
 -p, --progress             print progress messages\n\
 -o, --output-file=PATH     save output to the given file instead of stdout.\n\
-                           This option is incompatible with --batch.\n\
+                           This option is incompatible with --batch.\n");
+      printf ("\
+                           without --format the extention on filename\n\
+                           will be used as output file format if it matches\n\
+                           ( pnm | tiff* | png | jpe*g )\n");
+      printf ("\
 -n, --dont-scan            only set options, don't actually scan\n\
--T, --test                 test backend thoroughly\n\
+-T, --test                 test backend thoroughly (output on stderr)\n\
 -A, --all-options          list all available backend options\n\
 -h, --help                 display this help message and exit\n\
 -v, --verbose              give even more status messages\n\
