Replace dbVarSub with macLib.

Allow C style escape sequences
Fix long vx memory free list problem
Fix most compiler warning messages
This commit is contained in:
Marty Kraimer
1997-04-30 18:54:10 +00:00
parent 0d7698e0d4
commit b87f049c2d
11 changed files with 210 additions and 485 deletions

View File

@@ -149,7 +149,6 @@ int BSmakeServer(char** argv)
BS* BSipOpen(char* address, int Port)
{
struct hostent* pHostent;
unsigned long addr;
BSDATA info;
struct sockaddr_in* tsin;
@@ -166,6 +165,8 @@ BS* BSipOpen(char* address, int Port)
}
else
{
struct hostent* pHostent;
if((pHostent=gethostbyname(address))==NULL) return NULL;
memcpy((char*)&addr,pHostent->h_addr,sizeof(addr));
}
@@ -311,7 +312,6 @@ int BSsendData(BS* bdt,void* buffer,int size)
{
int len;
int remaining;
int rc;
if(bdt->state!=BSsData)
{
@@ -450,7 +450,6 @@ int BSreceiveHeader(BS* bdt,int* verb,int* size)
------------------------------------------------------------------------ */
int BSreceiveData(BS* bdt,void* buffer,int size)
{
int rc;
/* can only receive data when in the receive data state */
switch(bdt->state)
@@ -645,7 +644,6 @@ int BSsetPort(BSDATA* info, int dest_port)
int BSsetAddress(BSDATA* info, char* ip_addr)
{
struct hostent *pHostent;
struct sockaddr_in* sin = (struct sockaddr_in*)&(info->sin);
unsigned long addr;
@@ -659,6 +657,8 @@ int BSsetAddress(BSDATA* info, char* ip_addr)
}
else
{
struct hostent *pHostent;
if((pHostent=gethostbyname(ip_addr))==NULL) return -1;
memcpy((char*)&addr,pHostent->h_addr,sizeof(addr));
}
@@ -917,7 +917,6 @@ int BSgetBroadcastSocket(int port, struct sockaddr_in* sin)
{
int on=1;
int soc;
BS bs;
sin->sin_port=htons(port);
sin->sin_family=AF_INET;

View File

@@ -14,7 +14,6 @@ endif
# includes and manual pages to install:
#
INC := dbVarSub.h
MAN1 := dbLoadTemplate.1 subtool.1
MAN3 := dbLoadRecords.3 dbLoadTemplate.3
MAN5 := templatefile.5 dbfile.5
@@ -67,10 +66,10 @@ sub_src.c: dbLoadTemplate.c
#
sub_src_CFLAGS := -DSUB_TOOL
subtool$(EXE): sub_src$(OBJ) dbVarSub$(OBJ)
subtool$(EXE): sub_src$(OBJ)
$(LINK.c) $^ $(LDLIBS)
dbLoadTemplate$(EXE): dbVarSub$(OBJ) dbLoadTemplate$(OBJ) dbLoadRecords$(OBJ)
dbLoadTemplate$(EXE): dbLoadTemplate$(OBJ) dbLoadRecords$(OBJ)
$(LINK.c) $^ $(LDLIBS)
clean::

View File

@@ -4,10 +4,10 @@ include $(TOP)/config/CONFIG_BASE
YACCOPT = -l
LEXOPT = -L
SRCS.c = ../dbVarSub.c dbLoadTemplate_lex.c dbLoadTemplate.c \
SRCS.c = dbLoadTemplate_lex.c dbLoadTemplate.c \
dbLoadRecords_lex.c dbLoadRecords.c ../BSlib.c ../PVSvx.c ../vx_stats.c ../client_stats.c
LIBOBJS = dbVarSub.o dbLoadTemplate.o dbLoadRecords.o BSlib.o PVSvx.o vx_stats.o client_stats.o
LIBOBJS = dbLoadTemplate.o dbLoadRecords.o BSlib.o PVSvx.o vx_stats.o client_stats.o
LIBNAME = dbSubs
@@ -25,9 +25,9 @@ dbLoadTemplate.o: dbLoadTemplate_lex.c
dbLoadRecords.o: dbLoadRecords_lex.c
subtool: dbLoadTemplate_lex.c
subtool: dbLoadTemplate.c dbLoadTemplate_lex.c dbVarSub.o
subtool: dbLoadTemplate.c dbLoadTemplate_lex.c
$(RM) $@
$(LINK.c) $(CFLAGS) -DSUB_TOOL -o subtool dbLoadTemplate.c dbVarSub.o -s
$(LINK.c) $(CFLAGS) -DSUB_TOOL -o subtool dbLoadTemplate.c -s
clean::
@$(RM) dbLoadTemplate_lex.c dbLoadTemplate.c dbLoadRecords_lex.c \

View File

@@ -76,7 +76,7 @@ static int PVSannouce(int want_annouce,char* name)
{
int soc,mlen;
PVS_INFO_PACKET buf,in_buf;
BSDATA info,in_info;
BSDATA info;
if(want_annouce==0 && name)
{
@@ -116,7 +116,7 @@ static int PVSannouce(int want_annouce,char* name)
static void PVSserver(int want_annouce,char* name)
{
fd_set fds,rfds;
int tsoc,usoc,nsoc,len,s;
int tsoc,usoc,nsoc,len;
struct sockaddr stemp;
int stemp_len;
PVS_INFO_PACKET buf;
@@ -318,7 +318,7 @@ extern DBNODE* DbApplList;
void handle_applist(BS* bs)
{
DBNODE* n;
int size,len;
int len;
len=0;
for(n=DbApplList;n;n=n->next)

View File

@@ -36,7 +36,6 @@ void PVS_ClientStats(BS* bs)
{
int len;
char line[120];
char* ptr;
struct client *pclient;
/* report columns:

View File

@@ -35,14 +35,16 @@
#include <string.h>
#include <stdlib.h>
#include "dbVarSub.h"
#include "macLib.h"
#include "dbStaticLib.h"
#include "dbmf.h"
#include "epicsVersion.h"
static char subst_buffer[VAR_MAX_SUB_SIZE];
#define VAR_MAX_SUB_SIZE 300
static char *subst_buffer= NULL;
static int subst_used;
static int line_num;
static MAC_HANDLE *macHandle = NULL;
struct db_app_node
{
@@ -62,8 +64,15 @@ static void sub_pvname(char*,char*);
static DBENTRY* pdbentry;
extern struct dbBase *pdbbase;
#endif
static void* handle=NULL;
static char* strduplicate(char* x)
{
char* c;
c=(char*)malloc(strlen(x)+1);
strcpy(c,x);
return c;
}
%}
%start database
@@ -92,9 +101,9 @@ database: DATABASE d_head d_body
;
d_head: O_PAREN WORD C_PAREN
{ dbmfFree(handle,$2); }
{ dbmfFree($2); }
| O_PAREN WORD COMMA VALUE C_PAREN
{ dbmfFree(handle,$2); dbmfFree(handle,$4); }
{ dbmfFree($2); dbmfFree($4); }
;
d_body: O_BRACE nowhere_records db_components C_BRACE
@@ -123,12 +132,14 @@ applic: APPL O_PAREN VALUE C_PAREN
if(subst_used)
{
strcpy(subst_buffer,$<Str>3);
if(dbDoSubst(subst_buffer,sizeof(subst_buffer),NULL)!=0)
fprintf(stderr,"dbDoSubst failed\n");
int n;
n = macExpandString(macHandle,$<Str>3,subst_buffer,
VAR_MAX_SUB_SIZE-1);
if(n<0) fprintf(stderr,"macExpandString failed\n");
#ifdef vxWorks
an->name=strdup(subst_buffer);
dbmfFree(handle,$3);
an->name=strduplicate(subst_buffer);
dbmfFree($3);
#else
printf("\napplication(\"%s\")\n",subst_buffer);
#endif
@@ -136,7 +147,8 @@ applic: APPL O_PAREN VALUE C_PAREN
else
{
#ifdef vxWorks
an->name=$<Str>3;
an->name=strduplicate($<Str>3);
dbmfFree($3);
#else
printf("\napplication(\"%s\")\n",$<Str>3);
#endif
@@ -163,12 +175,12 @@ record: RECORD r_head r_body
r_head: O_PAREN WORD COMMA WORD C_PAREN
{
sub_pvname($2,$4);
dbmfFree(handle,$2); dbmfFree(handle,$4);
dbmfFree($2); dbmfFree($4);
}
| O_PAREN WORD COMMA VALUE C_PAREN
{
sub_pvname($2,$4);
dbmfFree(handle,$2); dbmfFree(handle,$4);
dbmfFree($2); dbmfFree($4);
}
;
@@ -188,9 +200,11 @@ field: FIELD O_PAREN WORD COMMA VALUE C_PAREN
#endif
if(subst_used)
{
strcpy(subst_buffer,$<Str>5);
if(dbDoSubst(subst_buffer,sizeof(subst_buffer),NULL)!=0)
fprintf(stderr,"dbDoSubst failed\n");
int n;
n = macExpandString(macHandle,$<Str>5,subst_buffer,
VAR_MAX_SUB_SIZE-1);
if(n<0) fprintf(stderr,"macExpandString failed\n");
#ifdef vxWorks
if( dbPutString(pdbentry, subst_buffer) )
fprintf(stderr,"Cannot set field %s to %s\n",
@@ -208,7 +222,7 @@ field: FIELD O_PAREN WORD COMMA VALUE C_PAREN
printf("\n\t\tfield(%s, \"%s\")",$<Str>3,$<Str>5);
#endif
}
dbmfFree(handle,$3); dbmfFree(handle,$5);
dbmfFree($3); dbmfFree($5);
}
;
@@ -218,44 +232,47 @@ field: FIELD O_PAREN WORD COMMA VALUE C_PAREN
static int yyerror(str)
char *str;
{ fprintf(stderr,"db file parse, Error line %d : %s\n",line_num, yytext); }
#ifdef vxWorks
static char* strdup(char* x)
{
char* c;
c=(char*)dbmfMalloc(handle,strlen(x)+1);
strcpy(c,x);
return c;
fprintf(stderr,"db file parse, Error line %d : %s\n",line_num, yytext);
return(0);
}
#endif
static int is_not_inited = 1;
int dbLoadRecords(char* pfilename, char* pattern)
{
FILE* fp;
long status;
DB_APP_NODE* an;
char **macPairs;
line_num=0;
#ifdef vxWorks
if(pdbbase==NULL)
{
fprintf(stderr,"dbLoadRecords: default.dctsdr file not loaded\n");
fprintf(stderr,"dbLoadRecords: dbLoadDatabase not called\n");
return -1;
}
#endif
if( pattern && *pattern )
{
subst_buffer = malloc(VAR_MAX_SUB_SIZE);
subst_used = 1;
dbInitSubst(pattern);
if(macCreateHandle(&macHandle,NULL)) {
fprintf(stderr,"dbLoadRecords macCreateHandle error\n");
return -1;
}
macParseDefns(macHandle,pattern,&macPairs);
if(macPairs == NULL) {
macDeleteHandle(macHandle);
macHandle = NULL;
} else {
macInstallMacros(macHandle,macPairs);
free((void *)macPairs);
}
}
else
subst_used = 0;
if( !(fp=fopen(pfilename,"r")) )
{
fprintf(stderr,"dbLoadRecords: error opening file\n");
@@ -266,7 +283,6 @@ int dbLoadRecords(char* pfilename, char* pattern)
{
yyin=fp;
is_not_inited=0;
handle=dbmfInit(55,1,4);
}
else
{
@@ -283,7 +299,12 @@ int dbLoadRecords(char* pfilename, char* pattern)
dbFreeEntry(pdbentry);
#endif
if(subst_used) dbFreeSubst();
if(subst_used) {
macDeleteHandle(macHandle);
macHandle = NULL;
free((void *)subst_buffer);
subst_buffer = NULL;
}
fclose(fp);
@@ -292,7 +313,7 @@ int dbLoadRecords(char* pfilename, char* pattern)
/* set up a default list to put on the master application list */
DbCurrentListHead=(DB_APP_NODE*)malloc(sizeof(DB_APP_NODE));
DbCurrentListTail=DbCurrentListHead;
DbCurrentListHead->name=strdup(pfilename);
DbCurrentListHead->name=strduplicate(pfilename);
DbCurrentListHead->next=(DB_APP_NODE*)NULL;
}
@@ -313,9 +334,11 @@ static void sub_pvname(char* type, char* name)
if(subst_used)
{
strcpy(subst_buffer,name);
if(dbDoSubst(subst_buffer,PVNAME_STRINGSZ,NULL)!=0)
fprintf(stderr,"dbDoSubst failed\n");
int n;
n = macExpandString(macHandle,name,subst_buffer,
VAR_MAX_SUB_SIZE-1);
if(n<0) fprintf(stderr,"macExpandString failed\n");
#ifdef vxWorks
if( dbCreateRecord(pdbentry,subst_buffer) )
fprintf(stderr,"Cannot create record %s\n",subst_buffer);

View File

@@ -1,6 +1,23 @@
pvname [a-zA-Z0-9_~\-:\.\[\]<>;]
value [a-zA-Z0-9_\,\^~\./\*#\[\]%: ;!|\'\-&\(\)@\?\+<>=\$\{\}]
BEL \\a
BS \\b
FF \\f
NL \\n
CR \\r
HT \\t
VT \\v
backSla \\\\
question \\\?
single \\\'
double \\\"
octal \\[0-7]+
hexa \\x[a-fA-F0-9]+
escape {BEL}|{BS}|{FF}|{NL}|{CR}|{HT}|{VT}|{backSla}|{question}|{single}|{double}|{octal}|{question}|{hexa}
spaces [ \t]
regular [a-zA-Z0-9_\,\^~\./\*#\[\]%:;!|\'\-&\(\)@\?\+<>=\$\{\}]
value {regular}|{spaces}|{escape}
%{
%}
@@ -16,9 +33,17 @@ value [a-zA-Z0-9_\,\^~\./\*#\[\]%: ;!|\'\-&\(\)@\?\+<>=\$\{\}]
"nowhere" { return(NOWHERE); }
"application" { return(APPL); }
\"{value}*\" { yylval.Str=(char *)dbmfMalloc(handle,strlen(yytext)+1); strcpy(yylval.Str,yytext+1); yylval.Str[strlen(yylval.Str)-1] = '\0'; return(VALUE); }
{pvname}+ { yylval.Str=(char *)dbmfMalloc(handle,strlen(yytext)+1); strcpy(yylval.Str,yytext); return(WORD); }
{pvname}+ { yylval.Str=(char *)dbmfMalloc(strlen(yytext)+1);
strcpy(yylval.Str,yytext);
return(WORD);
}
\"{value}+\" { yylval.Str=(char *)dbmfMalloc(strlen(yytext)+1);
yytext[strlen(yytext)-1] = '\0';
strcpy(yylval.Str,yytext+1);
return(VALUE);
}
"{" { return(O_BRACE); }
"}" { return(C_BRACE); }

View File

@@ -35,7 +35,7 @@
#include <string.h>
#include <stdlib.h>
#include "dbVarSub.h"
#include "macLib.h"
#include "dbmf.h"
#include "epicsVersion.h"
@@ -46,14 +46,23 @@ int dbLoadTemplate(char* sub_file);
#ifdef SUB_TOOL
static int sub_it();
#else
int dbLoadRecords(char* pfilename, char* pattern, char* container);
int dbLoadRecords(char* pfilename, char* pattern);
#endif
static char sub_collect[VAR_MAX_VAR_STRING];
static char** vars;
static char* db_file_name = (char*)NULL;
#ifdef vxWorks
#define VAR_MAX_VAR_STRING 1500
#define VAR_MAX_VARS 100
#else
#define VAR_MAX_VAR_STRING 50000
#define VAR_MAX_VARS 700
#endif
static char *sub_collect = NULL;
static MAC_HANDLE *macHandle = NULL;
static char** vars = NULL;
static char* db_file_name = NULL;
static int var_count,sub_count;
static void* handle=NULL;
%}
@@ -89,7 +98,7 @@ templ: templ_head O_BRACE subst C_BRACE
{
#ifndef SUB_TOOL
if(db_file_name)
dbLoadRecords(db_file_name,NULL,NULL);
dbLoadRecords(db_file_name,NULL);
else
fprintf(stderr,"Error: no db file name given\n");
#else
@@ -101,8 +110,10 @@ templ: templ_head O_BRACE subst C_BRACE
templ_head: DBFILE WORD
{
var_count=0;
if(db_file_name) free(db_file_name);
db_file_name=$2;
if(db_file_name) dbmfFree(db_file_name);
db_file_name = dbmfMalloc(strlen($2)+1);
strcpy(db_file_name,$2);
dbmfFree($2);
}
;
@@ -125,7 +136,11 @@ vars: vars var
;
var: WORD
{ vars[var_count++]=$1; }
{
vars[var_count++] = dbmfMalloc(strlen($1)+1);
strcpy(vars[var_count],$1);
dbmfFree($1);
}
;
subs: subs sub
@@ -140,14 +155,14 @@ sub: WORD O_BRACE vals C_BRACE
#endif
#ifndef SUB_TOOL
if(db_file_name)
dbLoadRecords(db_file_name,sub_collect,$1);
dbLoadRecords(db_file_name,sub_collect);
else
fprintf(stderr,"Error: no db file name given\n");
#else
sub_it();
#endif
dbmfFree(handle,$1);
dbmfFree($1);
sub_collect[0]='\0';
sub_count=0;
}
@@ -159,7 +174,7 @@ sub: WORD O_BRACE vals C_BRACE
#endif
#ifndef SUB_TOOL
if(db_file_name)
dbLoadRecords(db_file_name,sub_collect,NULL);
dbLoadRecords(db_file_name,sub_collect);
else
fprintf(stderr,"Error: no db file name given\n");
#else
@@ -183,9 +198,9 @@ val: QUOTE
strcat(sub_collect,"=\"");
strcat(sub_collect,$1);
strcat(sub_collect,"\",");
dbmfFree(handle,$1);
sub_count++;
}
dbmfFree($1);
}
| WORD
{
@@ -195,9 +210,9 @@ val: QUOTE
strcat(sub_collect,"=");
strcat(sub_collect,$1);
strcat(sub_collect,",");
dbmfFree(handle,$1);
sub_count++;
}
dbmfFree($1);
}
;
@@ -213,14 +228,14 @@ var_sub: WORD O_BRACE sub_pats C_BRACE
#endif
#ifndef SUB_TOOL
if(db_file_name)
dbLoadRecords(db_file_name,sub_collect,$1);
dbLoadRecords(db_file_name,sub_collect);
else
fprintf(stderr,"Error: no db file name given\n");
#else
sub_it();
#endif
dbmfFree(handle,$1);
dbmfFree($1);
sub_collect[0]='\0';
sub_count=0;
}
@@ -232,7 +247,7 @@ var_sub: WORD O_BRACE sub_pats C_BRACE
#endif
#ifndef SUB_TOOL
if(db_file_name)
dbLoadRecords(db_file_name,sub_collect,NULL);
dbLoadRecords(db_file_name,sub_collect);
else
fprintf(stderr,"Error: no db file name given\n");
#else
@@ -254,7 +269,7 @@ sub_pat: WORD EQUALS WORD
strcat(sub_collect,"=");
strcat(sub_collect,$3);
strcat(sub_collect,",");
dbmfFree(handle,$1); dbmfFree(handle,$3);
dbmfFree($1); dbmfFree($3);
sub_count++;
}
| WORD EQUALS QUOTE
@@ -263,7 +278,7 @@ sub_pat: WORD EQUALS WORD
strcat(sub_collect,"=\"");
strcat(sub_collect,$3);
strcat(sub_collect,"\",");
dbmfFree(handle,$1); dbmfFree(handle,$3);
dbmfFree($1); dbmfFree($3);
sub_count++;
}
;
@@ -276,6 +291,7 @@ static int yyerror(char* str)
{
fprintf(stderr,"Substitution file parse error\n");
fprintf(stderr,"line %d:%s\n",line_num,yytext);
return(0);
}
static int is_not_inited = 1;
@@ -283,7 +299,8 @@ static int is_not_inited = 1;
int dbLoadTemplate(char* sub_file)
{
FILE *fp;
long status;
int ind;
line_num=0;
if( !sub_file || !*sub_file)
@@ -299,6 +316,7 @@ int dbLoadTemplate(char* sub_file)
}
vars = (char**)malloc(VAR_MAX_VARS * sizeof(char*));
sub_collect = malloc(VAR_MAX_VAR_STRING);
sub_collect[0]='\0';
var_count=0;
sub_count=0;
@@ -307,7 +325,6 @@ int dbLoadTemplate(char* sub_file)
{
yyin=fp;
is_not_inited=0;
handle=dbmfInit(55,1,4);
}
else
{
@@ -315,9 +332,15 @@ int dbLoadTemplate(char* sub_file)
}
yyparse();
for(ind=0;ind<var_count;ind++) dbmfFree(vars[ind]);
free(vars);
free(sub_collect);
vars = NULL;
fclose(fp);
if(db_file_name){
dbmfFree((void *)db_file_name);
db_file_name = NULL;
}
return 0;
}
@@ -348,6 +371,7 @@ static int sub_it()
{
FILE* fp;
char var_buff[500];
char **macPairs;
#ifdef ERROR_STUFF
fprintf(stderr,"In sub_it()\n");
@@ -356,9 +380,20 @@ static int sub_it()
if( *sub_collect )
{
#ifdef ERROR_STUFF
fprintf(stderr," dbInitSubst() calling\n");
fprintf(stderr," macCreateHandle() calling\n");
#endif
dbInitSubst(sub_collect);
if(macCreateHandle(&macHandle,NULL)) {
fprintf(stderr,"dbLoadTemplate macCreateHandle error\n");
exit(1);
}
macParseDefns(macHandle,sub_collect,&macPairs);
if(macPairs == NULL) {
macDeleteHandle(macHandle);
macHandle = NULL;
} else {
macInstallMacros(macHandle,macPairs);
free((void *)macPairs);
}
}
else
{
@@ -375,17 +410,21 @@ static int sub_it()
/* do the work here */
while( fgets(var_buff,200,fp)!=(char*)NULL )
{
int n;
#ifdef ERROR_STUFF
fprintf(stderr," calling dbDoSubst()\n");
fprintf(stderr," calling macExpandString()\n");
#endif
dbDoSubst(var_buff,500,NULL);
fputs(var_buff,stdout);
n = macExpandString(macHandle,var_buff,sub_collect,
VAR_MAX_VAR_STRING-1);
if(n<0) fprintf(stderr,"macExpandString failed\n");
fputs(sub_collect,stdout);
}
#ifdef ERROR_STUFF
fprintf(stderr," calling dbFreeSubst()\n");
fprintf(stderr," calling macDeleteHandle()\n");
#endif
dbFreeSubst();
macDeleteHandle(macHandle);
macHandle = NULL;
fclose(fp);
return 0;
}
@@ -405,8 +444,9 @@ main(int argc, char** argv)
switch(c)
{
case 's':
if(name) free(name);
name = strdup(optarg);
if(name) dbmfFree(name);
name = dbmfMalloc(strlen(optarg));
strcpy(name,optarg);
break;
default: no_error=0; break;
}
@@ -422,9 +462,12 @@ main(int argc, char** argv)
exit(1);
}
if(!name) name = "Composite";
if(!name) {
name = dbmfMalloc(strlen("Composite") + 1);
strcpy(name,"Composite");
}
dbLoadTemplate(argv[1]);
dbmfFree((void *)name);
}
#endif
#endif

View File

@@ -1,8 +1,26 @@
value [a-zA-Z0-9_~\,\./\*#\[\]%: ;!|\-&\(\)@\?\+<>=\$]
word [a-zA-Z0-9_\.\^~/\*#\[\]%:;!|\-&\$\(\)@\?\+<>]
par [\"\']
BEL \\a
BS \\b
FF \\f
NL \\n
CR \\r
HT \\t
VT \\v
backSla \\\\
question \\\?
single \\\'
double \\\"
octal \\[0-7]+
hexa \\x[a-fA-F0-9]+
escape {BEL}|{BS}|{FF}|{NL}|{CR}|{HT}|{VT}|{backSla}|{question}|{single}|{double}|{octal}|{question}|{hexa}
spaces [ \t]
regular [a-zA-Z0-9_\,\^~\./\*#\[\]%:;!|\'\-&\(\)@\?\+<>=\$\{\}]
value {regular}|{spaces}|{escape}
%{
%}
@@ -10,13 +28,20 @@ par [\"\']
\#.*\n ;
"pattern" { return(PATTERN); }
"file" { return(DBFILE); }
"=" { return(EQUALS); }
"pattern" { return(PATTERN); }
"file" { return(DBFILE); }
"=" { return(EQUALS); }
{par}{value}*{par} { yylval.Str=(char*)dbmfMalloc(handle,strlen(yytext)+1); strcpy(yylval.Str,yytext+1); yylval.Str[strlen(yylval.Str)-1] = '\0'; return(QUOTE); }
{par}{value}*{par} { yylval.Str=(char*)dbmfMalloc(strlen(yytext)+1);
strcpy(yylval.Str,yytext+1);
yylval.Str[strlen(yylval.Str)-1] = '\0';
return(QUOTE);
}
{word}+ { yylval.Str=(char*)dbmfMalloc(handle,strlen(yytext)+1); strcpy(yylval.Str,yytext); return(WORD); }
{word}+ { yylval.Str=(char*)dbmfMalloc(strlen(yytext)+1);
strcpy(yylval.Str,yytext);
return(WORD);
}
"{" { return(O_BRACE); }
"}" { return(C_BRACE); }

View File

@@ -1,329 +0,0 @@
/**************************************************************************
*
* Author: Jim Kowalkowski
*
* Experimental Physics and Industrial Control System (EPICS)
*
* Copyright 1991, the Regents of the University of California,
* and the University of Chicago Board of Governors.
*
* This software was produced under U.S. Government contracts:
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
* and (W-31-109-ENG-38) at Argonne National Laboratory.
*
* Initial development by:
* The Controls and Automation Group (AT-8)
* Ground Test Accelerator
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Co-developed with
* The Controls and Computing Group
* Accelerator Systems Division
* Advanced Photon Source
* Argonne National Laboratory
*
* Modification Log:
* -----------------
* .01 10-29-93 jbk initial version
*
***********************************************************************/
#include <stdio.h>
#include <string.h>
#ifdef vxWorks
#include <memLib.h>
#endif
#include "dbmf.h"
#include "dbVarSub.h"
#include "dbStaticLib.h"
static int subst_total;
static struct var_sub *subst = (struct var_sub*)NULL;
static char* pattern;
static char* get_var(char**, char*);
static char* get_sub(char*, char*);
/* ------------------ variable substitution routines --------------*/
#ifdef vxWorks
static char* strdup(char*p) { return strcpy((char*)dbmfMalloc(NULL,strlen(p)+1),p); }
#endif
void dbFreeSubst()
{
int i;
if(subst)
{
free(pattern);
free(subst);
subst = (struct var_sub*)NULL;
subst_total = 0;
}
}
long dbDoSubst(char* replace, int size, struct var_tree* par)
{
/* perform substitution */
char preal[VAR_MAX_SUB_SIZE];
char pvar[VAR_MAX_SUB_SIZE];
char *to,*from,*pp;
char *hold = NULL;
int i,num_chars;
struct var_tree* test_var;
struct var_tree my_tree;
int l;
my_tree.parent = par;
l = strlen(replace);
for(num_chars=0,to=preal,from=replace;from<=(replace+l);)
{
/* see if this is really a variable */
if(from[0]==VAR_START_IND && from[1]==VAR_LEFT_IND)
{
/* found a variable */
from += 2;
if( !(pp=strchr(from,VAR_RIGHT_IND)) )
{
fprintf(stderr,
"dbDoSubst: Improper variable specification: %s\n",
from);
return -1;
}
*pp++ = '\0'; /* clear the closing paren for variable */
for(i=0;i<subst_total&&strcmp(subst[i].var,from);i++);
if(i<subst_total)
{
/* found a substitution */
strcpy(pvar,subst[i].sub);
/* check for looping in substitution */
my_tree.me=i;
for(test_var=par;test_var;test_var=test_var->parent)
{
if(test_var->me==i)
{
fprintf(stderr,
"dbDoSubst: recursive definition of variable %s\n",
from);
return -1;
}
}
/* check for successful substitution */
if(dbDoSubst(pvar,sizeof(pvar),&my_tree)<0) return -1;
/* copy substitution to output string */
for(hold=pvar;*to=*hold++;num_chars++,to++)
{
if(num_chars>size)
{
fprintf(stderr,
"dbDoSubst: substitution to long: %s), max=%d (r)\n",
replace,size);
return -1;
}
}
}
else
{
/* did not find a substitution */
#ifdef vxWorks
fprintf(stderr,"dbDoSubst: did not find sub for %s\n",from);
#endif
/* copy substitution to output string - this sucks */
/* the "$()" part of the variable must be re-added */
num_chars+=3; /* adjust for $() part */
*to++='$'; /* put the variable $ back in */
*to++='('; /* put the variable openning paren back in */
for(hold=from;*to=*hold++;num_chars++,to++)
{
if(num_chars>size)
{
fprintf(stderr,
"dbDoSubst: substitution to long: %s), max=%d (e)\n",
replace,size);
return -1;
}
}
*to++=')'; /* put the variable closing paren back in */
}
from = pp;
}
else
{
*to++ = *from++;
if(num_chars++>size)
{
fprintf(stderr,
"dbDoSubst: substitution to long for %s\n",
replace);
return -1;
}
}
}
strcpy(replace,preal);
return 0;
}
long dbInitSubst(char* parm_pattern)
{
char *pp,*hold;
int rc,pi,pass;
enum { var,sub } state;
/* --------- parse the pattern --------- */
rc=0;
if(parm_pattern && *parm_pattern)
{
pattern = strdup(parm_pattern);
dbFreeSubst();
/* count the number of variables in the pattern (use the = sign) */
for(subst_total=0,pp=pattern; *pp ;pp++)
{
/* find vars and subs */
switch(*pp)
{
case '\\': pp++; break; /* skip the next character */
case '=': subst_total++; break;
case '\"':
for(++pp;*pp && *pp!='\"';pp++)
if(*pp=='\\') pp++;
break;
default: break;
}
}
#ifdef ERROR_STUFF
fprintf(stderr,"total = %d\n",subst_total);
#endif
/* allocate the substitution table */
subst = (struct var_sub*)malloc( sizeof(struct var_sub)*subst_total );
/* fill table from pattern - this is kind-of putrid */
subst_total=0;
pp=pattern;
state=var;
while(*pp)
{
switch(*pp)
{
case ' ':
case ',':
case '\t': pp++; break;
case '\\': pp+=2; break;
case '=':
case '\"':
pp=get_sub(subst[subst_total++].sub,pp);
state=var;
break;
default:
if(state==var)
{
pp=get_var(&subst[subst_total].var,pp);
state=sub;
}
else
{
pp=get_sub(subst[subst_total++].sub,pp);
state=var;
}
break;
}
}
/* debug code */
#ifdef ERROR_STUFF
for(pi=0;pi<subst_total;pi++)
{
fprintf(stderr,"table[%d]=(%s,%s)\n",pi,subst[pi].var,subst[pi].sub);
}
#endif
/* resolve the multiple substitutions now */
for(pi=0;pi<subst_total;pi++)
{
if(dbDoSubst(subst[pi].sub,VAR_MAX_SUB_SIZE,(struct var_tree*)NULL)<0)
{
fprintf(stderr, "dbInitSubst: failed to build variable substitution table (%s)\n",subst[pi].sub);
rc = -1;
}
}
/* more debug code */
#ifdef ERROR_STUFF
for(pi=0;pi<subst_total;pi++)
{
fprintf(stderr,"table[%d]=(%s,%s)\n",pi,subst[pi].var,subst[pi].sub);
}
#endif
}
else
{
subst_total=0;
subst=(struct var_sub*)NULL;
}
return(rc);
}
/* put the pointer to the variable in "from" into "to" */
static char* get_var(char** to, char* from)
{
char* pp;
pp = strpbrk(from," \t=");
*pp = '\0';
pp++;
#ifdef ERROR_STUFF
fprintf(stderr,"get_var: (%s)\n",from);
#endif
*to=from;
return pp;
}
/* copy the substitution in "from" into "to" */
static char* get_sub(char* to, char* from)
{
char *pp,*hold;
char* cp = to;
for(pp=from;*pp==' ' || *pp=='\t' || *pp=='=';pp++);
if(*pp=='\"')
{
for(++pp;*pp!='\"';pp++)
{
if(*pp=='\\') pp++;
else *cp++ = *pp;
}
*cp='\0';
#ifdef ERROR_STUFF
fprintf(stderr,"get_sub: quote (%s)\n",to);
#endif
pp++;
}
else
{
for(hold=pp;*hold && *hold!=',';hold++);
if(*hold)
{
*hold = '\0';
hold++;
#ifdef ERROR_STUFF
fprintf(stderr,"get_sub: regular (%s)\n",pp);
#endif
}
strcpy(to,pp);
pp=hold;
}
return pp;
}

View File

@@ -1,59 +0,0 @@
/**************************************************************************
* $Id$
* Author: Jim Kowalkowski
*
* Experimental Physics and Industrial Control System (EPICS)
*
* Copyright 1991, the Regents of the University of California,
* and the University of Chicago Board of Governors.
*
* This software was produced under U.S. Government contracts:
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
* and (W-31-109-ENG-38) at Argonne National Laboratory.
*
* Initial development by:
* The Controls and Automation Group (AT-8)
* Ground Test Accelerator
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Co-developed with
* The Controls and Computing Group
* Accelerator Systems Division
* Advanced Photon Source
* Argonne National Laboratory
*
* Modification Log:
* -----------------
* .01 10-29-93 jbk initial version
*
***********************************************************************/
#define VAR_LEFT_IND '('
#define VAR_RIGHT_IND ')'
#define VAR_START_IND '$'
#ifdef vxWorks
#define VAR_MAX_SUB_SIZE 200
#define VAR_MAX_VAR_STRING 1500
#define VAR_MAX_VARS 100
#else
#define VAR_MAX_SUB_SIZE 300
#define VAR_MAX_VAR_STRING 50000
#define VAR_MAX_VARS 700
#endif
struct var_sub {
char *var;
char sub[VAR_MAX_SUB_SIZE];
};
struct var_tree {
int me;
struct var_tree* parent;
};
long dbDoSubst(char* replace, int replace_size, struct var_tree* par);
long dbInitSubst(char* parm_pattern);
void dbFreeSubst();