]> pere.pagekite.me Git - homepage.git/blob - linux/sane/agfa-snapscan-1236-5.diff
Switched blog to hungry.com for now. Updated all links.
[homepage.git] / linux / sane / agfa-snapscan-1236-5.diff
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
4 @@ -1,3 +1,25 @@
5 +1999-04-06 Petter Reinholdtsen <pere@td.org.uit.no>
6 + * backend/snapscan.c (sane_exit sane_get_devices): Removed memory
7 + leak.
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.
12 +
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_*.
16 +
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.
26 +
27 1999-04-03 David Mosberger-Tang <David.Mosberger@acm.org>
28
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
33 @@ -28,6 +28,8 @@
34 :comment "Ditto"
35 :model "SnapScan 600"
36 :comment "Ditto"
37 +:model "SnapScan 1236s"
38 +:comment "Ditto"
39 :mfg "Vuego"
40 :model "310S"
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
45 @@ -53,23 +53,45 @@
46
47 /* snapscan device field values */
48
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"
60
61 typedef enum
62 {
63 + UNKNOWN,
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 */
69 } SnapScan_Model;
70 +
71 +struct SnapScan_Model_desc
72 +{
73 + char *scsi_name;
74 + SnapScan_Model id;
75 +};
76 +
77 +static struct SnapScan_Model_desc scanners[] =
78 +{
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 },
85 +};
86 +#define known_scanners (sizeof(scanners)/sizeof(scanners[0]))
87 +
88 +static char *vendors[] =
89 +{
90 + /* SCSI Vendor name */
91 + "AGFA",
92 + "COLOR",
93 +};
94 +#define known_vendors (sizeof(vendors)/sizeof(vendors[0]))
95
96 typedef enum
97 {
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
101 @@ -161,7 +161,6 @@
102 #define DEFAULT_BRX (x_range.max)
103 #define DEFAULT_BRY (y_range.max)
104
105 -
106 #ifdef INOPERATIVE
107 static const SANE_Range percent_range =
108 {
109 @@ -339,6 +338,7 @@
110 {
111 case SNAPSCAN310:
112 case SNAPSCAN600:
113 + case SNAPSCAN1236S:
114 case VUEGO310S: /* WG changed */
115 po[OPT_MODE].constraint.string_list = names_310;
116 break;
117 @@ -370,6 +370,7 @@
118 {
119 case SNAPSCAN310:
120 case SNAPSCAN600:
121 + case SNAPSCAN1236S:
122 case VUEGO310S: /* WG changed */
123 po[OPT_PREVIEW_MODE].constraint.string_list = names_310;
124 break;
125 @@ -888,6 +889,19 @@
126 pc[3] = (0x000000ff & x);
127 }
128
129 +/* Convert 'STRING ' to 'STRING' by adding 0 after last non-space */
130 +static void
131 +remove_trailing_space(char *s)
132 +{
133 + int position;
134 +
135 + if (NULL == s)
136 + return;
137 +
138 + for (position = strlen(s); position > 0 && ' ' == s[position-1];
139 + position--);
140 + s[position] = 0;
141 +}
142
143 #define INQUIRY_LEN 6
144 #define INQUIRY_RET_LEN 120
145 @@ -936,6 +950,9 @@
146 memcpy (model, data + 16, 16);
147 model[16] = 0;
148
149 + remove_trailing_space(vendor);
150 + remove_trailing_space(model);
151 +
152 return SANE_STATUS_GOOD;
153 }
154
155 @@ -995,6 +1012,7 @@
156 {
157 case SNAPSCAN310:
158 case SNAPSCAN600:
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 -----*/
165
166
167 -/* for now, we support only one possible device, a SnapScan on /dev/sga */
168 -
169 /* available device list */
170
171 static SnapScan_Device *first_device = NULL; /* device list head */
172 static int n_devices = 0; /* the device count */
173
174 +/* list returned from sane_get_devices() */
175 +static const SANE_Device **get_devices_list = NULL;
176 +
177 +static SANE_Bool
178 +device_already_in_list(SnapScan_Device *current, SANE_String_Const name)
179 +{
180 + for ( ;NULL != current; current = current->pnext )
181 + if (0 == strcmp(name, current->dev.name))
182 + return SANE_TRUE;
183 + return SANE_FALSE;
184 +}
185 +
186 static SANE_Status
187 add_device (SANE_String_Const name)
188 {
189 @@ -1537,10 +1565,16 @@
190 static const char me[] = "add_device";
191 SANE_Status status;
192 SnapScan_Device *pd;
193 - SnapScan_Model model_num;
194 + SnapScan_Model model_num = UNKNOWN;
195 + int i, supported_vendor = 0;
196 char vendor[8], model[17];
197
198 - DBG (DL_CALL_TRACE, "%s\n", me);
199 + DBG (DL_CALL_TRACE, "%s(%s)\n", me, name);
200 +
201 + /* Avoid adding the same device more then once */
202 + if (device_already_in_list(first_device, name)) {
203 + return SANE_STATUS_GOOD;
204 + }
205
206 vendor[0] = model[0] = '\0';
207
208 @@ -1561,38 +1595,41 @@
209 return status;
210 }
211
212 - if ((strncasecmp (vendor, SNAPSCAN_VENDOR, strlen (SNAPSCAN_VENDOR)) == 0)
213 - ||
214 - (strncasecmp (vendor, VUEGO_VENDOR, strlen (VUEGO_VENDOR)) == 0)) /* WG changed */
215 - {
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;
229 - else
230 + DBG (DL_VERBOSE, "%s: Is vendor \"%s\" model \"%s\" a supported scanner?\n",
231 + me, vendor, model);
232 +
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]))
236 + {
237 + supported_vendor = 1;
238 + break;
239 + }
240 + if (!supported_vendor)
241 + {
242 + DBG (DL_MINOR_ERROR, "%s: \"%s %s\" is not an %s\n",
243 + me, vendor, model,
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;
248 + }
249 +
250 + /* Known vendor. Check if it is one of our supported models */
251 + for (i = 0; i < known_scanners; i++)
252 + {
253 + if (0 == strcasecmp (model, scanners[i].scsi_name))
254 {
255 - DBG (DL_INFO, "%s: sorry, model %s is not supported.\n"
256 - "Currently supported models are the SnapScan 300 and 310.\n",
257 - me, model);
258 - sanei_scsi_close (fd);
259 - return SANE_STATUS_INVAL;
260 + model_num = scanners[i].id;
261 + break;
262 }
263 }
264 - else
265 + if (UNKNOWN == model_num)
266 {
267 - DBG (DL_MINOR_ERROR, "%s: \"%s %s\" is not an %s %s\n",
268 - me, vendor, model,
269 - SNAPSCAN_VENDOR,
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",
274 + me, model);
275 sanei_scsi_close (fd);
276 return SANE_STATUS_INVAL;
277 }
278 @@ -1666,7 +1703,7 @@
279
280
281 SANE_Status
282 -sane_snapscan_init (SANE_Int * version_code,
283 +sane_init (SANE_Int * version_code,
284 SANE_Auth_Callback authorize)
285 {
286 static const char me[] = "sane_snapscan_init";
287 @@ -1705,11 +1742,11 @@
288 fp = sanei_config_open (SNAPSCAN_CONFIG_FILE);
289 if (!fp)
290 {
291 + /* default to DEFAULT_DEVICE instead of insisting on config file */
292 DBG (DL_INFO,
293 - "%s: configuration file not found, defaulting to /dev/scanner.\n",
294 - me);
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)
301 {
302 DBG (DL_MINOR_ERROR, "%s: failed to add device \"%s\"\n",
303 @@ -1752,22 +1789,30 @@
304 }
305
306 void
307 -sane_snapscan_exit (void)
308 +sane_exit (void)
309 {
310 DBG (DL_CALL_TRACE, "sane_snapscan_exit\n");
311
312 + if (NULL != get_devices_list)
313 + free(get_devices_list);
314 + get_devices_list = NULL;
315 +
316 /* just for safety, reset things to known values */
317 auth = NULL;
318 }
319
320 SANE_Status
321 -sane_snapscan_get_devices (const SANE_Device *** device_list,
322 +sane_get_devices (const SANE_Device *** device_list,
323 SANE_Bool local_only)
324 {
325 static const char *me = "sane_snapscan_get_devices";
326 DBG (DL_CALL_TRACE, "%s (%p, %ld)\n", me, (void *) device_list,
327 (long) local_only);
328
329 + /* Waste the last list returned from this function */
330 + if (NULL != get_devices_list)
331 + free(get_devices_list);
332 +
333 *device_list = (const SANE_Device **)
334 malloc ((n_devices + 1) * sizeof (SANE_Device *));
335
336 @@ -1787,13 +1832,13 @@
337 return SANE_STATUS_NO_MEM;
338 }
339
340 + get_devices_list = *device_list;
341 +
342 return SANE_STATUS_GOOD;
343 }
344
345 -#define TMP_FILE "snapscan-tmp"
346 -
347 SANE_Status
348 -sane_snapscan_open (SANE_String_Const name, SANE_Handle * h)
349 +sane_open (SANE_String_Const name, SANE_Handle * h)
350 {
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 */
355 {
356 char tname[128];
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)
360 {
361 - DBG (DL_MAJOR_ERROR, "%s: can't open temp file %s\n", me, tname);
362 - perror ("File error: ");
363 + char str[200];
364 + snprintf(str, sizeof(str), "Can't open temp file %s", tname);
365 + DBG (DL_MAJOR_ERROR, "%s: %s\n", me, str);
366 + perror (str);
367 free (*h);
368 return SANE_STATUS_ACCESS_DENIED;
369 }
370 @@ -1905,7 +1952,7 @@
371 }
372
373 void
374 -sane_snapscan_close (SANE_Handle h)
375 +sane_close (SANE_Handle h)
376 {
377 SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
378 DBG (DL_CALL_TRACE, "sane_snapscan_close (%p)\n", (void *) h);
379 @@ -1925,7 +1972,7 @@
380 }
381
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)
385 {
386 DBG (DL_CALL_TRACE, "sane_snapscan_get_option_descriptor (%p, %ld)\n",
387 (void *) h, (long) n);
388 @@ -1938,7 +1985,7 @@
389 }
390
391 SANE_Status
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,
395 SANE_Int * i)
396 {
397 @@ -2621,7 +2668,7 @@
398 }
399
400 SANE_Status
401 -sane_snapscan_get_parameters (SANE_Handle h,
402 +sane_get_parameters (SANE_Handle h,
403 SANE_Parameters * p)
404 {
405 static const char *me = "sane_snapscan_get_parameters";
406 @@ -2673,6 +2720,7 @@
407 {
408 case SNAPSCAN310:
409 case SNAPSCAN600:
410 + case SNAPSCAN1236S:
411 case VUEGO310S: /* WG changed */
412 if (!pss->preview)
413 {
414 @@ -2699,6 +2747,7 @@
415 {
416 case SNAPSCAN310:
417 case SNAPSCAN600:
418 + case SNAPSCAN1236S:
419 case VUEGO310S: /* WG changed */
420 pss->lines += line_offset;
421 p->lines -= line_offset;
422 @@ -2960,7 +3009,7 @@
423 }
424
425 SANE_Status
426 -sane_snapscan_start (SANE_Handle h)
427 +sane_start (SANE_Handle h)
428 {
429 static const char *me = "sane_snapscan_start";
430 SANE_Status status;
431 @@ -3114,6 +3163,7 @@
432 {
433 case SNAPSCAN310:
434 case SNAPSCAN600:
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 @@
440 {
441 case SNAPSCAN310:
442 case SNAPSCAN600:
443 + case SNAPSCAN1236S:
444 case VUEGO310S: /* WG changed */
445 rgb_buf_clean (pss);
446 break;
447 @@ -3153,6 +3204,7 @@
448 {
449 case SNAPSCAN310:
450 case SNAPSCAN600:
451 + case SNAPSCAN1236S:
452 case VUEGO310S: /* WG changed */
453 transfer_data_diff (other_buf, pss);
454 break;
455 @@ -3186,6 +3238,7 @@
456 {
457 case SNAPSCAN310:
458 case SNAPSCAN600:
459 + case SNAPSCAN1236S:
460 case VUEGO310S: /* WG changed */
461 rgb_buf_clean (pss);
462 break;
463 @@ -3231,13 +3284,14 @@
464 pss->bytes_per_line / pss->ms_per_line);
465
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 */
469 if (colour)
470 {
471 switch (pss->pdev->model)
472 {
473 case SNAPSCAN310:
474 case SNAPSCAN600:
475 + case SNAPSCAN1236S:
476 case VUEGO310S: /* WG changed */
477 rgb_buf_init (pss);
478 break;
479 @@ -3268,7 +3322,7 @@
480
481
482 SANE_Status
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)
486 {
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);
491
492 + *plen = 0;
493 +
494 if (!pss->expected_data_len)
495 {
496 if (pss->child > 0)
497 @@ -3292,8 +3348,6 @@
498 return SANE_STATUS_EOF;
499 }
500
501 - *plen = 0;
502 -
503 if (pss->preview)
504 mode = pss->preview_mode;
505
506 @@ -3302,13 +3356,15 @@
507 maxlen /= 8;
508
509 /* reset maxlen to a scan line boundary */
510 + /* XXX Why is this here? The non-blocking client should have no
511 + buffer limits */
512 maxlen = (maxlen / pss->bytes_per_line) * pss->bytes_per_line;
513
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);
521
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 @@
525 {
526 case SNAPSCAN310:
527 case SNAPSCAN600:
528 + case SNAPSCAN1236S:
529 case VUEGO310S: /* WG changed */
530 transferred_bytes = transfer_data_diff (buf, pss);
531 break;
532 @@ -3466,7 +3523,7 @@
533 }
534
535 void
536 -sane_snapscan_cancel (SANE_Handle h)
537 +sane_cancel (SANE_Handle h)
538 {
539 char *me = "sane_snapscan_cancel";
540 SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
541 @@ -3486,6 +3543,7 @@
542 {
543 case SNAPSCAN310:
544 case SNAPSCAN600:
545 + case SNAPSCAN1236S:
546 case VUEGO310S: /* WG changed */
547 rgb_buf_clean (pss);
548 break;
549 @@ -3506,7 +3564,7 @@
550 }
551
552 SANE_Status
553 -sane_snapscan_set_io_mode (SANE_Handle h, SANE_Bool m)
554 +sane_set_io_mode (SANE_Handle h, SANE_Bool m)
555 {
556 static char me[] = "sane_snapscan_set_io_mode";
557 SnapScan_Scanner *pss = (SnapScan_Scanner *) h;
558 @@ -3541,7 +3599,7 @@
559 }
560
561 SANE_Status
562 -sane_snapscan_get_select_fd (SANE_Handle h, SANE_Int * fd)
563 +sane_get_select_fd (SANE_Handle h, SANE_Int * fd)
564 {
565 static char me[] = "sane_snapscan_get_select_fd";
566 SnapScan_Scanner *pss = (SnapScan_Scanner *) h;