Provide epicsStrGlobMatch().

Add globbing to iocsh help command.
This commit is contained in:
W. Eric Norum
2004-10-07 20:10:38 +00:00
parent 667ab7eab8
commit 0d6784c31b
4 changed files with 67 additions and 66 deletions
+1 -47
View File
@@ -194,52 +194,6 @@ long epicsShareAPI dbnr(int verbose)
return(0);
}
static int specified_by(const char *ptest, const char *pspec)
{
short inx;
short wild_card_start;
/* check if the specification begins with a wild card */
if (*pspec == '*') wild_card_start = TRUE;
else wild_card_start = FALSE;
/* check for specification */
while (TRUE) {
/* skip any wild cards */
while (*pspec == '*') pspec++;
/* find the specification chars to compare */
inx = 0;
while ( (*(pspec+inx) != '*') && (*(pspec+inx)) )
inx++;
/* check for specification ending with wildcard */
if (inx == 0) return(TRUE);
/* find the spec chars in the test string */
while ((strlen(ptest) >= inx)
&& (strncmp(ptest,pspec,inx) != 0) ) {
/* check variable beginning */
if (!wild_card_start) return(FALSE);
else ptest++;
}
/* check segment found */
if (strlen(ptest) < inx) return(FALSE);
/* adjust pointers and wild card indication */
wild_card_start = TRUE;
ptest += inx;
pspec += inx;
/* check for end of specification */
if (*pspec == 0) {
if (*ptest == 0) return(TRUE);
else return(FALSE);
}
}
}
long epicsShareAPI dbgrep(const char *pmask)
{
@@ -262,7 +216,7 @@ long epicsShareAPI dbgrep(const char *pmask)
status = dbFirstRecord(pdbentry);
while(!status) {
pname = dbGetRecordName(pdbentry);
if (specified_by(pname, pmask)) printf("%s\n", pname);
if (epicsStrGlobMatch(pname, pmask)) printf("%s\n", pname);
status = dbNextRecord(pdbentry);
}
status = dbNextRecordType(pdbentry);
+17 -19
View File
@@ -370,15 +370,15 @@ static void helpCallFunc(const iocshArgBuf *args)
int argc = args[0].aval.ac;
const char * const * argv = args[0].aval.av;
struct iocshFuncDef const *piocshFuncDef;
struct iocshCommand *found;
struct iocshCommand *pcmd;
if (argc == 1) {
int l, col = 0;
printf ("Type `help command_name' to get more information about a particular command.\n");
iocshTableLock ();
for (found = iocshCommandHead ; found != NULL ; found = found->next) {
piocshFuncDef = found->pFuncDef;
for (pcmd = iocshCommandHead ; pcmd != NULL ; pcmd = pcmd->next) {
piocshFuncDef = pcmd->pFuncDef;
l = strlen (piocshFuncDef->name);
if ((l + col) >= 79) {
fputc ('\n', stdout);
@@ -403,24 +403,22 @@ static void helpCallFunc(const iocshArgBuf *args)
}
else {
for (int iarg = 1 ; iarg < argc ; iarg++) {
found = (iocshCommand *)registryFind (iocshCmdID, argv[iarg]);
if (found == NULL) {
printf ("%s -- no such command.\n", argv[iarg]);
}
else {
piocshFuncDef = found->pFuncDef;
fputs (piocshFuncDef->name, stdout);
for (int a = 0 ; a < piocshFuncDef->nargs ; a++) {
const char *cp = piocshFuncDef->arg[a]->name;
if ((piocshFuncDef->arg[a]->type == iocshArgArgv)
|| (strchr (cp, ' ') == NULL)) {
fprintf (stdout, " %s", cp);
}
else {
fprintf (stdout, " '%s'", cp);
for (pcmd = iocshCommandHead ; pcmd != NULL ; pcmd = pcmd->next) {
piocshFuncDef = pcmd->pFuncDef;
if (epicsStrGlobMatch(piocshFuncDef->name, argv[iarg]) != 0) {
fputs (piocshFuncDef->name, stdout);
for (int a = 0 ; a < piocshFuncDef->nargs ; a++) {
const char *cp = piocshFuncDef->arg[a]->name;
if ((piocshFuncDef->arg[a]->type == iocshArgArgv)
|| (strchr (cp, ' ') == NULL)) {
fprintf (stdout, " %s", cp);
}
else {
fprintf (stdout, " '%s'", cp);
}
}
fprintf (stdout,"\n");;
}
fprintf (stdout,"\n");;
}
}
}
+47
View File
@@ -204,3 +204,50 @@ epicsShareFunc int epicsShareAPI epicsStrSnPrintEscaped(
}
return nout;
}
epicsShareFunc int epicsShareAPI epicsStrGlobMatch(
const char *str, const char *pattern)
{
int inx;
int wild_card_start;
/* check if the specification begins with a wild card */
if (*pattern == '*') wild_card_start = 1;
else wild_card_start = 0;
/* check for specification */
while (1) {
/* skip any wild cards */
while (*pattern == '*') pattern++;
/* find the specification chars to compare */
inx = 0;
while ( (*(pattern+inx) != '*') && (*(pattern+inx)) )
inx++;
/* check for specification ending with wildcard */
if (inx == 0) return 1;
/* find the spec chars in the test string */
while ((strlen(str) >= inx)
&& (strncmp(str,pattern,inx) != 0) ) {
/* check variable beginning */
if (!wild_card_start) return 0;
else str++;
}
/* check segment found */
if (strlen(str) < inx) return 0;
/* adjust pointers and wild card indication */
wild_card_start = 1;
str += inx;
pattern += inx;
/* check for end of specification */
if (*pattern == '\0') {
if (*str == 0) return 1;
else return 0;
}
}
}
+2
View File
@@ -30,6 +30,8 @@ epicsShareFunc int epicsShareAPI epicsStrPrintEscaped(
FILE *fp, const char *s, int n);
epicsShareFunc int epicsShareAPI epicsStrSnPrintEscaped(
char *outbuf, int outsize, const char *inbuf, int inlen);
epicsShareFunc int epicsShareAPI epicsStrGlobMatch(
const char *str, const char *pattern);
#ifdef __cplusplus
}