pr.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (c) 1993, 1994  X Consortium
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00018 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00019 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00020 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00021 
00022 Except as contained in this notice, the name of the X Consortium shall not be
00023 used in advertising or otherwise to promote the sale, use or other dealings
00024 in this Software without prior written authorization from the X Consortium.
00025 
00026 */
00027 
00028 #ifdef __WIN32__
00029   #pragma warning(disable : 4996)
00030 #endif
00031 
00032 #include "def.h"
00033 
00034 #include <string.h>
00035 
00036 extern struct  inclist  inc_list[ MAXFILES ], *inclistp;
00037 extern char  *objprefix;
00038 extern char  *objsuffix;
00039 extern int  width;
00040 extern bool  printed;
00041 extern bool  verbose;
00042 extern bool  show_where_not;
00043 
00044 void add_include(filepointer *filep, inclist  *file,
00045     inclist  *file_red, char  *include, bool dot, bool failOK)
00046 {
00047   register struct inclist  *newfile;
00048   register struct filepointer  *content;
00049 
00050   /*
00051    * First decide what the pathname of this include file really is.
00052    */
00053   newfile = inc_path(file->i_file, include, dot, failOK);
00054   if (newfile == NULL) {
00055     if (failOK)
00056         return;
00057     if (file != file_red)
00058       warning("%s (reading %s, line %d): ",
00059         file_red->i_file, file->i_file, filep->f_line);
00060     else
00061       warning("%s, line %d: ", file->i_file, filep->f_line);
00062     warning1("cannot find include file \"%s\"\n", include);
00063 fatalerr("cannot find include file \"%s\"\n", include);
00064     show_where_not = true;
00065     newfile = inc_path(file->i_file, include, dot, failOK);
00066     show_where_not = false;
00067   }
00068 
00069   if (newfile) {
00070     included_by(file, newfile);
00071     if (!newfile->i_searched) {
00072       newfile->i_searched = true;
00073       content = getfile(newfile->i_file);
00074       find_includes(content, newfile, file_red, 0, failOK);
00075       freefile(content);
00076     }
00077   }
00078 }
00079 
00080 void recursive_pr_include(register struct inclist  *head, register char  *file,
00081     register char  *base)
00082 {
00083   register int  i;
00084 
00085   if (head->i_marked)
00086     return;
00087   head->i_marked = true;
00088   if (head->i_file != file) {
00089     bool rc_file = false;
00090     if ((strlen(file) >= 3) && !strcmp(file + strlen(file) - 3, ".rc"))
00091       rc_file = true;
00092     pr(head, file, base, rc_file);
00093   }
00094   for (i=0; i<head->i_listlen; i++)
00095     recursive_pr_include(head->i_list[ i ], file, base);
00096 }
00097 
00098 void pr(register struct inclist *ip, char *file, char *base, bool rc_file)
00099 {
00100   static char  *lastfile;
00101   static int  current_len;
00102   register int  len, i;
00103   char  buf[ BUFSIZ ];
00104 
00105   printed = true;
00106   len = int(strlen(ip->i_file)+1);
00107   if (current_len + len > width || file != lastfile) {
00108     lastfile = file;
00109     char *temp_suff = objsuffix;
00110     if (rc_file) temp_suff = (char *)".res";
00111     sprintf(buf, "\n%s%s%s: %s ", objprefix, base, temp_suff, ip->i_file);
00112     len = current_len = int(strlen(buf));
00113   }
00114   else {
00115     strcpy(buf, ip->i_file);
00116 //printf("ip->file=%s\n", ip->i_file);
00117     char tmp[2] = { ' ', '\0' };
00118 //printf("tmp=%s\n", tmp);
00119     strcat(buf, tmp);
00120 //printf("buf=%s\n", buf);
00121     current_len += len;
00122   }
00123   fwrite(buf, len, 1, stdout);
00124 
00125   // If verbose is set, then print out what this file includes.
00126   if (! verbose || ip->i_list == NULL || ip->i_notified)
00127     return;
00128   ip->i_notified = true;
00129   lastfile = NULL;
00130   printf("\n# %s includes:", ip->i_file);
00131   for (i=0; i<ip->i_listlen; i++)
00132     printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
00133 }
00134 

Generated on Fri Nov 28 04:28:50 2008 for HOOPLE Libraries by  doxygen 1.5.1