Wrap long lines in version's list of customized tables

Factor the wrapping print out of show_opts() into prwrap().  Use it
in show_custom().
This commit is contained in:
Markus Armbruster 2008-04-10 22:01:25 +02:00
parent 16b811d4ac
commit afb642b38d

View file

@ -47,6 +47,7 @@
static void show_custom(void); static void show_custom(void);
static void show_opts(int val); static void show_opts(int val);
static char *prwrap(char *, char *, int *);
int int
vers(void) vers(void)
@ -226,9 +227,9 @@ vers(void)
pr("\n"); pr("\n");
pr("You can have at most %d BTUs.\n", max_btus); pr("You can have at most %d BTUs.\n", max_btus);
pr("You are disconnected after %d minutes of idle time.\n", max_idle); pr("You are disconnected after %d minutes of idle time.\n", max_idle);
pr("\nOptions enabled in this game:\n "); pr("\nOptions enabled in this game:\n");
show_opts(1); show_opts(1);
pr("\n\nOptions disabled in this game:\n "); pr("\n\nOptions disabled in this game:\n");
show_opts(0); show_opts(0);
pr("\n\nSee \"info Options\" for a detailed list of options and descriptions.\n"); pr("\n\nSee \"info Options\" for a detailed list of options and descriptions.\n");
show_custom(); show_custom();
@ -243,15 +244,14 @@ vers(void)
static void static void
show_custom(void) show_custom(void)
{ {
char *sep = "\nCustomized in this game:\n "; char *sep;
int i; int col, i;
/* TODO wrap long lines */ sep = "\nCustomized in this game:\n\t";
col = 0;
for (i = 0; i < EF_MAX; i++) { for (i = 0; i < EF_MAX; i++) {
if (ef_flags(i) & EFF_CUSTOM) { if (ef_flags(i) & EFF_CUSTOM)
pr("%s%s", sep, ef_nameof(i)); sep = prwrap(sep, ef_nameof(i), &col);
sep = ", ";
}
} }
if (*sep == ',') if (*sep == ',')
pr("\nCheck \"show\" for details.\n"); pr("\nCheck \"show\" for details.\n");
@ -260,11 +260,11 @@ show_custom(void)
static void static void
show_opts(int val) show_opts(int val)
{ {
int col;
char *sep; char *sep;
int col;
struct keymatch *kp; struct keymatch *kp;
sep = ""; sep = "\t";
col = 0; col = 0;
for (kp = configkeys; kp->km_key; kp++) { for (kp = configkeys; kp->km_key; kp++) {
if (!(kp->km_flags & KM_OPTION)) if (!(kp->km_flags & KM_OPTION))
@ -273,13 +273,21 @@ show_opts(int val)
continue; continue;
if (!*(int *)kp->km_data != !val) if (!*(int *)kp->km_data != !val)
continue; continue;
col += strlen(sep) + strlen(kp->km_key); sep = prwrap(sep, kp->km_key, &col);
if (col > 70) {
pr(",\n ");
sep = "";
col = strlen(kp->km_key);
}
pr("%s%s", sep, kp->km_key);
sep = ", ";
} }
} }
static char *
prwrap(char *sep, char *it, int *col)
{
size_t len = strlen(it);
if (*col != 0 && *col + len > 70) {
sep = ",\n\t";
*col = 0;
}
pr("%s%s", sep, it);
sep = ", ";
*col += len + 2;
return sep;
}