📄 udcfgtxt.c
字号:
static
BOOL
WINAPI
StoreNewTopicCfg (TOPIC_CFG *pTopic)
{
BOOL status;
LPTOPIC_CFG lpTopicCfg;
CHAINSCANNER item_scanner;
/* initialize return value */
status = FALSE;
/* check whether there is already a topic with identical name */
lpTopicCfg = (LPTOPIC_CFG) FindFirstItem (&TopicCfgList, SCAN_FROM_HEAD,
TopicCfgNameMatch,
(LPSTR) pTopic->tc_name,
&item_scanner);
if (lpTopicCfg == NULL) {
/* topic name is unique */
/* allocate new structure from heap */
lpTopicCfg = TopicCfgAlloc();
if (lpTopicCfg != NULL) {
/* copy contents to new structure */
*lpTopicCfg = *pTopic;
/* add topic to list */
TopicCfgAddToList (lpTopicCfg);
/* indicate success */
status = TRUE;
}
}
/* indicate success or failure */
return (status);
} /* StoreNewTopicCfg */
/***********************************************************************
***********************************************************************
* String Scanning Routines *
***********************************************************************
***********************************************************************/
/**************************************************************************/
static
VOID
WINAPI
GetParamName (char **source_ptr, char *dest_ptr, int buf_len)
{
int len;
char ch;
char *scan_ptr;
/* get scanning pointer */
scan_ptr = *source_ptr;
/* scan until end of name found */
len = 0;
ch = *scan_ptr;
while ((ch) && (ch != '=') && (ch != ' ') && (ch != ';')) {
if (len < buf_len-1) {
*(dest_ptr++) = ch;
len++;
}
ch = *(++scan_ptr);
}
/* append '=' sign or ';' if found */
if ((ch == '=') || (ch == ';')) {
if (len < buf_len-1) {
*(dest_ptr++) = ch;
len++;
}
ch = *(++scan_ptr);
}
/* terminate string */
*dest_ptr = '\0';
/* return updated pointer */
*source_ptr = scan_ptr;
} /* GetParamName */
/**************************************************************************/
static
BOOL
WINAPI
GetParamStr (char **source_ptr, char *dest_ptr, int buf_len)
{
BOOL ok;
char *scan_ptr;
int len;
char ch;
/* initialize return value */
ok = TRUE;
/* get scanning pointer */
scan_ptr = *source_ptr;
/* get characters till blank or ';' */
len = 0;
ch = *scan_ptr;
while ((ch) && (ch != ' ') && (ch != ';')) {
if (len < buf_len-1) {
*(dest_ptr++) = ch;
len++;
} else {
/* string too long */
ok = FALSE;
}
ch = *(++scan_ptr);
}
/* terminate string */
*dest_ptr = '\0';
/* return updated pointer */
*source_ptr = scan_ptr;
/* indicate success or failure */
return (ok);
} /* GetParamStr */
/**************************************************************************/
static
BOOL
WINAPI
GetParamNumber (char **source_ptr, unsigned long *lValue)
{
BOOL ok;
unsigned long lRetval;
char *scan_ptr;
char *stop_ptr;
int len;
char param_str [31];
char ch;
/* initialize return values */
ok = TRUE;
lRetval = 0;
/* get scanning pointer */
scan_ptr = *source_ptr;
/* get characters till blank or ';' */
len = 0;
ch = *scan_ptr;
while ((ch) && (ch != ' ') && (ch != ';')) {
if (len < sizeof(param_str)-1)
param_str[len++] = ch;
else
/* string too long */
ok = FALSE;
ch = *(++scan_ptr);
}
param_str [len] = '\0';
if (len > 0) {
/* check for hex number */
if ((param_str[0] == '0') && (toupper(param_str[1]) == 'X')) {
/* interpret string as hexadecimal number */
lRetval = strtoul (¶m_str[2], &stop_ptr, 16);
} else {
/* interpret string as decimal number */
lRetval = strtoul (param_str, &stop_ptr, 10);
}
/* check whether conversion was successful */
if (((int) (stop_ptr - param_str)) != len)
/* illegal digits, indicate error */
ok = FALSE;
} else {
/* no digits, indicate error */
ok = FALSE;
}
/* return updated scan pointer */
*source_ptr = scan_ptr;
/* return value, indicate success or failure */
*lValue = lRetval;
return (ok);
} /* GetParamNumber */
/***********************************************************************/
/** determine whether character is an octal digit **/
static
BOOL
WINAPI
IsOctalDigit (char ch)
{
return ((('0' <= ch) && (ch <= '7')));
} /* IsOctalDigit */
/***********************************************************************/
/** determine whether character is a hexadecimal digit **/
static
BOOL
WINAPI
IsHexDigit (char ch)
{
return ((('0' <= ch) && (ch <= '9')) ||
(('A' <= ch) && (ch <= 'F')) ||
(('a' <= ch) && (ch <= 'f')));
} /* IsHexDigit */
/***********************************************************************/
/** get c-type string, delimited by ", accepting control characters
returns TRUE if string found **/
static
BOOL
WINAPI
GetDelimitedString (char **source_ptr, char *dest_ptr,
unsigned long buf_len, unsigned long *dest_len,
BOOL *truncated, char *status)
{
BOOL bFound;
int digit_count;
char ch, delimiter;
char done, stat_val;
long digit_val;
BOOL enable_double_quotes, trunc;
char *scan_ptr;
char *next_ptr;
unsigned long len, max_len, saved_offs;
/* initialize return value */
bFound = FALSE;
/* get scanning pointer */
next_ptr = *source_ptr;
/* get delimiter character, if any (" ' etc.) */
if (next_ptr)
delimiter = *next_ptr;
else
delimiter = 0;
if ((next_ptr != NULL) && (delimiter != 0))
{
/* save starting point */
scan_ptr = next_ptr;
/* get dest buffer pointer, length */
if (dest_ptr != NULL)
/* use actual length indicated */
max_len = buf_len;
else
/* force max length to zero -- no characters stored */
max_len = 0;
/* initialize scanning variables */
len = 0;
trunc = FALSE;
enable_double_quotes = TRUE;
stat_val = 'n';
/* acquire characters of string */
done = FALSE;
ch = *(++next_ptr);
while (ch && (!done))
{
/* check for end delimiter */
if (ch == delimiter)
{
/* check for doubling, e.g. "" to input one " */
ch = *(++next_ptr);
if ((ch != delimiter) || !enable_double_quotes)
{
/* string closed properly, stop scanning */
if (stat_val == 'n')
/* no error indicators, indicate ok */
stat_val = 'y';
done = TRUE;
}
/* else, use doubled delimiter as a single quote character */
}
else
{
/* check for embedded character */
if (ch == 0x5C) /* \ backslash */
{
/* handle escape sequence */
ch = *(++next_ptr);
switch (ch)
{
case 0 : /* no more characters */
stat_val = 'x'; /* indicate error */
done = TRUE; /* and stop scanning */
break;
case 'a' :
ch = 0x07; /* audible bell */
break;
case 'b' :
ch = 0x08; /* backspace */
break;
case 'f' :
ch = 0x0C; /* formfeed */
break;
case 'n' :
ch = 0x0A; /* newline, linefeed */
break;
case 'r' :
ch = 0x0D; /* carriage return */
break;
case 't' :
ch = 0x09; /* tab (horizontal) */
break;
case 'v' :
ch = 0x0B; /* tab (vertical) */
break;
case 0x5C : /* \ */
ch = 0x5C; /* backslash */
break;
case 0x27 : /* ' */
ch = 0x27; /* single quote (apostrophe) */
break;
case 0x22 : /* " */
ch = 0x22; /* double quote */
break;
case 0x3F : /* ? */
ch = 0x3F; /* question mark */
break;
case 'x' :
case 'X' :
/* a string of hex digits for a char */
saved_offs = (unsigned long) (next_ptr - scan_ptr) - 1L;
ch = *(++next_ptr);
if (!IsHexDigit (ch))
{
/* invalid hex value, treat as chars */
stat_val = 'x'; /* indicate error */
/* restore pointer, char = X */
next_ptr = scan_ptr + saved_offs;
ch = *next_ptr;
break;
}
digit_val = 0;
while ((digit_val <= 15) && (IsHexDigit (ch)))
{
/* add digit to hex char value */
if (ch >= 'a')
ch -= 32;
if (ch > '9')
ch -= 7;
digit_val = (digit_val << 4) + (ch - '0');
ch = *(++next_ptr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -