void AddReportParm(REPORT *pRep, const char *sParmName, enum PARMTYPE eType, void *pDefault) { SetString(&pRep->aParmName[pRep->iNumParms],sParmName); pRep->aParmTypes[pRep->iNumParms] = eType; switch (eType) { case TypeInt: case TypeSInt: case TypeBool: case TypeFloat: pRep->aParameters[pRep->iNumParms] = pDefault; break; case TypeString: SetString((char **) &pRep->aParameters[pRep->iNumParms],(const char *) pDefault); break; case TypeReport: case TypeRatio: break; } pRep->iNumParms++; if (pRep->iNumParms==MAXREPORTPARMS) { PrintUInt(pRepErr,"Unexpected Error: increase constant MAXREPORTPARMS [%d]\n",MAXREPORTPARMS); AbnormalExit(); } }
void ActivateReportTriggers() { UINT32 j; for (j=0;j<iNumReports;j++) { if (strcmp(aReports[j].sOutputFile,"null")==0) { aReports[j].bActive = FALSE; aReports[j].fileOut = 0; } if (aReports[j].bActive) { if (strcmp(aReports[j].sOutputFile,"stdout")==0) { aReports[j].fileOut = stdout; } else if (strcmp(aReports[j].sOutputFile,"stderr")==0) { aReports[j].fileOut = stderr; } else { if (aReports[j].bSpecialFileIO == FALSE) { aReports[j].fileOut = fopen(aReports[j].sOutputFile,"w"); if (aReports[j].fileOut == 0) { printf("Fatal Error: Invalid filename [%s] specified \n",aReports[j].sOutputFile); AbnormalExit(); } } } ActivateTriggers(aReports[j].sTriggers); } } }
void SetupReports() { unsigned int j; for (j=0;j<iNumReports;j++) { if (strcmp(aReports[j].sOutputFile,"null")==0) { /* aReports[j].bActive = 0;*/ aReports[j].fileOut = 0; } if (aReports[j].bActive) { if (strcmp(aReports[j].sOutputFile,"stdout")==0) { aReports[j].fileOut = stdout; } else if (strcmp(aReports[j].sOutputFile,"stderr")==0) { aReports[j].fileOut = stderr; } else if (strcmp(aReports[j].sOutputFile,"null")!=0) { aReports[j].fileOut = fopen(aReports[j].sOutputFile,"w"); if (aReports[j].fileOut == 0) { printf("Fatal Error: Invalid filename [%s] specified \n",aReports[j].sOutputFile); AbnormalExit(); } } ParseItemList(&listFunctions,aReports[j].sFunctions,ActivateFunction); } } }
void ParseItemList(ITEMLIST *pList, char *sItems, CALLBACKPTR ItemFunction) { char *pPos; signed int j; if (*sItems==0) return; pPos = strchr(sItems,','); if (pPos) { if (strlen(sItems) > MAXITEMLISTSTRINGLENGTH-1) { PrintUInt(pRepErr,"Unexpected Error: increase constant MAXITEMLISTSTRINGLENGTH [%d] \n",MAXITEMLISTSTRINGLENGTH); AbnormalExit(); } strcpy(sMasterString,sItems); sMasterString[pPos-sItems] = 0; pPos++; ParseItemList(pList,sMasterString,ItemFunction); ParseItemList(pList,pPos,ItemFunction); return; } j = FindItem(pList,sItems); if (pList->aItems[j].bCompound) { ParseItemList(pList,pList->aItems[j].sCompoundList,ItemFunction); } else { ItemFunction((unsigned int) j,sItems); } }
unsigned int FindItem(ITEMLIST *pList,char *sID) { unsigned int j; char *pPos; char *pPos2; unsigned int iLen; pPos = strchr(sID,'['); if (pPos) { pPos2 = strchr(sID,']'); if (pPos2) { iLen = pPos - sID; for (j=0;j<pList->iNumItems;j++) { if (strlen(pList->aItems[j].sID) == iLen) { if (strncmp(sID,pList->aItems[j].sID,iLen)==0) { return(j); } } } } else { PrintString(pRepErr,"Error: unbalanced [] in (%s)\n",sID); } } else { for (j=0;j<pList->iNumItems;j++) { if (strcmp(sID,pList->aItems[j].sID)==0) { return(j); } } } PrintString(pRepErr,"Error: reference to (%s) is unknown\n",sID); AbnormalExit(); return(0); }
void AddItem(ITEMLIST *pList,const char *sID) { SetString(&pList->aItems[pList->iNumItems].sID,sID); pList->aItems[pList->iNumItems].bCompound = 0; pList->iNumItems++; if (pList->iNumItems==MAXITEMLIST) { PrintUInt(pRepErr,"Unexpected Error: increase constant MAXITEMLIST [%d] \n",MAXITEMLIST); AbnormalExit(); } }
void SetupFile(FILE **fFil,const char *sOpenType, const char *sFilename, FILE *filDefault, BOOL bAllowNull) { if (*sFilename) { if (strcmp(sFilename,"null")==0) { if (bAllowNull) { (*fFil) = NULL; } else { fprintf(stderr,"Fatal Error: Invalid use of null i/o\n"); AbnormalExit(); } } else { (*fFil) = fopen(sFilename,sOpenType); if ((*fFil) == NULL) { printf("Fatal Error: Invalid filename [%s] specified \n",sFilename); AbnormalExit(); } } } else { (*fFil) = filDefault; } }
va_dcl #else NLM_EXTERN MsgAnswer CDECL Nlm_Message (Nlm_Int2 sevkey, const char *fmt, ...) #endif { const char *caption = GetProgramName(); MsgKey key = KEY_OK; ErrSev sev = SEV_INFO; MsgAnswer ans; if (sevkey < KEY_other) { key = (MsgKey) sevkey; } else { switch (sevkey) { case MSG_ERROR : Nlm_Beep(); sev = SEV_ERROR; break; case MSG_FATAL : Nlm_Beep(); sev = SEV_MAX; break; case MSG_POSTERR : Nlm_Beep(); sev = SEV_ERROR; key = KEY_NONE; break; case MSG_POST : key = KEY_NONE; break; } } {{ const Nlm_Char PNTR scratch_str = NULL; Nlm_Char PNTR message; TSPRINTF(scratch_str, fmt); message = Nlm_StringSave(scratch_str); ans = message ? MsgAlertStr(key, sev, caption, message) : ANS_NONE; Nlm_MemFree(message); }} if (sevkey == MSG_FATAL) AbnormalExit(1); return ans; }
static AppMsgInfo * GetAppMsgInfo (void) { AppMsgInfo *info = (AppMsgInfo*) GetAppProperty(_szPropKey); if (info == NULL) { info = (AppMsgInfo*) MemGet(sizeof(struct AppMsgInfo), TRUE); if (info == NULL) AbnormalExit(1); info->hookMessage = _DefMessageHook; info->hookBeep = _DefBeepHook; info->hookMonitor = _DefMonitorHook; SetAppProperty(_szPropKey,(void*)info); } return info; }
void *AllocateRAM( size_t size ) { UINT32 j; BOOL bFound; UINT32 iHeapID = 0; void *pReturn; size = size + (4-(size % 4)); iLastRequestSize = size; bFound = FALSE; for (j=0;j<iNumHeap;j++) { if (aHeap[j].iBytesFree >= size) { bFound = TRUE; iHeapID = j; break; } } if (!bFound) { if (size > DEFAULTHEAPSIZE) { aHeap[iNumHeap].pHeap = malloc(size); aHeap[iNumHeap].pFree = aHeap[iNumHeap].pHeap; aHeap[iNumHeap].iBytesFree = size; } else { aHeap[iNumHeap].pHeap = malloc(DEFAULTHEAPSIZE); aHeap[iNumHeap].pFree = aHeap[iNumHeap].pHeap; aHeap[iNumHeap].iBytesFree = DEFAULTHEAPSIZE; } iHeapID = iNumHeap; iNumHeap++; if (iNumHeap == MAXHEAPS) { ReportPrint1(pRepErr,"Unexpected Error: increase constant MAXHEAPS [%u]\n",MAXHEAPS); AbnormalExit(); } } pReturn = (void *) aHeap[iHeapID].pFree; aHeap[iHeapID].pFree += size; aHeap[iHeapID].iBytesFree -= size; iLastHeap = iHeapID; return(pReturn); }
void *AllocateRAM( size_t size ) { unsigned int j; unsigned int bFound = 0; unsigned int iHeapID = 0; void *pReturn; size = size + (4-(size % 4)); iLastRequestSize = size; bFound = 0; for (j=0;j<iNumHeap;j++) { if (aHeap[j].iBytesFree >= size) { bFound = 1; iHeapID = j; break; } } if (!bFound) { if (size > DEFAULTHEAPSIZE) { aHeap[iNumHeap].pHeap = (char*)malloc(size); aHeap[iNumHeap].pFree = aHeap[iNumHeap].pHeap; aHeap[iNumHeap].iBytesFree = size; } else { aHeap[iNumHeap].pHeap = (char*)malloc(DEFAULTHEAPSIZE); aHeap[iNumHeap].pFree = aHeap[iNumHeap].pHeap; aHeap[iNumHeap].iBytesFree = DEFAULTHEAPSIZE; } iHeapID = iNumHeap; iNumHeap++; if (iNumHeap == MAXHEAPS) { PrintUInt(pRepErr,"Unexpected Error: increase constant MAXHEAPS [%d]\n",MAXHEAPS); AbnormalExit(); } } pReturn = (void *) aHeap[iHeapID].pFree; aHeap[iHeapID].pFree += size; aHeap[iHeapID].iBytesFree -= size; iLastHeap = iHeapID; return(pReturn); }
REPORT *AddReport(const char *sID, const char *sDescription, const char *sOutputFile, const char *sFunctions) { REPORT *pRep; pRep = &aReports[iNumReports++]; if (iNumReports==MAXREPORTS) { PrintUInt(pRepErr,"Unexpected Error: increase constant MAXREPORTS [%d] \n",MAXREPORTS); AbnormalExit(); } SetString(&pRep->sID,sID); pRep->bActive = 0; pRep->fileOut = stdout; SetString(&pRep->sOutputFile,sOutputFile); pRep->iNumParms = 0; SetString(&pRep->sFunctions,sFunctions); SetString(&pRep->sDescription,sDescription); return (pRep); }
void VerifyStatsParms (char *sStatsParms) { unsigned int j; char *pPos; char *pPos2; unsigned int iLen; unsigned int bValid; pPos = sStatsParms; while (*pPos != 0) { bValid = 0; pPos2 = strstr(pPos,";"); if (pPos2) { iLen = pPos2 - pPos; } else { iLen = strlen(pPos); } if (iLen) { for (j=0;j<NUMVALIDSTATCODES;j++) { if (strlen(sValidStatCodes[j])==iLen) { if (strncmp(pPos,sValidStatCodes[j],iLen)==0) { bValid = 1; } } } if (bValid==0) { PrintString(pRepErr,"Error: reference to (%s) is unknown\n",pPos); AbnormalExit(); } } pPos += iLen; if (pPos2) pPos++; } }
void CreateFileRandom() { pRandomDataBuffer = AllocateRAM(RANDOMFILEBUFFERSIZE); SetupFile(&filRandomData,"rb",sFilenameRandomData,NULL,FALSE); if (filRandomData==NULL) { ReportPrint(pRepErr,"Error! Unable to read from random data file\n"); AbnormalExit(); } iRandomBufferRemaining = fread(pRandomDataBuffer,1,RANDOMFILEBUFFERSIZE,filRandomData); if ((iRandomBufferRemaining < RANDOMFILEBUFFERSIZE)||(feof(filRandomData))) { bCycleData = TRUE; iCycleDataLen = iRandomBufferRemaining; } else { bCycleData = FALSE; } pNextRandomData = pRandomDataBuffer; fxnRandUInt32 = FileRandomUInt32; }