Пример #1
0
extern	Bool
SetValueInteger(
	ValueStruct	*val,
	int			ival)
{
	Bool	rc;
	char	str[SIZE_NUMBUF+1];
	Bool	fMinus;

	if		(  val  ==  NULL  ) {
		fprintf(stderr,"no ValueStruct\n");
		rc = FALSE;
	} else {
		ValueIsNonNil(val);
		switch	(ValueType(val)) {
		  case	GL_TYPE_CHAR:
		  case	GL_TYPE_VARCHAR:
		  case	GL_TYPE_DBCODE:
		  case	GL_TYPE_TEXT:
		  case	GL_TYPE_SYMBOL:
			sprintf(str,"%d",ival);
			rc = SetValueString(val,str,NULL);
			break;
		  case	GL_TYPE_NUMBER:
			if		(  ival  <  0  ) {
				ival = - ival;
				fMinus = TRUE;
			} else {
				fMinus = FALSE;
			}
			sprintf(str,"%0*d",(int)ValueFixedLength(val),ival);
			if		(  fMinus  ) {
				*str |= 0x40;
			}
			rc = SetValueString(val,str,NULL);
			break;
		  case	GL_TYPE_INT:
			ValueInteger(val) = ival;
			rc = TRUE;
			break;
		  case	GL_TYPE_FLOAT:
			ValueFloat(val) = ival;
			rc = TRUE;
			break;
		  case	GL_TYPE_BOOL:
			ValueBool(val) = ( ival == 0 ) ? FALSE : TRUE;
			rc = TRUE;
			break;
		  case	GL_TYPE_OBJECT:
			ValueObjectId(val) = ival;
			if		(  ValueObjectFile(val)  !=  NULL  ) {
				xfree(ValueObjectFile(val));
				ValueObjectFile(val) = NULL;
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_TIMESTAMP:
		  case	GL_TYPE_DATE:
		  case	GL_TYPE_TIME:
			rc = (  localtime_r((time_t *)&ival,&ValueDateTime(val))  !=  NULL  ) ? TRUE : FALSE;
			break;
		  default:
			ValueIsNil(val);
			rc = FALSE;	  
		}
	}
	return	(rc);
}
Пример #2
0
/*
	ExecLine function
*/
inline int ExecLine(struct ST_SUIM *pS, const char *pchLine)
{
	if(pS->inFlgError== 1) return (ERR_NONE);

	if(pchLine[0]== 'i' && pchLine[1]== ':') {
		//if
		Calc(pS);
		if(pS->inErrCode!= SUCCESS) return (pS->inErrCode);

		if(pS->doCalcWork== 1.0) {
			return (pS->inLineNo + 1);
		}
		else {
			int inLineNo = pS->pinListJumpNo[pS->inLineNo];
			return (inLineNo);
		}
	}
	else {
		if(pchLine[0]== 'g' && pchLine[1]== ':') {
			//goto
			int inLineNo = pS->pinListJumpNo[pS->inLineNo];
			return (inLineNo);
		}
		else {
			if(pchLine[0]== 'c' && pchLine[1]== ':') {
				//call function
				if(pS->pchInArgs!= NULL) {
					free(pS->pchInArgs);
					pS->pchInArgs = NULL;
				}

				char pchFuncName[MAX_WORD] = "";

				CallBack pclCallBack = NULL;
				char *pchIndex = strchr(&pchLine[2], ' ');
				if(pchIndex== NULL) {
					strcpy(pchFuncName, &pchLine[2]);

					pclCallBack = GetCallBack(pS, &pchLine[2]);
				}
				else {
					char *pchInArgs = pchIndex + 1;

					int inSize = pchIndex - &pchLine[2];
					memset(pchFuncName, 0x00, MAX_WORD);
					strncpy(pchFuncName, &pchLine[2], inSize);

					pclCallBack = GetCallBack(pS, pchFuncName);
					if(pclCallBack!= NULL) {
						int inLength = strlen(pchInArgs);
						pS->pchInArgs = malloc(inLength + 1);
						strcpy(pS->pchInArgs, pchInArgs);
					}
				}

				if(pclCallBack!= NULL) {
					//exe side function
					int inErrCode = (*pclCallBack)((int *)pS);
					if(inErrCode!= SUCCESS) {
						SetError2(pS, inErrCode, "function call error.");
						return (inErrCode);
					}
				}
				else {
					//suim function
					if(pS->inStackBackNo>= MAX_STACK_FUNCTION) {
						SetError2(pS, ERR_OVERFLOW, "function stack overflow.");
						return (ERR_OVERFLOW);
					}

					pS->pinStackBackNo[pS->inStackBackNo] = pS->inLineNo;
					pS->inStackBackNo++;

					int inLineNo = GetFunctionDefine(pS, pchFuncName);
					if(inLineNo== 0) {
						SetError2(pS, ERR_FUNC_NAME, "can't find function name.");
						return (ERR_FUNC_NAME);
					}

					pS->inLineNo = inLineNo;
				}

				pS->inNoOut = 0;

				return (pS->inLineNo + 1);
			}
			else {
				if(pchLine[0]== 'o' && pchLine[1]== ':') {
					//setup out arg
					Calc(pS);
					if(pS->inErrCode!= SUCCESS) return (pS->inErrCode);

					if(pS->pchCalcWork== NULL) {
						int inErrCode = SetValueDouble(pS->ppstListOut, pS->inNoOut, pS->doCalcWork);
						if(inErrCode!= SUCCESS) return (inErrCode);
					}
					else {
						int inErrCode = SetValueString(pS->ppstListOut, pS->inNoOut, pS->pchCalcWork);
						if(inErrCode!= SUCCESS) return (inErrCode);
					}
					pS->inNoOut++;

					return (pS->inLineNo + 1);
				}
				else {
					if(pchLine[0]== '-' && pchLine[1]== '-') {
						//Separator
						return (ORDER_SEPARATOR);
					}
					else {
						if(pchLine[0]== 'r' && pchLine[1]== ':') {
							//return
							pS->inNoOut = 0;

							return (ORDER_RETURN);
						}
						else {
							if(pchLine[0]== 'e' && pchLine[1]== ':') {
								//function end
								if(pS->inStackBackNo>= 1) {
									pS->inLineNo = pS->pinStackBackNo[pS->inStackBackNo - 1];
									pS->pinStackBackNo[pS->inStackBackNo - 1] = 0;
									pS->inStackBackNo--;

									return (pS->inLineNo + 1);
								}

								return (ORDER_END);
							}
						}
					}
				}
			}
		}
	}

	//calculation
	int inNo = CngKey2No(&pchLine[0]);
	if(inNo< 0) return (ERR_OVERFLOW);
	if(inNo>= pS->inCountVariable) return (ERR_OVERFLOW);

	Calc(pS);
	if(pS->inErrCode!= SUCCESS) return (pS->inErrCode);

	int inErrCode = SUCCESS;
	if(pS->pchCalcWork== NULL) {
		inErrCode = SetValueDouble(pS->ppstListVariable, inNo, pS->doCalcWork);
	}
	else {
		inErrCode = SetValueString(pS->ppstListVariable, inNo, pS->pchCalcWork);

		free(pS->pchCalcWork);
		pS->pchCalcWork = NULL;
	}
	if(inErrCode!= SUCCESS) return (inErrCode);

	return (pS->inLineNo + 1);
}
Пример #3
0
/*
	SetBuffer function
	Setup suim code.
*/
SUIMLIB_API int SetBuffer(const int *S, const char *pchSuimName, const char *pchBuffer, const int inVarCount, const int inOutCount, int inCallBackCount)
{
	if(S== NULL) return (ERR_S_NULL);
	int inFlag = IsNullOrEmpty(pchSuimName);
	if(inFlag!= 0) return (ERR_NAME);
	inFlag = IsNullOrEmpty(pchBuffer);
	if(inFlag!= 0) return (ERR_BUFFLER);
	if(inVarCount>= MAX_VARIABLE_COUNT) return (ERR_OVERFLOW);

	struct ST_SUIM *pS = (struct ST_SUIM *)S;
	if(pS->pchSuimName!= NULL) return (ERR_SET_NAME);
	if(pS->pchBuffer!= NULL) return (ERR_SET_BUFFER);

	size_t szLength = strlen(pchSuimName);
	pS->pchSuimName = malloc(szLength + 1);
	if(pS->pchSuimName== NULL) return (ERR_MEMORY);
	strcpy(pS->pchSuimName, pchSuimName);

	szLength = strlen(pchBuffer);
	pS->pchBuffer = malloc(szLength + 1);
	if(pS->pchBuffer== NULL) return (ERR_MEMORY);
	strcpy(pS->pchBuffer, pchBuffer);

	int inMaxLine = 0;
	int inCnt, inMax = strlen(pchBuffer);
	for(inCnt= 0;inCnt< inMax;inCnt++)
	{
		if(pchBuffer[inCnt]== '\n') inMaxLine++;
	}

	pS->inMaxLineNum = inMaxLine;

	pS->ppchLines = malloc(sizeof(char *) * (inMaxLine));
	if(pS->ppchLines== NULL) return (ERR_MEMORY);
	memset(pS->ppchLines, 0x00, sizeof(char *) * (inMaxLine));

	//split lines
	inCnt = 0;
	char *pchPos = strtok( pS->pchBuffer, "\n" );
	while( pchPos != NULL && inCnt < inMaxLine )
	{
		pS->ppchLines[inCnt] = pchPos;
		inCnt++;

		pchPos = strtok( NULL, "\n" );
	}

	int inCountFunction = 0;
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		if(pS->ppchLines[inCnt][0]== 'f' && pS->ppchLines[inCnt][1]== '|') inCountFunction++;
	}

	//define setting
	pS->inCountVariable = inVarCount;
	if(inVarCount> 0) {
		pS->ppstListVariable = malloc(sizeof(struct ST_VALUE *) * inVarCount);
		memset(pS->ppstListVariable, 0x00, sizeof(struct ST_VALUE *) * inVarCount);
		for(inCnt= 0;inCnt< inVarCount;inCnt++)
		{
			SetValueDouble(pS->ppstListVariable, inCnt, 0.0);
		}

		for(inCnt= 0;inCnt< inMaxLine;inCnt++)
		{
			if(!(pS->ppchLines[inCnt][0]== 's' && pS->ppchLines[inCnt][1]== '|')) continue;

			char *pchKey = strtok(&pS->ppchLines[inCnt][2], ":");
			char *pchValue = strtok(NULL, ":");

			const int inNo = CngKey2No(pchKey);
			if(inNo< 0) return (ERR_OVERFLOW);
			if(inNo>= inMax) return (ERR_OVERFLOW);
			int inErrCode = SetValueString(pS->ppstListVariable, inNo, pchValue);
			if(inErrCode!= SUCCESS) return (inErrCode);
		}
	}

	//callback setting
	pS->inCountCallBack = inCallBackCount;
	if(inCallBackCount> 0) {
		pS->ppstListCallBack = malloc(sizeof(struct ST_VALUE_CALLBACK *) * inCallBackCount);
		memset(pS->ppstListCallBack, 0x00, sizeof(struct ST_VALUE_CALLBACK *) * inCallBackCount);
	}

	//out setting
	pS->pchInArgs = NULL;

	pS->inNoOut = 0;

	pS->inCountOut = inOutCount;
	if(inOutCount> 0) {
		pS->pchOutArgsType = malloc(inOutCount + 1);
		memset(pS->pchOutArgsType, 0x00, inOutCount + 1);

		pS->ppstListOut = malloc(sizeof(struct ST_VALUE *) * inOutCount);
		memset(pS->ppstListOut, 0x00, sizeof(struct ST_VALUE *) * inOutCount);
		for(inCnt= 0;inCnt< inOutCount;inCnt++)
		{
			SetValueDouble(pS->ppstListOut, inCnt, 0.0);
		}
	}

	//function setting
	pS->inCountFunction = inCountFunction;
	if(inCountFunction> 0) {
		pS->ppstListFunction = malloc(sizeof(struct ST_VALUE *) * inCountFunction);
		memset(pS->ppstListFunction, 0x00, sizeof(struct ST_VALUE *) * inCountFunction);
		for(inCnt= 0;inCnt< inMaxLine;inCnt++)
		{
			if(!(pS->ppchLines[inCnt][0]== 'f' && pS->ppchLines[inCnt][1]== '|')) continue;

			char *pchKey = strtok(&pS->ppchLines[inCnt][2], ":");
			char *pchValue = strtok(NULL, ":");
			int inLineNo = atoi(pchValue);

			int inRes = AddFunctionDefine(pS, pchKey, inLineNo);
			if(inRes!= SUCCESS) return (inRes);
		}
	}

	//set start position
	//set jump line no
	//create cmp string
	pS->pchListStartPos = malloc(sizeof(char) * inMaxLine);
	pS->pinListJumpNo = malloc(sizeof(int) * inMaxLine);
	pS->ppchListCmp = malloc(sizeof(char *) * inMaxLine);
	memset(pS->ppchListCmp, 0x00, sizeof(char *) * inMaxLine);
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		const char *pchLine = pS->ppchLines[inCnt];

		pS->pchListStartPos[inCnt] = 0;
		pS->pinListJumpNo[inCnt] = 0;
		pS->ppchListCmp[inCnt] = NULL;

		if(pchLine[0]== '-' && pchLine[1]== '-') continue;
		if(pchLine[1]== '|') continue;

		char *pchIndex = strchr(pchLine, ':');
		if(pchIndex== NULL) continue;
		pchIndex+= 1;

		pS->pchListStartPos[inCnt] = (char)(pchIndex - pchLine);

		if(pchIndex[0]== 'i' && pchIndex[1]== ':')
		{
			char *pchIndex2 = strstr(pchIndex, ")e");
			if(pchIndex2!= NULL)
			{
				pS->pinListJumpNo[inCnt] = atoi(pchIndex2 + 2);

				int inSize = (int)(pchIndex2 - &pchIndex[3]);
				pS->ppchListCmp[inCnt] = malloc(inSize + 1);
				memset(pS->ppchListCmp[inCnt], 0x00, inSize + 1);
				strncpy(pS->ppchListCmp[inCnt], &pchIndex[3], inSize);
			}
			continue;
		}

		if(pchIndex[0]== 'g' && pchIndex[1]== ':')
		{
			pchIndex = strchr(pchIndex, ':');
			if(pchIndex!= NULL)
			{
				pS->pinListJumpNo[inCnt] = atoi(pchIndex + 1);
			}
			continue;
		}
	}

	//memory allocate
	int inSize = sizeof(int) * inMaxLine;
	pS->pinListTokenNum = malloc(inSize);
	memset(pS->pinListTokenNum, 0x00, inSize);

	inSize = sizeof(int) * inMaxLine;
	pS->pinListTokenSt = malloc(inSize);
	memset(pS->pinListTokenSt, 0x00, inSize);

	//count token
	int inStToken = 0;
	int inMaxToken = 0;
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		const char *pchLine = pS->ppchLines[inCnt];

		if(pchLine[0]== '-' && pchLine[1]== '-') continue;
		if(pchLine[1]== '|') continue;

		if(pS->pchListStartPos[inCnt]== 0) continue;

		char *pchIndex = (char *)(pchLine + pS->pchListStartPos[inCnt]);
		if(pchIndex[0]== 'g' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'e' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'f' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'c' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'r' && pchIndex[1]== ':') continue;

		int inCntToken = 0;
		if(pchIndex[0]== 'o' && pchIndex[1]== ':') {
			inCntToken = CountToken(&pchIndex[2]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}
/*
		if(pchIndex[0]== 's' && pchIndex[1]== ':') {
			inCntToken = CountToken(&pchIndex[5]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}
		if(pchIndex[0]== 'd' && pchIndex[1]== ':') {
			inCntToken = CountToken(&pchIndex[5]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}
*/
		if(pchIndex[0]== 'i' && pchIndex[1]== ':') {
			inCntToken = CountToken(pS->ppchListCmp[inCnt]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}
		if(pchIndex[2]== '=') {
			inCntToken = CountToken(&pchIndex[3]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}

		pS->pinListTokenSt[inCnt] = inStToken;
		inStToken+= inCntToken;

		pS->pinListTokenNum[inCnt] = inCntToken;
	}

	//memory allocate
	pS->inMaxTokenNum = inMaxToken;

	inSize = sizeof(double) * inMaxToken * inMaxLine;
	pS->pdoListToken = malloc(inSize);
	memset(pS->pdoListToken, 0x00, inSize);

	inSize = sizeof(char) * inMaxToken * inMaxLine;
	pS->pchListTokenType = malloc(inSize);
	memset(pS->pchListTokenType, 0x00, inSize);

	inSize = sizeof(char) * MAX_WORD * inMaxToken * inMaxLine;
	pS->pchListTokenWord = malloc(inSize);
	memset(pS->pchListTokenWord, 0x00, inSize);

	//setup token data
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		const char *pchLine = pS->ppchLines[inCnt];

		if(pchLine[0]== '-' && pchLine[1]== '-') continue;
		if(pchLine[1]== '|') continue;

		if(pS->pchListStartPos[inCnt]== 0) continue;

		char *pchIndex = (char *)(pchLine + pS->pchListStartPos[inCnt]);
		if(pchIndex[0]== 'g' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'e' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'f' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'c' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'r' && pchIndex[1]== ':') continue;

		int inStToken = pS->pinListTokenSt[inCnt];
		if(pchIndex[0]== 'o' && pchIndex[1]== ':') {
			SetTokenData(pS, &pchIndex[2], inStToken);
		}
/*
		if(pchIndex[0]== 's' && pchIndex[1]== ':') {
			SetTokenData(pS, &pchIndex[5], inStToken);
		}
		if(pchIndex[0]== 'd' && pchIndex[1]== ':') {
			SetTokenData(pS, &pchIndex[5], inStToken);
		}
*/
		if(pchIndex[0]== 'i' && pchIndex[1]== ':') {
			SetTokenData(pS, pS->ppchListCmp[inCnt], inStToken);
		}
		if(pchIndex[2]== '=') {
			SetTokenData(pS, &pchIndex[3], inStToken);
		}
	}

	//global line execute
	int inFunc = 0;
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		const char *pchLine = pS->ppchLines[inCnt];

		if(pchLine[0]== '-' && pchLine[1]== '-') {
			int inLength = strlen(pchLine);
			if(inLength<= 2) continue;

			int inVersion = atoi(&pchLine[2]);
			if(inVersion== VERSION) continue;

			return (ERR_VERSION);
		}

		if(pchLine[1]== '|') continue;

		pS->inLineNo = inCnt;

		char *pchIndex = (char *)(pchLine + pS->pchListStartPos[inCnt]);

		if(pchIndex[0]== 'f') inFunc = 1;
		if(pchIndex[0]== 'e') inFunc = 0;
		if(inFunc== 1) continue;

		if(pchIndex[0]== 'e' && pchIndex[1]== ':') continue;

		int inLineNo = ExecLine(pS, pchIndex);
		if(inLineNo< 0) return (inLineNo);
	}

	return (SUCCESS);
}
Пример #4
0
int main(int argc, char *argv[]) {
  ValueStruct *value, *v;
  size_t size;
  char *buf;

  RecParserInit();
  value = RecParseValueMem(recdef, NULL);

  InitializeValue(value);
  v = GetRecordItem(value, "command");
  SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL);
  v = GetItemLongName(value, "record1[0].col1");
  SetValueString(v, "bbbb", NULL);
  v = GetItemLongName(value, "record1[0].record2.col21");
  SetValueString(v, "cccc", NULL);
  v = GetItemLongName(value, "int1");
  SetValueInteger(v, 10);
  v = GetItemLongName(value, "int2");
  SetValueInteger(v, 20);
  v = GetItemLongName(value, "double1");
  SetValueFloat(v, -3.2);

  fprintf(stderr, "\n---- JSON_PackValue\n");
  size = JSON_SizeValue(NULL, value);
  fprintf(stderr, "size:%ld\n", size);
  buf = malloc(size + 1);
  memset(buf, 0, size + 1);
  JSON_PackValue(NULL, buf, value);
  fprintf(stderr, "[%s]\nsize:%ld\n", buf, strlen(buf));

  fprintf(stderr, "\n---- JSON_UnPackValue 1\n");
  JSON_UnPackValue(NULL, buf, value);
  DumpValueStruct(value);
  free(buf);

  fprintf(stderr, "\n---- JSON_UnPackValue 2\n");
  JSON_UnPackValue(NULL, "{\"int1\":1000,\"int2\":2000}", value);
  DumpValueStruct(value);

  /* ommit */
  fprintf(stderr, "\n-------------------\n");
  fprintf(stderr, "ommit\n");
  fprintf(stderr, "-------------------\n\n");

  InitializeValue(value);
  v = GetRecordItem(value, "command");
  SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL);
  v = GetItemLongName(value, "record1[0].col1");
  SetValueString(v, "bbbb", NULL);
  v = GetItemLongName(value, "record1[0].record2.col21");
  SetValueString(v, "cccc", NULL);
  v = GetItemLongName(value, "int1");
  SetValueInteger(v, 10);
  v = GetItemLongName(value, "int2");
  SetValueInteger(v, 20);
  v = GetItemLongName(value, "record3[1].record4[1].vc41");
  SetValueString(v, "vc41", NULL);

  fprintf(stderr, "\n---- JSON_PackValueOmmit\n");
  size = JSON_SizeValueOmmit(NULL, value);
  fprintf(stderr, "size:%ld\n", size);
  buf = malloc(size + 1);
  memset(buf, 0, size + 1);
  JSON_PackValueOmmit(NULL, buf, value);
  fprintf(stderr, "size:%ld [%s]\n", strlen(buf), buf);
  free(buf);

  fprintf(stderr, "\n---- JSON_UnPackValueOmmit\n");
  JSON_UnPackValueOmmit(NULL, "{\"int1\":1000,\"int2\":2000}", value);
  DumpValueStruct(value);

  fprintf(stderr, "\n---- JSON_UnPackValueOmmit 2\n");
  JSON_UnPackValueOmmit(
      NULL,
      "{\"int1\":1234,\"int2\":5678,\"bool1\":false,\"double1\":3.141592}",
      value);
  DumpValueStruct(value);

  fprintf(stderr, "\n---- JSON_UnPackValueOmmit 3\n");
  JSON_UnPackValueOmmit(
      NULL,
      "{\"int1\":1000,\"command\":\"moge\",\"record1\":[{\"col1\":\"muge\","
      "\"record2\":{\"col21\":\"gage\"}},{},{\"col2\":\"nuge\"}],\"record3\":[{"
      "},{\"record4\":[{},{\"vc41\":\"vc41\"}]}]}",
      value);
  DumpValueStruct(value);

  InitializeValue(value);
  fprintf(stderr, "\n---- test\n");
  JSON_UnPackValueOmmit(NULL,
                        "{\"int1\":10,\"int0\":[0,1,2,3,0,5,0,6],\"bool1\":"
                        "false,\"arg1\":\"hogehoge\"}",
                        value);
  size = JSON_SizeValueOmmit(NULL, value);
  fprintf(stderr, "size:%ld\n", size);
  buf = malloc(size);
  memset(buf, 0, size);
  JSON_PackValueOmmit(NULL, buf, value);
  fprintf(stderr, "size:%d %s\n", (int)strlen(buf), buf);
  free(buf);

  fprintf(stderr, "\n\n\n\n\n\n---- JSON_PackValueOmmitString\n");

  InitializeValue(value);
  v = GetRecordItem(value, "command");
  SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL);
  v = GetItemLongName(value, "record1[0].col1");
  SetValueString(v, "bbbb", NULL);
#if 0
  v = GetItemLongName(value,"record1[0].record2.col21");
  SetValueString(v,"cccc",NULL);
#endif
  v = GetItemLongName(value, "int1");
  SetValueInteger(v, 10);
  v = GetItemLongName(value, "int2");
  SetValueInteger(v, 20);
  v = GetItemLongName(value, "record3[1].record4[1].vc41");
  SetValueString(v, "vc41", NULL);

  DumpValueStruct(value);

  size = JSON_SizeValueOmmitString(NULL, value);
  fprintf(stderr, "size:%ld\n", size);
  buf = malloc(size + 1);
  memset(buf, 0, size + 1);
  JSON_PackValueOmmitString(NULL, buf, value);
  fprintf(stderr, "size:%ld [%s]\n", strlen(buf), buf);
  free(buf);

  return 0;
}
Пример #5
0
extern	int
main(
	int		argc,
	char	**argv)
{
#define	SIZE_DATA		128

	char	name[SIZE_DATA];
	unsigned char	*p;
	int		i;
	ValueStruct	*val
		,		*val2;
	unsigned char	*buff;
	char	method[SIZE_LONGNAME+1];
	FILE	*fp;

	RecordDir = ".";
	RecParserInit();
	val = BuildMcpArea(10);

	/*	set	*/
	printf("***** Value setting *****\n");
	SetValueString(GetItemLongName(val,"func"),"aaa",SRC_CODE);
	SetValueString(GetItemLongName(val,"rc"),"0",SRC_CODE);

	SetValueString(GetItemLongName(val,"dc.window"),"1 Ë",SRC_CODE);
	SetValueString(GetItemLongName(val,"dc.widget"),"widget",SRC_CODE);
	SetValueString(GetItemLongName(val,"dc.event"),"1002 ",SRC_CODE);
	SetValueString(GetItemLongName(val,"dc.fromwin"),"fromwin",SRC_CODE);
	SetValueString(GetItemLongName(val,"dc.status"),"status",SRC_CODE);
	SetValueString(GetItemLongName(val,"dc.puttype"),"puttype",SRC_CODE);
	SetValueString(GetItemLongName(val,"dc.term"),"term",SRC_CODE);
	SetValueString(GetItemLongName(val,"dc.user"),"user",SRC_CODE);

	for	( i = 0 ; i < N_PATH ; i ++ ) {
		sprintf(name,"db.path[%d].blocks",i);
		SetValueInteger(GetItemLongName(val,name),i);
		sprintf(name,"db.path[%d].rname",i);
		SetValueInteger(GetItemLongName(val,name),i);
		sprintf(name,"db.path[%d].pname",i);
		SetValueInteger(GetItemLongName(val,name),i);
		sprintf(name,"db.path[%d].name",i);
		SetValueString(GetItemLongName(val,name),name,SRC_CODE);
	}

	SetValueString(GetItemLongName(val,"private.count"),"1",SRC_CODE);
	for	( i = 0 ; i < 100 ; i ++ ) {
		sprintf(name,"private.swindow[%d]",i);
		SetValueString(GetItemLongName(val,name),name,SRC_CODE);
	}
	for	( i = 0 ; i < ValueArraySize(GetItemLongName(val,"private.state")) ; i ++ ) {
		sprintf(name,"private.state[%d]",i);
		SetValueString(GetItemLongName(val,name),name,SRC_CODE);
	}
	for	( i = 0 ; i < ValueArraySize(GetItemLongName(val,"private.index")) ; i ++ ) {
		sprintf(name,"private.index[%d]",i);
		SetValueString(GetItemLongName(val,name),name,SRC_CODE);
	}
	SetValueString(GetItemLongName(val,"private.pstatus"),"1",SRC_CODE);
	SetValueString(GetItemLongName(val,"private.pputtype"),"2",SRC_CODE);
	SetValueString(GetItemLongName(val,"private.prc"),"3",SRC_CODE);
	buff = xmalloc(SIZE_BUFF);
	memset(buff,0,SIZE_BUFF);
	for	( p = buff, i = 0 ; i < 256 ; i ++ , p ++) {
		*p = (unsigned char)i;
	}
	SetValueBinary(GetItemLongName(val,"bin"),buff,256);


	printf("***** SOAP ****\n");
	memset(buff,0,SIZE_BUFF);

	SOAP_PackValue(buff,val,"Put","mcp","http://oreore",TRUE,FALSE);

	printf("%s\n",buff);
	fp = fopen("test.SOAP","w");
	fprintf(fp,"%s\n",buff);
	fclose(fp);

	val2 = DuplicateValue(val,FALSE);

	SOAP_UnPackValue(val2,(char *)buff,method);

	printf("method = [%s]\n",method);
	DumpByXML(val2,"mcparea");

	SOAP_PackValue(buff,val,"Put","mcp","http://oreore",TRUE,FALSE);
	val2 = SOAP_LoadValue((char *)buff,method);
	printf("method = [%s]\n",method);
	DumpByXML(val2,"mcparea");
	//DumpValueStruct(val2);

	return	(0);
}
NS_IMETHODIMP
nsSVGAnimatedString::SetBaseVal(const nsAString & aBaseVal)
{
  SetValueString(aBaseVal);
  return NS_OK;
}