From: Hans-Bernhard B. <br...@us...> - 2014-11-20 21:12:57
|
Update of /cvsroot/cscope/cscope/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv29475/src Modified Files: Makefile.in alloc.c build.c command.c crossref.c dir.c display.c find.c global.h input.c invlib.c invlib.h lookup.c main.c mypopen.c scanner.l vpinit.c Log Message: Update autotoolage, various code cleanups Index: Makefile.in =================================================================== RCS file: /cvsroot/cscope/cscope/src/Makefile.in,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -r1.19 -r1.20 *** Makefile.in 26 Jun 2013 20:58:48 -0000 1.19 --- Makefile.in 20 Nov 2014 21:12:54 -0000 1.20 *************** *** 1,8 **** ! # Makefile.in generated by automake 1.11.6 from Makefile.am. # @configure_input@ ! # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, ! # 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software ! # Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, --- 1,7 ---- ! # Makefile.in generated by automake 1.14.1 from Makefile.am. [...1191 lines suppressed...] --- 1120,1136 ---- .MAKE: install-am install-strip ! .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \ ! clean-binPROGRAMS clean-generic cscopelist-am ctags ctags-am \ ! distclean distclean-compile distclean-generic distclean-tags \ ! distdir dvi dvi-am html html-am info info-am install \ ! install-am install-binPROGRAMS install-data install-data-am \ ! install-dvi install-dvi-am install-exec install-exec-am \ ! install-html install-html-am install-info install-info-am \ ! install-man install-pdf install-pdf-am install-ps \ ! install-ps-am install-strip installcheck installcheck-am \ ! installdirs maintainer-clean maintainer-clean-generic \ ! mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \ ! ps ps-am tags tags-am uninstall uninstall-am \ ! uninstall-binPROGRAMS Index: alloc.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/alloc.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** alloc.c 23 Jul 2006 20:59:20 -0000 1.8 --- alloc.c 20 Nov 2014 21:12:54 -0000 1.9 *************** *** 64,68 **** mymalloc(size_t size) { ! return(alloctest(malloc((unsigned) size))); } --- 64,68 ---- mymalloc(size_t size) { ! return(alloctest(malloc(size))); } *************** *** 72,76 **** mycalloc(size_t nelem, size_t size) { ! return(alloctest(calloc((unsigned) nelem, (unsigned) size))); } --- 72,76 ---- mycalloc(size_t nelem, size_t size) { ! return(alloctest(calloc(nelem, size))); } *************** *** 80,84 **** myrealloc(void *p, size_t size) { ! return(alloctest(realloc(p, (unsigned) size))); } --- 80,84 ---- myrealloc(void *p, size_t size) { ! return(alloctest(realloc(p, size))); } Index: build.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/build.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -r1.16 -r1.17 *** build.c 12 Jun 2011 13:25:56 -0000 1.16 --- build.c 20 Nov 2014 21:12:54 -0000 1.17 *************** *** 141,145 **** char *s; /* pointer to basename in path */ ! path = mymalloc(strlen(reffile) + 10); strcpy(path, reffile); s = mybasename(path); --- 141,145 ---- char *s; /* pointer to basename in path */ ! path = mymalloc(strlen(reffile) + 10u); strcpy(path, reffile); s = mybasename(path); *************** *** 227,231 **** } /* sort the source file names (needed for rebuilding) */ ! qsort(srcfiles, nsrcfiles, sizeof(char *), compare); /* if there is an old cross-reference and its current directory matches */ --- 227,231 ---- } /* sort the source file names (needed for rebuilding) */ ! qsort(srcfiles, nsrcfiles, sizeof(*srcfiles), compare); /* if there is an old cross-reference and its current directory matches */ *************** *** 368,372 **** lastfile = nsrcfiles; if (invertedindex == YES) { ! srcoffset = mymalloc((nsrcfiles + 1) * sizeof(long)); } for (;;) { --- 368,372 ---- lastfile = nsrcfiles; if (invertedindex == YES) { ! srcoffset = mymalloc((nsrcfiles + 1u) * sizeof(*srcoffset)); } for (;;) { *************** *** 423,432 **** lastfile = nsrcfiles; if (invertedindex == YES) { ! srcoffset = myrealloc(srcoffset, ! (nsrcfiles + 1) * sizeof(long)); } /* sort the included file names */ ! qsort(&srcfiles[firstfile], (lastfile - firstfile), ! sizeof(char *), compare); } /* add a null file name to the trailing tab */ --- 423,430 ---- lastfile = nsrcfiles; if (invertedindex == YES) { ! srcoffset = myrealloc(srcoffset, (nsrcfiles + 1) * sizeof(*srcoffset)); } /* sort the included file names */ ! qsort(srcfiles + firstfile, lastfile - firstfile, sizeof(*srcfiles), compare); } /* add a null file name to the trailing tab */ *************** *** 604,608 **** copydata(void) { - char symbol[PATLEN + 1]; char *cp; --- 602,605 ---- *************** *** 630,633 **** --- 627,631 ---- /* look for an #included file */ if (*cp == INCLUDE) { + char symbol[PATLEN + 1]; blockp = cp; fetch_include_from_dbase(symbol, sizeof(symbol)); Index: command.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/command.c,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -r1.36 -r1.37 *** command.c 20 May 2012 13:58:53 -0000 1.36 --- command.c 20 Nov 2014 21:12:54 -0000 1.37 *************** *** 315,321 **** } if (c != '\r' && ! mygetline("", newpat, ! COLS - sizeof(appendprompt), c, NO) > 0 ! ) { shellpath(filename, sizeof(filename), newpat); if ((file = myfopen(filename, s)) == NULL) { --- 315,319 ---- } if (c != '\r' && ! mygetline("", newpat, COLS - sizeof(appendprompt), c, NO) > 0) { shellpath(filename, sizeof(filename), newpat); if ((file = myfopen(filename, s)) == NULL) { *************** *** 337,342 **** move(PRLINE, 0); addstr(readprompt); ! if (mygetline("", newpat, COLS - sizeof(readprompt), ! '\0', NO) > 0) { clearprompt(); shellpath(filename, sizeof(filename), newpat); --- 335,339 ---- move(PRLINE, 0); addstr(readprompt); ! if (mygetline("", newpat, COLS - sizeof(readprompt), '\0', NO) > 0) { clearprompt(); shellpath(filename, sizeof(filename), newpat); *************** *** 359,364 **** move(PRLINE, 0); addstr(pipeprompt); ! if (mygetline("", newpat, COLS - sizeof(pipeprompt), '\0', NO) ! == 0) { clearprompt(); return(NO); --- 356,360 ---- move(PRLINE, 0); addstr(pipeprompt); ! if (mygetline("", newpat, COLS - sizeof(pipeprompt), '\0', NO) == 0) { clearprompt(); return(NO); *************** *** 624,628 **** } /* create the line change indicators */ ! change = mycalloc(totallines, sizeof(BOOL)); changing = YES; mousemenu(); --- 620,624 ---- } /* create the line change indicators */ ! change = mycalloc(totallines, sizeof(*change)); changing = YES; mousemenu(); Index: crossref.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/crossref.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** crossref.c 28 Aug 2009 14:28:27 -0000 1.15 --- crossref.c 20 Nov 2014 21:12:54 -0000 1.16 *************** *** 49,64 **** ! /* convert long to a string */ ! #define ltobase(value) n = value; \ ! s = buf + (sizeof(buf) - 1); \ ! *s = '\0'; \ ! digits = 1; \ ! while (n >= BASE) { \ ! ++digits; \ ! i = n; \ ! n /= BASE; \ ! *--s = i - n * BASE + '!'; \ ! } \ ! *--s = n + '!'; #define SYMBOLINC 20 /* symbol list size increment */ --- 49,67 ---- ! /* convert long to a string in base BASE notation */ ! #define ltobase(value) \ ! do { \ ! n = (value); \ ! s = buf + (sizeof(buf) - 1); \ ! *s = '\0'; \ ! digits = 1; \ ! while (n >= BASE) { \ ! ++digits; \ ! i = n; \ ! n /= BASE; \ ! *--s = i - n * BASE + '!'; \ ! } \ ! *--s = n + '!'; \ ! } while (0) #define SYMBOLINC 20 /* symbol list size increment */ *************** *** 122,126 **** symbols = 0; if (symbol == NULL) { ! symbol = mymalloc(msymbols * sizeof(struct symbol)); } for (;;) { --- 125,129 ---- symbols = 0; if (symbol == NULL) { ! symbol = mymalloc(msymbols * sizeof(*symbol)); } for (;;) { *************** *** 201,205 **** if (symbols == msymbols) { msymbols += SYMBOLINC; ! symbol = myrealloc(symbol, msymbols * sizeof(struct symbol)); } /* save the symbol */ --- 204,208 ---- if (symbols == msymbols) { msymbols += SYMBOLINC; ! symbol = myrealloc(symbol, msymbols * sizeof(*symbol)); } /* save the symbol */ Index: dir.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/dir.c,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -r1.32 -r1.33 *** dir.c 4 Mar 2010 21:11:43 -0000 1.32 --- dir.c 20 Nov 2014 21:12:54 -0000 1.33 *************** *** 45,48 **** --- 45,49 ---- #include <dirent.h> #include <sys/stat.h> /* stat */ + #include <assert.h> static char const rcsid[] = "$Id$"; *************** *** 107,111 **** /* create the source directory list */ msrcdirs = nsrcdirs + DIRINC; ! srcdirs = mymalloc(msrcdirs * sizeof(char *)); *srcdirs = "."; /* first source dir is always current dir */ for (i = 1; i < vpndirs; ++i) { --- 108,112 ---- /* create the source directory list */ msrcdirs = nsrcdirs + DIRINC; ! srcdirs = mymalloc(msrcdirs * sizeof(*srcdirs)); *srcdirs = "."; /* first source dir is always current dir */ for (i = 1; i < vpndirs; ++i) { *************** *** 166,170 **** if (nsrcdirs == msrcdirs) { msrcdirs += DIRINC; ! srcdirs = myrealloc(srcdirs, msrcdirs * sizeof(char *)); } srcdirs[nsrcdirs++] = my_strdup(dir); --- 167,171 ---- if (nsrcdirs == msrcdirs) { msrcdirs += DIRINC; ! srcdirs = myrealloc(srcdirs, msrcdirs * sizeof(*srcdirs)); } srcdirs[nsrcdirs++] = my_strdup(dir); *************** *** 231,242 **** S_ISDIR(statstruct.st_mode)) { if (incdirs == NULL) { ! incdirs = mymalloc(mincdirs * sizeof(char *)); ! incnames = mymalloc(mincdirs * sizeof(char *)); } else if (nincdirs == mincdirs) { mincdirs += DIRINC; ! incdirs = myrealloc(incdirs, ! mincdirs * sizeof(char *)); ! incnames = myrealloc(incnames, ! mincdirs * sizeof(char *)); } incdirs[nincdirs] = my_strdup(path); --- 232,241 ---- S_ISDIR(statstruct.st_mode)) { if (incdirs == NULL) { ! incdirs = mymalloc(mincdirs * sizeof(*incdirs)); ! incnames = mymalloc(mincdirs * sizeof(*incnames)); } else if (nincdirs == mincdirs) { mincdirs += DIRINC; ! incdirs = myrealloc(incdirs, mincdirs * sizeof(*incdirs)); ! incnames = myrealloc(incnames, mincdirs * sizeof(*incnames)); } incdirs[nincdirs] = my_strdup(path); *************** *** 489,493 **** struct dirent *entry; char path[PATHLEN + 1]; - char *file; while ((entry = readdir(dirfile)) != NULL) { --- 488,491 ---- *************** *** 501,505 **** if (lstat(path,&buf) == 0) { - file = entry->d_name; if (recurse_dir && S_ISDIR(buf.st_mode) ) { --- 499,502 ---- *************** *** 595,598 **** --- 592,596 ---- unsigned int i; + assert(file != NULL); /* should never happen, but let's make sure anyway */ /* see if the file is already in the source file list */ if (infilelist(file) == YES) { *************** *** 701,709 **** if (nsrcfiles == msrcfiles) { msrcfiles += SRCINC; ! srcfiles = myrealloc(srcfiles, msrcfiles * sizeof(char *)); } /* add the file to the list */ srcfiles[nsrcfiles++] = my_strdup(compath(path)); ! p = mymalloc(sizeof(struct listitem)); p->text = my_strdup(compath(path)); i = hash(p->text) % HASHMOD; --- 699,707 ---- if (nsrcfiles == msrcfiles) { msrcfiles += SRCINC; ! srcfiles = myrealloc(srcfiles, msrcfiles * sizeof(*srcfiles)); } /* add the file to the list */ srcfiles[nsrcfiles++] = my_strdup(compath(path)); ! p = mymalloc(sizeof(*p)); p->text = my_strdup(compath(path)); i = hash(p->text) % HASHMOD; Index: display.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/display.c,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -r1.33 -r1.34 *** display.c 20 May 2012 12:24:17 -0000 1.33 --- display.c 20 Nov 2014 21:12:54 -0000 1.34 *************** *** 118,122 **** /* Internal prototypes: */ ! static RETSIGTYPE jumpback(int sig); /* initialize display parameters */ --- 118,122 ---- /* Internal prototypes: */ ! static void jumpback(int sig); /* initialize display parameters */ *************** *** 139,143 **** /* allocate the displayed line array */ ! displine = mymalloc(mdisprefs * sizeof(int)); } --- 139,143 ---- /* allocate the displayed line array */ ! displine = mymalloc(mdisprefs * sizeof(*displine)); } *************** *** 399,403 **** /*ARGSUSED*/ ! static RETSIGTYPE jumpback(int sig) { --- 399,403 ---- /*ARGSUSED*/ ! static void jumpback(int sig) { *************** *** 565,572 **** char *s; - s = "Unknown error"; #ifdef HAVE_STRERROR s = strerror(errno); #else if (errno < sys_nerr) { s = sys_errlist[errno]; --- 565,573 ---- char *s; #ifdef HAVE_STRERROR s = strerror(errno); #else + s = "Unknown error"; + if (errno < sys_nerr) { s = sys_errlist[errno]; Index: find.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/find.c,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -r1.26 -r1.27 *** find.c 15 Apr 2014 16:12:15 -0000 1.26 --- find.c 20 Nov 2014 21:12:54 -0000 1.27 *************** *** 876,880 **** /* read the previous block */ (void) dbseek((blocknumber - 1) * BUFSIZ); ! cp = &block[BUFSIZ - 1]; } } --- 876,880 ---- /* read the previous block */ (void) dbseek((blocknumber - 1) * BUFSIZ); ! cp = block + (BUFSIZ - 1); } } *************** *** 1210,1215 **** if (dbseek(p->lineoffset) != -1) { scanpast(FCNDEF); ! fetch_string_from_dbase(function, ! sizeof(function)); } } --- 1210,1214 ---- if (dbseek(p->lineoffset) != -1) { scanpast(FCNDEF); ! fetch_string_from_dbase(function, sizeof(function)); } } Index: global.h =================================================================== RCS file: /cvsroot/cscope/cscope/src/global.h,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -r1.38 -r1.39 *** global.h 5 Mar 2012 19:28:13 -0000 1.38 --- global.h 20 Nov 2014 21:12:54 -0000 1.39 *************** *** 82,96 **** #include "library.h" /* library function return values */ - /* Fallback, in case 'configure' failed to do its part of the job */ - #ifndef RETSIGTYPE - #if SVR2 || BSD && !sun - #define RETSIGTYPE int - #else - #define RETSIGTYPE void - #endif - #endif /* RETSIGTYPE */ - #ifndef HAVE_SIGHANDLER_T ! typedef RETSIGTYPE (*sighandler_t)(int); #endif --- 82,87 ---- #include "library.h" /* library function return values */ #ifndef HAVE_SIGHANDLER_T ! typedef void (*sighandler_t)(int); #endif Index: input.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/input.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** input.c 20 Aug 2006 15:00:34 -0000 1.15 --- input.c 20 Nov 2014 21:12:54 -0000 1.16 *************** *** 55,64 **** /* Internal prototypes: */ ! static RETSIGTYPE catchint(int sig); /* catch the interrupt signal */ /*ARGSUSED*/ ! static RETSIGTYPE catchint(int sig) { --- 55,64 ---- /* Internal prototypes: */ ! static void catchint(int sig); /* catch the interrupt signal */ /*ARGSUSED*/ ! static void catchint(int sig) { *************** *** 80,84 **** mygetch(void) { ! sighandler_t savesig; /* old value of signal */ int c; --- 80,84 ---- mygetch(void) { ! sighandler_t savesig = 0; /* old value of signal */ int c; *************** *** 126,130 **** * onto the end of 's' */ ! sright = calloc(sizeof(char), size ); strcpy ( s, p); --- 126,130 ---- * onto the end of 's' */ ! sright = calloc(size, sizeof(*sright)); strcpy ( s, p); Index: invlib.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/invlib.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -r1.21 -r1.22 *** invlib.c 10 Jul 2012 20:01:40 -0000 1.21 --- invlib.c 20 Nov 2014 21:12:54 -0000 1.22 *************** *** 78,86 **** static POSTING *item, *enditem, *item1 = NULL, *item2 = NULL; ! static unsigned setsize1, setsize2; static long numitems, totterm, zerolong; static char *indexfile, *postingfile; static FILE *outfile, *fpost; ! static unsigned supersize = SUPERINC, supintsize; static unsigned int numpost, numlogblk, amtused, nextpost; static unsigned int lastinblk, numinvitems; --- 78,86 ---- static POSTING *item, *enditem, *item1 = NULL, *item2 = NULL; ! static unsigned int setsize1, setsize2; static long numitems, totterm, zerolong; static char *indexfile, *postingfile; static FILE *outfile, *fpost; ! static size_t supersize = SUPERINC, supintsize; static unsigned int numpost, numlogblk, amtused, nextpost; static unsigned int lastinblk, numinvitems; *************** *** 110,114 **** int i; long fileindex = 0; /* initialze, to avoid warning */ ! unsigned postsize = POSTINC * sizeof(POSTING); unsigned long *intptr; char line[TERMMAX]; --- 110,114 ---- int i; long fileindex = 0; /* initialze, to avoid warning */ ! unsigned postsize = POSTINC * sizeof(*POST); unsigned long *intptr; char line[TERMMAX]; *************** *** 149,156 **** supfing = SUPFING; /* FIXME HBB: magic number alert (40) */ ! supintsize = supersize / 40; /* also for the superfinger index */ ! if ((SUPINT = malloc(supintsize * sizeof(long))) == NULL) { ! invcannotalloc(supintsize * sizeof(long)); return(0); } --- 149,156 ---- supfing = SUPFING; /* FIXME HBB: magic number alert (40) */ ! supintsize = supersize / 40u; /* also for the superfinger index */ ! if ((SUPINT = malloc(supintsize * sizeof(*SUPINT))) == NULL) { ! invcannotalloc(supintsize * sizeof(*SUPINT)); return(0); } *************** *** 198,204 **** #endif if (strcmp(thisterm, line) == 0) { ! if (postptr + 10 > POST + postsize / sizeof(POSTING)) { i = postptr - POST; ! postsize += POSTINC * sizeof(POSTING); if ((POST = realloc(POST, postsize)) == NULL) { invcannotalloc(postsize); --- 198,204 ---- #endif if (strcmp(thisterm, line) == 0) { ! if ((postptr + 10) > (POST + (postsize / sizeof(*POST)))) { i = postptr - POST; ! postsize += POSTINC * sizeof(*POST); if ((POST = realloc(POST, postsize)) == NULL) { invcannotalloc(postsize); *************** *** 380,387 **** if (numinvitems && numwilluse + amtused > sizeof(t_logicalblk)) { /* set up new block */ ! if (supfing + 500 > SUPFING + supersize) { i = supfing - SUPFING; ! supersize += 20000; ! if ((SUPFING = (char *)realloc(SUPFING, supersize)) == NULL) { invcannotalloc(supersize); return(0); --- 380,387 ---- if (numinvitems && numwilluse + amtused > sizeof(t_logicalblk)) { /* set up new block */ ! if (supfing + 500u > SUPFING + supersize) { i = supfing - SUPFING; ! supersize += 20000u; ! if ((SUPFING = realloc(SUPFING, supersize)) == NULL) { invcannotalloc(supersize); return(0); *************** *** 398,409 **** i = supint - SUPINT; supintsize += SUPERINC; ! if ((SUPINT = realloc(SUPINT, supintsize * sizeof(long))) == NULL) { ! invcannotalloc(supintsize * sizeof(long)); return(0); } supint = i + SUPINT; #if DEBUG ! printf("reallocated superfinger offset to %d, totpost = %ld\n", ! supintsize * sizeof(long), totpost); #endif } --- 398,408 ---- i = supint - SUPINT; supintsize += SUPERINC; ! if ((SUPINT = realloc(SUPINT, supintsize * sizeof(*SUPINT))) == NULL) { ! invcannotalloc(supintsize * sizeof(*SUPINT)); return(0); } supint = i + SUPINT; #if DEBUG ! printf("reallocated superfinger offset to %d, totpost = %ld\n", supintsize * sizeof(*SUPINT), totpost); #endif } *************** *** 500,508 **** logicalblk.invblk[(lastinblk/sizeof(long))+wdlen] = nextpost; if ((i = postptr - POST) > 0) { ! if (fwrite(POST, sizeof(POSTING), i, fpost) == 0) { invcannotwrite(postingfile); return(0); } ! nextpost += i * sizeof(POSTING); } logicalblk.invblk[3+2*numinvitems++] = iteminfo.packword[0]; --- 499,507 ---- logicalblk.invblk[(lastinblk/sizeof(long))+wdlen] = nextpost; if ((i = postptr - POST) > 0) { ! if (fwrite(POST, sizeof(*POST), i, fpost) == 0) { invcannotwrite(postingfile); return(0); } ! nextpost += i * sizeof(*POST); } logicalblk.invblk[3+2*numinvitems++] = iteminfo.packword[0]; *************** *** 534,537 **** --- 533,576 ---- } + /* small helper function to centralize handling of binary opening + * for reading, and use of the 'stat" flag */ + static FILE * + open_for_reading(char *name, int stat) + { + return vpfopen(name, ((stat == 0) ? "rb" : "r+b")); + } + + /* handle opening of a file under a possibly "flipped" name */ + /* If db created without '-f', but now invoked with '-f cscope.out', + * we need to check for 'cscope.in.out', rather than 'cscope.out.in': + * I.e, hack around our own violation of the inverse db naming convention */ + /* more silliness: if you create the db with '-f cscope', then try to open + * it without '-f cscope', you'll fail unless we check for 'cscope.out.in' + * here. */ + static FILE * + open_file_with_flipped_name(char *name, const char *flip_in, const char *flip_out, int stat) + { + if (! invflipname(name, flip_in, flip_out)) { + FILE *fptr = open_for_reading(name, stat); + if (! fptr) + /* flip back for error message */ + invflipname(name, flip_out, flip_in); + return fptr; + }; + return 0; + } + + static FILE * + open_file_with_possibly_flipped_name(char *name, const char *flip1, const char *flip2, int stat) + { + FILE *fptr = open_for_reading(name, stat); + + if (! fptr) + fptr = open_file_with_flipped_name(name, flip2, flip1, stat); + if (! fptr) + fptr = open_file_with_flipped_name(name, flip1, flip2, stat); + return fptr; + } + int invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat) *************** *** 539,570 **** int read_index; ! if ((invcntl->invfile = vpfopen(invname, ((stat == 0) ? "rb" : "r+b"))) == NULL) { ! /* If db created without '-f', but now invoked with '-f cscope.out', ! * we need to check for 'cscope.in.out', rather than 'cscope.out.in': ! * I.e, hack around our own violation of the inverse db naming convention */ ! if (!invflipname(invname, INVNAME2, INVNAME)) { ! if ((invcntl->invfile = vpfopen(invname, ((stat == 0) ? "rb" : "r+b")))) ! goto openedinvname; ! invflipname(invname, INVNAME, INVNAME2); /* change back for err msg */ ! } ! /* more silliness: if you create the db with '-f cscope', then try to open ! * it without '-f cscope', you'll fail unless we check for 'cscope.out.in' ! * here. */ ! else if (!invflipname(invname, INVNAME, INVNAME2)) { ! if ((invcntl->invfile = vpfopen(invname, ((stat == 0) ? "rb" : "r+b")))) ! goto openedinvname; ! invflipname(invname, INVNAME2, INVNAME); /* change back for err msg */ ! } invcannotopen(invname); return(-1); } - openedinvname: if (fread(&invcntl->param, sizeof(invcntl->param), 1, invcntl->invfile) == 0) { fprintf(stderr, "%s: empty inverted file\n", argv0); ! goto closeinv; } if (invcntl->param.version != FMTVERSION) { fprintf(stderr, "%s: cannot read old index format; use -U option to force database to rebuild\n", argv0); ! goto closeinv; } assert(invcntl->param.sizeblk == sizeof(t_logicalblk)); --- 578,595 ---- int read_index; ! invcntl->invfile = open_file_with_possibly_flipped_name(invname, INVNAME, INVNAME2, stat); ! if (! invcntl->invfile) { invcannotopen(invname); return(-1); } if (fread(&invcntl->param, sizeof(invcntl->param), 1, invcntl->invfile) == 0) { fprintf(stderr, "%s: empty inverted file\n", argv0); ! fclose(invcntl->invfile); ! return(-1); } if (invcntl->param.version != FMTVERSION) { fprintf(stderr, "%s: cannot read old index format; use -U option to force database to rebuild\n", argv0); ! fclose(invcntl->invfile); ! return(-1); } assert(invcntl->param.sizeblk == sizeof(t_logicalblk)); *************** *** 572,596 **** if (stat == 0 && invcntl->param.filestat == INVALONE) { fprintf(stderr, "%s: inverted file is locked\n", argv0); ! goto closeinv; } ! if ((invcntl->postfile = vpfopen(invpost, ((stat == 0) ? "rb" : "r+b"))) == NULL) { ! /* exact same naming convention hacks as above for invname */ ! if (!invflipname(invpost, INVPOST2, INVPOST)) { ! if ((invcntl->postfile = vpfopen(invpost, ((stat == 0) ? "rb" : "r+b")))) ! goto openedinvpost; ! invflipname(invpost, INVPOST, INVPOST2); /* change back for err msg */ ! } else if (!invflipname(invpost, INVPOST, INVPOST2)) { ! if ((invcntl->postfile = vpfopen(invpost,((stat == 0)?"rb":"r+b")))) ! goto openedinvpost; ! invflipname(invpost, INVPOST2, INVPOST); /* change back for err msg */ ! } invcannotopen(invpost); ! goto closeinv; } ! openedinvpost: /* allocate core for a logical block */ ! if ((invcntl->logblk = malloc((unsigned) invcntl->param.sizeblk)) == NULL) { ! invcannotalloc((unsigned) invcntl->param.sizeblk); ! goto closeboth; } /* allocate for and read in superfinger */ --- 597,617 ---- if (stat == 0 && invcntl->param.filestat == INVALONE) { fprintf(stderr, "%s: inverted file is locked\n", argv0); ! fclose(invcntl->invfile); ! return(-1); } ! ! invcntl->postfile = open_file_with_possibly_flipped_name(invpost, INVPOST, INVPOST2, stat); ! if (! invcntl->postfile) { invcannotopen(invpost); ! fclose(invcntl->invfile); ! return(-1); } ! /* allocate core for a logical block */ ! if ((invcntl->logblk = malloc((size_t) invcntl->param.sizeblk)) == NULL) { ! invcannotalloc((size_t) invcntl->param.sizeblk); ! fclose(invcntl->postfile); ! fclose(invcntl->invfile); ! return(-1); } /* allocate for and read in superfinger */ *************** *** 626,636 **** #endif if (invcntl->iindex == NULL) ! /* FIXME HBB: magic number alert (4) */ ! invcntl->iindex = malloc((unsigned) invcntl->param.supsize ! + 4 *sizeof(long)); if (invcntl->iindex == NULL) { ! invcannotalloc((unsigned) invcntl->param.supsize); free(invcntl->logblk); ! goto closeboth; } if (read_index) { --- 647,658 ---- #endif if (invcntl->iindex == NULL) ! /* FIXME HBB: magic number alert (4, sizeof(long)) */ ! invcntl->iindex = malloc((size_t) invcntl->param.supsize + 4 *sizeof(long)); if (invcntl->iindex == NULL) { ! invcannotalloc((size_t) invcntl->param.supsize); free(invcntl->logblk); ! fclose(invcntl->postfile); ! fclose(invcntl->invfile); ! return(-1); } if (read_index) { *************** *** 641,647 **** invcntl->numblk = -1; if (boolready() == -1) { - closeboth: fclose(invcntl->postfile); - closeinv: fclose(invcntl->invfile); return(-1); --- 663,667 ---- *************** *** 880,884 **** free(item1); setsize1 = SETINC; ! if ((item1 = malloc(SETINC * sizeof(POSTING))) == NULL) { invcannotalloc(SETINC); return(-1); --- 900,904 ---- free(item1); setsize1 = SETINC; ! if ((item1 = malloc(SETINC * sizeof(*item1))) == NULL) { invcannotalloc(SETINC); return(-1); *************** *** 887,891 **** free(item2); setsize2 = SETINC; ! if ((item2 = malloc(SETINC * sizeof(POSTING))) == NULL) { invcannotalloc(SETINC); return(-1); --- 907,911 ---- free(item2); setsize2 = SETINC; ! if ((item2 = malloc(SETINC * sizeof(*item2))) == NULL) { invcannotalloc(SETINC); return(-1); *************** *** 946,952 **** if (u > setsize1) { u += SETINC; ! if ((item1 = realloc( ! item1, u * sizeof(POSTING))) == NULL) { ! goto cannotalloc; } setsize1 = u; --- 966,974 ---- if (u > setsize1) { u += SETINC; ! if ((item1 = realloc(item1, u * sizeof(*item1))) == NULL) { ! invcannotalloc(u * sizeof(*item1)); ! boolready(); ! *num = -1; ! return(NULL); } setsize1 = u; *************** *** 957,964 **** if (u > setsize2) { u += SETINC; ! if ((item2 = realloc( ! item2, u * sizeof(POSTING))) == NULL) { ! cannotalloc: ! invcannotalloc(u * sizeof(POSTING)); boolready(); *num = -1; --- 979,984 ---- if (u > setsize2) { u += SETINC; ! if ((item2 = realloc(item2, u * sizeof(*item2))) == NULL) { ! invcannotalloc(u * sizeof(*item2)); boolready(); *num = -1; *************** *** 1153,1158 **** return(ptr); } ! i = (enditem - item) * sizeof(POSTING) + 100; ! if ((ptr = malloc(i))r == NULL) { invcannotalloc(i); return(ptr); --- 1173,1178 ---- return(ptr); } ! i = (enditem - item) * sizeof(*ptr) + 100; ! if ((ptr = malloc(i)) == NULL) { invcannotalloc(i); return(ptr); Index: invlib.h =================================================================== RCS file: /cvsroot/cscope/cscope/src/invlib.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** invlib.h 12 Feb 2004 18:14:05 -0000 1.7 --- invlib.h 20 Nov 2014 21:12:54 -0000 1.8 *************** *** 38,47 **** #include <stdio.h> /* need definition of FILE* */ ! #include <limits.h> /* inverted index definitions */ /* postings temporary file long number coding into characters */ - /* FIXME HBB: where would these definitions come from ? */ #if CHAR_MAX==255 # define BASE 223 /* 255 - ' ' */ --- 38,46 ---- #include <stdio.h> /* need definition of FILE* */ ! #include <limits.h> /* need definition of CHAR_MAX */ /* inverted index definitions */ /* postings temporary file long number coding into characters */ #if CHAR_MAX==255 # define BASE 223 /* 255 - ' ' */ Index: lookup.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/lookup.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** lookup.c 21 Apr 2006 10:45:48 -0000 1.4 --- lookup.c 20 Nov 2014 21:12:54 -0000 1.5 *************** *** 96,100 **** {"volatile", ' ', NULL}, }; ! #define KEYWORDS (sizeof(keyword) / sizeof(struct keystruct)) #define HASHMOD (KEYWORDS * 2 + 1) --- 96,100 ---- {"volatile", ' ', NULL}, }; ! #define KEYWORDS (sizeof(keyword) / sizeof(keyword[0])) #define HASHMOD (KEYWORDS * 2 + 1) Index: main.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/main.c,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -r1.56 -r1.57 *** main.c 20 Nov 2012 15:20:26 -0000 1.56 --- main.c 20 Nov 2014 21:12:54 -0000 1.57 *************** *** 117,120 **** --- 117,121 ---- /* Internal prototypes: */ + static void error_usage(void); static void initcompress(void); static void longusage(void); *************** *** 281,285 **** */ *argc = *argc - optind; ! return &argv[optind]; } #endif --- 282,286 ---- */ *argc = *argc - optind; ! return argv + optind; } #endif *************** *** 418,422 **** fprintf(stderr, "%s: -%c option: missing or empty value\n", argv0, c); ! goto usage; } switch (c) { --- 419,423 ---- fprintf(stderr, "%s: -%c option: missing or empty value\n", argv0, c); ! error_usage(); } switch (c) { *************** *** 456,460 **** %s: -p option: missing or invalid numeric value\n", argv0); ! goto usage; } dispcomponents = atoi(s); --- 457,461 ---- %s: -p option: missing or invalid numeric value\n", argv0); ! error_usage(); } dispcomponents = atoi(s); *************** *** 472,479 **** fprintf(stderr, "%s: unknown option: -%c\n", argv0, *s); ! usage: ! usage(); ! fprintf(stderr, "Try the -h option for more information.\n"); ! myexit(1); } /* switch(option letter) */ } /* for(option) */ --- 473,477 ---- fprintf(stderr, "%s: unknown option: -%c\n", argv0, *s); ! error_usage(); } /* switch(option letter) */ } /* for(option) */ *************** *** 645,649 **** } /* get the source file list */ ! srcfiles = mymalloc(nsrcfiles * sizeof(char *)); if (fileversion >= 9) { --- 643,647 ---- } /* get the source file list */ ! srcfiles = mymalloc(nsrcfiles * sizeof(*srcfiles)); if (fileversion >= 9) { *************** *** 717,721 **** } /* make the source file list */ ! srcfiles = mymalloc(msrcfiles * sizeof(char *)); makefilelist(); if (nsrcfiles == 0) { --- 715,719 ---- } /* make the source file list */ ! srcfiles = mymalloc(msrcfiles * sizeof(*srcfiles)); makefilelist(); if (nsrcfiles == 0) { *************** *** 991,994 **** --- 989,1000 ---- } + /* error exit including short usage information */ + static void + error_usage(void) + { + usage(); + fprintf(stderr, "Try the -h option for more information.\n"); + myexit(1); + } /* normal usage message */ Index: mypopen.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/mypopen.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -r1.14 -r1.15 *** mypopen.c 21 Apr 2006 10:40:29 -0000 1.14 --- mypopen.c 20 Nov 2014 21:12:54 -0000 1.15 *************** *** 36,40 **** #include <sys/types.h> #include <sys/wait.h> ! #include "global.h" /* pid_t, RETSIGTYPE, shell, and mybasename() */ #define tst(a,b) (*mode == 'r'? (b) : (a)) --- 36,40 ---- #include <sys/types.h> #include <sys/wait.h> ! #include "global.h" /* pid_t, shell, and mybasename() */ #define tst(a,b) (*mode == 'r'? (b) : (a)) *************** *** 56,60 **** static pid_t popen_pid[20]; ! static RETSIGTYPE (*tstat)(int); int --- 56,60 ---- static pid_t popen_pid[20]; ! static void (*tstat)(int); int *************** *** 178,186 **** mypclose(FILE *ptr) { - int f; - pid_t r; - int status; - sighandler_t hstat, istat, qstat; - #ifdef __DJGPP__ /* HBB 20010705: This system has its own pclose(), which we --- 178,181 ---- *************** *** 188,191 **** --- 183,191 ---- return (pclose)(ptr); #else + int f; + pid_t r; + int status = -1; + sighandler_t hstat, istat, qstat; + f = fileno(ptr); (void) fclose(ptr); *************** *** 194,198 **** hstat = signal(SIGHUP, SIG_IGN); while((r = wait(&status)) != popen_pid[f] && r != -1) ! ; if(r == -1) status = -1; --- 194,198 ---- hstat = signal(SIGHUP, SIG_IGN); while((r = wait(&status)) != popen_pid[f] && r != -1) ! ; /* nothing */ if(r == -1) status = -1; Index: scanner.l =================================================================== RCS file: /cvsroot/cscope/cscope/src/scanner.l,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** scanner.l 29 Jun 2011 15:48:00 -0000 1.10 --- scanner.l 20 Nov 2014 21:12:54 -0000 1.11 *************** *** 62,70 **** static BOOL fcndef; /* function definition */ static BOOL global; /* file global scope (outside functions) */ ! static int iflevel; /* #if nesting level */ static BOOL initializer; /* data initializer */ static int initializerbraces; /* data initializer outer brace count */ static BOOL lex; /* lex file */ ! static int miflevel = IFLEVELINC; /* maximum #if nesting level */ static int *maxifbraces; /* maximum brace count within #if */ static int *preifbraces; /* brace count before #if */ --- 62,70 ---- static BOOL fcndef; /* function definition */ static BOOL global; /* file global scope (outside functions) */ ! static size_t iflevel; /* #if nesting level */ static BOOL initializer; /* data initializer */ static int initializerbraces; /* data initializer outer brace count */ static BOOL lex; /* lex file */ ! static size_t miflevel = IFLEVELINC; /* maximum #if nesting level */ static int *maxifbraces; /* maximum brace count within #if */ static int *preifbraces; /* brace count before #if */ *************** *** 216,221 **** if (iflevel == miflevel) { miflevel += IFLEVELINC; ! maxifbraces = myrealloc(maxifbraces, miflevel * sizeof(int)); ! preifbraces = myrealloc(preifbraces, miflevel * sizeof(int)); } /* push the current brace count */ --- 216,221 ---- if (iflevel == miflevel) { miflevel += IFLEVELINC; ! maxifbraces = myrealloc(maxifbraces, miflevel * sizeof(*maxifbraces)); ! preifbraces = myrealloc(preifbraces, miflevel * sizeof(*preifbraces)); } /* push the current brace count */ *************** *** 603,608 **** if (maxifbraces == NULL) { ! maxifbraces = mymalloc(miflevel * sizeof(int)); ! preifbraces = mymalloc(miflevel * sizeof(int)); } first = 0; /* buffer index for first char of symbol */ --- 603,608 ---- if (maxifbraces == NULL) { ! maxifbraces = mymalloc(miflevel * sizeof(*maxifbraces)); ! preifbraces = mymalloc(miflevel * sizeof(*preifbraces)); } first = 0; /* buffer index for first char of symbol */ Index: vpinit.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/vpinit.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** vpinit.c 23 Jul 2006 20:59:20 -0000 1.8 --- vpinit.c 20 Nov 2014 21:12:54 -0000 1.9 *************** *** 106,110 **** } /* create the source directory list */ ! vpdirs = mymalloc(vpndirs * sizeof(char *)); /* don't change VPATH in the environment */ --- 106,110 ---- } /* create the source directory list */ ! vpdirs = mymalloc(vpndirs * sizeof(*vpdirs)); /* don't change VPATH in the environment */ *************** *** 125,129 **** /* convert the view path nodes to directories */ for (i = 0; i < vpndirs; ++i) { ! s = mymalloc((strlen(vpdirs[i]) + strlen(suffix) + 1)); (void) strcpy(s, vpdirs[i]); (void) strcat(s, suffix); --- 125,129 ---- /* convert the view path nodes to directories */ for (i = 0; i < vpndirs; ++i) { ! s = mymalloc(strlen(vpdirs[i]) + strlen(suffix) + 1); (void) strcpy(s, vpdirs[i]); (void) strcat(s, suffix); |