Re: forwarded message from Karl Heinz Kremer

From: Petter Reinholdtsen (pere@hungry.com)
Date: Mon Jan 17 2000 - 16:51:14 PST

  • Next message: Petter Reinholdtsen: "Libtool ltdl patch"

    [David Mosberger-Tang]
    > Could someone consider this for inclusion in the CVS tree?

    I had a look at it, reformatted it to be consistent with current style
    and rewrote the for loop to make sure non-batch mode still works.
    Could someone please verify that the new patch work? I don't have a
    scanner to test with. :-(

    I guess the batch mode should have a way to limit the number of scans.
    If it is used on the video4linux backend, the flow of images will
    never stop... :-)

    Index: frontend/scanimage.c
    ===================================================================
    RCS file: /cvsroot/external/sane/frontend/scanimage.c,v
    retrieving revision 1.1.1.1
    diff -u -r1.1.1.1 scanimage.c
    --- scanimage.c 1999/08/09 18:05:40 1.1.1.1
    +++ scanimage.c 2000/01/18 00:48:07
    @@ -61,7 +61,8 @@
       {"verbose", no_argument, NULL, 'v'},
       {"test", no_argument, NULL, 'T'},
       {"version", no_argument, NULL, 'V'},
    - {0, }
    + {"batch", optional_argument, NULL, 'b'},
    + {0, 0, NULL, 0}
     };
     
     #define BASE_OPTSTRING "d:hLvVT"
    @@ -749,7 +750,7 @@
       return image->data;
     }
     
    -static void
    +static SANE_Status
     scan_it (void)
     {
       int i, len, first_frame = 1, offset = 0, must_buffer = 0;
    @@ -870,7 +871,7 @@
                     {
                       fprintf (stderr, "%s: sane_read: %s\n",
                                prog_name, sane_strstatus (status));
    - return;
    + return status;
                     }
                   break;
                 }
    @@ -938,6 +939,8 @@
       sane_cancel (device);
       if (image.data)
         free (image.data);
    +
    + return status;
     }
     
     #define clean_buffer(buf,size) memset ((buf), 0x23, size)
    @@ -1049,6 +1052,8 @@
       const SANE_Device ** device_list;
       SANE_Int num_dev_options = 0;
       const char * devname = 0;
    + const char * format = 0;
    + int batch = 0;
       SANE_Status status;
       char *full_optstring;
     
    @@ -1076,6 +1081,7 @@
               break; /* may be an option that we'll parse later on */
     
             case 'd': devname = optarg; break;
    + case 'b': batch = 1; format = optarg; break;
             case 'h': help = 1; break;
             case 'v': ++verbose; break;
             case 'T': test= 1; break;
    @@ -1115,6 +1121,7 @@
     Start image acquisition on a scanner device and write PNM image data to\n\
     standard output.\n\
     \n\
    +-b, --batch=FORMAT working in batch mode\n\
     -d, --device-name=DEVICE use a given scanner device\n\
     -h, --help display this help message and exit\n\
     -L, --list-devices show available scanner devices\n\
    @@ -1337,11 +1344,43 @@
       signal (SIGTERM, sighandler);
     
       if (test == 0)
    - scan_it ();
    + {
    + int n = 1;
    +
    + if (batch && NULL == format)
    + format = "out%d.pnm";
    +
    + do
    + {
    + char path [ 1024];
    + sprintf (path, format, n); /* love --(C++) */
    +
    + if (batch && NULL == freopen (path, "w", stdout) )
    + {
    + fprintf (stderr, "cannot open %s\n", path);
    + return SANE_STATUS_ACCESS_DENIED;
    + }
    +
    + status = scan_it ();
    + if (batch)
    + fprintf( stderr, "status = %d\n", status);
    +
    + switch (status)
    + {
    + case SANE_STATUS_EOF:
    + status = SANE_STATUS_GOOD;
    + break;
    + default:
    + break;
    + } /* switch */
    + n++;
    + }
    + while (batch && SANE_STATUS_GOOD == status);
    + }
       else
         test_it ();
     
       sane_close (device);
     
    - return 0;
    + return status;
     }

    -- 
    ##>  Petter Reinholdtsen  <##  |  pere@td.org.uit.no
    

    -- Source code, list archive, and docs: http://www.mostang.com/sane/ To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com



    This archive was generated by hypermail 2b29 : Mon Jan 17 2000 - 16:55:15 PST