Beispiel #1
0
void CScanMgrDlg::InitScanner()
{
	if (_pTWAINApp)
	{
		_pTWAINApp->exit();
		SAFE_RELEASE(_pTWAINApp);
	}
	_pTWAINApp = new TwainApp(m_hWnd);

	TW_IDENTITY *pAppID = _pTWAINApp->getAppIdentity();

	pAppID->Version.MajorNum = 2;
	pAppID->Version.MinorNum = 1;
	pAppID->Version.Language = TWLG_ENGLISH_CANADIAN;
	pAppID->Version.Country = TWCY_CANADA;
	SSTRCPY(pAppID->Version.Info, sizeof(pAppID->Version.Info), "2.1.1");
	pAppID->ProtocolMajor = TWON_PROTOCOLMAJOR;
	pAppID->ProtocolMinor = TWON_PROTOCOLMINOR;
	pAppID->SupportedGroups = DF_APP2 | DG_IMAGE | DG_CONTROL;
	SSTRCPY(pAppID->Manufacturer, sizeof(pAppID->Manufacturer), "TWAIN Working Group");
	SSTRCPY(pAppID->ProductFamily, sizeof(pAppID->ProductFamily), "Sample");
	SSTRCPY(pAppID->ProductName, sizeof(pAppID->ProductName), "MFC Supported Caps");

	_pTWAINApp->connectDSM();
	if (_pTWAINApp->m_DSMState >= 3)
	{
		pTW_IDENTITY pID = NULL;
		int   i = 0;
		int   index = 0;
		int   nDefault = -1;

		// Emply the list the refill
		m_vecScanSrc.clear();

		if (NULL != (pID = _pTWAINApp->getDefaultDataSource())) // Get Default
		{
			nDefault = pID->Id;
		}
		USES_CONVERSION;
		while (NULL != (pID = _pTWAINApp->getDataSource((TW_INT16)i)))
		{
			m_vecScanSrc.push_back(A2T(pID->ProductName));
			if (LB_ERR == index)
			{
				break;
			}
			i++;
		}
		_pTWAINApp->disconnectDSM();
	}
	else
	{
		std::string strLog = "获取扫描仪列表 --> 连接扫描源失败";
		g_pLogger->information(strLog);
	}
}
Beispiel #2
0
/**
* The constructor for our class.  This is where we see if we have a
* file in the TWAINDSM_LOG environment variable.  If so, then we'll
* log stuff.  If not, then we'll log nothing.  TWAINDSM_LOGMODE
* selects how we open the file.  The default value is "w", which
* means it's wiped out each time a new session is started.  Setting
* this environmental to "a" will cause the log information to be
* appended to an existing file (a new one will still be created if
* needed...
*/
CTwnDsmLog::CTwnDsmLog()
{
  // Init stuff...
  m_ptwndsmlogimpl = new CTwnDsmLogImpl;

  // see if a logfile is to be used
  SGETENV(m_ptwndsmlogimpl->pod.m_logpath,NCHARS(m_ptwndsmlogimpl->pod.m_logpath),kLOGENV);

  // If we have a path, then get our mode...
  if (m_ptwndsmlogimpl->pod.m_logpath[0])
  {
    SGETENV(m_ptwndsmlogimpl->pod.m_logmode,NCHARS(m_ptwndsmlogimpl->pod.m_logmode),kLOGMODEENV);
    if (!m_ptwndsmlogimpl->pod.m_logmode[0])
    {
      // The default is to wipe the log clean...
      SSTRCPY(m_ptwndsmlogimpl->pod.m_logmode,sizeof(m_ptwndsmlogimpl->pod.m_logmode),"w");
    }

    // Only bother to allocate a buffer if logging is on...
    m_ptwndsmlogimpl->pod.m_message = (char*)calloc(TWNDSM_MAX_MSG,1);
    if (!m_ptwndsmlogimpl->pod.m_message)
    {
      kPANIC("Unable to allocate a buffer for logging...");
    }
  }
}
Beispiel #3
0
int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */
{
  char ident_str[6 * LCC_NAME_LEN];
  char ident_esc[12 * LCC_NAME_LEN];
  char command[1024] = "";
  lcc_response_t res;
  int status;
  size_t i;

  if ((c == NULL) || (vl == NULL) || (vl->values_len < 1)
      || (vl->values == NULL) || (vl->values_types == NULL))
  {
    lcc_set_errno (c, EINVAL);
    return (-1);
  }

  status = lcc_identifier_to_string (c, ident_str, sizeof (ident_str),
      &vl->identifier);
  if (status != 0)
    return (status);

  SSTRCATF (command, "PUTVAL %s",
      lcc_strescape (ident_esc, ident_str, sizeof (ident_esc)));

  if (vl->interval > 0)
    SSTRCATF (command, " interval=%i", vl->interval);

  if (vl->time > 0)
    SSTRCATF (command, "%u", (unsigned int) vl->time);
  else
    SSTRCAT (command, "N");

  for (i = 0; i < vl->values_len; i++)
  {
    if (vl->values_types[i] == LCC_TYPE_COUNTER)
      SSTRCATF (command, ":%"PRIu64, vl->values[i].counter);
    else if (vl->values_types[i] == LCC_TYPE_GAUGE)
    {
      if (isnan (vl->values[i].gauge))
        SSTRCPY (command, ":U");
      else
        SSTRCATF (command, ":%g", vl->values[i].gauge);
    }
  } /* for (i = 0; i < vl->values_len; i++) */

  status = lcc_sendreceive (c, command, &res);
  if (status != 0)
    return (status);

  if (res.status != 0)
  {
    LCC_SET_ERRSTR (c, "Server error: %s", res.message);
    lcc_response_free (&res);
    return (-1);
  }

  lcc_response_free (&res);
  return (0);
} /* }}} int lcc_putval */
Beispiel #4
0
void prep_annotators()
{
    char *p;

    while (nann < NAMAX && (p = get_param_multiple("annotator"))) {
	SSTRCPY(annotator[nann], p);
	nann++;
    }
}
Beispiel #5
0
/* Function putcal appends the caller's WFDB_Calinfo structure to the end of
   the calibration list. */
FINT putcal(WFDB_Calinfo *cal)
{
    SUALLOC(this_cle, 1, sizeof(struct cle));
    SSTRCPY(this_cle->sigtype, cal->sigtype);
    this_cle->caltype = cal->caltype;
    this_cle->low = cal->low;
    this_cle->high = cal->high;
    this_cle->scale = cal->scale;
    SSTRCPY(this_cle->units, cal->units);
    this_cle->next = NULL;

    if (first_cle) {
	prev_cle->next = this_cle;
	prev_cle = this_cle;
    }
    else
	first_cle = prev_cle = this_cle;
    return (0);
}
Beispiel #6
0
static void
config_misc(void)
{
     struct conf_sec *misc;

     misc = fetch_section_first(NULL, "misc");

     SSTRCPY(hftirc.conf.datef, fetch_opt_first(misc, "%m-%d %H:%M:%S", "date_format").str);
     hftirc.conf.bell   = fetch_opt_first(misc, "false", "bell").boolean;
     hftirc.conf.nicklist = fetch_opt_first(misc, "false", "nicklist_enable").boolean;
     hftirc.conf.lastlinepos = fetch_opt_first(misc, "false", "lastline_position").boolean;
}
Beispiel #7
0
int lcc_flush (lcc_connection_t *c, const char *plugin, /* {{{ */
    lcc_identifier_t *ident, int timeout)
{
  char command[1024] = "";
  lcc_response_t res;
  int status;

  if (c == NULL)
  {
    lcc_set_errno (c, EINVAL);
    return (-1);
  }

  SSTRCPY (command, "FLUSH");

  if (timeout > 0)
    SSTRCATF (command, " timeout=%i", timeout);

  if (plugin != NULL)
  {
    char buffer[2 * LCC_NAME_LEN];
    SSTRCATF (command, " plugin=%s",
        lcc_strescape (buffer, plugin, sizeof (buffer)));
  }

  if (ident != NULL)
  {
    char ident_str[6 * LCC_NAME_LEN];
    char ident_esc[12 * LCC_NAME_LEN];

    status = lcc_identifier_to_string (c, ident_str, sizeof (ident_str), ident);
    if (status != 0)
      return (status);

    SSTRCATF (command, " identifier=%s",
        lcc_strescape (ident_esc, ident_str, sizeof (ident_esc)));
  }

  status = lcc_sendreceive (c, command, &res);
  if (status != 0)
    return (status);

  if (res.status != 0)
  {
    LCC_SET_ERRSTR (c, "Server error: %s", res.message);
    lcc_response_free (&res);
    return (-1);
  }

  lcc_response_free (&res);
  return (0);
} /* }}} int lcc_flush */
Beispiel #8
0
/* Prompt for input, read a line from stdin, save it, return a pointer to it. */
char *prompt(char *prompt_string)
{
    char *p = NULL;

    fprintf(stderr, "%s: ", prompt_string);
    fflush(stderr);
    buf[0] = '\0';  /* clear previous content in case of EOF on stdin */
    if (fgets(buf, sizeof(buf), stdin)) {
        buf[strlen(buf)-1] = '\0';  /* discard trailing newline */
	if (buf[0])
	    SSTRCPY(p, buf);
    }
    return (p); /* Yes, it's a memory leak.  So sue me! */
}
Beispiel #9
0
static void
config_server(void)
{
     int i, j, n = 0;
     struct conf_sec **serv;
     struct opt_type *opt;
     ServInfo defsi = { "Hft", "irc.freenode.net", "", 6667, "hftircuser", " ", "HFTIrcuser", "HFTIrcuser"};

     if(!(serv = fetch_section(fetch_section_first(NULL, "servers"), "server"))
               || !(hftirc.conf.nserv = fetch_section_count(serv)))
     {
          hftirc.conf.serv = malloc(sizeof(ServInfo));
          hftirc.conf.serv[0] = defsi;
          hftirc.conf.nserv = 1;

          return;
     }

     hftirc.conf.serv = malloc(sizeof(ServInfo) * hftirc.conf.nserv);

     for(i = 0; i < hftirc.conf.nserv; ++i)
     {

          SSTRCPY(hftirc.conf.serv[i].adress,   fetch_opt_first(serv[i], "irc.hft-community.org", "adress").str);
          SSTRCPY(hftirc.conf.serv[i].name,     fetch_opt_first(serv[i], hftirc.conf.serv[i].adress, "name").str);
          SSTRCPY(hftirc.conf.serv[i].password, fetch_opt_first(serv[i], "", "password").str);
          SSTRCPY(hftirc.conf.serv[i].nick,     fetch_opt_first(serv[i], "hftircuser", "nickname").str);
          SSTRCPY(hftirc.conf.serv[i].username, fetch_opt_first(serv[i], "hftircuser", "username").str);
          SSTRCPY(hftirc.conf.serv[i].realname, fetch_opt_first(serv[i], "hftircuser", "realname").str);
          hftirc.conf.serv[i].port = fetch_opt_first(serv[i], "6667", "port").num;
          hftirc.conf.serv[i].ipv6 = fetch_opt_first(serv[i], "false", "ipv6").boolean;

          opt = fetch_opt(serv[i], "", "channel_autojoin");

          if((n = fetch_opt_count(opt)))
          {
               if((hftirc.conf.serv[i].nautojoin = n) > 127)
                    ui_print_buf(0, "HFTIrc configuration: section serv (%d), too many channel_autojoin (%d).", i, n);
               else
                    for(j = 0; j < n; ++j)
                         SSTRCPY(hftirc.conf.serv[i].autojoin[j], opt[j].str);
          }
     }
}
Beispiel #10
0
/* force_unique_signames() tries to ensure that each signal has a unique name.
   By default, the name of signal i is s[i].desc.  The names of any signals
   that are not unique are modified by appending a unique suffix to each
   such signal.  For example, if there are five signals with default names
        A, A, B, C, B
   they are renamed as
        A:1*, A:2*, B:3*, C, B:4*

   For efficiency, this function makes two assumptions that may cause it
   to fail to achieve its intended purpose in rare cases.  First, the unique
   suffix is limited to five characters, so that at most 999 signals can be
   renamed.  Second, if any default name ends with a string that matches a
   unique suffix, it will not be recognized as non-unique.  For example, if
   the default names are
       A, A, A:0*
   they are renamed as
       A:0*, A:1*, A:0*
   The format of the suffix has been chosen to make this unlikely.
 */
void force_unique_signames(void) {
    int i, j;

    SALLOC(sname, sizeof(char *), nsig);

    for (i = 0; i < nsig; i++) {
	for (j = i+1; j < nsig; j++) {
	    if (strcmp(s[i].desc, s[j].desc) == 0) {
		sname[i] = sname[j] = "change";
	    }
	}
    }

    for (i = j =  0; i < nsig; i++) {
	if (sname[i] == NULL && j < 1000) {
	    SSTRCPY(sname[i], s[i].desc);
	}
	else {
	    SUALLOC(sname[i], sizeof(char), strlen(s[i].desc) + 6);
	    sprintf(sname[i], "%s:%d*", s[i].desc, j++);
	}
    }	
}
Beispiel #11
0
int lcc_string_to_identifier (lcc_connection_t *c, /* {{{ */
    lcc_identifier_t *ident, const char *string)
{
  char *string_copy;
  char *host;
  char *plugin;
  char *plugin_instance;
  char *type;
  char *type_instance;

  string_copy = strdup (string);
  if (string_copy == NULL)
  {
    lcc_set_errno (c, ENOMEM);
    return (-1);
  }

  host = string_copy;
  plugin = strchr (host, '/');
  if (plugin == NULL)
  {
    LCC_SET_ERRSTR (c, "Malformed identifier string: %s", string);
    free (string_copy);
    return (-1);
  }
  *plugin = 0;
  plugin++;

  type = strchr (plugin, '/');
  if (type == NULL)
  {
    LCC_SET_ERRSTR (c, "Malformed identifier string: %s", string);
    free (string_copy);
    return (-1);
  }
  *type = 0;
  type++;

  plugin_instance = strchr (plugin, '-');
  if (plugin_instance != NULL)
  {
    *plugin_instance = 0;
    plugin_instance++;
  }

  type_instance = strchr (type, '-');
  if (type_instance != NULL)
  {
    *type_instance = 0;
    type_instance++;
  }

  memset (ident, 0, sizeof (*ident));

  SSTRCPY (ident->host, host);
  SSTRCPY (ident->plugin, plugin);
  if (plugin_instance != NULL)
    SSTRCPY (ident->plugin_instance, plugin_instance);
  SSTRCPY (ident->type, type);
  if (type_instance != NULL)
    SSTRCPY (ident->type_instance, type_instance);

  free (string_copy);
  return (0);
} /* }}} int lcc_string_to_identifier */
Beispiel #12
0
Tokenarray *parseline(char *line, Parsemode *pmode)
{
    int i, m = (strlen(line) + 1)/2, n = 0, state = 0;
    char d, *p, *q = NULL;

    SSTRCPY(tbuf, line);
    p = tbuf-1;
    SREALLOC(ta, sizeof(int)*2 + sizeof(char *)*m, 1);
    ta->maxtokens = m;

    if (pmode == NULL)
	pmode = &defpmode;
    else if (pmode->delim == NULL)
	pmode->delim = defpmode.delim;

    while (*(++p)) {	/* for each character in the line */

	/* is *p an escape character? */
	if (pmode->esc && *p == pmode->esc) {
	    if (*(p+1) == '\0')
		break;
	    if (state == 0) { /* start a new token */
		state = 1;
		ta->token[n++] = p;
	    }
	    p++;	/* include the next character in the token */
	    continue;
	}

	/* is *p the character needed to complete a quoted string? */
	if (q) {
	    if (*p == *q) { *p = '\0'; q = NULL; }
	    continue;
	}

	/* is *p a delimiter character? */
	i = 0;
        while (d = pmode->delim[i++]) {
	    if (*p == d) {
		*p = '\0';	/* replace delimiter with null */
		if (state == 0) { /* not in a token */
		    if (pmode->collapse == 0)
			ta->token[n++] = p;	/* count an empty token */
		}
		state = 0;
		break;
	    }
	}

	/* is *p an open-quote character? */
	i = 0;
	while (q = pmode->quotepair[i++]) {  /* q is an open-quote character */
	    if (*p == *q) { /* *p is first character of a quoted string */
		if (state == 0) { /* start a new token */
		    ta->token[n++] = p+1;
		    state = 1;
		}
		q++; /* *q is now the matching close-quote character */
		break;
	    }
	}

	if (d == '\0' && q == NULL) { 	/* p must be part of a token */
	    if (state == 0) {
		ta->token[n++] = p;	/* start a new token */
		state = 1;
	    }
	}
    }

    ta->ntokens = n;
    return (ta);
}
Beispiel #13
0
/* Function calopen reads the specified calibration file;  if called with
   a NULL argument, it takes the value of the environment variable WFDBCAL
   to be the name of the calibration file.  If the calibration file name
   does not begin with "+", calopen empties the calibration list first;
   otherwise, the "+" is discarded before attempting to open the file,
   which may be in any directory in the WFDB path.  If the file can be read,
   its contents are appended to the calibration list. */
FINT calopen(char *cfname)
{
    WFDB_FILE *cfile;
    char buf[128], *p1, *p2, *p3, *p4, *p5, *p6;

    /* If no calibration file is specified, return immediately. */
    if (cfname == NULL && (cfname = getenv("WFDBCAL")) == NULL &&
	(cfname = DEFWFDBCAL) == NULL)
	return (0);

    if (*cfname == '+')		/* don't empty the calibration list */
	cfname++;		/* discard the '+' prefix */
    else flushcal();		/* empty the calibration list */

    /* Quit if file can't be found or opened. */
    if ((cfile = wfdb_open(cfname, (char *)NULL, WFDB_READ)) == NULL) {
	wfdb_error("calopen: can't read calibration file %s\n", cfname);
	return (-2);
    }

    /* Read a line of the calibration file on each iteration.  See wfdbcal(5)
       for a description of the format. */
    while (wfdb_fgets(buf, 127, cfile)) {
	/* ignore leading whitespace */
	for (p1 = buf; *p1 == ' ' || *p1 == '\t' || *p1 == '\r'; p1++)
	    ;
	/* skip comments, empty lines, and improperly formatted lines */
	if (*p1 == '#' ||
	    (p1 = strtok(p1, "\t")) == NULL ||		    /* signal type */
	    (p2 = strtok((char *)NULL, " \t")) == NULL ||   /* low, or '-' */
	    (p3 = strtok((char *)NULL, " \t")) == NULL ||   /* high, or '-' */
	    (p4 = strtok((char *)NULL, " \t")) == NULL ||   /* pulse type */
	    (p5 = strtok((char *)NULL, " \t")) == NULL ||   /* scale */
	    (p6 = strtok((char *)NULL, " \t\r\n")) == NULL) /* units */
	    continue;

	/* This line appears to be a correctly formatted entry.  Allocate
	   memory for a calibration list entry. */
	SUALLOC(this_cle, 1, (sizeof(struct cle)));

	/* Fill in the fields of the new calibration list entry. */
	SSTRCPY(this_cle->sigtype, p1);
	if (strcmp(p2, "-") == 0) {
	    this_cle->caltype = WFDB_AC_COUPLED;
	    this_cle->low = 0.0;
	}
	else {
	    this_cle->caltype = WFDB_DC_COUPLED;
	    this_cle->low = atof(p2);
	}
	if (strcmp(p3, "-") == 0)
	    this_cle->high = this_cle->low = 0.0;
	else
	    this_cle->high = atof(p3);
	if (strcmp(p4, "square") == 0)
	    this_cle->caltype |= WFDB_CAL_SQUARE;
	else if (strcmp(p4, "sine") == 0)
	    this_cle->caltype |= WFDB_CAL_SINE;
	else if (strcmp(p4, "sawtooth") == 0)
	    this_cle->caltype |= WFDB_CAL_SAWTOOTH;
	/* otherwise pulse shape is undefined */
	this_cle->scale = atof(p5);
	SSTRCPY(this_cle->units, p6);
	this_cle->next = NULL;

	/* Append the new entry to the end of the list. */
	if (first_cle) {
	    prev_cle->next = this_cle;
	    prev_cle = this_cle;
	}
	else
	    first_cle = prev_cle = this_cle;
    }

    (void)wfdb_fclose(cfile);
    return (0);
}