summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--untic.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/untic.c b/untic.c
index 274af7a..4ce3418 100644
--- a/untic.c
+++ b/untic.c
@@ -76,6 +76,37 @@ static const char *ti_strings[] = {
};
static const size_t n_strings = sizeof(ti_strings) / sizeof(ti_strings[0]);
+int print_entry(int pos, const char *s)
+{
+ if (pos + (int)strlen(s) + 2 >= COLS) {
+ printf("\n\t");
+ pos = 8;
+ } else {
+ printf(" ");
+ pos++;
+ }
+ return pos + printf("%s,", s);
+}
+
+int print_number(int pos, const char *s, int n)
+{
+ char buf[1023];
+ snprintf(buf, sizeof(buf), "%s#%d", s, n);
+ return print_entry(pos, buf);
+}
+
+int print_string(int pos, const char *s, const char *v)
+{
+ char buf[1023];
+ int bpos = 0;
+ bpos = snprintf(buf + bpos, sizeof(buf) - bpos, "%s=", s);
+ while (*v) {
+ bpos += snprintf(buf + bpos, sizeof(buf) - bpos, "%s", unctrl(*v));
+ v++;
+ }
+ return print_entry(pos, buf);
+}
+
int main(int argc, char *argv[])
{
setlocale(LC_ALL, "");
@@ -118,32 +149,31 @@ int main(int argc, char *argv[])
return 1;
}
- printf("%s | %s\n", termname(), longname());
+ printf("%s | %s", termname(), longname());
+ int pos = COLS;
for (size_t i = 0; i < n_flags; i++) {
if (tigetflag(ti_flags[i]) > 0) {
- printf("\t%s,\n", ti_flags[i]);
+ pos = print_entry(pos, ti_flags[i]);
}
}
+ pos = COLS;
for (size_t i = 0; i < n_numbers; i++) {
int n = tigetnum(ti_numbers[i]);
if (n > -1) {
- printf("\t%s#%d,\n", ti_numbers[i], n);
+ pos = print_number(pos, ti_numbers[i], n);
}
}
+ pos = COLS;
for (size_t i = 0; i < n_strings; i++) {
char *s = tigetstr(ti_strings[i]);
if (s && s != (char*)-1) {
- printf("\t%s=", ti_strings[i]);
- while (*s) {
- printf("%s", unctrl(*s));
- s++;
- }
- printf(",\n");
+ pos = print_string(pos, ti_strings[i], s);
}
}
+ printf("\n");
return 0;
}