Adam Tkac | fded078 | 2008-03-22 11:20:54 +0000 | [diff] [blame] | 1 | /* $XConsortium: pr.c,v 1.17 94/04/17 20:10:38 gildea Exp $ */ |
| 2 | /* |
| 3 | |
| 4 | Copyright (c) 1993, 1994 X Consortium |
| 5 | |
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | of this software and associated documentation files (the "Software"), to deal |
| 8 | in the Software without restriction, including without limitation the rights |
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | copies of the Software, and to permit persons to whom the Software is |
| 11 | furnished to do so, subject to the following conditions: |
| 12 | |
| 13 | The above copyright notice and this permission notice shall be included in |
| 14 | all copies or substantial portions of the Software. |
| 15 | |
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 20 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | |
| 23 | Except as contained in this notice, the name of the X Consortium shall not be |
| 24 | used in advertising or otherwise to promote the sale, use or other dealings |
| 25 | in this Software without prior written authorization from the X Consortium. |
| 26 | |
| 27 | */ |
| 28 | |
| 29 | #include "def.h" |
| 30 | |
| 31 | extern struct inclist inclist[ MAXFILES ], |
| 32 | *inclistp; |
| 33 | extern char *objprefix; |
| 34 | extern char *objsuffix; |
| 35 | extern int width; |
| 36 | extern boolean printed; |
| 37 | extern boolean verbose; |
| 38 | extern boolean show_where_not; |
| 39 | |
| 40 | add_include(filep, file, file_red, include, dot, failOK) |
| 41 | struct filepointer *filep; |
| 42 | struct inclist *file, *file_red; |
| 43 | char *include; |
| 44 | boolean dot; |
| 45 | { |
| 46 | register struct inclist *newfile; |
| 47 | register struct filepointer *content; |
| 48 | |
| 49 | /* |
| 50 | * First decide what the pathname of this include file really is. |
| 51 | */ |
| 52 | newfile = inc_path(file->i_file, include, dot); |
| 53 | if (newfile == NULL) { |
| 54 | if (failOK) |
| 55 | return; |
| 56 | if (file != file_red) |
| 57 | warning("%s (reading %s, line %d): ", |
| 58 | file_red->i_file, file->i_file, filep->f_line); |
| 59 | else |
| 60 | warning("%s, line %d: ", file->i_file, filep->f_line); |
| 61 | warning1("cannot find include file \"%s\"\n", include); |
| 62 | show_where_not = TRUE; |
| 63 | newfile = inc_path(file->i_file, include, dot); |
| 64 | show_where_not = FALSE; |
| 65 | } |
| 66 | |
| 67 | if (newfile) { |
| 68 | included_by(file, newfile); |
| 69 | if (!newfile->i_searched) { |
| 70 | newfile->i_searched = TRUE; |
| 71 | content = getfile(newfile->i_file); |
| 72 | find_includes(content, newfile, file_red, 0, failOK); |
| 73 | freefile(content); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | recursive_pr_include(head, file, base) |
| 79 | register struct inclist *head; |
| 80 | register char *file, *base; |
| 81 | { |
| 82 | register int i; |
| 83 | |
| 84 | if (head->i_marked) |
| 85 | return; |
| 86 | head->i_marked = TRUE; |
| 87 | if (head->i_file != file) |
| 88 | pr(head, file, base); |
| 89 | for (i=0; i<head->i_listlen; i++) |
| 90 | recursive_pr_include(head->i_list[ i ], file, base); |
| 91 | } |
| 92 | |
| 93 | pr(ip, file, base) |
| 94 | register struct inclist *ip; |
| 95 | char *file, *base; |
| 96 | { |
| 97 | static char *lastfile; |
| 98 | register int len, i; |
| 99 | char buf[ BUFSIZ ]; |
| 100 | #ifdef WIN32 |
| 101 | char *transfile = TranslateFileNameD2U(ip->i_file,0); |
| 102 | #else |
| 103 | char *transfile = ip->i_file; |
| 104 | #endif |
| 105 | |
| 106 | printed = TRUE; |
| 107 | if (file != lastfile) { |
| 108 | lastfile = file; |
| 109 | sprintf(buf, "%s%s%s %s.d: %s", objprefix, base, objsuffix, |
| 110 | base, transfile); |
| 111 | } |
| 112 | else { |
| 113 | sprintf(buf, " \\\n %s", transfile); |
| 114 | } |
| 115 | fwrite(buf, strlen(buf), 1, stdout); |
| 116 | |
| 117 | /* |
| 118 | * If verbose is set, then print out what this file includes. |
| 119 | */ |
| 120 | if (! verbose || ip->i_list == NULL || ip->i_notified) |
| 121 | return; |
| 122 | ip->i_notified = TRUE; |
| 123 | lastfile = NULL; |
| 124 | printf("\n# %s includes:", transfile); |
| 125 | for (i=0; i<ip->i_listlen; i++) |
| 126 | printf("\n#\t%s", ip->i_list[ i ]->i_incstring); |
| 127 | #ifdef WIN32 |
| 128 | free(transfile); |
| 129 | #endif |
| 130 | } |