- Refactored site specific stuff into a site module - PSI specific stuff is now in the PSI directory. - The old version has been tagged with pre-ansto SKIPPED: psi/A1931.c psi/A1931.h psi/amor2t.c psi/amor2t.h psi/amor2t.i psi/amor2t.tex psi/amor2t.w psi/amorscan.c psi/amorscan.h psi/amorscan.w psi/amorstat.c psi/amorstat.h psi/amorstat.i psi/amorstat.tex psi/amorstat.w psi/bruker.c psi/bruker.h psi/bruker.w psi/buffer.c psi/buffer.h psi/dilludriv.c psi/dilludriv.h psi/dmc.c psi/dmc.h psi/dmc.w psi/docho.c psi/ecb.c psi/ecb.h psi/ecb.i psi/ecb.w psi/ecbdriv.c psi/ecbdriv.h psi/el734dc.c psi/el734driv.c psi/el755driv.c psi/el755driv.h psi/faverage.c psi/faverage.h psi/faverage.tex psi/faverage.w psi/fowrite.c psi/fowrite.h psi/itc4.c psi/itc4.h psi/itc4.w psi/itc4driv.c psi/ltc11.c psi/ltc11.h psi/nextrics.c psi/nextrics.h psi/nxamor.c psi/nxamor.h psi/nxamor.tex psi/nxamor.w psi/pimotor.c psi/pimotor.h psi/pimotor.tex psi/pimotor.w psi/pipiezo.c psi/polterwrite.c psi/polterwrite.h psi/psi.c psi/ruli.c psi/ruli.h psi/sanscook.c psi/sanswave.c psi/sanswave.h psi/sanswave.tex psi/sanswave.w psi/serial.c psi/serial.h psi/serial.w psi/sinqhmdriv.c psi/sinqhmdriv.i psi/sinqhmdriv.w psi/slsmagnet.c psi/sps.c psi/sps.h psi/sps.i psi/sps.tex psi/sps.w psi/swmotor.c psi/swmotor.h psi/swmotor.i psi/tas.c psi/tas.h psi/tas.tex psi/tas.w psi/tasdrive.c psi/tasinit.c psi/tasscan.c psi/tasu.h psi/tasutil.c psi/tdchm.c psi/tdchm.h psi/tecsdriv.c psi/tecsdriv.h psi/velodorn.c psi/velodorn.h psi/velodorn.w psi/velodornier.c psi/hardsup/README psi/hardsup/StrMatch.c psi/hardsup/asynsrv_def.h psi/hardsup/asynsrv_errcodes.h psi/hardsup/asynsrv_mark.c psi/hardsup/asynsrv_utility.c psi/hardsup/c_interfaces.c psi/hardsup/dillutil.c psi/hardsup/dillutil.h psi/hardsup/el734_def.h psi/hardsup/el734_errcodes.h psi/hardsup/el734_utility.c psi/hardsup/el734fix.h psi/hardsup/el734tcl.c psi/hardsup/el737_def.h psi/hardsup/el737_errcodes.h psi/hardsup/el737_utility.c psi/hardsup/el737fix.h psi/hardsup/el737tcl.c psi/hardsup/el755_def.h psi/hardsup/el755_errcodes.h psi/hardsup/el755_errorlog.c psi/hardsup/el755_utility.c psi/hardsup/err.c psi/hardsup/failinet.c psi/hardsup/geterrno.c psi/hardsup/itc4util.c psi/hardsup/itc4util.h psi/hardsup/make_gen psi/hardsup/makefile_alpha psi/hardsup/makefile_linux psi/hardsup/makeprint.c psi/hardsup/rs232c_def.h psi/hardsup/serialsinq.c psi/hardsup/serialsinq.h psi/hardsup/sinq_defs.h psi/hardsup/sinq_prototypes.h psi/hardsup/sinqhm.c psi/hardsup/sinqhm.h psi/hardsup/sinqhm_def.h psi/hardsup/stredit.c psi/hardsup/strjoin.c psi/hardsup/table.c psi/hardsup/table.h psi/hardsup/velsel_def.h psi/hardsup/velsel_utility.c psi/motor/Makefile psi/motor/el734_test psi/motor/el734_test.c psi/motor/makeprint.c psi/sinqhm/FOCUS_gbl.h psi/sinqhm/FOCUS_srv_main.c psi/sinqhm/Makefile psi/sinqhm/SinqHM_bootParamsConfig.c psi/sinqhm/SinqHM_bootUtil.c psi/sinqhm/SinqHM_def.h psi/sinqhm/SinqHM_gbl.h psi/sinqhm/SinqHM_srv_filler.c psi/sinqhm/SinqHM_srv_main.c psi/sinqhm/SinqHM_srv_routines.c psi/sinqhm/SinqHM_srv_server.c psi/sinqhm/bld psi/sinqhm/bld2 psi/sinqhm/bldmen psi/sinqhm/hist_mem_notes.tex psi/sinqhm/hist_mem_spec.tex psi/sinqhm/hist_mem_spec_fig1.ps psi/sinqhm/hist_mem_spec_fig2.ps psi/sinqhm/hist_mem_spec_fig3.ps psi/sinqhm/hist_mem_spec_fig4.ps psi/sinqhm/lwl_client.c psi/sinqhm/lwl_server.c psi/sinqhm/make_sinqhm.com psi/sinqhm/monitor.c psi/sinqhm/psi_logo.ps psi/sinqhm/sinq_logo.ps psi/sinqhm/sinqhm_bootutil_client.c psi/sinqhm/sinqhm_client.c psi/sinqhm/sinqhm_ctrl.c psi/sinqhm/usrConfig.c psi/sinqhm/usrConfig.c_diffs psi/sinqhm/usrConfig2604.c psi/sinqhm/vmio10_def.h psi/sinqhm/vmio_utility.c psi/tecs/coc_client.c psi/tecs/coc_client.h psi/tecs/coc_logfile.c psi/tecs/coc_logfile.h psi/tecs/coc_server.c psi/tecs/coc_server.h psi/tecs/coc_util.c psi/tecs/coc_util.h psi/tecs/fortify1.c psi/tecs/instr_hosts.c psi/tecs/instr_hosts.h psi/tecs/keep_running.c psi/tecs/make_gen psi/tecs/make_opt psi/tecs/make_opt_alpha psi/tecs/make_opt_llc psi/tecs/makefile psi/tecs/makefile_alpha psi/tecs/makefile_linux psi/tecs/myc_buf.c psi/tecs/myc_buf.h psi/tecs/myc_err.c psi/tecs/myc_err.h psi/tecs/myc_fortran.h psi/tecs/myc_mem.h psi/tecs/myc_str.c psi/tecs/myc_str.h psi/tecs/myc_time.c psi/tecs/myc_time.h psi/tecs/myc_tmp.c psi/tecs/myc_tmp.h psi/tecs/rstart.c psi/tecs/six.c psi/tecs/str.f psi/tecs/sys_cmdpar.f psi/tecs/sys_date.f psi/tecs/sys_env.c psi/tecs/sys_get_key.f psi/tecs/sys_getenv.f psi/tecs/sys_lun.f psi/tecs/sys_open.f psi/tecs/sys_open_alpha.f psi/tecs/sys_rdline.c psi/tecs/sys_select.c psi/tecs/sys_select.h psi/tecs/sys_unix.c psi/tecs/sys_wait.f psi/tecs/tecs.bld psi/tecs/tecs.c psi/tecs/tecs.tcl psi/tecs/tecs_c.c psi/tecs/tecs_c.h psi/tecs/tecs_cli.c psi/tecs/tecs_cli.h psi/tecs/tecs_client.f psi/tecs/tecs_data.c psi/tecs/tecs_data.h psi/tecs/tecs_dlog.inc psi/tecs/tecs_for.f psi/tecs/tecs_lsc.c psi/tecs/tecs_lsc.h psi/tecs/tecs_plot.f psi/tecs/tecs_serial.c psi/tecs/tecs_serial.h psi/tecs/term.c psi/tecs/term.h psi/utils/Makefile psi/utils/SerPortServer.c psi/utils/asynsrv_test.c psi/utils/ecb-load.c psi/utils/el734.c psi/utils/el734_test.c psi/utils/el737.c psi/utils/make.ecb psi/utils/check/amorcheck psi/utils/check/dmccheck psi/utils/check/focuscheck psi/utils/check/focusstatus.tcl psi/utils/check/hrptcheck psi/utils/check/sanscheck psi/utils/check/sicssyntax.tex psi/utils/check/sicssyntaxlib.tcl psi/utils/check/test.tcl psi/utils/check/topsicheck psi/utils/check/tricscheck psi/utils/check/tst
447 lines
11 KiB
C
447 lines
11 KiB
C
/*---------------------------------------------------------------------------
|
|
|
|
Splitter: a module to break a line in a list of words,
|
|
therby determinig type and storing results in a List.
|
|
|
|
Mark Koennecke October 1996
|
|
|
|
Free for non commercial use, no warranties of any kind taken.
|
|
---------------------------------------------------------------------------*/
|
|
#include "fortify.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include "splitter.h"
|
|
|
|
typedef enum _CharType {eSpace, eNum,eeText,eQuote} CharType;
|
|
|
|
|
|
/* ------------------------ local prototypes ------------------------------*/
|
|
|
|
static TokenList *CreateToken(TokenList *pN, TokenList *P);
|
|
static CharType CheckSpecial(char *pWord);
|
|
static int isEnd(char c);
|
|
|
|
/*=========================================================================*/
|
|
|
|
static TokenList *CreateToken(TokenList *pN, TokenList *pP)
|
|
{
|
|
TokenList *pRes = NULL;
|
|
|
|
pRes = (TokenList *) malloc(sizeof(TokenList));
|
|
if(!pRes)return NULL;
|
|
|
|
pRes->fVal = .0;
|
|
pRes->iVal = 0;
|
|
pRes->Type = eUndefined;
|
|
pRes->text = NULL;
|
|
pRes->pNext = pN;
|
|
if(pN)
|
|
{
|
|
pN->pPrevious = pRes;
|
|
}
|
|
pRes->pPrevious = pP;
|
|
if(pP)
|
|
{
|
|
pP->pNext = pRes;
|
|
}
|
|
return pRes;
|
|
}
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static CharType CheckSpecial(char *pWord)
|
|
{
|
|
CharType eRes = eText;
|
|
int iFlag = 0;
|
|
|
|
if(isspace(pWord[0]))return(eSpace);
|
|
if(isdigit(pWord[0]))return(eNum);
|
|
|
|
/* simple cases */
|
|
if(pWord[0] == '*') return(eeText);
|
|
if(pWord[0] == '/') return(eeText);
|
|
if(pWord[0] == '\\') return(eeText);
|
|
if(pWord[0] == ']') return(eeText);
|
|
if(pWord[0] == '[') return(eeText);
|
|
if(pWord[0] == '"') return(eQuote);
|
|
|
|
/* difficult cases, next characters will be searched for decision*/
|
|
|
|
if( pWord[0] == '-') iFlag = 1;
|
|
if( pWord[0] == '+') iFlag = 1;
|
|
if( pWord[0] == '.') iFlag = 1;
|
|
|
|
if (iFlag == 1)
|
|
{
|
|
|
|
if( isdigit(pWord[1]) )
|
|
{
|
|
return(eNum);
|
|
}
|
|
else if( isalpha(pWord[1] ))
|
|
{
|
|
return(eeText);
|
|
}
|
|
else if (!isspace( pWord[1]) )
|
|
{
|
|
pWord++;
|
|
return(CheckSpecial(pWord));
|
|
}
|
|
}
|
|
|
|
return(eeText);
|
|
}
|
|
/*--------------------------------------------------------------------------*/
|
|
static int isEnd(char c)
|
|
{
|
|
if( (c == '\0') || (c == '\n') || (c == '\r') )
|
|
{
|
|
return 2;
|
|
}
|
|
else if ( c== ' ')
|
|
{
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
TokenList *SplitText(char *pLine)
|
|
{
|
|
TokenList *pList = NULL;
|
|
TokenList *pCurrent;
|
|
char pBueffel[132];
|
|
char *pChar;
|
|
CharType eWhat;
|
|
int i;
|
|
|
|
if(!pLine)return NULL;
|
|
|
|
pChar = pLine;
|
|
|
|
/* loop through line */
|
|
while(isEnd(*pChar) != 2)
|
|
{
|
|
|
|
eWhat = CheckSpecial(pChar);
|
|
|
|
/* skip spaces */
|
|
if (eWhat == eSpace)
|
|
{
|
|
pChar++;
|
|
continue;
|
|
}
|
|
|
|
/* no space, read word in first place */
|
|
if(eWhat == eQuote)
|
|
{
|
|
i = 0;
|
|
pChar++;
|
|
while( (isEnd(*pChar) != 2) && (CheckSpecial(pChar) != eQuote))
|
|
{
|
|
pBueffel[i] = *pChar;
|
|
i++;
|
|
pChar++;
|
|
}
|
|
pBueffel[i] = '\0';
|
|
pChar++;
|
|
eWhat = eeText;
|
|
}
|
|
else
|
|
{
|
|
i = 0;
|
|
while(!isEnd(*pChar))
|
|
{
|
|
pBueffel[i] = *pChar;
|
|
i++;
|
|
pChar++;
|
|
}
|
|
pBueffel[i] = '\0';
|
|
}
|
|
if(pList == NULL)
|
|
{
|
|
pList = CreateToken(NULL,NULL);
|
|
pCurrent = pList;
|
|
}
|
|
else
|
|
{
|
|
pCurrent = CreateToken(NULL,pCurrent);
|
|
}
|
|
if(!pCurrent) return NULL;
|
|
|
|
/* copyy text always */
|
|
pCurrent->text = strdup(pBueffel);
|
|
if(eWhat == eeText)
|
|
{
|
|
pCurrent->Type = eText;
|
|
}
|
|
else if(eWhat == eNum)
|
|
{
|
|
/* float ? */
|
|
if(strchr(pBueffel,'.')== NULL)
|
|
{
|
|
pCurrent->Type = eInt;
|
|
sscanf(pBueffel,"%ld",&(pCurrent->iVal));
|
|
}
|
|
else
|
|
{
|
|
pCurrent->Type = eFloat;
|
|
sscanf(pBueffel,"%f",&(pCurrent->fVal));
|
|
}
|
|
}
|
|
/* pChar++;*/ if(isEnd(*pChar) == 2)break;
|
|
} /* eof big while */
|
|
return pList;
|
|
|
|
}
|
|
/*--------------------------------------------------------------------------*/
|
|
void DeleteTokenList(TokenList *pToken)
|
|
{
|
|
TokenList *pCurrent;
|
|
TokenList *pTemp;
|
|
|
|
pCurrent = pToken;
|
|
while(pCurrent != NULL)
|
|
{
|
|
pTemp = pCurrent->pNext;
|
|
if(pCurrent->text)
|
|
{
|
|
free(pCurrent->text);
|
|
}
|
|
free(pCurrent);
|
|
pCurrent = pTemp;
|
|
}
|
|
}
|
|
/*--------------------------------------------------------------------------*/
|
|
TokenList *SplitArguments(int argc, char *argv[])
|
|
{
|
|
int i, ii;
|
|
TokenList *pList = NULL;
|
|
TokenList *pCurrent;
|
|
CharType eWhat;
|
|
|
|
/* loop through arguments */
|
|
for( i = 0; i < argc; i++)
|
|
{
|
|
/* figure out what we have */
|
|
for(ii = 0; ii < strlen(argv[i]); ii++)
|
|
{
|
|
eWhat = CheckSpecial(argv[i]);
|
|
|
|
/* skip whitespace */
|
|
if(eWhat == eSpace)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
/* Create Token */
|
|
if(pList == NULL)
|
|
{
|
|
pList = CreateToken(NULL, pList);
|
|
pCurrent = pList;
|
|
}
|
|
else
|
|
{
|
|
pCurrent = CreateToken(NULL,pCurrent);
|
|
}
|
|
if(!pCurrent)
|
|
return NULL;
|
|
|
|
/* copy text always */
|
|
pCurrent->text = strdup(argv[i]);
|
|
|
|
/* text */
|
|
if(eWhat == eeText)
|
|
{
|
|
pCurrent->Type = eText;
|
|
break;
|
|
}
|
|
|
|
/* numbers */
|
|
if(eWhat == eNum)
|
|
{
|
|
/* float ? */
|
|
if(strchr(argv[i],'.')== NULL)
|
|
{
|
|
pCurrent->Type = eInt;
|
|
/* sscanf(argv[i],"%d",&(pCurrent->iVal));
|
|
*/ pCurrent->iVal = atoi(argv[i]);
|
|
}
|
|
else
|
|
{
|
|
pCurrent->Type = eFloat;
|
|
sscanf(argv[i],"%f",&(pCurrent->fVal));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return pList;
|
|
}
|
|
/*--------------------------------------------------------------------------*/
|
|
int Text2Arg(char *pLine, int *argc, char **argv[])
|
|
{
|
|
TokenList *pList = NULL;
|
|
TokenList *pCurrent = NULL;
|
|
char **margv = NULL;
|
|
int margc = 0;
|
|
int i = 0;
|
|
|
|
/* split to a TokenList */
|
|
pList = SplitText(pLine);
|
|
if(!pList)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
/* figure out how many args */
|
|
pCurrent = pList;
|
|
while(pCurrent)
|
|
{
|
|
margc++;
|
|
pCurrent = pCurrent->pNext;
|
|
}
|
|
|
|
/* allocate memory */
|
|
margv = (char **)malloc((margc + 2) * sizeof(char *));
|
|
if(!margv)
|
|
{
|
|
DeleteTokenList(pList);
|
|
return 0;
|
|
}
|
|
|
|
/* copy to argc, argv */
|
|
*argc = margc;
|
|
pCurrent = pList;
|
|
i = 0;
|
|
while(pCurrent)
|
|
{
|
|
margv[i] = strdup(pCurrent->text);
|
|
i++;
|
|
pCurrent = pCurrent->pNext;
|
|
}
|
|
|
|
/* done, clean up etc */
|
|
margv[i] = NULL;
|
|
*argv = margv;
|
|
DeleteTokenList(pList);
|
|
return 1;
|
|
|
|
}
|
|
/*---------------------------------------------------------------------------*/
|
|
int Arg2Text(int argc, char *argv[], char *buf, int iBufLen)
|
|
{
|
|
int i, iBufCount = 0;
|
|
|
|
if(argc < 1)
|
|
{
|
|
strcpy(buf,"\0");
|
|
return 1;
|
|
}
|
|
if(strlen(argv[0]) < iBufLen)
|
|
{
|
|
strcpy(buf, argv[0]);
|
|
iBufCount += strlen(argv[0]);
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
for(i = 1; i < argc; i++)
|
|
{
|
|
strcat(buf," ");
|
|
iBufCount += strlen(argv[i]) + 1;
|
|
if(iBufCount >= iBufLen)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
strcat(buf,argv[i]);
|
|
/* strcat(buf," "); */
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
/*--------------------------------------------------------------------------*/
|
|
int GetShellLine(FILE *fd, char *Buffer, int iBufLen)
|
|
{
|
|
char *pChar = NULL;
|
|
|
|
while(fgets(Buffer,iBufLen-1,fd) != NULL)
|
|
{
|
|
if(Buffer[0] != '#')
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
return EOF;
|
|
}
|
|
/*---------------------------------------------------------------------*/
|
|
int isNumeric(char *pText)
|
|
{
|
|
int i, ii, iGood;
|
|
static char pNum[13] = {"1234567890.+-"};
|
|
|
|
for(i = 0; i < strlen(pText); i++)
|
|
{
|
|
for(ii = 0; ii < 13; ii++)
|
|
{
|
|
iGood = 0;
|
|
if(pText[i] == pNum[ii])
|
|
{
|
|
iGood = 1;
|
|
break;
|
|
}
|
|
}
|
|
if(!iGood)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
/*============================================================================
|
|
|
|
Testprogram, can be activated by defining MAIN
|
|
*/
|
|
|
|
#ifdef MAIN
|
|
int main(int argc, char *argv[])
|
|
{
|
|
TokenList *pList = NULL;
|
|
TokenList *pCurrent;
|
|
|
|
pList = SplitText("Hallo 22 mal 0.8 Furz");
|
|
pCurrent = pList;
|
|
while(pCurrent)
|
|
{
|
|
if(pCurrent->Type == eText)
|
|
{
|
|
printf("TextToken = %s\n",pCurrent->text);
|
|
}
|
|
else if(pCurrent->Type == eFloat)
|
|
{
|
|
printf("FloatToken = %f\n",pCurrent->fVal);
|
|
}
|
|
else if(pCurrent->Type == eInt)
|
|
{
|
|
printf("IntToken = %d\n",pCurrent->iVal);
|
|
}
|
|
else
|
|
{
|
|
puts("ERRRRRRRRRROOOOOOOOOOOORRRRRRR!!!!!!!!");
|
|
}
|
|
pCurrent = pCurrent->pNext;
|
|
|
|
}
|
|
DeleteTokenList(pList);
|
|
|
|
}
|
|
#endif
|
|
|