From cfbfe81f5a8700c9469263b5043119a3a74f2cf2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 21 Sep 2010 22:37:37 +0200 Subject: [PATCH] Introduce UI Use o*print*() functions to print text to output in main object file to pass the text into shell pipe. Print errors into stderr. --- src/Makefile.am | 1 + src/shigofumi.c | 408 ++++++++++++++++++++++++++++++-------------------------- src/ui.h | 21 +++ 3 files changed, 238 insertions(+), 192 deletions(-) create mode 100644 src/ui.h diff --git a/src/Makefile.am b/src/Makefile.am index 26056a1..e32703a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,4 +11,5 @@ shigofumi_SOURCES = \ gettext.h \ io.c io.h \ shigofumi.c shigofumi.h \ + ui.h \ utils.c utils.h diff --git a/src/shigofumi.c b/src/shigofumi.c index 8c33ea1..6b94237 100644 --- a/src/shigofumi.c +++ b/src/shigofumi.c @@ -18,6 +18,7 @@ #include "completition.h" #include "data.h" #include "io.h" +#include "ui.h" #include "utils.h" #define CONFIG_FILE ".shigofumirc" @@ -99,7 +100,7 @@ static void shi_exit(int exit_code) { isds_list_free(&messages); if (cisds) { - fprintf(output, _("Logging out...\n")); + oprintf(_("Logging out...\n")); isds_logout(cisds); isds_ctx_free(&cisds); } @@ -170,7 +171,7 @@ static int shi_load_configuration(const char *config_file) { fprintf(stderr, _("Error while parsing configuration file `%s'\n"), config_name); } - printf(_("Using default configuration\n")); + oprintf(_("Using default configuration\n")); } if (config_name != config_file) free(config_name); @@ -182,10 +183,10 @@ static void finish_isds_operation(struct isds_ctx *ctx, isds_error err) { shi_progressbar_finish(); if (err) { if (isds_long_message(ctx)) - printf(_("Error occurred: %s: %s\n"), isds_strerror(err), + fprintf(stderr, _("Error occurred: %s: %s\n"), isds_strerror(err), isds_long_message(ctx)); else - printf(_("Error occurred: %s\n"), isds_strerror(err)); + fprintf(stderr, _("Error occurred: %s\n"), isds_strerror(err)); } } @@ -245,7 +246,7 @@ static int add_log_facility(isds_log_facility *facilities, const char *name) { else if (!strcmp(name, "xml")) *facilities |= ILF_XML; else if (!strcmp(name, "all")) *facilities |= ILF_ALL; else { - printf(_("%s: Unknown log facility\n"), name); + fprintf(stderr, _("%s: Unknown log facility\n"), name); return -1; } @@ -283,11 +284,12 @@ static void save_log_facility(int level) { /* Clamp long int to unsigned int */ static unsigned int normalize_timeout(long int raw) { if (raw < 0) { - printf(_("Configured network timeout is less then 0. Clamped to 0.\n")); + oprintf(_("Configured network timeout is less then 0. " + "Clamped to 0.\n")); return 0; } if (raw > UINT_MAX ) { - printf(_("Configured network timeout is greater then %1$u. " + oprintf(_("Configured network timeout is greater then %1$u. " "Clamped to %1$u.\n"), UINT_MAX); return UINT_MAX; } @@ -298,16 +300,16 @@ static unsigned int normalize_timeout(long int raw) { /* Clamp long int to <0;100> */ static unsigned int normalize_log_level(long int raw) { if (raw < 0) { - printf(_("Configured log level is less then 0. Clamped to 0.\n")); + oprintf(_("Configured log level is less then 0. Clamped to 0.\n")); return 0; } if (raw > ILL_ALL) { - printf(_("Configured log level is greater then %1$u. " + oprintf(_("Configured log level is greater then %1$u. " "Clamped to %1$u.\n"), ILL_ALL); return ILL_ALL; } if (raw > UINT_MAX ) { - printf(_("Configured log level is greater then %1$u. " + oprintf(_("Configured log level is greater then %1$u. " "Clamped to %1$u.\n"), UINT_MAX); return UINT_MAX; } @@ -321,7 +323,8 @@ static int shi_init(const char *config_file) { unsigned int timeout, log_level; isds_log_facility log_facility = ILF_NONE; - printf(_("This is Shigofumi, an ISDS client. Have a nice e-government.\n")); + oprintf(_("This is Shigofumi, an ISDS client. " + "Have a nice e-government.\n")); /* Do not permute arguments in getopt() */ if (setenv("POSIXLY_CORRECT", "", 1)) { @@ -389,7 +392,7 @@ static int shi_init(const char *config_file) { isds_strerror(err), isds_long_message(cisds)); } if (!cfg_getbool(configuration, CONFIG_VERIFYSERVER)) { - printf(_("Warning: Shigofumi disabled server identity verification " + oprintf(_("Warning: Shigofumi disabled server identity verification " "on user request!\n")); err = isds_set_opt(cisds, IOPT_TLS_VERIFY_SERVER, 0); if (err) { @@ -454,7 +457,7 @@ static int shi_quit(int argc, const char **argv) { static void shi_help_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s [COMMAND]\n" "Show COMMAND manual or list of currently available commands.\n" ), @@ -478,8 +481,8 @@ static int shi_help(int argc, const char **argv) { if ((*commands)[i].usage) (*commands)[i].usage((*commands)[i].name); else if ((*commands)[i].description) { - fhprint(output, (*commands)[i].name, command_width); - fprintf(output, " %s\n", _((*commands)[i].description)); + ohprint((*commands)[i].name, command_width); + oprintf(" %s\n", _((*commands)[i].description)); } else fprintf(stderr, @@ -493,10 +496,10 @@ static int shi_help(int argc, const char **argv) { } /* Or list all commands */ - fprintf(output, _("Following commands are available:\n")); + oprintf(_("Following commands are available:\n")); for (i = 0; (*commands)[i].name; i++) { - fhprint(output, (*commands)[i].name, command_width); - fprintf(output, " %s\n", _((*commands)[i].description)); + ohprint((*commands)[i].name, command_width); + oprintf(" %s\n", _((*commands)[i].description)); } return 0; @@ -506,8 +509,8 @@ static int shi_help(int argc, const char **argv) { static void show_version(void) { char *libisds_version = isds_version(); - printf(_("This is Shigofumi version %s.\n"), PACKAGE_VERSION); - printf(_("\n" + oprintf(_("This is Shigofumi version %s.\n"), PACKAGE_VERSION); + oprintf(_("\n" "Used libraries\n" "Readline: %s\n" "libisds: %s\n" @@ -519,7 +522,7 @@ static void show_version(void) { static int shi_version(int argc, const char **argv) { show_version(); - printf(_( + oprintf(_( "\n" "-----\n" "It's a shigofumi. A letter delivered from the afterlife. (Fumika)\n" @@ -531,7 +534,7 @@ static int shi_version(int argc, const char **argv) { static int shi_copying(int argc, const char **argv) { - printf(_( + oprintf(_( "This is Shigofumi, an ISDS client.\n" "Copyright (C) 2010 Petr Pisar\n" "\n" @@ -558,13 +561,13 @@ static int shi_cache(int argc, const char **argv) { if (boxes) { for (item = boxes, i = 0; item; item = item->next, i++); - printf(_( + oprintf(_( "Cached box list: %zu\n"), i); } if (messages) { - printf(_( + oprintf(_( "Cached message list:\n" "\tDirection: %s\n" "\tMessages: %'lu\n"), @@ -573,7 +576,7 @@ static int shi_cache(int argc, const char **argv) { } if (message) { - printf(_("Cached message: %s\n"), + oprintf(_("Cached message: %s\n"), (message->envelope && message->envelope->dmID) ? message->envelope->dmID : _("")); } @@ -583,7 +586,7 @@ static int shi_cache(int argc, const char **argv) { static void shi_chdir_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s [DIRECTORY]\n" "Change working directory to DIRECTORY.\n" "If no DIRECTORY is supplied, HOME directory will be used.\n"), @@ -604,12 +607,12 @@ static int shi_chdir(int argc, const char **argv) { else { directory = getenv("HOME"); if (!directory) { - printf("Environment variable HOME does not exist\n"); + oprintf("Environment variable HOME does not exist\n"); return -1; } } if (chdir(directory)) { - printf(_("Could not change working directory: %s: %s\n"), directory, + oprintf(_("Could not change working directory: %s: %s\n"), directory, strerror(errno)); return -1; } @@ -625,20 +628,20 @@ static int shi_pwd(int argc, const char **argv) { while (length += 1024) { newbuffer = realloc(buffer, length); if (!newbuffer) { - printf(_("Error: Not enough memory\n")); + fprintf(stderr, _("Error: Not enough memory\n")); free(buffer); return -1; } buffer = newbuffer; if (getcwd(buffer, length)) { - printf("%s\n", buffer); + oprintf("%s\n", buffer); free(buffer); return 0; } } - printf(_("Error: Current directory string is too long\n")); + fprintf(stderr, _("Error: Current directory string is too long\n")); free(buffer); return -1; } @@ -649,10 +652,10 @@ static int do_login(void) { isds_error err; if (batch_mode) { - printf(_("Unattended mode detected. " + oprintf(_("Unattended mode detected. " "Make sure credentials have been preset.\n")); } else { - printf(_("You are going to insert credentials for your account.\n" + oprintf(_("You are going to insert credentials for your account.\n" "Leave blank line to choose default value.\n")); } select_completition(COMPL_NONE); @@ -687,7 +690,7 @@ static int do_login(void) { return -1; } - printf(_("Logged in.\n")); + oprintf(_("Logged in.\n")); return 0; } @@ -743,7 +746,7 @@ static struct isds_DbOwnerInfo *stat_box(const char *id) { if (!item->data) continue; if (item->next) { - printf(_("Error: More boxes match ID `%s'\n"), id_locale); + fprintf(stderr, _("Error: More boxes match ID `%s'\n"), id_locale); goto leave; } @@ -761,7 +764,7 @@ leave: static void shi_commercial_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s [-0|-1] [BOX_ID]\n" "Manipulate commercial receiving box status.\n" " -O switch off receiving of commercial messages\n" @@ -797,7 +800,7 @@ static int shi_commercial(int argc, const char **argv) { } } if (optind + 1 < argc) { - printf(_("Bad invocation\n")); + fprintf(stderr, _("Bad invocation\n")); shi_commercial_usage((argv)?argv[0]:NULL); return -1; } @@ -807,7 +810,7 @@ static int shi_commercial(int argc, const char **argv) { box = do_box(); if (!box || !box->dbID || !*box->dbID) { isds_DbOwnerInfo_free(&box); - printf(_("Could not get current box ID\n")); + fprintf(stderr, _("Could not get current box ID\n")); return -1; } box_id = box->dbID; static_box_id = 1; @@ -817,7 +820,7 @@ static int shi_commercial(int argc, const char **argv) { box_id_locale = (char *) argv[optind]; box_id = locale2utf8(box_id_locale); static_box_id = 0; if (!box_id) { - printf(_("Could not convert box ID `%s' to UTF-8\n"), + fprintf(stderr, _("Could not convert box ID `%s' to UTF-8\n"), box_id_locale); return -1; } @@ -826,19 +829,19 @@ static int shi_commercial(int argc, const char **argv) { if (action == -1) { if (!box) box = stat_box(box_id); if (!box) { - printf(_("Could not get details about box ID `%s'\n"), + fprintf(stderr, _("Could not get details about box ID `%s'\n"), box_id_locale); retval = -1; goto leave; } - printf(_("Commercial receiving status of box `%s': "), box_id_locale); + oprintf(_("Commercial receiving status of box `%s': "), box_id_locale); if (!box->dbOpenAddressing) - printf(_("Unknown\n")); + oprintf(_("Unknown\n")); else if (*box->dbOpenAddressing) - printf(_("Positive\n")); + oprintf(_("Positive\n")); else - printf(_("Negative\n")); + oprintf(_("Negative\n")); } else { char *refnumber = NULL; printf((action) ? @@ -851,11 +854,11 @@ static int shi_commercial(int argc, const char **argv) { if (!err) { char *refnumber_locale = utf82locale(refnumber); - printf(_("Commercial receiving status successfully changed. " + oprintf(_("Commercial receiving status successfully changed. " "Assigned reference number: %s\n"), refnumber_locale); } else { - printf(_("Commercial receiving status has not been changed.\n")); + oprintf(_("Commercial receiving status has not been changed.\n")); retval = -1; } free(refnumber); @@ -886,7 +889,7 @@ static int shi_user(int argc, const char **argv) { static void shi_users_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s BOX_ID\n" "Get list of users having access to box with BOX_ID.\n"), command); @@ -911,11 +914,11 @@ static int shi_users(int argc, const char **argv) { for (item = users, ordinar = 0; item; item=item->next) { if (!item->data) continue; ordinar++; - printf(_("\n* User #%d:\n"), ordinar); + oprintf(_("\n* User #%d:\n"), ordinar); format_DbUserInfo(item->data); } if (ordinar == 0) - printf(_("Empty list of users returned.\n")); + oprintf(_("Empty list of users returned.\n")); isds_list_free(&users); return 0; @@ -949,7 +952,7 @@ static int do_passwd(void) { select_completition(COMPL_NONE); - printf(_( + oprintf(_( "You are going to change your password. If you don't want to change your\n" "password, insert empty string or EOF.\n" "\n" @@ -997,13 +1000,13 @@ static int do_passwd(void) { printf(_("Password change failed\n")); goto error; } else { - printf(_("Password HAS been successfully changed.\n")); + oprintf(_("Password HAS been successfully changed.\n")); goto leave; } error: retval = -1; - printf(_("Password has NOT been changed!\n")); + oprintf(_("Password has NOT been changed!\n")); leave: free(old_password); @@ -1013,14 +1016,14 @@ leave: set_prompt(NULL); select_completition(COMPL_COMMAND); - printf(_("\n" + oprintf(_("\n" "Remember, ISDS password has limited life time.\n")); return retval; } static void shi_passwd_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s [-S]\n" "Manipulate user password or change it if no option given.\n" "\n" @@ -1044,7 +1047,7 @@ static int shi_passwd(int argc, const char **argv) { } } if (optind != argc || argc > 1) { - printf(_("Bad invocation\n")); + fprintf(stderr, _("Bad invocation\n")); shi_passwd_usage((argv)?argv[0]:NULL); return -1; } @@ -1065,7 +1068,7 @@ static int shi_login(int argc, const char **argv) { static void shi_debug_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s -l LEVEL [-f FACILITY...] [{-e | -o FILE}]\n" "Debug FACILITIES on LEVEL.\n" "\n" @@ -1111,7 +1114,7 @@ static int shi_debug(int argc, const char **argv) { } } if (optind == 1 || optind != argc) { - printf(_("Bad invocation\n")); + fprintf(stderr, _("Bad invocation\n")); shi_debug_usage(argv[0]); return -1; } @@ -1149,11 +1152,11 @@ static void show_setting_str(const char *variable, _Bool cenzore) { if (value) { if (cenzore) - fprintf(output, _("%s = \n"), variable); + oprintf(_("%s = \n"), variable); else - fprintf(output, _("%s = `%s'\n"), variable, value); + oprintf(_("%s = `%s'\n"), variable, value); } else { - fprintf(output, _("%s = \n"), variable); + oprintf(_("%s = \n"), variable); } } @@ -1164,9 +1167,9 @@ static void show_setting_boolean(const char *variable) { _Bool value = cfg_getbool(configuration, variable); if (value) { - fprintf(output, _("%s = \n"), variable); + oprintf(_("%s = \n"), variable); } else { - fprintf(output, _("%s = \n"), variable); + oprintf(_("%s = \n"), variable); } } @@ -1176,7 +1179,7 @@ static void show_setting_int(const char *variable) { long int value = cfg_getint(configuration, variable); - fprintf(output, _("%s = %ld\n"), variable, value); + oprintf(_("%s = %ld\n"), variable, value); } @@ -1186,15 +1189,15 @@ static void show_setting_strlist(const char *variable) { int length = cfg_size(configuration, variable); if (length <= 0) { - fprintf(output, _("%s = \n"), variable); + oprintf(_("%s = \n"), variable); } else { - fprintf(output, _("%s = {"), variable); + oprintf(_("%s = {"), variable); for (int i = 0; i < length; i++) { const char *value = cfg_getnstr(configuration, variable, i); if (i < length - 1) - fprintf(output, _("`%s', "), value); + oprintf(_("`%s', "), value); else - fprintf(output, _("`%s'}\n"), value); + oprintf(_("`%s'}\n"), value); } } } @@ -1234,7 +1237,7 @@ static int shi_settings(int argc, const char **argv) { } */ - fprintf(output, _("Current settings:\n")); + oprintf(_("Current settings:\n")); show_setting_str(CONFIG_SERVER, 0); show_setting_str(CONFIG_USERNAME, 0); @@ -1256,7 +1259,7 @@ static int shi_settings(int argc, const char **argv) { static void shi_find_box_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s {OPTION... | BOX_ID}\n" "Get information about box with BOX_ID or boxes meeting other criteria.\n" "Each search option requires an argument:\n" @@ -1325,7 +1328,7 @@ static void shi_find_box_usage(const char *command) { zfree(variable); \ (variable) = locale2utf8(locale); \ if (!(variable)) { \ - printf(_("Error: Not enough memory\n")); \ + fprintf(stderr, _("Error: Not enough memory\n")); \ retval = -1; \ goto leave; \ } \ @@ -1335,7 +1338,7 @@ static void shi_find_box_usage(const char *command) { if (!(structure)) { \ (structure) = calloc(1, sizeof(*(structure))); \ if (!(structure)) { \ - printf(_("Error: Not enough memory\n")); \ + fprintf(stderr, _("Error: Not enough memory\n")); \ retval = -1; \ goto leave; \ } \ @@ -1346,14 +1349,15 @@ static void shi_find_box_usage(const char *command) { zfree(variable); \ (variable) = malloc(sizeof(*(variable))); \ if (!(variable)) { \ - printf(_("Error: Not enough memory\n")); \ + fprintf(stderr, _("Error: Not enough memory\n")); \ retval = -1; \ goto leave; \ } \ if (!strcmp((locale), "0")) *(variable) = 0; \ else if (!strcmp((locale), "1")) *(variable) = 1; \ else { \ - printf(_("%s: %s: Unknown boolean value\n"), argv[0], (locale)); \ + fprintf(stderr, _("%s: %s: Unknown boolean value\n"), \ + argv[0], (locale)); \ retval = -1; \ goto leave; \ } \ @@ -1361,7 +1365,7 @@ static void shi_find_box_usage(const char *command) { #define FILL_LONGINT_OR_LEAVE(variable, locale) { \ if (!(locale) || !*(locale)) { \ - printf(_("%s: Empty integer value\n"), argv[0]); \ + fprintf(stderr, _("%s: Empty integer value\n"), argv[0]); \ retval = -1; \ goto leave; \ } \ @@ -1369,13 +1373,14 @@ static void shi_find_box_usage(const char *command) { zfree(variable); \ (variable) = malloc(sizeof(*(variable))); \ if (!(variable)) { \ - printf(_("Error: Not enough memory\n")); \ + fprintf(stderr, _("Error: Not enough memory\n")); \ retval = -1; \ goto leave; \ } \ (*variable) = strtol((locale), &endptr, 0); \ if (*endptr) { \ - printf(_("%s: %s: Invalid integer value\n"), argv[0], (locale)); \ + fprintf(stderr, _("%s: %s: Invalid integer value\n"), \ + argv[0], (locale)); \ retval = -1; \ goto leave; \ } \ @@ -1390,14 +1395,14 @@ static int shi_find_box(int argc, const char **argv) { int retval = 0; if (!argv || !argv[1] || !*argv[1]) { - printf(_("Error: No argument supplied\n")); + fprintf(stderr, _("Error: No argument supplied\n")); shi_find_box_usage((argv)?argv[0]:NULL); return -1; } criteria = calloc(1, sizeof(*criteria)); if (!criteria) { - printf(_("Error: Not enough memory\n")); + fprintf(stderr, _("Error: Not enough memory\n")); retval = -1; goto leave; } @@ -1411,7 +1416,7 @@ static int shi_find_box(int argc, const char **argv) { case 't': criteria->dbType = malloc(sizeof(*criteria->dbType)); if (!criteria->dbType) { - printf(_("Error: Not enough memory\n")); + fprintf(stderr, _("Error: Not enough memory\n")); retval = -1; goto leave; } @@ -1440,7 +1445,8 @@ static int shi_find_box(int argc, const char **argv) { else if (!strcmp(optarg, "OVM_REQ")) *criteria->dbType = DBTYPE_OVM_REQ; else { - printf(_("%s: %s: Unknown box type\n"), argv[0], optarg); + fprintf(stderr, _("%s: %s: Unknown box type\n"), + argv[0], optarg); retval = -1; goto leave; } @@ -1476,7 +1482,8 @@ static int shi_find_box(int argc, const char **argv) { CALLOC_OR_LEAVE(criteria->birthInfo); criteria->birthInfo->biDate = datestring2tm(optarg); if (!criteria->birthInfo->biDate) { - printf(_("Error: Could not parse date: %s\n"), optarg); + fprintf(stderr, _("Error: Could not parse date: %s\n"), + optarg); retval = -1; goto leave; } @@ -1540,7 +1547,7 @@ static int shi_find_box(int argc, const char **argv) { case 'a': criteria->dbState = malloc(sizeof(*criteria->dbState)); if (!criteria->dbState) { - printf(_("Error: Not enough memory\n")); + fprintf(stderr, _("Error: Not enough memory\n")); retval = -1; goto leave; } @@ -1555,7 +1562,8 @@ static int shi_find_box(int argc, const char **argv) { else if (!strcmp(optarg, "REMOVED")) *criteria->dbState = DBSTATE_REMOVED; else { - printf(_("%s: %s: Unknown box status\n"), argv[0], optarg); + fprintf(stderr, _("%s: %s: Unknown box status\n"), + argv[0], optarg); retval = -1; goto leave; } @@ -1577,7 +1585,7 @@ static int shi_find_box(int argc, const char **argv) { /* There must be an option and all of them must be recognized, if not only * BOX_ID supplied */ if (argc > 2 && optind != argc) { - printf(_("Error: Superfluous argument\n")); + fprintf(stderr, _("Error: Superfluous argument\n")); shi_find_box_usage(argv[0]); retval = -1; goto leave; @@ -1587,7 +1595,7 @@ static int shi_find_box(int argc, const char **argv) { if (argc == 2 && argv[1] && *argv[1]) { criteria->dbID = locale2utf8(argv[1]); if (!criteria->dbID) { - printf(_("Error: Not enough memory\n")); + fprintf(stderr, _("Error: Not enough memory\n")); retval = -1; goto leave; } @@ -1602,7 +1610,7 @@ static int shi_find_box(int argc, const char **argv) { if (!item->data) continue; order++; - printf(_("\n* Result #%d:\n"), order); + oprintf(_("\n* Result #%d:\n"), order); format_DbOwnerInfo(item->data); } @@ -1613,7 +1621,7 @@ leave: static void shi_stat_box_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s BOX_ID...\n" "Get status of box with BOX_ID. More boxes can be specified.\n"), command); @@ -1627,7 +1635,7 @@ static int shi_stat_box(int argc, const char **argv) { long int status; if (!argv || !*argv || argc < 2 || !argv[1]) { - printf(_("Missing box ID\n")); + fprintf(stderr, _("Missing box ID\n")); shi_stat_box_usage((argv[0])?argv[0]:NULL); return -1; } @@ -1638,7 +1646,8 @@ static int shi_stat_box(int argc, const char **argv) { free(id); id = locale2utf8(argv[i]); if (!id) { - printf(_("%s: Could not covert box ID to UTF-8\n"), argv[i]); + fprintf(stderr, _("%s: Could not covert box ID to UTF-8\n"), + argv[i]); return -1; } @@ -1647,7 +1656,7 @@ static int shi_stat_box(int argc, const char **argv) { finish_isds_operation(cisds, err); if (err) return -1; - printf(_("Status of box `%s': %s\n"), + oprintf(_("Status of box `%s': %s\n"), argv[i], DbState2string(&status)); } @@ -1656,7 +1665,7 @@ static int shi_stat_box(int argc, const char **argv) { static void shi_compose_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s OPTION...\n" "Compose and send a message to recipient defined by his box ID.\n" "Each option requires an argument (if not stated otherwise):\n" @@ -1740,20 +1749,20 @@ static int shi_compose(int argc, const char **argv) { *dmStatus_locale = NULL; if (!argv || !argv[1] || !*argv[1]) { - printf(_("Error: No argument supplied\n")); + fprintf(stderr, _("Error: No argument supplied\n")); shi_compose_usage((argv)?argv[0]:NULL); return -1; } message = calloc(1, sizeof(*message)); if (!message) { - printf(_("Error: Not enough memory\n")); + fprintf(stderr, _("Error: Not enough memory\n")); retval = -1; goto leave; } envelope = calloc(1, sizeof(*envelope)); if (!envelope) { - printf(_("Error: Not enough memory\n")); + fprintf(stderr, _("Error: Not enough memory\n")); retval = -1; goto leave; } @@ -1793,7 +1802,8 @@ static int shi_compose(int argc, const char **argv) { break; case 'U': if (!copy) { - printf(_("Error: %s: Recipient box ID (-b) must precede " + fprintf(stderr, + _("Error: %s: Recipient box ID (-b) must precede " "recipient organisation unit name (-%c)\n"), optarg, opt); retval = -1; @@ -1803,7 +1813,8 @@ static int shi_compose(int argc, const char **argv) { break; case 'N': if (!copy) { - printf(_("Error: %s: Recipient box ID (-b) must precede " + fprintf(stderr, + _("Error: %s: Recipient box ID (-b) must precede " "recipient organisation unit number (-%c)\n"), optarg, opt); retval = -1; @@ -1813,7 +1824,8 @@ static int shi_compose(int argc, const char **argv) { break; case 'P': if (!copy) { - printf(_("Error: %s: Recipient box ID (-b) must precede " + fprintf(stderr, + _("Error: %s: Recipient box ID (-b) must precede " "to-hands option (-%c)\n"), optarg, opt); retval = -1; goto leave; @@ -1904,7 +1916,8 @@ static int shi_compose(int argc, const char **argv) { break; case 'D': if (!document) { - printf(_("Error: %s: Document file (-d) must precede " + fprintf(stderr, + _("Error: %s: Document file (-d) must precede " "document name (-%c)\n"), optarg, opt); retval = -1; goto leave; @@ -1913,7 +1926,8 @@ static int shi_compose(int argc, const char **argv) { break; case 'x': if (!document) { - printf(_("Error: %s: Document file (-d) must precede " + fprintf(stderr, + _("Error: %s: Document file (-d) must precede " "XPath expression (-%c)\n"), optarg, opt); retval = -1; goto leave; @@ -1937,7 +1951,8 @@ static int shi_compose(int argc, const char **argv) { break; case 'm': if (!document) { - printf(_("Error: %s: Document file (-d) must precede " + fprintf(stderr, + _("Error: %s: Document file (-d) must precede " "MIME type (-%c)\n"), optarg, opt); retval = -1; goto leave; @@ -1946,7 +1961,8 @@ static int shi_compose(int argc, const char **argv) { break; case 'g': if (!document) { - printf(_("Error: %s: Document file (-d) must precede " + fprintf(stderr, + _("Error: %s: Document file (-d) must precede " "document ID (-%c)\n"), optarg, opt); retval = -1; goto leave; @@ -1955,7 +1971,8 @@ static int shi_compose(int argc, const char **argv) { break; case 'G': if (!document) { - printf(_("Error: %s: Document file (-d) must precede " + fprintf(stderr, + _("Error: %s: Document file (-d) must precede " "document reference (-%c)\n"), optarg, opt); retval = -1; goto leave; @@ -1964,7 +1981,8 @@ static int shi_compose(int argc, const char **argv) { break; case 'c': if (!document) { - printf(_("Error: Document file (-d) must precede " + fprintf(stderr, + _("Error: Document file (-d) must precede " "document signature type (-%c)\n"), opt); retval = -1; goto leave; @@ -1981,14 +1999,14 @@ static int shi_compose(int argc, const char **argv) { /* All options must be recognized */ if (optind != argc) { - printf(_("Error: Superfluous argument\n")); + fprintf(stderr, _("Error: Superfluous argument\n")); shi_compose_usage(argv[0]); retval = -1; goto leave; } if (!copies) { - printf(_("Error: No recipient box ID specified\n")); + fprintf(stderr, _("Error: No recipient box ID specified\n")); shi_compose_usage(argv[0]); retval = -1; goto leave; @@ -1997,9 +2015,9 @@ static int shi_compose(int argc, const char **argv) { /* TODO: Check Legal Title soft dependencies */ /* Preview */ - printf(_("Following message has been composed:\n")); + oprintf(_("Following message has been composed:\n")); format_message(message); - printf(_("Following recipients have been specified:\n")); + oprintf(_("Following recipients have been specified:\n")); format_copies(copies); /* TODO: Confirmation, correction */ @@ -2022,16 +2040,16 @@ static int shi_compose(int argc, const char **argv) { retval = -1; if (copy->dmStatus) dmStatus_locale = utf82locale(copy->dmStatus); if (dmStatus_locale) - printf(_("%s: Failed: %s: %s\n"), + oprintf(_("%s: Failed: %s: %s\n"), recipient_id_locale, isds_strerror(copy->error), dmStatus_locale); else - printf(_("%s: Failed: %s\n"), recipient_id_locale, + oprintf(_("%s: Failed: %s\n"), recipient_id_locale, isds_strerror(copy->error)); zfree(dmStatus_locale); } else { message_id_locale = utf82locale(copy->dmID); - printf(_("%s: Succeeded. Assigned message ID: %s\n"), + oprintf(_("%s: Succeeded. Assigned message ID: %s\n"), recipient_id_locale, message_id_locale); free(message_id_locale); } @@ -2052,7 +2070,7 @@ leave: static void shi_delivery_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s MESSAGE_ID\n" "Get delivery data about message with MESSAGE_ID.\n"), command); @@ -2091,7 +2109,7 @@ static int shi_delivery(int argc, const char **argv) { static int shi_dump_message(int argc, const char **argv) { if (!message) { - printf(_("No message loaded\n")); + fprintf(stderr, _("No message loaded\n")); return -1; } @@ -2101,7 +2119,7 @@ static int shi_dump_message(int argc, const char **argv) { static void shi_hash_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s [MESSAGE_ID]\n" "Retrieve message hash stored in ISDS.\n" "If MESSAGE_ID is defined, query for that message.\n" @@ -2124,11 +2142,11 @@ static int shi_hash(int argc, const char **argv) { id = argv[1]; else { if (!message) { - printf(_("No message loaded\n")); + fprintf(stderr, _("No message loaded\n")); return -1; } if (!message->envelope || !message->envelope->dmID) { - printf(_("Current message is missing ID\n")); + fprintf(stderr, _("Current message is missing ID\n")); return -1; } id = message->envelope->dmID; @@ -2140,7 +2158,7 @@ static int shi_hash(int argc, const char **argv) { if (err) return -1; hash_string = hash2string(hash); - printf(_("ISDS states message with `%s' ID has following hash:\n%s\n"), + oprintf(_("ISDS states message with `%s' ID has following hash:\n%s\n"), id, hash_string); free(hash_string); @@ -2157,12 +2175,12 @@ static int shi_verify(int argc, const char **argv) { size_t width = 4; if (!message) { - printf(_("No message loaded\n")); + fprintf(stderr, _("No message loaded\n")); return -1; } if (!message->envelope) { - printf(_("Current message is missing envelope\n")); + fprintf(stderr, _("Current message is missing envelope\n")); return -1; } stored_hash = message->envelope->hash; @@ -2170,7 +2188,7 @@ static int shi_verify(int argc, const char **argv) { if (message->envelope->dmID) { /* Verify remote hash */ - printf(_("Remote hash check:\n")); + oprintf(_("Remote hash check:\n")); printf(_("Getting message hash...\n")); err = isds_download_message_hash(cisds, message->envelope->dmID, @@ -2179,8 +2197,8 @@ static int shi_verify(int argc, const char **argv) { if (retrieved_hash) { hash_string = hash2string(retrieved_hash); - fhprint(stdout, _("Retrieved:"), width); - printf("%s\n", hash_string); + ohprint(_("Retrieved:"), width); + oprintf("%s\n", hash_string); zfree(hash_string); } @@ -2191,8 +2209,8 @@ static int shi_verify(int argc, const char **argv) { if (!err) { hash_string = hash2string(message->envelope->hash); - fhprint(stdout, _("Computed:"), width); - printf("%s\n", hash_string); + ohprint(_("Computed:"), width); + oprintf("%s\n", hash_string); zfree(hash_string); } } @@ -2200,13 +2218,13 @@ static int shi_verify(int argc, const char **argv) { err = isds_hash_cmp(retrieved_hash, message->envelope->hash); switch (err) { case IE_SUCCESS: - printf(_("Hashes match.\n")); break; + oprintf(_("Hashes match.\n")); break; case IE_NOTUNIQ: - printf(_("Hashes do not match.\n")); + oprintf(_("Hashes do not match.\n")); retval = -1; break; default: - printf(_("Hashes could not be compared.\n")); + oprintf(_("Hashes could not be compared.\n")); retval = -1; break; } @@ -2217,11 +2235,11 @@ static int shi_verify(int argc, const char **argv) { if (stored_hash) { /* Verify stored hash */ - printf(_("Stored hash check:\n")); + oprintf(_("Stored hash check:\n")); hash_string = hash2string(stored_hash); - fhprint(stdout, _("Stored:"), width); - printf("%s\n", hash_string); + ohprint(_("Stored:"), width); + oprintf("%s\n", hash_string); zfree(hash_string); if (message->raw) { @@ -2231,8 +2249,8 @@ static int shi_verify(int argc, const char **argv) { if (!err) { hash_string = hash2string(message->envelope->hash); - fhprint(stdout, _("Computed:"), width); - printf("%s\n", hash_string); + ohprint(_("Computed:"), width); + oprintf("%s\n", hash_string); zfree(hash_string); } } @@ -2240,13 +2258,13 @@ static int shi_verify(int argc, const char **argv) { err = isds_hash_cmp(stored_hash, message->envelope->hash); switch (err) { case IE_SUCCESS: - printf(_("Hashes match.\n")); break; + oprintf(_("Hashes match.\n")); break; case IE_NOTUNIQ: - printf(_("Hashes do not match.\n")); + oprintf(_("Hashes do not match.\n")); retval = -1; break; default: - printf(_("Hashes could not be compared.\n")); + oprintf(_("Hashes could not be compared.\n")); retval = -1; break; } @@ -2264,11 +2282,11 @@ static int shi_authenticate(int argc, const char **argv) { int retval = 0; if (!message) { - printf(_("No message loaded\n")); + fprintf(stderr, _("No message loaded\n")); return -1; } if (!message->raw || message->raw_length == 0) { - printf(_("Current message is missing raw representation\n")); + fprintf(stderr, _("Current message is missing raw representation\n")); return -1; } @@ -2278,9 +2296,9 @@ static int shi_authenticate(int argc, const char **argv) { switch (err) { case IE_SUCCESS: - printf(_("Message originates in ISDS.\n")); break; + oprintf(_("Message originates in ISDS.\n")); break; case IE_NOTUNIQ: - printf(_("Message is unknown to ISDS or has been tampered.\n")); + oprintf(_("Message is unknown to ISDS or has been tampered.\n")); retval = -1; break; default: @@ -2293,7 +2311,7 @@ static int shi_authenticate(int argc, const char **argv) { static void shi_accept_message_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s [MESSAGE_ID...]\n" "Accept commercial message moving its state to received.\n" "If MESSAGE_ID is defined, accept that message. More messages can be specified.\n" @@ -2312,7 +2330,8 @@ static int shi_accept_message(int argc, const char **argv) { id = locale2utf8(argv[i]); if (!id) { - printf(_("Error: Could not convert message ID to UTF-8: %s\n"), + fprintf(stderr, + _("Error: Could not convert message ID to UTF-8: %s\n"), argv[i]); return -1; } @@ -2325,14 +2344,15 @@ static int shi_accept_message(int argc, const char **argv) { return -1; }; - printf(_("Message `%s' accepted\n"), argv[i]); + oprintf(_("Message `%s' accepted\n"), argv[i]); free(id); } if (argc < 2) { /* TODO: list commercial not received messages and accept all of them * */ - printf(_("Error: No message ID supplied. Accepting all commercial " + fprintf(stderr, + _("Error: No message ID supplied. Accepting all commercial " "messages not implemented yet.\n")); return -1; } @@ -2357,7 +2377,8 @@ static int do_read_message(const char *id, const char *id_locale) { static_id = 0; id = locale2utf8(id_locale); if (!id) { - printf(_("Error: Could not convert message ID to UTF-8: %s\n"), + fprintf(stderr, + _("Error: Could not convert message ID to UTF-8: %s\n"), id_locale); return -1; } @@ -2368,7 +2389,7 @@ static int do_read_message(const char *id, const char *id_locale) { finish_isds_operation(cisds, err); if (!err) - printf(_("Message `%s' marked as read\n"), id_locale); + oprintf(_("Message `%s' marked as read\n"), id_locale); if (static_id) free((char *) id_locale); else free((char *) id); @@ -2378,7 +2399,7 @@ static int do_read_message(const char *id, const char *id_locale) { static void shi_read_message_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s [MESSAGE_ID...]\n" "Mark message as read moving its state to read.\n" "\n" @@ -2401,15 +2422,15 @@ static int shi_read_message(int argc, const char **argv) { if (argc < 2) { if (!message) { - printf(_("No message loaded\n")); + fprintf(stderr, _("No message loaded\n")); return -1; } if (!message->envelope) { - printf(_("Loaded message is missing envelope\n")); + fprintf(stderr, _("Loaded message is missing envelope\n")); return -1; } if (!message->envelope->dmID || !*message->envelope->dmID) { - printf(_("Loaded message is missing ID\n")); + fprintf(stderr, _("Loaded message is missing ID\n")); return -1; } return do_read_message(message->envelope->dmID, NULL); @@ -2421,7 +2442,7 @@ static int shi_read_message(int argc, const char **argv) { static int shi_show_message(int argc, const char **argv) { if (!message) { - printf(_("No message loaded\n")); + fprintf(stderr, _("No message loaded\n")); return -1; } @@ -2431,7 +2452,7 @@ static int shi_show_message(int argc, const char **argv) { static void shi_incoming_message_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s [-r] MESSAGE_ID\n" "Get incoming message with MESSAGE_ID.\n" "Options:\n" @@ -2458,7 +2479,7 @@ static int shi_incoming_message(int argc, const char **argv) { } } if (optind + 1 != argc || !argv || !argv[optind] || !*argv[optind]) { - printf(_("Bad invocation\n")); + fprintf(stderr, _("Bad invocation\n")); shi_incoming_message_usage((argv)?argv[0]:NULL); return -1; } @@ -2491,7 +2512,7 @@ static int shi_incoming_message(int argc, const char **argv) { static void shi_outgoing_message_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s MESSAGE_ID\n" "Get outgoing message with MESSAGE_ID.\n"), command); @@ -2528,7 +2549,7 @@ static int shi_outgoing_message(int argc, const char **argv) { static void shi_load_anything_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s FILE\n" "Load message or message delivery details from local FILE.\n"), command); @@ -2558,9 +2579,9 @@ static int shi_load_anything(int argc, const char **argv) { if (err) { if (err == IE_NOTSUP) - printf(_("Unknown format. Could not parse the file.\n")); + fprintf(stderr, _("Unknown format. Could not parse the file.\n")); else - printf(_("Error while detecting format. " + fprintf(stderr, _("Error while detecting format. " "Could not parse the file.\n")); } else { switch (raw_type) { @@ -2585,7 +2606,8 @@ static int shi_load_anything(int argc, const char **argv) { break; default: - printf(_("Unsupported format. Could not parse the file.\n")); + fprintf(stderr, + _("Unsupported format. Could not parse the file.\n")); err = IE_NOTSUP; } } @@ -2610,7 +2632,7 @@ static int shi_load_anything(int argc, const char **argv) { static void shi_save_message_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s FILE\n" "Save message into local FILE.\n"), command); @@ -2646,11 +2668,11 @@ static int shi_save_message(int argc, const char **argv) { } if (!message) { - printf(_("No message loaded\n")); + fprintf(stderr, _("No message loaded\n")); return -1; } if (!message->raw || message->raw_length == 0) { - printf(_("Loaded message is missing raw representation\n")); + fprintf(stderr, _("Loaded message is missing raw representation\n")); return -1; } @@ -2671,12 +2693,13 @@ static const struct isds_document *locate_document_by_ordinal_string( ordinar = atoi(number); if (ordinar <= 0) { - printf(_("%s: Document number must be positive number\n"), number); + fprintf(stderr, _("%s: Document number must be positive number\n"), + number); return NULL; } if (!message) { - printf(_("No message loaded\n")); + fprintf(stderr, _("No message loaded\n")); return NULL; } @@ -2689,7 +2712,7 @@ static const struct isds_document *locate_document_by_ordinal_string( } } if (i != ordinar) { - printf(_("Message does not contain document #%d\n"), ordinar); + fprintf(stderr, _("Message does not contain document #%d\n"), ordinar); return NULL; } @@ -2698,7 +2721,7 @@ static const struct isds_document *locate_document_by_ordinal_string( static void shi_save_document_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s NUMBER [DESTINATION]\n" "Save document having ordinal NUMBER within current message into local file.\n" "If DESTINATION is file (or does not exist yet), document will be saved into\n" @@ -2742,7 +2765,7 @@ static int shi_save_document(int argc, const char **argv) { } else { filename = strdup(argv[2]); if (!filename) { - printf(_("Not enough memory\n")); + fprintf(stderr, _("Not enough memory\n")); return -1; } } @@ -2750,12 +2773,13 @@ static int shi_save_document(int argc, const char **argv) { if (!filename && document->dmFileDescr && &document->dmFileDescr) { filename = utf82locale(document->dmFileDescr); if (!filename) { - printf(_("Not enough memory\n")); + fprintf(stderr, _("Not enough memory\n")); return -1; } } if (!filename) { - printf(_("File name neither supplied, nor document name exists\n" + fprintf(stderr, + _("File name neither supplied, nor document name exists\n" "Please, supply one.\n")); return -1; } @@ -2769,7 +2793,7 @@ static int shi_save_document(int argc, const char **argv) { filename = NULL; } if (!path) { - printf(_("Not enough memory\n")); + fprintf(stderr, _("Not enough memory\n")); return -1; } @@ -2786,7 +2810,7 @@ static int shi_save_document(int argc, const char **argv) { static void shi_save_stamp_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s FILE\n" "Save message time stamp into local FILE.\n"), command); @@ -2802,12 +2826,12 @@ static int shi_save_stamp(int argc, const char **argv) { } if (!message) { - printf(_("No message loaded\n")); + fprintf(stderr, _("No message loaded\n")); return -1; } if (!message->envelope || !message->envelope->timestamp|| message->envelope->timestamp_length == 0) { - printf(_("Loaded message is missing time stamp\n")); + fprintf(stderr, _("Loaded message is missing time stamp\n")); return -1; } @@ -2819,11 +2843,11 @@ static int shi_save_stamp(int argc, const char **argv) { static int shi_show_list(int argc, const char **argv) { if (!messages) { - printf(_("No message list loaded\n")); + fprintf(stderr, _("No message list loaded\n")); return -1; } - printf((messages_are_outgoing) ? + oprintf((messages_are_outgoing) ? ngettext("You have %'lu outgoing message\n", "You have %'lu outgoing messages\n", total_messages) : ngettext("You have %'lu incoming message\n", @@ -2895,7 +2919,7 @@ static int do_convert(const struct isds_document *document) { char *name_locale = utf82locale(document->dmFileDescr); char *date_string = tm2string(date); char *id_locale = utf82locale(id); - printf(_( + oprintf(_( "Document submitted for authorized conversion successfully under name\n" "`%s' on %s.\n" "Submit identifier assigned by Czech POINT deposit is `%s'.\n"), @@ -2903,9 +2927,9 @@ static int do_convert(const struct isds_document *document) { free(name_locale); free(date_string); free(id_locale); - printf(_("Be ware that submitted document has restricted lifetime " + oprintf(_("Be ware that submitted document has restricted lifetime " "(30 days).\n")); - printf(_("See <%s> for more details.\n"), CZPDEPOSIT_URL); + oprintf(_("See <%s> for more details.\n"), CZPDEPOSIT_URL); } free(id); free(date); @@ -2914,16 +2938,16 @@ static int do_convert(const struct isds_document *document) { static void shi_convert_file_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s FILE [NAME]\n" "Submit local FILE to authorized conversion under NAME. If NAME is missing,\n" "it will use FILE name.\n"), command); - printf(_( + oprintf(_( "\n" "If Czech POINT deposit accepts document, it will return document identifier\n" "that user is supposed to provide to officer at Czech POINT contact place.\n" "Currently only PDF 1.3 and higher version files are accepted.\n")); - printf(_("See <%s> for more details.\n"), CZPDEPOSIT_URL); + oprintf(_("See <%s> for more details.\n"), CZPDEPOSIT_URL); } @@ -2963,16 +2987,16 @@ static int shi_convert_file(int argc, const char **argv) { static void shi_convert_document_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s NUMBER\n" "Submit message document with ordinal NUMBER to authorized conversion.\n"), command); - printf(_( + oprintf(_( "\n" "If Czech POINT deposit accepts document, it will return document identifier\n" "that user is supposed to provide to officer at Czech POINT contact place.\n" "Currently only PDF 1.3 and higher version files are accepted.\n")); - printf(_("See <%s> for more details.\n"), CZPDEPOSIT_URL); + oprintf(_("See <%s> for more details.\n"), CZPDEPOSIT_URL); } @@ -2993,7 +3017,7 @@ static int shi_convert_document(int argc, const char **argv) { #if ENABLE_DEBUG static void shi_print_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s STRING LENGTH\n" "Prints STRING into LENGTH columns. Negative LENGTH means not to cut\n" "overflowing string.\n" @@ -3022,9 +3046,9 @@ static int shi_print(int argc, const char **argv) { return -1; } - fprintf(output, _(">")); - fnprint(output, argv[1], width); - fprintf(output, _("<\n")); + oprintf(_(">")); + onprint(argv[1], width); + oprintf(_("<\n")); return 0; } @@ -3035,7 +3059,7 @@ static int shi_tokenize(int argc, const char **argv) { if (!argv) return 0; for (int i = 0; i < argc; i++) { - printf(_(">%s<\n"), argv[i]); + oprintf(_(">%s<\n"), argv[i]); } return 0; } @@ -3046,11 +3070,11 @@ static int shi_quote(int argc, const char **argv) { if (!argv) return 0; - printf(_("Original\tQuoted\tDequoted\n")); + oprintf(_("Original\tQuoted\tDequoted\n")); for (int i = 0; i < argc; i++) { escaped = shi_quote_filename((char *) argv[i], 0, NULL); unescaped = shi_dequote_filename((char *) argv[i], 0); - printf(_(">%s<\t>%s<\t>%s<\n"), argv[i], escaped, unescaped); + oprintf(_(">%s<\t>%s<\t>%s<\n"), argv[i], escaped, unescaped); free(escaped); free(unescaped); } @@ -3069,7 +3093,7 @@ int wait_for_shell(FILE **pipe) { output = stdout; if (retval == -1) - printf(_("Exit code of shell command could not " + fprintf(stderr, _("Exit code of shell command could not " "be determined\n")); else if (WIFEXITED(retval) && WEXITSTATUS(retval)) printf(_("Shell command exited with code %d\n"), @@ -3093,7 +3117,7 @@ void shi_loop(void) { FILE *pipe = NULL; int failed = 0; - printf(_("Use `help' command to get list of available commands.\n")); + oprintf(_("Use `help' command to get list of available commands.\n")); select_completition(COMPL_COMMAND); set_prompt(NULL); @@ -3157,7 +3181,7 @@ int shi_batch(char *lines) { FILE *pipe = NULL; int failed = 0; - printf(_("Batch mode started.\n")); + oprintf(_("Batch mode started.\n")); batch_mode = 1; select_completition(COMPL_COMMAND); @@ -3316,7 +3340,7 @@ static void main_version(void) { static void main_usage(const char *command) { - printf(_( + oprintf(_( "Usage: %s [OPTION...]\n" "Access ISDS, Process local data box messages or delivery details, submit\n" "document to authorized conversion.\n" diff --git a/src/ui.h b/src/ui.h new file mode 100644 index 0000000..7c7ce31 --- /dev/null +++ b/src/ui.h @@ -0,0 +1,21 @@ +#ifndef __ISDS_UI_H__ +#define __ISDS_UI_H__ + +/* Convenience wrappers around *printf() functions to pass text to output + * FILE stream. + * TODO: Find UI patterns and make generic toolkit interface allowing to pass + * it into GUI toolkit */ + +#include +#include "utils.h" + +#define oprintf(format, ...) fprintf(output, (format), ## __VA_ARGS__) +#define eprintf(format, ...) fprintf(stderr, (format), ## __VA_ARGS__) + +#define ohprint(locale_string, width) \ + fhprint(output, (locale_string), (width)); + +#define onprint(locale_string, width) \ + fnprint(output, (locale_string), (width)); + +#endif -- 2.11.4.GIT