[comp.sources.amiga] lib_ref part 1 of 1

ain@j.cc.purdue.edu (Patrick White) (01/30/88)

Program Name:	lib_ref   (part 1 of 1)
Submitted By:	bryce%hoser.Berkeley.EDU@ucbvax.berkeley.edu (Bryce Nesbitt)
Summary:	Files in the current directory ending with .fd are assumed
		to contain definitions for Amiga library calls.  An
		offset-reference sheet is produced on the standard output.
Poster Boy:  Pat White  (ain@j.cc.purdue.edu)
Compiled.

NOTES:
   I compiled it and it runs -- although I still don't really understand
what it is supposed to do :-)


-- Pat White   (co-moderator comp.sources/binaries.amiga)
UUCP: j.cc.purdue.edu!ain  BITNET: PATWHITE@PURCCVM   PHONE: (317) 743-8421
U.S.  Mail:  320 Brown St. apt. 406,    West Lafayette, IN 47906

========================================


   This is probably the command Bryce uses to compile it... I just included
it in case somebody wanted to know.  Pat.

lc -b -ccs -f -Lcd -r -v library_referencer.c



#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	l.c
# This archive created: Fri Jan 29 19:11:03 1988
# By:	Patrick White (PUCC Land, USA)
echo shar: extracting l.c '(3958 characters)'
cat << \SHAR_EOF > l.c
/*
 library_referencer reads all the files in the current directory.  Those
ending with .fd are assumed to contain definitions for Amiga library calls.
An offset-reference sheet is produced on the standard output.

 (C)1987 Bryce Nesbitt.  Unlimited, free, non-exclusive licence hereby
granted to anyone to use this code in any way, provided that this copyright
notice remains fully attached and with the exception that it not be
utilized by any entity that has been commonly referred to as Robert W.
Skyles, Skyles Electric Works, Jim Drew, Regie Warren or any organization
founded by, controlled, employing or profiting any such entity, it's
offspring or spouses.

 Designed to work under Lattice C 4.0 ONLY.  Kludged to compile under Manx
3.4b; what a pain!  Some features disabled under Manx.

 If comiled under Lattice, it will work from Workbench, sort of.  If it
encounters an error, it quits without explanation.

 If you want to remove the linefeed in the output, search for \014.

Bryce Nesbitt
1712 Marin Ave.
Berkeley, Ca 96034-9412
ucbvax!hoser!bryce
bryce@hoser.berkeley.EDU
*/

#define LATTICE_4   /* change to an undef for anything
		       other than Lattice C V4.0 */

#include "stdio.h"
#include "ctype.h"
#ifdef LATTICE_4
#undef NULL
#include "dos.h"
#include "string.h"
#include "stdlib.h"
#undef printf	/* Disable _builtin_printf */
#endif


#ifdef LATTICE_4
struct FILEINFO info;
#endif
char h[9];  /* ffffeeee */
char s[161];
#define SSIZE (sizeof(s)-1)


#ifdef LATTICE_4
void formatfile(FILE *,char *);
#endif
static void formatfile(handle,name)
register FILE *handle;
char *name;
{
long bias=0;
unsigned char class;
#ifdef LATTICE_4
char *p;
#else
int p;
#endif

    class=' ';  /* Assume these are public until told otherwise */

    while (p=fgets(&s[0],SSIZE,handle) ) /* Skip until ##base encountered */
	{
	if (!( strncmp(&s[0],"##base",6) ))
	    break;
	}
    if (p)
	{
     /* if (!( printf("\n%s\n",name) )) */
	if (!( printf("\014%s\n",name) ))
	    exit(11);
	}
    while (p)
	{
	if (!( strncmp(&s[0],"##",2) ))
	    if (!( strncmp(&s[2],"bias ",5) ))
		{
		sscanf(&s[7],"%ld",&bias); /* Get new starting negative offset */
		bias=0-bias;
		}
	    else if (!( strncmp(&s[2],"private",7) ))
		class='|';              /* Flag a private function */
	    else if (!( strncmp(&s[2],"public",6) ))
		class=' ';              /* Flag for a public function */
	if ( isalpha(s[0]) )
	    {
	    sprintf(h,"%lx",bias);
	    if (!( printf("%s %3lx %4ld%c%s",&h[4],0-bias,bias,class,s) ))
		exit(11);
	    bias-=6;
	    }
	p=fgets(&s[0],SSIZE,handle);
	}
}


void main(argc,argv)
int argc;
char *argv[];
{
int error;
register FILE *handle;
char *p;

    if (!stdout)
	exit(-1);   /* Sorry, Charlie! */

#ifdef LATTICE_4      /* Tell the user about us */
    if (argc>2 || *argv[1]=='?' )
	{
	printf("CLI Usage: %s [filename] ;By default it reads all the files in\
 the current directory.  Those ending with .fd are checked for definitions\
 for Amiga library calls.  An offset-reference sheet is produced on the\
 standard output.\n", argv[0]);
	exit(10);
	}
#else
    if (argc!=2 || *argv[1]=='?' )
	{
	printf("CLI Usage: %s filename ;The file is checked for definitions for\
 Amiga library calls.  You should feed it \".fd\" files.  An offset-reference\
 sheet is produced on the standard output.\n", argv[0]);
	exit(10);
	}
#endif

    if (argc==2)    /* Use the user's name */
	{
	if ( handle=fopen(argv[1],"r") )
	    {
	    formatfile(handle,argv[1]);
	    fclose(handle);
	    }
	exit(0);
	}

#ifdef LATTICE_4      /* Search the current directory */
    error=dfind(&info,"#?",0);  /* Search the current directory */

    while (!error) /* While there are still files */
	{
	p=strchr((char *)&info.fib_FileName,'.');
	if (!( strncmp(p,".fd",3) ))
	    {
	    if ( handle=fopen((char *)&info.fib_FileName,"r") )
		{
		formatfile(handle,(char *)&info.fib_FileName);
		fclose(handle);
		}
	    }
	error=dnext(&info);
	}
#endif
}
SHAR_EOF
if test 3958 -ne "`wc -c l.c`"
then
echo shar: error transmitting l.c '(should have been 3958 characters)'
fi
#	End of shell archive
exit 0