📄 trsapi.c
字号:
}
ReadSource=TRS_Default;
if (def[0]==0) return RETRY;
strcpy(buf,def);
continue;
case '!' :switch (buf[1]) {
case 'q': FlowStatus=TRS_QUIT;break;
case 'r': FlowStatus=TRS_RETRY;break;
case 'p': FlowStatus=TRS_PREVIOUS;break;
case 'e': FlowStatus=TRS_EXIT;break;
case 't': FlowStatus=TRS_TOP;break;
default : return RETRY;
};break;
case HELP_PREFIX:
trsPrintHelp(CurrentTest,buf[1],dstname,def,help);return RETRY;
default: return TRUE;
}
return FALSE;
}
}
TRSFUN(int, _trsCaseRead,(int *dst, char *name, char *items,char *def,char *help)){
char sep[2]=" ";
char buf[INPBUF_LEN];
char head[INPBUF_LEN],tail[INPBUF_LEN];
int res;
char* tname=name+1;
if ((!dst) || (!items) || (!def) || (!help)) return -1;
for(;;) {
sep[0]=items[0];
StrParse(items,sep,2,head,tail);
res=CmdWithoutPrefix(buf,"Select ",tname,tail,def,help);
switch (res) {
case RETRY : continue;
case FALSE : return FALSE;
case TRUE :
for (res=0;tail[0]!=0;res=res+1) {
StrParse(tail,sep,2,head,tail);
if (!strcmp(buf,head)) {
(*dst)=res;FlowStatus=TRS_CONTINUE;
return TRUE;
}
};
continue;
};
};
}
TRSFUN(int, _trsBitRead,(long int *dst, char *name, char *items,char *def, char *help)){
char sep[2]=" ";
char buf[INPBUF_LEN],bufhead[INPBUF_LEN];
char head[INPBUF_LEN],tail[INPBUF_LEN];
int res,bitno;
long int bitset=0;
char* tname=name+1;
if ((!dst) || (!items) || (!def) || (!help)) return -1;
for(;;) {
sep[0]=items[0];
StrParse(items,sep,2,head,tail);
res=CmdWithoutPrefix(buf,"Bits of ",tname,tail,def,help);
switch (res) {
case RETRY : continue;
case FALSE : return FALSE;
case TRUE :
for (;buf[0]!=0;) {
StrParse(buf,sep,2,bufhead,buf);
StrParse(items,sep,2,head,tail);
res=FALSE;
for (bitno=0;tail[0]!=0;bitno=bitno+1) {
StrParse(tail,sep,2,head,tail);
if (!strcmp(bufhead,head)) {
bitset=bitset | (1L<<bitno);
res=TRUE;break;
}
};
if (res) continue;
break;
}
if (res) {FlowStatus=TRS_CONTINUE;*dst=bitset;return TRUE;}
continue;
};
};
}
TRSFUN(int, _trstRead,(char * str,int size,char *name,char *def,char *help))
{
char buf[INPBUF_LEN];
int res;
for(;;) {
res=CmdWithoutPrefix(buf,prompt,name,"text",def,help);
switch (res) {
case RETRY : continue;
case FALSE : return FALSE;
case TRUE : StringnCpy(str,buf,size);
FlowStatus=TRS_CONTINUE;
return TRUE;
};
};
}
TRSFUN(int, trsPause,(char *def,char *help))
{
char buf[INPBUF_LEN];
int res;
for(;;) {
res=CmdWithoutPrefix(buf,"","Pause",help,def,help);
switch (res) {
case RETRY : continue;
case TRUE : return TRUE;
case FALSE : if (ReadSource==TRS_Default) return TRUE;
return FALSE;
};
};
}
TRSFUN(int, _trsiRead,(int * n,char *name,char *def,char *help))
{
char buf[INPBUF_LEN];
int res;
char* tname=name+1;
for(;;) {
res=CmdWithoutPrefix(buf,prompt,tname,"int",def,help);
switch (res) {
case RETRY : continue;
case FALSE : return FALSE;
case TRUE : res=sscanf(buf,"%ld",n);
if (res!=1) continue;
FlowStatus=TRS_CONTINUE;
return TRUE;
};
};
}
TRSFUN(int, _trssRead,(float *A,char *name,char *def,char *help))
{
char buf[INPBUF_LEN];
float a;
int res;
char* tname=name+1;
for(;;) {
res=CmdWithoutPrefix(buf,prompt,tname,"float",def,help);
switch (res) {
case RETRY : continue;
case FALSE : return FALSE;
case TRUE : res=sscanf(buf,"%f",&a);
if (res<1) continue;
*A=a;
FlowStatus=TRS_CONTINUE;
return TRUE;
};
};
}
TRSFUN(int, _trsdRead,(double *A,char *name,char *def,char *help))
{
char buf[INPBUF_LEN];
double a;
int res;
char* tname=name+1;
for(;;) {
res=CmdWithoutPrefix(buf,prompt,tname,"double",def,help);
switch (res) {
case RETRY : continue;
case FALSE : return FALSE;
case TRUE : res=sscanf(buf,"%lf",&a);
if (res<1) continue;
*A=a;
FlowStatus=TRS_CONTINUE;
return TRUE;
};
};
}
TRSFUN(int, _trssbRead,(float *A,char *name, int n,char *def,char *help))
{
char buf[INPBUF_LEN];
int res,i;
if ((n<=0) || (!A)) return FALSE;
for (i=0;i<n;i=i+1) {
sprintf(buf,"&%s[%d]",name,i);
res=_trssRead(&A[i],buf,def,help);
if (!res) return res;
};
return res;
}
TRSFUN(int, _trsdbRead,(double *A,char *name, int n,char *def,char *help))
{
char buf[INPBUF_LEN];
int res,i;
if ((n<=0) || (!A)) return FALSE;
for (i=0;i<n;i=i+1) {
sprintf(buf,"&%s[%d]",name,i);
res=_trsdRead(&A[i],buf,def,help);
if (!res) return res;
};
return res;
}
#endif
/* --- Output ---------------------------------------------------------------*/
TRSFUN(void, _trssPrint,(char *str,char *name,float src)){
printf("%s%s=(%+.8e)\n",str,name,src);
}
TRSFUN(void, _trsdPrint,(char *str,char *name,double src)){
printf("%s%s=(%+.17e)\n",str,name,src);
}
TRSFUN(void, _trssbPrint,(char *str, char *name,float *src, int n)){
int i;
if (!src) return;
for (i=0;i<n; i=i+1) {
printf("%s%s[%d]=(%+.8e)\n",str,name,i,src[i]);
};
}
TRSFUN(void, _trsdbPrint,(char *str, char *name,double *src, int n))
{
int i;
if (!src) return;
for (i=0;i<n; i=i+1) {
printf("%s%s[%d]=(%+.17e)\n",str,name,i,src[i]);
};
}
/*****************************************************************/
/* --- Generate special benchmark output file -------------------*/
/*****************************************************************/
static time_t StartTime;
#ifndef WIN32
typedef struct SYSTEM_INFO
{
int dwProcessorType;
}SYSTEM_INFO;
typedef struct OSVERSIONINFO
{
int dwPlatformId;
int dwMajorVersion;
int dwMinorVersion;
int dwBuildNumber;
int dwOSVersionInfoSize;
}OSVERSIONINFO;
#define GetSystemInfo(a)
#define GetVersionEx(a)
#define PROCESSOR_INTEL_386 1
#define PROCESSOR_INTEL_486 2
#define PROCESSOR_INTEL_PENTIUM 3
#define VER_PLATFORM_WIN32s 1
#define VER_PLATFORM_WIN32_NT 2
#endif
static void trsCSVHeader(void) {
SYSTEM_INFO SystemInfo;
OSVERSIONINFO OsVersion;
#ifdef ANYLIB
const IPLLibVersion *lib;
#endif
if (CsvFile) {
GetSystemInfo(&SystemInfo);
fprintf(CsvFile,"Header_begin\n");
fprintf(CsvFile," Processor,");
switch (SystemInfo.dwProcessorType) {
case PROCESSOR_INTEL_386: fprintf(CsvFile,"i386\n");break;
case PROCESSOR_INTEL_486: fprintf(CsvFile,"i486\n");break;
case PROCESSOR_INTEL_PENTIUM: fprintf(CsvFile,"Pentium\n");break;
default: fprintf(CsvFile,"Other\n");break;
}
OsVersion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(&OsVersion);
fprintf(CsvFile," OS,Windows");
switch (OsVersion.dwPlatformId) {
case VER_PLATFORM_WIN32s: fprintf(CsvFile,"32s on Windows");break;
case VER_PLATFORM_WIN32_NT:fprintf(CsvFile,"NT");break;
default: fprintf(CsvFile,"95");break;
}
fprintf(CsvFile," v%1ld.%1ld build %1ld\n",
OsVersion.dwMajorVersion,OsVersion.dwMinorVersion,
OsVersion.dwBuildNumber);
#ifdef ANYLIB
lib=iplGetLibVersion();
fprintf(CsvFile," Library,\"%s,%s,%s,%s,build %s\"\n",
lib->Name,lib->Version,lib->InternalVersion,
lib->CallConv,lib->BuildDate);
#endif
fprintf(CsvFile," Start_Date,\n");
time(&StartTime);
fprintf(CsvFile," Start_Time,%s",ctime(&StartTime));
fprintf(CsvFile,"Header_end\n");
fprintf(CsvFile,"Data_begin\n");
fprintf(CsvFile," Flavour,Function,Value,Units,Comments,Param1,Param2,Param3,Param4\n");
}
}
static void trsCSVFooter(void) {
time_t endTime;
double elapsedTime;
if (CsvFile) {
fprintf(CsvFile,"Data_end\n");
fprintf(CsvFile,"Footer_begin\n");
fprintf(CsvFile," End_Date,\n");
time(&endTime);
elapsedTime=difftime(endTime,StartTime);
fprintf(CsvFile," End_Time,%s",ctime(&endTime));
fprintf(CsvFile," Elapsed_Time,%.1f\n",elapsedTime);
fprintf(CsvFile,"Footer_end\n");
}
}
TRSFUN(void, trsCSVString9,(char *flavour, char *function,char *value,
char *units, char *comments,char *param1,
char *param2, char *param3, char *param4)) {
if (CsvFile) {
if (!units) units="us";
if (!comments) comments="";
if (!param1) param1="";
if (!param2) param2="";
if (!param3) param3="";
if (!param4) param4="";
fprintf(CsvFile," %s,%s,%s,%s,%s,%s,%s,%s,%s\n",
flavour,function,value,units,comments,
param1,param2,param3,param4);
fflush(CsvFile);
}
}
TRSFUN(void, trsCSVString10,(char *flavour, char *function,char *value,
char *units, char *comments,char *param1,
char *param2, char *param3, char *param4,
char *param5)) {
if (CsvFile) {
if (!units) units="us";
if (!comments) comments="";
if (!param1) param1="";
if (!param2) param2="";
if (!param3) param3="";
if (!param4) param4="";
if (!param5) param5="";
fprintf(CsvFile," %s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
flavour,function,value,units,comments,
param1,param2,param3,param4,param5);
fflush(CsvFile);
}
}
TRSFUN(void, trsCSVString11,(char *flavour, char *function,char *value,
char *units, char *comments,char *param1,
char *param2, char *param3, char *param4,
char *param5, char *param6)) {
if (CsvFile) {
if (!units) units="us";
if (!comments) comments="";
if (!param1) param1="";
if (!param2) param2="";
if (!param3) param3="";
if (!param4) param4="";
if (!param5) param5="";
if (!param6) param6="";
fprintf(CsvFile," %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
flavour,function,value,units,comments,
param1,param2,param3,param4,param5,param6);
fflush(CsvFile);
}
}
TRSFUN(void, trsCSVString5,(char *flavour,char *function,char *value,
char *units, char *comments)) {
trsCSVString9(flavour,function,value,units,comments,
NULL,NULL,NULL,NULL);
}
TRSFUN(void, trsCSVString6,(char *flavour,char *function,char *value,
char *units, char *comments,char *param1) {
trsCSVString9(flavour,function,value,units,comments,
param1,NULL,NULL,NULL));
}
TRSFUN(void, trsCSVString7,(char *flavour,char *function,char *value,
char *units, char *comments,
char *param1, char *param2)) {
trsCSVString9(flavour,function,value,units,comments,
param1,param2,NULL,NULL);
}
TRSFUN(void, trsCSVString8,(char *flavour,char *function,char *value,
char *units, char *comments,
char *param1, char *param2, char *param3)) {
trsCSVString9(flavour,function,value,units, comments,
param1,param2,param3,NULL);
}
#define BUF_NO 9
static char buf[BUF_NO][64];
static int buf_idx=0;
static void Next_buf_idx(void) {
buf_idx=(buf_idx+1)%BUF_NO;
}
TRSFUN(char *, trsFloat,(float src)) {
Next_buf_idx();
sprintf(buf[buf_idx],"%e",src)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -