Skip to content

Commit

Permalink
Code clean-up, to reduce cppcheck warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
compuphase committed Feb 13, 2022
1 parent f1004ed commit e36caf3
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BIN=makedepend
all: $(BIN)

clean:
rm -f $(BIN).exe *.o
rm -f $(BIN) *.o

depend:
$(BIN) $(SRCS)
Expand Down
7 changes: 4 additions & 3 deletions cppsetup.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct symtab **lookup(symbol)
pperror(tag, x0,x1,x2,x3,x4)
int tag,x0,x1,x2,x3,x4;
{
warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
warning("\"%s\", line %ld: ", currentinc->i_file, currentfile->f_line);
warning(x0,x1,x2,x3,x4);
}

Expand All @@ -135,13 +135,14 @@ static const char *
my_if_errors (IfParser *ip, const char *cp, const char *expecting)
{
struct _parse_data *pd = (struct _parse_data *) ip->data;
int lineno = pd->filep->f_line;
long lineno = pd->filep->f_line;
const char *filename = pd->filename;
char prefix[300];
int prefixlen;
int i;

snprintf (prefix, sizeof(prefix), "\"%s\":%d", filename, lineno);
snprintf (prefix, sizeof(prefix), "\"%s\":%ld", filename, lineno);
prefix[sizeof(prefix)-1] = '\0'; /* force zero-termination (snprintf() may not zero-terminate a string) */
prefixlen = strlen(prefix);
fprintf (stderr, "%s: %s", prefix, pd->line);
i = cp - pd->line;
Expand Down
1 change: 0 additions & 1 deletion include.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ included_by(struct inclist *ip, struct inclist *newfile)
register int i;
for (i=0; i<ip->i_listlen; i++)
if (ip->i_list[ i ] == newfile) {
i = strlen(newfile->i_file);
if (!(ip->i_flags & INCLUDED_SYM)) {
/* only warn if ip has no #include SYMBOL lines */
if (warn_multiple) {
Expand Down
28 changes: 17 additions & 11 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static struct sigaction sig_act;

int main (int argc, char *argv[])
{
char **fp = filelist;
char **fltail = filelist;
const char **incp = includedirs;
char *p;
struct inclist *ip;
Expand Down Expand Up @@ -250,15 +250,15 @@ int main (int argc, char *argv[])
continue;
}
if (**argv != '-') {
char **p;
char **pp;
/* treat +thing as an option for C++ */
if (endmarker && **argv == '+')
continue;
/* check for a file appearing twice on the command line */
for (p = filelist; p != fp && (strcmp (*p, argv[0]) != 0); p++)
for (pp = filelist; pp != fltail && (strcmp (*pp, argv[0]) != 0); pp++)
{}
if (p == fp) /* reached the end of the list, so this is a new file */
*fp++ = argv[0];
if (pp == fltail) /* reached the end of the list, so this is a new file */
*fltail++ = argv[0];
continue;
}
switch (argv[0][1]) {
Expand Down Expand Up @@ -298,10 +298,16 @@ int main (int argc, char *argv[])
case 'U':
/* Undef's override all -D's so save them up */
numundefs++;
if (numundefs == 1)
if (numundefs == 1) {
undeflist = (char**)malloc (sizeof (char *));
else
} else {
char **old = undeflist;
undeflist = (char**)realloc (undeflist, numundefs * sizeof (char *));
if (!undeflist) {
free (old);
memoryerr ();
}
}
i = 2;
if (argv[0][i] == '\0') {
argv++;
Expand Down Expand Up @@ -586,11 +592,11 @@ int main (int argc, char *argv[])
/*
* now peruse through the list of files.
*/
for (fp = filelist; *fp; fp++) {
filecontent = getfile (*fp);
for (fltail = filelist; *fltail; fltail++) {
filecontent = getfile (*fltail);
setfile_cmdinc (filecontent, cmdinc_count, cmdinc_list);
ip = newinclude (*fp, (char *) NULL);
setfile_vars (*fp, ip);
ip = newinclude (*fltail, (char *) NULL);
setfile_vars (*fltail, ip);
find_includes (filecontent, ip, ip, 0, TRUE);
freefile (filecontent);
if (include_cfile)
Expand Down
6 changes: 6 additions & 0 deletions makedepend.1
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ When verbose output is enabled (see
.B \-v
), the list of predefined variables is listed too.
.TP 5
.B \-i
Ignore include files that cannot be located. That is, do not warn about any
include files that cannot be found. Note that include files that are not found,
are never added as a dependency to the target. This option silences the warning
about missing files.
.TP 5
.B \-include \fIfile\fP
Process file as input, and include all the resulting output
before processing the regular input file. This has the same
Expand Down
6 changes: 6 additions & 0 deletions makedepend.man
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ OPTIONS
verbose output is enabled (see -v), the list of pre-
defined variables is listed too.

-i Ignore include files that cannot be located. That is,
do not warn about any include files that cannot be
found. Note that include files that are not found,
are never added as a dependency to the target. This
option silences the warning about missing files.

-include file
Process file as input, and include all the resulting
output before processing the regular input file. This
Expand Down
109 changes: 55 additions & 54 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ gobble(struct filepointer *filep, struct inclist *file,
struct inclist *file_red)
{
char *line;
int type;

while ((line = getnextline(filep))) {
switch(type = deftype(line, filep, file_red, file, FALSE)) {
int type = deftype(line, filep, file_red, file, FALSE);
switch(type) {
case IF:
case IFFALSE:
case IFGUESSFALSE:
Expand All @@ -67,7 +67,7 @@ gobble(struct filepointer *filep, struct inclist *file,
break;
case ELSE:
case ENDIF:
debug(0,("%s, line %d: #%s\n",
debug(0,("%s, line %ld: #%s\n",
file->i_file, filep->f_line,
directives[type]));
return(type);
Expand Down Expand Up @@ -140,7 +140,7 @@ deftype (char *line, struct filepointer *filep,
/*
* parse an expression.
*/
debug(0,("%s, line %d: #elif %s ",
debug(0,("%s, line %ld: #elif %s ",
file->i_file, filep->f_line, p));
ret = zero_value(file->i_file, p, filep, file_red);
if (ret != IF)
Expand Down Expand Up @@ -177,12 +177,12 @@ deftype (char *line, struct filepointer *filep,
* parse an expression.
*/
ret = zero_value(file->i_file, p, filep, file_red);
debug(0,("%s, line %d: %s #if %s\n",
debug(0,("%s, line %ld: %s #if %s\n",
file->i_file, filep->f_line, ret?"false":"true", p));
break;
case IFDEF:
case IFNDEF:
debug(0,("%s, line %d: #%s %s\n",
debug(0,("%s, line %ld: #%s %s\n",
file->i_file, filep->f_line, directives[ret], p));
case UNDEF:
/*
Expand All @@ -194,7 +194,7 @@ deftype (char *line, struct filepointer *filep,
break;
case INCLUDE:
case INCLUDENEXT:
debug(2,("%s, line %d: #include%s %s\n",
debug(2,("%s, line %ld: #include%s %s\n",
file->i_file, filep->f_line,
(ret == INCLUDE) ? "" : "_next", p));

Expand Down Expand Up @@ -253,7 +253,7 @@ deftype (char *line, struct filepointer *filep,
case SCCS:
case EJECT:
case WARNING:
debug(0,("%s, line %d: #%s\n",
debug(0,("%s, line %ld: #%s\n",
file->i_file, filep->f_line, directives[ret]));
/*
* nothing to do.
Expand All @@ -266,9 +266,7 @@ deftype (char *line, struct filepointer *filep,
struct symtab **
fdefined(const char *symbol, struct inclist *file, struct inclist **srcfile)
{
struct inclist **ip;
struct symtab **val;
int i;
static int recurse_lvl = 0;

if (file->i_flags & DEFCHECKED)
Expand All @@ -280,14 +278,17 @@ fdefined(const char *symbol, struct inclist *file, struct inclist **srcfile)
symbol, file->i_file, (*val)->s_value));
if (val == NULL && file->i_list)
{
struct inclist **ip;
int i;
for (ip = file->i_list, i=0; i < file->i_listlen; i++, ip++)
if (file->i_merged[i]==FALSE) {
val = fdefined(symbol, *ip, srcfile);
file->i_merged[i]=merge2defines(file,*ip);
if (val!=NULL) break;
}
}
else if (val != NULL && srcfile != NULL) *srcfile = file;
else if (val != NULL && srcfile != NULL)
*srcfile = file;
recurse_lvl--;
file->i_flags &= ~DEFCHECKED;

Expand Down Expand Up @@ -432,8 +433,6 @@ static char args[S_ARGS_BUFLEN];

char *val;
char *p_args = args;
int fix_args = 0, var_args = 0, loop = 1;
char *p_tmp;

args[0] = '\0';

Expand All @@ -444,6 +443,8 @@ static char args[S_ARGS_BUFLEN];

if (*val == '(') /* is this macro definition with parameters? */
{
int fix_args = 0, var_args = 0;
int loop = 1;
*val++ = '\0';

do /* parse the parameter list */
Expand All @@ -454,57 +455,57 @@ static char args[S_ARGS_BUFLEN];
/* extract next parameter name */
if (*val == '.')
{ /* it should be the var-args parameter: "..." */
var_args++;
p_tmp = p_args;
while (*val == '.')
{
*p_args++ = *val++;
if (p_args >= &args[S_ARGS_BUFLEN-1])
fatalerr("args buffer full failure in insert_defn()\n");
}
*p_args = '\0';
if (strcmp(p_tmp,"...")!=0)
{
fprintf(stderr, "unrecognized qualifier, should be \"...\" for-args\n");
}
char *p_tmp = p_args;
var_args++;
while (*val == '.')
{
*p_args++ = *val++;
if (p_args >= &args[S_ARGS_BUFLEN-1])
fatalerr("args buffer full failure in insert_defn()\n");
}
*p_args = '\0';
if (strcmp(p_tmp,"...")!=0)
{
fprintf(stderr, "unrecognized qualifier, should be \"...\" for-args\n");
}
}
else
{ /* regular parameter name */
fix_args++;
while (isalnum(*val) || *val == '_')
{
*p_args++ = *val++;
if (p_args >= &args[S_ARGS_BUFLEN-1])
fatalerr("args buffer full failure in insert_defn()\n");
}
fix_args++;
while (isalnum(*val) || *val == '_')
{
*p_args++ = *val++;
if (p_args >= &args[S_ARGS_BUFLEN-1])
fatalerr("args buffer full failure in insert_defn()\n");
}
}
while (*val == ' ' || *val == '\t')
val++;
val++;

if (*val == ',')
{
if (var_args)
{
fprintf(stderr, "there are more arguments after the first var-args qualifier\n");
}

*p_args++ = ','; /* we are using the , as a reserved char */
if (p_args >= &args[S_ARGS_BUFLEN-1])
fatalerr("args buffer full failure in insert_defn()\n");
val++;
if (var_args)
{
fprintf(stderr, "there are more arguments after the first var-args qualifier\n");
}

*p_args++ = ','; /* we are using the , as a reserved char */
if (p_args >= &args[S_ARGS_BUFLEN-1])
fatalerr("args buffer full failure in insert_defn()\n");
val++;
}
else
if (*val == ')')
{
*p_args = '\0';
val++;
loop=0;
*p_args = '\0';
val++;
loop=0;
}
else
if (*val != '.')
{
fprintf(stderr, "trailing ) on macro arguments missing\n");
loop=0;
fprintf(stderr, "trailing ) on macro arguments missing\n");
loop=0;
}
} while (loop);
}
Expand Down Expand Up @@ -657,7 +658,6 @@ add_include(struct filepointer *filep, struct inclist *file,
boolean failOK)
{
register struct inclist *newfile;
register struct filepointer *content;

/*
* First decide what the pathname of this include file really is.
Expand All @@ -671,15 +671,15 @@ add_include(struct filepointer *filep, struct inclist *file,
fprintf(stderr, "\n");
first_warning = FALSE;
}
fprintf(stderr, "makedepend: %s(%d): cannot locate \"%s\"\n", file->i_file, filep->f_line, include);
fprintf(stderr, "makedepend: %s(%ld): cannot locate \"%s\"\n", file->i_file, filep->f_line, include);
}
return;
}
if (file != file_red)
warning("%s (reading %s, line %d): ",
warning("%s (reading %s, line %ld): ",
file_red->i_file, file->i_file, filep->f_line);
else
warning("%s, line %d: ", file->i_file, filep->f_line);
warning("%s, line %ld: ", file->i_file, filep->f_line);
warning1("cannot find include file \"%s\"\n", include);
show_where_not = TRUE;
newfile = inc_path(file->i_file, include, type);
Expand All @@ -689,6 +689,7 @@ add_include(struct filepointer *filep, struct inclist *file,
if (newfile) {
included_by(file, newfile);
if (!(newfile->i_flags & SEARCHED)) {
register struct filepointer *content;
newfile->i_flags |= SEARCHED;
content = getfile(newfile->i_file);
find_includes(content, newfile, file_red, 0, failOK);
Expand Down Expand Up @@ -745,7 +746,7 @@ find_includes(struct filepointer *filep, struct inclist *file,

if (isdef) {
debug(1,(type == IFNDEF ?
"line %d: %s !def'd in %s via %s%s\n" : "",
"line %ld: %s !def'd in %s via %s%s\n" : "",
filep->f_line, line,
file->i_file, file_red->i_file, ": doit"));
type = find_includes(filep, file,
Expand All @@ -757,7 +758,7 @@ find_includes(struct filepointer *filep, struct inclist *file,
}
else {
debug(1,(type == IFDEF ?
"line %d: %s !def'd in %s via %s%s\n" : "",
"line %ld: %s !def'd in %s via %s%s\n" : "",
filep->f_line, line,
file->i_file, file_red->i_file, ": gobble"));
type = gobble(filep, file, file_red);
Expand Down
Loading

0 comments on commit e36caf3

Please sign in to comment.