Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / soltools / mkdepend / pr.c
blobfe8d756a636cff78c63de1f5527d5df2ba32e255
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* $XConsortium: pr.c,v 1.17 94/04/17 20:10:38 gildea Exp $ */
3 /*
5 Copyright (c) 1993, 1994 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
30 #include "def.h"
31 #include <string.h>
32 size_t pr( struct inclist *ip, char *file,char *base);
34 extern struct inclist inclist[ MAXFILES ];
35 extern int width;
37 void add_include(struct filepointer *filep, struct inclist *file, struct inclist *file_red, char *include, boolean dot, boolean failOK, struct IncludesCollection* incCollection, struct symhash *symbols)
39 struct inclist *newfile;
40 struct filepointer *content;
43 * First decide what the pathname of this include file really is.
45 newfile = inc_path(file->i_file, include, dot, incCollection);
46 if (newfile == NULL) {
47 if (failOK)
48 return;
49 if (file != file_red)
50 warning("%s (reading %s, line %d): ",
51 file_red->i_file, file->i_file, filep->f_line);
52 else
53 warning("%s, line %d: ", file->i_file, filep->f_line);
54 warning1("cannot find include file \"%s\"\n", include);
55 show_where_not = TRUE;
56 newfile = inc_path(file->i_file, include, dot, incCollection);
57 show_where_not = FALSE;
60 if (newfile) {
62 /* Only add new dependency files if they don't have "/usr/include" in them. */
63 if (!(newfile && newfile->i_file && strstr(newfile->i_file, "/usr/"))) {
64 included_by(file, newfile);
67 if (!newfile->i_searched) {
68 newfile->i_searched = TRUE;
69 content = getfile(newfile->i_file);
70 find_includes(content, newfile, file_red, 0, failOK, incCollection, symbols);
71 freefile(content);
76 void pr_dummy(struct inclist *ip)
78 fwrite(ip->i_file, strlen(ip->i_file), 1, stdout);
79 fwrite(" :\n\n", 4, 1, stdout);
82 void recursive_pr_dummy(struct inclist *head, char *file)
84 int i;
86 if (head->i_marked == 2)
87 return;
88 head->i_marked = 2; // it's a large boolean...
89 if (head->i_file != file)
90 pr_dummy(head);
91 for (i=0; i<head->i_listlen; i++)
92 recursive_pr_dummy(head->i_list[ i ], file);
96 void recursive_pr_include(struct inclist *head, char *file, char *base)
98 int i;
100 if (head->i_marked)
101 return;
102 head->i_marked = TRUE;
103 if (head->i_file != file)
104 pr(head, file, base);
105 for (i=0; i<head->i_listlen; i++)
106 recursive_pr_include(head->i_list[ i ], file, base);
109 size_t pr(struct inclist *ip, char *file, char *base)
111 size_t ret;
112 static char *lastfile;
113 static int current_len;
114 int len, i;
115 char buf[ BUFSIZ ];
117 printed = TRUE;
118 len = (int)strlen(ip->i_file)+4;
119 if (file != lastfile) {
120 lastfile = file;
121 sprintf(buf, "\n%s%s%s: \\\n %s", objprefix, base, objsuffix,
122 ip->i_file);
123 len = current_len = (int)strlen(buf);
125 else {
126 buf[0] = ' ';
127 buf[1] = '\\';
128 buf[2] = '\n';
129 buf[3] = ' ';
130 strcpy(buf+4, ip->i_file);
131 current_len += len;
133 ret = fwrite(buf, len, 1, stdout);
136 * If verbose is set, then print out what this file includes.
138 if (! verbose || ip->i_list == NULL || ip->i_notified)
139 return ret;
140 ip->i_notified = TRUE;
141 lastfile = NULL;
142 printf("\n# %s includes:", ip->i_file);
143 for (i=0; i<ip->i_listlen; i++)
144 printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
145 return ret;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */