// Copyright (c) 1998 Relic Entertainment Inc. // Written by Janik Joire // // $History: $ #include #include #include #include "vol.h" // Global variables FILE *pHeadFile; // Handle for header file FILE *pLookFile; // Handle for lookup file FILE *pFreqFile; // Handle for frequency file unsigned short nNumVolRs; // Number of volumes/ranges unsigned short nNumHeaders; // Number of headers unsigned short nVolRCount; // Volumes/ranges count unsigned short nHeaderCount; // Headers count long *aLookTab; // Lookup table float *aFreqTab; // Frequency table // Export functions // This function opens a lookup table file __declspec(dllexport) int __stdcall volOpenWLookup(char *szFileName,char *szID, unsigned short nNumVRs, unsigned short nNumHeads) { char *pID; // Open lookup file pLookFile=fopen(szFileName,"wb"); if(pLookFile == NULL) return(VOL_ERR_LUFILE); // Set number of volume/ranges and headers nNumVolRs=nNumVRs; nNumHeaders=nNumHeads; nHeaderCount=0; // Pad ID while(strlen(szID) < VOL_ID) strcat(szID," "); pID=szID; // Write constants fwrite(pID,sizeof(char),VOL_ID,pLookFile); fwrite(&nNumVolRs,sizeof(unsigned short),1,pLookFile); fwrite(&nNumHeaders,sizeof(unsigned short),1,pLookFile); // Allocate memory aLookTab=(long *)calloc(nNumVolRs*nNumHeaders,sizeof(long)); if(aLookTab == NULL) return(VOL_ERR_LUALLOC); return(OK); } // This function writes a patch to the lookup table file __declspec(dllexport) int __stdcall volWriteLookup(long *aLookup) { unsigned short n; // Check header count if(nHeaderCount > nNumHeaders) return(VOL_ERR_LUWRITE); // Populate lookup table for(n=0;n nNumHeaders) return(VOL_ERR_LUREAD); // Populate lookup table for(n=0;n nNumVolRs) return(VOL_ERR_LUWRITE); // Populate frequency data for(n=0;n nNumVolRs) return(VOL_ERR_LUREAD); // Populate frequency table for(n=0;n 0) strcat(*szLabels," "); strcat(*szLabels,pLabel); // Increment count (*nCount)++; } } } } } } // Close header file and return fclose(hHeadFile); return(OK); } // This function returns an error message for a matching VOL error code __declspec(dllexport) int __stdcall volGetErr(int nErr,char **szText) { char *pText; switch(nErr) { // VOL error codes case VOL_ERR_LUFILE: pText="Unable to open lookup file"; break; case VOL_ERR_LUWRITE: pText="Unable to write data to lookup table"; break; case VOL_ERR_LUREAD: pText="Unable to read data from lookup table"; break; case VOL_ERR_LUALLOC: pText="Unable to allocate memory for lookup table"; break; case VOL_ERR_LBLFILE: pText="Unable to open labels file"; break; case VOL_ERR_LBLALLOC: pText="Unable to allocate memory for labels"; break; // Default error codes case 0: pText="No error"; break; default: pText="Undefined error"; } // Allocate memory for text *szText=(char *)calloc(strlen(pText)+1,sizeof(char)); if(*szText == NULL) return(ERR); // Copy text strcpy(*szText,pText); return(OK); }