Browse Source

use DIV_ROUND_UP()

master
Boris Faure 1 week ago
parent
commit
62a8e0a021
Signed by: borisfaure
GPG Key ID: EAA9CD729F522998
  1. 20
      scripts/coccinelle/coccicheck.sh
  2. 6
      src/bin/backlog.c
  3. 4
      src/bin/sel.c
  4. 10
      src/bin/termpty.c
  5. 8
      src/bin/tycat.c

20
scripts/coccinelle/coccicheck.sh

@ -13,17 +13,21 @@ notnull.cocci
null_ref.cocci
unused.cocci
use_after_iter.cocci
div_round_up.cocci
"
HAS_ERROR=0
for f in $COCCI_FILES; do
CMD="spatch --timeout 200 --very-quiet --cocci-file scripts/coccinelle/$f --include-headers --dir $DIR"
#CMD="spatch --very-quiet --cocci-file scripts/coccinelle/$f --dir $DIR -allow_inconsistent_paths"
OUT=$($CMD)
echo "$CMD"
if [ -n "$OUT" ]; then
echo "$OUT"
HAS_ERROR=1
fi
OPTIONS=""
if [ "$COCCI_FILES" = "div_round_up" ]; then
OPTIONS="--defined DIV_ROUND_UP"
fi
CMD="spatch --timeout 200 --very-quiet --cocci-file scripts/coccinelle/$f --include-headers --dir $DIR $OPTIONS"
OUT=$($CMD)
echo "$CMD"
if [ -n "$OUT" ]; then
echo "$OUT"
HAS_ERROR=1
fi
done
exit $HAS_ERROR

6
src/bin/backlog.c

@ -16,11 +16,11 @@ _accounting_change(int64_t diff)
{
if (diff > 0)
{
diff = ((diff + 16-1) / 16) * 16;
diff = DIV_ROUND_UP(diff, 16) * 16;
}
else
{
diff = ((-1 * diff + 16-1) / 16) * -16;
diff = DIV_ROUND_UP(-1 * diff, 16) * -16;
}
_mem_used += diff;
}
@ -167,7 +167,7 @@ termpty_backlog_length(Termpty *ty)
if (!ts->cells)
goto end;
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
nb_lines = (ts->w == 0) ? 1 : DIV_ROUND_UP(ts->w, ty->w);
screen_y += nb_lines;
ty->backlog_beacon.screen_y = screen_y;
ty->backlog_beacon.backlog_y = backlog_y;

4
src/bin/sel.c

@ -147,7 +147,7 @@ _mouse_move_cb(void *data,
return;
iw = sqrt(eina_list_count(sd->items));
if (iw < 1) iw = 1;
ih = (eina_list_count(sd->items) + (iw - 1)) / iw;
ih = DIV_ROUND_UP(eina_list_count(sd->items), iw);
if (ih < 1) ih = 1;
evas_object_geometry_get(sd->self, &x, &y, &w, &h);
sw = w * sd->zoom;
@ -366,7 +366,7 @@ _layout(Sel *sd)
iw = sqrt(eina_list_count(sd->items));
if (iw < 1) iw = 1;
ih = (eina_list_count(sd->items) + (iw - 1)) / iw;
ih = DIV_ROUND_UP(eina_list_count(sd->items), iw);
if (ih < 1) ih = 1;
evas_object_geometry_get(sd->self, &ox, &oy, &ow, &oh);
w = ow * sd->zoom;

10
src/bin/termpty.c

@ -992,8 +992,8 @@ termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
{
int old_len = ts->w;
termpty_save_expand(ty, ts, cells, w);
ty->backlog_beacon.screen_y += (ts->w + ty->w - 1) / ty->w
- (old_len + ty->w - 1) / ty->w;
ty->backlog_beacon.screen_y += DIV_ROUND_UP(ts->w, ty->w)
- DIV_ROUND_UP(old_len, ty->w);
return;
}
}
@ -1060,7 +1060,7 @@ termpty_backscroll_adjust(Termpty *ty, int *scroll)
*scroll = ty->backlog_beacon.screen_y;
return;
}
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
nb_lines = (ts->w == 0) ? 1 : DIV_ROUND_UP(ts->w, ty->w);
screen_y += nb_lines;
ty->backlog_beacon.screen_y = screen_y;
ty->backlog_beacon.backlog_y = backlog_y;
@ -1099,7 +1099,7 @@ _termpty_cellrow_from_beacon_get(Termpty *ty, int requested_y, ssize_t *wret)
{
return NULL;
}
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
nb_lines = (ts->w == 0) ? 1 : DIV_ROUND_UP(ts->w, ty->w);
/* Only update the beacon if working on different line than the one
* from the beacon */
@ -1130,7 +1130,7 @@ _termpty_cellrow_from_beacon_get(Termpty *ty, int requested_y, ssize_t *wret)
{
return NULL;
}
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
nb_lines = (ts->w == 0) ? 1 : DIV_ROUND_UP(ts->w, ty->w);
ty->backlog_beacon.screen_y = screen_y;
ty->backlog_beacon.backlog_y = backlog_y;

8
src/bin/tycat.c

@ -52,17 +52,17 @@ scaleterm(int w, int h, int *iw, int *ih)
if (w > (width * cw))
{
*iw = width;
*ih = ((h * (width * cw) / w) + (ch - 1)) / ch;
*ih = DIV_ROUND_UP((h * (width * cw) / w), ch);
}
else
{
*iw = (w + (cw - 1)) / cw;
*ih = (h + (ch - 1)) / ch;
*iw = DIV_ROUND_UP(w, cw);
*ih = DIV_ROUND_UP(h, ch);
}
if (maxh && *ih > maxh)
{
*ih = maxh;
*iw = ((w * (maxh * ch) / h) + (cw - 1)) / cw;
*iw = DIV_ROUND_UP((w * (maxh * ch) / h), cw);
}
}

Loading…
Cancel
Save