makes the code more readable and also exe smaller (cca 700B)
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/hostmon.c | 50 ++++++++++++++++++--------------------------------
src/ifstats.c | 33 +++++++++++----------------------
src/itrafmon.c | 9 +++------
src/landesc.c | 6 ++----
src/options.c | 3 +--
src/othptab.c | 3 +--
src/pktsize.c | 9 +++------
src/serv.c | 30 ++++++++++--------------------
src/tcptable.c | 24 ++++++++----------------
src/timer.c | 3 +--
src/tui/input.c | 9 +++------
src/tui/menurt.c | 3 +--
src/tui/msgboxes.c | 3 +--
src/tui/winops.c | 3 +--
14 files changed, 64 insertions(+), 124 deletions(-)
diff --git a/src/hostmon.c b/src/hostmon.c
index 1548a0a..44dcf40 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -162,28 +162,18 @@ static void initethtab(struct ethtab *table)
wattrset(table->borderwin, BOXATTR);
tx_box(table->borderwin, ACS_VLINE, ACS_HLINE);
- wmove(table->borderwin, 0, 5 * COLS / 80);
- wprintw(table->borderwin, " PktsIn ");
- wmove(table->borderwin, 0, 16 * COLS / 80);
- wprintw(table->borderwin, " IP In ");
- wmove(table->borderwin, 0, 24 * COLS / 80);
- wprintw(table->borderwin, " BytesIn ");
- wmove(table->borderwin, 0, 34 * COLS / 80);
- wprintw(table->borderwin, " InRate ");
-
- wmove(table->borderwin, 0, 42 * COLS / 80);
- wprintw(table->borderwin, " PktsOut ");
- wmove(table->borderwin, 0, 53 * COLS / 80);
- wprintw(table->borderwin, " IP Out ");
- wmove(table->borderwin, 0, 61 * COLS / 80);
- wprintw(table->borderwin, " BytesOut ");
- wmove(table->borderwin, 0, 70 * COLS / 80);
- wprintw(table->borderwin, " OutRate ");
-
- wmove(table->borderwin, LINES - 3, 40);
-
- wprintw(table->borderwin, " InRate and OutRate are in %s ",
- dispmode(options.actmode));
+
+ mvwprintw(table->borderwin, 0, 5 * COLS / 80, " PktsIn ");
+ mvwprintw(table->borderwin, 0, 16 * COLS / 80, " IP In ");
+ mvwprintw(table->borderwin, 0, 24 * COLS / 80, " BytesIn ");
+ mvwprintw(table->borderwin, 0, 34 * COLS / 80, " InRate ");
+ mvwprintw(table->borderwin, 0, 42 * COLS / 80, " PktsOut ");
+ mvwprintw(table->borderwin, 0, 53 * COLS / 80, " IP Out ");
+ mvwprintw(table->borderwin, 0, 61 * COLS / 80, " BytesOut ");
+ mvwprintw(table->borderwin, 0, 70 * COLS / 80, " OutRate ");
+
+ mvwprintw(table->borderwin, LINES - 3, 40,
+ " InRate and OutRate are in %s ", dispmode(options.actmode));
wattrset(table->tabwin, STDATTR);
tx_colorwin(table->tabwin);
@@ -283,8 +273,8 @@ static struct ethtabent *addethentry(struct ethtab *table,
table->entcount++;
- wmove(table->borderwin, LINES - 3, 1);
- wprintw(table->borderwin, " %u entries ", table->entcount);
+ mvwprintw(table->borderwin, LINES - 3, 1, " %u entries ",
+ table->entcount);
return ptemp;
}
@@ -414,13 +404,11 @@ static void printrates(struct ethtab *table, unsigned int
target_row,
rate_print_no_units(rate_get_average(&ptmp->un.figs.inrate),
buf, sizeof(buf));
- wmove(table->tabwin, target_row, 32 * COLS / 80);
- wprintw(table->tabwin, "%s", buf);
+ mvwprintw(table->tabwin, target_row, 32 * COLS / 80, "%s", buf);
rate_print_no_units(rate_get_average(&ptmp->un.figs.outrate),
buf, sizeof(buf));
- wmove(table->tabwin, target_row, 69 * COLS / 80);
- wprintw(table->tabwin, "%s", buf);
+ mvwprintw(table->tabwin, target_row, 69 * COLS / 80, "%s", buf);
}
static void updateethrates(struct ethtab *table, unsigned long msecs,
@@ -476,9 +464,8 @@ static void scrollethwin(struct ethtab *table, int direction, unsigned
int *idx)
table->lastvisible = table->lastvisible->next_entry;
table->firstvisible = table->firstvisible->next_entry;
(*idx)++;
- wmove(table->tabwin, LINES - 5, 0);
scrollok(table->tabwin, 0);
- wprintw(table->tabwin, "%*c", COLS - 2, ' ');
+ mvwprintw(table->tabwin, LINES - 5, 0, "%*c", COLS - 2, ' ');
scrollok(table->tabwin, 1);
printethent(table, table->lastvisible, *idx);
if (table->lastvisible->type == 1)
@@ -491,8 +478,7 @@ static void scrollethwin(struct ethtab *table, int direction, unsigned
int *idx)
table->lastvisible = table->lastvisible->prev_entry;
table->firstvisible = table->firstvisible->prev_entry;
(*idx)--;
- wmove(table->tabwin, 0, 0);
- wprintw(table->tabwin, "%*c", COLS - 2, ' ');
+ mvwprintw(table->tabwin, 0, 0, "%*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 b11d853..3098868 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -298,8 +298,7 @@ static void printifentry(struct iflist *ptmp, WINDOW * win, unsigned
int idx)
target_row = ptmp->index - idx;
wattrset(win, STDATTR);
- wmove(win, target_row, 1);
- wprintw(win, "%s", ptmp->ifname);
+ mvwprintw(win, target_row, 1, "%s", ptmp->ifname);
wattrset(win, HIGHATTR);
wmove(win, target_row, 14 * COLS / 80);
printlargenum(ptmp->total, win);
@@ -333,24 +332,17 @@ static void print_if_entries(struct iftab *table)
static void labelstats(WINDOW *win)
{
- wmove(win, 0, 1);
- wprintw(win, " Iface ");
+ mvwprintw(win, 0, 1, " Iface ");
/* 14, 24, 34, ... from printifentry() */
/* 10 = strlen(printed number); from printlargenum() */
/* 7 = strlen(" Total ") */
/* 1 = align the string on 'l' from " Total " */
- wmove(win, 0, (14 * COLS / 80) + 10 - 7 + 1);
- wprintw(win, " Total ");
- wmove(win, 0, (24 * COLS / 80) + 10 - 6 + 1);
- wprintw(win, " IPv4 ");
- wmove(win, 0, (34 * COLS / 80) + 10 - 6 + 1);
- wprintw(win, " IPv6 ");
- wmove(win, 0, (44 * COLS / 80) + 10 - 7 + 1);
- wprintw(win, " NonIP ");
- wmove(win, 0, (53 * COLS / 80) + 8 - 7 + 1);
- wprintw(win, " BadIP ");
- wmove(win, 0, (63 * COLS / 80) + 14 - 10);
- wprintw(win, " Activity ");
+ mvwprintw(win, 0, (14 * COLS / 80) + 10 - 7 + 1, " Total ");
+ mvwprintw(win, 0, (24 * COLS / 80) + 10 - 6 + 1, " IPv4 ");
+ mvwprintw(win, 0, (34 * COLS / 80) + 10 - 6 + 1, " IPv6 ");
+ mvwprintw(win, 0, (44 * COLS / 80) + 10 - 7 + 1, " NonIP ");
+ mvwprintw(win, 0, (53 * COLS / 80) + 8 - 7 + 1, " BadIP ");
+ mvwprintw(win, 0, (63 * COLS / 80) + 14 - 10, " Activity ");
}
static void initiftab(struct iftab *table)
@@ -371,8 +363,7 @@ static void initiftab(struct iftab *table)
wattrset(table->statwin, STDATTR);
tx_colorwin(table->statwin);
wattrset(table->statwin, BOXATTR);
- wmove(table->borderwin, LINES - 3, 32 * COLS / 80);
- wprintw(table->borderwin,
+ mvwprintw(table->borderwin, LINES - 3, 32 * COLS / 80,
" Total, IP, NonIP, and BadIP are packet counts ");
}
@@ -388,9 +379,8 @@ static void scrollgstatwin(struct iftab *table, int direction)
wscrl(table->statwin, 1);
table->lastvisible = table->lastvisible->next_entry;
table->firstvisible = table->firstvisible->next_entry;
- wmove(table->statwin, LINES - 5, 0);
scrollok(table->statwin, 0);
- wprintw(table->statwin, "%*c", COLS - 2, ' ');
+ mvwprintw(table->statwin, LINES - 5, 0, "%*c", COLS - 2, ' ');
scrollok(table->statwin, 1);
printifentry(table->lastvisible, table->statwin,
table->firstvisible->index);
@@ -400,8 +390,7 @@ static void scrollgstatwin(struct iftab *table, int direction)
wscrl(table->statwin, -1);
table->firstvisible = table->firstvisible->prev_entry;
table->lastvisible = table->lastvisible->prev_entry;
- wmove(table->statwin, 0, 0);
- wprintw(table->statwin, "%*c", COLS - 2, ' ');
+ mvwprintw(table->statwin, 0, 0, "%*c", COLS - 2, ' ');
printifentry(table->firstvisible, table->statwin,
table->firstvisible->index);
}
diff --git a/src/itrafmon.c b/src/itrafmon.c
index 259bd2f..20c6f6c 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -72,8 +72,7 @@ static void uniq_help(int what)
static void prepare_statwin(WINDOW * win)
{
wattrset(win, IPSTATLABELATTR);
- wmove(win, 0, 1);
- wprintw(win, "Packets captured:");
+ mvwprintw(win, 0, 1, "Packets captured:");
mvwaddch(win, 0, 45 * COLS / 80, ACS_VLINE);
}
@@ -136,8 +135,7 @@ static void scrollupperwin(struct tcptable *table, int direction,
table->firstvisible = table->firstvisible->prev_entry;
table->lastvisible = table->lastvisible->prev_entry;
(*idx)--;
- wmove(table->tcpscreen, 0, 0);
- wprintw(table->tcpscreen, "%*c", COLS - 2, ' ');
+ mvwprintw(table->tcpscreen, 0, 0, "%*c", COLS - 2, ' ');
printentry(table, table->firstvisible, *idx, mode);
}
}
@@ -622,8 +620,7 @@ void ipmon(time_t facilitytime, char *ifptr)
statwin = newwin(1, COLS, LINES - 2, 0);
statpanel = new_panel(statwin);
wattrset(statwin, IPSTATLABELATTR);
- wmove(statwin, 0, 0);
- wprintw(statwin, "%*c", COLS, ' ');
+ mvwprintw(statwin, 0, 0, "%*c", COLS, ' ');
prepare_statwin(statwin);
show_stats(statwin, 0);
markactive(curwin, table.borderwin, othptbl.borderwin);
diff --git a/src/landesc.c b/src/landesc.c
index 4d67ed8..1f48137 100644
--- a/src/landesc.c
+++ b/src/landesc.c
@@ -254,10 +254,8 @@ static int dialog_eth_desc(struct FIELDLIST *fields, const char
*initaddr,
stdkeyhelp(win);
wattrset(win, DLGTEXTATTR);
- wmove(win, 2, 2 * COLS / 80);
- wprintw(win, "MAC Address:");
- wmove(win, 4, 2 * COLS / 80);
- wprintw(win, "Description:");
+ mvwprintw(win, 2, 2 * COLS / 80, "MAC Address:");
+ mvwprintw(win, 4, 2 * COLS / 80, "Description:");
tx_initfields(fields, 3, 52, 10, (COLS - 52) / 2 + 6 * COLS / 80,
DLGTEXTATTR, FIELDATTR);
diff --git a/src/options.c b/src/options.c
index a1cd4f8..c9b1ed1 100644
--- a/src/options.c
+++ b/src/options.c
@@ -212,8 +212,7 @@ static void settimeout(time_t *value, const char *units, int
allow_zero,
tx_box(dlgwin, ACS_VLINE, ACS_HLINE);
wattrset(dlgwin, DLGTEXTATTR);
- wmove(dlgwin, 2, 2);
- wprintw(dlgwin, "Enter value in %s", units);
+ mvwprintw(dlgwin, 2, 2, "Enter value in %s", units);
wmove(dlgwin, 5, 2);
stdkeyhelp(dlgwin);
diff --git a/src/othptab.c b/src/othptab.c
index 85acf58..5c09241 100644
--- a/src/othptab.c
+++ b/src/othptab.c
@@ -721,9 +721,8 @@ void printothpentry(struct othptable *table, struct othptabent
*entry,
strcat(msgstring, " on ");
strcat(msgstring, entry->iface);
- wmove(table->othpwin, target_row, 0);
scrollok(table->othpwin, 0);
- wprintw(table->othpwin, "%*c", COLS - 2, ' ');
+ mvwprintw(table->othpwin, target_row, 0, "%*c", COLS - 2, ' ');
scrollok(table->othpwin, 1);
wmove(table->othpwin, target_row, 1);
startstr = msgstring + table->strindex;
diff --git a/src/pktsize.c b/src/pktsize.c
index f30210f..54fb680 100644
--- a/src/pktsize.c
+++ b/src/pktsize.c
@@ -77,12 +77,10 @@ static int initialize_brackets(struct ifstat_brackets *brackets,
for (i = 0; i <= 9; i++) {
wattrset(win, STDATTR);
- wmove(win, i + 5, 2);
- wprintw(win, "%4u to %4u:", brackets[i].floor,
+ mvwprintw(win, i + 5, 2, "%4u to %4u:", brackets[i].floor,
brackets[i].ceil);
- wmove(win, i + 5, 23);
wattrset(win, HIGHATTR);
- wprintw(win, "%8lu", 0);
+ mvwprintw(win, i + 5, 23, "%8lu", 0);
}
for (i = 10; i <= 19; i++) {
@@ -96,9 +94,8 @@ static int initialize_brackets(struct ifstat_brackets *brackets,
wprintw(win, "%4u to %4u+:", brackets[i].floor,
brackets[i].ceil);
- wmove(win, (i - 10) + 5, 57);
wattrset(win, HIGHATTR);
- wprintw(win, "%8lu", 0);
+ mvwprintw(win, (i - 10) + 5, 57, "%8lu", 0);
}
wattrset(win, STDATTR);
diff --git a/src/serv.c b/src/serv.c
index ba0e887..34421b3 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -159,20 +159,13 @@ static void initportlist(struct portlist *list)
wattrset(list->borderwin, BOXATTR);
tx_box(list->borderwin, ACS_VLINE, ACS_HLINE);
- wmove(list->borderwin, 0, 1 * screen_scale);
- wprintw(list->borderwin, " Proto/Port ");
- wmove(list->borderwin, 0, 22 * screen_scale);
- wprintw(list->borderwin, " Pkts ");
- wmove(list->borderwin, 0, 31 * screen_scale);
- wprintw(list->borderwin, " Bytes ");
- wmove(list->borderwin, 0, 40 * screen_scale);
- wprintw(list->borderwin, " PktsTo ");
- wmove(list->borderwin, 0, 49 * screen_scale);
- wprintw(list->borderwin, " BytesTo ");
- wmove(list->borderwin, 0, 58 * screen_scale);
- wprintw(list->borderwin, " PktsFrom ");
- wmove(list->borderwin, 0, 67 * screen_scale);
- wprintw(list->borderwin, " BytesFrom ");
+ mvwprintw(list->borderwin, 0, 1 * screen_scale, " Proto/Port ");
+ mvwprintw(list->borderwin, 0, 22 * screen_scale, " Pkts ");
+ mvwprintw(list->borderwin, 0, 31 * screen_scale, " Bytes ");
+ mvwprintw(list->borderwin, 0, 40 * screen_scale, " PktsTo ");
+ mvwprintw(list->borderwin, 0, 49 * screen_scale, " BytesTo ");
+ mvwprintw(list->borderwin, 0, 58 * screen_scale, " PktsFrom ");
+ mvwprintw(list->borderwin, 0, 67 * screen_scale, " BytesFrom ");
list->win = newwin(LINES - 5, COLS - 2, 2, 1);
list->panel = new_panel(list->win);
@@ -228,8 +221,7 @@ static struct portlistent *addtoportlist(struct portlist *list,
if (list->count <= (unsigned) LINES - 5)
list->lastvisible = ptemp;
- wmove(list->borderwin, LINES - 4, 1);
- wprintw(list->borderwin, " %u entries ", list->count);
+ mvwprintw(list->borderwin, LINES - 4, 1, " %u entries ", list->count);
return ptemp;
}
@@ -632,9 +624,8 @@ static void scrollservwin(struct portlist *table, int direction,
table->lastvisible = table->lastvisible->next_entry;
table->firstvisible = table->firstvisible->next_entry;
(*idx)++;
- wmove(table->win, LINES - 6, 0);
scrollok(table->win, 0);
- wprintw(table->win, "%*c", COLS - 2, ' ');
+ mvwprintw(table->win, LINES - 6, 0, "%*c", COLS - 2, ' ');
scrollok(table->win, 1);
printportent(table, table->lastvisible, *idx);
}
@@ -644,8 +635,7 @@ static void scrollservwin(struct portlist *table, int direction,
table->lastvisible = table->lastvisible->prev_entry;
table->firstvisible = table->firstvisible->prev_entry;
(*idx)--;
- wmove(table->win, 0, 0);
- wprintw(table->win, "%*c", COLS - 2, ' ');
+ mvwprintw(table->win, 0, 0, "%*c", COLS - 2, ' ');
printportent(table, table->firstvisible, *idx);
}
}
diff --git a/src/tcptable.c b/src/tcptable.c
index e1a6ed8..a4133d9 100644
--- a/src/tcptable.c
+++ b/src/tcptable.c
@@ -33,17 +33,13 @@ static void setlabels(WINDOW *win, int mode)
whline(win, ACS_HLINE, 23 * COLS / 80);
if (mode == 0) {
- wmove(win, 0, 47 * COLS / 80);
- wprintw(win, " Packets ");
- wmove(win, 0, 59 * COLS / 80);
- wprintw(win, " Bytes ");
+ mvwprintw(win, 0, 47 * COLS / 80, " Packets ");
+ mvwprintw(win, 0, 59 * COLS / 80, " Bytes ");
} else if (mode == 1) {
mvwprintw(win, 0, 47 * COLS / 80, " Source MAC Addr ");
} else if (mode == 2) {
- wmove(win, 0, 45 * COLS / 80);
- wprintw(win, " Pkt Size ");
- wmove(win, 0, 56 * COLS / 80);
- wprintw(win, " Win Size ");
+ mvwprintw(win, 0, 45 * COLS / 80, " Pkt Size ");
+ mvwprintw(win, 0, 56 * COLS / 80, " Win Size ");
}
}
@@ -112,15 +108,12 @@ void init_tcp_table(struct tcptable *table)
wattrset(table->borderwin, BOXATTR);
tx_box(table->borderwin, ACS_VLINE, ACS_HLINE);
- wmove(table->borderwin, 0, 1);
- wprintw(table->borderwin, " TCP Connections (Source Host:Port) ");
+ mvwprintw(table->borderwin, 0, 1, " TCP Connections (Source Host:Port) ");
setlabels(table->borderwin, 0); /* initially use mode 0 */
- wmove(table->borderwin, 0, 65 * COLS / 80);
- wprintw(table->borderwin, " Flag ");
- wmove(table->borderwin, 0, 70 * COLS / 80);
- wprintw(table->borderwin, " Iface ");
+ mvwprintw(table->borderwin, 0, 65 * COLS / 80, " Flag ");
+ mvwprintw(table->borderwin, 0, 70 * COLS / 80, " Iface ");
update_panels();
doupdate();
table->ifnamew = COLS - (70 * COLS / 80) - 3;
@@ -767,8 +760,7 @@ void clearaddr(struct tcptable *table, struct tcptableent
*tableentry,
target_row = (tableentry->index) - screen_idx;
- wmove(table->tcpscreen, target_row, 1);
- wprintw(table->tcpscreen, "%44c", ' ');
+ mvwprintw(table->tcpscreen, target_row, 1, "%44c", ' ');
}
/*
diff --git a/src/timer.c b/src/timer.c
index 64bef53..08fed75 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -21,6 +21,5 @@ void printelapsedtime(time_t start, time_t now, int y, int x, WINDOW *
win)
hours = elapsed / 3600;
mins = (elapsed % 3600) / 60;
- wmove(win, y, x);
- wprintw(win, " Elapsed time: %3u:%02u ", hours, mins);
+ mvwprintw(win, y, x, " Elapsed time: %3u:%02u ", hours, mins);
}
diff --git a/src/tui/input.c b/src/tui/input.c
index b0742c3..2f76ed3 100644
--- a/src/tui/input.c
+++ b/src/tui/input.c
@@ -62,8 +62,7 @@ void tx_addfield(struct FIELDLIST *list, unsigned int len, unsigned int
y,
for (i = 1; i <= len; i++)
wprintw(list->fieldwin, " ");
- wmove(list->fieldwin, y, x);
- wprintw(list->fieldwin, "%s", newfield->buf);
+ mvwprintw(list->fieldwin, y, x, "%s", newfield->buf);
update_panels();
doupdate();
@@ -75,9 +74,8 @@ void tx_getinput(struct FIELDLIST *list, struct FIELD *field, int
*exitkey)
int y, x;
int endloop = 0;
- wmove(list->fieldwin, field->ypos, field->xpos);
wattrset(list->fieldwin, list->fieldattr);
- wprintw(list->fieldwin, "%s", field->buf);
+ mvwprintw(list->fieldwin, field->ypos, field->xpos, "%s",
field->buf);
update_panels();
doupdate();
@@ -93,8 +91,7 @@ void tx_getinput(struct FIELDLIST *list, struct FIELD *field, int
*exitkey)
if (field->tlen > 0) {
getyx(list->fieldwin, y, x);
x--;
- wmove(list->fieldwin, y, x);
- wprintw(list->fieldwin, " ");
+ mvwprintw(list->fieldwin, y, x, " ");
wmove(list->fieldwin, y, x);
field->tlen--;
field->buf[field->tlen] = '\0';
diff --git a/src/tui/menurt.c b/src/tui/menurt.c
index 265e297..b4c153a 100644
--- a/src/tui/menurt.c
+++ b/src/tui/menurt.c
@@ -200,8 +200,7 @@ void tx_operatemenu(struct MENU *menu, int *position, int *aborted)
wattrset(menu->descwin, menu->descriptionattr);
tx_colorwin(menu->descwin);
- wmove(menu->descwin, 0, 0);
- wprintw(menu->descwin, " %s", itemptr->desc);
+ mvwprintw(menu->descwin, 0, 0, " %s", itemptr->desc);
update_panels();
doupdate();
diff --git a/src/tui/msgboxes.c b/src/tui/msgboxes.c
index ee7ebdf..0b58716 100644
--- a/src/tui/msgboxes.c
+++ b/src/tui/msgboxes.c
@@ -39,9 +39,8 @@ void tui_error_va(const char *prompt, const char *err, va_list vararg)
wattrset(win, ERR_BORDER_ATTR);
tx_colorwin(win);
tx_box(win, ACS_VLINE, ACS_HLINE);
- wmove(win, 2, 2);
wattrset(win, ERR_PROMPT_ATTR);
- wprintw(win, "%s", prompt);
+ mvwprintw(win, 2, 2, "%s", prompt);
wattrset(win, ERR_TEXT_ATTR);
wmove(win, 1, 2);
diff --git a/src/tui/winops.c b/src/tui/winops.c
index 2b953b1..e323631 100644
--- a/src/tui/winops.c
+++ b/src/tui/winops.c
@@ -38,8 +38,7 @@ void tx_colorwin(WINDOW * win)
scrollok(win, 0);
for (ctr = 0; ctr < getmaxy(win); ctr++) {
- wmove(win, ctr, 0);
- wprintw(win, "%s", blankpad);
+ mvwprintw(win, ctr, 0, "%s", blankpad);
}
scrollok(win, 1);
free(blankpad);
--
1.7.8.4