Skip to content

Commit

Permalink
unibi-dump: accept a filename as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
mauke committed Feb 4, 2018
1 parent ec9ef0a commit 73385ba
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions tools/unibi-dump.c
Expand Up @@ -30,6 +30,9 @@ THE SOFTWARE.

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

static void print_str_esc(const char *s) {
if (!s) {
Expand Down Expand Up @@ -58,10 +61,26 @@ static void print_str_esc(const char *s) {
}
}

int main(void) {
unibi_term *const ut = unibi_from_env();
static unibi_term *get_term(const char *s) {
unibi_term *ut;
if (s) {
ut = unibi_from_file(s);
if (!ut) {
fprintf(stderr, "unibi_from_file(): %s: %s\n", s, strerror(errno));
}
} else {
ut = unibi_from_env();
if (!ut) {
const char *name = getenv("TERM");
fprintf(stderr, "unibi_from_env(): %s: %s\n", name ? name : "(null)", strerror(errno));
}
}
return ut;
}

int main(int argc, char **argv) {
unibi_term *const ut = get_term(argc > 1 ? argv[1] : NULL);
if (!ut) {
perror("unibi_from_env");
return 1;
}

Expand Down

0 comments on commit 73385ba

Please sign in to comment.