pr.c

Go to the documentation of this file.
00001 /* $XConsortium: pr.c /main/20 1996/12/04 10:11:41 swick $ */
00002 /*
00003 
00004 Copyright (c) 1993, 1994  X Consortium
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of the X Consortium shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from the X Consortium.
00026 
00027 */
00028 
00029 #include "def.h"
00030 
00031 extern struct inclist inclist[ MAXFILES ],
00032             *inclistp;
00033 extern char *objprefix;
00034 extern char *objsuffix;
00035 extern int width;
00036 extern boolean printed;
00037 extern boolean verbose;
00038 extern boolean show_where_not;
00039 
00040 extern void included_by(struct inclist *ip, struct inclist *newfile);
00041 extern int find_includes(struct filepointer *filep, struct inclist *file,
00042                             struct inclist *file_red, int recursion,
00043                             boolean failOK);
00044 extern void freefile(struct filepointer *fp);
00045 
00046 extern void ROOT_adddep(char* buf, size_t len);
00047 extern void ROOT_newFile();
00048 
00049 void
00050 add_include(filep, file, file_red, include, dot, failOK)
00051 struct filepointer *filep;
00052 struct inclist *file, *file_red;
00053 char *include;
00054 boolean dot, failOK;
00055 {
00056    register struct inclist *newfile;
00057    register struct filepointer *content;
00058 
00059    /*
00060     * First decide what the pathname of this include file really is.
00061     */
00062    newfile = inc_path(file->i_file, include, dot);
00063    if (newfile == NULL) {
00064       if (failOK)
00065          return;
00066       if (file != file_red)
00067          warning("%s (reading %s, line %d): ",
00068                  file_red->i_file, file->i_file, filep->f_line);
00069       else
00070          warning("%s, line %d: ", file->i_file, filep->f_line);
00071       warning1("cannot find include file \"%s\"\n", include);
00072       show_where_not = TRUE;
00073       newfile = inc_path(file->i_file, include, dot);
00074       show_where_not = FALSE;
00075    }
00076 
00077    if (newfile) {
00078       included_by(file, newfile);
00079       if (!(newfile->i_flags & SEARCHED)) {
00080          newfile->i_flags |= SEARCHED;
00081          content = getfile(newfile->i_file);
00082          find_includes(content, newfile, file_red, 0, failOK);
00083          freefile(content);
00084       }
00085    }
00086 }
00087 
00088 void
00089 pr(ip, file, base, dep)
00090 register struct inclist  *ip;
00091 char *file, *base, *dep;
00092 {
00093    static char *lastfile;
00094    static int current_len;
00095    register int len, i;
00096    char buf[ BUFSIZ ];
00097    char    *ipifile;
00098 
00099    printed = TRUE;
00100    len = strlen(ip->i_file) + 1;
00101    ipifile = 0;
00102    if (len > 2 && ip->i_file[1] == ':') {
00103       if (getenv("OSTYPE") && !strcmp(getenv("OSTYPE"), "msys")) {
00104          /* windows path */
00105          ipifile = malloc(len);
00106          strcpy(ipifile, ip->i_file);
00107          ipifile[1] = ipifile[0];
00108          ipifile[0] = '/';
00109       } else {
00110          /* generic cygwin */
00111          ipifile = malloc(len + 11);
00112          strcpy(ipifile, "/cygdrive/");
00113          ipifile[10] = ip->i_file[0];
00114          strcpy(ipifile + 11, ip->i_file + 2);
00115          len += 9;
00116       }
00117    } else ipifile = ip->i_file;
00118 
00119    if (current_len + len > width || file != lastfile) {
00120       lastfile = file;
00121       if (rootBuild)
00122          ROOT_newFile();
00123       if (dep == 0) {
00124          sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
00125                  ipifile);
00126       } else {
00127          sprintf(buf, "\n%s: %s", dep,
00128                  ipifile);
00129       }
00130       len = current_len = strlen(buf);
00131    } else {
00132       buf[0] = ' ';
00133       strcpy(buf + 1, ipifile);
00134       current_len += len;
00135    }
00136    if (len > 2 && ip->i_file[1] == ':')
00137       free(ipifile);
00138 
00139    if (rootBuild)
00140       ROOT_adddep(buf, len);
00141    else
00142       if (fwrite(buf, len, 1, stdout) != 1)
00143          fprintf(stderr, "pr: fwrite error\n");
00144 
00145    /*
00146     * If verbose is set, then print out what this file includes.
00147     */
00148    if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
00149       return;
00150    ip->i_flags |= NOTIFIED;
00151    lastfile = NULL;
00152    printf("\n# %s includes:", ip->i_file);
00153    for (i = 0; i < ip->i_listlen; i++)
00154       printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
00155 }
00156 
00157 void
00158 recursive_pr_include(head, file, base, dep)
00159 register struct inclist *head;
00160 register char *file, *base;
00161 register char  *dep;
00162 {
00163    register int i;
00164 
00165    if (head->i_flags & MARKED)
00166       return;
00167    head->i_flags |= MARKED;
00168    if (head->i_file != file)
00169       pr(head, file, base, dep);
00170    for (i = 0; i < head->i_listlen; i++)
00171       recursive_pr_include(head->i_list[ i ], file, base, dep);
00172 }

Generated on Tue Jul 5 14:10:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1