From b2d0f04a50f1444f9d62d11636a28c89951f0f40 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 4 Oct 2011 21:00:11 -0700 Subject: Add const attributes to fix gcc -Wwrite-strings warnings Does not fix all of them since some lists contain constant strings and some contain dynamically allocated strings that need to be freed later. Signed-off-by: Alan Coopersmith --- data.h | 4 ++-- hash.c | 6 +++--- hash.h | 2 +- list.c | 6 +++--- list.h | 6 +++--- mkfontscale.c | 44 ++++++++++++++++++++++---------------------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/data.h b/data.h index bb5b170..75e9325 100644 --- a/data.h +++ b/data.h @@ -26,7 +26,7 @@ /* Order is significant. For example, some B&H fonts are hinted by URW++, and both strings appear in the notice. */ -static char *notice_foundries[][2] = +static const char *notice_foundries[][2] = {{"Bigelow", "b&h"}, {"Adobe", "adobe"}, {"Bitstream", "bitstream"}, @@ -49,7 +49,7 @@ static char *notice_foundries[][2] = /* It should not contain useless entries (such as UNKN) nor duplicate entries for padding both with spaces and NULs. */ -static char *vendor_foundries[][2] = +static const char *vendor_foundries[][2] = {{"ADBE", "adobe"}, {"AGFA", "agfa"}, {"ALTS", "altsys"}, diff --git a/hash.c b/hash.c index 313d5b6..94ef2ac 100644 --- a/hash.c +++ b/hash.c @@ -31,7 +31,7 @@ #define NUMBUCKETS (1 << LOG2_NUMBUCKETS) static unsigned -hash(char *string) +hash(const char *string) { int i; unsigned u = 0; @@ -41,7 +41,7 @@ hash(char *string) } static void -strcpy_lwr(char *dst, char *src) +strcpy_lwr(char *dst, const char *src) { while(1) { *dst = tolower(*src); @@ -77,7 +77,7 @@ destroyHashTable(HashTablePtr table) } char * -getHash(HashTablePtr table, char *key) +getHash(HashTablePtr table, const char *key) { int i = hash(key); HashBucketPtr bp; diff --git a/hash.h b/hash.h index 592c424..9aa94a6 100644 --- a/hash.h +++ b/hash.h @@ -34,7 +34,7 @@ typedef HashBucketPtr* HashTablePtr; HashTablePtr makeHashTable(void); void destroyHashTable(HashTablePtr table); -char *getHash(HashTablePtr table, char *key); +char *getHash(HashTablePtr table, const char *key); int putHash(HashTablePtr table, char *key, char *value, int prio); int hashElements(HashTablePtr table); HashBucketPtr *hashArray(HashTablePtr table, int value_first); diff --git a/list.c b/list.c index 2854e18..1ca1998 100644 --- a/list.c +++ b/list.c @@ -27,7 +27,7 @@ #include "list.h" int -listMember(char *elt, ListPtr list) +listMember(const char *elt, ListPtr list) { while(list != NULL) { if(strcmp(elt, list->value) == 0) @@ -87,7 +87,7 @@ dsprintf(const char *f, ...) ListPtr -listConsF(ListPtr cdr, char *f, ...) +listConsF(ListPtr cdr, const char *f, ...) { va_list args; char *string; @@ -114,7 +114,7 @@ listConsF(ListPtr cdr, char *f, ...) } ListPtr -listAdjoinF(ListPtr cdr, char *f, ...) +listAdjoinF(ListPtr cdr, const char *f, ...) { va_list args; char *string; diff --git a/list.h b/list.h index 7403bc0..c68a78d 100644 --- a/list.h +++ b/list.h @@ -32,11 +32,11 @@ typedef struct _List { struct _List *next; } ListRec, *ListPtr; -int listMember(char *elt, ListPtr list); +int listMember(const char *elt, ListPtr list); ListPtr listCons(char *car, ListPtr cdr); ListPtr listAdjoin(char *car, ListPtr cdr); -ListPtr listConsF(ListPtr cdr, char *f, ...) _X_ATTRIBUTE_PRINTF(2,3); -ListPtr listAdjoinF(ListPtr cdr, char *f, ...) _X_ATTRIBUTE_PRINTF(2,3); +ListPtr listConsF(ListPtr cdr, const char *f, ...) _X_ATTRIBUTE_PRINTF(2,3); +ListPtr listAdjoinF(ListPtr cdr, const char *f, ...) _X_ATTRIBUTE_PRINTF(2,3); int listLength(ListPtr list); ListPtr appendList(ListPtr first, ListPtr second); ListPtr makeList(char **a, int n, ListPtr old, int begin); diff --git a/mkfontscale.c b/mkfontscale.c index 49bbe77..ad07377 100644 --- a/mkfontscale.c +++ b/mkfontscale.c @@ -60,7 +60,7 @@ #define QUOTE(x) #x #define STRINGIFY(x) QUOTE(x) -static char *encodings_array[] = +static const char *encodings_array[] = { "ascii-0", "iso8859-1", "iso8859-2", "iso8859-3", "iso8859-4", "iso8859-5", "iso8859-6", "iso8859-6.8", "iso8859-6.8x", "iso8859-6.16", @@ -79,20 +79,20 @@ static char *encodings_array[] = "gb2312.1980-0", "gb18030.2000-0", "gb18030.2000-1", "ksc5601.1987-0", "ksc5601.1992-3"}; -static char *extra_encodings_array[] = +static const char *extra_encodings_array[] = { "iso10646-1", "adobe-fontspecific", "microsoft-symbol" }; static ListPtr encodings, extra_encodings; -static char *outfilename; +static const char *outfilename; #define countof(_a) (sizeof(_a)/sizeof((_a)[0])) -static int doDirectory(char*, int, ListPtr); +static int doDirectory(const char*, int, ListPtr); static int checkEncoding(FT_Face face, char *encoding_name); static int checkExtraEncoding(FT_Face face, char *encoding_name, int found); static int find_cmap(int type, int pid, int eid, FT_Face face); -static char* notice_foundry(char *notice); -static char* vendor_foundry(signed char *vendor); +static const char* notice_foundry(const char *notice); +static const char* vendor_foundry(const signed char *vendor); static int readFontScale(HashTablePtr entries, char *dirname); ListPtr makeXLFD(char *filename, FT_Face face, int); static int readEncodings(ListPtr encodings, char *dirname); @@ -348,7 +348,7 @@ getName(FT_Face face, int nid) return NULL; } -static char* +static const char* os2Weight(int weight) { if(weight < 150) @@ -371,7 +371,7 @@ os2Weight(int weight) return "black"; } -static char* +static const char* os2Width(int width) { if(width <= 1) @@ -394,15 +394,15 @@ os2Width(int width) return "ultraexpanded"; } -static char *widths[] = { +static const char *widths[] = { "ultracondensed", "extracondensed", "condensed", "semicondensed", "normal", "semiexpanded", "expanded", "extraexpanded", "ultraexpanded" }; #define NUMWIDTHS (sizeof(widths) / sizeof(widths[0])) -static char* -nameWidth(char *name) +static const char* +nameWidth(const char *name) { char buf[500]; int i; @@ -419,8 +419,8 @@ nameWidth(char *name) return NULL; } -static char* -t1Weight(char *weight) +static const char* +t1Weight(const char *weight) { if(!weight) return NULL; @@ -466,8 +466,8 @@ unsafe(char c) c == '[' || c == ']' || c == '(' || c == ')' || c == '\\' || c == '-'; } -static char * -safe(char* s) +static const char * +safe(const char* s) { int i, len, safe_flag = 1; char *t; @@ -502,7 +502,7 @@ ListPtr makeXLFD(char *filename, FT_Face face, int isBitmap) { ListPtr xlfd = NULL; - char *foundry, *family, *weight, *slant, *sWidth, *adstyle, + const char *foundry, *family, *weight, *slant, *sWidth, *adstyle, *spacing, *full_name; TT_Header *head; TT_HoriHeader *hhea; @@ -754,7 +754,7 @@ filePrio(char *filename) } static int -doDirectory(char *dirname_given, int numEncodings, ListPtr encodingsToDo) +doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo) { char *dirname, *fontscale_name, *filename, *encdir; FILE *fontscale, *encfile; @@ -1209,8 +1209,8 @@ checkExtraEncoding(FT_Face face, char *encoding_name, int found) } } -static char* -notice_foundry(char *notice) +static const char* +notice_foundry(const char *notice) { int i; for(i = 0; i < countof(notice_foundries); i++) @@ -1220,7 +1220,7 @@ notice_foundry(char *notice) } static int -vendor_match(signed char *vendor, char *vendor_string) +vendor_match(const signed char *vendor, const char *vendor_string) { /* vendor is not necessarily NUL-terminated. */ int i, len; @@ -1233,8 +1233,8 @@ vendor_match(signed char *vendor, char *vendor_string) return 1; } -static char* -vendor_foundry(signed char *vendor) +static const char* +vendor_foundry(const signed char *vendor) { int i; for(i = 0; i < countof(vendor_foundries); i++) -- cgit v1.2.3