From 9216ee50f5c02ac290d48fee1bd6edbacc74aaf3 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Sat, 28 Jul 2012 19:31:14 +0200 Subject: [PATCH] use util_ functions for strtocmd and strtononcmd --- main.c | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/main.c b/main.c index ca404f9..7ca9fea 100644 --- a/main.c +++ b/main.c @@ -68,36 +68,6 @@ static int usage() { return -1; } -static void strtocmd(char *str) -{ - for(; *str; ++str) { - if (*str == '-') { - *str = '_'; - continue; - } - if (isalpha(*str) && !isupper(*str)) { - *str += 'A' - 'a'; - continue; - } - } -} - -static void strtononcmd(char *buf, const char *str) -{ - for(; *str; ++buf, ++str) { - if (*str == '_') { - *buf = '-'; - continue; - } - if (isalpha(*str) && isupper(*str)) { - *buf = *str + 'a' - 'A'; - continue; - } - *buf = *str; - } - *buf = 0; -} - static bool options_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) { size_t i; @@ -223,11 +193,11 @@ static bool options_parse(int argc, char **argv) { /* handle all -fflags */ case 'f': - strtocmd(argv[0]+2); + util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1); if (!strcmp(argv[0]+2, "HELP")) { printf("Possible flags:\n"); for (itr = 0; itr < COUNT_FLAGS; ++itr) { - strtononcmd(buffer, opts_flag_list[itr].name); + util_strtononcmd(opts_flag_list[itr].name, buffer, sizeof(buffer)); printf(" -f%s\n", buffer); } exit(0); @@ -244,11 +214,11 @@ static bool options_parse(int argc, char **argv) { } break; case 'W': - strtocmd(argv[0]+2); + util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1); if (!strcmp(argv[0]+2, "HELP")) { printf("Possible warnings:\n"); for (itr = 0; itr < COUNT_WARNINGS; ++itr) { - strtononcmd(buffer, opts_warn_list[itr].name); + util_strtononcmd(opts_warn_list[itr].name, buffer, sizeof(buffer)); printf(" -W%s\n", buffer); } exit(0); -- 2.39.2