📄 utility.c
字号:
/* Copyright 2003-2005, Voltage Security, all rights reserved.
*/
#include "Utility.h"
#include "icstringutils.h"
#include "stringutil.h"
int getXMLNodeValue (
int *out,
icXmlNode *node,
char *attrName,
VoltLibCtx *libCtx
)
{
char *valueStr;
int temp;
icTableGet (node->attributes, attrName, &valueStr, libCtx);
if (valueStr == (void *) 0)
return -1;
if (sscanf (valueStr, "%d", &temp) != 1)
return -1;
*out = temp;
return 0;
}
int makeStringArray (
char ***array,
int *count,
char *text,
VoltLibCtx *libCtx
)
{
char *start, *end;
char *line;
int max, code = 0;
if (Z2Strlen(text) == 0)
{
*count = 0;
*array = (void *) 0;
goto err_return5;
}
max = 10;
*count = 0;
*array = (char **)Z3Malloc(sizeof(char *) * max);
if(*array == (char**) 0)
{
code = VT_ERROR_MEMORY;
goto err_return5;
}
start = text;
while (1)
{
end = Z2Strchr(start, '\n');
if (end == (void *) 0)
end = start + Z2Strlen(start);
if (*count == max)
{
max *= 2;
*array = (char **)Z2Realloc(*array, sizeof(char *) * max);
}
line = (char *)Z3Malloc(sizeof(char) * (end - start + 1));
if(line == (char*) 0)
{
code = VT_ERROR_MEMORY;
goto err_return5;
}
Z2Strncpy(line, start, end - start);
line[end - start] = 0;
icTrim (line, libCtx);
if (Z2Strlen(line) > 0)
{
(*array)[*count] = line;
(*count)++;
}
else
{
Z2Free(line);
}
if (*end == 0) // strchr failed at top
break;
start = end + 1;
if (*start == 0)
break;
}
if (*count > 0)
{
*array = (char **)Z2Realloc(*array, sizeof(char *) * *count);
}
else
{
// We never found anything...
Z2Free(*array);
*array = (void *) 0;
}
err_return5:
return code;
}
void freeStringArray(char **array, int count, VoltLibCtx *libCtx)
{
int i;
for (i = 0; i < count; i++)
Z2Free(array[i]);
Z2Free(array);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -