diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-26 13:03:29 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-30 09:02:31 +1000 |
commit | bacf4e5a62d3a243f23b91c18a4cc0816ceeab51 (patch) | |
tree | 51856a4009906c7c87c19ad5ac7993f79cedf031 | |
parent | 7957f1980d5b3810da22aebee048772e205e737a (diff) | |
download | libinput-bacf4e5a62d3a243f23b91c18a4cc0816ceeab51.tar.gz |
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>
-rw-r--r-- | tools/libinput-record.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 87c5b1fb..d1472fe0 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -130,10 +130,12 @@ struct record_context { struct list devices; int ndevices; - char *outfile; /* file name given on cmdline */ - char *output_file; /* full file name with suffix */ + struct { + 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; @@ -227,7 +229,7 @@ iprintf(const struct record_context *ctx, snprintf(fmt, sizeof(fmt), "%s%s", &space[len - indent - 1], format); va_start(args, format); - rc = vfprintf(ctx->out_file, fmt, args); + rc = vfprintf(ctx->output_file.fp, fmt, args); va_end(args); assert(rc != -1 && (unsigned int)rc > indent); @@ -2084,18 +2086,18 @@ open_output_file(struct record_context *ctx, bool is_prefix) { FILE *out_file; - if (ctx->outfile) { - char *fname = init_output_file(ctx->outfile, is_prefix); - ctx->output_file = fname; + if (ctx->output_file.name) { + char *fname = init_output_file(ctx->output_file.name, is_prefix); + ctx->output_file.name_with_suffix = fname; out_file = fopen(fname, "w"); if (!out_file) return false; } else { - ctx->output_file = safe_strdup("stdout"); + ctx->output_file.name_with_suffix = safe_strdup("stdout"); out_file = stdout; } - ctx->out_file = out_file; + ctx->output_file.fp = out_file; return true; } @@ -2314,12 +2316,12 @@ mainloop(struct record_context *ctx) if (!open_output_file(ctx, autorestart)) { fprintf(stderr, "Failed to open '%s'\n", - ctx->output_file); + ctx->output_file.name_with_suffix); break; } fprintf(stderr, "%sRecording to '%s'.\n", isatty(STDERR_FILENO) ? "" : "# ", - ctx->output_file); + ctx->output_file.name_with_suffix); 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(); } @@ -2390,17 +2392,19 @@ mainloop(struct record_context *ctx) } /* If we didn't have events, delete the file. */ - if (!isatty(fileno(ctx->out_file))) { - if (!ctx->had_events && ctx->output_file) { - fprintf(stderr, "No events recorded, deleting '%s'\n", ctx->output_file); - unlink(ctx->output_file); + if (!isatty(fileno(ctx->output_file.fp))) { + if (!ctx->had_events && ctx->output_file.name_with_suffix) { + fprintf(stderr, + "No events recorded, deleting '%s'\n", + ctx->output_file.name_with_suffix); + unlink(ctx->output_file.name_with_suffix); } - fclose(ctx->out_file); - ctx->out_file = NULL; + fclose(ctx->output_file.fp); + ctx->output_file.fp = NULL; } - free(ctx->output_file); - ctx->output_file = NULL; + free(ctx->output_file.name_with_suffix); + ctx->output_file.name_with_suffix = NULL; } while (autorestart && !ctx->stop); sigprocmask(SIG_UNBLOCK, &mask, NULL); @@ -2751,7 +2755,7 @@ main(int argc, char **argv) goto out; } - ctx.outfile = safe_strdup(output_arg); + ctx.output_file.name = safe_strdup(output_arg); if (output_arg == NULL && (all || ndevices > 1)) { fprintf(stderr, |