Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / dmake / dmdump.c
blob631359758a05cf7230a1e38b98961e41e8c6939f
1 /* RCS $Id: dmdump.c,v 1.4 2007-06-12 06:05:11 obo Exp $
2 --
3 -- SYNOPSIS
4 -- Dump the internal dag to stdout.
5 --
6 -- DESCRIPTION
7 -- This file contains the routine that is called to dump a version of
8 -- the digested makefile to the standard output. May be useful perhaps
9 -- to the ordinary user, and invaluable for debugging make.
11 -- AUTHOR
12 -- Dennis Vadura, dvadura@dmake.wticorp.com
14 -- WWW
15 -- http://dmake.wticorp.com/
17 -- COPYRIGHT
18 -- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
20 -- This program is NOT free software; you can redistribute it and/or
21 -- modify it under the terms of the Software License Agreement Provided
22 -- in the file <distribution-root>/readme/license.txt.
24 -- LOG
25 -- Use cvs log to obtain detailed change logs.
28 #include "extern.h"
30 #define M_TEST (M_PRECIOUS | M_VAR_MASK)
32 static void dump_name ANSI((CELLPTR, int, int));
33 static void dump_normal_target ANSI((CELLPTR, CELLPTR, int));
34 static void dump_prerequisites ANSI((LINKPTR, CELLPTR, int, int, int));
35 static void dump_conditionals ANSI((CELLPTR,STRINGPTR,int,int));
36 static void dump_macro ANSI((HASHPTR, int));
39 PUBLIC void
40 Dump()/*
41 ======== Dump onto standard output the digested makefile. Note that
42 the form of the dump is not representative of the contents
43 of the original makefile contents at all */
45 HASHPTR hp;
46 int i;
48 DB_ENTER( "Dump" );
50 puts( "# Dump of dmake macro variables:" );
51 for( i=0; i<HASH_TABLE_SIZE; i++)
52 for( hp=Macs[i]; hp != NIL(HASH); hp = hp->ht_next ) {
53 int flag = hp->ht_flag;
54 dump_macro(hp, flag);
57 puts( "\n#====================================" );
58 puts( "# Dump of targets:\n" );
60 for( i=0; i<HASH_TABLE_SIZE; i++ )
61 for( hp = Defs[i]; hp != NIL(HASH); hp = hp->ht_next )
62 if( !(hp->CP_OWNR->ce_flag & F_PERCENT) ) {
63 if( hp->CP_OWNR == Root )
64 puts( "# ******* ROOT TARGET ********" );
65 if (Targets->ce_prq && hp->CP_OWNR == Targets->ce_prq->cl_prq)
66 puts( "# ******* FIRST USER DEFINED TARGET ******" );
67 dump_normal_target( hp->CP_OWNR,NIL(CELL),hp->CP_OWNR->ce_flag);
70 puts( "\n#====================================" );
71 puts( "# Dump of inference graph\n" );
73 for( i=0; i<HASH_TABLE_SIZE; i++ )
74 for( hp = Defs[i]; hp != NIL(HASH); hp = hp->ht_next )
75 if( (hp->CP_OWNR->ce_flag & F_PERCENT) &&
76 !(hp->CP_OWNR->ce_flag & F_MAGIC) )
77 dump_normal_target(hp->CP_OWNR,NIL(CELL),hp->CP_OWNR->ce_flag);
79 DB_VOID_RETURN;
84 PUBLIC void
85 Dump_recipe( sp )/*
86 ===================
87 Given a string pointer print the recipe line out */
88 STRINGPTR sp;
90 char *st;
91 char *nl;
93 if( sp == NIL(STRING) ) return;
95 putchar( '\t' );
96 if( sp->st_attr & A_SILENT ) putchar( '@' );
97 if( sp->st_attr & A_IGNORE ) putchar( '-' );
98 if( sp->st_attr & A_SHELL ) putchar( '+' );
99 if( sp->st_attr & A_SWAP ) putchar( '%' );
101 st = sp->st_string;
102 for( nl=strchr(st,'\n'); nl != NIL( char); nl=strchr(st,'\n') ) {
103 *nl = '\0';
104 printf( "%s\\\n", st );
105 *nl = '\n';
106 st = nl+1;
108 printf( "%s\n", st );
112 static char *_attrs[] = { ".PRECIOUS", ".SILENT", ".LIBRARY",
113 ".EPILOG", ".PROLOG", ".IGNORE", ".SYMBOL", ".NOINFER",
114 ".UPDATEALL", ".SEQUENTIAL", ".SETDIR=", ".USESHELL",
115 #if defined(MSDOS)
116 ".SWAP",
117 #else
118 # if defined(__CYGWIN__)
119 ".WINPATH",
120 # else
121 "- unused -",
122 # endif
123 #endif
124 ".MKSARGS",
125 ".PHONY", ".NOSTATE", ".IGNOREGROUP", ".EXECUTE", ".ERRREMOVE" };
127 static void
128 dump_normal_target( cp, namecp, flag )/*
129 ========================================
130 Dump in makefile like format the dag information */
131 CELLPTR cp;
132 CELLPTR namecp;
133 int flag;
135 register STRINGPTR sp;
136 t_attr attr;
137 unsigned int k;
139 DB_ENTER( "dump_normal_target" );
141 if(!(cp->ce_flag & F_TARGET) && !cp->ce_attr && !cp->ce_prq) {
142 DB_VOID_RETURN;
145 if(cp->ce_set && cp->ce_set != cp) {
146 DB_VOID_RETURN;
149 if( cp->ce_flag & F_MULTI ) {
150 /* recursively print multi or %-targets. */
151 int tflag = cp->ce_prq->cl_prq->ce_flag;
152 if( !(cp->ce_flag & F_PERCENT) ) tflag |= F_MULTI;
153 dump_conditionals(cp, cp->ce_cond, TRUE, TRUE);
154 putchar('\n');
156 #ifdef DBUG
157 /* Output also master targtet. (Only in debug builds) */
158 printf("Master name(s) (DBUG build): ");
159 dump_name(cp, FALSE, TRUE );
160 putchar('\n');
161 #endif
163 /* %-targets set namecp (3rd parameter) to NULL so that the next
164 * recursive dump_normal_target() prints the name of cp->ce_prq->cl_prq
165 * instead of cp. This should be the same unless CeMeToo(cp) points
166 * to a cell that is the head of an .UPDATEALL list. */
167 dump_prerequisites(cp->ce_prq,(cp->ce_flag&F_PERCENT)?NIL(CELL):cp,
168 FALSE, TRUE, tflag);
170 else {
171 dump_name(namecp?namecp:cp, FALSE, TRUE );
173 for( k=0, attr=1; attr <= MAX_ATTR; attr <<= 1, k++ )
174 if( cp->ce_attr & attr ) {
175 printf( "%s%s ", _attrs[k],
176 (attr != A_SETDIR) ? "" : (cp->ce_dir?cp->ce_dir:"") );
179 putchar( ':' );
181 if( flag & F_MULTI ) putchar( ':' );
182 if( flag & F_SINGLE ) putchar( '!' );
183 putchar( ' ' );
185 dump_prerequisites( cp->ce_prq, NIL(CELL), FALSE, FALSE, F_DEFAULT);
186 dump_prerequisites( cp->ce_indprq, NIL(CELL),TRUE, FALSE, F_DEFAULT);
188 putchar( '\n' );
189 if( cp->ce_flag & F_GROUP ) puts( "[" );
190 for( sp = cp->ce_recipe; sp != NIL(STRING); sp = sp->st_next )
191 Dump_recipe( sp );
192 if( cp->ce_flag & F_GROUP ) {
193 puts( "]" );
194 putchar( '\n' );
196 dump_conditionals(cp, cp->ce_cond, flag&F_MULTI, FALSE);
197 putchar('\n');
200 DB_VOID_RETURN;
204 static void
205 dump_conditionals( cp, sp, multi, global )
206 CELLPTR cp;
207 STRINGPTR sp;
208 int multi;
209 int global;
211 if (sp) {
212 dump_name(cp, FALSE, TRUE);
213 printf(".%sCONDITIONALS %s\n", global?"GLOBAL":"",multi?"::":":");
215 while(sp) {
216 printf("\t%s\n",sp->st_string);
217 sp=sp->st_next;
223 static void
224 dump_macro(hp, flag)
225 HASHPTR hp;
226 int flag;
228 printf( "%s ", hp->ht_name );
229 if(flag & M_EXPANDED)
230 putchar( ':' );
232 printf( "= " );
233 if(hp->ht_value != NIL(char))
234 printf( "%s",hp->ht_value );
236 if(flag & M_PRECIOUS)
237 printf( "\t # PRECIOUS " );
239 putchar( '\n' );
243 static void
244 dump_prerequisites( lp, namecp, quote, recurse, flag )/*
245 ========================================================
246 Dump as prerequisites if recurse is FALSE or as targets
247 if recurse is TRUE. (For F_MULTI/F_PERCENT targets.) */
248 LINKPTR lp;
249 CELLPTR namecp;
250 int quote;
251 int recurse;
252 int flag;
254 for( ; lp; lp=lp->cl_next )
255 if( recurse )
256 dump_normal_target(lp->cl_prq, namecp, flag);
257 else if( lp->cl_prq )
258 dump_name(lp->cl_prq, quote, FALSE);
262 static void
263 dump_name( cp, quote, all )/*
264 =============================
265 Prints out the first or all (if all is TRUE) names of an lcell list.
266 If quote is true enclose in ' quotes, if quote
267 is FALSE and the name includes a space enclose in " quotes. */
268 CELLPTR cp;
269 int quote;
270 int all;
272 LINKPTR lp;
273 char qc = '\'';
275 for(lp=CeMeToo(cp);lp;lp=lp->cl_next) {
276 if( !quote && strchr(lp->cl_prq->CE_NAME,' ') != NIL(char)) {
277 quote = TRUE;
278 qc = '"';
281 if (quote) putchar(qc);
282 printf( "%s", lp->cl_prq->CE_NAME );
283 if (quote) putchar(qc);
284 putchar(' ');
285 if (!all) break;