head 1.1; access; symbols pkgsrc-2026Q1:1.1.0.108 pkgsrc-2026Q1-base:1.1 pkgsrc-2025Q4:1.1.0.106 pkgsrc-2025Q4-base:1.1 pkgsrc-2025Q3:1.1.0.104 pkgsrc-2025Q3-base:1.1 pkgsrc-2025Q2:1.1.0.102 pkgsrc-2025Q2-base:1.1 pkgsrc-2025Q1:1.1.0.100 pkgsrc-2025Q1-base:1.1 pkgsrc-2024Q4:1.1.0.98 pkgsrc-2024Q4-base:1.1 pkgsrc-2024Q3:1.1.0.96 pkgsrc-2024Q3-base:1.1 pkgsrc-2024Q2:1.1.0.94 pkgsrc-2024Q2-base:1.1 pkgsrc-2024Q1:1.1.0.92 pkgsrc-2024Q1-base:1.1 pkgsrc-2023Q4:1.1.0.90 pkgsrc-2023Q4-base:1.1 pkgsrc-2023Q3:1.1.0.88 pkgsrc-2023Q3-base:1.1 pkgsrc-2023Q2:1.1.0.86 pkgsrc-2023Q2-base:1.1 pkgsrc-2023Q1:1.1.0.84 pkgsrc-2023Q1-base:1.1 pkgsrc-2022Q4:1.1.0.82 pkgsrc-2022Q4-base:1.1 pkgsrc-2022Q3:1.1.0.80 pkgsrc-2022Q3-base:1.1 pkgsrc-2022Q2:1.1.0.78 pkgsrc-2022Q2-base:1.1 pkgsrc-2022Q1:1.1.0.76 pkgsrc-2022Q1-base:1.1 pkgsrc-2021Q4:1.1.0.74 pkgsrc-2021Q4-base:1.1 pkgsrc-2021Q3:1.1.0.72 pkgsrc-2021Q3-base:1.1 pkgsrc-2021Q2:1.1.0.70 pkgsrc-2021Q2-base:1.1 pkgsrc-2021Q1:1.1.0.68 pkgsrc-2021Q1-base:1.1 pkgsrc-2020Q4:1.1.0.66 pkgsrc-2020Q4-base:1.1 pkgsrc-2020Q3:1.1.0.64 pkgsrc-2020Q3-base:1.1 pkgsrc-2020Q2:1.1.0.60 pkgsrc-2020Q2-base:1.1 pkgsrc-2020Q1:1.1.0.40 pkgsrc-2020Q1-base:1.1 pkgsrc-2019Q4:1.1.0.62 pkgsrc-2019Q4-base:1.1 pkgsrc-2019Q3:1.1.0.58 pkgsrc-2019Q3-base:1.1 pkgsrc-2019Q2:1.1.0.56 pkgsrc-2019Q2-base:1.1 pkgsrc-2019Q1:1.1.0.54 pkgsrc-2019Q1-base:1.1 pkgsrc-2018Q4:1.1.0.52 pkgsrc-2018Q4-base:1.1 pkgsrc-2018Q3:1.1.0.50 pkgsrc-2018Q3-base:1.1 pkgsrc-2018Q2:1.1.0.48 pkgsrc-2018Q2-base:1.1 pkgsrc-2018Q1:1.1.0.46 pkgsrc-2018Q1-base:1.1 pkgsrc-2017Q4:1.1.0.44 pkgsrc-2017Q4-base:1.1 pkgsrc-2017Q3:1.1.0.42 pkgsrc-2017Q3-base:1.1 pkgsrc-2017Q2:1.1.0.38 pkgsrc-2017Q2-base:1.1 pkgsrc-2017Q1:1.1.0.36 pkgsrc-2017Q1-base:1.1 pkgsrc-2016Q4:1.1.0.34 pkgsrc-2016Q4-base:1.1 pkgsrc-2016Q3:1.1.0.32 pkgsrc-2016Q3-base:1.1 pkgsrc-2016Q2:1.1.0.30 pkgsrc-2016Q2-base:1.1 pkgsrc-2016Q1:1.1.0.28 pkgsrc-2016Q1-base:1.1 pkgsrc-2015Q4:1.1.0.26 pkgsrc-2015Q4-base:1.1 pkgsrc-2015Q3:1.1.0.24 pkgsrc-2015Q3-base:1.1 pkgsrc-2015Q2:1.1.0.22 pkgsrc-2015Q2-base:1.1 pkgsrc-2015Q1:1.1.0.20 pkgsrc-2015Q1-base:1.1 pkgsrc-2014Q4:1.1.0.18 pkgsrc-2014Q4-base:1.1 pkgsrc-2014Q3:1.1.0.16 pkgsrc-2014Q3-base:1.1 pkgsrc-2014Q2:1.1.0.14 pkgsrc-2014Q2-base:1.1 pkgsrc-2014Q1:1.1.0.12 pkgsrc-2014Q1-base:1.1 pkgsrc-2013Q4:1.1.0.10 pkgsrc-2013Q4-base:1.1 pkgsrc-2013Q3:1.1.0.8 pkgsrc-2013Q3-base:1.1 pkgsrc-2013Q2:1.1.0.6 pkgsrc-2013Q2-base:1.1 pkgsrc-2013Q1:1.1.0.4 pkgsrc-2013Q1-base:1.1 pkgsrc-2012Q4:1.1.0.2 pkgsrc-2012Q4-base:1.1; locks; strict; comment @# @; 1.1 date 2012.12.28.03.03.08; author dholland; state Exp; branches; next ; desc @@ 1.1 log @Fix legacy C. Pass -Wall -W -Wmissing-declarations -Wwrite-strings on gcc45. - avoid implicit int, declare void functions void - return values from non-void functions - put most external declarations properly in header files - use some static and const - fix up a big mess with function pointer casting - use standard includes, don't provide own decls of standard functions - use types matching libc when providing own malloc, printf, and putchar - use functions correctly - silence assorted compiler warnings - fix some bugs exposed by compiler warnings - don't intentionally exercise signed overflow - remove some unused items - add patch comments to other patch (patch-aa) As this includes several fixes and removes some undefined behavior on a commonly reachable code path, bump PKGREVISION. @ text @$NetBSD$ - declare local functions static - declare void functions void - use const for string constants - wrap unused function in the proper matching ifdef - avoid implicit int - fix signed/unsigned mismatch - silence warnings about assignments in conditionals - silence warnings about && and || precedence --- ex_re.c~ 2012-12-27 21:58:42.000000000 +0000 +++ ex_re.c @@@@ -82,32 +82,35 @@@@ static char sccsid[] = "@@(#)ex_re.c 1.37 #include "ex.h" #include "ex_re.h" -int compsub __P((int)); -int dosubcon __P((int, line *)); -int snote __P((register int, register int)); -int comprhs __P((int)); -int confirmed __P((line *)); -int dosub __P((void)); -int ugo __P((int, int)); -int fixcase __P((register int)); -int cerror __P((char *)); -int cclass __P((register char *, register int, int)); +static int compsub __P((int)); +static int dosubcon __P((int, line *)); +static void snote __P((register int, register int)); +static void comprhs __P((int)); +static int confirmed __P((line *)); +static void dosub __P((void)); +static void ugo __P((int, int)); +static int fixcase __P((register int)); +static char *place __P((char *, char *, char *)); +static void cerror __P((const char *)); +static int cclass __P((register const char *, register int, int)); /* * Global, substitute and regular expressions. * Very similar to ed, with some re extensions and * confirmed substitute. */ +void global(k) bool k; { register char *gp; register int c; register line *a1; - char globuf[GBSIZE], *Cwas; + char globuf[GBSIZE]; + const char *Cwas; int lines = lineDOL(); int oinglobal = inglobal; - char *oglobp = globp; + const char *oglobp = globp; Cwas = Command; /* @@@@ -220,6 +223,7 @@@@ brkwh: } } +#ifdef notdef /* used above in a notdef block */ /* * gdelete: delete inside a global command. Handles the * special case g/r.e./d. All lines to be deleted have @@@@ -228,7 +232,8 @@@@ brkwh: * and g/r.e./.,/r.e.2/d are not treated specially. There is no * good reason for this except the question: where to you draw the line? */ -gdelete() +static void +gdelete(void) { register line *a1, *a2, *a3; @@@@ -250,16 +255,19 @@@@ gdelete() dot = dol; change(); } +#endif bool cflag; int scount, slines, stotal; +int substitute(c) int c; { register line *addr; register int n; - int gsubf, hopcount; + int gsubf; + unsigned hopcount; gsubf = compsub(c); if(FIXUNDO) @@@@ -267,7 +275,8 @@@@ substitute(c) stotal = 0; slines = 0; for (addr = addr1; addr <= addr2; addr++) { - scount = hopcount = 0; + scount = 0; + hopcount = 0; if (dosubcon(0, addr) == 0) continue; if (gsubf) { @@@@ -299,7 +308,8 @@@@ substitute(c) return (stotal); } -compsub(ch) +static int +compsub(int ch) { register int seof, c, uselastre; static int gsubf; @@@@ -368,6 +378,7 @@@@ compsub(ch) } } +static void comprhs(seof) int seof; { @@@@ -469,6 +480,7 @@@@ endrhs: *rp++ = 0; } +int getsub() { register char *p; @@@@ -480,6 +492,7 @@@@ getsub() return (0); } +static int dosubcon(f, a) bool f; line *a; @@@@ -494,11 +507,12 @@@@ dosubcon(f, a) return (1); } +static int confirmed(a) line *a; { register int c; - char *yesstr = catgets(catd, 1, 249, "y"); + const char *yesstr = catgets(catd, 1, 249, "y"); int okay = -1; if (cflag == 0) @@@@ -539,6 +553,7 @@@@ again: } #ifdef notdef +int ex_getch() { char c; @@@@ -553,6 +568,7 @@@@ ex_getch() } #endif /* notdef */ +static void ugo(cnt, with) int with; int cnt; @@@@ -567,7 +583,8 @@@@ ugo(cnt, with) int casecnt; bool destuc; -dosub() +static void +dosub(void) { register char *lp, *sp, *rp; int c; @@@@ -585,7 +602,7 @@@@ dosub() while (lp < loc1) *sp++ = *lp++; casecnt = 0; - while (c = *rp++) { + while ((c = *rp++) != 0) { #ifdef BIT8 c = cuc(c); q = *qp++; @@@@ -661,12 +678,13 @@@@ ovflo: } lp = loc2; loc2 = sp + (linebuf - genbuf); - while (*sp++ = *lp++) + while ((*sp++ = *lp++) != 0) if (sp >= &genbuf[LBSIZE]) goto ovflo; strcLIN(genbuf); } +static int fixcase(c) register int c; { @@@@ -683,7 +701,7 @@@@ fixcase(c) return (c); } -char * +static char * place(sp, l1, l2) register char *sp, *l1, *l2; { @@@@ -696,6 +714,7 @@@@ place(sp, l1, l2) return (sp); } +static void snote(total, lines) register int total, lines; { @@@@ -709,16 +728,17 @@@@ snote(total, lines) flush(); } +static void cerror(s) - char *s; + const char *s; { expbuf[0] = '\0'; error(s); } #ifdef UXRE -refree(rp) -struct regexp *rp; +static void +refree(struct regexp *rp) { struct regexp *r1 = NULL, *r2 = NULL; @@@@ -986,8 +1006,7 @@@@ complex: cerror(catgets(catd, 1, 139, } int -execute(gf, addr) -line *addr; +execute(int gf, line *addr) { char *p; int c; @@@@ -1041,6 +1060,7 @@@@ line *addr; goto complex; \ } +int compile(eof, oknl) int eof; int oknl; @@@@ -1123,7 +1143,7 @@@@ complex: return (eof); } if (value(MAGIC)) { - if (c != '*' && (c != '\\' || peekchar() != '{') || + if ((c != '*' && (c != '\\' || peekchar() != '{')) || ep == expbuf) { lastep = ep; } @@@@ -1349,7 +1369,7 @@@@ magic: "Badly formed re|Missing closing delimiter for regular expression")); case '$': - if (peekchar() == eof || peekchar() == EOF || oknl && peekchar() == '\n') { + if (peekchar() == eof || peekchar() == EOF || (oknl && peekchar() == '\n')) { *ep++ = CDOL; continue; } @@@@ -1370,17 +1390,19 @@@@ defchar: } } +int same(a, b) register int a, b; { - return (a == b || value(IGNORECASE) && - ((islower(a) && toupper(a) == b) || (islower(b) && toupper(b) == a))); + return (a == b || + (value(IGNORECASE) && + ((islower(a) && toupper(a) == b) || + (islower(b) && toupper(b) == a)))); } -ecmp(a, b, count) - register char *a, *b; - register int count; +static int +ecmp(register char *a, register char *b, register int count) { while (count--) if (!same(*a++, *b++)) @@@@ -1390,8 +1412,8 @@@@ ecmp(a, b, count) char *locs; -execute(gf, addr) - line *addr; +int +execute(int gf, line *addr) { register char *p1, *p2; register int c; @@@@ -1437,8 +1459,8 @@@@ execute(gf, addr) return (0); } -getrnge(str) - register char *str; +static void +getrnge(register char *str) { low = *str++ & 0377; siz = (*str & 0377) == 255 ? 20000 : (*str & 0377) - low; @@@@ -1446,6 +1468,7 @@@@ getrnge(str) #define uletter(c) (isalpha(c) || c == '_') +int advance(lp, ep) register char *lp, *ep; { @@@@ -1628,8 +1651,9 @@@@ star: } } +static int cclass(set, c, af) - register char *set; + register const char *set; register int c; int af; { @