Blame | Last modification | View Log | RSS feed
/* $XConsortium: pr.c /main/18 1995/12/08 18:26:47 gildea $ *//*Copyright (c) 1993, 1994 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.$Source: /cvsroot/device/DEVL/UTILS/MKDEPEND/pr.c,v $$Revision: 1.4 $ $Date: 2004/11/03 05:09:12 $ $State: Exp $$Author: ayoung $ $Locker: $*/#include "def.h"extern struct inclist inclist[ MAXFILES ],*inclistp;extern char **systemdirs;extern char *objprefixs[ MAXPREFIXS ];extern char *objsuffix;extern int width;extern boolean printed;extern boolean verbose;extern boolean opt_basename;extern int embeddedwhite;extern boolean show_where_not;voidadd_include(filep, file, file_red, include, dot, failOK)struct filepointer *filep;struct inclist *file, *file_red;char *include;boolean dot;{register struct inclist *newfile;register struct filepointer *content;/** First decide what the pathname of this include file really is.*/#ifdef MSDOS{char *p = include;do {if ((p = strchr(p, '\\')) != NULL)*p = '/';} while (p && *p);}#endifnewfile = inc_path(file->i_file, include, dot);if (newfile == NULL) {if (failOK)return;if (file != file_red)warning("%s (reading %s, line %d): ",file_red->i_file, file->i_file, filep->f_line);elsewarning("%s, line %d: ", file->i_file, filep->f_line);warning1("cannot find include file \"%s\"\n", include);show_where_not = TRUE;newfile = inc_path(file->i_file, include, dot);show_where_not = FALSE;if (mflags & MFLAG_GENERATED) {warning1("assumed as generated \"%s\"\n", include);newfile = newinclude(include, include);newfile->i_flags |= SEARCHED;}}if (newfile) {included_by(file, newfile);if (!(newfile->i_flags & SEARCHED)) {newfile->i_flags |= SEARCHED;content = getfile(newfile->i_file);find_includes(content, newfile, file_red, 0, failOK);freefile(content);}}}voidrecursive_pr_include(head, file, base)register struct inclist *head;register char *file, *base;{register int i;if (head->i_flags & MARKED)return;head->i_flags |= MARKED;if (head->i_file != file)pr(head, file, base);for (i=0; i<head->i_listlen; i++)recursive_pr_include(head->i_list[ i ], file, base);}static intpr_space( const char *str, char *buf ){int len = 0;if (embeddedwhite == BS_ESCAPE) {const char *c; /* escape spaces */char *b = buf;for (c = str; *c; *c++) {if (*c == ' ')*b++ = '\\', len++;*b++ = *c;}*b = '\0';} else if (embeddedwhite == BS_QUOTE) {sprintf(buf, "\"%s\"", str);len = 2;} else if (embeddedwhite == BS_URL) {const char *c;char *b = buf;for (c = str; *c; *c++) {if ( *c >= 127 ||strchr( "$&+,;=?@ \"<>{}|^~[]`", *c ) ){ /* convert */*b++ = '%';(void) sprintf( b, "%-2.2X", *c );b += 2;len += 2;} else { /* quote */*b++ = *c;}}*b = '\0';} else { /* unknown/ignore */static int spacewarning;if (embeddedwhite == BS_UNKNOWN && !spacewarning) {warning1( "embedded spaces encountered within paths, specify -W option\n");spacewarning++;}strcpy(buf, str);}return (len);}static intpr_object(const char *prefix, const char *file){static char buf[ MAX_PATH*3 ], sbuf[ MAX_PATH*3 ];int len = 0;sprintf(buf, "\n%s%s%s:", prefix?prefix:"", file, objsuffix);len = strlen( buf );if (strchr(buf, ' ') || embeddedwhite == BS_URL) {if (embeddedwhite == BS_JUNK)return -1; /* junk */len += pr_space( (const char *)buf, sbuf );fwrite(sbuf, len, 1, stdout);} else {fwrite(buf, len, 1, stdout);}return len;}voidpr(ip, file, base)register struct inclist *ip;char *file, *base;{static char *lastfile;static int current_len;static char buf[ MAX_PATH*3 ];const char *t_base;register int len, plen, i;boolean spaces;/** mask system directories*/if (mflags & MFLAG_NOSYSTEM) {char **pp;for (pp = systemdirs; *pp; pp++) {if (strncmp(*pp, ip->i_file, strlen(*pp)) == 0)return;(void) strcpy(buf, *pp);remove_dotdot(buf);if (strncmp(buf, ip->i_file, strlen(buf)) == 0)return;}}/** dump file*/printed = TRUE;len = strlen(ip->i_file)+1;spaces = strchr(ip->i_file, ' ') ? TRUE : FALSE;if (spaces && embeddedwhite == BS_JUNK)return; /* junk */buf[0] = ' ';if (spaces || embeddedwhite == BS_URL) {len += pr_space( ip->i_file, buf+1 );} else {strcpy( buf+1, ip->i_file );}if (opt_basename &&((t_base = strrchr(base, '/')) != NULL||(t_base = strrchr(base, '\\')) != NULL))t_base++;else t_base = base;if (objprefixs[1]) {/** Multiple objprefix's.*/for (i = 0; i < MAXPREFIXS && objprefixs[i]; i++) {if ((plen = pr_object( objprefixs[i], t_base )) == -1)return; /*junk*/if (plen >= 41) {fputs("\t", stdout);} else {while (plen < 41) {fputs("\t", stdout);plen = ((plen-1) >> 3 << 3) + 9;}}fwrite(buf+1, len-1, 1, stdout);}} else {/** None or one, objprefix's.*/if (current_len + len > width || file != lastfile) {/** Line length exceeded or new file.*/if ((plen = pr_object( objprefixs[0], t_base )) == -1)return; /*junk*/current_len = plen;}fwrite(buf, len, 1, stdout);current_len += len;lastfile = file;}/** If verbose is set, then print out what this file includes.*/if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)return;ip->i_flags |= NOTIFIED;lastfile = NULL;printf("\n# %s includes:", ip->i_file);for (i=0; i<ip->i_listlen; i++)printf("\n#\t%s", ip->i_list[ i ]->i_incstring);}