⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utility.c

📁 IBE是一种非对称密码技术
💻 C
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/

#include "Utility.h"
#include "icstringutils.h"
#include "stringutil.h"

/* Assumes theString is NULL-terminated, and theStringLen is the length
 * up to the first NULL terminator.
 */
static unsigned int FindEndchar (
   char *theString,
   unsigned int theStringLen
   );

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 *line, *start;
  int max, code = 0;
  unsigned int currentLen, newLen;

  currentLen = Z2Strlen(text);
	if (currentLen == 0)
	{
		*count = 0;
		*array = (void *) 0;
		goto err_return5;
	}

  currentLen++;
	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)
  {
    newLen = FindEndchar (start, currentLen);
    if (newLen == 1)
    {
      start++;
      currentLen--;
      if (currentLen != 0)
        continue;
      break;
    }

		if (*count == max)
		{
			max *= 2;
			*array = (char **)Z2Realloc(*array, sizeof(char *) * max);
		}
		line = (char *)Z3Malloc(newLen);
		if(line == (char*) 0)
		{
			code = VT_ERROR_MEMORY;
			goto err_return5;
		}
		Z2Memcpy(line, start, newLen - 1);
		line[newLen - 1] = 0;

    (*array)[*count] = line;
    (*count)++;

    currentLen -= newLen;
    start += newLen;
		if (currentLen == 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);
}

static unsigned int FindEndchar (
   char *theString,
   unsigned int theStringLen
   )
{
  unsigned int index;
  char theChar;

  for (index = 0; index < theStringLen; ++index)
  {
    theChar = theString[index];
    if ( (theChar == ' ' ) || (theChar == '\f') || (theChar == '\n') ||
         (theChar == '\r') || (theChar == '\t') || (theChar == '\v') ||
         (theChar == 0) )
      break;
  }

  return (index + 1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -