pr.c revision d43532a6
1/* 2 3Copyright (c) 1993, 1994, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25*/ 26 27#include "def.h" 28 29void 30add_include(struct filepointer *filep, struct inclist *file, 31 struct inclist *file_red, const char *include, int type, 32 boolean failOK) 33{ 34 register struct inclist *newfile; 35 register struct filepointer *content; 36 37 /* 38 * First decide what the pathname of this include file really is. 39 */ 40 newfile = inc_path(file->i_file, include, type); 41 if (newfile == NULL) { 42 if (failOK) 43 return; 44 if (file != file_red) 45 warning("%s (reading %s, line %ld): ", 46 file_red->i_file, file->i_file, filep->f_line); 47 else 48 warning("%s, line %ld: ", file->i_file, filep->f_line); 49 warning1("cannot find include file \"%s\"\n", include); 50 show_where_not = TRUE; 51 newfile = inc_path(file->i_file, include, type); 52 show_where_not = FALSE; 53 } 54 55 if (newfile) { 56 included_by(file, newfile); 57 if (!(newfile->i_flags & SEARCHED)) { 58 newfile->i_flags |= SEARCHED; 59 content = getfile(newfile->i_file); 60 find_includes(content, newfile, file_red, 0, failOK); 61 freefile(content); 62 } 63 } 64} 65 66static void 67pr(struct inclist *ip, const char *file, const char *base) 68{ 69 static const char *lastfile; 70 static int current_len; 71 register int len, i; 72 char buf[ BUFSIZ ]; 73 74 printed = TRUE; 75 len = strlen(ip->i_file)+1; 76 if (current_len + len > width || file != lastfile) { 77 lastfile = file; 78 sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix, 79 ip->i_file); 80 len = current_len = strlen(buf); 81 } 82 else { 83 buf[0] = ' '; 84 strcpy(buf+1, ip->i_file); 85 current_len += len; 86 } 87 fwrite(buf, len, 1, stdout); 88 89 /* 90 * If verbose is set, then print out what this file includes. 91 */ 92 if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED) 93 return; 94 ip->i_flags |= NOTIFIED; 95 lastfile = NULL; 96 printf("\n# %s includes:", ip->i_file); 97 for (i=0; i<ip->i_listlen; i++) 98 printf("\n#\t%s", ip->i_list[ i ]->i_incstring); 99} 100 101void 102recursive_pr_include(struct inclist *head, const char *file, const char *base) 103{ 104 int i; 105 106 if (head->i_flags & MARKED) 107 return; 108 head->i_flags |= MARKED; 109 if (head->i_file != file) 110 pr(head, file, base); 111 for (i=0; i<head->i_listlen; i++) 112 recursive_pr_include(head->i_list[ i ], file, base); 113} 114