sane-project-website/old-archive/1998-04/0082.html

236 wiersze
8.1 KiB
HTML

<!-- received="Wed Apr 8 13:14:39 1998 PDT" -->
<!-- sent="Wed, 8 Apr 1998 21:39:51 +0200 (MET DST)" -->
<!-- name="Oliver.Rauch@Wolfsburg.DE" -->
<!-- email="Oliver.Rauch@Wolfsburg.DE" -->
<!-- subject="find scanner via /proc/scsi/scsi" -->
<!-- id="199804081939.VAA11132@Babylon5.wolfsburg.de" -->
<!-- inreplyto="" -->
<title>sane-devel: find scanner via /proc/scsi/scsi</title>
<h1>find scanner via /proc/scsi/scsi</h1>
<a href="mailto:Oliver.Rauch@Wolfsburg.DE"><i>Oliver.Rauch@Wolfsburg.DE</i></a><br>
<i>Wed, 8 Apr 1998 21:39:51 +0200 (MET DST)</i>
<p>
<ul>
<li> <b>Messages sorted by:</b> <a href="date.html#82">[ date ]</a><a href="index.html#82">[ thread ]</a><a href="subject.html#82">[ subject ]</a><a href="author.html#82">[ author ]</a>
<!-- next="start" -->
<li> <b>Next message:</b> <a href="0083.html">Carlos Royo: "SANE &amp; Epson FilScan200"</a>
<li> <b>Previous message:</b> <a href="0081.html">Michael Sweet: "Re: What are pels and how can I convert them to mm?"</a>
<!-- nextthread="start" -->
<li> <b>Next in thread:</b> <a href="0083.html">Carlos Royo: "SANE &amp; Epson FilScan200"</a>
<li> <b>Reply:</b> <a href="0083.html">Carlos Royo: "SANE &amp; Epson FilScan200"</a>
<li> <b>Reply:</b> <a href="0086.html">David Wolfskill: "Re: find scanner via /proc/scsi/scsi"</a>
<li> <b>Reply:</b> <a href="0111.html">Ondrej Popp: "Re: find scanner via /proc/scsi/scsi"</a>
<li> <b>Reply:</b> <a href="0136.html">Ondrej Popp: "Re: find scanner via /proc/scsi/scsi"</a>
<!-- reply="end" -->
</ul>
<!-- body="start" -->
Hi,<br>
<p>
this is a little tool that reads /proc/scsi/scsi<br>
and tries to find out on which device the scanner is connected.<br>
<p>
To compile it, just call<br>
gcc readproc.c -o readproc<br>
<p>
To use it call<br>
readproc "vendor" "model"<br>
e.g.:<br>
readproc "UMAX " "UMAX S-12"<br>
<p>
Please tell me if the "guessed" devicename is correct or not!<br>
<p>
Bye<br>
Oliver<br>
<p>
---------------------------------------------------------------------<br>
<p>
/* readproc.c<br>
<p>
Copyright (C) 1998 Oliver Rauch<br>
<p>
This program is free software; you can redistribute it and/or<br>
modify it under the terms of the GNU General Public License as<br>
published by the Free Software Foundation; either version 2 of the<br>
License, or (at your option) any later version.<br>
<p>
This program is distributed in the hope that it will be useful, but<br>
WITHOUT ANY WARRANTY; without even the implied warranty of<br>
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
General Public License for more details.<br>
<p>
You should have received a copy of the GNU General Public License<br>
along with this program; if not, write to the Free Software<br>
Foundation, Inc., 59 Temple Place - Suite 330, Boston,<br>
MA 02111-1307, USA.<br>
<p>
*/<br>
<p>
/* --------------------------------------------------------------------------------------------------------- */<br>
<p>
#include &lt;stdio.h&gt;<br>
#include &lt;stdlib.h&gt;<br>
#include &lt;fcntl.h&gt;<br>
<p>
<p>
/* --------------------------------------------------------------------------------------------------------- */<br>
<p>
char *vendorstring = "Vendor:";<br>
char *modelstring = "Model:";<br>
char *revisionstring = "Rev:";<br>
<p>
/* --------------------------------------------------------------------------------------------------------- */<br>
<p>
char *killspaces(char *string)<br>
{<br>
char *start = string;<br>
while (*start == ' ') {start++;}<br>
return (start);<br>
}<br>
<p>
/* --------------------------------------------------------------------------------------------------------- */<br>
<p>
int get_scannerdevice(char *findvendor, char *findmodel)<br>
{<br>
FILE *proc_fd;<br>
char *procfile = "/proc/scsi/scsi";<br>
<p>
char line[256];<br>
<p>
char *string;<br>
char *vendor, *model, *revision;<br>
<p>
int number = -1;<br>
<p>
proc_fd = fopen(procfile,"r");<br>
if (proc_fd == 0)<br>
{<br>
fprintf(stderr, "ERROR: could not open %s!\n", procfile);<br>
return(-1);<br>
}<br>
<p>
while (!feof(proc_fd))<br>
{<br>
fgets(line, 256, proc_fd);<br>
string = killspaces(line);<br>
vendor=model=revision=NULL;<br>
<p>
while (*string != '\0')<br>
{<br>
if (strncmp(string, vendorstring, strlen(vendorstring)) == 0)<br>
{<br>
number++;<br>
string += strlen(vendorstring);<br>
string = killspaces(string);<br>
vendor = string;<br>
vendor[8] = '\0';<br>
string += 9;<br>
string = killspaces(string);<br>
}<br>
else if (strncmp(string, modelstring, strlen(modelstring)) == 0)<br>
{<br>
string += strlen(modelstring);<br>
string = killspaces(string);<br>
model = string;<br>
model[16] = '\0';<br>
string += 17;<br>
string = killspaces(string);<br>
}<br>
else if (strncmp(string, revisionstring, strlen(revisionstring)) == 0)<br>
{<br>
string += strlen(revisionstring);<br>
string = killspaces(string);<br>
revision = string;<br>
revision[4] = '\0';<br>
}<br>
else<br>
{ string++; }<br>
}<br>
<p>
if ( (vendor != NULL) &amp;&amp; (model != NULL) )<br>
{<br>
fprintf(stderr,"device = %d : vendor = \"%s\", model = \"%s\", revision = \"%s\"\n",<br>
number, vendor, model, revision);<br>
if ( (strncmp(vendor, findvendor, strlen(findvendor)) == 0)<br>
&amp;&amp; (strncmp(model, findmodel, strlen(findmodel)) == 0) )<br>
{<br>
fclose(proc_fd);<br>
return (number);<br>
}<br>
}<br>
}<br>
fclose(proc_fd);<br>
return (-1);<br>
}<br>
<p>
/* --------------------------------------------------------------------------------------------------------- */<br>
<p>
char *get_devicename(int device)<br>
{<br>
int dev_fd;<br>
int number = 0;<br>
char name[256];<br>
static char *device_name_list[] = { "/dev/uk", "/dev/sg", "/dev/sg", "/dev/gsc", };<br>
static char device_parameter_list[] = "00a0";<br>
const maxnum=4;<br>
<p>
while (number &lt; maxnum)<br>
{<br>
sprintf(name, "%s%c", device_name_list[number], device_parameter_list[number]+device);<br>
<p>
dev_fd = open(name,O_RDWR);<br>
if (dev_fd &gt; 1)<br>
{<br>
close(dev_fd);<br>
return ((char *)strdup(name));<br>
}<br>
<p>
number++;<br>
}<br>
<p>
return NULL;<br>
}<br>
<p>
/* --------------------------------------------------------------------------------------------------------- */<br>
<p>
main(int argc,char **argv)<br>
{<br>
int device;<br>
char *vendor, *model;<br>
<p>
fprintf(stdout,"readproc reads /proc/scsi/scsi\n"<br>
"and tries to find out on which device your scanner is connected\n");<br>
<p>
if (argc != 3)<br>
{<br>
fprintf(stderr,"Usage: %s \"vendor\" \"model\"\n", argv[0]);<br>
exit(-1);<br>
}<br>
<p>
vendor = argv[1];<br>
model = argv[2];<br>
<p>
fprintf(stdout,"looking for vendor = \"%s\", model = \"%s\"\n", vendor, model);<br>
device = get_scannerdevice(vendor, model);<br>
fprintf(stdout,"I guess the devicename is: %s\n",get_devicename(device));<br>
}<br>
<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="0083.html">Carlos Royo: "SANE &amp; Epson FilScan200"</a>
<li> <b>Previous message:</b> <a href="0081.html">Michael Sweet: "Re: What are pels and how can I convert them to mm?"</a>
<!-- nextthread="start" -->
<li> <b>Next in thread:</b> <a href="0083.html">Carlos Royo: "SANE &amp; Epson FilScan200"</a>
<li> <b>Reply:</b> <a href="0083.html">Carlos Royo: "SANE &amp; Epson FilScan200"</a>
<li> <b>Reply:</b> <a href="0086.html">David Wolfskill: "Re: find scanner via /proc/scsi/scsi"</a>
<li> <b>Reply:</b> <a href="0111.html">Ondrej Popp: "Re: find scanner via /proc/scsi/scsi"</a>
<li> <b>Reply:</b> <a href="0136.html">Ondrej Popp: "Re: find scanner via /proc/scsi/scsi"</a>
<!-- reply="end" -->
</ul>