aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c47
-rw-r--r--editors/ed.c2
2 files changed, 28 insertions, 21 deletions
diff --git a/editors/awk.c b/editors/awk.c
index d6dcd9578..ae7ca23d4 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -47,7 +47,7 @@ typedef struct var_s {
47typedef struct chain_s { 47typedef struct chain_s {
48 struct node_s *first; 48 struct node_s *first;
49 struct node_s *last; 49 struct node_s *last;
50 char *programname; 50 const char *programname;
51} chain; 51} chain;
52 52
53/* Function */ 53/* Function */
@@ -399,7 +399,7 @@ static int nextrec, nextfile;
399static node *break_ptr, *continue_ptr; 399static node *break_ptr, *continue_ptr;
400static rstream *iF; 400static rstream *iF;
401static xhash *vhash, *ahash, *fdhash, *fnhash; 401static xhash *vhash, *ahash, *fdhash, *fnhash;
402static char *programname; 402static const char *programname;
403static short lineno; 403static short lineno;
404static int is_f0_split; 404static int is_f0_split;
405static int nfields; 405static int nfields;
@@ -703,7 +703,7 @@ static var *setvar_i(var *v, double value)
703 return v; 703 return v;
704} 704}
705 705
706static char *getvar_s(var *v) 706static const char *getvar_s(var *v)
707{ 707{
708 /* if v is numeric and has no cached string, convert it to string */ 708 /* if v is numeric and has no cached string, convert it to string */
709 if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) { 709 if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) {
@@ -995,7 +995,7 @@ static node *new_node(uint32_t info)
995 return n; 995 return n;
996} 996}
997 997
998static node *mk_re_node(char *s, node *n, regex_t *re) 998static node *mk_re_node(const char *s, node *n, regex_t *re)
999{ 999{
1000 n->info = OC_REGEXP; 1000 n->info = OC_REGEXP;
1001 n->l.re = re; 1001 n->l.re = re;
@@ -1347,7 +1347,7 @@ static void parse_program(char *p)
1347 1347
1348/* -------- program execution part -------- */ 1348/* -------- program execution part -------- */
1349 1349
1350static node *mk_splitter(char *s, tsplitter *spl) 1350static node *mk_splitter(const char *s, tsplitter *spl)
1351{ 1351{
1352 regex_t *re, *ire; 1352 regex_t *re, *ire;
1353 node *n; 1353 node *n;
@@ -1375,7 +1375,7 @@ static node *mk_splitter(char *s, tsplitter *spl)
1375static regex_t *as_regex(node *op, regex_t *preg) 1375static regex_t *as_regex(node *op, regex_t *preg)
1376{ 1376{
1377 var *v; 1377 var *v;
1378 char *s; 1378 const char *s;
1379 1379
1380 if ((op->info & OPCLSMASK) == OC_REGEXP) { 1380 if ((op->info & OPCLSMASK) == OC_REGEXP) {
1381 return icase ? op->r.ire : op->l.re; 1381 return icase ? op->r.ire : op->l.re;
@@ -1419,7 +1419,7 @@ static void fsrealloc(int size)
1419 nfields = size; 1419 nfields = size;
1420} 1420}
1421 1421
1422static int awk_split(char *s, node *spl, char **slist) 1422static int awk_split(const char *s, node *spl, char **slist)
1423{ 1423{
1424 int l, n = 0; 1424 int l, n = 0;
1425 char c[4]; 1425 char c[4];
@@ -1427,7 +1427,8 @@ static int awk_split(char *s, node *spl, char **slist)
1427 regmatch_t pmatch[2]; 1427 regmatch_t pmatch[2];
1428 1428
1429 /* in worst case, each char would be a separate field */ 1429 /* in worst case, each char would be a separate field */
1430 *slist = s1 = xstrndup(s, strlen(s) * 2 + 3); 1430 *slist = s1 = xzalloc(strlen(s) * 2 + 3);
1431 strcpy(s1, s);
1431 1432
1432 c[0] = c[1] = (char)spl->info; 1433 c[0] = c[1] = (char)spl->info;
1433 c[2] = c[3] = '\0'; 1434 c[2] = c[3] = '\0';
@@ -1436,8 +1437,9 @@ static int awk_split(char *s, node *spl, char **slist)
1436 if ((spl->info & OPCLSMASK) == OC_REGEXP) { /* regex split */ 1437 if ((spl->info & OPCLSMASK) == OC_REGEXP) { /* regex split */
1437 while (*s) { 1438 while (*s) {
1438 l = strcspn(s, c+2); 1439 l = strcspn(s, c+2);
1439 if (regexec(icase ? spl->r.ire : spl->l.re, s, 1, pmatch, 0) == 0 && 1440 if (regexec(icase ? spl->r.ire : spl->l.re, s, 1, pmatch, 0) == 0
1440 pmatch[0].rm_so <= l) { 1441 && pmatch[0].rm_so <= l
1442 ) {
1441 l = pmatch[0].rm_so; 1443 l = pmatch[0].rm_so;
1442 if (pmatch[0].rm_eo == 0) { l++; pmatch[0].rm_eo++; } 1444 if (pmatch[0].rm_eo == 0) { l++; pmatch[0].rm_eo++; }
1443 } else { 1445 } else {
@@ -1510,7 +1512,8 @@ static void split_f0(void)
1510static void handle_special(var *v) 1512static void handle_special(var *v)
1511{ 1513{
1512 int n; 1514 int n;
1513 char *b, *sep, *s; 1515 char *b;
1516 const char *sep, *s;
1514 int sl, l, len, i, bsize; 1517 int sl, l, len, i, bsize;
1515 1518
1516 if (!(v->type & VF_SPECIAL)) 1519 if (!(v->type & VF_SPECIAL))
@@ -1737,7 +1740,8 @@ static int fmt_num(char *b, int size, const char *format, double n, int int_as_i
1737static char *awk_printf(node *n) 1740static char *awk_printf(node *n)
1738{ 1741{
1739 char *b = NULL; 1742 char *b = NULL;
1740 char *fmt, *s, *s1, *f; 1743 char *fmt, *s, *f;
1744 const char *s1;
1741 int i, j, incr, bsize; 1745 int i, j, incr, bsize;
1742 char c, c1; 1746 char c, c1;
1743 var *v, *arg; 1747 var *v, *arg;
@@ -1793,10 +1797,11 @@ static char *awk_printf(node *n)
1793 * all matches. If src or dst is NULL, use $0. If ex=TRUE, enable 1797 * all matches. If src or dst is NULL, use $0. If ex=TRUE, enable
1794 * subexpression matching (\1-\9) 1798 * subexpression matching (\1-\9)
1795 */ 1799 */
1796static int awk_sub(node *rn, char *repl, int nm, var *src, var *dest, int ex) 1800static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int ex)
1797{ 1801{
1798 char *ds = NULL; 1802 char *ds = NULL;
1799 char *sp, *s; 1803 const char *s;
1804 const char *sp;
1800 int c, i, j, di, rl, so, eo, nbs, n, dssize; 1805 int c, i, j, di, rl, so, eo, nbs, n, dssize;
1801 regmatch_t pmatch[10]; 1806 regmatch_t pmatch[10];
1802 regex_t sreg, *re; 1807 regex_t sreg, *re;
@@ -1865,7 +1870,7 @@ static var *exec_builtin(node *op, var *res)
1865 var *tv; 1870 var *tv;
1866 node *an[4]; 1871 node *an[4];
1867 var *av[4]; 1872 var *av[4];
1868 char *as[4]; 1873 const char *as[4];
1869 regmatch_t pmatch[2]; 1874 regmatch_t pmatch[2];
1870 regex_t sreg, *re; 1875 regex_t sreg, *re;
1871 static tsplitter tspl; 1876 static tsplitter tspl;
@@ -1998,8 +2003,10 @@ static var *exec_builtin(node *op, var *res)
1998 tt = getvar_i(av[1]); 2003 tt = getvar_i(av[1]);
1999 else 2004 else
2000 time(&tt); 2005 time(&tt);
2001 s = (nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y"; 2006 //s = (nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y";
2002 i = strftime(buf, MAXVARFMT, s, localtime(&tt)); 2007 i = strftime(buf, MAXVARFMT,
2008 ((nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y"),
2009 localtime(&tt));
2003 buf[i] = '\0'; 2010 buf[i] = '\0';
2004 setvar_s(res, buf); 2011 setvar_s(res, buf);
2005 break; 2012 break;
@@ -2054,7 +2061,7 @@ static var *evaluate(node *op, var *res)
2054 var *v1; 2061 var *v1;
2055 union { 2062 union {
2056 var *v; 2063 var *v;
2057 char *s; 2064 const char *s;
2058 double d; 2065 double d;
2059 int i; 2066 int i;
2060 } L, R; 2067 } L, R;
@@ -2168,7 +2175,7 @@ static var *evaluate(node *op, var *res)
2168 } else { /* OC_PRINTF */ 2175 } else { /* OC_PRINTF */
2169 L.s = awk_printf(op1); 2176 L.s = awk_printf(op1);
2170 fputs(L.s, X.F); 2177 fputs(L.s, X.F);
2171 free(L.s); 2178 free((char*)L.s);
2172 } 2179 }
2173 fflush(X.F); 2180 fflush(X.F);
2174 break; 2181 break;
@@ -2610,7 +2617,7 @@ static rstream *next_input_file(void)
2610{ 2617{
2611 static rstream rsm; 2618 static rstream rsm;
2612 FILE *F = NULL; 2619 FILE *F = NULL;
2613 char *fname, *ind; 2620 const char *fname, *ind;
2614 static int files_happen = FALSE; 2621 static int files_happen = FALSE;
2615 2622
2616 if (rsm.F) fclose(rsm.F); 2623 if (rsm.F) fclose(rsm.F);
diff --git a/editors/ed.c b/editors/ed.c
index 3aca75912..5a48fbe75 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -401,7 +401,7 @@ static void subCommand(const char * cmd, int num1, int num2)
401 if (cp) 401 if (cp)
402 *cp++ = '\0'; 402 *cp++ = '\0';
403 else 403 else
404 cp = ""; 404 cp = (char*)"";
405 405
406 while (*cp) switch (*cp++) { 406 while (*cp) switch (*cp++) {
407 case 'g': 407 case 'g':