[sane-devel] Proposals for scanimage and sane-find-scanner

Klaas Freitag freitag at suse.de
Thu Jan 10 16:41:34 GMT 2002


hello,

I like to propose two small patches to the sane utilities scanimage and
sane-find-scanner, which do some minor changes to the output of both tools.
Please add it to cvs if you like.

The change to scanimage does nothing else but changes the output format
of the results of scanimage -L. While scanimage -L would for example
print
device `umax:/dev/sg0' is a UMAX     Astra 2200       flatbed scanner

scanimage -s prints
"umax:/dev/sg0" "UMAX    " "Astra 2200      " "flatbed scanner"

and scanimage -S prints
DEVICE_FILE[0]="umax:/dev/sg0"; DEVICE_VENDOR[0]="UMAX    "; \
DEVICE_MODEL[0]="Astra 2200      "; DEVICE_TYPE[0]="flatbed scanner"

both are easily to parse in shell scripts, scanimage -S produces bash
syntax directly.

A quite similar change I would propose for sane-find-scanner:
A switch -s switches sane-find-scanner to silent mode, which produces
a more compressed output:

/space/temp/sane:$ sane-find-scanner -s
/dev/sg0 SCSI "scanner" "UMAX" "Astra 2200"

Both changes were done to make development of graphical installation
tools for sane easier, because scanimage can be used to detect scanners
already configured with sane, while sane-find-scanner is able to print
out scan devices not yet configured for sane.

Regards,

Klaas

-- 
 ----------------------------------------------------------------------
 Ja mach nur einen Plan und sei ein grosses Licht         Klaas Freitag
 dann mach noch einen zweiten Plan    *            mail freitag at suse.de
 gehn tun sie beide nicht. - B. Brecht             SuSE Labs, Nuernberg
 ----------------------------------------------------------------------

-------------- next part --------------
--- frontend/scanimage.c
+++ frontend/scanimage.c	2002/01/07 14:47:45
@@ -75,6 +75,8 @@
 static struct option basic_options[] = {
   {"device-name", required_argument, NULL, 'd'},
   {"list-devices", no_argument, NULL, 'L'},
+  {"list-devices-machine", no_argument, NULL, 's'},
+  {"list-devices-shell", no_argument, NULL, 'S'},
   {"help", no_argument, NULL, 'h'},
   {"verbose", no_argument, NULL, 'v'},
   {"test", no_argument, NULL, 'T'},
@@ -92,7 +94,7 @@
 #define OUTPUT_PNM      0
 #define OUTPUT_TIFF     1
 
-#define BASE_OPTSTRING	"d:hLvVTb"
+#define BASE_OPTSTRING	"d:hLsSvVTb"
 #define STRIP_HEIGHT	256	/* # lines we increment image height */
 
 static struct option *all_options;
@@ -1439,6 +1441,8 @@
 	  accept_only_md5_auth = 1;
 	  break;
 	case 'L':
+	case 's':
+	case 'S':
 	  {
 	    int i;
 
@@ -1452,17 +1456,38 @@
 
 	    for (i = 0; device_list[i]; ++i)
 	      {
-		printf ("device `%s' is a %s %s %s\n",
-			device_list[i]->name, device_list[i]->vendor,
-			device_list[i]->model, device_list[i]->type);
+		 if( ch == 's' )
+		 {
+		    printf( "\"%s\" \"%s\" \"%s\" \"%s\"\n",
+			    device_list[i]->name, device_list[i]->vendor,
+			    device_list[i]->model, device_list[i]->type);
+		 }
+		 else
+		 if( ch == 'S' )
+		 {
+		    printf ("DEVICE_FILE[%d]=\"%s\"; ",
+			    i, device_list[i]->name );
+		    printf ("DEVICE_VENDOR[%d]=\"%s\"; ",
+			    i, device_list[i]->vendor );
+		    printf ("DEVICE_MODEL[%d]=\"%s\"; ",
+			    i, device_list[i]->model );
+		    printf ("DEVICE_TYPE[%d]=\"%s\"\n",
+			    i, device_list[i]->type );
+		 }
+		 else
+		 {
+		    printf ("device `%s' is a %s %s %s\n",
+			    device_list[i]->name, device_list[i]->vendor,
+			    device_list[i]->model, device_list[i]->type);
+		 }
 	      }
-	    if (i == 0)
+	    if (i == 0 && ch != 's' && ch != 'S' )
 	      printf ("\nNo scanners were identified. If you were expecting "
 		      "something different,\ncheck that the scanner is plugged "
 		      "in, turned on and detected by the\nsane-find-scanner tool "
 		      "(if appropriate). Please read the documentation\nwhich came "
 		      "with this software (README, FAQ, manpages).\n");
-	    if (defdevname)
+	    if (defdevname && ch != 's')
 	      printf ("default device is `%s'\n", defdevname);
 
 	    exit (0);
@@ -1497,6 +1522,8 @@
 -d, --device-name=DEVICE   use a given scanner device (e.g. hp:/dev/scanner)\n\
 -h, --help                 display this help message and exit\n\
 -L, --list-devices         show available scanner devices\n\
+-s, --list-devices-machine a better parseable format of the scanner listing like -L\n\
+-S, --list-devices-shell   a bash evalable format of the -L list\n\
 -T, --test                 test backend thoroughly\n\
 -v, --verbose              give even more status messages\n\
 -V, --version              print version information\n\
--- tools/sane-find-scanner.c
+++ tools/sane-find-scanner.c	2002/01/10 09:05:03
@@ -36,6 +36,7 @@
 static const char *prog_name;
 
 static int verbose;
+static int silent;
 
 typedef struct
   {
@@ -71,6 +72,7 @@
   fprintf (stderr, "Usage: %s [-hv] [devname ...]\n", prog_name);
   fprintf (stderr, "\t-h: print this help message\n");
   fprintf (stderr, "\t-v: be verbose\n");
+  fprintf (stderr, "\t-s: be silent\n" );
   if (msg)
     fprintf (stderr, "\t%s\n", msg);
 }
@@ -168,9 +170,22 @@
   while (pp >= version && (*pp == ' ' || *(pp - 1) >= 127))
     *pp-- = '\0';
 
-  printf ("%s: found SCSI %s \"%s %s %s\" at device %s\n", prog_name,
-	  devtype < NELEMS(devtypes) ? devtypes[devtype] : "unknown device",
-	  vendor, product, version, devicename);
+  if( silent )
+  {
+     /* print out the device file first for easy parsing */
+     printf( "%s SCSI \"%s\" \"%s\" \"%s\"\n",
+            devicename, devtype < NELEMS(devtypes) ? devtypes[devtype] : "unknown device",
+            vendor, product );
+  }
+  else
+  {
+     printf ("%s: found SCSI %s \"%s %s %s\" at device %s\n", prog_name,
+            devtype < NELEMS(devtypes) ? devtypes[devtype] : "unknown device",
+            vendor, product, version, devicename);
+  }
+
+
+  
   return;
 }
 
@@ -201,6 +216,10 @@
 
 	case 'v':
 	  ++verbose;
+	  break;
+	case 's':
+	  ++silent;
+	  break;
 	}
     }
   if (ap < argv + argc)
@@ -447,15 +466,15 @@
       dev_list = default_dev_list;
       usb_dev_list = usb_default_dev_list;
     }
+  if( ! silent )
+     printf (
+	     "# Note that sane-find-scanner will find any scanner that is connected\n"
+	     "# to a SCSI bus and some scanners that are connected to the Universal\n"
+	     "# Serial Bus (USB) depending on your OS. It will even find scanners\n"
+	     "# that are not supported at all by SANE. It won't find a scanner that\n"
+	     "# is connected to a parallel or proprietary port.\n\n");
 
-  printf (
-       "# Note that sane-find-scanner will find any scanner that is connected\n"
-       "# to a SCSI bus and some scanners that are connected to the Universal\n"
-       "# Serial Bus (USB) depending on your OS. It will even find scanners\n"
-       "# that are not supported at all by SANE. It won't find a scanner that\n"
-       "# is connected to a parallel or proprietary port.\n\n");
-
-  if (getuid ())
+  if (getuid () && ! silent )
     printf (
      "# You may want to run this program as super-user to find all devices.\n"
      "# Once you found the scanner devices, be sure to adjust access\n"
@@ -488,11 +507,12 @@
     }
   if (!check_sg())
     {
-    printf (
-       "# If your scanner uses SCSI, you must have a driver for your SCSI\n"
-       "# adapter and support for SCSI Generic (sg) in your Operating System\n"
-       "# in order for the scanner to be used with SANE. If your scanner is\n"
-       "# NOT listed above, check that you have installed the drivers.\n\n");
+       if( ! silent )
+	  printf (
+		  "# If your scanner uses SCSI, you must have a driver for your SCSI\n"
+		  "# adapter and support for SCSI Generic (sg) in your Operating System\n"
+		  "# in order for the scanner to be used with SANE. If your scanner is\n"
+		  "# NOT listed above, check that you have installed the drivers.\n\n");
     }
 
   sanei_usb_init ();
@@ -521,6 +541,11 @@
 	    {
 	      if (verbose)
 		printf (" open ok, vendor and product ids were identified\n");
+	      if( silent )
+	      {	
+		 printf( "%s USB \"scanner\" \"0x%04x\" \"0x%04x\"\n", dev_name, vendor, product );
+	      }
+	      else
 	      printf ("%s: found USB scanner (vendor = 0x%04x, "
 		      "product = 0x%04x) at device %s\n", prog_name, vendor,
 		      product, dev_name);
@@ -537,7 +562,7 @@
 	  sanei_usb_close (fd);
 	}
     }
-  if (unknown_found)
+  if (unknown_found && ! silent )
     printf ("\n"
     "# `UNKNOWN vendor and product' means that there seems to be a scanner\n"
     "# at this device file but the vendor and product ids couldn't be \n"


More information about the sane-devel mailing list