Commit bfd53b59 authored by Timo Teräs's avatar Timo Teräs

print: minor cleanup to indented writer

parent 4bf13c3d
......@@ -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");
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment