michael@0: /* $Xorg: pr.c,v 1.4 2001/02/09 02:03:16 xorgcvs Exp $ */ michael@0: /* michael@0: michael@0: Copyright (c) 1993, 1994, 1998 The Open Group michael@0: michael@0: Permission to use, copy, modify, distribute, and sell this software and its michael@0: documentation for any purpose is hereby granted without fee, provided that michael@0: the above copyright notice appear in all copies and that both that michael@0: copyright notice and this permission notice appear in supporting michael@0: documentation. michael@0: michael@0: The above copyright notice and this permission notice shall be included in michael@0: all copies or substantial portions of the Software. michael@0: michael@0: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR michael@0: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, michael@0: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE michael@0: OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN michael@0: AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN michael@0: CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. michael@0: michael@0: Except as contained in this notice, the name of The Open Group shall not be michael@0: used in advertising or otherwise to promote the sale, use or other dealings michael@0: in this Software without prior written authorization from The Open Group. michael@0: michael@0: */ michael@0: /* $XFree86: xc/config/makedepend/pr.c,v 1.5 2001/12/14 19:53:21 dawes Exp $ */ michael@0: michael@0: #include "def.h" michael@0: michael@0: extern struct inclist inclist[ MAXFILES ], michael@0: *inclistp; michael@0: extern char *objprefix; michael@0: extern char *objsuffix; michael@0: extern int width; michael@0: extern boolean printed; michael@0: extern boolean verbose; michael@0: extern boolean show_where_not; michael@0: michael@0: void michael@0: add_include(struct filepointer *filep, struct inclist *file, michael@0: struct inclist *file_red, char *include, int type, michael@0: boolean failOK) michael@0: { michael@0: register struct inclist *newfile; michael@0: register struct filepointer *content; michael@0: michael@0: /* michael@0: * First decide what the pathname of this include file really is. michael@0: */ michael@0: newfile = inc_path(file->i_file, include, type); michael@0: if (newfile == NULL) { michael@0: if (failOK) michael@0: return; michael@0: if (file != file_red) michael@0: warning("%s (reading %s, line %d): ", michael@0: file_red->i_file, file->i_file, filep->f_line); michael@0: else michael@0: warning("%s, line %d: ", file->i_file, filep->f_line); michael@0: warning1("cannot find include file \"%s\"\n", include); michael@0: show_where_not = TRUE; michael@0: newfile = inc_path(file->i_file, include, type); michael@0: show_where_not = FALSE; michael@0: } michael@0: michael@0: if (newfile) { michael@0: included_by(file, newfile); michael@0: if (!(newfile->i_flags & SEARCHED)) { michael@0: newfile->i_flags |= SEARCHED; michael@0: content = getfile(newfile->i_file); michael@0: find_includes(content, newfile, file_red, 0, failOK); michael@0: freefile(content); michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: pr(struct inclist *ip, char *file, char *base) michael@0: { michael@0: static char *lastfile; michael@0: static int current_len; michael@0: register int len, i; michael@0: char buf[ BUFSIZ ]; michael@0: michael@0: printed = TRUE; michael@0: len = strlen(ip->i_file)+1; michael@0: if (current_len + len > width || file != lastfile) { michael@0: lastfile = file; michael@0: sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix, michael@0: ip->i_file); michael@0: len = current_len = strlen(buf); michael@0: } michael@0: else { michael@0: buf[0] = ' '; michael@0: strcpy(buf+1, ip->i_file); michael@0: current_len += len; michael@0: } michael@0: fwrite(buf, len, 1, stdout); michael@0: michael@0: /* michael@0: * If verbose is set, then print out what this file includes. michael@0: */ michael@0: if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED) michael@0: return; michael@0: ip->i_flags |= NOTIFIED; michael@0: lastfile = NULL; michael@0: printf("\n# %s includes:", ip->i_file); michael@0: for (i=0; ii_listlen; i++) michael@0: printf("\n#\t%s", ip->i_list[ i ]->i_incstring); michael@0: } michael@0: michael@0: void michael@0: recursive_pr_include(struct inclist *head, char *file, char *base) michael@0: { michael@0: int i; michael@0: michael@0: if (head->i_flags & MARKED) michael@0: return; michael@0: head->i_flags |= MARKED; michael@0: if (head->i_file != file) michael@0: pr(head, file, base); michael@0: for (i=0; ii_listlen; i++) michael@0: recursive_pr_include(head->i_list[ i ], file, base); michael@0: }