db: Suggest DBF_MENU values on parser error
This commit is contained in:
@@ -1187,6 +1187,7 @@ static void dbRecordField(char *name,char *value)
|
||||
errSymLookup(status, msg, sizeof(msg));
|
||||
epicsPrintf("Can't set \"%s.%s\" to \"%s\" %s : %s\n",
|
||||
dbGetRecordName(pdbentry), name, value, pdbentry->message ? pdbentry->message : "", msg);
|
||||
dbPutStringSuggest(pdbentry, value);
|
||||
yyerror(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2632,6 +2632,52 @@ long dbPutString(DBENTRY *pdbentry,const char *pstring)
|
||||
return(status);
|
||||
}
|
||||
|
||||
void dbPutStringSuggest(DBENTRY *pdbentry, const char *pstring)
|
||||
{
|
||||
dbFldDes *pflddes = pdbentry->pflddes;
|
||||
|
||||
switch (pflddes->field_type) {
|
||||
case DBF_MENU:
|
||||
case DBF_DEVICE: {
|
||||
int i, nchoices = 0;
|
||||
char** choices = NULL;
|
||||
const char *best = NULL;
|
||||
double maxdist = 0.0; /* don't offer suggestions which have no similarity */
|
||||
|
||||
if(pflddes->field_type==DBF_MENU) {
|
||||
dbMenu *pdbMenu = (dbMenu *)pflddes->ftPvt;
|
||||
if(!pdbMenu)
|
||||
return;
|
||||
|
||||
choices = pdbMenu->papChoiceValue;
|
||||
nchoices = pdbMenu->nChoice;
|
||||
|
||||
} else {
|
||||
dbDeviceMenu *pdbDeviceMenu = dbGetDeviceMenu(pdbentry);
|
||||
if(!pdbDeviceMenu)
|
||||
return;
|
||||
|
||||
choices = pdbDeviceMenu->papChoice;
|
||||
nchoices = pdbDeviceMenu->nChoice;
|
||||
}
|
||||
|
||||
for(i=0; i<nchoices; i++) {
|
||||
double dist = epicsStrSimilarity(pstring, choices[i]);
|
||||
if(dist>maxdist) {
|
||||
best = choices[i];
|
||||
maxdist = dist;
|
||||
}
|
||||
}
|
||||
if(best) {
|
||||
epicsPrintf(" Did you mean \"%s\"?\n", best);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char * dbVerify(DBENTRY *pdbentry, const char *pstring)
|
||||
{
|
||||
dbFldDes *pflddes = pdbentry->pflddes;
|
||||
|
||||
@@ -38,6 +38,8 @@ long dbPutStringNum(DBENTRY *pdbentry,const char *pstring);
|
||||
|
||||
void dbMsgPrint(DBENTRY *pdbentry, const char *fmt, ...) EPICS_PRINTF_STYLE(2,3);
|
||||
|
||||
void dbPutStringSuggest(DBENTRY *pdbentry, const char *pstring);
|
||||
|
||||
struct jlink;
|
||||
|
||||
typedef struct dbLinkInfo {
|
||||
|
||||
Reference in New Issue
Block a user