version 1.32, 2017/02/22 14:09:09 |
version 1.33, 2017/12/13 16:06:34 |
|
|
static int substitute(struct s_command *); |
static int substitute(struct s_command *); |
|
|
struct s_appends *appends; /* Array of pointers to strings to append. */ |
struct s_appends *appends; /* Array of pointers to strings to append. */ |
static int appendx; /* Index into appends array. */ |
static size_t appendx; /* Index into appends array. */ |
size_t appendnum; /* Size of appends array. */ |
size_t appendnum; /* Size of appends array. */ |
|
|
static int lastaddr; /* Set by applies if last address of a range. */ |
static int lastaddr; /* Set by applies if last address of a range. */ |
|
|
DEFFILEMODE)) == -1) |
DEFFILEMODE)) == -1) |
error(FATAL, "%s: %s", |
error(FATAL, "%s: %s", |
cp->t, strerror(errno)); |
cp->t, strerror(errno)); |
if (write(cp->u.fd, ps, psl) != psl || |
if ((size_t)write(cp->u.fd, ps, psl) != psl || |
write(cp->u.fd, "\n", 1) != 1) |
write(cp->u.fd, "\n", 1) != 1) |
error(FATAL, "%s: %s", |
error(FATAL, "%s: %s", |
cp->t, strerror(errno)); |
cp->t, strerror(errno)); |
|
|
regex_t *re; |
regex_t *re; |
regoff_t slen; |
regoff_t slen; |
int n, lastempty; |
int n, lastempty; |
size_t le = 0; |
regoff_t le = 0; |
char *s; |
char *s; |
|
|
s = ps; |
s = ps; |
|
|
if (cp->u.s->wfd == -1 && (cp->u.s->wfd = open(cp->u.s->wfile, |
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) |
O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) |
error(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 || |
if ((size_t)write(cp->u.s->wfd, ps, psl) != psl || |
write(cp->u.s->wfd, "\n", 1) != 1) |
write(cp->u.s->wfd, "\n", 1) != 1) |
error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno)); |
error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno)); |
} |
} |
|
|
flush_appends(void) |
flush_appends(void) |
{ |
{ |
FILE *f; |
FILE *f; |
int count, i; |
size_t count, idx; |
char buf[8 * 1024]; |
char buf[8 * 1024]; |
|
|
for (i = 0; i < appendx; i++) |
for (idx = 0; idx < appendx; idx++) |
switch (appends[i].type) { |
switch (appends[idx].type) { |
case AP_STRING: |
case AP_STRING: |
fwrite(appends[i].s, sizeof(char), appends[i].len, |
fwrite(appends[idx].s, sizeof(char), appends[idx].len, |
outfile); |
outfile); |
break; |
break; |
case AP_FILE: |
case AP_FILE: |
|
|
* would be truly bizarre, but possible. It's probably |
* would be truly bizarre, but possible. It's probably |
* not that big a performance win, anyhow. |
* not that big a performance win, anyhow. |
*/ |
*/ |
if ((f = fopen(appends[i].s, "r")) == NULL) |
if ((f = fopen(appends[idx].s, "r")) == NULL) |
break; |
break; |
while ((count = fread(buf, sizeof(char), sizeof(buf), f))) |
while ((count = fread(buf, sizeof(char), sizeof(buf), f))) |
(void)fwrite(buf, sizeof(char), count, outfile); |
(void)fwrite(buf, sizeof(char), count, outfile); |