-/* $OpenBSD: format.c,v 1.85 2015/10/23 16:02:21 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.86 2015/10/25 08:59:26 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
typedef void (*format_cb)(struct format_tree *, struct format_entry *);
void format_job_callback(struct job *);
-const char *format_job_get(struct format_tree *, const char *);
+char *format_job_get(struct format_tree *, const char *);
void format_job_timer(int, short, void *);
void format_cb_host(struct format_tree *, struct format_entry *);
}
/* Find a job. */
-const char *
+char *
format_job_get(struct format_tree *ft, const char *cmd)
{
struct format_job fj0, *fj;
if (ft->flags & FORMAT_STATUS)
fj->status = 1;
- return (fj->out);
+ return (format_expand(ft, fj->out));
}
/* Remove old jobs. */
char *
format_expand(struct format_tree *ft, const char *fmt)
{
- char *buf, *tmp, *cmd;
+ char *buf, *tmp, *cmd, *out;
const char *ptr, *s, *saved = fmt;
- size_t off, len, n, slen;
+ size_t off, len, n, outlen;
int ch, brackets;
if (fmt == NULL)
tmp[n] = '\0';
cmd = format_expand(ft, tmp);
- s = format_job_get(ft, cmd);
- slen = strlen(s);
+ out = format_job_get(ft, cmd);
+ outlen = strlen(out);
free(cmd);
free(tmp);
- while (len - off < slen + 1) {
+ while (len - off < outlen + 1) {
buf = xreallocarray(buf, 2, len);
len *= 2;
}
- memcpy(buf + off, s, slen);
- off += slen;
+ memcpy(buf + off, out, outlen);
+ off += outlen;
+
+ free(out);
fmt += n + 1;
continue;