Skip to content

Commit

Permalink
1) Const enough things to avoid warnings.
Browse files Browse the repository at this point in the history
2) Cast ifdef_level to a size_t before comparing it to a ratio of size_ts.
   Ifdef_level should always be positive.
3) Complete prototype for chfont.
4) Cast some ptrdiff_ts to ints before using as a field width.
5) Avoid shadowing a local variable p with another local variable p.
  • Loading branch information
dwmalone committed Mar 30, 2002
1 parent 02ab2c8 commit 99e7728
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
8 changes: 4 additions & 4 deletions usr.bin/indent/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static const char rcsid[] =

static void scan_profile(FILE *);

char *option_source = "?";
const char *option_source = "?";

/*
* N.B.: because of the way the table here is scanned, options whose names are
Expand All @@ -81,7 +81,7 @@ char *option_source = "?";
* default value is the one actually assigned.
*/
struct pro {
char *p_name; /* name, eg -bl, -cli */
const char *p_name; /* name, eg -bl, -cli */
int p_type; /* type (int, bool, special) */
int p_default; /* the default value (if int) */
int p_special; /* depends on type */
Expand Down Expand Up @@ -200,10 +200,10 @@ scan_profile(register FILE *f)
}
}

char *param_start;
const char *param_start;

static int
eqin(char *s1, char *s2)
eqin(const char *s1, const char *s2)
{
while (*s1) {
if (*s1++ != *s2++)
Expand Down
16 changes: 8 additions & 8 deletions usr.bin/indent/indent.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ static const char rcsid[] =

static void bakcopy(void);

char *in_name = "Standard Input"; /* will always point to name of input
const char *in_name = "Standard Input"; /* will always point to name of input
* file */
char *out_name = "Standard Output"; /* will always point to name
const char *out_name = "Standard Output"; /* will always point to name
* of output file */
char bakfile[MAXPATHLEN] = "";

Expand All @@ -89,7 +89,7 @@ main(int argc, char **argv)
int squest; /* when this is positive, we have seen a ?
* without the matching : in a <c>?<s>:<s>
* construct */
register char *t_ptr; /* used for copying tokens */
const char *t_ptr; /* used for copying tokens */
int type_code; /* the type of token, returned by lexi */

int last_else = 0; /* true iff last keyword was an else */
Expand Down Expand Up @@ -267,7 +267,7 @@ main(int argc, char **argv)
ps.ind_level = ps.i_l_follow = col / ps.ind_size;
}
if (troff) {
register char *p = in_name,
const char *p = in_name,
*beg = in_name;

while (*p)
Expand Down Expand Up @@ -574,7 +574,7 @@ main(int argc, char **argv)
e_code += strlen(e_code);
}
else {
char *res = token;
const char *res = token;

if (ps.in_decl && !ps.block_init) { /* if this is a unary op
* in a declaration, we
Expand All @@ -600,7 +600,7 @@ main(int argc, char **argv)
if (ps.want_blank)
*e_code++ = ' ';
{
char *res = token;
const char *res = token;

if (troff)
switch (token[0]) {
Expand Down Expand Up @@ -1077,7 +1077,7 @@ main(int argc, char **argv)
while ((c = getc(input)) == '\n');
ungetc(c, input);
}
if (ifdef_level < sizeof state_stack / sizeof state_stack[0]) {
if ((size_t)ifdef_level < sizeof(state_stack)/sizeof(state_stack[0])) {
match_state[ifdef_level].tos = -1;
state_stack[ifdef_level++] = ps;
}
Expand Down Expand Up @@ -1143,7 +1143,7 @@ bakcopy(void)
int n,
bakchn;
char buff[8 * 1024];
register char *p;
const char *p;

/* construct file name .Bfile */
for (p = in_name; *p; p++); /* skip to end of string */
Expand Down
8 changes: 4 additions & 4 deletions usr.bin/indent/indent.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ int compute_code_target(void);
int compute_label_target(void);
int count_spaces(int, char *);
int lexi(void);
void diag2(int, char *);
void diag3(int, char *, int);
void diag4(int, char *, int, int);
void diag2(int, const char *);
void diag3(int, const char *, int);
void diag4(int, const char *, int, int);
void dump_line(void);
void fill_buffer(void);
void parse(int);
void parsefont(struct fstate *, char *);
void parsefont(struct fstate *, const char *);
void pr_comment(void);
void set_defaults(void);
void set_option(char *);
Expand Down
2 changes: 1 addition & 1 deletion usr.bin/indent/indent_globs.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct fstate {
char size;
int allcaps:1;
};
char *chfont();
char *chfont(struct fstate *, struct fstate *, char *);

struct fstate
keywordf, /* keyword font */
Expand Down
14 changes: 7 additions & 7 deletions usr.bin/indent/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ dump_line(void)
s++;
if (s < e_lab)
fprintf(output, s[0]=='/' && s[1]=='*' ? "\t%.*s" : "\t/* %.*s */",
e_lab - s, s);
(int)(e_lab - s), s);
}
else fprintf(output, "%.*s", e_lab - s_lab, s_lab);
else fprintf(output, "%.*s", (int)(e_lab - s_lab), s_lab);
cur_col = count_spaces(cur_col, s_lab);
}
else
Expand Down Expand Up @@ -539,7 +539,7 @@ count_spaces(int current, char *buffer)
int found_err;

void
diag4(int level, char *msg, int a, int b)
diag4(int level, const char *msg, int a, int b)
{
if (level)
found_err = 1;
Expand All @@ -556,7 +556,7 @@ diag4(int level, char *msg, int a, int b)
}

void
diag3(int level, char *msg, int a)
diag3(int level, const char *msg, int a)
{
if (level)
found_err = 1;
Expand All @@ -573,7 +573,7 @@ diag3(int level, char *msg, int a)
}

void
diag2(int level, char *msg)
diag2(int level, const char *msg)
{
if (level)
found_err = 1;
Expand Down Expand Up @@ -627,9 +627,9 @@ chfont(struct fstate *of, struct fstate *nf, char *s)
}

void
parsefont(struct fstate *f, char *s0)
parsefont(struct fstate *f, const char *s0)
{
register char *s = s0;
const char *s = s0;
int sizedelta = 0;

bzero(f, sizeof *f);
Expand Down
13 changes: 7 additions & 6 deletions usr.bin/indent/lexi.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ static const char rcsid[] =
#include <string.h>
#include "indent_globs.h"
#include "indent_codes.h"
#include "indent.h"

#define alphanum 1
#define opchar 3

void fill_buffer(void);

struct templ {
char *rwd;
const char *rwd;
int rwcode;
};

Expand Down Expand Up @@ -149,7 +150,7 @@ lexi(void)
/*
* we have a character or number
*/
register char *j; /* used for searching thru list of
const char *j; /* used for searching thru list of
*
* reserved words */
register struct templ *p;
Expand Down Expand Up @@ -249,15 +250,15 @@ lexi(void)
* This loop will check if the token is a keyword.
*/
for (p = specials; (j = p->rwd) != 0; p++) {
register char *p = s_token; /* point at scanned token */
if (*j++ != *p++ || *j++ != *p++)
const char *q = s_token; /* point at scanned token */
if (*j++ != *q++ || *j++ != *q++)
continue; /* This test depends on the fact that
* identifiers are always at least 1 character
* long (ie. the first two bytes of the
* identifier are always meaningful) */
if (p[-1] == 0)
if (q[-1] == 0)
break; /* If its a one-character identifier */
while (*p++ == *j)
while (*q++ == *j)
if (*j++ == 0)
goto found_keyword; /* I wish that C had a multi-level
* break... */
Expand Down

0 comments on commit 99e7728

Please sign in to comment.