diff -ru sane-pre1.01-4/ChangeLog sane-pre1.01-4-pere/ChangeLog
--- sane-pre1.01-4/ChangeLog	Tue Apr  6 19:27:56 1999
+++ sane-pre1.01-4-pere/ChangeLog	Tue Apr  6 20:00:21 1999
@@ -1,3 +1,25 @@
+1999-04-06  Petter Reinholdtsen <pere@td.org.uit.no>
+	* backend/snapscan.c (sane_exit sane_get_devices): Removed memory
+	leak.
+	(sane_open): Give more sensible error message when unable to open
+	temp file.  Open temp file in /var/tmp, not in current directory.
+	(mini_inquiry add_device): Make sure to only match listed models.
+  	Earlier, substrings would also match.
+
+1999-04-04  Petter Reinholdtsen <pere@td.org.uit.no>
+	* backend/snapscan.c (sane_snapscan_*): Changed API entries from
+	sane_snapscan_* to sane_*.
+
+1999-03-10  Petter Reinholdtsen  <pere@td.org.uit.no>
+	* backend/snapscan.c (add_device init_options inquiry
+ 	sane_snapscan_get_parameters sane_snapscan_start
+ 	sane_snapscan_set_io_mode sane_snapscan_read) backend/snapscan.h
+ 	backend/snapscan.desc: Rewrote scanner detection code to loop over
+ 	array of supported SCSI names.  Added AGFA SnapScan 1236s support.
+  	It seems to be compatible with SnapScan 600.
+	Make sure to not add the same device more then once to the device
+ 	list.  Bugfix in sane_snapscan_read() triggered on EOF.
+
 1999-04-03  David Mosberger-Tang  <David.Mosberger@acm.org>
 
 	* include/sane/sanei_debug.h: Define sanei_debug_BACKEND_NAME only
diff -ru sane-pre1.01-4/backend/snapscan.desc sane-pre1.01-4-pere/backend/snapscan.desc
--- sane-pre1.01-4/backend/snapscan.desc	Tue Apr  6 19:27:45 1999
+++ sane-pre1.01-4-pere/backend/snapscan.desc	Sun Apr  4 18:44:11 1999
@@ -28,6 +28,8 @@
 :comment "Ditto"
 :model "SnapScan 600"
 :comment "Ditto"
+:model "SnapScan 1236s"
+:comment "Ditto"
 :mfg "Vuego"
 :model "310S"
 :comment "Close SnapScan 310 compatible."
diff -ru sane-pre1.01-4/backend/snapscan.h sane-pre1.01-4-pere/backend/snapscan.h
--- sane-pre1.01-4/backend/snapscan.h	Tue Apr  6 19:27:41 1999
+++ sane-pre1.01-4-pere/backend/snapscan.h	Tue Apr  6 20:18:03 1999
@@ -53,23 +53,45 @@
 
 /* snapscan device field values */
 
-#define SNAPSCAN_NAME      "/dev/sga"
-#define SNAPSCAN_VENDOR    "AGFA"
-#define VUEGO_VENDOR	   "COLOR"
-#define SNAPSCAN_MODEL300  "SnapScan"
-#define SNAPSCAN_MODEL310  "SNAPSCAN 310"
-#define VUEGO_MODEL310S	   "FlatbedScanner_4"
-#define SNAPSCAN_MODEL600  "SNAPSCAN 600"
+#define DEFAULT_DEVICE "/dev/scanner" /* Check this if config is missing */
 #define SNAPSCAN_TYPE      "flatbed scanner"
 /*#define	INOPERATIVE*/
+#define TMP_FILE_PREFIX "/var/tmp/snapscan"
 
 typedef enum
 {
+  UNKNOWN,
   SNAPSCAN300,			/* the original SnapScan or SnapScan 300 */
   SNAPSCAN310,			/* the SnapScan 310 */
   SNAPSCAN600,			/* the SnapScan 600 */
+  SNAPSCAN1236S,		/* the SnapScan 1236s */
   VUEGO310S			/* Vuego-Version of SnapScan 310 WG changed */
 } SnapScan_Model;
+
+struct SnapScan_Model_desc
+{
+  char *scsi_name;
+  SnapScan_Model id;
+};
+
+static struct SnapScan_Model_desc scanners[] =
+{
+  /* SCSI model name -> enum value */
+  { "FlatbedScanner_4",	VUEGO310S },
+  { "SNAPSCAN 1236",	SNAPSCAN1236S },
+  { "SNAPSCAN 310",	SNAPSCAN310 },
+  { "SNAPSCAN 600",	SNAPSCAN600 },
+  { "SnapScan",		SNAPSCAN300 },
+};
+#define known_scanners (sizeof(scanners)/sizeof(scanners[0]))
+
+static char *vendors[] =
+{
+  /* SCSI Vendor name */
+  "AGFA",
+  "COLOR",
+};
+#define known_vendors (sizeof(vendors)/sizeof(vendors[0]))
 
 typedef enum
   {
diff -ru sane-pre1.01-4/backend/snapscan.c sane-pre1.01-4-pere/backend/snapscan.c
--- sane-pre1.01-4/backend/snapscan.c	Tue Apr  6 19:27:40 1999
+++ sane-pre1.01-4-pere/backend/snapscan.c	Tue Apr  6 20:23:07 1999
@@ -161,7 +161,6 @@
 #define DEFAULT_BRX  (x_range.max)
 #define DEFAULT_BRY  (y_range.max)
 
-
 #ifdef INOPERATIVE
 static const SANE_Range percent_range =
 {
@@ -339,6 +338,7 @@
       {
       case SNAPSCAN310:
       case SNAPSCAN600:
+      case SNAPSCAN1236S:
       case VUEGO310S:		/* WG changed */
 	po[OPT_MODE].constraint.string_list = names_310;
 	break;
@@ -370,6 +370,7 @@
       {
       case SNAPSCAN310:
       case SNAPSCAN600:
+      case SNAPSCAN1236S:
       case VUEGO310S:		/* WG changed */
 	po[OPT_PREVIEW_MODE].constraint.string_list = names_310;
 	break;
@@ -888,6 +889,19 @@
   pc[3] = (0x000000ff & x);
 }
 
+/* Convert 'STRING   ' to 'STRING' by adding 0 after last non-space */
+static void
+remove_trailing_space(char *s)
+{
+  int position;
+
+  if (NULL == s)
+    return;
+
+  for (position = strlen(s); position > 0 && ' ' == s[position-1];
+       position--);
+  s[position] = 0;  
+}
 
 #define INQUIRY_LEN 6
 #define INQUIRY_RET_LEN 120
@@ -936,6 +950,9 @@
   memcpy (model, data + 16, 16);
   model[16] = 0;
 
+  remove_trailing_space(vendor);
+  remove_trailing_space(model);
+
   return SANE_STATUS_GOOD;
 }
 
@@ -995,6 +1012,7 @@
     {
     case SNAPSCAN310:
     case SNAPSCAN600:
+    case SNAPSCAN1236S:
     case VUEGO310S:		/* WG changed */
       rgb_buf_set_diff (pss,
 			pss->buf[INQUIRY_G2R_DIFF],
@@ -1523,13 +1541,23 @@
 /*----- global data structures and access utilities -----*/
 
 
-/* for now, we support only one possible device, a SnapScan on /dev/sga */
-
 /* available device list */
 
 static SnapScan_Device *first_device = NULL;	/* device list head */
 static int n_devices = 0;	/* the device count */
 
+/* list returned from sane_get_devices() */
+static const SANE_Device **get_devices_list = NULL;
+
+static SANE_Bool
+device_already_in_list(SnapScan_Device *current, SANE_String_Const name)
+{
+  for ( ;NULL != current; current = current->pnext )
+    if (0 == strcmp(name, current->dev.name))
+      return SANE_TRUE;
+  return SANE_FALSE;
+}
+
 static SANE_Status
 add_device (SANE_String_Const name)
 {
@@ -1537,10 +1565,16 @@
   static const char me[] = "add_device";
   SANE_Status status;
   SnapScan_Device *pd;
-  SnapScan_Model model_num;
+  SnapScan_Model model_num = UNKNOWN;
+  int i, supported_vendor = 0;
   char vendor[8], model[17];
 
-  DBG (DL_CALL_TRACE, "%s\n", me);
+  DBG (DL_CALL_TRACE, "%s(%s)\n", me, name);
+
+  /* Avoid adding the same device more then once */
+  if (device_already_in_list(first_device, name)) {
+    return SANE_STATUS_GOOD;
+  }
 
   vendor[0] = model[0] = '\0';
 
@@ -1561,38 +1595,41 @@
       return status;
     }
 
-  if ((strncasecmp (vendor, SNAPSCAN_VENDOR, strlen (SNAPSCAN_VENDOR)) == 0)
-      ||
-      (strncasecmp (vendor, VUEGO_VENDOR, strlen (VUEGO_VENDOR)) == 0))	/* WG changed */
-    {
-      /* original SnapScan */
-      if (strncasecmp (model, SNAPSCAN_MODEL310,
-		       strlen (SNAPSCAN_MODEL310)) == 0)
-	model_num = SNAPSCAN310;
-      else if (strncasecmp (model, SNAPSCAN_MODEL600,
-			    strlen (SNAPSCAN_MODEL600)) == 0)
-	model_num = SNAPSCAN600;
-      else if (strncasecmp (model, SNAPSCAN_MODEL300,
-			    strlen (SNAPSCAN_MODEL300)) == 0)
-	model_num = SNAPSCAN300;
-      else if (strncasecmp (model, VUEGO_MODEL310S,	/* WG changed */
-			    strlen (VUEGO_MODEL310S)) == 0)
-	model_num = VUEGO310S;
-      else
+  DBG (DL_VERBOSE, "%s: Is vendor \"%s\" model \"%s\" a supported scanner?\n",
+       me, vendor, model);
+
+  /* check if this is one of our supported vendors */
+  for (i = 0; i < known_vendors; i++)
+    if (0 == strcasecmp (vendor, vendors[i]))
+      {
+	supported_vendor = 1;
+	break;
+      }
+  if (!supported_vendor)
+    {
+      DBG (DL_MINOR_ERROR, "%s: \"%s %s\" is not an %s\n",
+	   me, vendor, model,
+	   "AGFA SnapScan model 300, 310, 600 and 1236s"
+	   " or VUEGO model 310S"); /* WG changed */
+      sanei_scsi_close (fd);
+      return SANE_STATUS_INVAL;
+    }
+
+  /* Known vendor.  Check if it is one of our supported models */
+  for (i = 0; i < known_scanners; i++)
+    {
+      if (0 == strcasecmp (model, scanners[i].scsi_name))
 	{
-	  DBG (DL_INFO, "%s: sorry, model %s is not supported.\n"
-	       "Currently supported models are the SnapScan 300 and 310.\n",
-	       me, model);
-	  sanei_scsi_close (fd);
-	  return SANE_STATUS_INVAL;
+	  model_num = scanners[i].id;
+	  break;
 	}
     }
-  else
+  if (UNKNOWN == model_num)
     {
-      DBG (DL_MINOR_ERROR, "%s: \"%s %s\" is not an %s %s\n",
-	   me, vendor, model,
-	   SNAPSCAN_VENDOR,
-	   "AGFA SnapScan model 300, 310, and 600 or VUEGO model 310S"); /* WG changed */
+      DBG (DL_INFO, "%s: sorry, model %s is not supported.\n"
+	   "Currently supported models are AGFA SnapScan model 300, 310, 600\n"
+	   "and 1236s and VUEGO model 310S\n",
+	   me, model);
       sanei_scsi_close (fd);
       return SANE_STATUS_INVAL;
     }
@@ -1666,7 +1703,7 @@
 
 
 SANE_Status
-sane_snapscan_init (SANE_Int * version_code,
+sane_init (SANE_Int * version_code,
 		    SANE_Auth_Callback authorize)
 {
   static const char me[] = "sane_snapscan_init";
@@ -1705,11 +1742,11 @@
   fp = sanei_config_open (SNAPSCAN_CONFIG_FILE);
   if (!fp)
     {
+      /* default to DEFAULT_DEVICE instead of insisting on config file */
       DBG (DL_INFO,
-	   "%s: configuration file not found, defaulting to /dev/scanner.\n",
-	   me);
-      /* default to /dev/scanner instead of insisting on config file */
-      status = add_device ("/dev/scanner");
+	   "%s: configuration file not found, defaulting to %s.\n",
+	   me, DEFAULT_DEVICE);
+      status = add_device (DEFAULT_DEVICE);
       if (status != SANE_STATUS_GOOD)
 	{
 	  DBG (DL_MINOR_ERROR, "%s: failed to add device \"%s\"\n",
@@ -1752,22 +1789,30 @@
 }
 
 void
-sane_snapscan_exit (void)
+sane_exit (void)
 {
   DBG (DL_CALL_TRACE, "sane_snapscan_exit\n");
 
+  if (NULL != get_devices_list)
+    free(get_devices_list);
+  get_devices_list = NULL;
+
   /* just for safety, reset things to known values */
   auth = NULL;
 }
 
 SANE_Status
-sane_snapscan_get_devices (const SANE_Device *** device_list,
+sane_get_devices (const SANE_Device *** device_list,
 			   SANE_Bool local_only)
 {
   static const char *me = "sane_snapscan_get_devices";
   DBG (DL_CALL_TRACE, "%s (%p, %ld)\n", me, (void *) device_list,
        (long) local_only);
 
+  /* Waste the last list returned from this function */
+  if (NULL != get_devices_list)
+    free(get_devices_list);
+
   *device_list = (const SANE_Device **)
     malloc ((n_devices + 1) * sizeof (SANE_Device *));
 
@@ -1787,13 +1832,13 @@
       return SANE_STATUS_NO_MEM;
     }
 
+  get_devices_list = *device_list;
+
   return SANE_STATUS_GOOD;
 }
 
-#define TMP_FILE "snapscan-tmp"
-
 SANE_Status
-sane_snapscan_open (SANE_String_Const name, SANE_Handle * h)
+sane_open (SANE_String_Const name, SANE_Handle * h)
 {
   static const char *me = "sane_snapscan_open";
   SnapScan_Device *psd;
@@ -1842,11 +1887,13 @@
       /* temp file name and the temp file */
       {
 	char tname[128];
-	sprintf (tname, TMP_FILE "-%p", (void *) pss);
+	snprintf (tname, sizeof(tname), TMP_FILE_PREFIX "-%p", (void *) pss);
 	if ((pss->tfd = open (tname, O_CREAT | O_RDWR | O_TRUNC, 0600)) == -1)
 	  {
-	    DBG (DL_MAJOR_ERROR, "%s: can't open temp file %s\n", me, tname);
-	    perror ("File error: ");
+	    char str[200];
+	    snprintf(str, sizeof(str), "Can't open temp file %s", tname);
+	    DBG (DL_MAJOR_ERROR, "%s: %s\n", me, str);
+	    perror (str);
 	    free (*h);
 	    return SANE_STATUS_ACCESS_DENIED;
 	  }
@@ -1905,7 +1952,7 @@
 }
 
 void
-sane_snapscan_close (SANE_Handle h)
+sane_close (SANE_Handle h)
 {
   SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
   DBG (DL_CALL_TRACE, "sane_snapscan_close (%p)\n", (void *) h);
@@ -1925,7 +1972,7 @@
 }
 
 const SANE_Option_Descriptor *
-sane_snapscan_get_option_descriptor (SANE_Handle h, SANE_Int n)
+sane_get_option_descriptor (SANE_Handle h, SANE_Int n)
 {
   DBG (DL_CALL_TRACE, "sane_snapscan_get_option_descriptor (%p, %ld)\n",
        (void *) h, (long) n);
@@ -1938,7 +1985,7 @@
 }
 
 SANE_Status
-sane_snapscan_control_option (SANE_Handle h, SANE_Int n,
+sane_control_option (SANE_Handle h, SANE_Int n,
 			      SANE_Action a, void *v,
 			      SANE_Int * i)
 {
@@ -2621,7 +2668,7 @@
 }
 
 SANE_Status
-sane_snapscan_get_parameters (SANE_Handle h,
+sane_get_parameters (SANE_Handle h,
 			      SANE_Parameters * p)
 {
   static const char *me = "sane_snapscan_get_parameters";
@@ -2673,6 +2720,7 @@
 	  {
 	  case SNAPSCAN310:
 	  case SNAPSCAN600:
+	  case SNAPSCAN1236S:
 	  case VUEGO310S:	/* WG changed */
 	    if (!pss->preview)
 	      {
@@ -2699,6 +2747,7 @@
 	  {
 	  case SNAPSCAN310:
 	  case SNAPSCAN600:
+	  case SNAPSCAN1236S:
 	  case VUEGO310S:	/* WG changed */
 	    pss->lines += line_offset;
 	    p->lines -= line_offset;
@@ -2960,7 +3009,7 @@
 }
 
 SANE_Status
-sane_snapscan_start (SANE_Handle h)
+sane_start (SANE_Handle h)
 {
   static const char *me = "sane_snapscan_start";
   SANE_Status status;
@@ -3114,6 +3163,7 @@
 	      {
 	      case SNAPSCAN310:
 	      case SNAPSCAN600:
+	      case SNAPSCAN1236S:
 	      case VUEGO310S:	/* WG changed */
 		if (SANE_STATUS_GOOD != rgb_buf_init (pss))
 		  return SANE_STATUS_NO_MEM;
@@ -3134,6 +3184,7 @@
 		  {
 		  case SNAPSCAN310:
 		  case SNAPSCAN600:
+	          case SNAPSCAN1236S:
 		  case VUEGO310S:	/* WG changed */
 		    rgb_buf_clean (pss);
 		    break;
@@ -3153,6 +3204,7 @@
 	      {
 	      case SNAPSCAN310:
 	      case SNAPSCAN600:
+	      case SNAPSCAN1236S:
 	      case VUEGO310S:	/* WG changed */
 		transfer_data_diff (other_buf, pss);
 		break;
@@ -3186,6 +3238,7 @@
 	      {
 	      case SNAPSCAN310:
 	      case SNAPSCAN600:
+	      case SNAPSCAN1236S:
 	      case VUEGO310S:	/* WG changed */
 		rgb_buf_clean (pss);
 		break;
@@ -3231,13 +3284,14 @@
        pss->bytes_per_line / pss->ms_per_line);
 
   /* allocate and initialize rgb ring buffer if the device is
-     a snapscan 310 or 600 model, in colour mode               */
+     a snapscan 310, 600 or 1236s model, in colour mode               */
   if (colour)
     {
       switch (pss->pdev->model)
 	{
 	case SNAPSCAN310:
 	case SNAPSCAN600:
+	case SNAPSCAN1236S:
 	case VUEGO310S:	/* WG changed */
 	  rgb_buf_init (pss);
 	  break;
@@ -3268,7 +3322,7 @@
 
 
 SANE_Status
-sane_snapscan_read (SANE_Handle h, SANE_Byte * buf,
+sane_read (SANE_Handle h, SANE_Byte * buf,
 		    SANE_Int maxlen, SANE_Int * plen)
 {
   static const char *me = "sane_snapscan_read";
@@ -3279,6 +3333,8 @@
   DBG (DL_CALL_TRACE, "%s (%p, %p, %ld, %p)\n",
        me, (void *) h, (void *) buf, (long) maxlen, (void *) plen);
 
+  *plen = 0;
+
   if (!pss->expected_data_len)
     {
       if (pss->child > 0)
@@ -3292,8 +3348,6 @@
       return SANE_STATUS_EOF;
     }
 
-  *plen = 0;
-
   if (pss->preview)
     mode = pss->preview_mode;
 
@@ -3302,13 +3356,15 @@
     maxlen /= 8;
 
   /* reset maxlen to a scan line boundary */
+  /* XXX Why is this here? The non-blocking client should have no
+     buffer limits */
   maxlen = (maxlen / pss->bytes_per_line) * pss->bytes_per_line;
 
   /* expected data per read is the minimum of the scanner effective
      buffer length , the frontend effective buffer length, and the
      total remaining data in the scan */
-  pss->expected_read_bytes = MIN (pss->buf_sz, pss->expected_data_len);
-  pss->expected_read_bytes = MIN (maxlen, pss->expected_read_bytes);
+  pss->expected_read_bytes =
+    MIN (MIN (pss->buf_sz, maxlen), pss->expected_data_len);
 
   /* since a cancellation happens asynchronously, it seems in practice
      that we need to check for cancellation both before and after IO
@@ -3413,6 +3469,7 @@
 	      {
 	      case SNAPSCAN310:
 	      case SNAPSCAN600:
+	      case SNAPSCAN1236S:
 	      case VUEGO310S:	/* WG changed */
 		transferred_bytes = transfer_data_diff (buf, pss);
 		break;
@@ -3466,7 +3523,7 @@
 }
 
 void
-sane_snapscan_cancel (SANE_Handle h)
+sane_cancel (SANE_Handle h)
 {
   char *me = "sane_snapscan_cancel";
   SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
@@ -3486,6 +3543,7 @@
 	    {
 	    case SNAPSCAN310:
 	    case SNAPSCAN600:
+	    case SNAPSCAN1236S:
 	    case VUEGO310S:	/* WG changed */
 	      rgb_buf_clean (pss);
 	      break;
@@ -3506,7 +3564,7 @@
 }
 
 SANE_Status
-sane_snapscan_set_io_mode (SANE_Handle h, SANE_Bool m)
+sane_set_io_mode (SANE_Handle h, SANE_Bool m)
 {
   static char me[] = "sane_snapscan_set_io_mode";
   SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
@@ -3541,7 +3599,7 @@
 }
 
 SANE_Status
-sane_snapscan_get_select_fd (SANE_Handle h, SANE_Int * fd)
+sane_get_select_fd (SANE_Handle h, SANE_Int * fd)
 {
   static char me[] = "sane_snapscan_get_select_fd";
   SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
