Changes for replacing default.dctsdr by all ascii files

This commit is contained in:
Marty Kraimer
1995-11-29 14:38:52 +00:00
parent 8d8f5754a1
commit fb6f4ce704
41 changed files with 5522 additions and 119 deletions

18
src/dbStatic/Makefile Normal file
View File

@@ -0,0 +1,18 @@
#
# $Id$
#
# Base: Lowest Level Directroy Makefile
# by Janet Anderson
#
# $Log$
# Revision 1.1 1994/09/07 19:26:01 jba
# New file
#
#
EPICS=../../..
include $(EPICS)/config/CONFIG_BASE
include $(EPICS)/config/RULES_ARCHS

47
src/dbStatic/Makefile.Unix Executable file
View File

@@ -0,0 +1,47 @@
EPICS = ../../../..
include Target.include
include $(EPICS)/config/CONFIG_BASE
USR_LDLIBS = -lDb -lCom -lm
#USR_CFLAGS = -v -g
#CC = $(PURIFYHOME)/purify $(C_$(CMPLR))
LEX = $(ELEX)
YACC = $(EYACC)
DEPLIBS_BASE = $(EPICS_BASE_LIB)
DEPLIBS = ./libDb.a\
$(DEPLIBS_BASE)/libCom.a
SRCS.c = \
dbAsciiYacc.c \
../dbAsciiTest.c\
../dbPvdLib.c\
../dbStaticNoRun.c\
../dbStaticLib.c\
../dbAsciiToMenuH.c\
../dbAsciiToRecordtypeH.c
OBJS = \
dbAsciiTest.o\
dbAsciiToMenuH.o\
dbAsciiToRecordtypeH.o
LIBOBJS = dbStaticLib.o dbAsciiYacc.o dbPvdLib.o dbStaticNoRun.o
LIBNAME = libDb.a
PROD = \
dbAsciiTest\
dbAsciiToMenuH\
dbAsciiToRecordtypeH
include $(EPICS)/config/RULES.Unix
# Extra rule since dbAsciiRoutines.c is included in dbAsciiYacc.c
dbAsciiYacc.o: dbAsciiLex.c ../dbAsciiRoutines.c
clean::
@$(RM) dbAsciiLex.c dbAsciiYacc.c

36
src/dbStatic/Makefile.Vx Normal file
View File

@@ -0,0 +1,36 @@
EPICS = ../../../..
include Target.include
include $(EPICS)/config/CONFIG_BASE
LEX = $(ELEX)
YACC = $(EYACC)
USR_CFLAGS = -ansi
VX_WARN_YES = -Wall -pedantic
SRCS.c = \
dbAsciiYacc.c \
../dbPvdLib.c\
../dbStaticRun.c\
../dbStaticLib.c
OBJSdbLib = \
dbAsciiYacc.o\
dbPvdLib.o\
dbStaticRun.o\
dbStaticLib.o
PROD = dbStaticLib
include $(EPICS)/config/RULES.Vx
# Extra rule since dbAsciiRoutines.c is included in dbAsciiYacc.c
dbAsciiYacc.o: dbAsciiLex.c ../dbAsciiRoutines.c
clean::
@$(RM) dbAsciiLex.c dbAsciiYacc.c
dbStaticLib: $(OBJSdbLib)
$(RM) $@
$(LINK.c) $@ $(OBJSdbLib) $(LDLIBS)

70
src/dbStatic/dbAsciiLex.l Normal file
View File

@@ -0,0 +1,70 @@
name [a-zA-Z0-9_\-:\.\[\]<>;]
string [a-zA-Z0-9_\,\./\*#\[\]%: ;!|\'\-&\(\)@\?\+<>=\$\t]
%{
#undef YY_INPUT
#define YY_INPUT(b,r,ms) (r=(*dbAscii_yyinput)(b,ms))
static int yyreset(void)
{
BEGIN INITIAL;
return(0);
}
%}
%%
"include" {return(tokenINCLUDE);}
"path" {return(tokenPATH);}
"menu" {return(tokenMENU);}
"choice" {return(tokenCHOICE);}
"recordtype" {return(tokenRECORDTYPE);}
"field" {return(tokenFIELD);}
"device" {return(tokenDEVICE);}
"driver" {return(tokenDRIVER);}
"breaktable" {return(tokenBREAKTABLE);}
"record" {return(tokenRECORD);}
[0-9]+ { /*integer number*/
yylval.Str = (char *)malloc(strlen(yytext)+1);
strcpy(yylval.Str,yytext);
return(tokenSTRING);
}
([0-9]+|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?) { /*real number*/
yylval.Str = (char *)malloc(strlen(yytext)+1);
strcpy(yylval.Str,yytext);
return(tokenSTRING);
}
{name}+ { /*unquoted string*/
yylval.Str = (char *)malloc(strlen(yytext)+1);
strcpy(yylval.Str,yytext);
return(tokenSTRING);
}
\"{string}*\" { /*quoted string*/
yylval.Str = (char *)malloc(strlen(yytext)+1);
strcpy(yylval.Str,yytext+1);
yylval.Str[strlen(yylval.Str)-1] = '\0';
return(tokenSTRING);
}
"{" { return(yytext[0]); }
"}" { return(yytext[0]); }
"(" { return(yytext[0]); }
")" { return(yytext[0]); }
"," { return(yytext[0]); }
#.* { ;}
[ \t\r] ;
\n { ;}
. {
char message[20];
sprintf(message,"invalid character '%c'",yytext[0]);
yyerror(message);
}
%%

View File

@@ -0,0 +1,822 @@
/* dbAsciiRoutines.c */
/* Author: Marty Kraimer Date: 13JUL95*/
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
/*
*
* Modification Log:
* -----------------
* .01 13JUL95 mrk Initial Implementation
*/
/*The routines in this module are serially reusable NOT reentrant*/
#ifdef vxWorks
#include <vxWorks.h>
#endif
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <dbDefs.h>
#include <dbFldTypes.h>
#include <epicsPrint.h>
#include <errMdef.h>
#include <dbStaticLib.h>
#include <dbStaticPvt.h>
#include <ellLib.h>
#include <gpHash.h>
#include <freeList.h>
#include <guigroup.h>
#include <special.h>
#include <link.h>
/*private routines */
static void yyerrorAbort(char *str);
static void allocTemp(void *pvoid);
static void *popFirstTemp(void);
static void *getLastTemp(void);
static int dbAscii_yyinput(char *buf,int max_size);
static void dbAsciiIncludePrint(FILE *fp);
static void dbAsciiPath(char *path);
static void dbAsciiIncludeNew(char *include_file);
static void dbAsciiMenuHead(char *name);
static void dbAsciiMenuChoice(char *name,char *value);
static void dbAsciiMenuBody(void);
static void dbAsciiRecordtypeHead(char *name);
static void dbAsciiRecordtypeBody(void);
static void dbAsciiRecordtypeFieldHead(char *name,char *type);
static void dbAsciiRecordtypeFieldItem(char *name,char *value);
static void dbAsciiDevice(char *recordtype,char *linktype,
char *dsetname,char *choicestring);
static void dbAsciiDriver(char *name);
static void dbAsciiBreakHead(char *name);
static void dbAsciiBreakItem(char *value);
static void dbAsciiBreakBody(void);
static void dbAsciiRecordHead(char *rectype,char*name);
static void dbAsciiRecordField(char *name,char *value);
static void dbAsciiRecordBody(void);
/*private declarations*/
static int firstTime = TRUE;
#define MY_BUFFER_SIZE 1024
static char *my_buffer=NULL;
static char *my_buffer_ptr=NULL;
typedef struct inputFile{
ELLNODE node;
char *path;
char *filename;
FILE *fp;
int line_num;
}inputFile;
static ELLLIST inputFileList;
static inputFile *pinputFileNow = NULL;
static DBBASE *pdbbase = NULL;
typedef struct tempListNode {
ELLNODE node;
void *item;
}tempListNode;
static ELLLIST tempList;
static void *freeListPvt = NULL;
static int duplicate = FALSE;
static void yyerrorAbort(char *str)
{
yyerror(str);
free((void *)my_buffer);
exit(-1);
}
static void allocTemp(void *pvoid)
{
tempListNode *ptempListNode;
ptempListNode = freeListCalloc(freeListPvt);
ptempListNode->item = pvoid;
ellAdd(&tempList,&ptempListNode->node);
}
static void *popFirstTemp(void)
{
tempListNode *ptempListNode;
void *ptemp;
ptempListNode = (tempListNode *)ellFirst(&tempList);
ptemp = ptempListNode->item;
ellDelete(&tempList,(ELLNODE *)ptempListNode);
freeListFree(freeListPvt,ptempListNode);
return(ptemp);
}
static void *getLastTemp(void)
{
tempListNode *ptempListNode;
ptempListNode = (tempListNode *)ellLast(&tempList);
return(ptempListNode->item);
}
static long dbAsciiReadCOM(DBBASE **ppdbbase,const char *filename, FILE *fp)
{
long status;
inputFile *pinputFile;
my_buffer = dbCalloc(MY_BUFFER_SIZE,sizeof(char));
if(firstTime) {
ellInit(&inputFileList);
ellInit(&tempList);
freeListInitPvt(&freeListPvt,sizeof(tempListNode),5);
firstTime = FALSE;
}
pinputFile = (inputFile *)ellLast(&inputFileList);
while(pinputFile) {
fclose(pinputFile->fp);
free((void *)pinputFile->filename);
free((void *)pinputFile->path);
ellDelete(&inputFileList,(ELLNODE *)pinputFile);
free((void *)pinputFile);
pinputFile = (inputFile *)ellLast(&inputFileList);
}
pinputFile = dbCalloc(1,sizeof(inputFile));
if(filename) {
pinputFile->filename = dbCalloc(strlen(filename)+1,sizeof(char));
strcpy(pinputFile->filename,filename);
}
if(!fp) {
if(!filename || !(fp = fopen(filename,"r"))) {
errPrintf(0,__FILE__, __LINE__,
"dbAsciiRead opening file %s\n",filename);
free((void *)pinputFile);
free((void *)my_buffer);
return(-1);
}
}
pinputFile->fp = fp;
pinputFile->line_num = 0;
pinputFileNow = pinputFile;
my_buffer[0] = '\0';
my_buffer_ptr = my_buffer;
if(*ppdbbase) {
pdbbase = *ppdbbase;
} else {
pdbbase = dbAllocBase();
*ppdbbase = pdbbase;
}
ellAdd(&inputFileList,&pinputFile->node);
status = pvt_yy_parse();
if(status) {
fprintf(stderr,"db_parse returned %d\n",status);
}
freeListCleanup(freeListPvt);
free((void *)my_buffer);
firstTime = TRUE;
return(0);
}
long dbAsciiRead(DBBASE **ppdbbase,const char *filename)
{return (dbAsciiReadCOM(ppdbbase,filename,0));}
long dbAsciiReadFP(DBBASE **ppdbbase,FILE *fp)
{return (dbAsciiReadCOM(ppdbbase,0,fp));}
static int dbAscii_yyinput(char *buf, int max_size)
{
int l,n;
if(*my_buffer_ptr==0) {
while(fgets(my_buffer,MY_BUFFER_SIZE,pinputFileNow->fp)==NULL) {
if(fclose(pinputFileNow->fp))
errPrintf(0,__FILE__, __LINE__,
"Closing file %s\n",pinputFileNow->filename);
free((void *)pinputFileNow->filename);
free((void *)pinputFileNow->path);
ellDelete(&inputFileList,(ELLNODE *)pinputFileNow);
free((void *)pinputFileNow);
pinputFileNow = (inputFile *)ellLast(&inputFileList);
if(!pinputFileNow) return(0);
}
if(dbDebug) fprintf(stderr,"%s",my_buffer);
pinputFileNow->line_num++;
my_buffer_ptr = &my_buffer[0];
}
l = strlen(my_buffer_ptr);
n = (l<=max_size ? l : max_size);
memcpy(buf,my_buffer_ptr,n);
my_buffer_ptr += n;
return(n);
}
static void dbAsciiIncludePrint(FILE *fp)
{
inputFile *pinputFile = pinputFileNow;
fprintf(fp,"input line: %s",my_buffer);
while(pinputFile) {
if(pinputFile->filename) {
fprintf(fp," in file: ");
if(pinputFile->path)
fprintf(fp," path \"%s\"",pinputFile->path);
fprintf(fp,"%s",pinputFile->filename);
} else {
fprintf(fp," stdin:");
if(pinputFile->path)
fprintf(fp," path \"%s\"",pinputFile->path);
}
fprintf(fp," line %d\n",pinputFile->line_num);
pinputFile = (inputFile *)ellPrevious(&pinputFile->node);
}
fprintf(fp,"\n");
return;
}
static void dbAsciiPath(char *path)
{
pinputFileNow->path = path;
}
static void dbAsciiIncludeNew(char *filename)
{
inputFile *newfile;
inputFile *pinputFile;
inputFile *pinputFileFirst;
FILE *fp;
char *currentPath;
int lenPathAndFilename = 0;
int lenstr;
newfile = dbCalloc(1,sizeof(inputFile));
newfile->filename = dbCalloc(strlen(filename)+1,sizeof(char));
strcpy(newfile->filename,filename);
/*search backward for first path starting with / */
pinputFile = (inputFile *)ellLast(&inputFileList);
while(pinputFile) {
if(pinputFile->path) {
if(pinputFile->path[0]=='/') break;
}
pinputFile = (inputFile *)ellPrevious(&pinputFile->node);
}
if(!pinputFile) pinputFile=(inputFile *)ellFirst(&inputFileList);
pinputFileFirst = pinputFile;
while(pinputFile) {
if(pinputFile->path) {
lenstr = strlen(pinputFile->path);
lenPathAndFilename += lenstr;
if(pinputFile->path[lenstr-1] != '/') lenPathAndFilename++;
}
pinputFile = (inputFile *)ellNext(&pinputFile->node);
}
lenPathAndFilename += strlen(filename) + 1;
currentPath = dbCalloc(lenPathAndFilename,sizeof(char));
pinputFile = pinputFileFirst;
while(pinputFile) {
if(pinputFile->path) {
strcat(currentPath,pinputFile->path);
lenstr = strlen(pinputFile->path);
if(pinputFile->path[lenstr-1] != '/') strcat(currentPath,"/");
}
pinputFile = (inputFile *)ellNext(&pinputFile->node);
}
strcat(currentPath,filename);
fp = fopen(currentPath,"r");
if(!fp) {
errPrintf(0,__FILE__, __LINE__,
"dbAsciiIncludeNew opening file %s\n",currentPath);
yyerror(NULL);
free((void *)filename);
free((void *)newfile);
return;
}
free((void *)currentPath);
free((void *)filename);
newfile->fp = fp;
ellAdd(&inputFileList,&newfile->node);
pinputFileNow = newfile;
}
static void dbAsciiMenuHead(char *name)
{
dbMenu *pdbMenu;
GPHENTRY *pgphentry;
pgphentry = gphFind(pdbbase->pgpHash,name,&pdbbase->menuList);
if(pgphentry) {
yyerror("Duplicate menu ignored");
duplicate = TRUE;
}
pdbMenu = dbCalloc(1,sizeof(dbMenu));
pdbMenu->name = name;
if(ellCount(&tempList)) yyerrorAbort("dbAsciiMenuHead: tempList not empty");
allocTemp(pdbMenu);
}
static void dbAsciiMenuChoice(char *name,char *value)
{
if(duplicate) {
free((void *)name);
free((void *)value);
return;
}
allocTemp(name);
allocTemp(value);
}
static void dbAsciiMenuBody(void)
{
dbMenu *pnewMenu;
dbMenu *pMenu;
int nChoice;
int i;
GPHENTRY *pgphentry;
if(duplicate) {
duplicate = FALSE;
return;
}
pnewMenu = (dbMenu *)popFirstTemp();
pnewMenu->nChoice = nChoice = ellCount(&tempList)/2;
pnewMenu->papChoiceName = dbCalloc(pnewMenu->nChoice,sizeof(char *));
pnewMenu->papChoiceValue = dbCalloc(pnewMenu->nChoice,sizeof(char *));
for(i=0; i<nChoice; i++) {
pnewMenu->papChoiceName[i] = (char *)popFirstTemp();
pnewMenu->papChoiceValue[i] = (char *)popFirstTemp();
}
if(ellCount(&tempList)) yyerrorAbort("dbAsciiMenuBody: tempList not empty");
/* Add menu in sorted order */
pMenu = (dbMenu *)ellFirst(&pdbbase->menuList);
while(pMenu && strcmp(pMenu->name,pnewMenu->name) >0 )
pMenu = (dbMenu *)ellNext(&pMenu->node);
if(pMenu)
ellInsert(&pdbbase->menuList,ellPrevious(&pMenu->node),&pnewMenu->node);
else
ellAdd(&pdbbase->menuList,&pnewMenu->node);
pgphentry = gphAdd(pdbbase->pgpHash,pnewMenu->name,&pdbbase->menuList);
if(!pgphentry) {
yyerrorAbort("gphAdd failed");
} else {
pgphentry->userPvt = pnewMenu;
}
}
static void dbAsciiRecordtypeHead(char *name)
{
dbRecDes *pdbRecDes;
GPHENTRY *pgphentry;
pgphentry = gphFind(pdbbase->pgpHash,name,&pdbbase->recDesList);
if(pgphentry) {
yyerror("Duplicate recordtype ignored");
duplicate = TRUE;
}
pdbRecDes = dbCalloc(1,sizeof(dbRecDes));
pdbRecDes->name = name;
if(ellCount(&tempList))
yyerrorAbort("dbAsciiRecordtypeHead tempList not empty");
allocTemp(pdbRecDes);
}
static void dbAsciiRecordtypeFieldHead(char *name,char *type)
{
dbFldDes *pdbFldDes;
int i;
if(duplicate) {
free((void *)name);
free((void *)type);
return;
}
pdbFldDes = dbCalloc(1,sizeof(dbFldDes));
allocTemp(pdbFldDes);
pdbFldDes->name = name;
for(i=0; i<DBF_NTYPES; i++) {
if(strcmp(type,pamapdbfType[i].strvalue)==0) {
pdbFldDes->field_type = pamapdbfType[i].value;
free((void *)type);
return;
}
}
free((void *)type);
yyerrorAbort("Illegal Field Type");
}
static void dbAsciiRecordtypeFieldItem(char *name,char *value)
{
dbFldDes *pdbFldDes;
if(duplicate) {
free((void *)name);
free((void *)value);
return;
}
pdbFldDes = (dbFldDes *)getLastTemp();
if(strcmp(name,"asl")==0) {
if(strcmp(value,"ASL0")==0) {
pdbFldDes->as_level = ASL0;
} else if(strcmp(value,"ASL1")==0) {
pdbFldDes->as_level = ASL1;
} else {
yyerror("Illegal Access Security value: Must be ASL0 or ASL1");
}
free((void *)name);
free((void *)value);
return;
}
if(strcmp(name,"initial")==0) {
pdbFldDes->initial = value;
free((void *)name);
return;
}
if(strcmp(name,"promptgroup")==0) {
int i;
for(i=0; i<GUI_NTYPES; i++) {
if(strcmp(value,pamapguiGroup[i].strvalue)==0) {
pdbFldDes->promptgroup = pamapguiGroup[i].value;
free((void *)name);
free((void *)value);
return;
}
}
yyerror("Illegal promptgroup. See guigroup.h for legal values");
return;
}
if(strcmp(name,"prompt")==0) {
pdbFldDes->prompt = value;
free((void *)name);
return;
}
if(strcmp(name,"special")==0) {
int i;
for(i=0; i<SPC_NTYPES; i++) {
if(strcmp(value,pamapspcType[i].strvalue)==0) {
pdbFldDes->special = pamapspcType[i].value;
free((void *)name);
free((void *)value);
return;
}
}
if(sscanf(value,"%hd",&pdbFldDes->special)==1) {
free((void *)name);
free((void *)value);
return;
}
yyerror("Illegal promptgroup. See guigroup.h for legal values");
return;
}
if(strcmp(name,"pp")==0) {
if((strcmp(value,"YES")==0) || (strcmp(value,"TRUE")==0)) {
pdbFldDes->process_passive = TRUE;
} else if((strcmp(value,"NO")==0) || (strcmp(value,"FALSE")==0)) {
pdbFldDes->process_passive = FALSE;
} else {
yyerror("Illegal value. Must be NO or YES");
}
free((void *)name);
free((void *)value);
return;
}
if(strcmp(name,"interest")==0) {
if(sscanf(value,"%hd",&pdbFldDes->interest)!=1)
yyerror("Illegal value. Must be integer");
free((void *)name);
free((void *)value);
return;
}
if(strcmp(name,"base")==0) {
if(strcmp(value,"DECIMAL")==0) {
pdbFldDes->base = CT_DECIMAL;
} else if(strcmp(value,"HEX")==0) {
pdbFldDes->base = CT_HEX;
} else {
yyerror("Illegal value. Must be CT_DECIMAL or CT_HEX");
}
free((void *)name);
free((void *)value);
return;
}
if(strcmp(name,"size")==0) {
if(sscanf(value,"%hd",&pdbFldDes->size)!=1)
yyerror("Illegal value. Must be integer");
free((void *)name);
free((void *)value);
return;
}
if(strcmp(name,"extra")==0) {
pdbFldDes->extra = value;
free((void *)name);
return;
}
if(strcmp(name,"menu")==0) {
pdbFldDes->ftPvt = (dbMenu *)dbFindMenu(pdbbase,value);
if(!pdbbase->ignoreMissingMenus && !pdbFldDes->ftPvt)
yyerrorAbort("menu not found");
free((void *)name);
free((void *)value);
return;
}
}
static void dbAsciiRecordtypeBody(void)
{
dbRecDes *pdbRecDes;
dbFldDes *pdbFldDes;
int i,j,ilink;
GPHENTRY *pgphentry;
int no_fields,no_prompt,no_links;
dbfType field_type;
char *psortFldNameTemp;
short psortFldIndTemp;
char **papsortFldName;
short *sortFldInd;
if(duplicate) {
duplicate = FALSE;
return;
}
pdbRecDes= (dbRecDes *)popFirstTemp();
pdbRecDes->no_fields = no_fields = ellCount(&tempList);
pdbRecDes->papFldDes = dbCalloc(no_fields,sizeof(dbFldDes *));
pdbRecDes->papsortFldName = dbCalloc(no_fields,sizeof(char *));
pdbRecDes->sortFldInd = dbCalloc(no_fields,sizeof(short));
no_prompt = no_links = 0;
for(i=0; i<no_fields; i++) {
pdbFldDes = (dbFldDes *)popFirstTemp();
pdbFldDes->pdbRecDes = pdbRecDes;
pdbFldDes->indRecDes = i;
pdbRecDes->papFldDes[i] = pdbFldDes;
if(pdbFldDes->promptgroup) no_prompt++;
field_type = pdbFldDes->field_type;
if((field_type>=DBF_INLINK) && (field_type<=DBF_FWDLINK))no_links++;
if((field_type==DBF_STRING) && (pdbFldDes->size==0))
fprintf(stderr,"recordtype(%s).%s size not specified\n",
pdbRecDes->name,pdbFldDes->name);
if((field_type==DBF_NOACCESS) && (pdbFldDes->extra==0))
fprintf(stderr,"recordtype(%s).%s extra not specified\n",
pdbRecDes->name,pdbFldDes->name);
}
if(ellCount(&tempList)) yyerrorAbort("dbAsciiMenuBody: tempList not empty");
pdbRecDes->no_prompt = no_prompt;
pdbRecDes->no_links = no_links;
pdbRecDes->link_ind = dbCalloc(no_prompt,sizeof(short));
ilink = 0;
for(i=0; i<no_fields; i++) {
pdbFldDes = pdbRecDes->papFldDes[i];
field_type = pdbFldDes->field_type;
if((field_type>=DBF_INLINK) && (field_type<=DBF_FWDLINK))
pdbRecDes->link_ind[ilink++] = i;
if(strcmp(pdbFldDes->name,"VAL")==0) {
pdbRecDes->pvalFldDes = pdbRecDes->papFldDes[i];
pdbRecDes->indvalFlddes = i;
}
pdbRecDes->papsortFldName[i] = pdbFldDes->name;
pdbRecDes->sortFldInd[i] = i;
}
/*Now sort fields. Sorry dumb sort algorithm */
papsortFldName = pdbRecDes->papsortFldName;
sortFldInd = pdbRecDes->sortFldInd;
for(i=0; i<no_fields; i++) {
for(j=i+1; j<no_fields; j++) {
if(strcmp(papsortFldName[j],papsortFldName[i])<0 ) {
psortFldNameTemp = papsortFldName[j];
psortFldIndTemp = sortFldInd[j];
papsortFldName[j] = papsortFldName[i];
sortFldInd[j] = sortFldInd[i];
papsortFldName[i] = psortFldNameTemp;
sortFldInd[i] = psortFldIndTemp;
}
}
}
/*Initialize lists*/
ellInit(&pdbRecDes->recList);
ellInit(&pdbRecDes->devList);
pgphentry = gphAdd(pdbbase->pgpHash,pdbRecDes->name,&pdbbase->recDesList);
if(!pgphentry) {
yyerrorAbort("gphAdd failed");
} else {
pgphentry->userPvt = pdbRecDes;
}
ellAdd(&pdbbase->recDesList,&pdbRecDes->node);
dbGetRecordtypeSizeOffset(pdbRecDes);
}
static void dbAsciiDevice(char *recordtype,char *linktype,
char *dsetname,char *choicestring)
{
devSup *pdevSup;
dbRecDes *pdbRecDes;
GPHENTRY *pgphentry;
int i,link_type;
pgphentry = gphFind(pdbbase->pgpHash,recordtype,&pdbbase->recDesList);
if(!pgphentry) {
yyerror(" record type not found");
return;
}
free(recordtype);
link_type=-1;
for(i=0; i<LINK_NTYPES; i++) {
if(strcmp(pamaplinkType[i].strvalue,linktype)==0) {
link_type = pamaplinkType[i].value;
break;
}
}
free(linktype);
if(link_type==-1) {
yyerror("Illegal link type");
return;
}
pdbRecDes = (dbRecDes *)pgphentry->userPvt;
pgphentry = gphFind(pdbbase->pgpHash,choicestring,&pdbRecDes->devList);
if(pgphentry) {
yyerror("Duplicate Device Support ignored");
free((void *)dsetname);
free((void *)choicestring);
return;
}
pdevSup = dbCalloc(1,sizeof(devSup));
pdevSup->name = dsetname;
pdevSup->choice = choicestring;
pdevSup->link_type = link_type;
pgphentry = gphAdd(pdbbase->pgpHash,choicestring,&pdbRecDes->devList);
if(!pgphentry) {
yyerror("gphAdd failed");
} else {
pgphentry->userPvt = pdevSup;
}
ellAdd(&pdbRecDes->devList,&pdevSup->node);
}
static void dbAsciiDriver(char *name)
{
drvSup *pdrvSup;
GPHENTRY *pgphentry;
pgphentry = gphFind(pdbbase->pgpHash,name,&pdbbase->drvList);
if(pgphentry) {
yyerror("Duplicate driver ignored");
return;
}
pdrvSup = dbCalloc(1,sizeof(drvSup));
pdrvSup->name = name;
pgphentry = gphAdd(pdbbase->pgpHash,name,&pdbbase->drvList);
if(!pgphentry) {
yyerrorAbort("gphAdd failed");
}
pgphentry->userPvt = pdrvSup;
ellAdd(&pdbbase->drvList,&pdrvSup->node);
}
static void dbAsciiBreakHead(char *name)
{
brkTable *pbrkTable;
GPHENTRY *pgphentry;
pgphentry = gphFind(pdbbase->pgpHash,name,&pdbbase->bptList);
if(pgphentry) {
yyerror("Duplicate breakpoint table ignored");
duplicate = TRUE;
}
pbrkTable = dbCalloc(1,sizeof(brkTable));
pbrkTable->name = name;
if(ellCount(&tempList)) yyerrorAbort("dbAsciiBreakHead:tempList not empty"); allocTemp(pbrkTable);
}
static void dbAsciiBreakItem(char *value)
{
if(duplicate) {
free((void *)value);
return;
}
allocTemp(value);
}
static void dbAsciiBreakBody(void)
{
brkTable *pnewbrkTable;
brkTable *pbrkTable;
int number;
int i,choice;
GPHENTRY *pgphentry;
if(duplicate) {
duplicate = FALSE;
return;
}
pnewbrkTable = (brkTable *)popFirstTemp();
pnewbrkTable->number = number = ellCount(&tempList)/2;
if(number*2 != ellCount(&tempList))
yyerrorAbort("dbAsciiBreakBody: Odd number of values");
pnewbrkTable->papBrkInt = dbCalloc(number,sizeof(brkInt));
for(i=0; i<number; i++) {
double raw,eng;
char *praw;
char *peng;
praw = (char *)popFirstTemp();
peng = (char *)popFirstTemp();
if((sscanf(praw,"%lf",&raw)!=1) || (sscanf(peng,"%lf",&eng)!=1) ) {
yyerrorAbort("dbAsciibrkTable: Illegal table value");
}
free((void *)praw);
free((void *)peng);
pnewbrkTable->papBrkInt[i] = dbCalloc(1,sizeof(brkInt));
pnewbrkTable->papBrkInt[i]->raw = raw;
pnewbrkTable->papBrkInt[i]->eng = eng;
}
/* Compute slopes */
for(i=0; i<number-1; i++) {
pnewbrkTable->papBrkInt[i]->slope =
(pnewbrkTable->papBrkInt[i+1]->eng - pnewbrkTable->papBrkInt[i]->eng)/
(pnewbrkTable->papBrkInt[i+1]->raw - pnewbrkTable->papBrkInt[i]->raw);
}
/* Add brkTable in sorted order */
pbrkTable = (brkTable *)ellFirst(&pdbbase->bptList);
while(pbrkTable) {
choice = strcmp(pbrkTable->name,pnewbrkTable->name);
if(choice==0) {
ellInsert(&pdbbase->bptList,ellPrevious((ELLNODE *)pbrkTable),
(ELLNODE *)pnewbrkTable);
gphDelete(pdbbase->pgpHash,pbrkTable->name,&pdbbase->bptList);
ellDelete(&pdbbase->bptList,(ELLNODE *)pbrkTable);
break;
} else if(choice>0) {
ellInsert(&pdbbase->bptList,ellPrevious((ELLNODE *)pbrkTable),
(ELLNODE *)pnewbrkTable);
break;
}
pbrkTable = (brkTable *)ellNext(&pbrkTable->node);
}
pgphentry = gphAdd(pdbbase->pgpHash,pnewbrkTable->name,&pdbbase->bptList);
if(!pgphentry) {
yyerrorAbort("gphAdd failed");
} else {
pgphentry->userPvt = pnewbrkTable;
}
if(!pbrkTable) ellAdd(&pdbbase->bptList,&pnewbrkTable->node);
}
static void dbAsciiRecordHead(char *rectype,char *name)
{
DBENTRY *pdbentry;
long status;
pdbentry = dbAllocEntry(pdbbase);
if(ellCount(&tempList))
yyerrorAbort("dbAsciiRecordHead: tempList not empty");
allocTemp(pdbentry);
status = dbFindRecdes(pdbentry,rectype);
if(status) {
errMessage(status,"");
yyerrorAbort(NULL);
return;
}
/*Duplicate records ok. Thus dont check return status.*/
dbCreateRecord(pdbentry,name);
}
static void dbAsciiRecordField(char *name,char *value)
{
DBENTRY *pdbentry;
tempListNode *ptempListNode;
long status;
ptempListNode = (tempListNode *)ellFirst(&tempList);
pdbentry = ptempListNode->item;
status = dbFindField(pdbentry,name);
if(status) {
errMessage(status,"");
yyerror(NULL);
return;
}
status = dbPutString(pdbentry,value);
if(status) {
errMessage(status,"");
yyerror(NULL);
return;
}
}
static void dbAsciiRecordBody(void)
{
DBENTRY *pdbentry;
pdbentry = (DBENTRY *)popFirstTemp();
if(ellCount(&tempList))
yyerrorAbort("dbAsciiRecordBody: tempList not empty");
dbFreeEntry(pdbentry);
}

View File

@@ -0,0 +1,56 @@
/* asciiTest.c */
/* Author: Marty Kraimer Date: 13JUL95 */
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
/* Modification Log:
* -----------------
* .01 13JUL95 mrk Initial Implementation
*/
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <epicsPrint.h>
#include <errMdef.h>
#include <dbStaticLib.h>
#include <dbStaticPvt.h>
#include <dbBase.h>
#include <gpHash.h>
DBBASE *pdbbase = NULL;
int main(int argc,char **argv)
{
long status;
int i;
if(argc<2) {
printf("usage: dbAsciiTest file1.ascii fi;e2.ascii ...\n");
exit(0);
}
for(i=1; i<argc; i++) {
status = dbAsciiRead(&pdbbase,argv[i]);
if(!status) continue;
epicsPrintf("For input file %s",argv[i]);
errMessage(status,"from dbAsciiInitialize");
}
/*
dbDumpRecDes(pdbbase,"ai");
dbDumpRecDes(pdbbase,NULL);
dbPvdDump(pdbbase);
gphDump(pdbbase->pgpHash);
dbDumpMenu(pdbbase,NULL);
dbDumpRecords(pdbbase,NULL,0);
*/
dbFreeBase(pdbbase);
return(0);
}

View File

@@ -0,0 +1,79 @@
/* dbAsciiToMenuH.c */
/* Author: Marty Kraimer Date: 11Sep95 */
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
/* Modification Log:
* -----------------
* .01 11Sep95 mrk Initial Implementation
*/
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <epicsPrint.h>
#include <errMdef.h>
#include <dbStaticLib.h>
#include <dbStaticPvt.h>
#include <dbBase.h>
#include <gpHash.h>
DBBASE *pdbbase = NULL;
int main(int argc,char **argv)
{
long status;
dbMenu *pdbMenu;
char *outFilename;
char *pext;
FILE *outFile;
int i;
if(argc!=2) {
fprintf(stderr,"usage: dbAsciiToMenuH file.ascii\n");
exit(-1);
}
outFilename = dbCalloc(1,strlen(argv[1])+1);
strcpy(outFilename,argv[1]);
pext = strstr(outFilename,".ascii");
if(!pext) {
fprintf(stderr,"Input file MUST have .ascii extension\n");
exit(-1);
}
strcpy(pext,".h");
outFile = fopen(outFilename,"w");
if(!outFile) {
errPrintf(0,__FILE__,__LINE__,"Error opening %s\n",outFilename);
exit(-1);
}
pdbbase = dbAllocBase();
pdbbase->ignoreMissingMenus = TRUE;
status = dbAsciiRead(&pdbbase,argv[1]);
if(status) {
epicsPrintf("Terminal error For input file %s\n",argv[1]);
exit(-1);
}
pdbMenu = (dbMenu *)ellFirst(&pdbbase->menuList);
while(pdbMenu) {
fprintf(outFile,"#ifndef INC%sH\n",pdbMenu->name);
fprintf(outFile,"#define INC%sH\n",pdbMenu->name);
fprintf(outFile,"typedef enum {\n");
for(i=0; i<pdbMenu->nChoice; i++) {
fprintf(outFile,"\t%s,\n",pdbMenu->papChoiceName[i]);
}
fprintf(outFile,"}%s;\n",pdbMenu->name);
fprintf(outFile,"#endif /*INC%sH*/\n",pdbMenu->name);
pdbMenu = (dbMenu *)ellNext(&pdbMenu->node);
}
fclose(outFile);
free((void *)outFilename);
return(0);
}

View File

@@ -0,0 +1,207 @@
/* dbAsciiToRecordtypeH.c */
/* Author: Marty Kraimer Date: 11Sep95 */
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
/* Modification Log:
* -----------------
* .01 11Sep95 mrk Initial Implementation
*/
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <epicsPrint.h>
#include <errMdef.h>
#include <dbStaticLib.h>
#include <dbStaticPvt.h>
#include <dbBase.h>
#include <gpHash.h>
DBBASE *pdbbase = NULL;
int main(int argc,char **argv)
{
long status;
char *outFilename;
char *pext;
FILE *outFile;
int i;
dbMenu *pdbMenu;
dbRecDes *pdbRecDes;
dbFldDes *pdbFldDes;
int isdbCommonRecord = FALSE;
if(argc!=2) {
fprintf(stderr,"usage: dbAsciiToMenuH file.ascii\n");
exit(-1);
}
outFilename = dbCalloc(1,strlen(argv[1])+1);
strcpy(outFilename,argv[1]);
pext = strstr(outFilename,".ascii");
if(!pext) {
fprintf(stderr,"Input file MUST have .ascii extension\n");
exit(-1);
}
strcpy(pext,".h");
if(strcmp(outFilename,"dbCommonRecord.h")==0) {
strcpy(outFilename,"dbCommon.h");
isdbCommonRecord = TRUE;
}
outFile = fopen(outFilename,"w");
if(!outFile) {
errPrintf(0,__FILE__,__LINE__,"Error opening %s\n",outFilename);
exit(-1);
}
pdbbase = dbAllocBase();
pdbbase->ignoreMissingMenus = TRUE;
status = dbAsciiRead(&pdbbase,argv[1]);
if(status) {
epicsPrintf("Terminal error For input file %s\n",argv[1]);
exit(-1);
}
fprintf(outFile,"#include <vxWorks.h>\n");
fprintf(outFile,"#include <semLib.h>\n");
fprintf(outFile,"#include \"ellLib.h\"\n");
fprintf(outFile,"#include \"fast_lock.h\"\n");
fprintf(outFile,"#include \"link.h\"\n");
fprintf(outFile,"#include \"tsDefs.h\"\n");
pdbMenu = (dbMenu *)ellFirst(&pdbbase->menuList);
while(pdbMenu) {
fprintf(outFile,"\n#ifndef INC%sH\n",pdbMenu->name);
fprintf(outFile,"#define INC%sH\n",pdbMenu->name);
fprintf(outFile,"typedef enum {\n");
for(i=0; i<pdbMenu->nChoice; i++) {
fprintf(outFile,"\t%s,\n",pdbMenu->papChoiceName[i]);
}
fprintf(outFile,"}%s;\n",pdbMenu->name);
fprintf(outFile,"#endif /*INC%sH*/\n",pdbMenu->name);
pdbMenu = (dbMenu *)ellNext(&pdbMenu->node);
}
pdbRecDes = (dbRecDes *)ellFirst(&pdbbase->recDesList);
while(pdbRecDes) {
fprintf(outFile,"#ifndef INC%sH\n",pdbRecDes->name);
fprintf(outFile,"#define INC%sH\n",pdbRecDes->name);
fprintf(outFile,"typedef struct %s",pdbRecDes->name);
if(!isdbCommonRecord) fprintf(outFile,"Record");
fprintf(outFile," {\n");
for(i=0; i<pdbRecDes->no_fields; i++) {
char name[256];
int j;
pdbFldDes = pdbRecDes->papFldDes[i];
for(j=0; j< (int)strlen(pdbFldDes->name); j++)
name[j] = tolower(pdbFldDes->name[j]);
name[strlen(pdbFldDes->name)] = 0;
switch(pdbFldDes->field_type) {
case DBF_STRING :
fprintf(outFile,"\tchar\t\t%s[%d]; /*%s*/\n",
name,pdbFldDes->size,pdbFldDes->prompt);
break;
case DBF_CHAR :
fprintf(outFile,"\tchar\t\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_UCHAR :
fprintf(outFile,"\tunsigned char\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_SHORT :
fprintf(outFile,"\tshort\t\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_USHORT :
fprintf(outFile,"\tunsigned short\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_LONG :
fprintf(outFile,"\tlong\t\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_ULONG :
fprintf(outFile,"\tunsigned long\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_FLOAT :
fprintf(outFile,"\tfloat\t\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_DOUBLE :
fprintf(outFile,"\tdouble\t\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_ENUM :
case DBF_MENU :
case DBF_DEVICE :
fprintf(outFile,"\tunsigned short\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_INLINK :
case DBF_OUTLINK :
case DBF_FWDLINK :
fprintf(outFile,"\tDBLINK\t\t%s;\t/*%s*/\n",
name,pdbFldDes->prompt);
break;
case DBF_NOACCESS:
fprintf(outFile,"\t%s;\t/*%s*/\n",
pdbFldDes->extra,pdbFldDes->prompt);
break;
default:
fprintf(outFile,"ILLEGAL FIELD TYPE\n");
}
}
fprintf(outFile,"} %s",pdbRecDes->name);
if(!isdbCommonRecord) fprintf(outFile,"Record");
fprintf(outFile,";\n");
if(!isdbCommonRecord) {
for(i=0; i<pdbRecDes->no_fields; i++) {
pdbFldDes = pdbRecDes->papFldDes[i];
fprintf(outFile,"#define %sRecord%s\t%d\n",
pdbRecDes->name,pdbFldDes->name,pdbFldDes->indRecDes);
}
}
fprintf(outFile,"#endif /*INC%sH*/\n",pdbRecDes->name);
pdbRecDes = (dbRecDes *)ellNext(&pdbRecDes->node);
if(pdbRecDes) fprintf(outFile,"\n");
}
if(!isdbCommonRecord) {
fprintf(outFile,"#ifdef GEN_SIZE_OFFSET\n");
pdbRecDes = (dbRecDes *)ellFirst(&pdbbase->recDesList);
while(pdbRecDes) {
fprintf(outFile,"int %sRecordSizeOffset(dbRecDes *pdbRecDes)\n{\n",
pdbRecDes->name);
fprintf(outFile," %sRecord *prec = 0;\n",pdbRecDes->name);
for(i=0; i<pdbRecDes->no_fields; i++) {
char name[256];
int j;
pdbFldDes = pdbRecDes->papFldDes[i];
for(j=0; j< (int)strlen(pdbFldDes->name); j++)
name[j] = tolower(pdbFldDes->name[j]);
name[strlen(pdbFldDes->name)] = 0;
fprintf(outFile,
" pdbRecDes->papFldDes[%d]->size=sizeof(prec->%s);\n",
i,name);
fprintf(outFile," pdbRecDes->papFldDes[%d]->offset=",i);
fprintf(outFile,
"(short)((char *)&prec->%s - (char *)prec);\n",name);
}
fprintf(outFile," pdbRecDes->rec_size = sizeof(*prec);\n");
fprintf(outFile," return(0);\n");
fprintf(outFile,"}\n");
pdbRecDes = (dbRecDes *)ellNext(&pdbRecDes->node);
}
fprintf(outFile,"#endif /*GEN_SIZE_OFFSET*/\n");
}
fclose(outFile);
free((void *)outFilename);
return(0);
}

199
src/dbStatic/dbAsciiYacc.y Normal file
View File

@@ -0,0 +1,199 @@
%{
static int yyerror();
static int yy_start;
static long pvt_yy_parse(void);
static int yyFailed = 0;
#include "dbAsciiRoutines.c"
static char *menuString = "menu";
%}
%start database
%token tokenINCLUDE tokenPATH
%token tokenMENU tokenCHOICE tokenRECORDTYPE tokenFIELD
%token tokenDEVICE tokenDRIVER tokenBREAKTABLE
%token tokenRECORD
%token <Str> tokenSTRING
%union
{
char *Str;
}
%%
database: database database_item | database_item;
database_item: include
| path
| tokenMENU menu_head menu_body
| tokenRECORDTYPE recordtype_head recordtype_body
| device
| driver
| tokenBREAKTABLE break_head break_body
| tokenRECORD record_head record_body
;
include: tokenINCLUDE tokenSTRING
{
if(dbDebug>2) printf("include : %s\n",$2);
dbAsciiIncludeNew($2);
};
path: tokenPATH tokenSTRING
{
if(dbDebug>2) printf("path : %s\n",$2);
dbAsciiPath($2);
};
menu_head: '(' tokenSTRING ')'
{
if(dbDebug>2) printf("menu_head %s\n",$2);
dbAsciiMenuHead($2);
};
menu_body: '{' choice_list '}'
{
if(dbDebug>2) printf("menu_body\n");
dbAsciiMenuBody();
}
| include ;
choice_list: choice_list choice | choice;
choice: tokenCHOICE '(' tokenSTRING ',' tokenSTRING ')'
{
if(dbDebug>2) printf("choice %s %s\n",$3,$5);
dbAsciiMenuChoice($3,$5);
} ;
recordtype_head: '(' tokenSTRING ')'
{
if(dbDebug>2) printf("recordtype_head %s\n",$2);
dbAsciiRecordtypeHead($2);
};
recordtype_body: '{' recordtype_field_list '}'
{
if(dbDebug>2) printf("recordtype_body\n");
dbAsciiRecordtypeBody();
};
recordtype_field_list: recordtype_field_list recordtype_field
| recordtype_field;
recordtype_field: tokenFIELD recordtype_field_head recordtype_field_body
| include ;
recordtype_field_head: '(' tokenSTRING ',' tokenSTRING ')'
{
if(dbDebug>2) printf("recordtype_field_head %s %s\n",$2,$4);
dbAsciiRecordtypeFieldHead($2,$4);
};
recordtype_field_body: '{' recordtype_field_item_list '}' ;
recordtype_field_item_list: recordtype_field_item_list recordtype_field_item
| recordtype_field_item;
recordtype_field_item: tokenSTRING '(' tokenSTRING ')'
{
if(dbDebug>2) printf("recordtype_field_item %s %s\n",$1,$3);
dbAsciiRecordtypeFieldItem($1,$3);
}
| tokenMENU '(' tokenSTRING ')'
{
char *pmenu;
if(dbDebug>2) printf("recordtype_field_item %s (%s)\n",menuString,$3);
pmenu = (char *)malloc(strlen(menuString)+1);
strcpy(pmenu,menuString);
dbAsciiRecordtypeFieldItem(pmenu,$3);
};
device: tokenDEVICE '('
tokenSTRING ',' tokenSTRING ',' tokenSTRING ',' tokenSTRING ')'
{
if(dbDebug>2) printf("device %s %s %s %s\n",$3,$5,$7,$9);
dbAsciiDevice($3,$5,$7,$9);
};
driver: tokenDRIVER '(' tokenSTRING ')'
{
if(dbDebug>2) printf("driver %s\n",$3);
dbAsciiDriver($3);
};
break_head: '(' tokenSTRING ')'
{
if(dbDebug>2) printf("break_head %s\n",$2);
dbAsciiBreakHead($2);
};
break_body : '{' break_list '}'
{
if(dbDebug>2) printf("break_body\n");
dbAsciiBreakBody();
};
break_list: break_list ',' break_item | break_item;
break_item: tokenSTRING
{
if(dbDebug>2) printf("break_item tokenSTRING %s\n",$1);
dbAsciiBreakItem($1);
};
record_head: '(' tokenSTRING ',' tokenSTRING ')'
{
if(dbDebug>2) printf("record_head %s %s\n",$2,$4);
dbAsciiRecordHead($2,$4);
};
record_body: '{' record_field_list '}'
{
if(dbDebug>2) printf("record_body\n");
dbAsciiRecordBody();
};
record_field_list: record_field_list record_field
| record_field;
record_field: tokenFIELD '(' tokenSTRING ',' tokenSTRING ')'
{
if(dbDebug>2) printf("record_field %s %s\n",$3,$5);
dbAsciiRecordField($3,$5);
}
| include ;
%%
#include "dbAsciiLex.c"
static int yyerror(char *str)
{
fprintf(stderr,"Error ");
if(str) fprintf(stderr,"\"%s\"",str);
fprintf(stderr," Last token \"%s\"\n",yytext);
dbAsciiIncludePrint(stderr);
yyFailed = TRUE;
return(0);
}
static long pvt_yy_parse(void)
{
static int FirstFlag = 1;
long rtnval;
if (!FirstFlag) {
yyFailed = FALSE;
yyreset();
yyrestart(NULL);
}
FirstFlag = 0;
rtnval = yyparse();
if(rtnval!=0 || yyFailed) return(-1); else return(0);
}

243
src/dbStatic/dbPvdLib.c Normal file
View File

@@ -0,0 +1,243 @@
/*dbPvdLib.c*/
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
#ifdef vxWorks
#include <vxWorks.h>
#include <taskLib.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ellLib.h>
#include <dbDefs.h>
#include <dbStaticLib.h>
#include <dbStaticPvt.h>
int dbPvdHashTableSize = 512;
static int dbPvdHashTableShift;
#define NTABLESIZES 9
static struct {
unsigned int tablesize;
int shift;
}hashTableParms[9] = {
{256,0},
{512,1},
{1024,2},
{2048,3},
{4096,4},
{8192,5},
{16384,6},
{32768,7},
{65536,8}
};
/*The hash algorithm is a modification of the algorithm described in */
/* Fast Hashing of Variable Length Text Strings, Peter K. Pearson, */
/* Communications of the ACM, June 1990 */
/* The modifications were designed by Marty Kraimer */
static unsigned char T[256] = {
39,159,180,252, 71, 6, 13,164,232, 35,226,155, 98,120,154, 69,
157, 24,137, 29,147, 78,121, 85,112, 8,248,130, 55,117,190,160,
176,131,228, 64,211,106, 38, 27,140, 30, 88,210,227,104, 84, 77,
75,107,169,138,195,184, 70, 90, 61,166, 7,244,165,108,219, 51,
9,139,209, 40, 31,202, 58,179,116, 33,207,146, 76, 60,242,124,
254,197, 80,167,153,145,129,233,132, 48,246, 86,156,177, 36,187,
45, 1, 96, 18, 19, 62,185,234, 99, 16,218, 95,128,224,123,253,
42,109, 4,247, 72, 5,151,136, 0,152,148,127,204,133, 17, 14,
182,217, 54,199,119,174, 82, 57,215, 41,114,208,206,110,239, 23,
189, 15, 3, 22,188, 79,113,172, 28, 2,222, 21,251,225,237,105,
102, 32, 56,181,126, 83,230, 53,158, 52, 59,213,118,100, 67,142,
220,170,144,115,205, 26,125,168,249, 66,175, 97,255, 92,229, 91,
214,236,178,243, 46, 44,201,250,135,186,150,221,163,216,162, 43,
11,101, 34, 37,194, 25, 50, 12, 87,198,173,240,193,171,143,231,
111,141,191,103, 74,245,223, 20,161,235,122, 63, 89,149, 73,238,
134, 68, 93,183,241, 81,196, 49,192, 65,212, 94,203, 10,200, 47
};
static unsigned short hash( char *pname, int length)
{
unsigned char h0=0;
unsigned char h1=0;
unsigned short ind0,ind1;
int even = TRUE;
unsigned char c;
int i;
for(i=0; i<length; i++, pname++) {
c = *pname;
if(even) {h0 = T[h0^c]; even = FALSE;}
else {h1 = T[h1^c]; even = TRUE;}
}
ind0 = (unsigned short)h0;
ind1 = (unsigned short)h1;
return((ind1<<dbPvdHashTableShift) ^ ind0);
}
int dbPvdTableSize(DBBASE *pdbBase,int size)
{
int i;
for(i=0; i< NTABLESIZES; i++) {
if(size==hashTableParms[i].tablesize) {
dbPvdHashTableSize = hashTableParms[i].tablesize;
dbPvdHashTableShift = hashTableParms[i].shift;
return(0);
}
}
printf("Illegal Size for Process Variable Directory\n");
return(-1);
}
void dbPvdInitPvt(dbBase *pdbBase)
{
ELLLIST **ppvd;
int i;
for(i=0; i< NTABLESIZES; i++) {
if((i==NTABLESIZES-1)
||((dbPvdHashTableSize>=hashTableParms[i].tablesize)
&& (dbPvdHashTableSize<hashTableParms[i+1].tablesize))) {
dbPvdHashTableSize = hashTableParms[i].tablesize;
dbPvdHashTableShift = hashTableParms[i].shift;
break;
}
}
ppvd = dbCalloc(dbPvdHashTableSize, sizeof(ELLLIST *));
pdbBase->ppvd = (void *) ppvd;
return;
}
PVDENTRY *dbPvdFind(dbBase *pdbBase,char *name,int lenName)
{
unsigned short hashInd;
ELLLIST **ppvd = (ELLLIST **) pdbBase->ppvd;
ELLLIST *pvdlist;
PVDENTRY *ppvdNode;
hashInd = hash(name, lenName);
if ((pvdlist=ppvd[hashInd]) == NULL) return (NULL);
ppvdNode = (PVDENTRY *) ellFirst(pvdlist);
while(ppvdNode) {
if(strcmp(name,ppvdNode->precnode->recordname) == 0)
return(ppvdNode);
ppvdNode = (PVDENTRY *) ellNext((ELLNODE*)ppvdNode);
}
return (NULL);
}
PVDENTRY *dbPvdAdd(dbBase *pdbBase,dbRecDes *precdes,dbRecordNode *precnode)
{
unsigned short hashInd;
ELLLIST **ppvd = (ELLLIST **) pdbBase->ppvd;
ELLLIST *ppvdlist;
PVDENTRY *ppvdNode;
int lenName;
char *name=precnode->recordname;
lenName=strlen(name);
hashInd = hash(name, lenName);
if (ppvd[hashInd] == NULL) {
ppvd[hashInd] = dbCalloc(1, sizeof(ELLLIST));
ellInit(ppvd[hashInd]);
}
ppvdlist=ppvd[hashInd];
ppvdNode = (PVDENTRY *) ellFirst(ppvdlist);
while(ppvdNode) {
if(strcmp(name,(char *)ppvdNode->precnode->precord) == 0) return(NULL);
ppvdNode = (PVDENTRY *) ellNext((ELLNODE*)ppvdNode);
}
ppvdNode = dbCalloc(1, sizeof(PVDENTRY));
ellAdd(ppvdlist, (ELLNODE*)ppvdNode);
ppvdNode->precdes = precdes;
ppvdNode->precnode = precnode;
return (ppvdNode);
}
void dbPvdDelete(dbBase *pdbBase,dbRecordNode *precnode)
{
char *name=precnode->recordname;
unsigned short hashInd;
ELLLIST **ppvd = (ELLLIST **) pdbBase->ppvd;
ELLLIST *ppvdlist;
PVDENTRY *ppvdNode;
int lenName;
lenName=strlen(name);
hashInd = hash(name, lenName);
if (ppvd[hashInd] == NULL)return;
ppvdlist=ppvd[hashInd];
ppvdNode = (PVDENTRY *) ellFirst(ppvdlist);
while(ppvdNode) {
if(ppvdNode->precnode && ppvdNode->precnode->precord
&& strcmp(name,(char *)ppvdNode->precnode->precord) == 0) {
ellDelete(ppvdlist, (ELLNODE*)ppvdNode);
free((void *)ppvdNode);
return;
}
ppvdNode = (PVDENTRY *) ellNext((ELLNODE*)ppvdNode);
}
return;
}
void dbPvdFreeMem(dbBase *pdbBase)
{
unsigned short hashInd;
ELLLIST **ppvd = (ELLLIST **) pdbBase->ppvd;
ELLLIST *ppvdlist;
PVDENTRY *ppvdNode;
PVDENTRY *next;
if (ppvd == NULL) return;
for (hashInd=0; hashInd<(unsigned short)dbPvdHashTableSize; hashInd++) {
if(ppvd[hashInd] == NULL) continue;
ppvdlist=ppvd[hashInd];
ppvdNode = (PVDENTRY *) ellFirst(ppvdlist);
while(ppvdNode) {
next = (PVDENTRY *) ellNext((ELLNODE*)ppvdNode);
ellDelete(ppvdlist,(ELLNODE*)ppvdNode);
free((void *)ppvdNode);
ppvdNode = next;
}
free((void *)ppvd[hashInd]);
}
free((void *)ppvd);
}
void dbPvdDump(dbBase *pdbBase,int verbose)
{
unsigned short hashInd;
ELLLIST **ppvd = (ELLLIST **) pdbBase->ppvd;
ELLLIST *ppvdlist;
PVDENTRY *ppvdNode;
int number;
if (ppvd == NULL) return;
printf("Process Variable Directory\n");
printf("dbPvdHashTableSize %d dbPvdHashTableShift %d\n",
dbPvdHashTableSize,dbPvdHashTableShift);
for (hashInd=0; hashInd<(unsigned short)dbPvdHashTableSize; hashInd++) {
if(ppvd[hashInd] == NULL) continue;
ppvdlist=ppvd[hashInd];
ppvdNode = (PVDENTRY *) ellFirst(ppvdlist);
printf("\n%3.3hd=%3.3d ",hashInd,ellCount(ppvdlist));
number=0;
while(ppvdNode && verbose) {
printf(" %s",(char *)ppvdNode->precnode->recordname);
if(number++ ==2) {number=0;printf("\n ");}
ppvdNode = (PVDENTRY *) ellNext((ELLNODE*)ppvdNode);
}
}
printf("\nEnd of Process Variable Directory\n");
}

2580
src/dbStatic/dbStaticLib.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,266 @@
/*dbStaticNoRun.c*/
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
/*
* Modification Log:
* -----------------
* .01 06-JUN-95 mrk Initial Version
*/
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <math.h>
#include <dbDefs.h>
#include <dbFldTypes.h>
#include <epicsPrint.h>
#include <errMdef.h>
#include <dbStaticLib.h>
#include <dbStaticPvt.h>
long dbAllocRecord(DBENTRY *pdbentry,char *precordName)
{
dbRecDes *precdes = pdbentry->precdes;
dbRecordNode *precnode = pdbentry->precnode;
dbFldDes *pflddes;
void **papField;
int i;
char *pstr;
if(!precdes) return(S_dbLib_recdesNotFound);
if(!precnode) return(S_dbLib_recNotFound);
precnode->precord = dbCalloc(precdes->no_fields,sizeof(void *));
papField = (void **)precnode->precord;
for(i=0; i<precdes->no_fields; i++) {
pflddes = precdes->papFldDes[i];
if(!pflddes) continue;
switch(pflddes->field_type) {
case DBF_STRING:
if(pflddes->size <= 0) {
epicsPrintf("size=0 for %s.%s\n",precdes->name,pflddes->name);
pflddes->size = 1;
}
papField[i] = dbCalloc(pflddes->size,sizeof(char));
if(pflddes->initial) {
if(strlen(pflddes->initial) >= pflddes->size) {
epicsPrintf("initial size > size for %s.%s\n",
precdes->name,pflddes->name);
} else {
strcpy((char *)papField[i],pflddes->initial);
}
}
break;
case DBF_CHAR:
case DBF_UCHAR:
case DBF_SHORT:
case DBF_USHORT:
case DBF_LONG:
case DBF_ULONG:
case DBF_FLOAT:
case DBF_DOUBLE:
case DBF_ENUM:
if(pflddes->initial) {
papField[i] =
dbCalloc(strlen(pflddes->initial)+1,sizeof(char));
strcpy((char *)papField[i],pflddes->initial);
}
break;
case DBF_MENU:
case DBF_DEVICE:
papField[i] = dbCalloc(1,sizeof(unsigned short));
if(pflddes->initial) sscanf(pflddes->initial,"%hu",papField[i]);
break;
case DBF_INLINK:
case DBF_OUTLINK:
case DBF_FWDLINK: {
struct link *plink;
papField[i] = plink = dbCalloc(1,sizeof(struct link));
if(pflddes->initial) {
plink->value.constantStr =
dbCalloc(strlen(pflddes->initial)+1,sizeof(char));
strcpy(plink->value.constantStr,pflddes->initial);
}
}
break;
case DBF_NOACCESS:
break;
default:
epicsPrintf("dbAllocRecord: Illegal field type\n");
}
}
pstr = (char *)papField[0];
strcpy(pstr,precordName);
return(0);
}
long dbFreeRecord(DBENTRY *pdbentry)
{
dbRecDes *precdes = pdbentry->precdes;
dbRecordNode *precnode = pdbentry->precnode;
dbFldDes *pflddes = pdbentry->pflddes;
void **pap;
int i,field_type;
if(!precdes) return(S_dbLib_recdesNotFound);
if(!precnode) return(S_dbLib_recNotFound);
if(!precnode->precord) return(S_dbLib_recNotFound);
pap = (void **)precnode->precord;
precnode->precord = NULL;
for(i=0; i<precdes->no_fields; i++) {
pflddes = precdes->papFldDes[i];
field_type = pflddes->field_type;
if(field_type==DBF_INLINK
|| field_type==DBF_OUTLINK
|| field_type==DBF_FWDLINK) {
struct link *plink = (struct link *)pap[i];
if(plink->type== CONSTANT)
free((void *)plink->value.constantStr);
if(plink->type==PV_LINK)
free((void *)plink->value.pv_link.pvname);
}
free(pap[i]);
}
free((void *)pap);
return(0);
}
long dbGetFieldAddress(DBENTRY *pdbentry)
{
dbRecDes *precdes = pdbentry->precdes;
dbRecordNode *precnode = pdbentry->precnode;
dbFldDes *pflddes = pdbentry->pflddes;
void **pap;
if(!precdes) return(S_dbLib_recdesNotFound);
if(!precnode) return(S_dbLib_recNotFound);
if(!pflddes) return(S_dbLib_flddesNotFound);
if(!precnode->precord) return(0);
pap = (void **)precnode->precord;
pdbentry->pfield = pap[pflddes->indRecDes];
return(0);
}
char *dbRecordName(DBENTRY *pdbentry)
{
dbRecDes *precdes = pdbentry->precdes;
dbRecordNode *precnode = pdbentry->precnode;
void **pap;
if(!precdes) return(0);
if(!precnode) return(0);
if(!precnode->precord) return(0);
pap = (void **)precnode->precord;
return((char *)pap[0]);
}
int dbIsDefaultValue(DBENTRY *pdbentry)
{
dbFldDes *pflddes = pdbentry->pflddes;
void *pfield = pdbentry->pfield;
if(!pflddes) return(FALSE);
switch (pflddes->field_type) {
case DBF_STRING:
if(!pfield) return(FALSE);
if(!pflddes->initial)
return((*(char *)pfield =='\0') ? TRUE : FALSE);
return(strcmp((char *)pfield,(char *)pflddes->initial)==0);
case DBF_CHAR:
case DBF_UCHAR:
case DBF_SHORT:
case DBF_USHORT:
case DBF_LONG:
case DBF_ULONG:
case DBF_FLOAT:
case DBF_DOUBLE:
case DBF_ENUM:
if(!pfield) return(TRUE);
if(!pflddes->initial) return(FALSE);
return(strcmp((char *)pfield,(char *)pflddes->initial)==0);
case DBF_MENU:
case DBF_DEVICE: {
unsigned short val,ival;
if(!pfield) return(FALSE);
val = *(unsigned short *)pfield;
if(pflddes->initial == 0) return((val==0)?TRUE:FALSE);
sscanf(pflddes->initial,"%hu",&ival);
return((val==ival)?TRUE:FALSE);
}
case DBF_INLINK:
case DBF_OUTLINK:
case DBF_FWDLINK: {
struct link *plink = (struct link *)pfield;
if(!plink) return(FALSE);
if(plink->type!=CONSTANT) return(FALSE);
if(plink->value.constantStr == 0) return(TRUE);
if(strcmp(plink->value.constantStr,pflddes->initial)==0)
return(TRUE);
return(FALSE);
}
}
return(FALSE);
}
char *dbGetStringNum(DBENTRY *pdbentry)
{
dbRecordNode *precnode = pdbentry->precnode;
dbFldDes *pflddes = pdbentry->pflddes;
void *pfield = pdbentry->pfield;
void **pap;
static char zero[] = "0";
if(!precnode) return(0);
if(!precnode->precord) return(0);
if(!pflddes) return(0);
pap = (void **)precnode->precord;
if(!pfield) return(zero);
return((char *)pap[pflddes->indRecDes]);
}
long dbPutStringNum(DBENTRY *pdbentry,char *pstring)
{
dbRecordNode *precnode = pdbentry->precnode;
dbFldDes *pflddes = pdbentry->pflddes;
char *pfield = (char *)pdbentry->pfield;
void **pap;
if(!precnode) return(S_dbLib_recNotFound);
if(!precnode->precord) return(S_dbLib_recNotFound);
if(!pflddes) return(S_dbLib_flddesNotFound);
if(pfield) {
if(strlen(pfield) < strlen(pstring)) {
free((void *)pfield);
pfield = NULL;
}
}
if(!pfield) {
pfield = dbCalloc(strlen(pstring)+1,sizeof(char));
strcpy(pfield,pstring);
pdbentry->pfield = pfield;
pap = (void **)precnode->precord;
pap[pflddes->indRecDes] = pfield;
}
strcpy(pfield,pstring);
return(0);
}
void dbGetRecordtypeSizeOffset(dbRecDes *pdbRecDes)
{
/*For no run cant and dont need to set size and offset*/
return;
}

View File

@@ -0,0 +1,64 @@
/* dbStaticPvt.h */
/*
* Author: Marty Kraimer
* Date: 06Jun95
*
* 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 06JUN95 mrk Initial version
*/
#ifndef INCdbStaticPvth
#define INCdbStaticPvth 1
/*Following are not intended for client code */
void dbInitDeviceMenu(DBENTRY *pdbentry);
/*The following routines have different versions for run-time no-run-time*/
long dbAllocRecord(DBENTRY *pdbentry,char *precordName);
long dbFreeRecord(DBENTRY *pdbentry);
long dbGetFieldAddress(DBENTRY *pdbentry);
char *dbRecordName(DBENTRY *pdbentry);
char *dbGetStringNum(DBENTRY *pdbentry);
long dbPutStringNum(DBENTRY *pdbentry,char *pstring);
void dbGetRecordtypeSizeOffset(dbRecDes *pdbRecDes);
/*The following are in dbPvdLib.c*/
/*directory*/
typedef struct{
ELLNODE node;
dbRecDes *precdes;
dbRecordNode *precnode;
}PVDENTRY;
int dbPvdTableSize(DBBASE *pdbBase,int size);
void dbPvdInitPvt(DBBASE *pdbBase);
PVDENTRY *dbPvdFind(DBBASE *pdbBase,char *name,int lenname);
PVDENTRY *dbPvdAdd(DBBASE *pdbBase,dbRecDes *precdes,dbRecordNode *precnode);
void dbPvdDelete(DBBASE *pdbBase,dbRecordNode *precnode);
void dbPvdFreeMem(DBBASE *pdbBase);
void dbPvdDump(DBBASE *pdbBase,int verbose);
#endif /*INCdbStaticPvth*/

591
src/dbStatic/dbStaticRun.c Normal file
View File

@@ -0,0 +1,591 @@
/*dbStaticLibRun.c*/
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
/* Modification Log:
* -----------------
* .01 06-12-95 mrk Initial
*/
#ifdef vxWorks
#include <vxWorks.h>
#include <taskLib.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <math.h>
#include <symLib.h>
#include <sysSymTbl.h> /* for sysSymTbl*/
#include <dbDefs.h>
#include <errMdef.h>
#include <epicsPrint.h>
#include <ellLib.h>
#include <dbDefs.h>
#include <cvtFast.h>
#include <dbStaticLib.h>
#include <dbStaticPvt.h>
#include <devSup.h>
#include <drvSup.h>
#include <recSup.h>
#include <cvtTable.h>
#include <special.h>
static char hex_digit_to_ascii[16]={'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f'};
static void ulongToHexString(unsigned long source,char *pdest)
{
unsigned long val,temp;
char digit[10];
int i,j;
if(source==0) {
strcpy(pdest,"0x0");
return;
}
*pdest++ = '0'; *pdest++ = 'x';
val = source;
for(i=0; val!=0; i++) {
temp = val/16;
digit[i] = hex_digit_to_ascii[val - temp*16];
val = temp;
}
for(j=i-1; j>=0; j--) {
*pdest++ = digit[j];
}
*pdest = 0;
return;
}
static double delta[2]={1e-6,1e-15};
static int precision[2]={6,14};
static void realToString(double value,char *preturn,int isdouble)
{
long intval;
double diff,absvalue;
int logval,prec,end;
char tstr[30];
char *ptstr=&tstr[0];
int round;
int ise=FALSE;
char *loce=NULL;
if(value==0.0) {strcpy(preturn,"0"); return;};
intval=value;
diff = value - intval;
if(diff<0.0) diff =-diff;
absvalue = (value<0.0? -value: value);
if(diff < absvalue*delta[isdouble]) {
cvtLongToString(intval,preturn);
return;
}
/*Now starts the hard cases*/
if(value<0.0) {*preturn++ = '-'; value = -value;}
logval = (int)log10(value);
if(logval>6 || logval<-2 ) {
ise=TRUE;
prec = precision[isdouble];
sprintf(ptstr,"%.*e",prec,value);
loce = strchr(ptstr,'e');
if(!loce) {errMessage(-1,"logic error in real to string"); return;}
*loce++ = 0;
} else {
prec = precision[isdouble]-logval;
if(prec<0)prec=0;
sprintf(ptstr,"%.*f",prec,value);
}
if(prec>0) {
end = strlen(ptstr) -1;
round=FALSE;
while(TRUE) {
if(end<=0)break;
if(tstr[end]=='.'){end--; break;}
if(tstr[end]=='0'){end--; continue;}
if(!round && end<precision[isdouble]) break;
if(!round && tstr[end]<'8') break;
if(tstr[end-1]=='.') {
if(round)end = end-2;
break;
}
if(tstr[end-1]!='9') break;
round=TRUE;
end--;
}
tstr[end+1]=0;
while (round) {
if(tstr[end]<'9') {tstr[end]++; break;}
if(end==0) { *preturn++='1'; tstr[end]='0'; break;}
tstr[end--]='0';
}
}
strcpy(preturn,&tstr[0]);
if(ise) {
if(!(strchr(preturn,'.'))) strcat(preturn,".0");
strcat(preturn,"e");
strcat(preturn,loce);
}
return;
}
static void floatToString(float value,char *preturn)
{
realToString((double)value,preturn,0);
return;
}
static void doubleToString(double value,char *preturn)
{
realToString(value,preturn,1);
return;
}
long dbAllocRecord(DBENTRY *pdbentry,char *precordName)
{
dbRecDes *precdes = pdbentry->precdes;
dbRecordNode *precnode = pdbentry->precnode;
dbFldDes *pflddes;
int i;
char *precord;
char *pfield;
if(!precdes) return(S_dbLib_recdesNotFound);
if(!precnode) return(S_dbLib_recNotFound);
precnode->precord = dbCalloc(1,precdes->rec_size);
precord = (char *)precnode->precord;
if(precdes->rec_size == 0) {
epicsPrintf("dbAllocRecord(%s) record_size =0\n",
precdes->name);
return(S_dbLib_noRecSup);
}
pflddes = precdes->papFldDes[0];
if(!pflddes) {
epicsPrintf("dbAllocRecord pflddes for NAME not found\n");
return(S_dbLib_flddesNotFound);
}
if(strlen(precordName)>=pflddes->size) {
epicsPrintf("dbAllocRecord: NAME(%s) too long\n",precordName);
return(S_dbLib_nameLength);
}
pfield = precord + pflddes->offset;
strcpy(pfield,precordName);
for(i=1; i<precdes->no_fields; i++) {
pflddes = precdes->papFldDes[i];
if(!pflddes) continue;
pfield = precord + pflddes->offset;
pdbentry->pfield = (void *)pfield;
pdbentry->pflddes = pflddes;
pdbentry->indfield = i;
switch(pflddes->field_type) {
case DBF_STRING:
if(pflddes->initial) {
if(strlen(pflddes->initial) >= pflddes->size) {
epicsPrintf("initial size > size for %s.%s\n",
precdes->name,pflddes->name);
} else {
strcpy(pfield,pflddes->initial);
}
}
break;
case DBF_CHAR:
case DBF_UCHAR:
case DBF_SHORT:
case DBF_USHORT:
case DBF_LONG:
case DBF_ULONG:
case DBF_FLOAT:
case DBF_DOUBLE:
case DBF_ENUM:
case DBF_DEVICE:
if(!pflddes->ftPvt) dbInitDeviceMenu(pdbentry);
case DBF_MENU:
if(pflddes->initial) {
long status;
status = dbPutStringNum(pdbentry,pflddes->initial);
if(status)
epicsPrintf("Error initializing %s.%s initial %s\n",
precdes->name,pflddes->name,pflddes->initial);
}
break;
case DBF_INLINK:
case DBF_OUTLINK:
case DBF_FWDLINK: {
DBLINK *plink = (DBLINK *)pfield;
if(pflddes->initial) {
plink->value.constantStr =
dbCalloc(strlen(pflddes->initial)+1,sizeof(char));
strcpy(plink->value.constantStr,pflddes->initial);
}
}
break;
case DBF_NOACCESS:
break;
default:
epicsPrintf("dbAllocRecord: Illegal field type\n");
}
}
return(0);
}
long dbFreeRecord(DBENTRY *pdbentry)
{
dbRecDes *precdes = pdbentry->precdes;
dbRecordNode *precnode = pdbentry->precnode;
if(!precdes) return(S_dbLib_recdesNotFound);
if(!precnode) return(S_dbLib_recNotFound);
if(!precnode->precord) return(S_dbLib_recNotFound);
free(precnode->precord);
precnode->precord = NULL;
return(0);
}
long dbGetFieldAddress(DBENTRY *pdbentry)
{
dbRecDes *precdes = pdbentry->precdes;
dbRecordNode *precnode = pdbentry->precnode;
dbFldDes *pflddes = pdbentry->pflddes;
if(!precdes) return(S_dbLib_recdesNotFound);
if(!precnode) return(S_dbLib_recNotFound);
if(!pflddes) return(S_dbLib_flddesNotFound);
if(!precnode->precord) return(0);
pdbentry->pfield = ((char *)precnode->precord) + pflddes->offset;
return(0);
}
char *dbRecordName(DBENTRY *pdbentry)
{
dbRecDes *precdes = pdbentry->precdes;
dbRecordNode *precnode = pdbentry->precnode;
dbFldDes *pflddes;
char *precord;
if(!precdes) return(0);
if(!precnode) return(0);
if(!precnode->precord) return(0);
precord = (char *)precnode->precord;
pflddes = precdes->papFldDes[0];
if(!pflddes) return(NULL);
return(precord + pflddes->offset);
}
int dbIsDefaultValue(DBENTRY *pdbentry)
{
dbFldDes *pflddes = pdbentry->pflddes;
void *pfield = pdbentry->pfield;
if(!pflddes) return(FALSE);
if(!pfield) return(FALSE);
switch (pflddes->field_type) {
case (DBF_STRING) : {
char *p = (char *)pfield;
if(!pflddes->initial) return((strlen(p)==0) ? TRUE : FALSE);
return((strcmp(pflddes->initial,p)==0) ? TRUE : FALSE);
}
case DBF_CHAR: {
char field = *(char *)pfield;
long ltemp;
if(pflddes->initial) {
ltemp = strtol(pflddes->initial,NULL,0);
return((field==ltemp));
}
return((field==0));
}
case DBF_UCHAR: {
unsigned char field = *(unsigned char *)pfield;
unsigned long ltemp;
if(pflddes->initial) {
ltemp = strtoul(pflddes->initial,NULL,0);
return((field==ltemp));
}
return((field==0));
}
case DBF_SHORT: {
short field = *(short *)pfield;
long ltemp;
if(pflddes->initial) {
ltemp = strtol(pflddes->initial,NULL,0);
return((field==ltemp));
}
return((field==0));
}
case DBF_USHORT: {
unsigned short field = *(unsigned short *)pfield;
unsigned long ltemp;
if(pflddes->initial) {
ltemp = strtoul(pflddes->initial,NULL,0);
return((field==ltemp));
}
return((field==0));
}
case DBF_LONG: {
long field = *(long *)pfield;
long ltemp;
if(pflddes->initial) {
ltemp = strtol(pflddes->initial,NULL,0);
return((field==ltemp));
}
return((field==0));
}
case DBF_ULONG: {
unsigned long field = *(unsigned long *)pfield;
unsigned long ltemp;
if(pflddes->initial) {
ltemp = strtoul(pflddes->initial,NULL,0);
return((field==ltemp));
}
return((field==0));
}
case DBF_FLOAT: {
float field = *(float *)pfield;
double dtemp;
if(pflddes->initial) {
dtemp = strtod(pflddes->initial,NULL);
return((field==dtemp));
}
return((field==0.0));
}
case DBF_DOUBLE: {
double field = *(double *)pfield;
double dtemp;
if(pflddes->initial) {
dtemp = strtod(pflddes->initial,NULL);
return((field==dtemp));
}
return((field==0.0));
}
case DBF_ENUM:
case DBF_MENU:
case DBF_DEVICE: {
unsigned short field = *(unsigned short *)pfield;
unsigned long ltemp;
if(pflddes->initial) {
ltemp = strtoul(pflddes->initial,NULL,0);
return((field==ltemp));
}
return((field==0));
}
case DBF_INLINK:
case DBF_OUTLINK:
case DBF_FWDLINK:
return(TRUE); /*Dont know what to do with this!!*/
default:
return(TRUE);
}
return(FALSE);
}
char *dbGetStringNum(DBENTRY *pdbentry)
{
dbFldDes *pflddes = pdbentry->pflddes;
void *pfield = pdbentry->pfield;
char *message;
unsigned char cvttype;
if(!pdbentry->message) pdbentry->message = dbCalloc(1,50);
message = pdbentry->message;
cvttype = pflddes->base;
switch (pflddes->field_type) {
case DBF_CHAR:
if(cvttype==CT_DECIMAL)
cvtCharToString(*(char*)pfield, message);
else
ulongToHexString((unsigned long)(*(char*)pfield),message);
break;
case DBF_UCHAR:
if(cvttype==CT_DECIMAL)
cvtUcharToString(*(unsigned char*)pfield, message);
else
ulongToHexString((unsigned long)(*(unsigned char*)pfield),message);
break;
case DBF_SHORT:
if(cvttype==CT_DECIMAL)
cvtShortToString(*(short*)pfield, message);
else
ulongToHexString((unsigned long)(*(short*)pfield),message);
break;
case DBF_USHORT:
case DBF_ENUM:
if(cvttype==CT_DECIMAL)
cvtUshortToString(*(unsigned short*)pfield, message);
else
ulongToHexString((unsigned long)(*(unsigned short*)pfield),message);
break;
case DBF_LONG:
if(cvttype==CT_DECIMAL)
cvtLongToString(*(long*)pfield, message);
else
ulongToHexString((unsigned long)(*(long*)pfield), message);
break;
case DBF_ULONG:
if(cvttype==CT_DECIMAL)
cvtUlongToString(*(unsigned long *)pfield, message);
else
ulongToHexString(*(unsigned long*)pfield, message);
break;
case DBF_FLOAT:
floatToString(*(float *)pfield,message);
break;
case DBF_DOUBLE:
doubleToString(*(double *)pfield,message);
break;
default:
return(NULL);
}
return (message);
}
long dbPutStringNum(DBENTRY *pdbentry,char *pstring)
{
dbFldDes *pflddes = pdbentry->pflddes;
void *pfield = pdbentry->pfield;
long status=0;
switch (pflddes->field_type) {
case DBF_CHAR :
case DBF_SHORT :
case DBF_LONG:{
long value;
char *endp;
value = strtol(pstring,&endp,0);
if(*endp!=0) status = S_dbLib_badField;
switch (pflddes->field_type) {
case DBF_CHAR : *(char *)pfield = value; break;
case DBF_SHORT : *(short *)pfield = value; break;
case DBF_LONG : *(long *)pfield = value; break;
default: epicsPrintf("Logic error in dbPutStringNum\n");
}
}
break;
case DBF_UCHAR:
case DBF_USHORT:
case DBF_ULONG:
case DBF_ENUM:{
unsigned long value;
char *endp;
value = strtoul(pstring,&endp,0);
if(*endp!=0) status = S_dbLib_badField;
switch (pflddes->field_type) {
case DBF_UCHAR : *(unsigned char *)pfield = value; break;
case DBF_USHORT:
case DBF_ENUM: *(unsigned short *)pfield=value; break;
case DBF_ULONG : *(unsigned long *)pfield = value; break;
default: epicsPrintf("Logic error in dbPutStringNum\n");
}
}
break;
case DBF_FLOAT:
case DBF_DOUBLE: {
double value;
char *endp;
value = strtod(pstring,&endp);
if(*endp!=0) status = S_dbLib_badField;
if(pflddes->field_type==DBF_FLOAT)
*(float *)pfield = value;
else
*(double *)pfield = value;
}
break;
case DBF_MENU: {
dbMenu *pdbMenu = (dbMenu *)pflddes->ftPvt;
char **papChoiceValue;
char *pchoice;
unsigned short *field= (unsigned short*)pfield;
unsigned int nChoice,ind;
int nargs,nchars;
if( pdbMenu && (papChoiceValue = pdbMenu->papChoiceValue)) {
nChoice = pdbMenu->nChoice;
for(ind=0; ind<nChoice; ind++) {
if(!(pchoice=papChoiceValue[ind])) continue;
if(strcmp(pchoice,pstring)==0) {
*field = ind;
return(0);
}
}
nargs = sscanf(pstring," %u %n",&ind,&nchars);
if(nargs==1 && nchars==strlen(pstring) && ind<nChoice) {
*field = ind;
return(0);
}
}
}
return (S_dbLib_badField);
case DBF_DEVICE: {
dbDeviceMenu *pdbDeviceMenu=(dbDeviceMenu *)pflddes->ftPvt;
char **papChoice;
char *pchoice;
unsigned short *field= (unsigned short*)pfield;
unsigned int nChoice,ind;
int nargs,nchars;
if( pdbDeviceMenu && (papChoice = pdbDeviceMenu->papChoice)) {
nChoice = pdbDeviceMenu->nChoice;
for(ind=0; ind<nChoice; ind++) {
if(!(pchoice=papChoice[ind])) continue;
if(strcmp(pchoice,pstring)==0) {
*field = ind;
return(0);
}
}
nargs = sscanf(pstring," %u %n",&ind,&nchars);
if(nargs==1 && nchars==strlen(pstring) && ind<nChoice) {
*field = ind;
return(0);
}
}
}
return (S_dbLib_badField);
default:
return (S_dbLib_badField);
}
return(status);
}
void dbGetRecordtypeSizeOffset(dbRecDes *pdbRecDes)
{
char name[60];
SYM_TYPE type;
STATUS vxstatus;
long status;
int (*sizeOffset)(dbRecDes *pdbRecDes);
strcpy(name,"_");
strcat(name,pdbRecDes->name);
strcat(name,"RecordSizeOffset");
vxstatus = symFindByName(sysSymTbl, name,
(void *)&sizeOffset, &type);
if (vxstatus != OK) {
status = S_rec_noSizeOffset;
errPrintf(status,__FILE__,__LINE__,"%s",pdbRecDes->name);
return;
}
sizeOffset(pdbRecDes);
}

View File

@@ -84,8 +84,8 @@ static long init_record(pai)
/* ai.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pai->inp.type) {
case (CONSTANT) :
pai->val = pai->inp.value.value;
pai->udf = FALSE;
if(recGblInitConstantLink(&pai->inp,DBF_DOUBLE,&pai->val))
pai->udf = FALSE;
break;
case (PV_LINK) :

View File

@@ -85,7 +85,7 @@ static long init_record(pai)
/* ai.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pai->inp.type) {
case (CONSTANT) :
pai->rval = pai->inp.value.value;
recGblInitConstantLink(&pai->inp,DBF_LONG,&pai->rval);
break;
case (PV_LINK) :
case (DB_LINK) :

View File

@@ -108,8 +108,8 @@ static long init_record(pai)
callbackSetCallback(myCallback,&pcallback->callback);
pcallback->precord = (struct dbCommon *)pai;
pcallback->wd_id = wdCreate();
pai->val = pai->inp.value.value;
pai->udf = FALSE;
if(recGblInitConstantLink(&pai->inp,DBF_DOUBLE,&pai->val))
pai->udf = FALSE;
break;
default :
recGblRecordError(S_db_badField,(void *)pai,

View File

@@ -81,8 +81,8 @@ static long init_record(pbi)
/* bi.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK */
switch (pbi->inp.type) {
case (CONSTANT) :
pbi->val = pbi->inp.value.value;
pbi->udf = FALSE;
if(recGblInitConstantLink(&pbi->inp,DBF_ENUM,&pbi->val))
pbi->udf = FALSE;
break;
case (DB_LINK) :
case (PV_LINK) :

View File

@@ -82,7 +82,7 @@ static long init_record(pbi)
/* bi.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pbi->inp.type) {
case (CONSTANT) :
pbi->rval = pbi->inp.value.value;
recGblInitConstantLink(&pbi->inp,DBF_ULONG,&pbi->rval);
break;
case (DB_LINK) :
case (PV_LINK) :

View File

@@ -110,8 +110,8 @@ static long init_record(pbi)
callbackSetCallback(myCallback,&pcallback->callback);
pcallback->precord = (struct dbCommon *)pbi;
pcallback->wd_id = wdCreate();
pbi->val = pbi->inp.value.value;
pbi->udf = FALSE;
if(recGblInitConstantLink(&pbi->inp,DBF_ENUM,&pbi->val))
pbi->udf = FALSE;
break;
default :
recGblRecordError(S_db_badField,(void *)pbi,

View File

@@ -79,10 +79,8 @@ static long init_record(pevent)
/* event.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pevent->inp.type) {
case (CONSTANT) :
if(pevent->inp.value.value!=0.0 && pevent->val == 0.0){
pevent->val=pevent->inp.value.value;
}
pevent->udf= FALSE;
if(recGblInitConstantLink(&pevent->inp,DBF_USHORT,&pevent->val))
pevent->udf = FALSE;
break;
case (PV_LINK) :
status = dbCaAddInlink(&(pevent->inp), (void *) pevent, "VAL");

View File

@@ -80,7 +80,7 @@ static long init_record(phistogram)
/* histogram.svl must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (phistogram->svl.type) {
case (CONSTANT) :
phistogram->sgnl = phistogram->svl.value.value;
recGblInitConstantLink(&phistogram->svl,DBF_DOUBLE,&phistogram->sgnl);
break;
case (PV_LINK) :
case (DB_LINK) :

View File

@@ -107,7 +107,7 @@ static long init_record(phistogram)
callbackSetCallback(myCallback,&pcallback->callback);
pcallback->precord = (struct dbCommon *)phistogram;
pcallback->wd_id = wdCreate();
phistogram->sgnl = phistogram->svl.value.value;
recGblInitConstantLink(&phistogram->svl,DBF_DOUBLE,&phistogram->sgnl);
break;
default :
recGblRecordError(S_db_badField,(void *)phistogram,

View File

@@ -78,8 +78,8 @@ static long init_record(plongin)
/* longin.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (plongin->inp.type) {
case (CONSTANT) :
plongin->val = plongin->inp.value.value;
plongin->udf = FALSE;
if(recGblInitConstantLink(&plongin->inp,DBF_LONG,&plongin->val))
plongin->udf = FALSE;
break;
case (PV_LINK) :
case (DB_LINK) :

View File

@@ -81,8 +81,8 @@ static long init_record(pmbbi)
/* mbbi.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pmbbi->inp.type) {
case (CONSTANT) :
pmbbi->val = pmbbi->inp.value.value;
pmbbi->udf = FALSE;
if(recGblInitConstantLink(&pmbbi->inp,DBF_ENUM,&pmbbi->val))
pmbbi->udf = FALSE;
break;
case (DB_LINK) :
case (PV_LINK) :

View File

@@ -80,7 +80,7 @@ static long init_record(pmbbi)
/* mbbi.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pmbbi->inp.type) {
case (CONSTANT) :
pmbbi->rval = pmbbi->inp.value.value;
recGblInitConstantLink(&pmbbi->inp,DBF_ULONG,&pmbbi->rval);
break;
case (DB_LINK) :
case (PV_LINK) :

View File

@@ -80,8 +80,8 @@ static long init_record(pmbbi)
long status;
if (pmbbi->inp.type == CONSTANT) {
pmbbi->val = pmbbi->inp.value.value;
pmbbi->udf = FALSE;
if(recGblInitConstantLink(&pmbbi->inp,DBF_ENUM,&pmbbi->val))
pmbbi->udf = FALSE;
}
else {
status = recGblInitFastInLink(&(pmbbi->inp), (void *) pmbbi, DBR_USHORT, "VAL");

View File

@@ -81,7 +81,7 @@ static long init_record(pmbbi)
long status;
if (pmbbi->inp.type == CONSTANT) {
pmbbi->rval = pmbbi->inp.value.value;
recGblInitConstantLink(&pmbbi->inp,DBF_ULONG,&pmbbi->rval);
}
else {
status = recGblInitFastInLink(&(pmbbi->inp), (void *) pmbbi, DBR_ULONG, "RVAL");

View File

@@ -109,8 +109,8 @@ static long init_record(pmbbi)
callbackSetCallback(myCallback,&pcallback->callback);
pcallback->precord = (struct dbCommon *)pmbbi;
pcallback->wd_id = wdCreate();
pmbbi->val = pmbbi->inp.value.value;
pmbbi->udf = FALSE;
if(recGblInitConstantLink(&pmbbi->inp,DBF_ENUM,&pmbbi->val))
pmbbi->udf = FALSE;
break;
default :
recGblRecordError(S_db_badField,(void *)pmbbi,

View File

@@ -53,6 +53,9 @@
*****************************************************************
*
* $Log$
* Revision 1.2 1995/04/05 14:13:43 winans
* Only do a sysIntEnable() for those cards that are found with the probe.
*
* Revision 1.1 1995/03/31 15:03:32 winans
* Machine protection system interface card
*
@@ -151,6 +154,7 @@
#include "devSup.h"
#include "link.h"
#include "dbCommon.h"
#include "aiRecord.h"
#include "boRecord.h"
#include "biRecord.h"

View File

@@ -57,7 +57,6 @@
#include <iv.h>
#include <alarm.h>
#include <dbRecType.h>
#include <dbDefs.h>
#include <dbAccess.h>
#include <dbCommon.h>

View File

@@ -79,11 +79,8 @@ static long init_record(pstringin)
/* stringin.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pstringin->inp.type) {
case (CONSTANT) :
if(pstringin->inp.value.value!=0.0){
sprintf(pstringin->val,"%-14.7g",pstringin->inp.value.value);
pstringin->udf= FALSE;
}
pstringin->udf= FALSE;
if(recGblInitConstantLink(&pstringin->inp,DBF_STRING,pstringin->val))
pstringin->udf = FALSE;
break;
case (PV_LINK) :
status = dbCaAddInlink(&(pstringin->inp), (void *) pstringin, "VAL");

View File

@@ -108,10 +108,8 @@ static long init_record(pstringin)
callbackSetCallback(myCallback,&pcallback->callback);
pcallback->precord = (struct dbCommon *)pstringin;
pcallback->wd_id = wdCreate();
if (pstringin->inp.value.value!=0.0) {
sprintf(pstringin->val,"%-14.7g",pstringin->inp.value.value);
pstringin->udf = FALSE;
}
if(recGblInitConstantLink(&pstringin->inp,DBF_STRING,pstringin->val))
pstringin->udf = FALSE;
break;
default :
recGblRecordError(S_db_badField,(void *)pstringin,

View File

@@ -58,6 +58,9 @@
* ...
*
* $Log$
* Revision 1.9 1995/01/18 16:38:03 winans
* added the '0x' in front of the hex input and outputs in the report function.
*
* Revision 1.8 1995/01/09 20:52:02 winans
* Added analog input support for temperature
*
@@ -95,6 +98,7 @@
#include <link.h>
#include <fast_lock.h>
#include <dbCommon.h>
#include <aiRecord.h>
#include <boRecord.h>
#include <biRecord.h>

View File

@@ -39,7 +39,6 @@
#include <iv.h>
#include <alarm.h>
#include <dbRecType.h>
#include <dbDefs.h>
#include <dbAccess.h>
#include <dbCommon.h>

View File

@@ -79,7 +79,6 @@
#include <drvEpvxi.h>
#include <alarm.h>
#include <dbRecType.h>
#include <dbDefs.h>
#include <dbAccess.h>
#include <dbCommon.h>

View File

@@ -5,12 +5,9 @@
/* common to epics Unix and vxWorks */
#include "dbAccess.h"
#include "asLib.h"
#include "sdrHeader.h"
#include "drvSup.h"
#include "devSup.h"
#include "recSup.h"
#include "dbRecType.h"
#include "dbRecords.h"
#include "tsDefs.h"
#include "drvGpibErr.h"
#include "drvBitBusErr.h"

View File

@@ -53,6 +53,7 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
#ifdef vxWorks
#include <vxWorks.h>
#include <fast_lock.h>
#endif
#include <string.h>
@@ -60,6 +61,20 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
#include <stddef.h>
#include <freeList.h>
typedef struct allocMem {
struct allocMem *next;
void *memory;
}allocMem;
typedef struct {
int size;
int nmalloc;
void *head;
allocMem *mallochead;
#ifdef vxWorks
FAST_LOCK lock;
#endif
}FREELISTPVT;
void freeListInitPvt(void **ppvt,int size,int nmalloc)
{
FREELISTPVT *pfl;
@@ -74,6 +89,7 @@ void freeListInitPvt(void **ppvt,int size,int nmalloc)
pfl->size = size;
pfl->nmalloc = nmalloc;
pfl->head = NULL;
pfl->mallochead = NULL;
#ifdef vxWorks
FASTLOCKINIT(&pfl->lock);
#endif
@@ -96,6 +112,7 @@ void *freeListMalloc(void *pvt)
FREELISTPVT *pfl = pvt;
void *ptemp;
void **ppnext;
allocMem *pallocmem;
int i;
#ifdef vxWorks
@@ -103,13 +120,18 @@ void *freeListMalloc(void *pvt)
#endif
ptemp = pfl->head;
if(!ptemp) {
ptemp = (void *)malloc(pfl->nmalloc*pfl->size);
if(!ptemp) {
ptemp = (void *)malloc((pfl->nmalloc*pfl->size)+sizeof(void *));
pallocmem = (allocMem *)calloc(1,sizeof(allocMem));
if(!ptemp || !pallocmem) {
#ifdef vxWorks
FASTUNLOCK(&pfl->lock);
#endif
return(ptemp);
}
pallocmem->memory = ptemp;
if(pfl->mallochead)
pallocmem->next = pfl->mallochead;
pfl->mallochead = pallocmem;
for(i=0; i<pfl->nmalloc; i++) {
ppnext = ptemp;
*ppnext = pfl->head;
@@ -141,3 +163,19 @@ void freeListFree(void *pvt,void*pmem)
FASTUNLOCK(&pfl->lock);
#endif
}
void freeListCleanup(void *pvt)
{
FREELISTPVT *pfl = pvt;
allocMem *phead;
allocMem *pnext;
phead = pfl->mallochead;
while(phead) {
pnext = phead->next;
free(phead->memory);
free(phead);
phead = pnext;
}
free(pvt);
}

View File

@@ -53,6 +53,7 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
#ifdef vxWorks
#include <vxWorks.h>
#include <fast_lock.h>
#endif
#include <string.h>
@@ -60,6 +61,20 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
#include <stddef.h>
#include <freeList.h>
typedef struct allocMem {
struct allocMem *next;
void *memory;
}allocMem;
typedef struct {
int size;
int nmalloc;
void *head;
allocMem *mallochead;
#ifdef vxWorks
FAST_LOCK lock;
#endif
}FREELISTPVT;
void freeListInitPvt(void **ppvt,int size,int nmalloc)
{
FREELISTPVT *pfl;
@@ -74,6 +89,7 @@ void freeListInitPvt(void **ppvt,int size,int nmalloc)
pfl->size = size;
pfl->nmalloc = nmalloc;
pfl->head = NULL;
pfl->mallochead = NULL;
#ifdef vxWorks
FASTLOCKINIT(&pfl->lock);
#endif
@@ -96,6 +112,7 @@ void *freeListMalloc(void *pvt)
FREELISTPVT *pfl = pvt;
void *ptemp;
void **ppnext;
allocMem *pallocmem;
int i;
#ifdef vxWorks
@@ -103,13 +120,18 @@ void *freeListMalloc(void *pvt)
#endif
ptemp = pfl->head;
if(!ptemp) {
ptemp = (void *)malloc(pfl->nmalloc*pfl->size);
if(!ptemp) {
ptemp = (void *)malloc((pfl->nmalloc*pfl->size)+sizeof(void *));
pallocmem = (allocMem *)calloc(1,sizeof(allocMem));
if(!ptemp || !pallocmem) {
#ifdef vxWorks
FASTUNLOCK(&pfl->lock);
#endif
return(ptemp);
}
pallocmem->memory = ptemp;
if(pfl->mallochead)
pallocmem->next = pfl->mallochead;
pfl->mallochead = pallocmem;
for(i=0; i<pfl->nmalloc; i++) {
ppnext = ptemp;
*ppnext = pfl->head;
@@ -141,3 +163,19 @@ void freeListFree(void *pvt,void*pmem)
FASTUNLOCK(&pfl->lock);
#endif
}
void freeListCleanup(void *pvt)
{
FREELISTPVT *pfl = pvt;
allocMem *phead;
allocMem *pnext;
phead = pfl->mallochead;
while(phead) {
pnext = phead->next;
free(phead->memory);
free(phead);
phead = pnext;
}
free(pvt);
}

View File

@@ -62,10 +62,11 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
#include <stddef.h>
#include <gpHash.h>
#include <ellLib.h>
#include <epicsPrint.h>
/*Algorithm depends on HASH_NO=256*/
#define HASH_NO 256 /*DO NOT CHANGE: number of hash table entries */
static int tableSize=0;
static int nShift=0;
#ifdef vxWorks
static FAST_LOCK lock;
#endif
@@ -75,7 +76,7 @@ static FAST_LOCK lock;
/* Fast Hashing of Variable Length Text Strings, Peter K. Pearson, */
/* Communications of the ACM, June 1990 */
static unsigned char T0[256] = {
static unsigned char T[256] = {
39,159,180,252, 71, 6, 13,164,232, 35,226,155, 98,120,154, 69,
157, 24,137, 29,147, 78,121, 85,112, 8,248,130, 55,117,190,160,
176,131,228, 64,211,106, 38, 27,140, 30, 88,210,227,104, 84, 77,
@@ -93,6 +94,9 @@ static unsigned char T0[256] = {
111,141,191,103, 74,245,223, 20,161,235,122, 63, 89,149, 73,238,
134, 68, 93,183,241, 81,196, 49,192, 65,212, 94,203, 10,200, 47
};
#define NSIZES 9
static int allowSize[NSIZES] = {256,512,1024,2048,4096,8192,16384,32768,65636};
static void *myCalloc(size_t nobj,size_t size)
{
@@ -108,21 +112,41 @@ static void *myCalloc(size_t nobj,size_t size)
return(NULL);
}
static unsigned char hash( char *pname)
static int hash( char *pname)
{
unsigned char h=0;
unsigned char h0=0;
unsigned char h1=0;
unsigned short ind0,ind1;
int even = TRUE;
unsigned char c;
while(*pname) {
h = T0[h^*pname];
c = *pname;
if(even) {h0 = T[h0^c]; even = FALSE;}
else {h1 = T[h1^c]; even = TRUE;}
pname++;
}
return(h);
ind0 = (unsigned short)h0;
ind1 = (unsigned short)h1;
return((ind1<<nShift) ^ ind0);
}
void gphInitPvt(void **pgphPvt)
void gphInitPvt(void **pgphPvt,int size)
{
ELLLIST **pgph;
pgph = myCalloc(HASH_NO, sizeof(ELLLIST *));
ELLLIST **pgph;
int i;
for(i=0; i<NSIZES; i++) {
if(size==allowSize[i]) {
tableSize = size;
nShift = i;
}
}
if(tableSize==0) {
epicsPrintf("gphInitPvt: Illegal size\n");
return;
}
pgph = myCalloc(tableSize, sizeof(ELLLIST *));
#ifdef vxWorks
FASTLOCKINIT(&lock);
#endif
@@ -132,12 +156,13 @@ void gphInitPvt(void **pgphPvt)
GPHENTRY *gphFind(void *gphPvt,char *name,void *pvtid)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *gphlist;
GPHENTRY *pgphNode;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *gphlist;
GPHENTRY *pgphNode;
hashInd = (unsigned short)hash(name);
if(tableSize==0) return(NULL);
hashInd = hash(name);
#ifdef vxWorks
FASTLOCK(&lock);
#endif
@@ -160,12 +185,13 @@ GPHENTRY *gphFind(void *gphPvt,char *name,void *pvtid)
GPHENTRY *gphAdd(void *gphPvt,char *name,void *pvtid)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
hashInd = (unsigned short)hash(name);
if(tableSize==0) return(NULL);
hashInd = hash(name);
#ifdef vxWorks
FASTLOCK(&lock);
#endif
@@ -197,12 +223,13 @@ GPHENTRY *gphAdd(void *gphPvt,char *name,void *pvtid)
void gphDelete(void *gphPvt,char *name,void *pvtid)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
hashInd = (unsigned short)hash(name);
if(tableSize==0) return;
hashInd = hash(name);
#ifdef vxWorks
FASTLOCK(&lock);
#endif
@@ -229,17 +256,17 @@ void gphDelete(void *gphPvt,char *name,void *pvtid)
void gphFreeMem(void * gphPvt)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
GPHENTRY *next;;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
GPHENTRY *next;;
if (pgph == NULL) return;
#ifdef vxWorks
FASTLOCK(&lock);
#endif
for (hashInd=0; hashInd<HASH_NO; hashInd++) {
for (hashInd=0; hashInd<tableSize; hashInd++) {
if(pgph[hashInd] == NULL) continue;
plist=pgph[hashInd];
pgphNode = (GPHENTRY *) ellFirst(plist);
@@ -259,14 +286,14 @@ void gphFreeMem(void * gphPvt)
void gphDump(void * gphPvt)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
int number;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
int number;
if (pgph == NULL) return;
for (hashInd=0; hashInd<HASH_NO; hashInd++) {
for (hashInd=0; hashInd<tableSize; hashInd++) {
if(pgph[hashInd] == NULL) continue;
plist=pgph[hashInd];
pgphNode = (GPHENTRY *) ellFirst(plist);

View File

@@ -62,10 +62,11 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
#include <stddef.h>
#include <gpHash.h>
#include <ellLib.h>
#include <epicsPrint.h>
/*Algorithm depends on HASH_NO=256*/
#define HASH_NO 256 /*DO NOT CHANGE: number of hash table entries */
static int tableSize=0;
static int nShift=0;
#ifdef vxWorks
static FAST_LOCK lock;
#endif
@@ -75,7 +76,7 @@ static FAST_LOCK lock;
/* Fast Hashing of Variable Length Text Strings, Peter K. Pearson, */
/* Communications of the ACM, June 1990 */
static unsigned char T0[256] = {
static unsigned char T[256] = {
39,159,180,252, 71, 6, 13,164,232, 35,226,155, 98,120,154, 69,
157, 24,137, 29,147, 78,121, 85,112, 8,248,130, 55,117,190,160,
176,131,228, 64,211,106, 38, 27,140, 30, 88,210,227,104, 84, 77,
@@ -93,6 +94,9 @@ static unsigned char T0[256] = {
111,141,191,103, 74,245,223, 20,161,235,122, 63, 89,149, 73,238,
134, 68, 93,183,241, 81,196, 49,192, 65,212, 94,203, 10,200, 47
};
#define NSIZES 9
static int allowSize[NSIZES] = {256,512,1024,2048,4096,8192,16384,32768,65636};
static void *myCalloc(size_t nobj,size_t size)
{
@@ -108,21 +112,41 @@ static void *myCalloc(size_t nobj,size_t size)
return(NULL);
}
static unsigned char hash( char *pname)
static int hash( char *pname)
{
unsigned char h=0;
unsigned char h0=0;
unsigned char h1=0;
unsigned short ind0,ind1;
int even = TRUE;
unsigned char c;
while(*pname) {
h = T0[h^*pname];
c = *pname;
if(even) {h0 = T[h0^c]; even = FALSE;}
else {h1 = T[h1^c]; even = TRUE;}
pname++;
}
return(h);
ind0 = (unsigned short)h0;
ind1 = (unsigned short)h1;
return((ind1<<nShift) ^ ind0);
}
void gphInitPvt(void **pgphPvt)
void gphInitPvt(void **pgphPvt,int size)
{
ELLLIST **pgph;
pgph = myCalloc(HASH_NO, sizeof(ELLLIST *));
ELLLIST **pgph;
int i;
for(i=0; i<NSIZES; i++) {
if(size==allowSize[i]) {
tableSize = size;
nShift = i;
}
}
if(tableSize==0) {
epicsPrintf("gphInitPvt: Illegal size\n");
return;
}
pgph = myCalloc(tableSize, sizeof(ELLLIST *));
#ifdef vxWorks
FASTLOCKINIT(&lock);
#endif
@@ -132,12 +156,13 @@ void gphInitPvt(void **pgphPvt)
GPHENTRY *gphFind(void *gphPvt,char *name,void *pvtid)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *gphlist;
GPHENTRY *pgphNode;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *gphlist;
GPHENTRY *pgphNode;
hashInd = (unsigned short)hash(name);
if(tableSize==0) return(NULL);
hashInd = hash(name);
#ifdef vxWorks
FASTLOCK(&lock);
#endif
@@ -160,12 +185,13 @@ GPHENTRY *gphFind(void *gphPvt,char *name,void *pvtid)
GPHENTRY *gphAdd(void *gphPvt,char *name,void *pvtid)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
hashInd = (unsigned short)hash(name);
if(tableSize==0) return(NULL);
hashInd = hash(name);
#ifdef vxWorks
FASTLOCK(&lock);
#endif
@@ -197,12 +223,13 @@ GPHENTRY *gphAdd(void *gphPvt,char *name,void *pvtid)
void gphDelete(void *gphPvt,char *name,void *pvtid)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
hashInd = (unsigned short)hash(name);
if(tableSize==0) return;
hashInd = hash(name);
#ifdef vxWorks
FASTLOCK(&lock);
#endif
@@ -229,17 +256,17 @@ void gphDelete(void *gphPvt,char *name,void *pvtid)
void gphFreeMem(void * gphPvt)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
GPHENTRY *next;;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
GPHENTRY *next;;
if (pgph == NULL) return;
#ifdef vxWorks
FASTLOCK(&lock);
#endif
for (hashInd=0; hashInd<HASH_NO; hashInd++) {
for (hashInd=0; hashInd<tableSize; hashInd++) {
if(pgph[hashInd] == NULL) continue;
plist=pgph[hashInd];
pgphNode = (GPHENTRY *) ellFirst(plist);
@@ -259,14 +286,14 @@ void gphFreeMem(void * gphPvt)
void gphDump(void * gphPvt)
{
unsigned short hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
int number;
int hashInd;
ELLLIST **pgph = (ELLLIST **) gphPvt;
ELLLIST *plist;
GPHENTRY *pgphNode;
int number;
if (pgph == NULL) return;
for (hashInd=0; hashInd<HASH_NO; hashInd++) {
for (hashInd=0; hashInd<tableSize; hashInd++) {
if(pgph[hashInd] == NULL) continue;
plist=pgph[hashInd];
pgphNode = (GPHENTRY *) ellFirst(plist);