diff --git a/src/db/atdb.c b/src/db/atdb.c new file mode 100644 index 000000000..2199cf43a --- /dev/null +++ b/src/db/atdb.c @@ -0,0 +1,83 @@ +/*atodb.c*/ +/* share/src/db $Id$ */ +/* + * + * Author: Marty Kraimer + * + * 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 07-13-93 mrk Original version + */ + +#include +#include +#include +#include +#include +#include +#include +DBBASE *pdbbase; +DBENTRY *pdbentry; + +main(int argc,char **argv) +{ + FILE *fpdctsdr; + FILE *fp; + long status; + char *ptime; + time_t timeofday; + char *rectype; + + + if(argc!=3) { + printf("Usage: atdb \n"); + exit(-1); + } + fpdctsdr = fopen(argv[1],"r"); + if(!fpdctsdr) { + errMessage(0,"Error opening file"); + exit(-1); + } + pdbbase=dbAllocBase(); + pdbentry=dbAllocEntry(pdbbase); + status=dbRead(pdbbase,fpdctsdr); + if(status) { + errMessage(status,"dbRead"); + exit(-1); + } + yyreset(); + yyparse(); + fp=fopen(argv[2],"w"); + if(fp==NULL) { + errMessage(0,"Error opening file"); + exit(-1); + } + status = dbWrite(pdbbase,fpdctsdr,fp); + if(status) errMessage(status,"dbWrite"); + fclose(fpdctsdr); + fclose(fp); + dbFreeEntry(pdbentry); + dbFreeBase(pdbbase); + return(0); +} diff --git a/src/db/atdb_lex.l b/src/db/atdb_lex.l new file mode 100644 index 000000000..1e4337d10 --- /dev/null +++ b/src/db/atdb_lex.l @@ -0,0 +1,35 @@ +b [a-zA-Z0-9_] +a [ \t] +d [a-zA-Z0-9_\,\./\*#\[\]%:;!|\'\-&\(\)@\?\+<>] + +%{ + +yyreset() +{ + line_num=1; + BEGIN INITIAL; + return; +} + +%} + +%% + +^[A-Z0-9_]+ { yylval.Str=(char *)malloc(strlen(yytext)+1); + strcpy(yylval.Str,yytext); + return(FIELD); } + +^"PV:" { return(PV); } +"Type:" { return(TYPE); } + { return(CLOSE); } + \n { line_num++; return(CLOSE); } +"$$end" { return(CLOSE); } + +{d}+ { yylval.Str=(char *)malloc(strlen(yytext)+1); + strcpy(yylval.Str,yytext); + return(WORD); } + +. ; +\n { line_num++; } + +%% diff --git a/src/db/atdb_yacc.y b/src/db/atdb_yacc.y new file mode 100644 index 000000000..ccda7eba8 --- /dev/null +++ b/src/db/atdb_yacc.y @@ -0,0 +1,119 @@ +%{ +#include +#include +#include +#include +/* kludge for buggy lex/yacc. exploits the fact that we know the union */ +/* below will be given the name YYSTYPE. done so that ifndef YYSTYPE */ +/* (as it appears in pdb.c) fails */ +#define YYSTYPE OUR_YYSTYPE +int line_num; + +extern DBENTRY *pdbentry; +char rectype[100]; +char recname[100]; + +char curr_field[10]; +char curr_value[200]; +char message[200]; +long status; + +static void printMessage(char *mess) { + + sprintf(message,"%s Error near line %d Type: %s Name: %s Field: %s Value: %s", + mess,line_num,rectype,recname,curr_field,curr_value); + errMessage(status,message); +} +%} + +%start conv + +%token WORD +%token FIELD +%token TYPE +%token PV CLOSE + +%union +{ + int Int; + char Char; + char *Str; + double Real; +} + +%% + +conv: things + ; + +things: + | things thing + ; + +thing: header fields CLOSE + | header CLOSE + | junko + ; + +header: PV WORD TYPE WORD WORD +{ + strcpy(rectype,$4); + strcpy(recname,$2); + status = dbFindRecdes(pdbentry,rectype); + if(status) printMessage("dbFindRecdes"); + status = dbCreateRecord(pdbentry,recname); + if(status) printMessage("dbCreateRecord"); +} + +fields: field + | fields field + ; + +field: f_name words +{ + status = dbPutString(pdbentry,curr_value); + if(status) printMessage("dbPutString"); +} + ; + +f_name: FIELD +{ + + curr_value[0]='\0'; + strcpy(curr_field,$1); + status = dbFindField(pdbentry,$1); + if(status) printMessage("dbFindField"); +} + ; + +words: + | words WORD +{ + char* p; + /* pretty crappy stuff */ + if((p=strstr($2,".PP.MS"))) {p[0]=' ';p[3]=' ';} + else if((p=strstr($2,".PP.NMS"))) {p[0]=' ';p[3]=' ';} + else if((p=strstr($2,".NPP.MS"))) {p[0]=' ';p[4]=' ';} + else if((p=strstr($2,".NPP.NMS"))) {p[0]=' ';p[4]=' ';} + else if(strlen(curr_value)>0) { strcat(curr_value," "); } + strcat(curr_value,$2); +} + ; + +junko: WORD + | CLOSE + ; + +%% + +#include "atdb_lex.c" + +yyerror(str) +char *str; +{ + sprintf(message,"Error line %d : %s\n",line_num, yytext); + errMessage(-1,message); +} + +yywrap() { return(1); } + diff --git a/src/db/dbta.c b/src/db/dbta.c new file mode 100644 index 000000000..92dc4b18e --- /dev/null +++ b/src/db/dbta.c @@ -0,0 +1,165 @@ +/*dbta.c*/ +/* share/src/db $Id$ */ +/* + * + * Author: Marty Kraimer + * + * 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 07-13-93 mrk Original version + */ + +#include +#include +#include +#include +#include +#include +#include +DBBASE *pdbbase; + +void parse_command_line_args(int, char **, int *, int *, char **); + +int main(int argc,char **argv) +{ + DBENTRY *pdbentry; + FILE *fp; + long status; + char *ptime; + time_t timeofday; + char *rectype; + int verbose; + int oldshortform; + char *dbname; + char *sdr_filename; + + parse_command_line_args(argc, argv, &verbose, &oldshortform, &dbname); + + fp = fopen(dbname,"r"); + if(!fp) { + errMessage(0,"Error opening file"); + exit(-1); + } + pdbbase=dbAllocBase(); + pdbentry=dbAllocEntry(pdbbase); + status=dbRead(pdbbase,fp); + if(status) { + errMessage(status,"dbRead"); + exit(-1); + } + fclose(fp); + status = dbFirstRecdes(pdbentry); + if(status) { + printf("No record description\n"); + exit(-1); + } + if(oldshortform) { + printf("$$mono\n"); + timeofday = time((time_t *)0); + ptime = ctime(&timeofday); + printf(" Time: %s\n",ptime); + } + while(!status) { + rectype = dbGetRecdesName(pdbentry); + status = dbFirstRecord(pdbentry); + while(!status) { + int generate_nl; + + printf("\nPV: %s Type: %s (atdb)",dbGetRecordName(pdbentry),rectype); + printf("\n"); + generate_nl=FALSE; + status = dbFirstFielddes(pdbentry,TRUE); + if(status) printf(" No Fields\n"); + while(!status) { + char *pstr; + int lineout; + + if(verbose || !dbIsDefaultValue(pdbentry)) { + if(generate_nl) printf("\n"); + printf("%4s ",dbGetFieldName(pdbentry)); + pstr = dbGetString(pdbentry); + if(pstr) printf("%s",pstr); + generate_nl=TRUE; + } + status=dbNextFielddes(pdbentry,TRUE); + } + printf("\f\n"); + status = dbNextRecord(pdbentry); + } + status = dbNextRecdes(pdbentry); + } + if(oldshortform) printf("$$end\n"); + dbFreeEntry(pdbentry); + dbFreeBase(pdbbase); + return(0); +} + +void parse_command_line_args(int argc, char **argv,int *verbose, + int *oldshortform, char **dbname) +{ + extern char *optarg; /* needed for getopt() */ + extern int optind; /* needed for getopt() */ + int i; + int c; + int input_error; + + /* defaults */ + *verbose = FALSE; + *oldshortform = FALSE; + *dbname = (char *) NULL; + + input_error = FALSE; + + while (!input_error && (c = getopt(argc, argv, "vs")) != -1) + { + switch (c) + { + case 'v': *verbose = TRUE; break; + case 's': *oldshortform = TRUE; break; + case '?': input_error = 1; break; + default: input_error = 1; break; + } /* end switch() */ + } /* endwhile */ + + if (!input_error && optind < argc) + { + int gotperiod=FALSE; + int len; + + len = strlen(argv[optind]); + if(strchr(argv[optind],'.')) gotperiod = TRUE; + if(!gotperiod) len = len + strlen(".database"); + *dbname = dbCalloc(1,len); + strcpy(*dbname,argv[optind]); + if(!gotperiod) strcat(*dbname,".database"); + return; + } + fprintf(stderr, "\nusage: dbta [-v] [-s] fn\n"); + fprintf(stderr,"\n\t-v\tVerbose mode, outputs all prompt fields of\n"); + fprintf(stderr,"\t\trecords to standard out. If not specified,\n"); + fprintf(stderr,"\t\tthen only non default fields will be printed\n"); + fprintf(stderr,"\t-s\tGenerate old DCT short form format file\n"); + fprintf(stderr,"\tfn\tNames the .database file.\n"); + exit(1); +}