Skip to content

Commit

Permalink
roff: fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince213 committed Sep 4, 2021
1 parent 43e7db6 commit 5b72358
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 120 deletions.
2 changes: 2 additions & 0 deletions char.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,7 @@ int sstr_next(void)

void sstr_back(int c)
{
/* not used */
(void) c;
sstr_s--;
}
4 changes: 2 additions & 2 deletions clr.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int ccom(char *s, int len)
int clr_get(char *s)
{
int c = (unsigned char) s[0];
int i;
size_t i;
if (c == '#' && strlen(s) == 7)
return CLR_RGB(ccom(s + 1, 2), ccom(s + 3, 2), ccom(s + 5, 2));
if (c == '#' && strlen(s) == 4)
Expand All @@ -53,7 +53,7 @@ int clr_get(char *s)
return CLR_RGB(ccom(s + 1, 2), ccom(s + 1, 2), ccom(s + 1, 2));
if (c == '#' && strlen(s) == 2)
return CLR_RGB(ccom(s + 1, 1), ccom(s + 1, 1), ccom(s + 1, 1));
if (isdigit(c) && atoi(s) >= 0 && atoi(s) < LEN(colors))
if (isdigit(c) && atoi(s) >= 0 && (size_t) atoi(s) < LEN(colors))
return colors[atoi(s)].value;
for (i = 0; i < LEN(colors); i++)
if (!strcmp(colors[i].name, s))
Expand Down
2 changes: 1 addition & 1 deletion dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void tr_fspecial(char **args)
return;
}
for (i = 2; i < NARGS; i++) {
if (args[i] && fspecial_n < LEN(fspecial_fn)) {
if (args[i] && (size_t) fspecial_n < LEN(fspecial_fn)) {
snprintf(fspecial_fn[fspecial_n],
sizeof(fspecial_fn[fspecial_n]), "%s", fn);
snprintf(fspecial_sp[fspecial_n],
Expand Down
2 changes: 1 addition & 1 deletion draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void ren_dcmd(struct wb *wb, char *s)
while (*s) {
if (tok_numpt(&s, 'm', &h1) || tok_numpt(&s, 'v', &v1)) {
char tok[64];
int i = 0;
size_t i = 0;
while (i < sizeof(tok) - 1 && *s && *s != ' ')
tok[i++] = *s++;
tok[i] = '\0';
Expand Down
6 changes: 5 additions & 1 deletion fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ static void fmt_wb2word(struct fmt *f, struct word *word, struct wb *wb,
int hy, int str, int gap, int cost)
{
int len = strlen(wb_buf(wb));
/* not used */
(void) f;
word->s = xmalloc(len + 1);
memcpy(word->s, wb_buf(wb), len + 1);
word->wid = wb_wid(wb);
Expand Down Expand Up @@ -451,7 +453,7 @@ static long scaledown(long cost)
static long FMT_COST(int llen, int lwid, int swid, int nspc)
{
/* the ratio that the stretchable spaces of the line should be spread */
long ratio = abs((llen - lwid) * 100l / (swid ? swid : 1));
long ratio = labs((llen - lwid) * 100l / (swid ? swid : 1));
/* ratio too large; scaling it down */
if (ratio > 4000)
ratio = 4000 + scaledown(ratio - 4000);
Expand Down Expand Up @@ -544,6 +546,8 @@ static int fmt_breakparagraph(struct fmt *f, int pos, int br)
int lwid = 0; /* current line length */
int swid = 0; /* amount of stretchable spaces */
int nspc = 0; /* number of stretchable spaces */
/* not used */
(void) swid;
if (f->fillreq > 0 && f->fillreq <= f->words_n) {
fmt_findcost(f, f->fillreq);
return f->fillreq;
Expand Down
20 changes: 13 additions & 7 deletions font.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ int font_layout(struct font *fn, struct glyph **gsrc, int nsrc, int sz,
int ndst = nsrc;
int i;
int featlg, featkn;
/* not used */
(void) sz;
/* initialising dst */
for (i = 0; i < nsrc; i++)
dst[i] = font_idx(fn, gsrc[i]);
Expand Down Expand Up @@ -353,10 +355,10 @@ static int font_readchar(struct font *fn, FILE *fin, int *n, int *gid)
static int font_findfeat(struct font *fn, char *feat)
{
int i;
for (i = 0; i < LEN(fn->feat_name) && fn->feat_name[i][0]; i++)
for (i = 0; (size_t) i < LEN(fn->feat_name) && fn->feat_name[i][0]; i++)
if (!strcmp(feat, fn->feat_name[i]))
return i;
if (i < LEN(fn->feat_name)) {
if ((size_t) i < LEN(fn->feat_name)) {
snprintf(fn->feat_name[i], sizeof(fn->feat_name[i]), "%s", feat);
return i;
}
Expand All @@ -366,10 +368,10 @@ static int font_findfeat(struct font *fn, char *feat)
static int font_findscrp(struct font *fn, char *scrp)
{
int i;
for (i = 0; i < LEN(fn->scrp_name) && fn->scrp_name[i][0]; i++)
for (i = 0; (size_t) i < LEN(fn->scrp_name) && fn->scrp_name[i][0]; i++)
if (!strcmp(scrp, fn->scrp_name[i]))
return i;
if (i == LEN(fn->scrp_name))
if ((size_t) i == LEN(fn->scrp_name))
return -1;
snprintf(fn->scrp_name[i], sizeof(fn->scrp_name[i]), "%s", scrp);
return i;
Expand All @@ -378,10 +380,10 @@ static int font_findscrp(struct font *fn, char *scrp)
static int font_findlang(struct font *fn, char *lang)
{
int i;
for (i = 0; i < LEN(fn->lang_name) && fn->lang_name[i][0]; i++)
for (i = 0; (size_t) i < LEN(fn->lang_name) && fn->lang_name[i][0]; i++)
if (!strcmp(lang, fn->lang_name[i]))
return i;
if (i == LEN(fn->lang_name))
if ((size_t) i == LEN(fn->lang_name))
return -1;
snprintf(fn->lang_name[i], sizeof(fn->lang_name[i]), "%s", lang);
return i;
Expand All @@ -390,6 +392,8 @@ static int font_findlang(struct font *fn, char *lang)
static struct gpat *font_gpat(struct font *fn, int len)
{
struct gpat *pats = xmalloc(len * sizeof(pats[0]));
/* not used */
(void) fn;
memset(pats, 0, len * sizeof(pats[0]));
return pats;
}
Expand Down Expand Up @@ -582,6 +586,8 @@ static void skipline(FILE* filp)
static struct gpat *font_rulefirstpat(struct font *fn, struct grule *rule)
{
int i;
/* not used */
(void) fn;
for (i = 0; i < rule->len; i++)
if (!(rule->pats[i].flg & (GF_REP | GF_CON)))
return &rule->pats[i];
Expand Down Expand Up @@ -633,7 +639,7 @@ struct font *font_open(char *path)
while (fscanf(fin, "%s", ligs[ligs_n]) == 1) {
if (!strcmp("0", ligs[ligs_n]))
break;
if (ligs_n < LEN(ligs))
if ((size_t) ligs_n < LEN(ligs))
ligs_n++;
}
} else if (!strcmp("gsec", tok)) {
Expand Down
6 changes: 3 additions & 3 deletions hyph.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void hw_add(char *s)
char *n = hwhyph + hwword_len;
int len = strlen(s) + 1;
int i = 0, c;
if (hw_n == NHYPHS || hwword_len + len > sizeof(hwword))
if (hw_n == NHYPHS || (size_t)(hwword_len + len) > sizeof(hwword))
return;
memset(n, 0, len);
while ((c = (unsigned char) *s++)) {
Expand Down Expand Up @@ -181,7 +181,7 @@ static void hy_add(char *s)
char *n = hynums + hypats_len;
int len = strlen(s) + 1;
int i = 0, c;
if (hy_n >= NHYPHS || hypats_len + len >= sizeof(hypats))
if (hy_n >= NHYPHS || (size_t)(hypats_len + len) >= sizeof(hypats))
return;
memset(n, 0, len);
while ((c = (unsigned char) *s++)) {
Expand Down Expand Up @@ -385,7 +385,7 @@ void tr_hpfa(char **args)
}
/* lowercase-uppercase character hcode mappings */
if (args[3] && !strcmp("-", args[3])) {
int i;
size_t i;
for (i = 0; i < LEN(hycase); i++)
hcode_add(hycase[i][1], hycase[i][0]);
}
Expand Down
2 changes: 1 addition & 1 deletion in.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void in_back(int c)
{
if (c < 0)
return;
if (buf && buf->un < sizeof(buf->unbuf))
if (buf && (size_t) buf->un < LEN(buf->unbuf))
buf->unbuf[buf->un++] = c;
}

Expand Down
6 changes: 3 additions & 3 deletions reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ void env_init(void)
int i;
init_time();
init_globals();
for (i = 0; i < LEN(eregs); i++)
for (i = 0; (size_t) i < LEN(eregs); i++)
eregs_idx[map(eregs[i])] = i + 1;
env_set(map("0"));
}

void env_done(void)
{
int i;
size_t i;
for (i = 0; i < LEN(envs); i++)
if (envs[i])
env_free(envs[i]);
Expand Down Expand Up @@ -398,7 +398,7 @@ void tr_ta(char **args)
static int tab_idx(int pos)
{
int i;
for (i = 0; i < LEN(env->tabs); i++)
for (i = 0; (size_t) i < LEN(env->tabs); i++)
if (env->tabs[i] > pos)
return i;
return -1;
Expand Down
12 changes: 11 additions & 1 deletion ren.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ int f_hpos(void)

void tr_divbeg(char **args)
{
/* not used */
(void) args;
odiv_beg();
ren_div++;
}

void tr_divend(char **args)
{
/* not used */
(void) args;
if (ren_div <= 0)
errdie("neatroff: diversion stack empty\n");
odiv_end();
Expand Down Expand Up @@ -455,16 +459,22 @@ void tr_sv(char **args)

void tr_ns(char **args)
{
/* not used */
(void) args;
n_ns = 1;
}

void tr_rs(char **args)
{
/* not used */
(void) args;
n_ns = 0;
}

void tr_os(char **args)
{
/* not used */
(void) args;
if (n_sv)
down(n_sv);
n_sv = 0;
Expand Down Expand Up @@ -941,7 +951,7 @@ void ren_tl(int (*next)(void), void (*back)(int))
static void ren_field(struct wb *wb, int (*next)(void), void (*back)(int))
{
struct wb wbs[NFIELDS];
int i, n = 0;
size_t i, n = 0;
int wid = 0;
int left, right, cur_left;
int pad, rem;
Expand Down
Loading

0 comments on commit 5b72358

Please sign in to comment.