sane-project-website/old-archive/1999-04/0392.html

225 wiersze
8.3 KiB
HTML

<!-- received="Tue Apr 27 15:28:36 1999 PDT" -->
<!-- sent="Wed, 28 Apr 1999 00:32:11 +0200" -->
<!-- name="Petter Reinholdtsen" -->
<!-- email="pere@hungry.com" -->
<!-- subject="Patch: sane_init() may fail" -->
<!-- id="199904272232.AAA24299@lee.Cc.Uit.No" -->
<!-- inreplyto="" -->
<title>sane-devel: Patch: sane_init() may fail</title>
<h1>Patch: sane_init() may fail</h1>
<b>Petter Reinholdtsen</b> (<a href="mailto:pere@hungry.com"><i>pere@hungry.com</i></a>)<br>
<i>Wed, 28 Apr 1999 00:32:11 +0200</i>
<p>
<ul>
<li> <b>Messages sorted by:</b> <a href="date.html#392">[ date ]</a><a href="index.html#392">[ thread ]</a><a href="subject.html#392">[ subject ]</a><a href="author.html#392">[ author ]</a>
<!-- next="start" -->
<li> <b>Next message:</b> <a href="0393.html">Petter Reinholdtsen: "Patch: Autogenerate lsm entry"</a>
<li> <b>Previous message:</b> <a href="0391.html">Petter Reinholdtsen: "Re: May sane_init fail?"</a>
<!-- nextthread="start" -->
<!-- reply="end" -->
</ul>
<!-- body="start" -->
Here is my patch to document and implement the changes required to let<br>
sane_init() fail. It is relative to SANE 1.0.1.<br>
<p>
diff -ur sane-1.0.1/ChangeLog sane-1.0.1-pere/ChangeLog<br>
--- sane-1.0.1/ChangeLog Mon Apr 19 18:21:33 1999<br>
+++ sane-1.0.1-pere/ChangeLog Wed Apr 28 00:28:01 1999<br>
@@ -1,3 +1,10 @@<br>
+1999-04-28 Petter Reinholdtsen &lt;<a href="mailto:pere@td.org.uit.no">pere@td.org.uit.no</a>&gt;<br>
+<br>
+ * doc/sane.tex frontend/scanimage.c frontend/xcam.c<br>
+ frontend/xscanimage.c: Specified valid return values for<br>
+ sane_init(), and made sure all our frontends checks for the<br>
+ correct return value before using other methods in the backend.<br>
+<br>
1999-04-19 David Mosberger-Tang &lt;<a href="mailto:David.Mosberger@acm.org">David.Mosberger@acm.org</a>&gt;<br>
<br>
* Version 1.0.1 released.<br>
diff -ur sane-1.0.1/doc/sane.tex sane-1.0.1-pere/doc/sane.tex<br>
--- sane-1.0.1/doc/sane.tex Sat Apr 3 23:16:07 1999<br>
+++ sane-1.0.1-pere/doc/sane.tex Wed Apr 28 00:17:31 1999<br>
@@ -1052,9 +1052,11 @@<br>
<br>
This function must be called before any other SANE function can be<br>
called. The behavior of a SANE backend is undefined if this function<br>
-is not called first. The version code of the backend is returned in<br>
-the value pointed to by \code{version\_code}. If that pointer is<br>
-\code{NULL}, no version code is returned. <br>
+is not called first. The behavior of a backend is also undefined if<br>
+this function returns anything other then \code{SANE\_STATUS\_GOOD}.<br>
+The version code of the backend is returned in the value pointed to by<br>
+\code{version\_code}. If that pointer is \code{NULL}, no version code<br>
+is returned.<br>
Argument \code{authorize} is either a pointer to a function that is<br>
invoked when the backend requires authentication for a specific<br>
resource or \code{NULL} if the frontend does not support<br>
@@ -1064,6 +1066,16 @@<br>
SANE_Status sane_init (SANE_Int * version_code,<br>
SANE_Authorization_Callback authorize);<br>
\end{verbatim}<br>
+\end{quote}<br>
+<br>
+This function may fail with one of the following status codes.<br>
+\begin{quote}<br>
+\begin{description}<br>
+\item[\code{SANE\_STATUS\_UNSUPPORTED}:] The backend is not supported on <br>
+ this machines current configuration.<br>
+\item[\code{SANE\_STATUS\_NO\_MEM}:] An insufficent amount of memory<br>
+ is available to complete. Try later when more memory is available.<br>
+\end{description}<br>
\end{quote}<br>
<br>
The authorization function may be called by a backend in response to<br>
diff -ur sane-1.0.1/frontend/scanimage.c sane-1.0.1-pere/frontend/scanimage.c<br>
--- sane-1.0.1/frontend/scanimage.c Fri Mar 5 07:13:49 1999<br>
+++ sane-1.0.1-pere/frontend/scanimage.c Wed Apr 28 00:28:44 1999<br>
@@ -73,6 +73,7 @@<br>
static SANE_Handle device;<br>
static int verbose;<br>
static int test;<br>
+static int list;<br>
static int help;<br>
static const char * prog_name;<br>
static SANE_Option_Descriptor window_option[2];<br>
@@ -1041,6 +1042,29 @@<br>
free (image.data);<br>
}<br>
<br>
+void<br>
+list_devices(void)<br>
+{<br>
+ const SANE_Device ** device_list;<br>
+ SANE_Status status;<br>
+ int i;<br>
+<br>
+ status = sane_get_devices (&amp;device_list, SANE_FALSE);<br>
+ if (status != SANE_STATUS_GOOD)<br>
+ {<br>
+ fprintf (stderr, "%s: sane_get_devices() failed: %s\n",<br>
+ prog_name, sane_strstatus (status));<br>
+ return;<br>
+ }<br>
+<br>
+ for (i = 0; device_list[i]; ++i)<br>
+ {<br>
+ printf ("device `%s' is a %s %s %s\n",<br>
+ device_list[i]-&gt;name, device_list[i]-&gt;vendor,<br>
+ device_list[i]-&gt;model, device_list[i]-&gt;type);<br>
+ }<br>
+}<br>
+<br>
int<br>
main (int argc, char **argv)<br>
{<br>
@@ -1060,8 +1084,6 @@<br>
else<br>
prog_name = argv[0];<br>
<br>
- sane_init (0, 0);<br>
-<br>
/* make a first pass through the options with error printing and argument<br>
permutation disabled: */<br>
opterr = 0;<br>
@@ -1079,27 +1101,7 @@<br>
case 'h': help = 1; break;<br>
case 'v': ++verbose; break;<br>
case 'T': test= 1; break;<br>
- case 'L':<br>
- {<br>
- int i;<br>
-<br>
- status = sane_get_devices (&amp;device_list, SANE_FALSE);<br>
- if (status != SANE_STATUS_GOOD)<br>
- {<br>
- fprintf (stderr, "%s: sane_get_devices() failed: %s\n",<br>
- prog_name, sane_strstatus (status));<br>
- exit (1);<br>
- }<br>
-<br>
- for (i = 0; device_list[i]; ++i)<br>
- {<br>
- printf ("device `%s' is a %s %s %s\n",<br>
- device_list[i]-&gt;name, device_list[i]-&gt;vendor,<br>
- device_list[i]-&gt;model, device_list[i]-&gt;type);<br>
- }<br>
- exit (0);<br>
- }<br>
-<br>
+ case 'L': list = 1; break;<br>
case 'V':<br>
printf ("scanimage (%s) %s\n", PACKAGE, VERSION);<br>
exit (0);<br>
@@ -1122,6 +1124,18 @@<br>
-v, --verbose give even more status messages\n\<br>
-V, --version print version information\n",<br>
prog_name);<br>
+<br>
+ if (SANE_STATUS_GOOD != sane_init (NULL, NULL))<br>
+ {<br>
+ fprintf(stderr,"sane_init() failed. Unable to do anything. Exiting\n");<br>
+ return(1);<br>
+ }<br>
+<br>
+ if (list)<br>
+ {<br>
+ list_devices();<br>
+ return(0);<br>
+ }<br>
<br>
if (!devname)<br>
{<br>
diff -ur sane-1.0.1/frontend/xcam.c sane-1.0.1-pere/frontend/xcam.c<br>
--- sane-1.0.1/frontend/xcam.c Sat Apr 4 06:39:20 1998<br>
+++ sane-1.0.1-pere/frontend/xcam.c Tue Apr 27 23:54:56 1999<br>
@@ -894,7 +894,11 @@<br>
/* turn on by default as we don't support graphical geometry selection */<br>
preferences.advanced = 1;<br>
<br>
- sane_init (NULL, 0);<br>
+ if (SANE_STATUS_GOOD != sane_init (NULL, NULL))<br>
+ {<br>
+ fprintf(stderr,"sane_init() failed. Unable to do anything. Exiting\n");<br>
+ return(1);<br>
+ }<br>
<br>
gdk_set_show_events (0);<br>
gtk_init (&amp;argc, &amp;argv);<br>
diff -ur sane-1.0.1/frontend/xscanimage.c sane-1.0.1-pere/frontend/xscanimage.c<br>
--- sane-1.0.1/frontend/xscanimage.c Sat Apr 3 06:07:57 1999<br>
+++ sane-1.0.1-pere/frontend/xscanimage.c Tue Apr 27 23:56:42 1999<br>
@@ -257,7 +257,12 @@<br>
nargs, nreturn_vals,<br>
args, return_vals);<br>
<br>
- sane_init (0, 0);<br>
+ if (SANE_STATUS_GOOD != sane_init (NULL, NULL))<br>
+ {<br>
+ fprintf(stderr,"sane_init() failed. Unable to do anything. Exiting\n");<br>
+ return(1);<br>
+ }<br>
+<br>
sane_get_devices (&amp;devlist, SANE_FALSE);<br>
<br>
for (i = 0; devlist[i]; ++i)<br>
<p>
<pre>
--
##&gt; Petter Reinholdtsen &lt;## | <a href="mailto:pere@td.org.uit.no">pere@td.org.uit.no</a>
<a href="http://www.hungry.com/~pere/">http://www.hungry.com/~pere/</a> O- | Go Mozilla, go! Go!
<p>
<pre>
--
Source code, list archive, and docs: <a href="http://www.mostang.com/sane/">http://www.mostang.com/sane/</a>
To unsubscribe: echo unsubscribe sane-devel | mail <a href="mailto:majordomo@mostang.com">majordomo@mostang.com</a>
</pre>
<!-- body="end" -->
<p>
<ul>
<!-- next="start" -->
<li> <b>Next message:</b> <a href="0393.html">Petter Reinholdtsen: "Patch: Autogenerate lsm entry"</a>
<li> <b>Previous message:</b> <a href="0391.html">Petter Reinholdtsen: "Re: May sane_init fail?"</a>
<!-- nextthread="start" -->
<!-- reply="end" -->
</ul>