pr.c revision 63165362
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 29extern struct inclist inclist[ MAXFILES ], 30 *inclistp; 31extern char *objprefix; 32extern char *objsuffix; 33extern int width; 34extern boolean printed; 35extern boolean verbose; 36extern boolean show_where_not; 37 38void 39add_include(struct filepointer *filep, struct inclist *file, 40 struct inclist *file_red, const char *include, int type, 41 boolean failOK) 42{ 43 register struct inclist *newfile; 44 register struct filepointer *content; 45 46 /* 47 * First decide what the pathname of this include file really is. 48 */ 49 newfile = inc_path(file->i_file, include, type); 50 if (newfile == NULL) { 51 if (failOK) 52 return; 53 if (file != file_red) 54 warning("%s (reading %s, line %ld): ", 55 file_red->i_file, file->i_file, filep->f_line); 56 else 57 warning("%s, line %ld: ", file->i_file, filep->f_line); 58 warning1("cannot find include file \"%s\"\n", include); 59 show_where_not = TRUE; 60 newfile = inc_path(file->i_file, include, type); 61 show_where_not = FALSE; 62 } 63 64 if (newfile) { 65 included_by(file, newfile); 66 if (!(newfile->i_flags & SEARCHED)) { 67 newfile->i_flags |= SEARCHED; 68 content = getfile(newfile->i_file); 69 find_includes(content, newfile, file_red, 0, failOK); 70 freefile(content); 71 } 72 } 73} 74 75static void 76pr(struct inclist *ip, const char *file, const char *base) 77{ 78 static const char *lastfile; 79 static int current_len; 80 register int len, i; 81 char buf[ BUFSIZ ]; 82 83 printed = TRUE; 84 len = strlen(ip->i_file)+1; 85 if (current_len + len > width || file != lastfile) { 86 lastfile = file; 87 sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix, 88 ip->i_file); 89 len = current_len = strlen(buf); 90 } 91 else { 92 buf[0] = ' '; 93 strcpy(buf+1, ip->i_file); 94 current_len += len; 95 } 96 fwrite(buf, len, 1, stdout); 97 98 /* 99 * If verbose is set, then print out what this file includes. 100 */ 101 if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED) 102 return; 103 ip->i_flags |= NOTIFIED; 104 lastfile = NULL; 105 printf("\n# %s includes:", ip->i_file); 106 for (i=0; i<ip->i_listlen; i++) 107 printf("\n#\t%s", ip->i_list[ i ]->i_incstring); 108} 109 110void 111recursive_pr_include(struct inclist *head, const char *file, const char *base) 112{ 113 int i; 114 115 if (head->i_flags & MARKED) 116 return; 117 head->i_flags |= MARKED; 118 if (head->i_file != file) 119 pr(head, file, base); 120 for (i=0; i<head->i_listlen; i++) 121 recursive_pr_include(head->i_list[ i ], file, base); 122} 123