diff --git a/src/dbtools/Makefile.Host b/src/dbtools/Makefile.Host index 2513a6f64..b26fd30de 100644 --- a/src/dbtools/Makefile.Host +++ b/src/dbtools/Makefile.Host @@ -10,25 +10,22 @@ LEXOPT := -L # includes and manual pages to install: # -MAN1 := dbLoadTemplate.1 subtool.1 +MAN1 := dbLoadTemplate.1 MAN3 := dbLoadRecords.3 dbLoadTemplate.3 MAN5 := templatefile.5 dbfile.5 # uses getopt, optind, optarg from lib Com: PROD_LIBS := Db Com -PROD := subtool dbLoadTemplate +PROD := dbLoadTemplate # hard-coded dependencies and rules, # hopefully system-independent -# SRCS for subtool and dbLoadTemplate +# SRCS for and dbLoadTemplate # SRCS = dbLoadTemplate.c dbLoadRecords.c -# special CFLAGS only for subtool -# -subtool_CFLAGS := -DSUB_TOOL include $(TOP)/config/RULES.Host diff --git a/src/dbtools/Makefile.Vx b/src/dbtools/Makefile.Vx index 760671b15..a3bd01172 100644 --- a/src/dbtools/Makefile.Vx +++ b/src/dbtools/Makefile.Vx @@ -14,21 +14,12 @@ LIBOBJS += dbLoadRecords.o LIBNAME = dbSubs -MAN1 = dbLoadTemplate.1 subtool.1 -MAN3 = dbLoadRecords.3 dbLoadTemplate.3 -MAN5 = templatefile.5 dbfile.5 - include $(TOP)/config/RULES.Vx -USR_CFLAGS = -I../../rsrv -I../../ca +#USR_CFLAGS = -I../../rsrv -I../../ca dbLoadTemplate.o: dbLoadTemplate_lex.c dbLoadRecords.o: dbLoadRecords_lex.c -subtool: dbLoadTemplate_lex.c - -subtool: dbLoadTemplate.c dbLoadTemplate_lex.c - $(RM) $@ - $(LINK.c) $(CFLAGS) -DSUB_TOOL -o subtool dbLoadTemplate.c -s clean:: @$(RM) dbLoadTemplate_lex.c dbLoadTemplate.c dbLoadRecords_lex.c \ diff --git a/src/dbtools/dbLoadTemplate.y b/src/dbtools/dbLoadTemplate.y index 975faf09c..446a7b75a 100644 --- a/src/dbtools/dbLoadTemplate.y +++ b/src/dbtools/dbLoadTemplate.y @@ -47,12 +47,7 @@ static int line_num; static int yyerror(); int dbLoadTemplate(char* sub_file); -#ifdef SUB_TOOL -static int sub_it(); -#else int dbLoadRecords(char* pfilename, char* pattern); -#endif - #ifdef vxWorks #define VAR_MAX_VAR_STRING 5000 @@ -100,14 +95,10 @@ templs: templs templ templ: templ_head O_BRACE subst C_BRACE | templ_head { -#ifndef SUB_TOOL if(db_file_name) dbLoadRecords(db_file_name,NULL); else fprintf(stderr,"Error: no db file name given\n"); -#else - sub_it(); -#endif } ; @@ -158,15 +149,10 @@ sub: WORD O_BRACE vals C_BRACE #ifdef ERROR_STUFF fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect); #endif -#ifndef SUB_TOOL if(db_file_name) dbLoadRecords(db_file_name,sub_collect); else fprintf(stderr,"Error: no db file name given\n"); -#else - sub_it(); -#endif - dbmfFree($1); sub_collect[0]='\0'; sub_count=0; @@ -177,15 +163,10 @@ sub: WORD O_BRACE vals C_BRACE #ifdef ERROR_STUFF fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect); #endif -#ifndef SUB_TOOL if(db_file_name) dbLoadRecords(db_file_name,sub_collect); else fprintf(stderr,"Error: no db file name given\n"); -#else - sub_it(); -#endif - sub_collect[0]='\0'; sub_count=0; } @@ -231,15 +212,10 @@ var_sub: WORD O_BRACE sub_pats C_BRACE #ifdef ERROR_STUFF fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect); #endif -#ifndef SUB_TOOL if(db_file_name) dbLoadRecords(db_file_name,sub_collect); else fprintf(stderr,"Error: no db file name given\n"); -#else - sub_it(); -#endif - dbmfFree($1); sub_collect[0]='\0'; sub_count=0; @@ -250,15 +226,10 @@ var_sub: WORD O_BRACE sub_pats C_BRACE #ifdef ERROR_STUFF fprintf(stderr,"dbLoadRecords(%s)\n",sub_collect); #endif -#ifndef SUB_TOOL if(db_file_name) dbLoadRecords(db_file_name,sub_collect); else fprintf(stderr,"Error: no db file name given\n"); -#else - sub_it(); -#endif - sub_collect[0]='\0'; sub_count=0; } @@ -350,94 +321,8 @@ int dbLoadTemplate(char* sub_file) } #ifndef vxWorks -#ifdef SUB_TOOL -/* this is generic substitution on any file */ - -char* dbfile; - -main(int argc, char** argv) -{ - if(argc!=3) - { - fprintf(stderr,"Usage: %s file sub_file\n",argv[0]); - fprintf(stderr,"\n\twhere file is any ascii text file\n"); - fprintf(stderr,"\tsub_file in the variable substitution file\n"); - fprintf(stderr,"\n\tThis program uses the sub_file to perform\n"); - fprintf(stderr,"\tsubstitutions on to standard out.\n"); - exit(1); - } - dbfile = argv[1]; - dbLoadTemplate(argv[2]); - return 0; -} - -/* use sub_collect and db_file_name to do work */ -static int sub_it() -{ - FILE* fp; - char var_buff[500]; - char **macPairs; - -#ifdef ERROR_STUFF - fprintf(stderr,"In sub_it()\n"); -#endif - - if( *sub_collect ) - { -#ifdef ERROR_STUFF - fprintf(stderr," macCreateHandle() calling\n"); -#endif - if(macCreateHandle(&macHandle,NULL)) { - fprintf(stderr,"dbLoadTemplate macCreateHandle error\n"); - exit(1); - } - macSuppressWarning(macHandle,TRUE); - macParseDefns(macHandle,sub_collect,&macPairs); - if(macPairs == NULL) { - macDeleteHandle(macHandle); - macHandle = NULL; - } else { - macInstallMacros(macHandle,macPairs); - free((void *)macPairs); - } - } - else - { - fprintf(stderr,"No valid substitutions found in table\n"); - exit(1); - } - - if( !(fp=fopen(dbfile,"r")) ) - { - fprintf(stderr,"sub_tool: error opening file\n"); - exit(1); - } - - /* do the work here */ - while( fgets(var_buff,200,fp)!=(char*)NULL ) - { - int n; -#ifdef ERROR_STUFF - fprintf(stderr," calling macExpandString()\n"); -#endif - 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 macDeleteHandle()\n"); -#endif - macDeleteHandle(macHandle); - macHandle = NULL; - fclose(fp); - return 0; -} - -#else /* this is template loader similar to vxWorks one for .db files */ -main(int argc, char** argv) +int main(int argc, char** argv) { extern char* optarg; extern int optind; @@ -474,6 +359,6 @@ main(int argc, char** argv) } dbLoadTemplate(argv[1]); dbmfFree((void *)name); + return(0); } #endif -#endif diff --git a/src/dbtools/subtool.1 b/src/dbtools/subtool.1 deleted file mode 100644 index bae57dbca..000000000 --- a/src/dbtools/subtool.1 +++ /dev/null @@ -1,51 +0,0 @@ -.\" @(#) -.TH SUBTOOL 1 "04 Nov 1993" -.SH NAME -subtool \- Perform substitutions on variables in an ascii text file. -.SH SYNOPSIS -.B subtool -.IR file_name -.IR substitution_file -.SH AVAILABILITY -The tool in available under Unix from the EPICS application directory -provided by getrel in release 3.11 or greater. -.SH DESCRIPTION -.LP -This tool applies variable substitutions to -.B file_name -according to rules in the -.B substitution_file -to produce a file at standard out. See templatefile(5) for a full -description of the substitution file. -.SH EXAMPLE -Running the command "subtool file_name sub_file" with sub_file contents of -.sp -.nf -{ a=test1,b=one } -{ a=test2,b=two } -.fi -.sp -and file_name contents of -.sp -.nf -This is var a: $(a), this is var b: $(b) -This is another var a: $(a), this is another var b: $(b) -.fi -.sp -writes to standard out the following: -.sp -.nf -This is var a: test1, this is var b: one -This is another var a: test1, this is another var b: one -This is var a: test2, this is var b: two -This is another var a: test2, this is another var b: two -.fi -.sp -.SH NOTES -This tool will use all type of templatefile(5) definitions. If an -IOC type is used by the tool, the dbfile(5) information will be ignored -and the -.I file_name -will be used. -.SH "SEE ALSO" -.BR templatefile(5) diff --git a/src/dbtools/templatefile.5 b/src/dbtools/templatefile.5 index 06baa20c3..d700b2f0e 100644 --- a/src/dbtools/templatefile.5 +++ b/src/dbtools/templatefile.5 @@ -4,11 +4,7 @@ templatefile \- The file containing rules for substitutions. .SH DESCRIPTION .LP -This file contains the rules for performing substitutions on ascii text -file or ".db" files. Two formats can exist: one specifically for -an ascii ".db" file (usually produced by GDCT) and one for a plain ascii -text file. Most tools will except either format; the different -formats exist for convenience. +This file contains the rules for performing substitutions on ".db" files. .sp The purpose of this file is to specify a set of substitutions to be performed on a file. Substitutions can be defined in one of two ways. @@ -17,9 +13,11 @@ sets is defined as follows: .nf .sp .B *Version-1* -{ set1var1=sub1, set1var2=sub2,...... } -{ set2var1=sub1, set2var2=sub2,...... } -{ set3var1=sub1, set3var2=sub2,...... } +file name.db { + { set1var1=sub1, set1var2=sub2,...... } + { set2var1=sub1, set2var2=sub2,...... } + { set3var1=sub1, set3var2=sub2,...... } +} \. \. \. @@ -27,10 +25,12 @@ sets is defined as follows: - or - .B *Version-2* -pattern{ var1,var2,var3,....... } -{ sub1_for_set1, sub2_for_set1, sub3_for_set1, ... } -{ sub1_for_set2, sub2_for_set2, sub3_for_set2, ... } -{ sub1_for_set3, sub2_for_set3, sub3_for_set3, ... } +file name.db { + pattern{ var1,var2,var3,....... } + { sub1_for_set1, sub2_for_set1, sub3_for_set1, ... } + { sub1_for_set2, sub2_for_set2, sub3_for_set2, ... } + { sub1_for_set3, sub2_for_set3, sub3_for_set3, ... } +} \. \. \. @@ -44,29 +44,9 @@ are listed in the "pattern{}" line, which must precede the braced substitution lines. The braced substitution lines contains set which match up with the pattern{} line. An example will be given later. .sp -For some tools such as -.B subtool(1), -putting substitution rules into a file (only one version type -allowed per file) as -above is enough for the tool to operate. For other tools, such as -.B dbLoadTemplate(3) -which is capable of loading records onto an IOC, more information -must be given. -.sp -.nf -file name.db -{ - *put version 1 or 2 of substitutions here* -} -.fi -.sp The keyword file identifies a .B dbfile(5) to perform the substitutions on, in this case "name.db". -.sp -To summarize, substitutions can be specified using version 1 or 2. The -files can be written in two different flavors: one way for an IOC dbfile(5), -and one way for a plain ascii text file. .SH EXAMPLES Four simple template file examples are listed here, the first two are IOC db specific, the last two are general ones. All the examples @@ -76,8 +56,6 @@ first set, and this=sub3 and that=sub4 for a second set. 1) file test.db { { this=sub1,that=sub2 } { this=sub3,that=sub4 } } 2) file test.db { pattern{this,that} {sub1,sub2} {sub3,sub4 } } -3) { this=sub1, that=sub2 } { this=sub3, that=sub4 } -4) pattern{this,that} {sub1,sub2} {sub3,sub4 } input file for 1 and 2 (see dbfile(5) for examplanation of file): @@ -87,30 +65,12 @@ database(test) record(ai,"$(that)record") { field(DESC,"this = $(that)") } } -input file for 3 and 4: - -The first variable "this" equals $(this), the -second variable "that" is equal to $(that). - .fi When 1 and 2 are applied to their corresponding file, two sets of the record() lines will be produced: (sub1record,sub2record) and (sub3record, sub4record), see dbLoadTemplate(1) for a more thorough explanation. -.sp -When 3 and 4 are applied to their corresponding file, the following is -produced. -.nf - -The first variable "this" equals sub1, the -second variable "that" is equal to sub2. - -The first variable "this" equals sub3, the -second variable "that" is equal to sub4. - -.fi .SH NOTES No special spacing or carriage returns are required in this file. .SH "SEE ALSO" .BR dbLoadTemplate(1), .BR dbLoadTemplate(3), -.BR subtool(1)