Add ioccrfArgArgv argument type to support functions which take an

arbitrary number of arguments (e.g. show).  Clean up help display
of argument desciptors containing spaces.
This commit is contained in:
W. Eric Norum
2001-03-17 18:25:30 +00:00
parent 7ec189d2ce
commit 45de0e4e1f
6 changed files with 35 additions and 41 deletions

View File

@@ -53,7 +53,7 @@ static void dbstatCallFunc(const ioccrfArgBuf *args) { dbstat();}
/* dbp */
static const ioccrfArg dbpArg0 = { "record name",ioccrfArgString};
static const ioccrfArg dbpArg1 = { "interest_level",ioccrfArgInt};
static const ioccrfArg dbpArg1 = { "interest level",ioccrfArgInt};
static const ioccrfArg * const dbpArgs[2] = {&dbpArg0,&dbpArg1};
static const ioccrfFuncDef dbpFuncDef = {"dbp",2,dbpArgs};
static void dbpCallFunc(const ioccrfArgBuf *args)

View File

@@ -41,7 +41,7 @@ static void dbDumpPathCallFunc(const ioccrfArgBuf *args)
/* dbDumpRecord */
static const ioccrfArg dbDumpRecordArg0 = { "pdbbase",ioccrfArgPdbbase};
static const ioccrfArg dbDumpRecordArg1 = { "recordTypeName",ioccrfArgString};
static const ioccrfArg dbDumpRecordArg2 = { "interest_level",ioccrfArgInt};
static const ioccrfArg dbDumpRecordArg2 = { "interest level",ioccrfArgInt};
static const ioccrfArg * const dbDumpRecordArgs[3] =
{&dbDumpRecordArg0,&dbDumpRecordArg1,&dbDumpRecordArg2};
static const ioccrfFuncDef dbDumpRecordFuncDef = {"dbDumpRecord",3,dbDumpRecordArgs};

View File

@@ -67,7 +67,7 @@ static void dbpfCallFunc(const ioccrfArgBuf *args)
/* dbpr */
static const ioccrfArg dbprArg0 = { "record name",ioccrfArgString};
static const ioccrfArg dbprArg1 = { "interest_level",ioccrfArgInt};
static const ioccrfArg dbprArg1 = { "interest level",ioccrfArgInt};
static const ioccrfArg * const dbprArgs[2] = {&dbprArg0,&dbprArg1};
static const ioccrfFuncDef dbprFuncDef = {"dbpr",2,dbprArgs};
static void dbprCallFunc(const ioccrfArgBuf *args)
@@ -95,7 +95,7 @@ static void dbtpfCallFunc(const ioccrfArgBuf *args)
/* dbior */
static const ioccrfArg dbiorArg0 = { "record name",ioccrfArgString};
static const ioccrfArg dbiorArg1 = { "interest_level",ioccrfArgInt};
static const ioccrfArg dbiorArg1 = { "interest level",ioccrfArgInt};
static const ioccrfArg * const dbiorArgs[2] = {&dbiorArg0,&dbiorArg1};
static const ioccrfFuncDef dbiorFuncDef = {"dbior",2,dbiorArgs};
static void dbiorCallFunc(const ioccrfArgBuf *args)
@@ -139,7 +139,7 @@ static void tpnCallFunc(const ioccrfArgBuf *args)
/* dblsr */
static const ioccrfArg dblsrArg0 = { "record name",ioccrfArgString};
static const ioccrfArg dblsrArg1 = { "interest_level",ioccrfArgInt};
static const ioccrfArg dblsrArg1 = { "interest level",ioccrfArgInt};
static const ioccrfArg * const dblsrArgs[2] = {&dblsrArg0,&dblsrArg1};
static const ioccrfFuncDef dblsrFuncDef = {"dblsr",2,dblsrArgs};
static void dblsrCallFunc(const ioccrfArgBuf *args)
@@ -153,7 +153,7 @@ static void scanpplCallFunc(const ioccrfArgBuf *args)
{ scanppl(args[0].dval);}
/* scanpel */
static const ioccrfArg scanpelArg0 = { "event_number",ioccrfArgInt};
static const ioccrfArg scanpelArg0 = { "event number",ioccrfArgInt};
static const ioccrfArg * const scanpelArgs[1] = {&scanpelArg0};
static const ioccrfFuncDef scanpelFuncDef = {"scanpel",1,scanpelArgs};
static void scanpelCallFunc(const ioccrfArgBuf *args)

View File

@@ -48,43 +48,31 @@ static void pwdCallFunc (const ioccrfArgBuf *args)
}
/* show (thread information) */
static const ioccrfArg showArg0 = { "task",ioccrfArgString};
static const ioccrfArg showArg1 = { "task",ioccrfArgString};
static const ioccrfArg showArg2 = { "task",ioccrfArgString};
static const ioccrfArg showArg3 = { "task",ioccrfArgString};
static const ioccrfArg showArg4 = { "task",ioccrfArgString};
static const ioccrfArg showArg5 = { "task",ioccrfArgString};
static const ioccrfArg showArg6 = { "task",ioccrfArgString};
static const ioccrfArg showArg7 = { "task",ioccrfArgString};
static const ioccrfArg showArg8 = { "task",ioccrfArgString};
static const ioccrfArg showArg9 = { "task",ioccrfArgString};
static const ioccrfArg * const showArgs[10] = {
&showArg0,&showArg1,&showArg2,&showArg3,&showArg4,
&showArg5,&showArg6,&showArg7,&showArg8,&showArg9,
};
static const ioccrfFuncDef showFuncDef = {"show",10,showArgs};
static const ioccrfArg showArg0 = { "[-level] [task ...]", ioccrfArgArgv};
static const ioccrfArg * const showArgs[1] = { &showArg0 };
static const ioccrfFuncDef showFuncDef = {"show",1,showArgs};
static void showCallFunc(const ioccrfArgBuf *args)
{
int i = 0;
int i = 1;
int first = 1;
int level = 0;
char *cp;
const char *cp;
epicsThreadId tid;
unsigned long ltmp;
int argc = args[0].ival;
const char * const *argv = args[1].vval;
char *endp;
if (((cp = args[i].sval) != NULL)
&& (*cp == '-')) {
if ((i < argc) && (*(cp = argv[i]) == '-')) {
level = atoi (cp + 1);
i++;
}
if ((cp = args[i].sval) == NULL) {
if (i >= argc) {
epicsThreadShowAll (level);
return;
}
for ( ; i < 10 ; i++) {
if ((cp = args[i].sval) == NULL)
return;
for ( ; i < argc ; i++) {
cp = argv[i];
ltmp = strtoul (cp, &endp, 16);
if (*endp) {
tid = epicsThreadGetId (cp);

View File

@@ -402,13 +402,12 @@ ioccrf (const char *pathname)
fputs (pioccrfFuncDef->name, stdout);
for (int a = 0 ; a < pioccrfFuncDef->nargs ; a++) {
const char *cp = pioccrfFuncDef->arg[a]->name;
putchar (' ');
while (*cp != '\0') {
if (isspace (*cp))
putchar ('_');
else
putchar (*cp);
cp++;
if ((pioccrfFuncDef->arg[a]->type == ioccrfArgArgv)
|| (strchr (cp, ' ') == NULL)) {
printf (" %s", cp);
}
else {
printf (" '%s'", cp);
}
}
putchar ('\n');
@@ -432,13 +431,11 @@ ioccrf (const char *pathname)
* Process arguments and call function
*/
for (int arg = 0 ; ; arg++) {
char *p = (arg < argc) ? argv[arg+1] : NULL;
if (arg == pioccrfFuncDef->nargs) {
(*found->func)(argBuf);
break;
}
if (arg >= argBufCapacity) {
if ((arg+1) >= argBufCapacity) {
void *np;
argBufCapacity += 20;
@@ -450,7 +447,15 @@ ioccrf (const char *pathname)
}
argBuf = (ioccrfArgBuf *)np;
}
if (!cvtArg (filename, lineno, p, &argBuf[arg], pioccrfFuncDef->arg[arg]))
if (pioccrfFuncDef->arg[arg]->type == ioccrfArgArgv) {
argBuf[arg].ival = argc-arg;
argBuf[arg+1].vval = argv+arg;
(*found->func)(argBuf);
break;
}
if (!cvtArg (filename, lineno,
((arg < argc) ? argv[arg+1] : NULL),
&argBuf[arg], pioccrfFuncDef->arg[arg]))
break;
}
}

View File

@@ -21,7 +21,8 @@ typedef enum {
ioccrfArgInt,
ioccrfArgDouble,
ioccrfArgString,
ioccrfArgPdbbase
ioccrfArgPdbbase,
ioccrfArgArgv
}ioccrfArgType;
typedef union ioccrfArgBuf {