pr.c revision 0eb10989
10eb10989Smrg/* $Xorg: pr.c,v 1.4 2001/02/09 02:03:16 xorgcvs Exp $ */
20eb10989Smrg/*
30eb10989Smrg
40eb10989SmrgCopyright (c) 1993, 1994, 1998 The Open Group
50eb10989Smrg
60eb10989SmrgPermission to use, copy, modify, distribute, and sell this software and its
70eb10989Smrgdocumentation for any purpose is hereby granted without fee, provided that
80eb10989Smrgthe above copyright notice appear in all copies and that both that
90eb10989Smrgcopyright notice and this permission notice appear in supporting
100eb10989Smrgdocumentation.
110eb10989Smrg
120eb10989SmrgThe above copyright notice and this permission notice shall be included in
130eb10989Smrgall copies or substantial portions of the Software.
140eb10989Smrg
150eb10989SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
160eb10989SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
170eb10989SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
180eb10989SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
190eb10989SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
200eb10989SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
210eb10989Smrg
220eb10989SmrgExcept as contained in this notice, the name of The Open Group shall not be
230eb10989Smrgused in advertising or otherwise to promote the sale, use or other dealings
240eb10989Smrgin this Software without prior written authorization from The Open Group.
250eb10989Smrg
260eb10989Smrg*/
270eb10989Smrg/* $XFree86: xc/config/makedepend/pr.c,v 1.4 2001/04/29 23:25:02 tsi Exp $ */
280eb10989Smrg
290eb10989Smrg#include "def.h"
300eb10989Smrg
310eb10989Smrgextern struct	inclist	inclist[ MAXFILES ],
320eb10989Smrg			*inclistp;
330eb10989Smrgextern char	*objprefix;
340eb10989Smrgextern char	*objsuffix;
350eb10989Smrgextern int	width;
360eb10989Smrgextern boolean	printed;
370eb10989Smrgextern boolean	verbose;
380eb10989Smrgextern boolean	show_where_not;
390eb10989Smrg
400eb10989Smrgvoid
410eb10989Smrgadd_include(struct filepointer *filep, struct inclist *file,
420eb10989Smrg	    struct inclist *file_red, char *include, int type,
430eb10989Smrg	    boolean failOK)
440eb10989Smrg{
450eb10989Smrg	register struct inclist	*newfile;
460eb10989Smrg	register struct filepointer	*content;
470eb10989Smrg
480eb10989Smrg	/*
490eb10989Smrg	 * First decide what the pathname of this include file really is.
500eb10989Smrg	 */
510eb10989Smrg	newfile = inc_path(file->i_file, include, type);
520eb10989Smrg	if (newfile == NULL) {
530eb10989Smrg		if (failOK)
540eb10989Smrg		    return;
550eb10989Smrg		if (file != file_red)
560eb10989Smrg			warning("%s (reading %s, line %d): ",
570eb10989Smrg				file_red->i_file, file->i_file, filep->f_line);
580eb10989Smrg		else
590eb10989Smrg			warning("%s, line %d: ", file->i_file, filep->f_line);
600eb10989Smrg		warning1("cannot find include file \"%s\"\n", include);
610eb10989Smrg		show_where_not = TRUE;
620eb10989Smrg		newfile = inc_path(file->i_file, include, type);
630eb10989Smrg		show_where_not = FALSE;
640eb10989Smrg	}
650eb10989Smrg
660eb10989Smrg	if (newfile) {
670eb10989Smrg		included_by(file, newfile);
680eb10989Smrg		if (!(newfile->i_flags & SEARCHED)) {
690eb10989Smrg			newfile->i_flags |= SEARCHED;
700eb10989Smrg			content = getfile(newfile->i_file);
710eb10989Smrg			find_includes(content, newfile, file_red, 0, failOK);
720eb10989Smrg			freefile(content);
730eb10989Smrg		}
740eb10989Smrg	}
750eb10989Smrg}
760eb10989Smrg
770eb10989Smrgstatic void
780eb10989Smrgpr(struct inclist *ip, char *file, char *base)
790eb10989Smrg{
800eb10989Smrg	static char	*lastfile;
810eb10989Smrg	static int	current_len;
820eb10989Smrg	register int	len, i;
830eb10989Smrg	char	buf[ BUFSIZ ];
840eb10989Smrg
850eb10989Smrg	printed = TRUE;
860eb10989Smrg	len = strlen(ip->i_file)+1;
870eb10989Smrg	if (current_len + len > width || file != lastfile) {
880eb10989Smrg		lastfile = file;
890eb10989Smrg		sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
900eb10989Smrg			ip->i_file);
910eb10989Smrg		len = current_len = strlen(buf);
920eb10989Smrg	}
930eb10989Smrg	else {
940eb10989Smrg		buf[0] = ' ';
950eb10989Smrg		strcpy(buf+1, ip->i_file);
960eb10989Smrg		current_len += len;
970eb10989Smrg	}
980eb10989Smrg	fwrite(buf, len, 1, stdout);
990eb10989Smrg
1000eb10989Smrg	/*
1010eb10989Smrg	 * If verbose is set, then print out what this file includes.
1020eb10989Smrg	 */
1030eb10989Smrg	if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
1040eb10989Smrg		return;
1050eb10989Smrg	ip->i_flags |= NOTIFIED;
1060eb10989Smrg	lastfile = NULL;
1070eb10989Smrg	printf("\n# %s includes:", ip->i_file);
1080eb10989Smrg	for (i=0; i<ip->i_listlen; i++)
1090eb10989Smrg		printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
1100eb10989Smrg}
1110eb10989Smrg
1120eb10989Smrgvoid
1130eb10989Smrgrecursive_pr_include(struct inclist *head, char *file, char *base)
1140eb10989Smrg{
1150eb10989Smrg	int	i;
1160eb10989Smrg
1170eb10989Smrg	if (head->i_flags & MARKED)
1180eb10989Smrg		return;
1190eb10989Smrg	head->i_flags |= MARKED;
1200eb10989Smrg	if (head->i_file != file)
1210eb10989Smrg		pr(head, file, base);
1220eb10989Smrg	for (i=0; i<head->i_listlen; i++)
1230eb10989Smrg		recursive_pr_include(head->i_list[ i ], file, base);
1240eb10989Smrg}
125