awk: style fixes; remove one xstrdup/free pair; testsuite

This commit is contained in:
Denis Vlasenko 2007-07-18 18:31:11 +00:00
parent 91afdf8096
commit b78c782c85

View File

@ -1446,7 +1446,7 @@ static node *mk_splitter(const char *s, tsplitter *spl)
n = &spl->n;
if ((n->info & OPCLSMASK) == OC_REGEXP) {
regfree(re);
regfree(ire);
regfree(ire); // TODO: nuke ire, use re+1?
}
if (strlen(s) > 1) {
mk_re_node(s, n, re);
@ -1511,7 +1511,7 @@ static int awk_split(const char *s, node *spl, char **slist)
int l, n = 0;
char c[4];
char *s1;
regmatch_t pmatch[2];
regmatch_t pmatch[2]; // TODO: why [2]? [1] is enough...
/* in worst case, each char would be a separate field */
*slist = s1 = xzalloc(strlen(s) * 2 + 3);
@ -1946,7 +1946,8 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int
sp += eo;
if (i == nm) break;
if (eo == so) {
if (! (ds[di++] = *sp++)) break;
ds[di] = *sp++;
if (!ds[di++]) break;
}
}
@ -2797,13 +2798,16 @@ int awk_main(int argc, char **argv)
/* Huh, people report that sometimes environ is NULL. Oh well. */
if (environ) for (envp = environ; *envp; envp++) {
char *s = xstrdup(*envp);
/* environ is writable, thus we don't strdup it needlessly */
char *s = *envp;
char *s1 = strchr(s, '=');
if (s1) {
*s1++ = '\0';
setvar_u(findvar(iamarray(intvar[ENVIRON]), s), s1);
*s1 = '\0';
/* Both findvar and setvar_u take const char*
* as 2nd arg -> environment is not trashed */
setvar_u(findvar(iamarray(intvar[ENVIRON]), s), s1 + 1);
*s1 = '=';
}
free(s);
}
opt_complementary = "v::";
opt = getopt32(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &g_progname, &opt_W);