Files
pcas/src/db/dbta.c
Janet B. Anderson 2d40290c26 Initial revision
1993-07-19 13:56:10 +00:00

166 lines
4.3 KiB
C
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*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 <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <time.h>
#include <errMdef.h>
#include <dbDefs.h>
#include <dbStaticLib.h>
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);
}