[comp.sources.d] C Cross Reference Database for SCO Xenix SV

greg@smash.CTS.COM (Greg Laskin) (10/09/87)

As distributed, the program uses pointers and longs interchangably.  These
hacks make it work better under SCO Xenix SV (2.1.3).  Most of the changes
would probably be useful for uPort too.  Watch out under uPort for lots
of mallocs and the makefile changes some of which are Xenix specific.


*** cxref.orig/bsearch.c	Fri Oct  9 11:24:49 1987
--- cxref/bsearch.c	Fri Oct  9 12:11:34 1987
***************
*** 1,6
  /* Copyright (c) 1986, Greg McGary */
  static char sccsid[] = "@(#)bsearch.c	1.1 86/10/09";
! 
  char *bsearch();
  
  /*

--- 1,9 -----
  /* Copyright (c) 1986, Greg McGary */
  static char sccsid[] = "@(#)bsearch.c	1.1 86/10/09";
! #ifdef LINT_ARGS
! #define bsearch Bsearch
! #endif
! long bsearch();
  
  /*

***************
*** 6,12
  /*
  	Binary search -- from Knuth (6.2.1) Algorithm B
  */
! char *
  bsearch(key, base, nel, width, compar)
  	char		*key;
  	register char	*base;

--- 8,14 -----
  /*
  	Binary search -- from Knuth (6.2.1) Algorithm B
  */
! long
  bsearch(key, base, nel, width, compar)
  	char		*key;
  	long	base;
***************
*** 9,15
  char *
  bsearch(key, base, nel, width, compar)
  	char		*key;
! 	register char	*base;
  	unsigned int	nel;
  	int		width;
  	int		(*compar)();

--- 11,17 -----
  long
  bsearch(key, base, nel, width, compar)
  	char		*key;
! 	long	base;
  	unsigned int	nel;
  	int		width;
  	int		(*compar)();
***************
*** 14,21
  	int		width;
  	int		(*compar)();
  {
! 	register char	*last;
! 	register char	*position;
  	register int	result;
  	int		width2;
  

--- 16,23 -----
  	int		width;
  	int		(*compar)();
  {
! 	long	last;
! 	long	position;
  	register int	result;
  	int		width2;
  
***************
*** 20,26
  	int		width2;
  
  	width2 = width * 2;
! 	last = &base[width * (nel - 1)];
  
  	while (last >= base) {
  		position = &base[width * ((last - base)/width2)];

--- 22,28 -----
  	int		width2;
  
  	width2 = width * 2;
! 	last = base + (width * (nel - 1));
  
  	while (last >= base) {
  		position = base + (width * ((last - base)/width2));
***************
*** 23,29
  	last = &base[width * (nel - 1)];
  
  	while (last >= base) {
! 		position = &base[width * ((last - base)/width2)];
  		
  		if ((result = (*compar)(key, position)) == 0)
  			return position;

--- 25,31 -----
  	last = base + (width * (nel - 1));
  
  	while (last >= base) {
! 		position = base + (width * ((last - base)/width2));
  		
  		if ((result = (*compar)(key, position)) == 0)
  			return position;
***************
*** 32,36
  		else
  			base = position + width;
  	}
! 	return (char *)0;
  }

--- 34,38 -----
  		else
  			base = position + width;
  	}
! 	return 0;
  }




*** cxref.orig/hash.c	Fri Oct  9 11:24:56 1987
--- cxref/hash.c	Wed Oct  7 10:37:07 1987
***************
*** 27,34
  	char		*base;		/* base of hash table */
  	register int	nel;		/* number of elements in table */
  	int		width;		/* width of each element */
! 	int		(*h1)();	/* primary hash function */
! 	int		(*h2)();	/* secondary hash function */
  	int		(*compar)();	/* key comparison function */
  	long		*probes;
  {

--- 27,34 -----
  	char		*base;		/* base of hash table */
  	register int	nel;		/* number of elements in table */
  	int		width;		/* width of each element */
! 	unsigned		(*h1)();	/* primary hash function */
! 	unsigned		(*h2)();	/* secondary hash function */
  	int		(*compar)();	/* key comparison function */
  	long		*probes;
  {
***************
*** 32,39
  	int		(*compar)();	/* key comparison function */
  	long		*probes;
  {
! 	register int	hash1;
! 	register int	hash2;
  	register char	*slot;
  
  	hash1 = (*h1)(key) % nel;

--- 32,39 -----
  	int		(*compar)();	/* key comparison function */
  	long		*probes;
  {
! 	register unsigned	hash1;
! 	register unsigned	hash2;
  	register char	*slot;
  
  	hash1 = (*h1)(key) % nel;
*** cxref.orig/init.c	Fri Oct  9 11:24:58 1987
--- cxref/init.c	Tue Oct  6 18:23:31 1987
***************
*** 21,27
  		return NULL;
  
  	fseek(idFILE, 0L, 0);
! 	fread(idhp, sizeof(struct idhead), 1, idFILE);
  	if (!strnequ(idhp->idh_magic, IDH_MAGIC, sizeof(idhp->idh_magic))) {
  		fprintf(stderr, "%s: Not an id file: `%s'\n", MyName, idFile);
  		exit(1);

--- 21,27 -----
  		return NULL;
  
  	fseek(idFILE, 0L, 0);
! 	fread((char *)idhp, sizeof(struct idhead), 1, idFILE);
  	if (!strnequ(idhp->idh_magic, IDH_MAGIC, sizeof(idhp->idh_magic))) {
  		fprintf(stderr, "%s: Not an id file: `%s'\n", MyName, idFile);
  		exit(1);
*** cxref.orig/lid.c	Fri Oct  9 11:25:03 1987
--- cxref/lid.c	Wed Oct  7 16:56:30 1987
***************
*** 231,237
  	if (!Merging || (re = fileRE(name, delimit, delimit)) == NULL)
  		re = NULL;
  #ifdef REGEX
! 	else if ((reCompiled = regcmp(re, 0)) == NULL) {
  		fprintf(stderr, "%s: Syntax Error: %s\n", MyName, re);
  		return;
  	}

--- 231,237 -----
  	if (!Merging || (re = fileRE(name, delimit, delimit)) == NULL)
  		re = NULL;
  #ifdef REGEX
! 	else if ((reCompiled = regcmp(re,(char *) 0)) == NULL) {
  		fprintf(stderr, "%s: Syntax Error: %s\n", MyName, re);
  		return;
  	}
***************
*** 473,479
  	char		*reCompiled;
  
  #ifdef REGEX
! 	if ((reCompiled = regcmp(re, 0)) == NULL) {
  		fprintf(stderr, "%s: Syntax Error: %s\n", MyName, re);
  		return 0;
  	}

--- 473,479 -----
  	char		*reCompiled;
  
  #ifdef REGEX
! 	if ((reCompiled = regcmp(re, (char *)0)) == NULL) {
  		fprintf(stderr, "%s: Syntax Error: %s\n", MyName, re);
  		return 0;
  	}


*** cxref.orig/makefile	Fri Oct  9 11:24:32 1987
--- cxref/makefile	Fri Oct  9 12:14:33 1987
***************
*** 32,38
  #   it, set `RANLIB' to something harmless like `@:', or `echo'
  # --------------------------------------------------------------------
  
! # DEFS	=	-DREGEX -DNDIR -DTERMIO	# typical System-V defs
  # DEFS	=	-Dvoid=int -DRINDEX -DRE_EXEC -DNDIR	# typical V7 defs
  DEFS	=	-Dvoid=int -DRINDEX -DRE_EXEC -DERRLINEBUF	# BSD defs
  

--- 32,38 -----
  #   it, set `RANLIB' to something harmless like `@:', or `echo'
  # --------------------------------------------------------------------
  
! DEFS	=	-DREGEX -DNDIR -DTERMIO	# typical System-V defs
  # DEFS	=	-Dvoid=int -DRINDEX -DRE_EXEC -DNDIR	# typical V7 defs
  # DEFS	=	-Dvoid=int -DRINDEX -DRE_EXEC -DERRLINEBUF	# BSD defs
  
***************
*** 34,40
  
  # DEFS	=	-DREGEX -DNDIR -DTERMIO	# typical System-V defs
  # DEFS	=	-Dvoid=int -DRINDEX -DRE_EXEC -DNDIR	# typical V7 defs
! DEFS	=	-Dvoid=int -DRINDEX -DRE_EXEC -DERRLINEBUF	# BSD defs
  
  # LIBS	=	-lndir -lPW	# typical System-V libs
  # LIBS	=	-lndir	# typical V7 libs

--- 34,40 -----
  
  DEFS	=	-DREGEX -DNDIR -DTERMIO	# typical System-V defs
  # DEFS	=	-Dvoid=int -DRINDEX -DRE_EXEC -DNDIR	# typical V7 defs
! # DEFS	=	-Dvoid=int -DRINDEX -DRE_EXEC -DERRLINEBUF	# BSD defs
  
  # LIBS	=	-lndir -lPW	# typical System-V libs
  # LIBS	=	-lndir	# typical V7 libs
***************
*** 38,44
  
  # LIBS	=	-lndir -lPW	# typical System-V libs
  # LIBS	=	-lndir	# typical V7 libs
! LIBS	=	# typical BSD libs (none)
  
  #RANLIB	=	@:	# system doesn't have ranlib (Sys-V)
  RANLIB	=	ranlib	# system has ranlib (typically V7 & BSD)

--- 38,45 -----
  
  # LIBS	=	-lndir -lPW	# typical System-V libs
  # LIBS	=	-lndir	# typical V7 libs
! # LIBS	=	# typical BSD libs (none)
! LIBS	=	-lx # Xenix SV ndir extension
  
  #RANLIB	=	@:	# system doesn't have ranlib (Sys-V)
  RANLIB	=	ranlib	# system has ranlib (typically V7 & BSD)
***************
*** 51,57
  
  # CCFLG	=	-g -DDEBUG 	# debugging
  # CCFLG	=	-p	# profiling
! CCFLG	=	-O	# production
  
  # LDFLG	=	-g	# debugging
  # LDFLG	=	-p	# profiling

--- 52,58 -----
  
  # CCFLG	=	-g -DDEBUG 	# debugging
  # CCFLG	=	-p	# profiling
! CCFLG	=	-LARGE -O	-Ml # production
  
  # LDFLG	=	-g	# debugging
  # LDFLG	=	-p	# profiling
***************
*** 55,61
  
  # LDFLG	=	-g	# debugging
  # LDFLG	=	-p	# profiling
! LDFLG	=	# production
  
  # --------------------------------------------------------------------
  

--- 56,62 -----
  
  # LDFLG	=	-g	# debugging
  # LDFLG	=	-p	# profiling
! LDFLG	=	-S3 -Ml -i # production
  
  # --------------------------------------------------------------------
  
***************
*** 82,88
  		$(RANLIB) $@
  
  mkid:		mkid.o libid.a
! 		$(CC) -o $@ $@.o $(LDFLAGS)
  
  fid:		fid.o libid.a
  		$(CC) -o $@ $@.o $(LDFLAGS)

--- 83,89 -----
  		$(RANLIB) $@
  
  mkid:		mkid.o libid.a
! 		$(CC) $(LDFLAGS) -o $@ $@.o
  
  fid:		fid.o libid.a
  		$(CC) $(LDFLAGS) -o $@ $@.o
***************
*** 85,91
  		$(CC) -o $@ $@.o $(LDFLAGS)
  
  fid:		fid.o libid.a
! 		$(CC) -o $@ $@.o $(LDFLAGS)
  
  lid:		lid.o libid.a
  		$(CC) -o $@ $@.o $(LDFLAGS)

--- 86,92 -----
  		$(CC) $(LDFLAGS) -o $@ $@.o
  
  fid:		fid.o libid.a
! 		$(CC) $(LDFLAGS) -o $@ $@.o
  
  lid:		lid.o libid.a
  		$(CC) $(LDFLAGS) -o $@ $@.o
***************
*** 88,94
  		$(CC) -o $@ $@.o $(LDFLAGS)
  
  lid:		lid.o libid.a
! 		$(CC) -o $@ $@.o $(LDFLAGS)
  
  idx:		idx.o libid.a
  		$(CC) -o $@ $@.o $(LDFLAGS)

--- 89,95 -----
  		$(CC) $(LDFLAGS) -o $@ $@.o
  
  lid:		lid.o libid.a
! 		$(CC) $(LDFLAGS) -o $@ $@.o
  
  idx:		idx.o libid.a
  		$(CC) $(LDFLAGS) -o $@ $@.o
***************
*** 91,97
  		$(CC) -o $@ $@.o $(LDFLAGS)
  
  idx:		idx.o libid.a
! 		$(CC) -o $@ $@.o $(LDFLAGS)
  
  $(LIDLINKS): lid
  		-/bin/rm -f $@

--- 92,98 -----
  		$(CC) $(LDFLAGS) -o $@ $@.o
  
  idx:		idx.o libid.a
! 		$(CC) $(LDFLAGS) -o $@ $@.o
  
  $(LIDLINKS): lid
  		-/bin/rm -f $@



*** cxref.orig/mkid.c	Fri Oct  9 11:25:11 1987
--- cxref/mkid.c	Fri Oct  9 12:11:14 1987
***************
*** 174,180
  	for (idArgs = idArgHead; idArgs->ida_next; idArgs = idArgs->ida_next) {
  		char		*(*scanner)();
  		FILE		*srcFILE;
! 		char		*arg, *lang, *suff;
  
  		arg = idArgs->ida_arg;
  		if (idArgs->ida_flags & IDA_ARG) {

--- 174,180 -----
  	for (idArgs = idArgHead; idArgs->ida_next; idArgs = idArgs->ida_next) {
  		char		*(*scanner)();
  		FILE		*srcFILE;
! 		char		*arg, *lang=NULL, *suff;
  
  		arg = idArgs->ida_arg;
  		if (idArgs->ida_flags & IDA_ARG) {
***************
*** 238,244
  	hashCompress(HashTable, HashSize);
  	if (Verbose)
  		fprintf(stderr, "Sorting Hash Table...\n");
! 	qsort(HashTable, HashFill, sizeof(struct idname *), idnQsortCmp);
  
  	if (argsFrom == AF_IDFILE) {
  		if (Verbose)

--- 238,244 -----
  	hashCompress(HashTable, HashSize);
  	if (Verbose)
  		fprintf(stderr, "Sorting Hash Table...\n");
! 	qsort((char *)HashTable, (int)HashFill, sizeof(struct idname *), idnQsortCmp);
  
  	if (argsFrom == AF_IDFILE) {
  		if (Verbose)
***************
*** 277,283
  	int		flags;
  
  	while ((key = (*getId)(srcFILE, &flags)) != NULL) {
! 		slot = (struct idname **)hashSearch(key, HashTable, HashSize, sizeof(struct idname *), h1str, h2str, idnHashCmp, &HashProbes);
  		HashSearches++;
  		if (*slot != NULL) {
  			(*slot)->idn_flags |= flags;

--- 277,283 -----
  	int		flags;
  
  	while ((key = (*getId)(srcFILE, &flags)) != NULL) {
! 		slot = (struct idname **)hashSearch(key, (char *)HashTable, (int) HashSize, sizeof(struct idname *), h1str, h2str, idnHashCmp, &HashProbes);
  		HashSearches++;
  		if (*slot != NULL) {
  			(*slot)->idn_flags |= flags;
***************
*** 337,343
  	idh.idh_vecc = i;
  
  	vecBuf = malloc((idh.idh_pthc + 1) * idh.idh_vecc);
- 
  	putc('\377', idFILE);
  	before = idh.idh_namo = ftell(idFILE);
  	longest = 0;

--- 337,342 -----
  	idh.idh_vecc = i;
  
  	vecBuf = malloc((idh.idh_pthc + 1) * idh.idh_vecc);
  	putc('\377', idFILE);
  	before = idh.idh_namo = ftell(idFILE);
  	longest = 0;
***************
*** 378,384
  	strncpy(idh.idh_magic, IDH_MAGIC, sizeof(idh.idh_magic));
  	idh.idh_vers = IDH_VERS;
  	fseek(idFILE, 0L, 0);
! 	fwrite(&idh, sizeof(struct idhead), 1, idFILE);
  
  	fclose(idFILE);
  }

--- 377,383 -----
  	strncpy(idh.idh_magic, IDH_MAGIC, sizeof(idh.idh_magic));
  	idh.idh_vers = IDH_VERS;
  	fseek(idFILE, 0L, 0);
! 	fwrite((char *)&idh, sizeof(struct idhead), 1, idFILE);
  
  	fclose(idFILE);
  }
***************
*** 412,418
  		usage();
  	}
  	idModTime = statBuf.st_mtime;
! 	fread(&idh, sizeof(struct idhead), 1, idFILE);
  	if (!strnequ(idh.idh_magic, IDH_MAGIC, sizeof(idh.idh_magic))) {
  		fprintf(stderr, "%s: Not an id file: `%s'\n", MyName, idFile);
  		exit(1);

--- 411,417 -----
  		usage();
  	}
  	idModTime = statBuf.st_mtime;
! 	fread((char *)&idh, sizeof(struct idhead), 1, idFILE);
  	if (!strnequ(idh.idh_magic, IDH_MAGIC, sizeof(idh.idh_magic))) {
  		fprintf(stderr, "%s: Not an id file: `%s'\n", MyName, idFile);
  		exit(1);
***************
*** 477,483
  
  	if ((idFILE = fopen(idFile, "r")) == NULL)
  		filerr("open", idFile);
! 	fread(&idh, sizeof(struct idhead), 1, idFILE);
  
  	entry = malloc(idh.idh_bsiz);
  

--- 476,482 -----
  
  	if ((idFILE = fopen(idFile, "r")) == NULL)
  		filerr("open", idFile);
! 	fread((char *)&idh, sizeof(struct idhead), 1, idFILE);
  
  	entry = malloc(idh.idh_bsiz);
  	bitsOff = malloc(BitArraySize);
***************
*** 480,486
  	fread(&idh, sizeof(struct idhead), 1, idFILE);
  
  	entry = malloc(idh.idh_bsiz);
- 
  	bitsOff = malloc(BitArraySize);
  	bzero(bitsOff, BitArraySize);
  	for (i = 0; idArgs->ida_next; idArgs = idArgs->ida_next)

--- 479,484 -----
  	fread((char *)&idh, sizeof(struct idhead), 1, idFILE);
  
  	entry = malloc(idh.idh_bsiz);
  	bitsOff = malloc(BitArraySize);
  	bzero(bitsOff, BitArraySize);
  	for (i = 0; idArgs->ida_next; idArgs = idArgs->ida_next)
***************
*** 490,495
  	bitArray = malloc(BitArraySize);
  	bzero(bitArray, BitArraySize);
  	t2 = newTable = (struct idname **)malloc((idh.idh_namc + 1) * sizeof(struct idname *));
  	fseek(idFILE, idh.idh_namo, 0);
  	count = 0;
  	for (i = 0; i < idh.idh_namc; i++) {

--- 488,494 -----
  	bitArray = malloc(BitArraySize);
  	bzero(bitArray, BitArraySize);
  	t2 = newTable = (struct idname **)malloc((idh.idh_namc + 1) * sizeof(struct idname *));
+ 
  	fseek(idFILE, idh.idh_namo, 0);
  	count = 0;
  	for (i = 0; i < idh.idh_namc; i++) {
***************
*** 587,593
  		fprintf(stderr, "Rehashing... (doubling size to %ld)\n", HashSize);
  	HashMaxLoad = HashSize - (HashSize >> 4);
  	HashTable = (struct idname **)calloc(HashSize, sizeof(struct idname *));
- 
  	HashFill = 0;
  	for (htp = oldHashTable; htp < &oldHashTable[oldHashSize]; htp++) {
  		if (*htp == NULL)

--- 586,591 -----
  		fprintf(stderr, "Rehashing... (doubling size to %ld)\n", HashSize);
  	HashMaxLoad = HashSize - (HashSize >> 4);
  	HashTable = (struct idname **)calloc(HashSize, sizeof(struct idname *));
  	HashFill = 0;
  	for (htp = oldHashTable; htp < &oldHashTable[oldHashSize]; htp++) {
  		if (*htp == NULL)
***************
*** 592,598
  	for (htp = oldHashTable; htp < &oldHashTable[oldHashSize]; htp++) {
  		if (*htp == NULL)
  			continue;
! 		slot = (struct idname **)hashSearch((*htp)->idn_name, (char *)HashTable, HashSize, sizeof(struct idname *), h1str, h2str, idnHashCmp, &HashProbes);
  		if (*slot) {
  			fprintf(stderr, "%s: Duplicate hash entry!\n");
  			exit(1);

--- 590,596 -----
  	for (htp = oldHashTable; htp < &oldHashTable[oldHashSize]; htp++) {
  		if (*htp == NULL)
  			continue;
! 		slot = (struct idname **)hashSearch((*htp)->idn_name, (char *)HashTable, (int)HashSize, sizeof(struct idname *), h1str, h2str, idnHashCmp, &HashProbes);
  		if (*slot) {
  			fprintf(stderr, "%s: Duplicate hash entry!\n");
  			exit(1);
***************
*** 601,607
  		HashSearches++;
  		HashFill++;
  	}
! 	free(oldHashTable);
  }
  
  /*

--- 599,605 -----
  		HashSearches++;
  		HashFill++;
  	}
! 	free((char *)oldHashTable);
  }
  
  /*



*** cxref.orig/paths.c	Fri Oct  9 11:25:14 1987
--- cxref/paths.c	Tue Oct  6 18:00:29 1987
***************
*** 127,134
  }
  #include	<sys/types.h>
  #include	<sys/stat.h>
! #ifdef NDIR
! #include	<ndir.h>
  #else
  #include	<sys/dir.h>
  #endif

--- 127,136 -----
  }
  #include	<sys/types.h>
  #include	<sys/stat.h>
! #if defined(NDIR) && defined(M_XENIX) && defined(M_SYS5)
! #include <sys/ndir.h>
! #elif defined (NDIR)
! #include <ndir.h>
  #else
  #include	<sys/dir.h>
  #endif
-- 
Greg Laskin           
"When everybody's talking and nobody's listening, how can we decide?"
INTERNET:     laskin@gryphon.CTS.COM
UUCP:         {hplabs!hp-sdd, sdcsvax, ihnp4, nosc}!crash!gryphon!laskin