红联Linux门户
Linux帮助

奇怪问题-函数超过3个参数返回就有错

发布时间:2009-03-25 10:49:49来源:红联作者:ewolfe
下面的调试程序中只要GetCfg()函数参数超过3个,tst中输出的内容就是乱码,想请教一下。
系统 sco

#include "stdio.h"
#include
#define PMAX_FUN 20
#define INT int
#define CHAR char
#define INT int
#define BOOL char
main()
{
INT nCnt;
CHAR *sProcCont[256];
CHAR sLine[]="aaa|bbb|ccc";

memset(sProcCont, '\0', sizeof(sProcCont));
//nCnt = GetFunCfg("trmspfuncfg", "HOME", "trmsp/etc", "PROC", sProcCont);
// nCnt = GetCfg("trmspfuncfg", "HOME", "trmsp/etc", "PROC", sProcCont);
nCnt = GetCfg1("aa","HOME", "PROC", sProcCont);
//nCnt = Parse(sLine, sProcCont);

while(nCnt >= 0)
{
printf("xxxxx%d: %s\n", nCnt, sProcCont[nCnt]);
nCnt--;
}
}

//INT GetCfg(CHAR *pFile, CHAR *pEnv, CHAR *pPath, CHAR *pFunNm, CHAR *pVal[])
INT GetCfg1(CHAR *xx, CHAR *pEnv, CHAR *pFunNm, CHAR *pVal[])
{
INT nCnt = 0;
INT nLen = 0;
BOOL bFlag;
CHAR sPath[80];
CHAR sLine[PMAX_FUN * 10]; //每个功能最多10个字符
FILE *fp;
// char pFunNm[]="PROC";

int i;

bFlag = 0;
nLen = strlen(pFunNm);
memset(pVal, '\0', sizeof(pVal));
memset(sPath, 0x00, sizeof(sPath));
// _GetEnvPath(pEnv,pPath, sPath, sizeof(sPath));
// sprintf(sPath, "%s/%s", sPath, pFile);
strcpy(sPath,"/usr/tstcom/trmsp/etc/trmspfuncfg");

printf("88 %s\n",sPath);

if ( (fp=fopen(sPath, "r")) == NULL)
{
printf("open trmspcont err !\n");
exit(1);
}


while ( fgets(sLine, sizeof(sLine), fp) != NULL )
{
if (sLine[0] == '#')
continue;
if ( isspace(sLine[0]) )
continue;

if ( (bFlag == 1) && (sLine[0] == '[') )
{
break;
}
if ( (bFlag == 1) && (sLine[0] != '[') )
{
printf("999 %s\n",sLine);
nCnt = Parse(sLine, pVal);
for(i=nCnt-1;i>=0;i--)
printf("yyy %s\n",pVal[i]);
break;
}

if( (sLine[0] == '[') && !memcmp(&sLine[1], pFunNm, nLen) &&
(sLine[nLen+1] == ']') ) //保证完全匹配
{
bFlag = 1;
continue;
}
}

fclose(fp);
return(nCnt);
}


-------------------------------------

Parse函数如下:

INT Parse(CHAR *pLine, CHAR *pWord[])
//INT Parse(CHAR *pLine, CHAR pWord[][20])
{
INT nWordCnt;
int i;

nWordCnt = 0;
while ( (*pLine != 0x00) && (*pLine != '\n') )
{
while ( (*pLine == ' ') || (*pLine == '\t') ||
(*pLine == '|') )
*pLine++ = 0x00;
pWord[nWordCnt++] = pLine;
//strcpy(pWord[nWordCnt++], pLine);

while ((*pLine != 0x00) && (* pLine != ' ') &&
(*pLine != '\t') && (* pLine != '\n') &&
(*pLine != '|') )
pLine++;
}
*pLine = 0x00;

return(nWordCnt);
}


--------------
读的文件 trmsfuncfg文件内容如下
#
#
[MAIN]
proc
[PROC]
comcli|comsrv|trmspproc
文章评论

共有 0 条评论