commit b7beb4433d178aa96ace40bcd4e4eba913c4af1f
parent 847fb6ce4bd43c83cb9a0ace7d56a34f87891714
Author: Claudio Alessi <smoppy@gmail.com>
Date: Sun, 13 Mar 2016 16:43:41 +0100
Implements maxof().
Clean up a bit.
Diffstat:
M | core.c | | | 23 | +++++++++++++---------- |
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/core.c b/core.c
@@ -93,6 +93,7 @@ void flagas(const Arg *arg);
Item *getitem(void);
int *getmaxlengths(View *view);
void itempos(const Arg *arg);
+int maxof(int *list, int size);
MYSQL_RES *mysql_exec(const char *sqlstr, ...);
int mysql_fields(MYSQL_RES *res, Field **fields);
int mysql_items(MYSQL_RES *res, Item **items);
@@ -377,6 +378,16 @@ itempos(const Arg *arg) {
stfl_set(selview->form, L"pos", stfl_ipool_towc(ipool, tmp));
}
+int
+maxof(int *list, int size) {
+ int i, max = 0;
+
+ for(i = 0; i < size; ++i)
+ if(max < list[i])
+ max = list[i];
+ return max;
+}
+
MYSQL_RES *
mysql_exec(const char *sqlstr, ...) {
MYSQL_RES *res;
@@ -475,11 +486,7 @@ stfl_showfields(Field *fds, int *lens) {
for(fld = fds, nfields = 0; fld; fld = fld->next, ++nfields);
- maxlen = 0;
- for(i = 0; i < nfields; ++i)
- if(maxlen < lens[i])
- maxlen = lens[i];
-
+ maxlen = maxof(lens, nfields);
txtsz = maxlen + 1;
linesz = maxlen * nfields + fldseplen * (nfields - 1) + 1;
txt = ecalloc(txtsz, sizeof(char));
@@ -649,11 +656,7 @@ stfl_putitem(Item *item, int *lens) {
if(!(item && lens))
return;
- maxlen = 0;
- for(i = 0; i < item->ncols; ++i)
- if(maxlen < lens[i])
- maxlen = lens[i];
-
+ maxlen = maxof(lens, item->ncols);
txtsz = maxlen + 1;
linesz = maxlen * item->ncols + fldseplen * (item->ncols - 1) + 1;
txt = ecalloc(txtsz, sizeof(char));