-/* $OpenBSD: compile.c,v 1.38 2015/06/23 22:52:55 millert Exp $ */
+/* $OpenBSD: compile.c,v 1.39 2015/10/26 14:08:47 mmcc Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
for (;;) {
if ((p = cu_fgets(&lbuf, &bufsize)) == NULL) {
if (stack != 0)
- err(COMPILE, "unexpected EOF (pending }'s)");
+ error(COMPILE, "unexpected EOF (pending }'s)");
return (link);
}
nonsel: /* Now parse the command */
if (!*p)
- err(COMPILE, "command expected");
+ error(COMPILE, "command expected");
cmd->code = *p;
for (fp = cmd_fmts; fp->code; fp++)
if (fp->code == *p)
break;
if (!fp->code)
- err(COMPILE, "invalid command code %c", *p);
+ error(COMPILE, "invalid command code %c", *p);
if (naddr > fp->naddr)
- err(COMPILE,
+ error(COMPILE,
"command %c expects up to %d address(es), found %d",
*p, fp->naddr, naddr);
switch (fp->args) {
*/
cmd->nonsel = 1;
if (stack == 0)
- err(COMPILE, "unexpected }");
+ error(COMPILE, "unexpected }");
cmd2 = stack;
stack = cmd2->next;
cmd2->next = cmd;
goto semicolon;
}
if (*p)
- err(COMPILE,
+ error(COMPILE,
"extra characters at the end of %c command", cmd->code);
break;
case TEXT: /* a c i */
p++;
EATSPACE();
if (*p != '\\')
- err(COMPILE, "command %c expects \\ followed by"
+ error(COMPILE, "command %c expects \\ followed by"
" text", cmd->code);
p++;
EATSPACE();
if (*p)
- err(COMPILE, "extra characters after \\ at the"
+ error(COMPILE, "extra characters after \\ at the"
" end of %c command", cmd->code);
cmd->t = compile_text();
break;
p++;
EATSPACE();
if (*p == '\0')
- err(COMPILE, "filename expected");
+ error(COMPILE, "filename expected");
cmd->t = duptoeol(p, "w command", NULL);
if (aflag)
cmd->u.fd = -1;
else if ((cmd->u.fd = open(p,
O_WRONLY|O_APPEND|O_CREAT|O_TRUNC,
DEFFILEMODE)) == -1)
- err(FATAL, "%s: %s", p, strerror(errno));
+ error(FATAL, "%s: %s", p, strerror(errno));
break;
case RFILE: /* r */
p++;
EATSPACE();
cmd->t = duptoeol(p, "label", &p);
if (strlen(cmd->t) == 0)
- err(COMPILE, "empty label");
+ error(COMPILE, "empty label");
enterlabel(cmd);
if (*p == ';') {
p++;
case SUBST: /* s */
p++;
if (*p == '\0' || *p == '\\')
- err(COMPILE, "substitute pattern can not be"
+ error(COMPILE, "substitute pattern can not be"
" delimited by newline or backslash");
cmd->u.s = xmalloc(sizeof(struct s_subst));
p = compile_re(p, &cmd->u.s->re);
if (p == NULL)
- err(COMPILE, "unterminated substitute pattern");
+ error(COMPILE, "unterminated substitute pattern");
--p;
p = compile_subst(p, cmd->u.s);
p = compile_flags(p, cmd->u.s);
goto semicolon;
}
if (*p)
- err(COMPILE, "extra text at the end of a"
+ error(COMPILE, "extra text at the end of a"
" transform command");
break;
}
if (c == '\0')
return (NULL);
else if (c == '\\')
- err(COMPILE, "\\ can not be used as a string delimiter");
+ error(COMPILE, "\\ can not be used as a string delimiter");
else if (c == '\n')
- err(COMPILE, "newline can not be used as a string delimiter");
+ error(COMPILE, "newline can not be used as a string delimiter");
while (*p) {
if (*p == '[' && *p != c) {
if ((d = compile_ccl(&p, d)) == NULL)
- err(COMPILE, "unbalanced brackets ([])");
+ error(COMPILE, "unbalanced brackets ([])");
continue;
} else if (*p == '\\' && p[1] == '[') {
*d++ = *p++;
}
*repp = xmalloc(sizeof(regex_t));
if (p && (eval = regcomp(*repp, re, Eflag ? REG_EXTENDED : 0)) != 0)
- err(COMPILE, "RE error: %s", strregerror(eval, *repp));
+ error(COMPILE, "RE error: %s", strregerror(eval, *repp));
if (maxnsub < (*repp)->re_nsub)
maxnsub = (*repp)->re_nsub;
free(re);
ref = *p - '0';
if (s->re != NULL &&
ref > s->re->re_nsub)
- err(COMPILE,
+ error(COMPILE,
"\\%c not defined in the RE", *p);
if (s->maxbref < ref)
s->maxbref = ref;
s->new = xrealloc(text, size);
return (p);
} else if (*p == '\n') {
- err(COMPILE,
+ error(COMPILE,
"unescaped newline inside substitute pattern");
/* NOTREACHED */
}
}
size += sp - op;
} while ((p = cu_fgets(&lbuf, &bufsize)));
- err(COMPILE, "unterminated substitute in regular expression");
+ error(COMPILE, "unterminated substitute in regular expression");
/* NOTREACHED */
}
switch (*p) {
case 'g':
if (gn)
- err(COMPILE, "more than one number or 'g' in"
+ error(COMPILE, "more than one number or 'g' in"
" substitute flags");
gn = 1;
s->n = 0;
case '4': case '5': case '6':
case '7': case '8': case '9':
if (gn)
- err(COMPILE, "more than one number or 'g' in"
+ error(COMPILE, "more than one number or 'g' in"
" substitute flags");
gn = 1;
l = strtol(p, &p, 10);
if (l <= 0 || l >= INT_MAX)
- err(COMPILE,
+ error(COMPILE,
"number in substitute flags out of range");
s->n = (int)l;
continue;
p++;
#ifdef HISTORIC_PRACTICE
if (*p != ' ') {
- err(WARNING, "space missing before w wfile");
+ error(WARNING, "space missing before w wfile");
return (p);
}
#endif
if (*p == '\n')
break;
if (q >= eq)
- err(COMPILE, "wfile too long");
+ error(COMPILE, "wfile too long");
*q++ = *p++;
}
*q = '\0';
if (q == wfile)
- err(COMPILE, "no wfile specified");
+ error(COMPILE, "no wfile specified");
s->wfile = strdup(wfile);
if (!aflag && (s->wfd = open(wfile,
O_WRONLY|O_APPEND|O_CREAT|O_TRUNC,
DEFFILEMODE)) == -1)
- err(FATAL, "%s: %s", wfile, strerror(errno));
+ error(FATAL, "%s: %s", wfile, strerror(errno));
return (p);
default:
- err(COMPILE,
+ error(COMPILE,
"bad flag in substitute command: '%c'", *p);
break;
}
char *old = NULL, *new = NULL;
if (*p == '\0' || *p == '\\')
- err(COMPILE,
+ error(COMPILE,
"transform pattern can not be delimited by newline or backslash");
old = xmalloc(strlen(p) + 1);
p = compile_delimited(p, old, 1);
if (p == NULL) {
- err(COMPILE, "unterminated transform source string");
+ error(COMPILE, "unterminated transform source string");
goto bad;
}
new = xmalloc(strlen(p) + 1);
p = compile_delimited(--p, new, 1);
if (p == NULL) {
- err(COMPILE, "unterminated transform target string");
+ error(COMPILE, "unterminated transform target string");
goto bad;
}
EATSPACE();
if (strlen(new) != strlen(old)) {
- err(COMPILE, "transform strings are not the same length");
+ error(COMPILE, "transform strings are not the same length");
goto bad;
}
/* We assume characters are 8 bits */
case '/': /* Context address */
p = compile_re(p, &a->u.r);
if (p == NULL)
- err(COMPILE, "unterminated regular expression");
+ error(COMPILE, "unterminated regular expression");
a->type = AT_RE;
return (p);
a->u.l = strtoul(p, &end, 10);
return (end);
default:
- err(COMPILE, "expected context address");
+ error(COMPILE, "expected context address");
return (NULL);
}
}
*s = '\0';
}
if (ws)
- err(WARNING, "whitespace after %s", ctype);
+ error(WARNING, "whitespace after %s", ctype);
len = s - start + 1;
if (semi)
*semi = s;
break;
}
if ((cp->u.c = findlabel(cp->t)) == NULL)
- err(COMPILE2, "undefined label '%s'", cp->t);
+ error(COMPILE2, "undefined label '%s'", cp->t);
free(cp->t);
break;
case '{':
lhp = &labels[h & LHMASK];
for (lh = *lhp; lh != NULL; lh = lh->lh_next)
if (lh->lh_hash == h && strcmp(cp->t, lh->lh_cmd->t) == 0)
- err(COMPILE2, "duplicate label '%s'", cp->t);
+ error(COMPILE2, "duplicate label '%s'", cp->t);
lh = xmalloc(sizeof *lh);
lh->lh_next = *lhp;
lh->lh_hash = h;
for (lh = labels[i]; lh != NULL; lh = next) {
next = lh->lh_next;
if (!lh->lh_ref)
- err(WARNING, "unused label '%s'",
+ error(WARNING, "unused label '%s'",
lh->lh_cmd->t);
free(lh);
}
-/* $OpenBSD: main.c,v 1.28 2015/10/25 20:18:37 tobias Exp $ */
+/* $OpenBSD: main.c,v 1.29 2015/10/26 14:08:47 mmcc Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
if (inplace != NULL) {
if (pledge("stdio rpath wpath cpath fattr", NULL) == -1)
- err(1, "pledge");
+ error(1, "pledge");
} else {
if (pledge("stdio rpath wpath cpath", NULL) == -1)
- err(1, "pledge");
+ error(1, "pledge");
}
/* First usage case; script is the first arg */
process();
cfclose(prog, NULL);
if (fclose(stdout))
- err(FATAL, "stdout: %s", strerror(errno));
+ error(FATAL, "stdout: %s", strerror(errno));
exit (rval);
}
switch (script->type) {
case CU_FILE:
if ((f = fopen(script->s, "r")) == NULL)
- err(FATAL,
+ error(FATAL,
"%s: %s", script->s, strerror(errno));
fname = script->s;
state = ST_FILE;
/* stdin? */
if (files->fname == NULL) {
if (inplace != NULL)
- err(FATAL, "-i may not be used with stdin");
+ error(FATAL, "-i may not be used with stdin");
infile = stdin;
fname = "stdin";
outfile = stdout;
fclose(infile);
if (*oldfname != '\0') {
if (rename(fname, oldfname) != 0) {
- err(WARNING, "rename()");
+ error(WARNING, "rename()");
unlink(tmpfname);
exit(1);
}
fname = files->fname;
if (inplace != NULL) {
if (lstat(fname, &sb) != 0)
- err(1, "%s: %s", fname,
+ error(1, "%s: %s", fname,
strerror(errno ? errno : EIO));
if (!S_ISREG(sb.st_mode))
- err(FATAL, "%s: %s %s", fname,
+ error(FATAL, "%s: %s %s", fname,
"in-place editing only",
"works for regular files");
if (*inplace != '\0') {
len = strlcat(oldfname, inplace,
sizeof(oldfname));
if (len > sizeof(oldfname))
- err(FATAL, "%s: name too long", fname);
+ error(FATAL, "%s: name too long", fname);
}
len = snprintf(tmpfname, sizeof(tmpfname), "%s/sedXXXXXXXXXX",
dirname(fname));
if (len >= sizeof(tmpfname))
- err(FATAL, "%s: name too long", fname);
+ error(FATAL, "%s: name too long", fname);
if ((fd = mkstemp(tmpfname)) == -1)
- err(FATAL, "%s", fname);
+ error(FATAL, "%s", fname);
if ((outfile = fdopen(fd, "w")) == NULL) {
unlink(tmpfname);
- err(FATAL, "%s", fname);
+ error(FATAL, "%s", fname);
}
fchown(fileno(outfile), sb.st_uid, sb.st_gid);
fchmod(fileno(outfile), sb.st_mode & ALLPERMS);
outfname = "stdout";
}
if ((infile = fopen(fname, "r")) == NULL) {
- err(WARNING, "%s", strerror(errno));
+ error(WARNING, "%s", strerror(errno));
rval = 1;
continue;
}
*/
p = fgetln(infile, &len);
if (ferror(infile))
- err(FATAL, "%s: %s", fname, strerror(errno ? errno : EIO));
+ error(FATAL, "%s: %s", fname, strerror(errno ? errno : EIO));
if (len != 0 && p[len - 1] == '\n') {
sp->append_newline = 1;
len--;
-/* $OpenBSD: process.c,v 1.26 2015/07/20 18:24:15 jasper Exp $ */
+/* $OpenBSD: process.c,v 1.27 2015/10/26 14:08:47 mmcc Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
if (cp->u.fd == -1 && (cp->u.fd = open(cp->t,
O_WRONLY|O_APPEND|O_CREAT|O_TRUNC,
DEFFILEMODE)) == -1)
- err(FATAL, "%s: %s",
+ error(FATAL, "%s: %s",
cp->t, strerror(errno));
if (write(cp->u.fd, ps, psl) != psl ||
write(cp->u.fd, "\n", 1) != 1)
- err(FATAL, "%s: %s",
+ error(FATAL, "%s: %s",
cp->t, strerror(errno));
break;
case 'x':
if (re == NULL) {
if (defpreg != NULL && cp->u.s->maxbref > defpreg->re_nsub) {
linenum = cp->u.s->linenum;
- err(COMPILE, "\\%d not defined in the RE",
+ error(COMPILE, "\\%d not defined in the RE",
cp->u.s->maxbref);
}
}
if (cp->u.s->wfile && !pd) {
if (cp->u.s->wfd == -1 && (cp->u.s->wfd = open(cp->u.s->wfile,
O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1)
- err(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno));
+ error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno));
if (write(cp->u.s->wfd, ps, psl) != psl ||
write(cp->u.s->wfd, "\n", 1) != 1)
- err(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno));
+ error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno));
}
return (1);
}
break;
}
if (ferror(outfile))
- err(FATAL, "%s: %s", outfname, strerror(errno ? errno : EIO));
+ error(FATAL, "%s: %s", outfname, strerror(errno ? errno : EIO));
appendx = sdone = 0;
}
(void)fputc('$', outfile);
(void)fputc('\n', outfile);
if (ferror(outfile))
- err(FATAL, "%s: %s", outfname, strerror(errno ? errno : EIO));
+ error(FATAL, "%s: %s", outfname, strerror(errno ? errno : EIO));
}
static inline int
if (preg == NULL) {
if (defpreg == NULL)
- err(FATAL, "first RE may not be empty");
+ error(FATAL, "first RE may not be empty");
} else
defpreg = preg;
case REG_NOMATCH:
return (0);
}
- err(FATAL, "RE error: %s", strregerror(eval, defpreg));
+ error(FATAL, "RE error: %s", strregerror(eval, defpreg));
/* NOTREACHED */
}
switch (cp->code) {
case 's':
if (cp->u.s->wfd != -1 && close(cp->u.s->wfd))
- err(FATAL,
+ error(FATAL,
"%s: %s", cp->u.s->wfile, strerror(errno));
cp->u.s->wfd = -1;
break;
case 'w':
if (cp->u.fd != -1 && close(cp->u.fd))
- err(FATAL, "%s: %s", cp->t, strerror(errno));
+ error(FATAL, "%s: %s", cp->t, strerror(errno));
cp->u.fd = -1;
break;
case '{':