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

📄 scalar.c

📁 一个简单的数据库管理工具
💻 C
📖 第 1 页 / 共 3 页
字号:
    return(MkScalar(eStringType,sBuf,1+iStrLen(sBuf)));}Scalar_t *ScalarRPad(Scalar_t *pList){    int		 iSize		,iPadSize		;    Scalar_t 	 *pSource		,*pSize		,*pChar		;    char	 *pStrSource		,*pStrChar = " "		,sBuf[MAX_BUFSIZ]		;    /* fprintf(stderr,"RPad(!)\n");fflush(stderr);     */    if(!pList){	DebugHTML(__FILE__,__LINE__,0,"ScalarRPad:Scalar is NULL(%x)",pList);	MsgPush("ScalarRPad:Scalar is NULL");	return(&gsNullScalar);    }    iSize = l_size(pList->uVal.pList);    if(iSize != 2 && iSize !=3) {	DebugHTML(__FILE__,__LINE__,0,"WARN:RPAD:USAGE:RPad(input,size[,padchar])");	return(&gsNullScalar);    }    pSource = DEQ(pList->uVal.pList);    pSize   = DEQ(pList->uVal.pList);    if(iSize == 3) {	pChar = DEQ(pList->uVal.pList);    }    pStrSource = ScalarToString(pSource);    iPadSize = (int)ScalarToDouble(pSize);    pStrChar = ScalarToString(pChar);    if(iPadSize >= MAX_BUFSIZ) {	DebugHTML(__FILE__,__LINE__,0		,"WARN:RPAD:overflow, truncated to %d",MAX_BUFSIZ);	iPadSize = MAX_BUFSIZ -1;    }    memset(sBuf, *pStrChar, iPadSize);    sBuf[iPadSize] = 0;    strncpy(sBuf,pStrSource,iStrLen(pStrSource));    return(MkScalar(eStringType, sBuf,1+iStrLen(sBuf)));}Scalar_t *ScalarLTrim(Scalar_t *pList){    int		 iSize		;    Scalar_t 	 *pSource		,*pChar		;    char	 *pStrSource		,*pStrChar = " "		,sBuf[MAX_BUFSIZ]		;    if(!pList){	DebugHTML(__FILE__,__LINE__,0,"ScalarTrim:Scalar is NULL(%x)",pList);	MsgPush("ScalarLTrim:Scalar is NULL");	return(&gsNullScalar);    }    iSize = l_size(pList->uVal.pList);    if(iSize != 1 && iSize !=2) {	DebugHTML(__FILE__,__LINE__,0,"WARN:LTRIM:USAGE:LTrim(input[,trimchar])");	return(&gsNullScalar);    }    /*    /* Get String version of Variable     */    pSource = DEQ(pList->uVal.pList);    pStrSource = ScalarToString(pSource);    /*    /* Now Get The "Trimoff Char"     */    if(iSize == 2) {	pChar = DEQ(pList->uVal.pList);	pStrChar = ScalarToString(pChar);    }    while(*pStrSource == *pStrChar)	pStrSource++;    if(*pStrSource)	 strcpy(sBuf,pStrSource);    else sBuf[0] = 0;    return(MkScalar(eStringType, sBuf,1+iStrLen(sBuf)));}Scalar_t *ScalarRTrim(Scalar_t *pList){    int		 iSize		;    Scalar_t 	 *pSource		,*pChar		;    char	 *pStrSource		,*pStrChar = " "		;    if(!pList){	DebugHTML(__FILE__,__LINE__,0,"ScalarRTrim:Scalar is NULL(%x)",pList);	MsgPush("ScalarRTrim:Scalar is NULL");	return(&gsNullScalar);    }    iSize = l_size(pList->uVal.pList);    if(iSize != 1 && iSize !=2) {	DebugHTML(__FILE__,__LINE__,0,"WARN:RTRIM:USAGE:RTrim(input[,padchar])");	return(&gsNullScalar);    }    pSource = DEQ(pList->uVal.pList);    pStrSource = ScalarToString(pSource);    if(iSize == 2) {	pChar = DEQ(pList->uVal.pList);	pStrChar = ScalarToString(pChar);    }    iSize = iStrLen(pStrSource);    while( *(pStrSource+ (--iSize)) == *pStrChar)	; /* nothing */    *(pStrSource + iSize +1) = 0;    return(MkScalar(eStringType, pStrSource,1+iStrLen(pStrSource)));}static voidToUpper(char *pBuf){    int c;    for(c= *pBuf;c;c = *++pBuf)	*pBuf=(char)toupper(c);    return;}static voidToLower(char *pBuf){    int c;    for(c = *pBuf;c; c= *++pBuf)	*pBuf = (char)tolower(c);    return;}static voidFormatString(char *pInpStr,char *pFmtStr,char *pOutBuf){    char *pInDecPt	,*pFmtDecPt	;    int  iInDecSize	,iFmtPrecision	,iNewDecSize	,iNewBufSize	,iCommaFlag	,i	;    DebugHTML(__FILE__,__LINE__,3,"FormatString(%s,%s,buf)",pInpStr,pFmtStr);    pInDecPt = (char *)strchr(pInpStr,'.');    pFmtDecPt= (char *)strchr(pFmtStr,'.');    iInDecSize   = (pInDecPt) ? pInDecPt - pInpStr : iStrLen(pInpStr);    iFmtPrecision= (pFmtDecPt)? iStrLen(pFmtDecPt+1) : 0;    iCommaFlag =  (strchr(pFmtStr,',')) ? 1 : 0;    iNewDecSize= (iCommaFlag)		? (iInDecSize + ((iInDecSize-1)/3)) /* Fmt str has commas */		: iInDecSize			    /* Fmt str NO commas  */		;    iNewBufSize= iNewDecSize + ((iFmtPrecision>0)?1:0) + iFmtPrecision;/*    fprintf(stderr,"NSiz=%d (%d + %d + %d) (fmtprec=%s)\n"/* 	    , iNewBufSize/* 	    , iNewDecSize/* 	    , ((iFmtPrecision>0)?1:0) /* 	    , iFmtPrecision/* 	    , pFmtDecPt+1/* 	    );/*    fflush(stderr); */    for(i=0;i<iNewBufSize;i++) {	/* Place Decimal point when not included in pInpStr	 */	if(i==iNewDecSize && !pInDecPt) {	    *pOutBuf++ = '.';	}	/* if a comma goes here	 */	else if(iCommaFlag		/* format string has comma */	    && i>0			/* no leading comma */	    && iNewDecSize-i>0		/* no comma after decpt */	    && ((iNewDecSize-i)%4)==0)	/* comma position */	{	    *pOutBuf++ = ',';		/* Insert Comma */	}else {	    *pOutBuf++ = (*pInpStr) ?*pInpStr++ : '0';	}    }    *pOutBuf = 0;    return;}extern eBoolean_tAssignCond(Scalar_t *pScalarName	  ,Scalar_t *pScalarValue	  ){    char *pValue	,*pName	;    if(!pScalarName) {	DebugHTML(__FILE__,__LINE__,0 ,"WARN:ASSIGN:No Symbol Name");	MsgPush("WARN:ASSIGN:No Symbol Name");	return(eFalse);    }    pName=pScalarName->pName? pScalarName->pName: ScalarToString(pScalarName);    DebugHTML(__FILE__,__LINE__,2,"AssignCond(%s)",pName);     if(!pScalarValue) {	DebugHTML(__FILE__,__LINE__,0		 ,"WARN:ASSIGN:No Symbol Value for %s"		 ,pName		 );	/* return(eFalse);	 */	pValue = "";    } else {	pValue = ScalarToString(pScalarValue); /* Determine Value */    }    SELSym(pName,pValue);    DebugHTML(__FILE__,__LINE__,2,"AssignCond:Completed");    return(eTrue);}extern Scalar_t *ScalarGetSym(Scalar_t *pScalar	    ,char *pRule	){    char *pBuf, *pName;    Scalar_t *pNewScalar;    long lSize;    if(!pScalar){	DebugHTML(__FILE__,__LINE__,0,"ScalarGetSym:%s:Scalar is NULL",pRule);	MsgPush("ScalarGetSym:%s:Scalar is NULL",pRule);	return(pScalar);    }    pName =  pScalar->pName? pScalar->pName: ScalarToString(pScalar);    if(!pName || iStrLen(pName)==0) {	DebugHTML(__FILE__,__LINE__,0,"ScalarGetSym:No Name");	return(pScalar);    }    (void)GetRawSymbolValueREF(pName,&pBuf,&lSize);    DebugHTML(__FILE__,__LINE__,2,"ScalarGetSym(%s,%s):%s:%d"	    ,pName	    ,pBuf?pBuf:""	    ,pRule	    ,lSize	    );    pNewScalar = MkScalar(eStringType,pBuf,lSize);    pNewScalar->pName = DupBuf(pName);    return(pNewScalar);}Scalar_t *ScalarGetSymARR(Scalar_t *pScalar,Scalar_t *pArrayOffset){    char *pBuf, *pName;    int iOffset;    Scalar_t *pNewScalar;    if(!pScalar || !pArrayOffset){	DebugHTML(__FILE__,__LINE__,0,"ScalarARRGetSym(%x,%x):Scalar is NULL"		,pScalar		,pArrayOffset		);	MsgPush("ScalarARRGetSym:Scalar is NULL");	return(pScalar);    }    pName =  pScalar->pName? pScalar->pName: ScalarToString(pScalar);    if(!pName || iStrLen(pName)==0) {	DebugHTML(__FILE__,__LINE__,0,"ScalarGetSym:No Name");	return(pScalar);    }    iOffset = (int)ScalarToDouble(pArrayOffset);    DebugHTML(__FILE__,__LINE__,2,"ScalarGetSym(%s,%d):%s",pName,iOffset);     (void)GetARRSymbolValueREF(pName,iOffset,&pBuf);    pNewScalar = MkScalar(eStringType,pBuf,1+iStrLen(pBuf));    pNewScalar->pName = DupBuf(pName);    return(pNewScalar);}Scalar_t *ScalarGetCookieValue(Scalar_t *pList){    int iListSize;    long lSize;    char *pName, *pBuf;    Scalar_t *pCookieName;    DebugHTML(__FILE__,__LINE__,3,"Called GetCookieValue()");    if(!pList){	DebugHTML(__FILE__,__LINE__,0,"GetCookieValue:Scalar is NULL(0)");	MsgPush("GetCookieValue:Scalar is NULL");	return(&gsNullScalar);    }    /* Check number of parameters (the USAGE)     */    iListSize = l_size(pList->uVal.pList);    if(iListSize != 1) {	DebugHTML(__FILE__,__LINE__,0		 ,"WARN:GetCookieValue:USAGE:GetCookieValue(CookieName)"		 );	return(&gsNullScalar);    }    /*    /* Get CookieName      */    pCookieName=(Scalar_t *)DEQ(pList->uVal.pList);    pName=ScalarToString(pCookieName);    lSize=0L;    (void)GetCookieValueREF(pName,&pBuf,&lSize);    if(lSize>0){	return( MkScalar(eStringType,pBuf,1+iStrLen(pBuf)) );    }    DebugHTML(__FILE__,__LINE__,1 ,"WARN:GetCookie(%s):No HTTP_COOKIE",pName);    return(&gsNullScalar);}Scalar_t *ScalarReplace(Scalar_t *pList){    char *pStr, *pSrch, *pRepl, *pResult;    int iSize;    Scalar_t *pString = 0	    ,*pSearch = 0	    ,*pReplace = 0	;    DebugHTML(__FILE__,__LINE__,3,"ScalarReplace()");    if(!pList){	DebugHTML(__FILE__,__LINE__,0,"ScalarReplace:Scalar is NULL(%x)",pList);	MsgPush("ScalarReplace:Scalar is NULL");	return(&gsNullScalar);    }    iSize = l_size(pList->uVal.pList);    if(iSize==2){	pString=(Scalar_t *)DEQ(pList->uVal.pList);	pSearch=(Scalar_t *)DEQ(pList->uVal.pList);	pStr   = ScalarToString(pString);	pSrch  = ScalarToString(pSearch);        DebugHTML(__FILE__,__LINE__,2,"ScalarReplace(%s,%s)",pStr,pSrch);	pResult= Replace( pStr, pSrch, "" );	pString->esType = eStringType;	pString->uVal.pString = pResult;	pString->lSize = iStrLen(pResult);	return(pString);    } else if (iSize==3) {	pString =(Scalar_t *)DEQ(pList->uVal.pList);	pSearch =(Scalar_t *)DEQ(pList->uVal.pList);	pReplace=(Scalar_t *)DEQ(pList->uVal.pList);	pStr   = ScalarToString(pString);	pSrch  = ScalarToString(pSearch);	pRepl  = ScalarToString(pReplace);        DebugHTML(__FILE__,__LINE__,2,"ScalarReplace(%s,%s,%s)"		 ,pStr		 ,pSrch		 ,pRepl		 );	pResult= Replace( pStr, pSrch, pRepl );	pString->esType = eStringType;	pString->uVal.pString = pResult;	pString->lSize = iStrLen(pResult);	return(pString);    } else {	DebugHTML(__FILE__,__LINE__,0,"WARN:SUBSTR:Invalid args to Replace");    }    return(&gsNullScalar);}static char *Replace( char *pBuf, char *pSrch, char *pRepl ){    char *p, *pE, *po, *pOut;    long lOutSize;    lOutSize=GetReplaceSize(pBuf,pSrch,pRepl);				/* Calc size of resultant string */    po=pOut=(char*)malloc(lOutSize+1);				/* Get storage */    (void)memset(pOut,0,lOutSize);				/* just in case ... cleanup space */    for(pE=pBuf,p=strstr(pBuf,pSrch); p; p=strstr(pE,pSrch)) {	while(pE<p)	    *po++ = *pE++;	/* copy characters not being replaced */	strcpy(po,pRepl);	/* copy replace string */	pE = p + strlen(pSrch);	/* move pointer on input string ahead */	po = po + strlen(pRepl);/* move pointer on output string ahead */    }    while(*pE)			/* process remaining part of string */	*po++ = *pE++;		/* copy characters */    *po=0;			/* don't forget the all important NULL */    return( pOut );		/* OK, otta here! */}static longGetReplaceSize(char *pBuf, char *pSrch, char *pRepl ){    char *p, *pE;    long lStrCount = 0;    for( p=strstr(pBuf,pSrch); p; p=strstr(pE,pSrch)) {	pE = p + strlen(pSrch);	pE++;	lStrCount++;		/* Count occurances of "pSrch" */    }    return (strlen(pBuf)+(lStrCount*(strlen(pRepl)-strlen(pSrch))) );				/* Calc Size of replaced string */}Scalar_t *ScalarAscii(Scalar_t *pList){    char *pStr;    Scalar_t *pInt;    int iSize, iChar;    DebugHTML(__FILE__,__LINE__,3,"ScalarAscii()");    if(!pList){	DebugHTML(__FILE__,__LINE__,0,"ScalarAscii:Scalar is NULL(%x)",pList);	MsgPush("ScalarAscii:Scalar is NULL");	return(&gsNullScalar);    }    iSize = l_size(pList->uVal.pList);    if(iSize!=1){	DebugHTML(__FILE__,__LINE__,0,"WARN:Invalid args to Ascii");	return(&gsNullScalar);    }    pInt=(Scalar_t *)DEQ(pList->uVal.pList);    pStr=ScalarToString(pInt);    DebugHTML(__FILE__,__LINE__,2,"ScalarAscii(%s)",pStr);    iChar = (int) *pStr;    pInt->esType = eIntType;    pInt->uVal.iInt = iChar;    pInt->lSize = 1;    return(pInt);}Scalar_t *ScalarCHR(Scalar_t *pList){    char *pStr, sChar[2];    Scalar_t *pString;    int iSize, iChar;    DebugHTML(__FILE__,__LINE__,3,"ScalarCHR()");    if(!pList){	DebugHTML(__FILE__,__LINE__,0,"ScalarCHR:Scalar is NULL(%x)",pList);	MsgPush("ScalarCHR:Scalar is NULL");	return(&gsNullScalar);    }    iSize = l_size(pList->uVal.pList);    if(iSize!=1){	DebugHTML(__FILE__,__LINE__,0,"WARN:Invalid args to CHR");	return(&gsNullScalar);    }    pString=(Scalar_t *)DEQ(pList->uVal.pList);    iChar = (int) ScalarToDouble(pString);    DebugHTML(__FILE__,__LINE__,2,"ScalarCHR(%d)",iChar);    sChar[0] = (char)iChar;    sChar[1] = (char)0;    DebugHTML(__FILE__,__LINE__,2,"ScalarCHR(%s,%c)",sChar,iChar);    pString->esType = eStringType;    pString->uVal.pString = DupBuf(sChar);    pString->lSize =iStrLen(sChar);    return(pString);}

⌨️ 快捷键说明

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