1 diff -ru sane-pre1.01-4/ChangeLog sane-pre1.01-4-pere/ChangeLog
2 --- sane-pre1.01-4/ChangeLog Tue Apr 6 19:27:56 1999
3 +++ sane-pre1.01-4-pere/ChangeLog Tue Apr 6 20:00:21 1999
5 +1999-04-06 Petter Reinholdtsen <pere@td.org.uit.no>
6 + * backend/snapscan.c (sane_exit sane_get_devices): Removed memory
8 + (sane_open): Give more sensible error message when unable to open
9 + temp file. Open temp file in /var/tmp, not in current directory.
10 + (mini_inquiry add_device): Make sure to only match listed models.
11 + Earlier, substrings would also match.
13 +1999-04-04 Petter Reinholdtsen <pere@td.org.uit.no>
14 + * backend/snapscan.c (sane_snapscan_*): Changed API entries from
15 + sane_snapscan_* to sane_*.
17 +1999-03-10 Petter Reinholdtsen <pere@td.org.uit.no>
18 + * backend/snapscan.c (add_device init_options inquiry
19 + sane_snapscan_get_parameters sane_snapscan_start
20 + sane_snapscan_set_io_mode sane_snapscan_read) backend/snapscan.h
21 + backend/snapscan.desc: Rewrote scanner detection code to loop over
22 + array of supported SCSI names. Added AGFA SnapScan 1236s support.
23 + It seems to be compatible with SnapScan 600.
24 + Make sure to not add the same device more then once to the device
25 + list. Bugfix in sane_snapscan_read() triggered on EOF.
27 1999-04-03 David Mosberger-Tang <David.Mosberger@acm.org>
29 * include/sane/sanei_debug.h: Define sanei_debug_BACKEND_NAME only
30 diff -ru sane-pre1.01-4/backend/snapscan.desc sane-pre1.01-4-pere/backend/snapscan.desc
31 --- sane-pre1.01-4/backend/snapscan.desc Tue Apr 6 19:27:45 1999
32 +++ sane-pre1.01-4-pere/backend/snapscan.desc Sun Apr 4 18:44:11 1999
37 +:model "SnapScan 1236s"
41 :comment "Close SnapScan 310 compatible."
42 diff -ru sane-pre1.01-4/backend/snapscan.h sane-pre1.01-4-pere/backend/snapscan.h
43 --- sane-pre1.01-4/backend/snapscan.h Tue Apr 6 19:27:41 1999
44 +++ sane-pre1.01-4-pere/backend/snapscan.h Tue Apr 6 20:18:03 1999
47 /* snapscan device field values */
49 -#define SNAPSCAN_NAME "/dev/sga"
50 -#define SNAPSCAN_VENDOR "AGFA"
51 -#define VUEGO_VENDOR "COLOR"
52 -#define SNAPSCAN_MODEL300 "SnapScan"
53 -#define SNAPSCAN_MODEL310 "SNAPSCAN 310"
54 -#define VUEGO_MODEL310S "FlatbedScanner_4"
55 -#define SNAPSCAN_MODEL600 "SNAPSCAN 600"
56 +#define DEFAULT_DEVICE "/dev/scanner" /* Check this if config is missing */
57 #define SNAPSCAN_TYPE "flatbed scanner"
58 /*#define INOPERATIVE*/
59 +#define TMP_FILE_PREFIX "/var/tmp/snapscan"
64 SNAPSCAN300, /* the original SnapScan or SnapScan 300 */
65 SNAPSCAN310, /* the SnapScan 310 */
66 SNAPSCAN600, /* the SnapScan 600 */
67 + SNAPSCAN1236S, /* the SnapScan 1236s */
68 VUEGO310S /* Vuego-Version of SnapScan 310 WG changed */
71 +struct SnapScan_Model_desc
77 +static struct SnapScan_Model_desc scanners[] =
79 + /* SCSI model name -> enum value */
80 + { "FlatbedScanner_4", VUEGO310S },
81 + { "SNAPSCAN 1236", SNAPSCAN1236S },
82 + { "SNAPSCAN 310", SNAPSCAN310 },
83 + { "SNAPSCAN 600", SNAPSCAN600 },
84 + { "SnapScan", SNAPSCAN300 },
86 +#define known_scanners (sizeof(scanners)/sizeof(scanners[0]))
88 +static char *vendors[] =
90 + /* SCSI Vendor name */
94 +#define known_vendors (sizeof(vendors)/sizeof(vendors[0]))
98 diff -ru sane-pre1.01-4/backend/snapscan.c sane-pre1.01-4-pere/backend/snapscan.c
99 --- sane-pre1.01-4/backend/snapscan.c Tue Apr 6 19:27:40 1999
100 +++ sane-pre1.01-4-pere/backend/snapscan.c Tue Apr 6 20:23:07 1999
102 #define DEFAULT_BRX (x_range.max)
103 #define DEFAULT_BRY (y_range.max)
107 static const SANE_Range percent_range =
113 + case SNAPSCAN1236S:
114 case VUEGO310S: /* WG changed */
115 po[OPT_MODE].constraint.string_list = names_310;
121 + case SNAPSCAN1236S:
122 case VUEGO310S: /* WG changed */
123 po[OPT_PREVIEW_MODE].constraint.string_list = names_310;
126 pc[3] = (0x000000ff & x);
129 +/* Convert 'STRING ' to 'STRING' by adding 0 after last non-space */
131 +remove_trailing_space(char *s)
138 + for (position = strlen(s); position > 0 && ' ' == s[position-1];
143 #define INQUIRY_LEN 6
144 #define INQUIRY_RET_LEN 120
146 memcpy (model, data + 16, 16);
149 + remove_trailing_space(vendor);
150 + remove_trailing_space(model);
152 return SANE_STATUS_GOOD;
159 + case SNAPSCAN1236S:
160 case VUEGO310S: /* WG changed */
161 rgb_buf_set_diff (pss,
162 pss->buf[INQUIRY_G2R_DIFF],
163 @@ -1523,13 +1541,23 @@
164 /*----- global data structures and access utilities -----*/
167 -/* for now, we support only one possible device, a SnapScan on /dev/sga */
169 /* available device list */
171 static SnapScan_Device *first_device = NULL; /* device list head */
172 static int n_devices = 0; /* the device count */
174 +/* list returned from sane_get_devices() */
175 +static const SANE_Device **get_devices_list = NULL;
178 +device_already_in_list(SnapScan_Device *current, SANE_String_Const name)
180 + for ( ;NULL != current; current = current->pnext )
181 + if (0 == strcmp(name, current->dev.name))
187 add_device (SANE_String_Const name)
189 @@ -1537,10 +1565,16 @@
190 static const char me[] = "add_device";
193 - SnapScan_Model model_num;
194 + SnapScan_Model model_num = UNKNOWN;
195 + int i, supported_vendor = 0;
196 char vendor[8], model[17];
198 - DBG (DL_CALL_TRACE, "%s\n", me);
199 + DBG (DL_CALL_TRACE, "%s(%s)\n", me, name);
201 + /* Avoid adding the same device more then once */
202 + if (device_already_in_list(first_device, name)) {
203 + return SANE_STATUS_GOOD;
206 vendor[0] = model[0] = '\0';
208 @@ -1561,38 +1595,41 @@
212 - if ((strncasecmp (vendor, SNAPSCAN_VENDOR, strlen (SNAPSCAN_VENDOR)) == 0)
214 - (strncasecmp (vendor, VUEGO_VENDOR, strlen (VUEGO_VENDOR)) == 0)) /* WG changed */
216 - /* original SnapScan */
217 - if (strncasecmp (model, SNAPSCAN_MODEL310,
218 - strlen (SNAPSCAN_MODEL310)) == 0)
219 - model_num = SNAPSCAN310;
220 - else if (strncasecmp (model, SNAPSCAN_MODEL600,
221 - strlen (SNAPSCAN_MODEL600)) == 0)
222 - model_num = SNAPSCAN600;
223 - else if (strncasecmp (model, SNAPSCAN_MODEL300,
224 - strlen (SNAPSCAN_MODEL300)) == 0)
225 - model_num = SNAPSCAN300;
226 - else if (strncasecmp (model, VUEGO_MODEL310S, /* WG changed */
227 - strlen (VUEGO_MODEL310S)) == 0)
228 - model_num = VUEGO310S;
230 + DBG (DL_VERBOSE, "%s: Is vendor \"%s\" model \"%s\" a supported scanner?\n",
231 + me, vendor, model);
233 + /* check if this is one of our supported vendors */
234 + for (i = 0; i < known_vendors; i++)
235 + if (0 == strcasecmp (vendor, vendors[i]))
237 + supported_vendor = 1;
240 + if (!supported_vendor)
242 + DBG (DL_MINOR_ERROR, "%s: \"%s %s\" is not an %s\n",
244 + "AGFA SnapScan model 300, 310, 600 and 1236s"
245 + " or VUEGO model 310S"); /* WG changed */
246 + sanei_scsi_close (fd);
247 + return SANE_STATUS_INVAL;
250 + /* Known vendor. Check if it is one of our supported models */
251 + for (i = 0; i < known_scanners; i++)
253 + if (0 == strcasecmp (model, scanners[i].scsi_name))
255 - DBG (DL_INFO, "%s: sorry, model %s is not supported.\n"
256 - "Currently supported models are the SnapScan 300 and 310.\n",
258 - sanei_scsi_close (fd);
259 - return SANE_STATUS_INVAL;
260 + model_num = scanners[i].id;
265 + if (UNKNOWN == model_num)
267 - DBG (DL_MINOR_ERROR, "%s: \"%s %s\" is not an %s %s\n",
270 - "AGFA SnapScan model 300, 310, and 600 or VUEGO model 310S"); /* WG changed */
271 + DBG (DL_INFO, "%s: sorry, model %s is not supported.\n"
272 + "Currently supported models are AGFA SnapScan model 300, 310, 600\n"
273 + "and 1236s and VUEGO model 310S\n",
275 sanei_scsi_close (fd);
276 return SANE_STATUS_INVAL;
278 @@ -1666,7 +1703,7 @@
282 -sane_snapscan_init (SANE_Int * version_code,
283 +sane_init (SANE_Int * version_code,
284 SANE_Auth_Callback authorize)
286 static const char me[] = "sane_snapscan_init";
287 @@ -1705,11 +1742,11 @@
288 fp = sanei_config_open (SNAPSCAN_CONFIG_FILE);
291 + /* default to DEFAULT_DEVICE instead of insisting on config file */
293 - "%s: configuration file not found, defaulting to /dev/scanner.\n",
295 - /* default to /dev/scanner instead of insisting on config file */
296 - status = add_device ("/dev/scanner");
297 + "%s: configuration file not found, defaulting to %s.\n",
298 + me, DEFAULT_DEVICE);
299 + status = add_device (DEFAULT_DEVICE);
300 if (status != SANE_STATUS_GOOD)
302 DBG (DL_MINOR_ERROR, "%s: failed to add device \"%s\"\n",
303 @@ -1752,22 +1789,30 @@
307 -sane_snapscan_exit (void)
310 DBG (DL_CALL_TRACE, "sane_snapscan_exit\n");
312 + if (NULL != get_devices_list)
313 + free(get_devices_list);
314 + get_devices_list = NULL;
316 /* just for safety, reset things to known values */
321 -sane_snapscan_get_devices (const SANE_Device *** device_list,
322 +sane_get_devices (const SANE_Device *** device_list,
323 SANE_Bool local_only)
325 static const char *me = "sane_snapscan_get_devices";
326 DBG (DL_CALL_TRACE, "%s (%p, %ld)\n", me, (void *) device_list,
329 + /* Waste the last list returned from this function */
330 + if (NULL != get_devices_list)
331 + free(get_devices_list);
333 *device_list = (const SANE_Device **)
334 malloc ((n_devices + 1) * sizeof (SANE_Device *));
336 @@ -1787,13 +1832,13 @@
337 return SANE_STATUS_NO_MEM;
340 + get_devices_list = *device_list;
342 return SANE_STATUS_GOOD;
345 -#define TMP_FILE "snapscan-tmp"
348 -sane_snapscan_open (SANE_String_Const name, SANE_Handle * h)
349 +sane_open (SANE_String_Const name, SANE_Handle * h)
351 static const char *me = "sane_snapscan_open";
352 SnapScan_Device *psd;
353 @@ -1842,11 +1887,13 @@
354 /* temp file name and the temp file */
357 - sprintf (tname, TMP_FILE "-%p", (void *) pss);
358 + snprintf (tname, sizeof(tname), TMP_FILE_PREFIX "-%p", (void *) pss);
359 if ((pss->tfd = open (tname, O_CREAT | O_RDWR | O_TRUNC, 0600)) == -1)
361 - DBG (DL_MAJOR_ERROR, "%s: can't open temp file %s\n", me, tname);
362 - perror ("File error: ");
364 + snprintf(str, sizeof(str), "Can't open temp file %s", tname);
365 + DBG (DL_MAJOR_ERROR, "%s: %s\n", me, str);
368 return SANE_STATUS_ACCESS_DENIED;
370 @@ -1905,7 +1952,7 @@
374 -sane_snapscan_close (SANE_Handle h)
375 +sane_close (SANE_Handle h)
377 SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
378 DBG (DL_CALL_TRACE, "sane_snapscan_close (%p)\n", (void *) h);
379 @@ -1925,7 +1972,7 @@
382 const SANE_Option_Descriptor *
383 -sane_snapscan_get_option_descriptor (SANE_Handle h, SANE_Int n)
384 +sane_get_option_descriptor (SANE_Handle h, SANE_Int n)
386 DBG (DL_CALL_TRACE, "sane_snapscan_get_option_descriptor (%p, %ld)\n",
387 (void *) h, (long) n);
388 @@ -1938,7 +1985,7 @@
392 -sane_snapscan_control_option (SANE_Handle h, SANE_Int n,
393 +sane_control_option (SANE_Handle h, SANE_Int n,
394 SANE_Action a, void *v,
397 @@ -2621,7 +2668,7 @@
401 -sane_snapscan_get_parameters (SANE_Handle h,
402 +sane_get_parameters (SANE_Handle h,
405 static const char *me = "sane_snapscan_get_parameters";
406 @@ -2673,6 +2720,7 @@
410 + case SNAPSCAN1236S:
411 case VUEGO310S: /* WG changed */
414 @@ -2699,6 +2747,7 @@
418 + case SNAPSCAN1236S:
419 case VUEGO310S: /* WG changed */
420 pss->lines += line_offset;
421 p->lines -= line_offset;
422 @@ -2960,7 +3009,7 @@
426 -sane_snapscan_start (SANE_Handle h)
427 +sane_start (SANE_Handle h)
429 static const char *me = "sane_snapscan_start";
431 @@ -3114,6 +3163,7 @@
435 + case SNAPSCAN1236S:
436 case VUEGO310S: /* WG changed */
437 if (SANE_STATUS_GOOD != rgb_buf_init (pss))
438 return SANE_STATUS_NO_MEM;
439 @@ -3134,6 +3184,7 @@
443 + case SNAPSCAN1236S:
444 case VUEGO310S: /* WG changed */
447 @@ -3153,6 +3204,7 @@
451 + case SNAPSCAN1236S:
452 case VUEGO310S: /* WG changed */
453 transfer_data_diff (other_buf, pss);
455 @@ -3186,6 +3238,7 @@
459 + case SNAPSCAN1236S:
460 case VUEGO310S: /* WG changed */
463 @@ -3231,13 +3284,14 @@
464 pss->bytes_per_line / pss->ms_per_line);
466 /* allocate and initialize rgb ring buffer if the device is
467 - a snapscan 310 or 600 model, in colour mode */
468 + a snapscan 310, 600 or 1236s model, in colour mode */
471 switch (pss->pdev->model)
475 + case SNAPSCAN1236S:
476 case VUEGO310S: /* WG changed */
479 @@ -3268,7 +3322,7 @@
483 -sane_snapscan_read (SANE_Handle h, SANE_Byte * buf,
484 +sane_read (SANE_Handle h, SANE_Byte * buf,
485 SANE_Int maxlen, SANE_Int * plen)
487 static const char *me = "sane_snapscan_read";
488 @@ -3279,6 +3333,8 @@
489 DBG (DL_CALL_TRACE, "%s (%p, %p, %ld, %p)\n",
490 me, (void *) h, (void *) buf, (long) maxlen, (void *) plen);
494 if (!pss->expected_data_len)
497 @@ -3292,8 +3348,6 @@
498 return SANE_STATUS_EOF;
504 mode = pss->preview_mode;
506 @@ -3302,13 +3356,15 @@
509 /* reset maxlen to a scan line boundary */
510 + /* XXX Why is this here? The non-blocking client should have no
512 maxlen = (maxlen / pss->bytes_per_line) * pss->bytes_per_line;
514 /* expected data per read is the minimum of the scanner effective
515 buffer length , the frontend effective buffer length, and the
516 total remaining data in the scan */
517 - pss->expected_read_bytes = MIN (pss->buf_sz, pss->expected_data_len);
518 - pss->expected_read_bytes = MIN (maxlen, pss->expected_read_bytes);
519 + pss->expected_read_bytes =
520 + MIN (MIN (pss->buf_sz, maxlen), pss->expected_data_len);
522 /* since a cancellation happens asynchronously, it seems in practice
523 that we need to check for cancellation both before and after IO
524 @@ -3413,6 +3469,7 @@
528 + case SNAPSCAN1236S:
529 case VUEGO310S: /* WG changed */
530 transferred_bytes = transfer_data_diff (buf, pss);
532 @@ -3466,7 +3523,7 @@
536 -sane_snapscan_cancel (SANE_Handle h)
537 +sane_cancel (SANE_Handle h)
539 char *me = "sane_snapscan_cancel";
540 SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
541 @@ -3486,6 +3543,7 @@
545 + case SNAPSCAN1236S:
546 case VUEGO310S: /* WG changed */
549 @@ -3506,7 +3564,7 @@
553 -sane_snapscan_set_io_mode (SANE_Handle h, SANE_Bool m)
554 +sane_set_io_mode (SANE_Handle h, SANE_Bool m)
556 static char me[] = "sane_snapscan_set_io_mode";
557 SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
558 @@ -3541,7 +3599,7 @@
562 -sane_snapscan_get_select_fd (SANE_Handle h, SANE_Int * fd)
563 +sane_get_select_fd (SANE_Handle h, SANE_Int * fd)
565 static char me[] = "sane_snapscan_get_select_fd";
566 SnapScan_Scanner *pss = (SnapScan_Scanner *) h;