From 0c38707542c8cf466302f7f1ed2d37cfe6911453 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Thu, 12 May 2022 09:55:38 -0400 Subject: [PATCH] A number of other corrections around CalmaFullDump, which had mistakenly recast the input file routines from zlib back to stdio; only the output file routines should have been changed. --- calma/CalmaWrite.c | 32 ++++++++++++++++---------------- calma/calma.h | 4 ++++ calma/calmaInt.h | 1 + 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/calma/CalmaWrite.c b/calma/CalmaWrite.c index f6ed9b8c..d7a570de 100644 --- a/calma/CalmaWrite.c +++ b/calma/CalmaWrite.c @@ -588,14 +588,14 @@ calmaDumpStructure(def, outf, calmaDefHash, filename) int datatype; READI2(nbytes); - if (feof(calmaInputFile)) + if (FEOF(calmaInputFile)) { /* Unexpected end-of-file */ - fseek(calmaInputFile, -(CALMAHEADERLENGTH), SEEK_END); + FSEEK(calmaInputFile, -(CALMAHEADERLENGTH), SEEK_END); break; } - rtype = getc(calmaInputFile); - datatype = getc(calmaInputFile); + rtype = FGETC(calmaInputFile); + datatype = FGETC(calmaInputFile); switch (rtype) { case CALMA_BGNSTR: UNREADRH(nbytes, rtype); @@ -642,7 +642,7 @@ calmaDumpStructure(def, outf, calmaDefHash, filename) while (nbytes-- > 0) { int byte; - if ((byte = getc(calmaInputFile)) < 0) + if ((byte = FGETC(calmaInputFile)) < 0) { TxError("End of file with %d bytes remaining to be read.\n", nbytes); @@ -682,7 +682,7 @@ syntaxerror: void calmaFullDump(def, fi, outf, filename) CellDef *def; - FILE *fi; + FILETYPE fi; FILE *outf; char *filename; { @@ -702,8 +702,8 @@ calmaFullDump(def, fi, outf, filename) HashInit(&calmaDefHash, 32, 0); - calmaInputFile = fi; cifReadCellDef = def; + calmaInputFile = fi; /* Read and ignore the GDS-II header */ @@ -771,7 +771,7 @@ calmaFullDump(def, fi, outf, filename) else HashSetValue(he, StrDup(NULL, "")); - while (calmaDumpStructure(def, outf, &calmaDefHash, filename)) + while (calmaDumpStructure(def, fi, outf, &calmaDefHash, filename)) if (SigInterruptPending) goto done; calmaSkipExact(CALMA_ENDLIB); @@ -949,7 +949,7 @@ calmaProcessDef(def, outf, do_library) dlong cval; int namelen; char *modName; - FILE *fi; + FILETYPE fi; /* Handle compressed files */ @@ -980,10 +980,10 @@ calmaProcessDef(def, outf, do_library) } } - /* Use PaOpen() so the paths searched are the same as were */ + /* Use PaZOpen() so the paths searched are the same as were */ /* searched to find the .mag file that indicated this GDS file. */ - fi = PaOpen(modName, "r", "", Path, CellLibPath, &retfilename); + fi = PaZOpen(modName, "r", "", Path, CellLibPath, &retfilename); if (fi == NULL) { /* This is a rare error, but if the subcell is inside */ @@ -1022,7 +1022,7 @@ calmaProcessDef(def, outf, do_library) if (he == NULL) calmaFullDump(def, fi, outf, retfilename); - fclose(fi); + FCLOSE(fi); def->cd_flags |= CDVENDORGDS; } else @@ -1060,12 +1060,12 @@ calmaProcessDef(def, outf, do_library) if (strlen(def->cd_name) & 0x1) structstart--; structstart -= 2; - fseek(fi, structstart, SEEK_SET); + FSEEK(fi, structstart, SEEK_SET); /* Read the structure name and check against the CellDef name */ defsize = (size_t)(cellstart - structstart); buffer = (char *)mallocMagic(defsize + 1); - numbytes = fread(buffer, sizeof(char), (size_t)defsize, fi); + numbytes = FREAD(buffer, sizeof(char), (size_t)defsize, fi); if (numbytes == defsize) { buffer[defsize] = '\0'; @@ -1105,7 +1105,7 @@ calmaProcessDef(def, outf, do_library) defsize = (size_t)(cellend - cellstart); buffer = (char *)mallocMagic(defsize); - numbytes = fread(buffer, sizeof(char), (size_t)defsize, fi); + numbytes = FREAD(buffer, sizeof(char), (size_t)defsize, fi); if (numbytes == defsize) { @@ -1147,7 +1147,7 @@ calmaProcessDef(def, outf, do_library) } freeMagic(buffer); } - fclose(fi); + FCLOSE(fi); if (modName != filename) { diff --git a/calma/calma.h b/calma/calma.h index 9b72126d..82794402 100644 --- a/calma/calma.h +++ b/calma/calma.h @@ -55,4 +55,8 @@ extern void CalmaTechInit(); extern bool CalmaGenerateArray(); extern void CalmaReadError(); +#ifdef HAVE_ZLIB +extern bool CalmaWriteZ(); +#endif + #endif /* _CALMA_H */ diff --git a/calma/calmaInt.h b/calma/calmaInt.h index c8a27e67..9c4a7a4b 100644 --- a/calma/calmaInt.h +++ b/calma/calmaInt.h @@ -167,6 +167,7 @@ typedef enum { LABEL_TYPE_NONE, LABEL_TYPE_TEXT, LABEL_TYPE_PORT, LABEL_TYPE_CEL /* Globals for Calma reading */ extern FILETYPE calmaInputFile; +extern FILE *calmaInputFileNoCompression; extern char *calmaFilename; extern int calmaReadScale1; extern int calmaReadScale2;