| Date: Thu, 31 Aug 2017 01:13:54 +0200
Simplify uri printing
Diffstat:
M ui_ti.c | 14 +++++---------
M ui_txt.c | 17 ++++++++---------
2 files changed, 13 insertions(+), 18 deletions(-)
--- |
| @@ -163,6 +163,7 @@ displaystatus(Item *item)
static void
displayuri(Item *item)
{
+ char *fmt;
int n;
if (item->type == 'i')
@@ -177,15 +178,10 @@ displayuri(Item *item)
n = printf("%s: %s", item->username, item->selector);
break;
default:
- if (!strcmp(item->port, "70")) {
- n = printf("%s: gopher://%s/%c%s", item->username,
- item->host, item->type,
- item->selector);
- } else {
- n = printf("%s: gopher://%s:%s/%c%s", item->username,
- item->host, item->port, item->type,
- item->selector);
- }
+ fmt = strcmp(item->port, "70") ? "%s: gopher://%s:%5$s/%c%s" :
+ "%s: gopher://%s/%c%s";
+ n = printf(fmt, item->username,
+ item->host, item->type, item->selector, item->port);
break;
}
putp(tparm(exit_standout_mode)); |
| @@ -136,8 +136,11 @@ uidisplay(Item *entry)
void
printuri(Item *item, size_t i)
{
+ char *fmt;
+
if (!item)
return;
+
switch (item->type) {
case 'i':
break;
@@ -145,15 +148,11 @@ printuri(Item *item, size_t i)
printf("%zu: %s: %s\n", i, item->username, item->selector);
break;
default:
- if (!strcmp(item->port, "70")) {
- printf("%zu: %s: gopher://%s/%c%s\n", i, item->username,
- item->host, item->type,
- item->selector);
- } else {
- printf("%zu: %s: gopher://%s:%s/%c%s\n", i, item->username,
- item->host, item->port, item->type,
- item->selector);
- }
+ fmt = strcmp(item->port, "70") ?
+ "%zu: %s: gopher://%s:%6$s/%c%s\n" :
+ "%zu: %s: gopher://%s/%c%s\n";
+ printf(fmt, i, item->username,
+ item->host, item->type, item->selector, item->port);
break;
}
} |