From 85be7b241127de4d9adba19616106a280f00dfc0 Mon Sep 17 00:00:00 2001 From: cancel Date: Sun, 2 Dec 2018 17:48:07 +0900 Subject: [PATCH] Add ability to start tui with no input file --- tui_main.c | 62 +++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/tui_main.c b/tui_main.c index ec16a60..a2bad9c 100644 --- a/tui_main.c +++ b/tui_main.c @@ -13,7 +13,7 @@ static void usage() { // clang-format off fprintf(stderr, - "Usage: ui [options] infile\n\n" + "Usage: ui [options] [file]\n\n" "Options:\n" " -h or --help Print this message and exit.\n" ); @@ -247,39 +247,39 @@ int main(int argc, char** argv) { fprintf(stderr, "Expected only 1 file argument.\n"); return 1; } - if (input_file == NULL) { - fprintf(stderr, "No input file.\n"); - usage(); - return 1; - } Field field; - field_init(&field); - Field_load_error fle = field_load_file(input_file, &field); - if (fle != Field_load_error_ok) { - field_deinit(&field); - char const* errstr = "Unknown"; - switch (fle) { - case Field_load_error_ok: - break; - case Field_load_error_cant_open_file: - errstr = "Unable to open file"; - break; - case Field_load_error_too_many_columns: - errstr = "Grid file has too many columns"; - break; - case Field_load_error_too_many_rows: - errstr = "Grid file has too many rows"; - break; - case Field_load_error_no_rows_read: - errstr = "Grid file has no rows"; - break; - case Field_load_error_not_a_rectangle: - errstr = "Grid file is not a rectangle"; - break; + if (input_file) { + field_init(&field); + Field_load_error fle = field_load_file(input_file, &field); + if (fle != Field_load_error_ok) { + field_deinit(&field); + char const* errstr = "Unknown"; + switch (fle) { + case Field_load_error_ok: + break; + case Field_load_error_cant_open_file: + errstr = "Unable to open file"; + break; + case Field_load_error_too_many_columns: + errstr = "Grid file has too many columns"; + break; + case Field_load_error_too_many_rows: + errstr = "Grid file has too many rows"; + break; + case Field_load_error_no_rows_read: + errstr = "Grid file has no rows"; + break; + case Field_load_error_not_a_rectangle: + errstr = "Grid file is not a rectangle"; + break; + } + fprintf(stderr, "File load error: %s.\n", errstr); + return 1; } - fprintf(stderr, "File load error: %s.\n", errstr); - return 1; + } else { + input_file = "unnamed"; + field_init_fill(&field, 25, 57, '.'); } Markmap_reusable markmap_r; markmap_reusable_init(&markmap_r);