summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/apk.c11
-rw-r--r--src/apk_blob.h8
-rw-r--r--src/apk_print.h6
-rw-r--r--src/print.c11
-rw-r--r--src/solver.c2
5 files changed, 18 insertions, 20 deletions
diff --git a/src/apk.c b/src/apk.c
index fdd31a8..7942445 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -97,7 +97,7 @@ static int format_option(char *buf, size_t len, struct apk_option *o,
static void print_usage(const char *cmd, const char *args, int num_opts,
struct apk_option *opts)
{
- struct apk_indent indent = { 0, 11 };
+ struct apk_indent indent = { .indent = 11 };
char word[128];
int i, j;
@@ -116,7 +116,7 @@ static void print_usage(const char *cmd, const char *args, int num_opts,
static void print_options(int num_opts, struct apk_option *opts)
{
- struct apk_indent indent = { 0, 26 };
+ struct apk_indent indent = { .indent = 26 };
char word[128];
int i;
@@ -139,19 +139,18 @@ static int usage(struct apk_applet *applet)
printf("\nThe following commands are available:\n");
for (a = &__start_apkapplets; a < &__stop_apkapplets; a++) {
- struct apk_indent indent = { 0, 26 };
+ struct apk_indent indent = { .indent = 26 };
indent.x = printf(" %-*s", indent.indent - 3, (*a)->name);
apk_print_indented_words(&indent, (*a)->help);
printf("\n");
}
} else {
- struct apk_indent indent = { 0, 2 };
+ struct apk_indent indent = { .indent = 2 };
print_usage(applet->name, applet->arguments,
applet->num_options, applet->options);
- printf("\nDescription:\n%*s", indent.indent - 1, "");
- indent.x = indent.indent - 1;
+ printf("\nDescription:\n");
apk_print_indented_words(&indent, applet->help);
printf("\n");
}
diff --git a/src/apk_blob.h b/src/apk_blob.h
index f1c3a35..c93d09d 100644
--- a/src/apk_blob.h
+++ b/src/apk_blob.h
@@ -109,14 +109,6 @@ 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);
-
void apk_atom_init(void);
apk_blob_t *apk_blob_atomize(apk_blob_t blob);
apk_blob_t *apk_blob_atomize_dup(apk_blob_t blob);
diff --git a/src/apk_print.h b/src/apk_print.h
index a88d873..668aa12 100644
--- a/src/apk_print.h
+++ b/src/apk_print.h
@@ -23,6 +23,12 @@ const char *apk_error_str(int error);
void apk_reset_screen_width(void);
int apk_get_screen_width(void);
+
+struct apk_indent {
+ int x;
+ int indent;
+};
+
int apk_print_indented(struct apk_indent *i, apk_blob_t blob);
void apk_print_indented_words(struct apk_indent *i, const char *text);
diff --git a/src/print.c b/src/print.c
index e673f12..732ede9 100644
--- a/src/print.c
+++ b/src/print.c
@@ -41,11 +41,12 @@ int apk_get_screen_width(void)
int apk_print_indented(struct apk_indent *i, apk_blob_t blob)
{
- if (i->x + blob.len + 1 >= apk_get_screen_width()) {
- i->x = i->indent;
- printf("\n%*s", i->indent - 1, "");
- }
- i->x += printf(" " BLOB_FMT, BLOB_PRINTF(blob));
+ if (i->x + blob.len + 1 >= apk_get_screen_width())
+ i->x = printf("\n%*s" BLOB_FMT, i->indent, "", BLOB_PRINTF(blob)) - 1;
+ else if (i->x <= i->indent)
+ i->x += printf("%*s" BLOB_FMT, i->indent - i->x, "", BLOB_PRINTF(blob));
+ else
+ i->x += printf(" " BLOB_FMT, BLOB_PRINTF(blob));
return 0;
}
diff --git a/src/solver.c b/src/solver.c
index 75575c2..0e338b6 100644
--- a/src/solver.c
+++ b/src/solver.c
@@ -915,7 +915,7 @@ static int dump_packages(struct apk_changeset *changeset,
{
struct apk_change *change;
struct apk_name *name;
- struct apk_indent indent = { 0, 2 };
+ struct apk_indent indent = { .indent = 2 };
int match = 0, i;
for (i = 0; i < changeset->changes->num; i++) {