From 5c170940c89065df4c7bbc6561cbdfd297363aad Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Mon, 29 Oct 2007 18:41:15 -0700 Subject: general cleanup of CLI output --- src/cli_new.c | 4 ++-- src/commit.c | 5 +++-- src/delete.c | 16 ++++++++++++---- src/set.c | 19 ++++++++++++++----- 4 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/cli_new.c b/src/cli_new.c index 8037909..8abdbff 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -105,7 +105,7 @@ void bye(char *msg, ...) va_list ap; if (is_silent_msg()) - exit(0); + exit(-1); va_start(ap, msg); if (is_echo()) printf("echo \""); @@ -113,7 +113,7 @@ void bye(char *msg, ...) printf(is_echo()? "\";":"\n"); va_end(ap); - exit(0); + exit(-1); } /* msg: diff --git a/src/commit.c b/src/commit.c index a8edbaf..7cd01df 100644 --- a/src/commit.c +++ b/src/commit.c @@ -270,11 +270,12 @@ int main(int argc, char **argv) st = lstat(mod, &statbuf); my_free(mod); if (st < 0 ) { + fprintf(out_stream, "No configuration changes to commit\n"); bye("No configuration changes to commit\n"); - exit(-1); } if(!get_config_lock(get_adirp(), LOCK_NAME)) { + fprintf(out_stream, "Cannot commit: Configuration is locked\n"); bye("Configuration is locked\n"); } @@ -1325,7 +1326,7 @@ static int fin_commit(boolean ok) int a_len = strlen(get_adirp()); set_echo(TRUE); if (!ok){ - printf("Commit FAILED!\n"); + fprintf(out_stream, "Commit failed\n"); return -1; } command = my_malloc(strlen(format1) + m_len + t_len, ""); diff --git a/src/delete.c b/src/delete.c index 5981923..0f16e7d 100644 --- a/src/delete.c +++ b/src/delete.c @@ -47,6 +47,7 @@ boolean set_validate(vtw_def *defp, char *valp) push_path(&t_path, DEF_NAME); if (lstat(t_path.path, &statbuf) < 0 || (statbuf.st_mode & S_IFMT) != S_IFREG) { + fprintf(out_stream, "The specified configuration node is not valid\n"); bye("Can not set value (2), no definition for %s", m_path.path); } /* defniition present */ @@ -75,7 +76,7 @@ int main(int argc, char **argv) } if (argc < 2) { - fprintf(stderr, "Need to specify the config node to delete\n"); + fprintf(out_stream, "Need to specify the config node to delete\n"); exit(1); } @@ -129,8 +130,10 @@ int main(int argc, char **argv) struct dirent *dirp; DIR *dp; - if (lstat(m_path.path, &statbuf) < 0) + if (lstat(m_path.path, &statbuf) < 0) { + fprintf(out_stream, "Nothing to delete\n"); bye("Nothing to delete at %s", m_path.path); + } remove_rf(FALSE); pop_path(&m_path); if ((dp = opendir(m_path.path)) == NULL){ @@ -183,6 +186,7 @@ int main(int argc, char **argv) exit(0); } if(ai < argc -1 || last_tag) { + fprintf(out_stream, "The specified configuration node is not valid\n"); bye("There is no appropriate template for %s", m_path.path + strlen(get_mdirp())); } @@ -190,8 +194,10 @@ int main(int argc, char **argv) pop_path(&m_path); /*it was value, not path segment */ push_path(&m_path, VAL_NAME); /* set value */ - if (lstat(m_path.path, &statbuf) < 0) + if (lstat(m_path.path, &statbuf) < 0) { + fprintf(out_stream, "Nothing to delete\n"); bye("Nothing to delete at %s", m_path.path); + } if ((statbuf.st_mode & S_IFMT) != S_IFREG) bye("Not a regular file %s", m_path.path); /* get definition to deal with potential multi */ @@ -199,6 +205,7 @@ int main(int argc, char **argv) push_path(&t_path, DEF_NAME); if (lstat(t_path.path, &statbuf) < 0 || (statbuf.st_mode & S_IFMT) != S_IFREG) { + fprintf(out_stream, "The specified configuration node is not valid\n"); bye("Can not delete value, no definition for %s", m_path.path); } /* defniition present */ @@ -254,9 +261,10 @@ int main(int argc, char **argv) remove_rf(FALSE); return 0; } + fprintf(out_stream, "The specified configuration node is not valid\n"); bye("There is no appropriate template for %s", m_path.path + strlen(get_mdirp())); - return 0; + return 1; } diff --git a/src/set.c b/src/set.c index 39d4a2f..7d63b95 100644 --- a/src/set.c +++ b/src/set.c @@ -35,8 +35,8 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val) for (i = 0; i < val_len; i++) { if (valp[i] == '\'') { - fprintf(stderr, "Cannot use the \"'\" (single quote) character " - "in a value string\n"); + fprintf(out_stream, "Cannot use the \"'\" (single quote) character " + "in a value string\n"); exit(1); } } @@ -55,8 +55,9 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val) push_path(&t_path, DEF_NAME); if (lstat(t_path.path, &statbuf) < 0 || (statbuf.st_mode & S_IFMT) != S_IFREG) { + fprintf(out_stream, "The specified configuration node is not valid\n"); bye("Can not set value (4), no definition for %s, template %s", - m_path.path,t_path.path); + m_path.path,t_path.path); } /* defniition present */ memset(defp, 0, sizeof(vtw_def)); @@ -71,6 +72,7 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val) if (empty_val) { if (defp->def_type != TEXT_TYPE || defp->tag || defp->multi){ printf("Empty string may be assigned only to TEXT type leaf node\n"); + fprintf(out_stream, "Empty value is not allowed\n"); return FALSE; } return TRUE; @@ -107,6 +109,8 @@ int main(int argc, char **argv) for (ai = 1; ai < argc; ++ai) { if (!*argv[ai]) { /* empty string */ if (ai < argc -1) { + fprintf(out_stream, "Empty value is not allowed after \"%s\"\n", + argv[ai - 1]); bye("empty string in argument list \n"); } empty_val = TRUE; @@ -144,8 +148,9 @@ int main(int argc, char **argv) /* every tag match validated already */ /* non tag matches are OK by definition */ /* do we already have it? */ - if (lstat(m_path.path, &statbuf) >= 0) + if (lstat(m_path.path, &statbuf) >= 0) { bye("Already exists %s", m_path.path + strlen(get_mdirp())); + } /* else */ /* prevent value node without actual value */ push_path(&t_path, DEF_NAME); @@ -153,8 +158,11 @@ int main(int argc, char **argv) memset(&def, 0, sizeof(vtw_def)); if ((status = parse_def(&def, t_path.path, FALSE))) exit(status); - if (def.def_type != ERROR_TYPE && !def.tag) + if (def.def_type != ERROR_TYPE && !def.tag) { + fprintf(out_stream, + "The specified configuration node requires a value\n"); bye("Must provide actual value\n"); + } if (def.def_type == ERROR_TYPE && !def.tag) { pop_path(&t_path); if(!validate_value(&def, "")) { @@ -172,6 +180,7 @@ int main(int argc, char **argv) if(ai < argc -1 || last_tag) { fprintf(stderr, "There is no appropriate template for %s", m_path.path + strlen(get_mdirp())); + fprintf(out_stream, "The specified configuration node is not valid\n"); exit(1); } /*ai == argc -1, must be actual value */ -- cgit v1.2.3