Skip to content

Commit

Permalink
db: add set("link:scope", ...) syntax
Browse files Browse the repository at this point in the history
and dbLinkScopeDefault() private accessor

New DB syntax is:

  set '(' STR ( ',' STR )* ')'
  • Loading branch information
mdavidsaver committed Nov 25, 2023
1 parent 20dc6ae commit 979491e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/database/src/ioc/db/dbLink.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ long dbInitLink(struct link *plink, short dbfType)

srcMask = plink->value.pv_link.pvlMask & pvlOptSrcMask;

if(srcMask == pvlOptSrcAuto) {
/* apply default from set("link:scope", ...) */
srcMask = plink->flags & pvlOptSrcMask;
}

if((srcMask == pvlOptSrcInt) && dbChannelTest(plink->value.pv_link.pvname)) {
DBENTRY closest;
epicsPrintf("%s.%s " ERL_ERROR ": Unable to create INT link to \"" ANSI_BOLD("%s") "\".\n",
Expand Down
1 change: 1 addition & 0 deletions modules/database/src/ioc/dbStatic/dbLex.l
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static int yyreset(void)
"registrar" return(tokenREGISTRAR);
"function" return(tokenFUNCTION);
"variable" return(tokenVARIABLE);
"set" return(tokenSET);

{bareword}+ { /* unquoted string or number */
yylval.Str = dbmfStrdup((char *) yytext);
Expand Down
56 changes: 56 additions & 0 deletions modules/database/src/ioc/dbStatic/dbLexRoutines.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ typedef struct inputFile{
const char *filename;
FILE *fp;
int line_num;
unsigned linkDefLoc;
}inputFile;
static ELLLIST inputFileList = ELLLIST_INIT;

Expand Down Expand Up @@ -1292,6 +1293,61 @@ static void dbAlias(char *name, char *alias)
dbFinishEntry(pdbEntry);
}

static void warnSetUnknown(const char *name)
{
static ELLLIST warned;
ELLNODE *cur;
tempListNode *node;
size_t namelen = strlen(name);

for(cur = ellFirst(&warned); cur; cur = ellNext(cur)) {
node = CONTAINER(cur, tempListNode, node);
if(strcmp((char*)node->item, name)==0)
return; /* omit duplicate warning */
}

epicsPrintf(ERL_WARNING " Unknown name in set(\"%s\", ...)\n", name);

if(!!(node = malloc(sizeof(*node) + namelen + 1))) {
node->item = &node[1];
strcpy((char*)node->item, name);
ellAdd(&warned, &node->node);
}
}

static void dbSet(const char *name)
{
if(strcmp(name, "link:scope")==0) {
char* val = popFirstTemp();

if(!val || strcmp(val, "AUTO")==0 || strcmp(val, "EXT")==0) {
pinputFileNow->linkDefLoc = pvlOptSrcExt;

} else if(strcmp(val, "INT")==0) {
pinputFileNow->linkDefLoc = pvlOptSrcInt;

} else {
epicsPrintf(ERL_WARNING " Invalid value in set(\"%s\", \"%s\")\n", name, val);
}
dbmfFree(val);

} else {
warnSetUnknown(name);
}

/* clean up unused arguments */
while(ellCount(&tempList))
dbmfFree(popFirstTemp());
}

unsigned dbLinkScopeDefault(void)
{
int ret = pvlOptSrcExt;
if(pinputFileNow && pinputFileNow->linkDefLoc)
ret = pinputFileNow->linkDefLoc;
return ret;
}

static void dbRecordBody(void)
{
DBENTRY *pdbentry;
Expand Down
2 changes: 2 additions & 0 deletions modules/database/src/ioc/dbStatic/dbStaticLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,8 @@ long dbPutString(DBENTRY *pdbentry,const char *pstring)
free(plink->text);
plink->text = epicsStrDup(pstring);
dbFreeLinkInfo(&link_info);
/* capture default link scope */
plink->flags |= dbLinkScopeDefault();
} else {
/* assignment after init (eg. autosave restore) */
struct dbCommon *prec = pdbentry->precnode->precord;
Expand Down
2 changes: 2 additions & 0 deletions modules/database/src/ioc/dbStatic/dbStaticPvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ void dbPvdFreeMem(DBBASE *pdbbase);
DBCORE_API
char** dbCompleteRecord(const char *word);

unsigned dbLinkScopeDefault(void);

#ifdef __cplusplus
}
#endif
Expand Down
21 changes: 21 additions & 0 deletions modules/database/src/ioc/dbStatic/dbYacc.y
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static int yyAbort = 0;
%token tokenFIELD tokenINFO tokenREGISTRAR
%token tokenDEVICE tokenDRIVER tokenLINK tokenBREAKTABLE
%token tokenRECORD tokenGRECORD tokenVARIABLE tokenFUNCTION
%token tokenSET
%token <Str> tokenSTRING tokenCDEFS

%token jsonNULL jsonTRUE jsonFALSE
Expand Down Expand Up @@ -60,6 +61,7 @@ database_item: include
| tokenRECORD record_head record_body
| tokenGRECORD grecord_head record_body
| alias
| set
;

include: tokenINCLUDE tokenSTRING
Expand Down Expand Up @@ -278,6 +280,25 @@ alias: tokenALIAS '(' tokenSTRING ',' tokenSTRING ')'
dbAlias($3,$5); dbmfFree($3); dbmfFree($5);
};

set: tokenSET '(' tokenSTRING set_args ')'
{
if(dbStaticDebug>2) printf("set(%s\n",$3);
dbSet($3); dbmfFree($3);
/* dbSet() empties tempList */
};

set_args:
{
if (ellCount(&tempList))
yyerrorAbort("dbSet: tempList not empty");
}
| set_args ',' tokenSTRING
{
if(dbStaticDebug>2) printf(" %s,\n",$3);
allocTemp($3); /* takes ownership of $3 */
}
;

json_object: '{' '}'
{
$$ = dbmfStrdup("{}");
Expand Down
1 change: 1 addition & 0 deletions modules/database/src/ioc/dbStatic/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ DBCORE_API extern maplinkType pamaplinkType[];
/* DBLINK Flag bits */
#define DBLINK_FLAG_INITIALIZED 1 /* dbInitLink() called */
#define DBLINK_FLAG_TSELisTIME 2 /* Use TSEL to get timeStamp */
/* pvlOptSrc* bits also used to indicate default from file parsing. */

struct macro_link {
char *macroStr;
Expand Down

0 comments on commit 979491e

Please sign in to comment.