⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 depend.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * mkdepend() creates include file dependencies for object files and installs * them to dependency list dlp. Returns a pointer to the dependency list. */DLIST *mkdepend(){	extern SLIST *SRCLIST;		/* source file name list */	char *suffix;			/* suffix pointer */	DLBLK *dlappend();		/* append dependency list */	DLIST *dlinit();		/* initialize dependency list */	DLIST *dlist;			/* dependency list */	INCBLK *ibp;			/* pointer to chain of include files */	INCBLK *readC();		/* read C include-style files */	INCBLK *readF();		/* read Fortran include-style files */	INCBLK *readP();		/* read Pascal include-style files */	int cleanup();			/* remove temporary makefile and exit */	int lookuptypeofinclude();	/* look up the brand of include */	int slsort();			/* sort singly-linked list */	int type;			/* source file type */	SLBLK *lbp;			/* list block pointer */	SLIST *slinit();		/* initialize singly-linked list */	void addincdir();		/* add to list of include directories */	void rmprinttag();		/* remove "already printed" tags */	/* initialize include file look-up lists */	C_INCDIR   = slinit();	CXX_INCDIR = slinit();	F_INCDIR   = slinit();	P_INCDIR   = slinit();	/* add additional include directories */	addincdir();	/* initialize external and system header file name lists */	EXTLIST = slinit();	SYSLIST = slinit();	/* initialize dependency list */	dlist = dlinit();	for (lbp = SRCLIST->head; lbp != NULL; lbp = lbp->next)		{		suffix = strrchr(lbp->key, '.');		type = lookuptypeofinclude(++suffix);		switch (type)			{			case INCLUDE_C:			case INCLUDE_CXX:				ibp = readC(lbp->key, 0, lbp->key, type);				break;			case INCLUDE_FORTRAN:				ibp = readF(lbp->key, 0, lbp->key, type);				break;			case INCLUDE_PASCAL:				ibp = readP(lbp->key, 0, lbp->key, type);				break;			case INCLUDE_NONE:				ibp = NULL;				break;			}		if (ibp != NULL)			{			if (dlappend(type, lbp, ibp, dlist) == NULL)				cleanup();			}		}	if (slsort(strcmp, EXTLIST) == NO || slsort(strcmp, SYSLIST) == NO)		cleanup();	return(dlist);}/* * notfound() prints a "can't find" filename error message. */voidnotfound(curname, lineno, incname)	char *curname;			/* current file name */	char *incname;			/* name of include file */	int lineno;			/* current line number */{	if (PGN != NULL && *PGN != '\0')		{		fprintf(stderr, "%s: ", PGN);		}	if (*incname == '<')		{		fprintf(stderr, "\"%s\", line %d: can't find %s\n",			curname, lineno, incname);		}	else	{		fprintf(stderr, "\"%s\", line %d: can't find \"%s\"\n",			curname, lineno, incname);		}}/* * readC() searches C files for included files. Returns a pointer to * the chain of include files installed or found in the include file * hash table, or null if no include files found. */INCBLK *readC(lastfile, lastline, curname, type)	char *lastfile;			/* parent file name */	int lastline;			/* current line in parent file */	char *curname;			/* current file name */	int type;			/* file type */{	register char *p;		/* include string pointer */	register FILE *ifp;		/* input file stream */	register int c;			/* current character */	char incname[PATHSIZE];		/* name of include file */	char incpath[PATHSIZE];		/* path to include file */	char *slappend();		/* append pathname to list */	FILE *fopen();			/* open file */	HASHBLK *ftb;			/* fromrule hash table entry block */	HASHBLK *htb;			/* hash table entry block */	HASHBLK *instalinclude();	/* install include name in hash table */	HASHBLK *lookupinclude();	/* look up include in hash table */	INCBLK *i_head = NULL;		/* head of include chain */	INCBLK *i_tail = NULL;		/* tail of include chain */	INCBLK *inclink();		/* link include file hash blocks */	int cleanup();			/* remove temporary makefile and exit */	int findinclude();		/* locate include file */	int getinclude();		/* get include name from input line */	int inctype;			/* origin of include file */	int lineno = 1;			/* current line number */	void notfound();		/* print "can't find" filename msg */	if ((ifp = fopen(curname, "r")) == NULL)		{		if (lastline > 0)			fprintf(stderr, "%s: \"%s\", line %d: ", PGN,				lastfile, lastline);		else			fprintf(stderr, "%s: ", PGN);		perror(curname);		return(NULL);		}	while ((c = getc(ifp)) != EOF)		{		if (ISWHITESPACE(c))			continue;		if (c != '#')			goto nextline;		SKIPWHITESPACE(c, ifp);		for (p = "include"; (c = getc(ifp)) == *p && *p != '\0' ; p++)			continue;		if (*p != '\0')			goto nextline;		ungetc(c, ifp);		if (getinclude(incname, curname, lineno, ifp) == NO)			goto nextline;		if ((htb = lookupinclude(incname, type)) == NULL)			{			inctype = findinclude(incpath, incname, curname, type);			if (inctype == INTERNAL)				{				htb = instalinclude(incname, incpath, type);				}			else if (inctype == SYSTEM && SYSHDRS == YES)				{				htb = instalinclude(incname, incpath, type);				if (slappend(incpath, SYSLIST) == NULL)					cleanup();				}			else if (inctype == SYSTEM && SYSHDRS == NO)				{				goto nextline;				}			else if (inctype == EXTERNAL)				{				htb = instalinclude(incname, incpath, type);				if (slappend(incpath, EXTLIST) == NULL)					cleanup();				}			else if (inctype == FROMRULE)				{				htb = instalinclude(incname, incname, type);				ftb = instalinclude(incpath, incpath, type);				}			else	{				notfound(curname, lineno, incname);				goto nextline;				}			/* look for nested include files */			htb->h_sub = readC(curname, lineno, incpath, type);			if (inctype == FROMRULE)				ftb->h_sub = htb->h_sub;			}		if (i_tail == NULL)			{			i_head = i_tail = inclink(htb);			}		else	{			i_tail = i_tail->i_next = inclink(htb);			}nextline:	while (c != '\n' && c != EOF)			c = getc(ifp);		lineno++;		}	fclose(ifp);	return(i_head);}/* * readF() searches Fortran files for included files. Returns a pointer * to the chain of include files installed or found in the include file * hash table, or null if no include files found. */INCBLK *readF(lastfile, lastline, curname, type)	char *lastfile;			/* parent file name */	int lastline;			/* current line in parent file */	char *curname;			/* current file name */	int type;			/* file type */{	register char *p;		/* include string pointer */	register FILE *ifp;		/* input file stream */	register int c;			/* current character */	char incname[PATHSIZE];		/* name of include file */	char incpath[PATHSIZE];		/* path to include file */	char *slappend();		/* append pathname to list */	FILE *fopen();			/* open file */	HASHBLK *ftb;			/* fromrule hash table entry block */	HASHBLK *htb;			/* hash table entry block */	HASHBLK *instalinclude();	/* install include name in hash table */	HASHBLK *lookupinclude();	/* look up include in hash table */	INCBLK *i_head = NULL;		/* head of include chain */	INCBLK *i_tail = NULL;		/* tail of include chain */	INCBLK *inclink();		/* link include file hash blocks */	int cleanup();			/* remove temporary makefile and exit */	int findinclude();		/* locate include file */	int getinclude();		/* get include name from input line */	int inctype;			/* origin of include file */	int lineno = 1;			/* current line number */	void notfound();		/* print "can't find" filename msg */	if ((ifp = fopen(curname, "r")) == NULL)		{		if (lastline > 0)			fprintf(stderr, "%s: \"%s\", line %d: ", PGN,				lastfile, lastline);		else			fprintf(stderr, "%s: ", PGN);		perror(curname);		return(NULL);		}	while ((c = getc(ifp)) != EOF)		{		if (c == 'c' || c == 'C' || c == '*' || c == '\n')			goto nextline;		while ((c = getc(ifp)) == ' ' || c == '\t' || c == '#' || c == '$')			continue;		for (p = "include"; *p == TOLOWER(c) && *p != '\0'; p++)			c = getc(ifp);		if (*p != '\0')			goto nextline;		ungetc(c, ifp);		if (getinclude(incname, curname, lineno, ifp) == NO)			goto nextline;		if ((htb = lookupinclude(incname, type)) == NULL)			{			inctype = findinclude(incpath, incname, curname, type);			if (inctype == INTERNAL)				{				htb = instalinclude(incname, incpath, type);				}			else if (inctype == SYSTEM && SYSHDRS == YES)				{				htb = instalinclude(incname, incpath, type);				if (slappend(incpath, SYSLIST) == NULL)					cleanup();				}			else if (inctype == SYSTEM && SYSHDRS == NO)				{				goto nextline;				}			else if (inctype == EXTERNAL)				{				htb = instalinclude(incname, incpath, type);				if (slappend(incpath, EXTLIST) == NULL)					cleanup();				}			else if (inctype == FROMRULE)				{				htb = instalinclude(incname, incname, type);				ftb = instalinclude(incpath, incpath, type);				}			else	{				notfound(curname, lineno, incname);				goto nextline;				}			/* look for nested include files */			htb->h_sub = readF(curname, lineno, incpath, type);			if (inctype == FROMRULE)				ftb->h_sub = htb->h_sub;			}		if (i_tail == NULL)			{			i_head = i_tail = inclink(htb);			}		else	{			i_tail = i_tail->i_next = inclink(htb);			}nextline:	while (c != '\n' && c != EOF)			c = getc(ifp);		lineno++;		}	fclose(ifp);	return(i_head);}/* * readP() searches Pascal files for included files. Returns a pointer * to the chain of include files installed or found in the include file * hash table, or null if no include files found. */INCBLK *readP(lastfile, lastline, curname, type)	char *lastfile;			/* parent file name */	int lastline;			/* current line in parent file */	char *curname;			/* current file name */	int type;			/* file type */{	register char *p;		/* include string pointer */	register FILE *ifp;		/* input file stream */	register int c;			/* current character */	char incname[PATHSIZE];		/* name of include file */	char incpath[PATHSIZE];		/* path to include file */	char *slappend();		/* append pathname to list */	FILE *fopen();			/* open file */	HASHBLK *ftb;			/* fromrule hash table entry block */	HASHBLK *htb;			/* hash table entry block */	HASHBLK *instalinclude();	/* install include name in hash table */	HASHBLK *lookupinclude();	/* look up include in hash table */	INCBLK *i_head = NULL;		/* head of include chain */	INCBLK *i_tail = NULL;		/* tail of include chain */	INCBLK *inclink();		/* link include file hash blocks */	int cleanup();			/* remove temporary makefile and exit */	int findinclude();		/* locate include file */	int getinclude();		/* get include name from input line */	int inctype;			/* origin of include file */	int lineno = 1;			/* current line number */	void notfound();		/* print "can't find" filename msg */	if ((ifp = fopen(curname, "r")) == NULL)		{		if (lastline > 0)			fprintf(stderr, "%s: \"%s\", line %d: ", PGN,				lastfile, lastline);		else			fprintf(stderr, "%s: ", PGN);		perror(curname);		return(NULL);		}	while ((c = getc(ifp)) != EOF)		{		if (ISWHITESPACE(c))			continue;		if (c != '#' && c != '$')			goto nextline;		while ((c = getc(ifp)) == ' ' || c == '\t')			continue;		for (p = "include"; *p == TOLOWER(c) && *p != '\0'; p++)			c = getc(ifp);		if (*p != '\0')			goto nextline;		ungetc(c, ifp);		if (getinclude(incname, curname, lineno, ifp) == NO)			goto nextline;		if ((htb = lookupinclude(incname, type)) == NULL)			{			inctype = findinclude(incpath, incname, curname, type);			if (inctype == INTERNAL)				{				htb = instalinclude(incname, incpath, type);				}			else if (inctype == SYSTEM && SYSHDRS == YES)				{				htb = instalinclude(incname, incpath, type);				if (slappend(incpath, SYSLIST) == NULL)					cleanup();				}			else if (inctype == SYSTEM && SYSHDRS == NO)				{				goto nextline;				}			else if (inctype == EXTERNAL)				{				htb = instalinclude(incname, incpath, type);				if (slappend(incpath, EXTLIST) == NULL)					cleanup();				}			else if (inctype == FROMRULE)				{				htb = instalinclude(incname, incname, type);				ftb = instalinclude(incpath, incpath, type);				}			else	{				notfound(curname, lineno, incname);				goto nextline;				}			/* look for nested include files */			htb->h_sub = readP(curname, lineno, incpath, type);			if (inctype == FROMRULE)				ftb->h_sub = htb->h_sub;			}		if (i_tail == NULL)			{			i_head = i_tail = inclink(htb);			}		else	{			i_tail = i_tail->i_next = inclink(htb);			}nextline:	while (c != '\n' && c != EOF)			c = getc(ifp);		lineno++;		}	fclose(ifp);	return(i_head);}initsysinclude(){	HASHBLK *htb;			/* hash table entry block */	HASHBLK *htlookup();		/* find hash table entry */#ifdef _HasCompileSysType	if ((htb = htlookup(MCOMPILESYSTYPE, MDEFTABLE)) != NULL)		{	        sprintf(SYSINCLUDE, "/%s", htb->h_def);	        sprintf(SYSINCLUDECC, "/%s", htb->h_def);		}#endif        strcat(SYSINCLUDE, USRINCLUDE);        strcat(SYSINCLUDECC, USRINCLUDECC);	SYSINCLUDELEN = strlen(SYSINCLUDE)-1; /* length - last '/' */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -