diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-08-06 15:34:33 +0300 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-08-06 15:34:33 +0300 |
commit | ced1fa83d6361ebfdc40920d98eb292ca4661b4e (patch) | |
tree | 25656c2faa18952680a6a5908799505db8476bb3 | |
parent | 974a00bc5f42d11da1b0f27a4c2d399147a07f10 (diff) | |
download | apk-tools-ced1fa83d6361ebfdc40920d98eb292ca4661b4e.tar.gz apk-tools-ced1fa83d6361ebfdc40920d98eb292ca4661b4e.tar.bz2 apk-tools-ced1fa83d6361ebfdc40920d98eb292ca4661b4e.tar.xz apk-tools-ced1fa83d6361ebfdc40920d98eb292ca4661b4e.zip |
state: indent package lists
-rw-r--r-- | src/apk.c | 19 | ||||
-rw-r--r-- | src/apk_blob.h | 8 | ||||
-rw-r--r-- | src/state.c | 17 |
3 files changed, 25 insertions, 19 deletions
@@ -96,12 +96,7 @@ static int version(void) return 0; } -struct apk_indent { - int x; - int indent; -}; - -static int print_indented(struct apk_indent *i, apk_blob_t blob) +int apk_print_indented(struct apk_indent *i, apk_blob_t blob) { static const int wrap_length = 80; @@ -113,10 +108,10 @@ static int print_indented(struct apk_indent *i, apk_blob_t blob) return 0; } -static void print_indented_words(struct apk_indent *i, const char *text) +void apk_print_indented_words(struct apk_indent *i, const char *text) { apk_blob_for_each_segment(APK_BLOB_STR(text), " ", - (apk_blob_cb) print_indented, i); + (apk_blob_cb) apk_print_indented, i); } static int format_option(char *buf, size_t len, struct apk_option *o, @@ -150,10 +145,10 @@ static void print_usage(const char *cmd, const char *args, int num_opts, word[j++] = '['; j += format_option(&word[j], sizeof(word) - j, &opts[i], "|"); word[j++] = ']'; - print_indented(&indent, APK_BLOB_PTR_LEN(word, j)); + apk_print_indented(&indent, APK_BLOB_PTR_LEN(word, j)); } if (args != NULL) - print_indented(&indent, APK_BLOB_STR(args)); + apk_print_indented(&indent, APK_BLOB_STR(args)); printf("\n"); } @@ -166,7 +161,7 @@ static void print_options(int num_opts, struct apk_option *opts) for (i = 0; i < num_opts; i++) { format_option(word, sizeof(word), &opts[i], ", "); indent.x = printf(" %-*s", indent.indent - 3, word); - print_indented_words(&indent, opts[i].help); + apk_print_indented_words(&indent, opts[i].help); printf("\n"); } } @@ -189,7 +184,7 @@ static int usage(struct apk_applet *applet) print_usage(applet->name, applet->arguments, applet->num_options, applet->options); printf("\ndescription:\n%*s", indent.indent - 1, ""); - print_indented_words(&indent, applet->help); + apk_print_indented_words(&indent, applet->help); } printf("\n\ngeneric options:\n"); print_options(ARRAY_SIZE(generic_options), generic_options); diff --git a/src/apk_blob.h b/src/apk_blob.h index 398056a..68b8f7c 100644 --- a/src/apk_blob.h +++ b/src/apk_blob.h @@ -101,4 +101,12 @@ void apk_blob_pull_csum(apk_blob_t *b, struct apk_checksum *csum); void apk_blob_pull_base64(apk_blob_t *b, apk_blob_t to); void apk_blob_pull_hexdump(apk_blob_t *b, apk_blob_t to); +struct apk_indent { + int x; + int indent; +}; + +void apk_print_indented_words(struct apk_indent *i, const char *text); +int apk_print_indented(struct apk_indent *i, apk_blob_t blob); + #endif diff --git a/src/state.c b/src/state.c index 1b1b333..ff1a2bb 100644 --- a/src/state.c +++ b/src/state.c @@ -613,24 +613,27 @@ static int dump_packages(struct apk_state *state, { struct apk_change *change; struct apk_name *name; - int match = 0; + struct apk_indent indent = { 0, 2 }; + char tmp[256]; + int match = 0, i; list_for_each_entry(change, &state->change_list_head, change_list) { if (!cmp(change)) continue; if (match == 0) - fprintf(stderr, "%s:\n ", msg); + printf("%s:\n ", msg); if (change->newpkg != NULL) name = change->newpkg->name; else name = change->oldpkg->name; - fprintf(stderr, " %s%s", name->name, - (name->flags & APK_NAME_TOPLEVEL) ? "*" : ""); + i = snprintf(tmp, sizeof(tmp), "%s%s", name->name, + (name->flags & APK_NAME_TOPLEVEL) ? "*" : ""); + apk_print_indented(&indent, APK_BLOB_PTR_LEN(tmp, i)); match++; } if (match) - fprintf(stderr, "\n"); + printf("\n"); return match; } @@ -754,8 +757,8 @@ int apk_state_commit(struct apk_state *state, "additional disk space will be used"); } if (apk_flags & APK_INTERACTIVE) { - fprintf(stderr, "Do you want to continue [Y/n]? "); - fflush(stderr); + printf("Do you want to continue [Y/n]? "); + fflush(stdout); r = fgetc(stdin); if (r != 'y' && r != 'Y') return -1; |