mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-05 11:08:16 +02:00
tools/record: rename the output file handling
Less confusing than having output_file, out_file, and outfile. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
7957f1980d
commit
bacf4e5a62
1 changed files with 25 additions and 21 deletions
|
|
@ -130,10 +130,12 @@ struct record_context {
|
||||||
struct list devices;
|
struct list devices;
|
||||||
int ndevices;
|
int ndevices;
|
||||||
|
|
||||||
char *outfile; /* file name given on cmdline */
|
struct {
|
||||||
char *output_file; /* full file name with suffix */
|
char *name; /* file name given on cmdline */
|
||||||
|
char *name_with_suffix; /* full file name with suffix */
|
||||||
|
FILE *fp;
|
||||||
|
} output_file;
|
||||||
|
|
||||||
FILE *out_file;
|
|
||||||
|
|
||||||
struct libinput *libinput;
|
struct libinput *libinput;
|
||||||
|
|
||||||
|
|
@ -227,7 +229,7 @@ iprintf(const struct record_context *ctx,
|
||||||
|
|
||||||
snprintf(fmt, sizeof(fmt), "%s%s", &space[len - indent - 1], format);
|
snprintf(fmt, sizeof(fmt), "%s%s", &space[len - indent - 1], format);
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
rc = vfprintf(ctx->out_file, fmt, args);
|
rc = vfprintf(ctx->output_file.fp, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
assert(rc != -1 && (unsigned int)rc > indent);
|
assert(rc != -1 && (unsigned int)rc > indent);
|
||||||
|
|
@ -2084,18 +2086,18 @@ open_output_file(struct record_context *ctx, bool is_prefix)
|
||||||
{
|
{
|
||||||
FILE *out_file;
|
FILE *out_file;
|
||||||
|
|
||||||
if (ctx->outfile) {
|
if (ctx->output_file.name) {
|
||||||
char *fname = init_output_file(ctx->outfile, is_prefix);
|
char *fname = init_output_file(ctx->output_file.name, is_prefix);
|
||||||
ctx->output_file = fname;
|
ctx->output_file.name_with_suffix = fname;
|
||||||
out_file = fopen(fname, "w");
|
out_file = fopen(fname, "w");
|
||||||
if (!out_file)
|
if (!out_file)
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
ctx->output_file = safe_strdup("stdout");
|
ctx->output_file.name_with_suffix = safe_strdup("stdout");
|
||||||
out_file = stdout;
|
out_file = stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->out_file = out_file;
|
ctx->output_file.fp = out_file;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -2314,12 +2316,12 @@ mainloop(struct record_context *ctx)
|
||||||
if (!open_output_file(ctx, autorestart)) {
|
if (!open_output_file(ctx, autorestart)) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Failed to open '%s'\n",
|
"Failed to open '%s'\n",
|
||||||
ctx->output_file);
|
ctx->output_file.name_with_suffix);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%sRecording to '%s'.\n",
|
fprintf(stderr, "%sRecording to '%s'.\n",
|
||||||
isatty(STDERR_FILENO) ? "" : "# ",
|
isatty(STDERR_FILENO) ? "" : "# ",
|
||||||
ctx->output_file);
|
ctx->output_file.name_with_suffix);
|
||||||
|
|
||||||
ctx->had_events = false;
|
ctx->had_events = false;
|
||||||
|
|
||||||
|
|
@ -2366,7 +2368,7 @@ mainloop(struct record_context *ctx)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->out_file != stdout)
|
if (ctx->output_file.fp != stdout)
|
||||||
print_progress_bar();
|
print_progress_bar();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2390,17 +2392,19 @@ mainloop(struct record_context *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we didn't have events, delete the file. */
|
/* If we didn't have events, delete the file. */
|
||||||
if (!isatty(fileno(ctx->out_file))) {
|
if (!isatty(fileno(ctx->output_file.fp))) {
|
||||||
if (!ctx->had_events && ctx->output_file) {
|
if (!ctx->had_events && ctx->output_file.name_with_suffix) {
|
||||||
fprintf(stderr, "No events recorded, deleting '%s'\n", ctx->output_file);
|
fprintf(stderr,
|
||||||
unlink(ctx->output_file);
|
"No events recorded, deleting '%s'\n",
|
||||||
|
ctx->output_file.name_with_suffix);
|
||||||
|
unlink(ctx->output_file.name_with_suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(ctx->out_file);
|
fclose(ctx->output_file.fp);
|
||||||
ctx->out_file = NULL;
|
ctx->output_file.fp = NULL;
|
||||||
}
|
}
|
||||||
free(ctx->output_file);
|
free(ctx->output_file.name_with_suffix);
|
||||||
ctx->output_file = NULL;
|
ctx->output_file.name_with_suffix = NULL;
|
||||||
} while (autorestart && !ctx->stop);
|
} while (autorestart && !ctx->stop);
|
||||||
|
|
||||||
sigprocmask(SIG_UNBLOCK, &mask, NULL);
|
sigprocmask(SIG_UNBLOCK, &mask, NULL);
|
||||||
|
|
@ -2751,7 +2755,7 @@ main(int argc, char **argv)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.outfile = safe_strdup(output_arg);
|
ctx.output_file.name = safe_strdup(output_arg);
|
||||||
|
|
||||||
if (output_arg == NULL && (all || ndevices > 1)) {
|
if (output_arg == NULL && (all || ndevices > 1)) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue