calma: use 'const' with readonly data

This then required a cascade of function APIs to also now receive
const arguments.

This reduces the .data segment use of this module.
This commit is contained in:
Darryl L. Miles 2024-10-04 11:19:10 +01:00 committed by Tim Edwards
parent 378755e083
commit 4cd1235575
7 changed files with 44 additions and 42 deletions

View File

@ -350,7 +350,7 @@ bool
calmaParseStructure( calmaParseStructure(
char *filename) /* Name of the GDS file read */ char *filename) /* Name of the GDS file read */
{ {
static int structs[] = { CALMA_STRCLASS, CALMA_STRTYPE, -1 }; static const int structs[] = { CALMA_STRCLASS, CALMA_STRTYPE, -1 };
int nbytes = -1, rtype = 0, nsrefs, osrefs, npaths; int nbytes = -1, rtype = 0, nsrefs, osrefs, npaths;
char *strname = NULL; char *strname = NULL;
HashEntry *he; HashEntry *he;
@ -680,7 +680,7 @@ calmaParseElement(
int *pnsrefs, int *pnsrefs,
int *pnpaths) int *pnpaths)
{ {
static int node[] = { CALMA_ELFLAGS, CALMA_PLEX, CALMA_LAYER, static const int node[] = { CALMA_ELFLAGS, CALMA_PLEX, CALMA_LAYER,
CALMA_NODETYPE, CALMA_XY, -1 }; CALMA_NODETYPE, CALMA_XY, -1 };
int nbytes, rtype, madeinst; int nbytes, rtype, madeinst;
@ -1351,7 +1351,7 @@ calmaUniqueCell(
CellDef * CellDef *
calmaFindCell( calmaFindCell(
char *name, /* Name of desired cell */ const char *name, /* Name of desired cell */
bool *was_called, /* If this cell is in the hash table, then it bool *was_called, /* If this cell is in the hash table, then it
* was instanced before it was defined. We * was instanced before it was defined. We
* need to know this so as to avoid flattening * need to know this so as to avoid flattening

View File

@ -490,9 +490,9 @@ calmaReadR8(
void void
calmaSkipSet( calmaSkipSet(
int *skipwhat) const int *skipwhat)
{ {
int *skipp; const int *skipp;
int nbytes, rtype; int nbytes, rtype;
for (;;) for (;;)

View File

@ -732,7 +732,7 @@ calmaElementPath(void)
void void
calmaElementText(void) calmaElementText(void)
{ {
static int ignore[] = { CALMA_PATHTYPE, CALMA_WIDTH, -1 }; static const int ignore[] = { CALMA_PATHTYPE, CALMA_WIDTH, -1 };
char *textbody = NULL; char *textbody = NULL;
int nbytes = -1, rtype = 0; int nbytes = -1, rtype = 0;
int layer, textt, cifnum, textpres; int layer, textt, cifnum, textpres;

View File

@ -147,7 +147,7 @@ HashTable calmaLayerHash;
HashTable calmaDefInitHash; HashTable calmaDefInitHash;
/* Common stuff to ignore */ /* Common stuff to ignore */
int calmaElementIgnore[] = { CALMA_ELFLAGS, CALMA_PLEX, -1 }; const int calmaElementIgnore[] = { CALMA_ELFLAGS, CALMA_PLEX, -1 };
/* /*
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
@ -174,10 +174,10 @@ CalmaReadFile(
int k, version; int k, version;
char *libname = NULL, *libnameptr = NULL; char *libname = NULL, *libnameptr = NULL;
MagWindow *mw; MagWindow *mw;
static int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS, static const int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS,
CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE, CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE,
CALMA_STYPTABLE, CALMA_GENERATIONS, -1 }; CALMA_STYPTABLE, CALMA_GENERATIONS, -1 };
static int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME, static const int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME,
CALMA_LIBSECUR, -1 }; CALMA_LIBSECUR, -1 };
if (EditCellUse == (CellUse *)NULL) if (EditCellUse == (CellUse *)NULL)
@ -558,12 +558,12 @@ calmaUnexpected(
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
*/ */
char * const char *
calmaRecordName( calmaRecordName(
int rtype) int rtype)
{ {
static char numeric[10]; static char numeric[10];
static char *calmaRecordNames[] = static const char * const calmaRecordNames[] =
{ {
"HEADER", "BGNLIB", "LIBNAME", "UNITS", "HEADER", "BGNLIB", "LIBNAME", "UNITS",
"ENDLIB", "BGNSTR", "STRNAME", "ENDSTR", "ENDLIB", "BGNSTR", "STRNAME", "ENDSTR",

View File

@ -102,7 +102,7 @@ extern void calmaWriteLabelFunc(Label *lab, int ltype, int type, FILE *f);
extern void calmaOutHeader(CellDef *rootDef, FILE *f); extern void calmaOutHeader(CellDef *rootDef, FILE *f);
extern void calmaOutDate(time_t t, FILE *f); extern void calmaOutDate(time_t t, FILE *f);
extern void calmaOutStringRecord(int type, char *str, FILE *f); extern void calmaOutStringRecord(int type, char *str, FILE *f);
extern void calmaOut8(char *str, FILE *f); extern void calmaOut8(const char *str, FILE *f);
extern void calmaOutR8(double d, FILE *f); extern void calmaOutR8(double d, FILE *f);
extern void calmaProcessBoundary(BoundaryTop *blist, calmaOutputStruct *cos); extern void calmaProcessBoundary(BoundaryTop *blist, calmaOutputStruct *cos);
extern void calmaRemoveColinear(BoundaryTop *blist); extern void calmaRemoveColinear(BoundaryTop *blist);
@ -199,7 +199,7 @@ HashTable calmaUndefHash;
(void) putc(u.u_c[3], f); \ (void) putc(u.u_c[3], f); \
} }
static char calmaMapTableStrict[] = static const char calmaMapTableStrict[] =
{ {
0, 0, 0, 0, 0, 0, 0, 0, /* NUL - BEL */ 0, 0, 0, 0, 0, 0, 0, 0, /* NUL - BEL */
0, 0, 0, 0, 0, 0, 0, 0, /* BS - SI */ 0, 0, 0, 0, 0, 0, 0, 0, /* BS - SI */
@ -219,7 +219,7 @@ static char calmaMapTableStrict[] =
'x', 'y', 'z', '_', '_', '_', '_', 0, /* x - DEL */ 'x', 'y', 'z', '_', '_', '_', '_', 0, /* x - DEL */
}; };
static char calmaMapTablePermissive[] = static const char calmaMapTablePermissive[] =
{ {
0, 0, 0, 0, 0, 0, 0, 0, /* NUL - BEL */ 0, 0, 0, 0, 0, 0, 0, 0, /* NUL - BEL */
0, 0, 0, 0, 0, 0, 0, 0, /* BS - SI */ 0, 0, 0, 0, 0, 0, 0, 0, /* BS - SI */
@ -686,10 +686,10 @@ calmaFullDump(
HashSearch hs; HashSearch hs;
HashEntry *he, *he2; HashEntry *he, *he2;
static int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS, static const int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS,
CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE, CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE,
CALMA_STYPTABLE, CALMA_GENERATIONS, -1 }; CALMA_STYPTABLE, CALMA_GENERATIONS, -1 };
static int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME, static const int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME,
CALMA_LIBSECUR, -1 }; CALMA_LIBSECUR, -1 };
HashInit(&calmaDefHash, 32, 0); HashInit(&calmaDefHash, 32, 0);
@ -1524,10 +1524,10 @@ calmaWriteUseFunc(
* only 4 possible values, it is faster to have them pre-computed * only 4 possible values, it is faster to have them pre-computed
* than to format with calmaOutR8(). * than to format with calmaOutR8().
*/ */
static unsigned char r90[] = { 0x42, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const unsigned char r90[] = { 0x42, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static unsigned char r180[] = { 0x42, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const unsigned char r180[] = { 0x42, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static unsigned char r270[] = { 0x43, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const unsigned char r270[] = { 0x43, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00 };
unsigned char *whichangle; const unsigned char *whichangle;
int x, y, topx, topy, rows, cols, xxlate, yxlate, hdrsize; int x, y, topx, topy, rows, cols, xxlate, yxlate, hdrsize;
int rectype, stransflags; int rectype, stransflags;
Transform *t; Transform *t;
@ -1738,7 +1738,7 @@ calmaOutStructName(
unsigned char c; unsigned char c;
char *cp; char *cp;
int calmanum; int calmanum;
char *table; const char *table;
if (CIFCurStyle->cs_flags & CWF_PERMISSIVE_LABELS) if (CIFCurStyle->cs_flags & CWF_PERMISSIVE_LABELS)
{ {
@ -3245,7 +3245,8 @@ calmaOutStringRecord(
{ {
int len; int len;
unsigned char c; unsigned char c;
char *table, *locstr, *origstr = NULL; const char *table;
char *locstr, *origstr = NULL;
char *locstrprv; /* Added by BSI */ char *locstrprv; /* Added by BSI */
if(CIFCurStyle->cs_flags & CWF_PERMISSIVE_LABELS) if(CIFCurStyle->cs_flags & CWF_PERMISSIVE_LABELS)
@ -3415,7 +3416,7 @@ calmaOutR8(
void void
calmaOut8( calmaOut8(
char *str, /* 8-byte string to be output */ const char *str, /* 8-byte string to be output */
FILE *f) /* Stream file */ FILE *f) /* Stream file */
{ {
int i; int i;

View File

@ -112,7 +112,7 @@ extern void calmaWriteLabelFuncZ(Label *lab, int ltype, int type, gzFile f);
extern void calmaOutHeaderZ(CellDef *rootDef, gzFile f); extern void calmaOutHeaderZ(CellDef *rootDef, gzFile f);
extern void calmaOutDateZ(time_t t, gzFile f); extern void calmaOutDateZ(time_t t, gzFile f);
extern void calmaOutStringRecordZ(int type, char *str, gzFile f); extern void calmaOutStringRecordZ(int type, char *str, gzFile f);
extern void calmaOut8Z(char *str, gzFile f); extern void calmaOut8Z(const char *str, gzFile f);
extern void calmaOutR8Z(double d, gzFile f); extern void calmaOutR8Z(double d, gzFile f);
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
@ -180,7 +180,7 @@ extern void calmaOutR8Z(double d, gzFile f);
(void) gzputc(f, u.u_c[3]); \ (void) gzputc(f, u.u_c[3]); \
} }
static char calmaMapTableStrict[] = static const char calmaMapTableStrict[] =
{ {
0, 0, 0, 0, 0, 0, 0, 0, /* NUL - BEL */ 0, 0, 0, 0, 0, 0, 0, 0, /* NUL - BEL */
0, 0, 0, 0, 0, 0, 0, 0, /* BS - SI */ 0, 0, 0, 0, 0, 0, 0, 0, /* BS - SI */
@ -200,7 +200,7 @@ static char calmaMapTableStrict[] =
'x', 'y', 'z', '_', '_', '_', '_', 0, /* x - DEL */ 'x', 'y', 'z', '_', '_', '_', '_', 0, /* x - DEL */
}; };
static char calmaMapTablePermissive[] = static const char calmaMapTablePermissive[] =
{ {
0, 0, 0, 0, 0, 0, 0, 0, /* NUL - BEL */ 0, 0, 0, 0, 0, 0, 0, 0, /* NUL - BEL */
0, 0, 0, 0, 0, 0, 0, 0, /* BS - SI */ 0, 0, 0, 0, 0, 0, 0, 0, /* BS - SI */
@ -667,10 +667,10 @@ calmaFullDumpZ(
HashSearch hs; HashSearch hs;
HashEntry *he, *he2; HashEntry *he, *he2;
static int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS, static const int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS,
CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE, CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE,
CALMA_STYPTABLE, CALMA_GENERATIONS, -1 }; CALMA_STYPTABLE, CALMA_GENERATIONS, -1 };
static int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME, static const int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME,
CALMA_LIBSECUR, -1 }; CALMA_LIBSECUR, -1 };
HashInit(&calmaDefHash, 32, 0); HashInit(&calmaDefHash, 32, 0);
@ -1365,10 +1365,10 @@ calmaWriteUseFuncZ(
* only 4 possible values, it is faster to have them pre-computed * only 4 possible values, it is faster to have them pre-computed
* than to format with calmaOutR8Z(). * than to format with calmaOutR8Z().
*/ */
static unsigned char r90[] = { 0x42, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const unsigned char r90[] = { 0x42, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static unsigned char r180[] = { 0x42, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const unsigned char r180[] = { 0x42, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static unsigned char r270[] = { 0x43, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const unsigned char r270[] = { 0x43, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00 };
unsigned char *whichangle; const unsigned char *whichangle;
int x, y, topx, topy, rows, cols, xxlate, yxlate, hdrsize; int x, y, topx, topy, rows, cols, xxlate, yxlate, hdrsize;
int rectype, stransflags; int rectype, stransflags;
Transform *t; Transform *t;
@ -1579,7 +1579,7 @@ calmaOutStructNameZ(
unsigned char c; unsigned char c;
char *cp; char *cp;
int calmanum; int calmanum;
char *table; const char *table;
if (CIFCurStyle->cs_flags & CWF_PERMISSIVE_LABELS) if (CIFCurStyle->cs_flags & CWF_PERMISSIVE_LABELS)
{ {
@ -2638,7 +2638,8 @@ calmaOutStringRecordZ(
{ {
int len; int len;
unsigned char c; unsigned char c;
char *table, *locstr, *origstr = NULL; const char *table;
char *locstr, *origstr = NULL;
char *locstrprv; char *locstrprv;
if(CIFCurStyle->cs_flags & CWF_PERMISSIVE_LABELS) if(CIFCurStyle->cs_flags & CWF_PERMISSIVE_LABELS)
@ -2808,7 +2809,7 @@ calmaOutR8Z(
void void
calmaOut8Z( calmaOut8Z(
char *str, /* 8-byte string to be output */ const char *str, /* 8-byte string to be output */
gzFile f) /* Compressed stream file */ gzFile f) /* Compressed stream file */
{ {
int i; int i;

View File

@ -226,8 +226,8 @@ typedef struct portlabel
/* Other commonly used globals */ /* Other commonly used globals */
extern HashTable calmaLayerHash; extern HashTable calmaLayerHash;
extern int calmaElementIgnore[]; extern const int calmaElementIgnore[];
extern CellDef *calmaFindCell(char *name, bool *was_called, bool *predefined); extern CellDef *calmaFindCell(const char *name, bool *was_called, bool *predefined);
/* (Added by Nishit, 8/18/2004--8/24/2004) */ /* (Added by Nishit, 8/18/2004--8/24/2004) */
extern CellDef *calmaLookCell(char *name); extern CellDef *calmaLookCell(char *name);
@ -235,8 +235,8 @@ extern void calmaWriteContacts(FILE *f);
extern CellDef *calmaGetContactCell(TileType type, bool lookOnly); extern CellDef *calmaGetContactCell(TileType type, bool lookOnly);
extern bool calmaIsContactCell; extern bool calmaIsContactCell;
extern char *calmaRecordName(int rtype); extern const char *calmaRecordName(int rtype);
extern void calmaSkipSet(int *skipwhat); extern void calmaSkipSet(const int *skipwhat);
extern bool calmaParseUnits(void); extern bool calmaParseUnits(void);
extern int compport(const void *one, const void *two); extern int compport(const void *one, const void *two);