From: Robin Barker Date: Fri, 21 Dec 2007 14:30:20 +0000 (+0000) Subject: C -Wwrite-strings clean X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aab391487e4ce7ac2d97b35a504de2697fadd1b6;p=p5sagit%2Fp5-mst-13.2.git C -Wwrite-strings clean From: "Robin Barker" Message-ID: <46A0F33545E63740BC7563DE59CA9C6D09399C@exchsvr2.npl.ad.local> p4raw-id: //depot/perl@32690 --- diff --git a/x2p/Makefile.SH b/x2p/Makefile.SH index b4c3058..ba56c49 100755 --- a/x2p/Makefile.SH +++ b/x2p/Makefile.SH @@ -124,6 +124,9 @@ run_byacc: FORCE -e 's/^yynewerror://' \ -e 's/^ goto yynewerror;//' \ -e 's|^static char yysccsid\(.*\)|/* static char yysccsid\1 */|' \ + -e 's/^\(char \*yyname\[\]\)/const \1/' \ + -e 's/^\(char \*yyrule\[\]\)/const \1/' \ + -e 's/^\( register\) \(char \*yys;\)/\1 const \2/' \ < y.tab.c > a2p.c FORCE: diff --git a/x2p/a2p.c b/x2p/a2p.c index 20e3227..4186cdf 100644 --- a/x2p/a2p.c +++ b/x2p/a2p.c @@ -1984,7 +1984,7 @@ short yycheck[] = { 41, #endif #define YYMAXTOKEN 306 #if YYDEBUG -char *yyname[] = { +const char *yyname[] = { "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,"'%'",0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0,0, "':'","';'","'<'",0,"'>'","'?'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -1999,7 +1999,7 @@ char *yyname[] = { "DELETE","ASGNOP","OROR","ANDAND","NUMBER","VAR","SUBSTR","INDEX","MATCHOP", "RELOP","OR","STRING","UMINUS","NOT","INCR","DECR","FIELD","VFIELD","SVFIELD", }; -char *yyrule[] = { +const char *yyrule[] = { "$accept : program", "program : junk hunks", "begin : BEGIN '{' maybe states '}' junk", @@ -2193,7 +2193,7 @@ yyparse(void) { register int yym, yyn, yystate; #if YYDEBUG - register char *yys; + register const char *yys; if ((yys = getenv("YYDEBUG"))) { diff --git a/x2p/a2p.h b/x2p/a2p.h index db09edd..e38e2d2 100644 --- a/x2p/a2p.h +++ b/x2p/a2p.h @@ -252,7 +252,7 @@ char *strcpy(), *strcat(); #define OSTAR 88 #ifdef DOINIT -char *opname[] = { +const char *opname[] = { "0", "PROG", "JUNK", @@ -345,7 +345,7 @@ char *opname[] = { "89" }; #else -extern char *opname[]; +extern const char *opname[]; #endif EXT int mop INIT(1); @@ -370,8 +370,8 @@ typedef struct htbl HASH; /* A string is TRUE if not "" or "0". */ #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1]))) -EXT char *Yes INIT("1"); -EXT char *No INIT(""); +EXT const char *Yes INIT("1"); +EXT const char *No INIT(""); #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str))) EXT STR *Str; @@ -397,8 +397,8 @@ void putone ( void ); int rememberargs ( int arg ); char * scannum ( char *s ); char * scanpat ( char *s ); -int string ( char *ptr, int len ); -void yyerror ( char *s ); +int string ( const char *ptr, int len ); +void yyerror ( const char *s ); int yylex ( void ); EXT int line INIT(0); diff --git a/x2p/a2py.c b/x2p/a2py.c index df0a55c..b6497af 100644 --- a/x2p/a2py.c +++ b/x2p/a2py.c @@ -18,8 +18,8 @@ #endif #include "util.h" -char *filename; -char *myname; +const char *filename; +const char *myname; int checkers = 0; @@ -59,7 +59,7 @@ usage() #endif int -main(register int argc, register char **argv, register char **env) +main(register int argc, register const char **argv, register const char **env) { register STR *str; int i; @@ -126,7 +126,6 @@ main(register int argc, register char **argv, register char **env) } filename = savestr(argv[0]); - filename = savestr(argv[0]); if (strEQ(filename,"-")) argv[0] = ""; if (!*argv[0]) @@ -562,7 +561,7 @@ yylex(void) else if (strEQ(d,"function")) XTERM(FUNCTION); if (strEQ(d,"FILENAME")) - d = "ARGV"; + ID("ARGV"); if (strEQ(d,"foreach")) *d = toUPPER(*d); else if (strEQ(d,"format")) @@ -666,14 +665,14 @@ yylex(void) SNARFWORD; if (strEQ(d,"ORS")) { saw_ORS = TRUE; - d = "\\"; + ID("\\"); } if (strEQ(d,"OFS")) { saw_OFS = TRUE; - d = ","; + ID(","); } if (strEQ(d,"OFMT")) { - d = "#"; + ID("#"); } if (strEQ(d,"open")) *d = toUPPER(*d); @@ -701,8 +700,8 @@ yylex(void) case 'r': case 'R': SNARFWORD; if (strEQ(d,"RS")) { - d = "/"; saw_RS = TRUE; + ID("/"); } if (strEQ(d,"rand")) { yylval = ORAND; @@ -743,7 +742,7 @@ yylex(void) XTERM(FUN1); } if (strEQ(d,"SUBSEP")) { - d = ";"; + ID(";"); } if (strEQ(d,"sin")) { yylval = OSIN; @@ -878,7 +877,7 @@ scanpat(register char *s) } void -yyerror(char *s) +yyerror(const char *s) { fprintf(stderr,"%s in file %s at line %d\n", s,filename,line); @@ -921,7 +920,7 @@ scannum(register char *s) } int -string(char *ptr, int len) +string(const char *ptr, int len) { int retval = mop; diff --git a/x2p/str.c b/x2p/str.c index 0b1c940..3909f5b 100644 --- a/x2p/str.c +++ b/x2p/str.c @@ -25,7 +25,7 @@ str_2ptr(register STR *str) register char *s; if (!str) - return ""; + return (char *)""; /* probably safe - won't be written to */ GROWSTR(&(str->str_ptr), &(str->str_len), 24); s = str->str_ptr; if (str->str_nok) { @@ -56,7 +56,7 @@ str_sset(STR *dstr, register STR *sstr) } void -str_nset(register STR *str, register char *ptr, register int len) +str_nset(register STR *str, register const char *ptr, register int len) { GROWSTR(&(str->str_ptr), &(str->str_len), len + 1); memcpy(str->str_ptr,ptr,len); @@ -67,7 +67,7 @@ str_nset(register STR *str, register char *ptr, register int len) } void -str_set(register STR *str, register char *ptr) +str_set(register STR *str, register const char *ptr) { register int len; @@ -82,7 +82,7 @@ str_set(register STR *str, register char *ptr) } void -str_ncat(register STR *str, register char *ptr, register int len) +str_ncat(register STR *str, register const char *ptr, register int len) { if (!(str->str_pok)) str_2ptr(str); @@ -104,7 +104,7 @@ str_scat(STR *dstr, register STR *sstr) } void -str_cat(register STR *str, register char *ptr) +str_cat(register STR *str, register const char *ptr) { register int len; @@ -250,7 +250,7 @@ thats_all_folks: } STR * -str_make(char *s) +str_make(const char *s) { register STR *str = str_new(0); diff --git a/x2p/str.h b/x2p/str.h index f5b590b..98e354c 100644 --- a/x2p/str.h +++ b/x2p/str.h @@ -29,15 +29,15 @@ EXT STR **tmps_list; EXT long tmps_max INIT(-1); char * str_2ptr ( STR *str ); -void str_cat ( STR *str, char *ptr ); +void str_cat ( STR *str, const char *ptr ); void str_free ( STR *str ); char * str_gets ( STR *str, FILE *fp ); int str_len ( STR *str ); -STR * str_make ( char *s ); -void str_ncat ( STR *str, char *ptr, int len ); +STR * str_make ( const char *s ); +void str_ncat ( STR *str, const char *ptr, int len ); STR * str_new ( int len ); -void str_nset ( STR *str, char *ptr, int len ); +void str_nset ( STR *str, const char *ptr, int len ); void str_numset ( STR *str, double num ); void str_scat ( STR *dstr, STR *sstr ); -void str_set ( STR *str, char *ptr ); +void str_set ( STR *str, const char *ptr ); void str_sset ( STR *dstr, STR *sstr ); diff --git a/x2p/util.c b/x2p/util.c index 6994e87..aff3f00 100644 --- a/x2p/util.c +++ b/x2p/util.c @@ -119,9 +119,10 @@ cpy2(register char *to, register char *from, register int delim) /* return ptr to little string in big string, NULL if not found */ char * -instr(char *big, char *little) +instr(char *big, const char *little) { - register char *t, *s, *x; + register char *t, *x; + register const char *s; for (t = big; *t; t++) { for (x=t,s=little; *s; x++,s++) { @@ -139,7 +140,7 @@ instr(char *big, char *little) /* copy a string to a safe spot */ char * -savestr(char *str) +savestr(const char *str) { register char * const newaddr = (char *) safemalloc((MEM_SIZE)(strlen(str)+1)); diff --git a/x2p/util.h b/x2p/util.h index 74341c2..3330a60 100644 --- a/x2p/util.h +++ b/x2p/util.h @@ -21,8 +21,8 @@ char * cpy2 ( char *to, char *from, int delim ); char * cpytill ( char *to, char *from, int delim ); void growstr ( char **strptr, int *curlen, int newlen ); -char * instr ( char *big, char *little ); -char * savestr ( char *str ); +char * instr ( char *big, const char *little ); +char * savestr ( const char *str ); void fatal ( const char *pat, ... ); void warn ( const char *pat, ... ); int prewalk ( int numit, int level, int node, int *numericptr ); diff --git a/x2p/walk.c b/x2p/walk.c index de1263f..cc9f8ac 100644 --- a/x2p/walk.c +++ b/x2p/walk.c @@ -19,9 +19,9 @@ bool saw_FNR = FALSE; bool saw_argv0 = FALSE; bool saw_fh = FALSE; int maxtmp = 0; -char *lparen; -char *rparen; -char *limit; +const char *lparen; +const char *rparen; +const char *limit; STR *subs; STR *curargs = Nullstr; @@ -36,7 +36,7 @@ STR * walk ( int useval, int level, int node, int *numericptr, int minprec ); #ifdef NETWARE char *savestr(char *str); char *cpytill(register char *to, register char *from, register int delim); -char *instr(char *big, char *little); +char *instr(char *big, const char *little); #endif STR * @@ -838,7 +838,9 @@ sub Pick {\n\ len = type >> 8; type &= 255; tmp3str = str_new(0); - if (type == OSTR) { + { + const char *s; + if (type == OSTR) { tmp2str=walk(1,level,ops[ops[node+2].ival+1].ival,&numarg,P_MIN); for (t = tmp2str->str_ptr, d=tokenbuf; *t; d++,t++) { if (*t == '&') @@ -849,18 +851,19 @@ sub Pick {\n\ } *d = '\0'; str_set(tmp2str,tokenbuf); - s = (char *) (gsub ? "/g" : "/"); - } - else { + s = (gsub ? "/g" : "/"); + } + else { tmp2str=walk(1,level,ops[node+2].ival,&numarg,P_MIN); str_set(tmp3str,"($s_ = '\"'.("); str_scat(tmp3str,tmp2str); str_cat(tmp3str,").'\"') =~ s/&/\\$&/g, "); str_set(tmp2str,"eval $s_"); - s = (char *) (gsub ? "/ge" : "/e"); + s = (gsub ? "/ge" : "/e"); i++; + } + str_cat(tmp2str,s); } - str_cat(tmp2str,s); type = ops[ops[node+1].ival].ival; len = type >> 8; type &= 255; @@ -909,8 +912,9 @@ sub Pick {\n\ break; case OSTR: tmpstr = walk(1,level,ops[node+1].ival,&numarg,P_MIN); - s = "'"; - for (t = tmpstr->str_ptr, d=tokenbuf; *t; d++,t++) { + { + const char *s = "'"; + for (t = tmpstr->str_ptr, d=tokenbuf; *t; d++,t++) { if (*t == '\'') s = "\""; else if (*t == '\\') { @@ -924,13 +928,14 @@ sub Pick {\n\ } } *d = *t + 128; + } + *d = '\0'; + str = str_new(0); + str_set(str,s); + str_cat(str,tokenbuf); + str_free(tmpstr); + str_cat(str,s); } - *d = '\0'; - str = str_new(0); - str_set(str,s); - str_cat(str,tokenbuf); - str_free(tmpstr); - str_cat(str,s); break; case ODEFINED: prec = P_UNI; @@ -1208,7 +1213,7 @@ sub Pick {\n\ } tmpstr = walk(1+(type==OPRINT),level,ops[node+1].ival,&numarg,P_MIN); if (!*tmpstr->str_ptr && lval_field) { - t = (char*)(saw_OFS ? "$," : "' '"); + const char *t = (saw_OFS ? "$," : "' '"); if (split_to_array) { sprintf(tokenbuf,"join(%s,@Fld)",t); str_cat(tmpstr,tokenbuf); @@ -1284,7 +1289,7 @@ sub Pick {\n\ tmpstr = str_new(0); if (!tmpstr->str_ptr || !*tmpstr->str_ptr) { if (lval_field) { - t = (char*)(saw_OFS ? "$," : "' '"); + const char *t = (saw_OFS ? "$," : "' '"); if (split_to_array) { sprintf(tokenbuf,"join(%s,@Fld)",t); str_cat(tmpstr,tokenbuf);