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