makes the code more readable and also exe smaller (cca 400B)
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/deskman.c | 13 ++++---------
src/hostmon.c | 7 ++-----
src/ifstats.c | 7 ++-----
src/itrafmon.c | 11 +++--------
src/othptab.c | 7 ++-----
src/serv.c | 16 ++++------------
src/tcptable.c | 6 ++----
src/tui/listbox.c | 12 +++---------
src/tui/winops.c | 4 +---
9 files changed, 23 insertions(+), 60 deletions(-)
diff --git a/src/deskman.c b/src/deskman.c
index e180ea4..ba73796 100644
--- a/src/deskman.c
+++ b/src/deskman.c
@@ -54,21 +54,19 @@ int ICMPV6ATTR;
void draw_desktop(void)
{
int row; /* counter for desktop construction */
- char sp_buf[10];
- sprintf(sp_buf, "%%%dc", COLS);
scrollok(stdscr, 0);
attrset(STATUSBARATTR);
move(0, 0);
- printw(sp_buf, ' '); /* these two print the top n' bottom */
+ printw("%*c", COLS, ' '); /* these two print the top n' bottom */
move(LINES - 1, 0);
- printw(sp_buf, ' '); /* lines */
+ printw("%*c", COLS, ' '); /* lines */
attrset(FIELDATTR);
for (row = 1; row <= LINES - 2; row++) { /* draw the background */
move(row, 0);
- printw(sp_buf, ' ');
+ printw("%*c", COLS, ' ');
}
refresh();
@@ -172,11 +170,8 @@ void tabkeyhelp(WINDOW * win)
void indicate(char *message)
{
- char sp_buf[10];
-
attrset(STATUSBARATTR);
- sprintf(sp_buf, "%%%dc", COLS);
- mvprintw(LINES - 1, 0, sp_buf, ' ');
+ mvprintw(LINES - 1, 0, "%*c", COLS, ' ');
mvprintw(LINES - 1, 1, message);
refresh();
}
diff --git a/src/hostmon.c b/src/hostmon.c
index de72163..1548a0a 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -469,9 +469,6 @@ static void refresh_hostmon_screen(struct ethtab *table, unsigned int
idx)
static void scrollethwin(struct ethtab *table, int direction, unsigned int *idx)
{
- char sp_buf[10];
-
- sprintf(sp_buf, "%%%dc", COLS - 2);
wattrset(table->tabwin, STDATTR);
if (direction == SCROLLUP) {
if (table->lastvisible != table->tail) {
@@ -481,7 +478,7 @@ static void scrollethwin(struct ethtab *table, int direction, unsigned
int *idx)
(*idx)++;
wmove(table->tabwin, LINES - 5, 0);
scrollok(table->tabwin, 0);
- wprintw(table->tabwin, sp_buf, ' ');
+ wprintw(table->tabwin, "%*c", COLS - 2, ' ');
scrollok(table->tabwin, 1);
printethent(table, table->lastvisible, *idx);
if (table->lastvisible->type == 1)
@@ -495,7 +492,7 @@ static void scrollethwin(struct ethtab *table, int direction, unsigned
int *idx)
table->firstvisible = table->firstvisible->prev_entry;
(*idx)--;
wmove(table->tabwin, 0, 0);
- wprintw(table->tabwin, sp_buf, ' ');
+ wprintw(table->tabwin, "%*c", COLS - 2, ' ');
printethent(table, table->firstvisible, *idx);
if (table->firstvisible->type == 1)
printrates(table, 0, table->firstvisible);
diff --git a/src/ifstats.c b/src/ifstats.c
index f2ff72e..b11d853 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -382,9 +382,6 @@ static void initiftab(struct iftab *table)
static void scrollgstatwin(struct iftab *table, int direction)
{
- char buf[255];
-
- sprintf(buf, "%%%dc", COLS - 2);
wattrset(table->statwin, STDATTR);
if (direction == SCROLLUP) {
if (table->lastvisible->next_entry != NULL) {
@@ -393,7 +390,7 @@ static void scrollgstatwin(struct iftab *table, int direction)
table->firstvisible = table->firstvisible->next_entry;
wmove(table->statwin, LINES - 5, 0);
scrollok(table->statwin, 0);
- wprintw(table->statwin, buf, ' ');
+ wprintw(table->statwin, "%*c", COLS - 2, ' ');
scrollok(table->statwin, 1);
printifentry(table->lastvisible, table->statwin,
table->firstvisible->index);
@@ -404,7 +401,7 @@ static void scrollgstatwin(struct iftab *table, int direction)
table->firstvisible = table->firstvisible->prev_entry;
table->lastvisible = table->lastvisible->prev_entry;
wmove(table->statwin, 0, 0);
- wprintw(table->statwin, buf, ' ');
+ wprintw(table->statwin, "%*c", COLS - 2, ' ');
printifentry(table->firstvisible, table->statwin,
table->firstvisible->index);
}
diff --git a/src/itrafmon.c b/src/itrafmon.c
index 670ab6d..259bd2f 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -117,9 +117,6 @@ static void show_stats(WINDOW * win, unsigned long long total)
static void scrollupperwin(struct tcptable *table, int direction,
unsigned long *idx, int mode)
{
- char sp_buf[10];
-
- sprintf(sp_buf, "%%%dc", COLS - 2);
wattrset(table->tcpscreen, STDATTR);
if (direction == SCROLLUP) {
if (table->lastvisible != table->tail) {
@@ -129,7 +126,7 @@ static void scrollupperwin(struct tcptable *table, int direction,
(*idx)++;
wmove(table->tcpscreen, table->imaxy - 1, 0);
scrollok(table->tcpscreen, 0);
- wprintw(table->tcpscreen, sp_buf, ' ');
+ wprintw(table->tcpscreen, "%*c", COLS - 2, ' ');
scrollok(table->tcpscreen, 1);
printentry(table, table->lastvisible, *idx, mode);
}
@@ -140,7 +137,7 @@ static void scrollupperwin(struct tcptable *table, int direction,
table->lastvisible = table->lastvisible->prev_entry;
(*idx)--;
wmove(table->tcpscreen, 0, 0);
- wprintw(table->tcpscreen, sp_buf, ' ');
+ wprintw(table->tcpscreen, "%*c", COLS - 2, ' ');
printentry(table, table->firstvisible, *idx, mode);
}
}
@@ -550,7 +547,6 @@ void ipmon(time_t facilitytime, char *ifptr)
unsigned int frag_off;
struct tcphdr *transpacket; /* IP-encapsulated packet */
in_port_t sport = 0, dport = 0; /* TCP/UDP port values */
- char sp_buf[10];
unsigned long screen_idx = 1;
@@ -627,8 +623,7 @@ void ipmon(time_t facilitytime, char *ifptr)
statpanel = new_panel(statwin);
wattrset(statwin, IPSTATLABELATTR);
wmove(statwin, 0, 0);
- sprintf(sp_buf, "%%%dc", COLS);
- wprintw(statwin, sp_buf, ' ');
+ wprintw(statwin, "%*c", COLS, ' ');
prepare_statwin(statwin);
show_stats(statwin, 0);
markactive(curwin, table.borderwin, othptbl.borderwin);
diff --git a/src/othptab.c b/src/othptab.c
index 142c9c2..85acf58 100644
--- a/src/othptab.c
+++ b/src/othptab.c
@@ -341,7 +341,6 @@ void printothpentry(struct othptable *table, struct othptabent
*entry,
char additional[MSGSTRING_MAX];
char msgstring[MSGSTRING_MAX];
char scratchpad[MSGSTRING_MAX];
- char sp_buf[SHORTSTRING_MAX];
char *startstr;
char *packet_type;
@@ -354,8 +353,6 @@ void printothpentry(struct othptable *table, struct othptabent
*entry,
struct protoent *protptr;
- sprintf(sp_buf, "%%%dc", COLS - 2);
-
wmove(table->borderwin, table->obmaxy - 1, 1);
if ((table->lastvisible == table->tail) && (table->htstat != TIND)
&& (table->count >= table->oimaxy)) {
@@ -370,7 +367,7 @@ void printothpentry(struct othptable *table, struct othptabent
*entry,
wmove(table->othpwin, target_row, 0);
scrollok(table->othpwin, 0);
wattrset(table->othpwin, UNKNATTR);
- wprintw(table->othpwin, sp_buf, ' ');
+ wprintw(table->othpwin, "%*c", COLS - 2, ' ');
scrollok(table->othpwin, 1);
wmove(table->othpwin, target_row, 1);
@@ -726,7 +723,7 @@ void printothpentry(struct othptable *table, struct othptabent
*entry,
wmove(table->othpwin, target_row, 0);
scrollok(table->othpwin, 0);
- wprintw(table->othpwin, sp_buf, ' ');
+ wprintw(table->othpwin, "%*c", COLS - 2, ' ');
scrollok(table->othpwin, 1);
wmove(table->othpwin, target_row, 1);
startstr = msgstring + table->strindex;
diff --git a/src/serv.c b/src/serv.c
index a41d627..ba0e887 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -277,7 +277,6 @@ static void printportent(struct portlist *list, struct portlistent
*entry,
int tcplabelattr;
int udplabelattr;
int highattr;
- char sp_buf[10];
if ((entry->idx < idx) || (entry->idx > idx + (LINES - 6)))
return;
@@ -295,9 +294,8 @@ static void printportent(struct portlist *list, struct portlistent
*entry,
}
wattrset(list->win, tcplabelattr);
- sprintf(sp_buf, "%%%dc", COLS - 2);
scrollok(list->win, 0);
- mvwprintw(list->win, target_row, 0, sp_buf, ' ');
+ mvwprintw(list->win, target_row, 0, "%*c", COLS - 2, ' ');
scrollok(list->win, 1);
wmove(list->win, target_row, 1);
@@ -627,9 +625,6 @@ static void sortportents(struct portlist *list, unsigned int *idx, int
command)
static void scrollservwin(struct portlist *table, int direction,
unsigned int *idx)
{
- char sp_buf[10];
-
- sprintf(sp_buf, "%%%dc", COLS - 2);
wattrset(table->win, STDATTR);
if (direction == SCROLLUP) {
if (table->lastvisible != table->tail) {
@@ -639,7 +634,7 @@ static void scrollservwin(struct portlist *table, int direction,
(*idx)++;
wmove(table->win, LINES - 6, 0);
scrollok(table->win, 0);
- wprintw(table->win, sp_buf, ' ');
+ wprintw(table->win, "%*c", COLS - 2, ' ');
scrollok(table->win, 1);
printportent(table, table->lastvisible, *idx);
}
@@ -650,7 +645,7 @@ static void scrollservwin(struct portlist *table, int direction,
table->firstvisible = table->firstvisible->prev_entry;
(*idx)--;
wmove(table->win, 0, 0);
- wprintw(table->win, sp_buf, ' ');
+ wprintw(table->win, "%*c", COLS - 2, ' ');
printportent(table, table->firstvisible, *idx);
}
}
@@ -780,8 +775,6 @@ void servmon(char *ifname, time_t facilitytime)
WINDOW *statwin;
PANEL *statpanel;
- char sp_buf[10];
-
int fd;
struct porttab *ports;
@@ -804,8 +797,7 @@ void servmon(char *ifname, time_t facilitytime)
statpanel = new_panel(statwin);
scrollok(statwin, 0);
wattrset(statwin, IPSTATLABELATTR);
- sprintf(sp_buf, "%%%dc", COLS);
- mvwprintw(statwin, 0, 0, sp_buf, ' ');
+ mvwprintw(statwin, 0, 0, "%*c", COLS, ' ');
move(LINES - 1, 1);
scrollkeyhelp();
diff --git a/src/tcptable.c b/src/tcptable.c
index 956866c..e1a6ed8 100644
--- a/src/tcptable.c
+++ b/src/tcptable.c
@@ -809,8 +809,7 @@ void printentry(struct tcptable *table, struct tcptableent
*tableentry,
wmove(table->tcpscreen, target_row, 2);
if (tableentry->reused) {
scrollok(table->tcpscreen, 0);
- sprintf(sp_buf, "%%%dc", COLS - 4);
- wprintw(table->tcpscreen, sp_buf, ' ');
+ wprintw(table->tcpscreen, "%*c", COLS - 4, ' ');
scrollok(table->tcpscreen, 1);
tableentry->reused = 0;
wmove(table->tcpscreen, target_row, 1);
@@ -823,8 +822,7 @@ void printentry(struct tcptable *table, struct tcptableent
*tableentry,
/* proceed with the actual entry */
wattrset(table->tcpscreen, normalattr);
- sprintf(sp_buf, "%%%dc", COLS - 5);
- mvwprintw(table->tcpscreen, target_row, 2, sp_buf, ' ');
+ mvwprintw(table->tcpscreen, target_row, 2, "%*c", COLS - 5, ' ');
sprintf(sp_buf, "%%.%ds:%%.%ds", 32 * COLS / 80, 10);
diff --git a/src/tui/listbox.c b/src/tui/listbox.c
index a9d528c..ce8d5bf 100644
--- a/src/tui/listbox.c
+++ b/src/tui/listbox.c
@@ -83,8 +83,7 @@ void tx_operate_listbox(struct scroll_list *list, int *keystroke, int
*aborted)
int ch;
int endloop = 0;
int row = 0;
- char padding[MAX_TEXT_LENGTH];
- char sp_buf[10];
+ int width = list->width - 3;
if (list->textlist == NULL) {
tui_error(ANYKEY_MSG, "No list entries");
@@ -99,18 +98,13 @@ void tx_operate_listbox(struct scroll_list *list, int *keystroke, int
*aborted)
doupdate();
while (!endloop) {
- snprintf(sp_buf, 9, "%%%zuc",
- list->width - strlen(list->textptr->text) - 3);
- snprintf(padding, MAX_TEXT_LENGTH - 1, sp_buf, ' ');
wattrset(list->win, list->selectattr);
- mvwprintw(list->win, row, 0, " %s%s", list->textptr->text,
- padding);
+ mvwprintw(list->win, row, 0, " %-*s", width, list->textptr->text);
ch = wgetch(list->win);
wattrset(list->win, list->mainattr);
- mvwprintw(list->win, row, 0, " %s%s", list->textptr->text,
- padding);
+ mvwprintw(list->win, row, 0, " %-*s", width, list->textptr->text);
switch (ch) {
case KEY_UP:
diff --git a/src/tui/winops.c b/src/tui/winops.c
index 73a3899..2b953b1 100644
--- a/src/tui/winops.c
+++ b/src/tui/winops.c
@@ -50,13 +50,11 @@ void tx_wcoloreol(WINDOW * win)
int x, curx;
int y __unused;
int cury __unused;
- char sp_buf[10];
getyx(win, cury, curx);
getmaxyx(win, y, x);
- sprintf(sp_buf, "%%%dc", x - curx - 1);
scrollok(win, 0);
- wprintw(win, sp_buf, ' ');
+ wprintw(win, "%*c", x - curx - 1, ' ');
}
/*
--
1.7.8.4