📄 ictable.c
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "icTable.h"
#include "errorctx.h"
int icTableCreate (
icTable **entry,
VoltLibCtx *libCtx
)
{
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_SET_FNCT_LINE (fnctLine)
*entry = (icTable *)Z3Malloc (sizeof (icTable));
if ((*entry) != (icTable *)0)
{
Z2Memset (*entry, 0, sizeof (icTable));
return (0);
}
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, VT_ERROR_MEMORY, VT_ERROR_TYPE_PRIMARY, fnctLine,
"icTableCreate", (char *)0)
return (VT_ERROR_MEMORY);
}
void icTableFree (
icTable **table,
VoltLibCtx *libCtx
)
{
icTable *currentTable, *nextTable;
/* Anything to free?
*/
if (table == (icTable **)0)
return;
currentTable = *table;
while (currentTable != (icTable *)0)
{
nextTable = (icTable *)(currentTable->next);
Z2Free (currentTable->key);
Z2Free (currentTable->value);
Z2Free (currentTable);
currentTable = nextTable;
}
*table = (icTable *)0;
}
int icTablePut (
icTable *table,
char *key,
char *value,
VoltLibCtx *libCtx
)
{
int status;
icTable *currentTable, *lastTable;
icTable *newTable = (icTable *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Cycle through the Table looking for the entry. If found just replace
* the value.
*/
currentTable = table;
do
{
if (Z2Strcmp (currentTable->key, key) == 0)
{
Z2Free (currentTable->value);
currentTable->value = (char *)0;
VOLT_SET_FNCT_LINE (fnctLine)
status = Z2Strdup (value, &(currentTable->value));
break;
}
lastTable = currentTable;
currentTable = (icTable *)(currentTable->next);
} while (currentTable != (icTable *)0);
/* If currentTable is not NULL, either we found a matching key and
* replaced the value, or there was an error. Either way, we're
* done. If currentTable is NULL, we went through the list without
* a match, we need to build a new table and place it at the end of
* the link list.
*/
if (currentTable != (icTable *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = icTableCreate (&newTable, libCtx);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = Z2Strdup (key, &(newTable->key));
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = Z2Strdup (value, &(newTable->value));
if (status != 0)
break;
lastTable->next = (Pointer)newTable;
} while (0);
if (status == 0)
return (0);
/* If there was an error, free any memory we allocated.
*/
icTableFree (&newTable, libCtx);
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, 0, fnctLine, "icTablePut", (char *)0)
return (status);
}
void icTableGet (
icTable *table,
char *key,
char **value,
VoltLibCtx *libCtx
)
{
icTable *currentTable = table;
*value = (char *)0;
/* Go through the Table checking to see if the keys match.
*/
while (currentTable != (icTable *)0)
{
if (Z2Strcmp (currentTable->key, key) == 0)
{
*value = currentTable->value;
return;
}
currentTable = (icTable *)(currentTable->next);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -