tSimplify uri printing - sacc - sacc (saccomys): simple gopher client. | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 5fadc79985c013fe96490029054ef46299a4483a | |
parent 502029b085642f9f09c3d9d7a2b82f87358fd78c | |
Author: Quentin Rameau <[email protected]> | |
Date: Thu, 31 Aug 2017 01:13:54 +0200 | |
Simplify uri printing | |
Diffstat: | |
ui_ti.c | 14 +++++--------- | |
ui_txt.c | 17 ++++++++--------- | |
2 files changed, 13 insertions(+), 18 deletions(-) | |
--- | |
diff --git a/ui_ti.c b/ui_ti.c | |
t@@ -163,6 +163,7 @@ displaystatus(Item *item) | |
static void | |
displayuri(Item *item) | |
{ | |
+ char *fmt; | |
int n; | |
if (item->type == 'i') | |
t@@ -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)); | |
diff --git a/ui_txt.c b/ui_txt.c | |
t@@ -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; | |
t@@ -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->usernam… | |
- item->host, item->type, | |
- item->selector); | |
- } else { | |
- printf("%zu: %s: gopher://%s:%s/%c%s\n", i, item->user… | |
- 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; | |
} | |
} |