From f4cb31d5d5eb46577b25f021a219b47d122334df Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 27 Oct 2023 08:57:12 -0700 Subject: [PATCH] dbRecordField() add "did you mean..." hint for unknown field --- .../database/src/ioc/dbStatic/dbLexRoutines.c | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/database/src/ioc/dbStatic/dbLexRoutines.c b/modules/database/src/ioc/dbStatic/dbLexRoutines.c index 4819d4a41..16124d64e 100644 --- a/modules/database/src/ioc/dbStatic/dbLexRoutines.c +++ b/modules/database/src/ioc/dbStatic/dbLexRoutines.c @@ -1167,8 +1167,28 @@ static void dbRecordField(char *name,char *value) pdbentry = ptempListNode->item; status = dbFindField(pdbentry,name); if (status) { - epicsPrintf("Record \"%s\" does not have a field \"%s\"\n", - dbGetRecordName(pdbentry), name); + epicsPrintf("%s Record \"%s\" does not have a field \"%s\"\n", + dbGetRecordTypeName(pdbentry), dbGetRecordName(pdbentry), name); + if(dbGetRecordName(pdbentry)) { + DBENTRY temp; + double bestSim = -1.0; + const dbFldDes *bestFld = NULL; + dbCopyEntryContents(pdbentry, &temp); + for(status = dbFirstField(&temp, 0); !status; status = dbNextField(&temp, 0)) { + double sim = epicsStrSimilarity(name, temp.pflddes->name); + if(!bestFld || sim > bestSim) { + bestSim = sim; + bestFld = temp.pflddes; + } + } + dbFinishEntry(&temp); + if(bestSim>0.0) { + epicsPrintf(" Did you mean \"%s\"?", bestFld->name); + if(bestFld->prompt) + epicsPrintf(" (%s)", bestFld->prompt); + epicsPrintf("\n"); + } + } yyerror(NULL); return; }