Exemplo n.º 1
0
/*--------------------------------------------------------------------------*/
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
  char dev_name[PATH_MAX];
  size_t len;
  FILE *fp = NULL;

  DBG_INIT ();
  DBG (2, "sane_init (authorize %s null)\n", (authorize) ? "!=" : "==");
  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, 0);
/*  fp = sanei_config_open (AS6E_CONFIG_FILE);*/
  if (!fp)
    {
      return (attach ("as6edriver", 0));
    }

  while (fgets (dev_name, sizeof (dev_name), fp))
    {
      if (dev_name[0] == '#')	/* ignore line comments */
	continue;
      len = strlen (dev_name);
      if (dev_name[len - 1] == '\n')
	dev_name[--len] = '\0';
      if (!len)
	continue;		/* ignore empty lines */
/*      sanei_config_attach_matching_devices (dev_name, attach_one);*/
    }
  fclose (fp);
  return (SANE_STATUS_GOOD);
}
Exemplo n.º 2
0
/* 
   Find our devices
 */
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
  char config_line[PATH_MAX];
  size_t len;
  FILE *fp;

  DBG_INIT ();

#if 0
  DBG_LEVEL = 10;
#endif

  DBG (2, "sane_init: version_code %s 0, authorize %s 0\n",
       version_code == 0 ? "=" : "!=", authorize == 0 ? "=" : "!=");
  DBG (1, "sane_init: SANE Canon630u backend version %d.%d.%d from %s\n",
       SANE_CURRENT_MAJOR, V_MINOR, BUILD, PACKAGE_STRING);

  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);

  sanei_usb_init ();

  fp = sanei_config_open (CANONUSB_CONFIG_FILE);
  if (!fp)
    {
      /* no config-file: try these */
      attach_scanner ("/dev/scanner", 0);
      attach_scanner ("/dev/usbscanner", 0);
      attach_scanner ("/dev/usb/scanner", 0);
      return SANE_STATUS_GOOD;
    }

  DBG (3, "reading configure file %s\n", CANONUSB_CONFIG_FILE);

  while (sanei_config_read (config_line, sizeof (config_line), fp))
    {
      if (config_line[0] == '#')
	continue;		/* ignore line comments */

      len = strlen (config_line);

      if (!len)
	continue;		/* ignore empty lines */

      DBG (4, "attach_matching_devices(%s)\n", config_line);
      sanei_usb_attach_matching_devices (config_line, attach_one);
    }

  DBG (4, "finished reading configure file\n");

  fclose (fp);

  return SANE_STATUS_GOOD;
}
Exemplo n.º 3
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback __sane_unused__ authorize)
{
  SANE_Status 	ret;
  SANE_Word	vendor_id, product_id;
  
  DBG_INIT();
  
  DBG (1, "SANE backed for HP ScanJet 4500C/4570C/5500C/5550C/5590/7650 %u.%u.%u\n",
       SANE_CURRENT_MAJOR, V_MINOR, BUILD);
  DBG (1, "(c) Ilia Sotnikov <*****@*****.**>\n");

  if (version_code)
    *version_code = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, V_MINOR, BUILD);

  sanei_usb_init();

  sanei_usb_set_timeout (USB_TIMEOUT);

  scanners_list = NULL;

  ret = hp5590_vendor_product_id (SCANNER_HP4570, &vendor_id, &product_id);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp4570);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = hp5590_vendor_product_id (SCANNER_HP5550, &vendor_id, &product_id);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp5550);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = hp5590_vendor_product_id (SCANNER_HP5590, &vendor_id, &product_id);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp5590);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = hp5590_vendor_product_id (SCANNER_HP7650, &vendor_id, &product_id);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp7650);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  return SANE_STATUS_GOOD;
}
Exemplo n.º 4
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback cb)
{
  DBG_INIT ();
  DBG (2, "sane_init: Xerox backend (build %d), version %s null, authorize %s null\n", BACKEND_BUILD,
       (version_code) ? "!=" : "==", (cb) ? "!=" : "==");

  if (version_code)
    *version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, BACKEND_BUILD);

  sanei_usb_init ();
  return SANE_STATUS_GOOD;
}
Exemplo n.º 5
0
SANE_Status
sane_init (SANE_Int __sane_unused__ * version_code,
	   SANE_Auth_Callback __sane_unused__ authorize)
{
  DBG_INIT ();
  DBG (DBG_INFO, "This is panasonic kvs40xx driver\n");

  *version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 1);

  /* Initialize USB */
  sanei_usb_init ();

  return SANE_STATUS_GOOD;
}
Exemplo n.º 6
0
SANE_Status
sane_init (SANE_Int * version_code,
	   SANE_Auth_Callback __sane_unused__ authorize)
{

  if (version_code != NULL)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);

  DBG_INIT();

  sanei_usb_init ();

  return SANE_STATUS_GOOD;
}
Exemplo n.º 7
0
SANE_Status
sane_init( SANE_Int *versionP, SANE_Auth_Callback authorize )
{
	FILE *fp;
	SANE_Status status;

	DBG_INIT();
	DBG(DCODE, "sane_init: version %s null, authorize %s null\n", (versionP) ? "!=" : "==", (authorize) ? "!=" : "==");

	if( versionP != NULL )
		*versionP = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, V_MINOR, 0);

	status = SANE_STATUS_GOOD;
	if( (fp = sanei_config_open(ST400_CONFIG_FILE)) != NULL ) {
		char line[PATH_MAX], *str;
		size_t len, linenum;

		linenum = 0;
		DBG(DCODE, "sane_init: reading config file\n");
		while( sanei_config_read(line, sizeof(line), fp) ) {
			++linenum;
			str = line;
			if( str[0] == '#' )
				continue;	/* ignore comments */
			str = (char *)sanei_config_skip_whitespace(str);
			len = strlen(str);
			if( !len )
				continue;	/* ignore empty lines */
			if( strncmp(str, "option", 6) == 0 && isspace(str[6]) ) {
				DBG(DCODE, "sane_init: config line <%s>\n", line);
				status = st400_config_do_option(str+7, linenum);
			}
			else {
				DBG(DCODE, "sane_init: attaching device <%s>\n", line);
				sanei_config_attach_matching_devices(line, st400_attach_one);
			}
			if( status != SANE_STATUS_GOOD )
				break;
		}
		DBG(DCODE, "sane_init: closing config file\n");
		fclose(fp);
	}

	if( status == SANE_STATUS_GOOD && st400_devices == NULL ) {
		DBG(DCODE, "sane_init: attaching default device <%s>\n", ST400_DEFAULT_DEVICE);
		sanei_config_attach_matching_devices(ST400_DEFAULT_DEVICE, st400_attach_one);
	}

	return status;
}
Exemplo n.º 8
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
  char dev_name[PATH_MAX];
  size_t len;
  FILE *fp;

  authorize = authorize;		/* silence gcc */

  DBG_INIT ();

  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, 0);

  fp = sanei_config_open (ABATON_CONFIG_FILE);
  if (!fp)
    {
      /* default to /dev/scanner instead of insisting on config file */
      attach ("/dev/scanner", 0, SANE_FALSE);
      return SANE_STATUS_GOOD;
    }

  while (sanei_config_read (dev_name, sizeof (dev_name), fp))
    {
      if (dev_name[0] == '#')	/* ignore line comments */
	continue;

      len = strlen (dev_name);

      if (!len)
	continue;		/* ignore empty lines */

      if (strncmp (dev_name, "option", 6) == 0
	  && isspace (dev_name[6]))
	{
	  const char *str = dev_name + 7;

	  while (isspace (*str))
	    ++str;

	  continue;
	}

      sanei_config_attach_matching_devices (dev_name, attach_one);
    }
  fclose (fp);
  return SANE_STATUS_GOOD;
}
Exemplo n.º 9
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback __sane_unused__ authorize)
{
  FILE *fp;
  char dev_name[PATH_MAX];
  size_t len;

  DBG_INIT ();

  DBG (DBG_sane_init, "sane_init\n");

  DBG (DBG_error, "This is sane-leo version %d.%d-%d\n", SANE_CURRENT_MAJOR,
       V_MINOR, BUILD);
  DBG (DBG_error, "(C) 2002 by Frank Zago\n");

  if (version_code)
    {
      *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);
    }

  fp = sanei_config_open (LEO_CONFIG_FILE);
  if (!fp)
    {
      /* default to /dev/scanner instead of insisting on config file */
      attach_scanner ("/dev/scanner", 0);
      return SANE_STATUS_GOOD;
    }

  while (sanei_config_read (dev_name, sizeof (dev_name), fp))
    {
      if (dev_name[0] == '#')	/* ignore line comments */
	continue;
      len = strlen (dev_name);

      if (!len)
	continue;		/* ignore empty lines */

      sanei_config_attach_matching_devices (dev_name, attach_one);
    }

  fclose (fp);

  DBG (DBG_proc, "sane_init: leave\n");

  return SANE_STATUS_GOOD;
}
Exemplo n.º 10
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
  char devnam[PATH_MAX] = "/dev/scanner";
  FILE *fp;

  authorize = authorize;		/* silence gcc */

  DBG_INIT ();
  DBG (11, ">> sane_init\n");

#if defined PACKAGE && defined VERSION
  DBG (2, "sane_init: " PACKAGE " " VERSION "\n");
#endif

  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, 0);

  fp = sanei_config_open(RICOH_CONFIG_FILE);
  if (fp)
    {
      char line[PATH_MAX], *lp;
      size_t len;

      /* read config file */
      while (sanei_config_read (line, sizeof (line), fp))
        {
          if (line[0] == '#')           /* ignore line comments */
            continue;
          len = strlen (line);
  
          if (!len)
            continue;                   /* ignore empty lines */

	  /* skip white space: */
	  for (lp = line; isspace(*lp); ++lp);
          strcpy (devnam, lp);
        }
      fclose (fp);
    }
  sanei_config_attach_matching_devices (devnam, attach_one);
  DBG (11, "<< sane_init\n");
  return SANE_STATUS_GOOD;
}
Exemplo n.º 11
0
extern SANE_Status sane_hpaio_init(SANE_Int * pVersionCode, SANE_Auth_Callback authorize)
{
    int stat;

    DBG_INIT();
    InitDbus();

    DBG(8, "sane_hpaio_init(): %s %d\n", __FILE__, __LINE__);

    if( pVersionCode )
    {
       *pVersionCode = SANE_VERSION_CODE( 1, 0, 0 );
    }


    stat = orblite_init(pVersionCode, authorize);

    return stat;
}  /* sane_hpaio_init() */
Exemplo n.º 12
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
  char dev_name[PATH_MAX], *str;
  size_t len;
  FILE *fp;

  authorize = authorize;	/* stop gcc from complaining */
  DBG_INIT ();

  DBG (2, "SANE v4l backend version %d.%d build %d from %s\n", SANE_CURRENT_MAJOR,
       V_MINOR, BUILD, PACKAGE_STRING);

  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);

  fp = sanei_config_open (V4L_CONFIG_FILE);
  if (!fp)
    {
      DBG (2,
	   "sane_init: file `%s' not accessible (%s), trying /dev/video0\n",
	   V4L_CONFIG_FILE, strerror (errno));

      return attach ("/dev/video0", 0);
    }

  while (sanei_config_read (dev_name, sizeof (dev_name), fp))
    {
      if (dev_name[0] == '#')	/* ignore line comments */
	continue;
      len = strlen (dev_name);

      if (!len)
	continue;		/* ignore empty lines */

      /* Remove trailing space and trailing comments */
      for (str = dev_name; *str && !isspace (*str) && *str != '#'; ++str);
      attach (dev_name, 0);
    }
  fclose (fp);
  return SANE_STATUS_GOOD;
}
Exemplo n.º 13
0
/*
 * Called by SANE initially.
 * 
 * From the SANE spec:
 * This function must be called before any other SANE function can be
 * called. The behavior of a SANE backend is undefined if this
 * function is not called first. The version code of the backend is
 * returned in the value pointed to by version_code. If that pointer
 * is NULL, no version code is returned. Argument authorize is either
 * a pointer to a function that is invoked when the backend requires
 * authentication for a specific resource or NULL if the frontend does
 * not support authentication.
 */
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
    authorize = authorize;        /* get rid of compiler warning */
  
    DBG_INIT ();
    DBG (10, "sane_init: start\n");
  
    sanei_usb_init();
  
    if (version_code)
      *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);
  
    DBG (5, "sane_init: cardscan backend %d.%d.%d, from %s\n",
      SANE_CURRENT_MAJOR, V_MINOR, BUILD, PACKAGE_STRING);
  
    DBG (10, "sane_init: finish\n");
  
    return SANE_STATUS_GOOD;
}
Exemplo n.º 14
0
SANE_Status sane_init(SANE_Int* version_code, SANE_Auth_Callback authorize) {
    if (is_initialized) {
        return SANE_STATUS_INVAL;
    }
    SANE_Device *sane_device = NULL;
    SANE_Virtual_Device* virtual_device = NULL;
    SANE_Virtual_Device* previous_virtual_device = NULL;
    *version_code = SANE_VERSION_CODE(MAJOR, MINOR, BUILD);
    sane_device_list = malloc((DEVICE_COUNT + 1) * sizeof(sane_device));
    SANE_Int i;
    for (i = 0; i < DEVICE_COUNT; i++) {
        virtual_device = malloc(sizeof(*virtual_device));
        virtual_device->next = NULL;
        if (i == 0) {
            first_virtual_device = virtual_device;
        } else {
            previous_virtual_device->next = virtual_device;
        }
        previous_virtual_device = virtual_device;
        if (i == 0) {
            virtual_device->device.name = "Scanner 1";
        } else {
            virtual_device->device.name = "Scanner 2";
        }
        virtual_device->device.vendor = "SavvyArk";
        virtual_device->device.model = "Mock Scanner";
        virtual_device->device.type = "Virtual";
        virtual_device->open = SANE_FALSE;
        virtual_device->scanning = SANE_FALSE;
        virtual_device->cancelled = SANE_FALSE;
        virtual_device->pixels_per_line = 0;
        virtual_device->bytes_per_line = 0;
        virtual_device->eof = SANE_FALSE;
        virtual_device->page = 0;
        create_options(virtual_device);
        sane_device_list[i] = &virtual_device->device;
    }
    sane_device_list[i] = NULL;
    is_initialized = SANE_TRUE;
    return SANE_STATUS_GOOD;
}
Exemplo n.º 15
0
SANE_Status
sane_init (SANE_Int *version_code, SANE_Auth_Callback authorize)
{
  char dev_name[PATH_MAX];
  size_t len;
  FILE *fp;

  authorize = authorize; /* silence compilation warnings */

  DBG_INIT();

  sanei_thread_init();

  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, 0);

  fp = sanei_config_open (TAMARACK_CONFIG_FILE);
  if (!fp) {
    /* default to /dev/scanner instead of insisting on config file */
    attach ("/dev/scanner", 0);
    return SANE_STATUS_GOOD;
  }

  while (sanei_config_read (dev_name, sizeof (dev_name), fp)) {
    if (dev_name[0] == '#')		/* ignore line comments */
      continue;
    len = strlen (dev_name);
    
    if (!len)
      continue;			/* ignore empty lines */
    
    sanei_config_attach_matching_devices (dev_name, attach_one);
  }
  fclose (fp);
  return SANE_STATUS_GOOD;
}
Exemplo n.º 16
0
SANE_Status
sane_init (SANE_Int * piVersion, SANE_Auth_Callback pfnAuth)
{
  FILE *conf_fp;		/* Config file stream  */
  SANE_Char line[PATH_MAX];
  SANE_Char *str = NULL;
  SANE_String_Const proper_str;
  int nline = 0;

  /* prevent compiler from complaing about unused parameters */
  pfnAuth = pfnAuth;

  strcpy(usb_devfile, "/dev/usb/scanner0");
  _pFirstSaneDev = 0;
  iNumSaneDev = 0;

  InitHp5400_internal();


  DBG_INIT ();

  HP5400_DBG (DBG_MSG, "sane_init: SANE hp5400 backend version %d.%d-%d (from %s)\n",
       SANE_CURRENT_MAJOR, V_MINOR, BUILD, PACKAGE_STRING);

  sanei_usb_init ();

  conf_fp = sanei_config_open (HP5400_CONFIG_FILE);

  iNumSaneDev = 0;

  if (conf_fp)
    {
      HP5400_DBG (DBG_MSG, "Reading config file\n");

      while (sanei_config_read (line, sizeof (line), conf_fp))
	{
	  ++nline;

	  if (str)
	    {
	      free (str);
	    }

	  proper_str = sanei_config_get_string (line, &str);

	  /* Discards white lines and comments */
	  if (!str || proper_str == line || str[0] == '#')
	    {
	      HP5400_DBG (DBG_MSG, "Discarding line %d\n", nline);
	    }
	  else
	    {
	      /* If line's not blank or a comment, then it's the device
	       * filename or a usb directive. */
	      HP5400_DBG (DBG_MSG, "Trying to attach %s\n", line);
	      sanei_usb_attach_matching_devices (line, attach_one_device);
	    }
	}			/* while */
      fclose (conf_fp);
    }
  else
    {
      HP5400_DBG (DBG_ERR, "Unable to read config file \"%s\": %s\n",
	   HP5400_CONFIG_FILE, strerror (errno));
      HP5400_DBG (DBG_MSG, "Using default built-in values\n");
      attach_one_device (usb_devfile);
    }

  if (piVersion != NULL)
    {
      *piVersion = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);
    }


  return SANE_STATUS_GOOD;
}
Exemplo n.º 17
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
  char backend_name[PATH_MAX];
  size_t len;
  FILE *fp;
  int i;

  DBG_INIT();

  auth_callback = authorize;

  DBG(1, "sane_init: SANE dll backend version %s from %s\n", DLL_VERSION,
      PACKAGE_VERSION);

  /* chain preloaded backends together: */
  for (i = 0; i < NELEMS(preloaded_backends); ++i)
    {
      if (!preloaded_backends[i].name)
        continue;
      preloaded_backends[i].next = first_backend;
      first_backend = &preloaded_backends[i];
    }

  /* Return the version number of the sane-backends package to allow
     the frontend to print them. This is done only for net and dll,
     because these backends are usually called by the frontend. */
  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_DLL_V_MAJOR, SANE_DLL_V_MINOR,
				       SANE_DLL_V_BUILD);

  fp = sanei_config_open (DLL_CONFIG_FILE);
  if (!fp)
    {
      DBG(1, "sane_init: Couldn't open config file (%s): %s\n", 
	  DLL_CONFIG_FILE, strerror (errno));
      return SANE_STATUS_GOOD;    /* don't insist on config file */
    }

  while (sanei_config_read (backend_name, sizeof (backend_name), fp))
    {
      if (backend_name[0] == '#')       /* ignore line comments */
        continue;
      len = strlen (backend_name);

      if (!len)
        continue;               /* ignore empty lines */

      add_backend (backend_name, 0);
    }
  fclose (fp);

  fp = sanei_config_open (DLL_ALIASES_FILE);
  if (!fp)
    return SANE_STATUS_GOOD;    /* don't insist on aliases file */

  while (sanei_config_read (backend_name, sizeof (backend_name), fp))
    {
      if (backend_name[0] == '#')       /* ignore line comments */
        continue;
      len = strlen (backend_name);

      if (!len)
        continue;               /* ignore empty lines */

      add_alias (backend_name);
    }
  fclose (fp);
  return SANE_STATUS_GOOD;
}
Exemplo n.º 18
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
  SANE_Char line[PATH_MAX];
  SANE_Char *word, *end;
  SANE_String_Const cp;
  SANE_Int linenumber;
  FILE *fp;

  DBG_INIT ();
  DBG (2, "SANE Mustek USB backend version %d.%d build %d from %s\n", SANE_CURRENT_MAJOR,
       V_MINOR, BUILD, PACKAGE_STRING);

  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);

  DBG (5, "sane_init: authorize %s null\n", authorize ? "!=" : "==");


  num_devices = 0;
  first_dev = 0;
  first_handle = 0;
  devlist = 0;
  new_dev = 0;
  new_dev_len = 0;
  new_dev_alloced = 0;

  sanei_usb_init ();

  fp = sanei_config_open (MUSTEK_USB_CONFIG_FILE);
  if (!fp)
    {
      /* default to /dev/usb/scanner instead of insisting on config file */
      DBG (3, "sane_init: couldn't open config file `%s': %s. Using "
	   "/dev/usb/scanner directly\n", MUSTEK_USB_CONFIG_FILE,
	   strerror (errno));
      attach ("/dev/usb/scanner", 0, SANE_FALSE);
      return SANE_STATUS_GOOD;
    }
  linenumber = 0;
  DBG (4, "sane_init: reading config file `%s'\n", MUSTEK_USB_CONFIG_FILE);

  while (sanei_config_read (line, sizeof (line), fp))
    {
      word = 0;
      linenumber++;

      cp = sanei_config_get_string (line, &word);
      if (!word || cp == line)
	{
	  DBG (5, "sane_init: config file line %d: ignoring empty line\n",
	       linenumber);
	  if (word)
	    free (word);
	  continue;
	}
      if (word[0] == '#')
	{
	  DBG (5, "sane_init: config file line %d: ignoring comment line\n",
	       linenumber);
	  free (word);
	  continue;
	}

      if (strcmp (word, "option") == 0)
	{
	  free (word);
	  word = 0;
	  cp = sanei_config_get_string (cp, &word);

	  if (!word)
	    {
	      DBG (1, "sane_init: config file line %d: missing quotation mark?\n",
		   linenumber);
	      continue;
	    }

	  if (strcmp (word, "max_block_size") == 0)
	    {
	      free (word);
	      word = 0;
	      cp = sanei_config_get_string (cp, &word);
	      if (!word)
		{
		  DBG (1, "sane_init: config file line %d: missing quotation mark?\n",
		       linenumber);
		  continue;
		}

	      errno = 0;
	      max_block_size = strtol (word, &end, 0);
	      if (end == word)
		{
		  DBG (3, "sane-init: config file line %d: max_block_size "
		       "must have a parameter; using 8192 bytes\n",
		       linenumber);
		  max_block_size = 8192;
		}
	      if (errno)
		{
		  DBG (3,
		       "sane-init: config file line %d: max_block_size `%s' "
		       "is invalid (%s); using 8192 bytes\n", linenumber,
		       word, strerror (errno));
		  max_block_size = 8192;
		}
	      else
		{
		  DBG (3,
		       "sane_init: config file line %d: max_block_size set "
		       "to %d bytes\n", linenumber, max_block_size);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else if (strcmp (word, "1200ub") == 0)
	    {
	      if (new_dev_len > 0)
		{
		  /* this is a 1200 UB */
		  new_dev[new_dev_len - 1]->chip->scanner_type = MT_1200UB;
		  new_dev[new_dev_len - 1]->sane.model = "1200 UB";
		  DBG (3, "sane_init: config file line %d: `%s' is a Mustek "
		       "1200 UB\n", linenumber,
		       new_dev[new_dev_len - 1]->sane.name);
		}
	      else
		{
		  DBG (3, "sane_init: config file line %d: option "
		       "1200ub ignored, was set before any device "
		       "name\n", linenumber);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else if (strcmp (word, "1200cu") == 0)
	    {
	      if (new_dev_len > 0)
		{
		  /* this is a 1200 CU */
		  new_dev[new_dev_len - 1]->chip->scanner_type = MT_1200CU;
		  new_dev[new_dev_len - 1]->sane.model = "1200 CU";
		  DBG (3, "sane_init: config file line %d: `%s' is a Mustek "
		       "1200 CU\n", linenumber,
		       new_dev[new_dev_len - 1]->sane.name);
		}
	      else
		{
		  DBG (3, "sane_init: config file line %d: option "
		       "1200cu ignored, was set before any device "
		       "name\n", linenumber);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else if (strcmp (word, "1200cu_plus") == 0)
	    {
	      if (new_dev_len > 0)
		{
		  /* this is a 1200 CU Plus */
		  new_dev[new_dev_len - 1]->chip->scanner_type
		    = MT_1200CU_PLUS;
		  new_dev[new_dev_len - 1]->sane.model = "1200 CU Plus";
		  DBG (3, "sane_init: config file line %d: `%s' is a Mustek "
		       "1200 CU Plus\n", linenumber,
		       new_dev[new_dev_len - 1]->sane.name);
		}
	      else
		{
		  DBG (3, "sane_init: config file line %d: option "
		       "1200cu_plus ignored, was set before any device "
		       "name\n", linenumber);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else if (strcmp (word, "600cu") == 0)
	    {
	      if (new_dev_len > 0)
		{
		  /* this is a 600 CU */
		  new_dev[new_dev_len - 1]->chip->scanner_type = MT_600CU;
		  new_dev[new_dev_len - 1]->sane.model = "600 CU";
		  DBG (3, "sane_init: config file line %d: `%s' is a Mustek "
		       "600 CU\n", linenumber,
		       new_dev[new_dev_len - 1]->sane.name);
		}
	      else
		{
		  DBG (3, "sane_init: config file line %d: option "
		       "600cu ignored, was set before any device "
		       "name\n", linenumber);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else
	    {
	      DBG (3, "sane_init: config file line %d: option "
		   "%s is unknown\n", linenumber, word);
	      if (word)
		free (word);
	      word = 0;
	    }
	}
      else
	{
	  new_dev_len = 0;
	  DBG (4, "sane_init: config file line %d: trying to attach `%s'\n",
	       linenumber, line);
	  sanei_usb_attach_matching_devices (line, attach_one_device);
	  if (word)
	    free (word);
	  word = 0;
	}
    }

  if (new_dev_alloced > 0)
    {
      new_dev_len = new_dev_alloced = 0;
      free (new_dev);
    }

  fclose (fp);
  DBG (5, "sane_init: exit\n");

  return SANE_STATUS_GOOD;
}
Exemplo n.º 19
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback __sane_unused__ authorize)
{

  char f[] = "sane_init";
  char dev_name[PATH_MAX], *p;
  size_t len;
  FILE *fp;
  int baud;

  DBG_INIT ();

  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, 0);

  fp = sanei_config_open (DC210_CONFIG_FILE);

  /* defaults */
  Camera.baud = DEFAULT_BAUD_RATE;
  Camera.tty_name = DEFAULT_TTY;

  if (!fp)
    {
      /* default to /dev/whatever instead of insisting on config file */
      DBG (1, "%s:  missing config file '%s'\n", f, DC210_CONFIG_FILE);
    }
  else
    {
      while (sanei_config_read (dev_name, sizeof (dev_name), fp))
	{
	  dev_name[sizeof (dev_name) - 1] = '\0';
	  DBG (20, "%s:  config- %s\n", f, dev_name);

	  if (dev_name[0] == '#')
	    continue;		/* ignore line comments */
	  len = strlen (dev_name);
	  if (!len)
	    continue;		/* ignore empty lines */
	  if (strncmp (dev_name, "port=", 5) == 0)
	    {
	      p = strchr (dev_name, '/');
	      if (p)
		Camera.tty_name = strdup (p);
	      DBG (20, "Config file port=%s\n", Camera.tty_name);
	    }
	  else if (strncmp (dev_name, "baud=", 5) == 0)
	    {
	      baud = atoi (&dev_name[5]);
	      switch (baud)
		{
		case 9600:
		  Camera.baud = B9600;
		  break;
		case 19200:
		  Camera.baud = B19200;
		  break;
		case 38400:
		  Camera.baud = B38400;
		  break;
#ifdef B57600
		case 57600:
		  Camera.baud = B57600;
		  break;
#endif
#ifdef B115200
		case 115200:
		  Camera.baud = B115200;
		  break;
#endif
		}
	      DBG (20, "Config file baud=%d\n", Camera.baud);
	    }
	  else if (strcmp (dev_name, "dumpinquiry") == 0)
	    {
	      dumpinquiry = SANE_TRUE;
	    }
	  else if (strncmp (dev_name, "cmdrespause=", 12) == 0)
	    {
	      cmdrespause = atoi (&dev_name[12]);
	      DBG (20, "Config file cmdrespause=%lu\n", cmdrespause);
	    }
	  else if (strncmp (dev_name, "breakpause=", 11) == 0)
	    {
	      breakpause = atoi (&dev_name[11]);
	      DBG (20, "Config file breakpause=%lu\n", breakpause);
	    }
	}
      fclose (fp);
    }

  if (init_dc210 (&Camera) == -1)
    return SANE_STATUS_INVAL;

  if (get_info (&Camera) == -1)
    {
      DBG (2, "error: could not get info\n");
      close_dc210 (Camera.fd);
      return SANE_STATUS_INVAL;
    }
  if (Camera.pic_taken == 0)
    {
      sod[DC210_OPT_IMAGE_NUMBER].cap |= SANE_CAP_INACTIVE;
      image_range.min = 0;
      image_range.max = 0;
    }
  else
    {
      sod[DC210_OPT_IMAGE_NUMBER].cap &= ~SANE_CAP_INACTIVE;
      image_range.min = 1;
      image_range.max = Camera.pic_taken;
    }


  /* load the current images array */
  Camera.Pictures = get_pictures_info ();

  if (Camera.pic_taken == 0)
    {
      Camera.current_picture_number = 0;
      parms.bytes_per_line = 0;
      parms.pixels_per_line = 0;
      parms.lines = 0;
    }
  else
    {
      Camera.current_picture_number = 1;
      if (Camera.Pictures[Camera.current_picture_number - 1].low_res)
	{
	  parms.bytes_per_line = 640 * 3;
	  parms.pixels_per_line = 640;
	  parms.lines = 480;
	}
      else
	{
	  parms.bytes_per_line = 1152 * 3;
	  parms.pixels_per_line = 1152;
	  parms.lines = 864;
	}
    }

  if (dumpinquiry)
    {
      DBG (0, "\nCamera information:\n~~~~~~~~~~~~~~~~~\n\n");
      DBG (0, "Model...........: DC%x\n", Camera.model);
      DBG (0, "Firmware version: %d.%d\n", Camera.ver_major,
	   Camera.ver_minor);
      DBG (0, "Pictures........: %d/%d\n", Camera.pic_taken,
	   Camera.pic_taken + Camera.pic_left);
      DBG (0, "Resolution......: %s\n",
	   Camera.flags.low_res ? "low" : "high");
      DBG (0, "Battery state...: %s\n",
	   Camera.flags.low_batt ? "low" : "good");
    }

  return SANE_STATUS_GOOD;
}