struct script_stream {
struct timeval oldtime; /* last update */
- struct script_log *logs; /* logs where to write data from stream */
+ struct script_log **logs; /* logs where to write data from stream */
size_t nlogs; /* number of logs */
};
size_t i;
for (i = 0; i < stream->nlogs; i++) {
- struct script_log *log = &stream->logs[i];
-
- if (strcmp(stream->logs[i].filename, name) == 0)
+ struct script_log *log = stream->logs[i];
+ if (strcmp(log->filename, name) == 0)
return log;
}
return NULL;
{
struct script_log *log;
- log = get_log_by_name(&ctl->out, filename);
- if (!log)
- log = get_log_by_name(&ctl->in, filename);
+ assert(ctl);
+ assert(filename);
+ assert(stream);
+
+ log = get_log_by_name(stream, filename);
+ if (log)
+ return log; /* already defined */
+
+ log = get_log_by_name(stream == &ctl->out ? &ctl->in : &ctl->out, filename);
if (!log) {
/* create a new log */
- stream->logs = xrealloc(stream->logs,
- (stream->nlogs + 1) * sizeof(*log));
- log = &stream->logs[stream->nlogs];
- stream->nlogs++;
-
- memset(log, 0, sizeof(*log));
- if (filename)
- log->filename = xstrdup(filename);
+ log = xcalloc(1, sizeof(*log));
+ log->filename = xstrdup(filename);
log->format = format;
}
+ /* add log to the stream */
+ stream->logs = xrealloc(stream->logs,
+ (stream->nlogs + 1) * sizeof(log));
+ stream->logs[stream->nlogs] = log;
+ stream->nlogs++;
+
return log;
}
uint64_t outsz = 0;
for (i = 0; i < stream->nlogs; i++)
- outsz += log_write(ctl, &stream->logs[i], buf, bytes);
+ outsz += log_write(ctl, stream->logs[i], buf, bytes);
return outsz;
}
/* close all output logs */
for (i = 0; i < ctl->out.nlogs; i++)
- log_close(ctl, &ctl->out.logs[i], msg, status);
+ log_close(ctl, ctl->out.logs[i], msg, status);
/* close all input logs */
for (i = 0; i < ctl->in.nlogs; i++)
- log_close(ctl, &ctl->in.logs[i], msg, status);
+ log_close(ctl, ctl->in.logs[i], msg, status);
if (!ctl->quiet)
printf(_("Script done.\n"));
/* start all output logs */
for (i = 0; i < ctl->out.nlogs; i++)
- log_start(ctl, &ctl->out.logs[i]);
+ log_start(ctl, ctl->out.logs[i]);
/* start all input logs */
for (i = 0; i < ctl->in.nlogs; i++)
- log_start(ctl, &ctl->in.logs[i]);
+ log_start(ctl, ctl->in.logs[i]);
while (!ctl->die) {
size_t i;