SANE_DEFAULT_DEVICE for scanimage (patch)

From: Ingo Wilken (Ingo.Wilken@Informatik.Uni-Oldenburg.DE)
Date: Mon Mar 27 2000 - 14:26:57 PST

  • Next message: pixel fairy: "noisy umax astra 2200"

    This patch adds support for an environment variable SANE_DEFAULT_DEVICE
    to scanimage. Useful if the first device on the list is not your
    preferred device, and you don't want to use the --device option in
    every command.

    I think I sent a similar patch for SANE-1.0.1 to this list some time
    ago. Anyway, it's not in 1.0.2, so I reimplemented it (with a minor
    improvement: if the variable is set, show its contents with -L).

    Regards,
    Ingo

    *** doc/scanimage.man.orig Thu Mar 16 05:25:19 2000
    --- doc/scanimage.man Thu Mar 16 05:38:45 2000
    ***************
    *** 38,43 ****
    --- 38,47 ----
      .B --list-devices
      option (see below). If no device-name is specified explicitly,
      .B scanimage
    + reads a device-name from the environment variable
    + .BR SANE_DEFAULT_DEVICE .
    + If this variable is not set,
    + .B scanimage
      will attempt to open the first available device.
      .PP
      The
    ***************
    *** 228,233 ****
    --- 232,241 ----
      .BR /tmp/input.ppm .
      .RE
      
    + .SH ENVIRONMENT
    + .TP
    + .B SANE_DEFAULT_DEVICE
    + The default device-name.
      .SH FILES
      .TP
      .I @CONFIGDIR@
    *** frontend/scanimage.c.orig Wed Mar 15 17:30:38 2000
    --- frontend/scanimage.c Wed Mar 15 18:05:17 2000
    ***************
    *** 1062,1067 ****
    --- 1062,1068 ----
        const SANE_Device ** device_list;
        SANE_Int num_dev_options = 0;
        const char * devname = 0;
    + const char * defdevname = 0;
        const char * format = 0;
        int batch = 0;
        SANE_Status status;
    ***************
    *** 1075,1080 ****
    --- 1076,1083 ----
        else
          prog_name = argv[0];
      
    + defdevname = getenv("SANE_DEFAULT_DEVICE");
    +
        sane_init (0, 0);
      
        /* make a first pass through the options with error printing and argument
    ***************
    *** 1113,1118 ****
    --- 1116,1124 ----
                               device_list[i]->name, device_list[i]->vendor,
                               device_list[i]->model, device_list[i]->type);
                    }
    + if (defdevname)
    + printf ("default device is `%s'\n", defdevname);
    +
                  exit (0);
                }
      
    ***************
    *** 1142,1150 ****
      
        if (!devname)
          {
    ! /* If no device name was specified explicitly, we open the first
    ! device we find (if any): */
    !
            status = sane_get_devices (&device_list, SANE_FALSE);
            if (status != SANE_STATUS_GOOD)
              {
    --- 1148,1159 ----
      
        if (!devname)
          {
    ! /* If no device name was specified explicitly, we look at the
    ! environment variable SANE_DEFAULT_DEVICE. If this variable
    ! is not set, we open the first device we find (if any): */
    ! devname = defdevname;
    ! if (!devname )
    ! {
                status = sane_get_devices (&device_list, SANE_FALSE);
                if (status != SANE_STATUS_GOOD)
                   {
    ***************
    *** 1158,1163 ****
    --- 1167,1173 ----
                     exit (1);
                   }
                devname = device_list[0]->name;
    + }
          }
      
        status = sane_open (devname, &device);

    --
    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 Mar 27 2000 - 14:12:52 PST