home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dmake40.zip / dmdump.c < prev    next >
C/C++ Source or Header  |  1994-10-23  |  7KB  |  265 lines

  1. /* RCS      -- $Header: /u5/dvadura/src/public/dmake/src/RCS/dmdump.c,v 1.1 1994/10/06 17:42:38 dvadura Exp $
  2. -- SYNOPSIS -- dump the internal dag to stdout.
  3. -- 
  4. -- DESCRIPTION
  5. --    This file contains the routine that is called to dump a version of
  6. --    the digested makefile to the standard output.  May be useful perhaps
  7. --    to the ordinary user, and invaluable for debugging make.
  8. -- 
  9. -- AUTHOR
  10. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  11. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  12. --
  13. -- COPYRIGHT
  14. --      Copyright (c) 1992,1994 by Dennis Vadura.  All rights reserved.
  15. -- 
  16. --      This program is free software; you can redistribute it and/or
  17. --      modify it under the terms of the GNU General Public License
  18. --      (version 1), as published by the Free Software Foundation, and
  19. --      found in the file 'LICENSE' included with this distribution.
  20. -- 
  21. --      This program is distributed in the hope that it will be useful,
  22. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  23. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. --      GNU General Public License for more details.
  25. -- 
  26. --      You should have received a copy of the GNU General Public License
  27. --      along with this program;  if not, write to the Free Software
  28. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. --
  30. -- LOG
  31. --     $Log: dmdump.c,v $
  32.  * Revision 1.1  1994/10/06  17:42:38  dvadura
  33.  * dmake Release Version 4.0, Initial revision
  34.  *
  35. */
  36.  
  37. #include "extern.h"
  38.  
  39. #define M_TEST    (M_PRECIOUS | M_VAR_MASK)
  40.  
  41. static    void    dump_name ANSI((CELLPTR, int, int));
  42. static    void    dump_normal_target ANSI((CELLPTR, CELLPTR, int));
  43. static  void    dump_prerequisites ANSI((LINKPTR, CELLPTR, int, int, int));
  44. static  void    dump_conditionals ANSI((CELLPTR,STRINGPTR,int,int));
  45. static  void    dump_macro ANSI((HASHPTR, int));
  46.  
  47.  
  48. PUBLIC void
  49. Dump()/*
  50. ========  Dump onto standard output the digested makefile.  Note that
  51.       the form of the dump is not representative of the contents
  52.       of the original makefile contents at all */
  53. {
  54.    HASHPTR      hp;
  55.    int          i;
  56.  
  57.    DB_ENTER( "Dump" );
  58.  
  59.    puts( "# Dump of dmake macro variables:" );
  60.    for( i=0; i<HASH_TABLE_SIZE; i++)
  61.       for( hp=Macs[i]; hp != NIL(HASH); hp = hp->ht_next ) {
  62.      int flag = hp->ht_flag;
  63.      dump_macro(hp, flag);
  64.       }
  65.  
  66.    puts( "\n#====================================" );
  67.    puts( "# Dump of targets:\n" );
  68.  
  69.    for( i=0; i<HASH_TABLE_SIZE; i++ )
  70.       for( hp = Defs[i]; hp != NIL(HASH); hp = hp->ht_next )
  71.          if( !(hp->CP_OWNR->ce_flag & F_PERCENT) ) {
  72.         if( hp->CP_OWNR == Root )
  73.            puts( "# ******* ROOT TARGET ********" );
  74.         if (Targets->ce_prq && hp->CP_OWNR == Targets->ce_prq->cl_prq)
  75.            puts( "# ******* FIRST USER DEFINED TARGET ******" );
  76.         dump_normal_target( hp->CP_OWNR,NIL(CELL),hp->CP_OWNR->ce_flag);
  77.      }
  78.  
  79.    puts( "\n#====================================" );
  80.    puts( "# Dump of inference graph\n" );
  81.  
  82.    for( i=0; i<HASH_TABLE_SIZE; i++ )
  83.       for( hp = Defs[i]; hp != NIL(HASH); hp = hp->ht_next )
  84.          if( (hp->CP_OWNR->ce_flag & F_PERCENT) &&
  85.         !(hp->CP_OWNR->ce_flag & F_MAGIC) )
  86.         dump_normal_target(hp->CP_OWNR,NIL(CELL),hp->CP_OWNR->ce_flag);
  87.  
  88.    DB_VOID_RETURN;
  89. }
  90.  
  91.  
  92.  
  93. PUBLIC void
  94. Dump_recipe( sp )/*
  95. ===================
  96.    Given a string pointer print the recipe line out */
  97. STRINGPTR sp;
  98. {
  99.    char *st;
  100.    char *nl;
  101.  
  102.    if( sp == NIL(STRING) ) return;
  103.  
  104.    putchar( '\t' );
  105.    if( sp->st_attr & A_SILENT ) putchar( '@' );
  106.    if( sp->st_attr & A_IGNORE ) putchar( '-' );
  107.    if( sp->st_attr & A_SHELL  ) putchar( '+' );
  108.    if( sp->st_attr & A_SWAP   ) putchar( '%' );
  109.  
  110.    st = sp->st_string;
  111.    for( nl=strchr(st,'\n'); nl != NIL( char); nl=strchr(st,'\n') ) {
  112.       *nl = '\0';
  113.       printf( "%s\\\n", st );
  114.       *nl = '\n';
  115.       st  = nl+1;
  116.    }
  117.    printf( "%s\n", st );
  118. }
  119.  
  120.  
  121. static char *_attrs[] = { ".PRECIOUS", ".SILENT", ".LIBRARY",
  122.    ".EPILOG", ".PROLOG", ".IGNORE", ".SYMBOL", ".NOINFER",
  123.    ".UPDATEALL", ".SEQUENTIAL", ".SETDIR=", ".USESHELL", ".SWAP", ".MKSARGS",
  124.    ".PHONY", ".NOSTATE", ".IGNOREGROUP" };
  125.  
  126. static void
  127. dump_normal_target( cp, namecp, flag )/*
  128. ========================================
  129.     Dump in makefile like format the dag information */
  130. CELLPTR cp;
  131. CELLPTR namecp;
  132. int     flag;
  133. {
  134.    register STRINGPTR sp;
  135.    t_attr          attr;
  136.    unsigned int          k;
  137.  
  138.    DB_ENTER( "dump_normal_target" );
  139.  
  140.    if(!(cp->ce_flag & F_TARGET) && !cp->ce_attr && !cp->ce_prq) {
  141.       DB_VOID_RETURN;
  142.    }
  143.  
  144.    if(cp->ce_set && cp->ce_set != cp) {
  145.       DB_VOID_RETURN;
  146.    }
  147.  
  148.    if( cp->ce_flag & F_MULTI ) {
  149.       int tflag = cp->ce_prq->cl_prq->ce_flag;
  150.       if( !(cp->ce_flag & F_PERCENT) ) tflag |= F_MULTI;
  151.       dump_conditionals(cp, cp->ce_cond, TRUE, TRUE);
  152.       putchar('\n');
  153.       dump_prerequisites(cp->ce_prq,(cp->ce_flag&F_PERCENT)?NIL(CELL):cp,
  154.              FALSE, TRUE, tflag);
  155.    }
  156.    else {
  157.       CELLPTR tcp;
  158.  
  159.       dump_name(namecp?namecp:cp, FALSE, TRUE );
  160.  
  161.       for( k=0, attr=1; attr <= MAX_ATTR; attr <<= 1, k++ )
  162.      if( cp->ce_attr & attr ) {
  163.         printf( "%s%s ", _attrs[k],
  164.             (attr != A_SETDIR) ? "" : (cp->ce_dir?cp->ce_dir:"") );
  165.      }
  166.         
  167.       putchar( ':' );
  168.  
  169.       if( flag & F_MULTI )  putchar( ':' );
  170.       if( flag & F_SINGLE ) putchar( '!' );
  171.       putchar( ' ' );
  172.  
  173.       dump_prerequisites( cp->ce_prq, NIL(CELL), FALSE, FALSE, F_DEFAULT);
  174.       dump_prerequisites( cp->ce_indprq, NIL(CELL),TRUE, FALSE, F_DEFAULT);
  175.  
  176.       putchar( '\n' );
  177.       if( cp->ce_flag & F_GROUP ) puts( "[" );
  178.       for( sp = cp->ce_recipe; sp != NIL(STRING); sp = sp->st_next )
  179.      Dump_recipe( sp );
  180.       if( cp->ce_flag & F_GROUP ) {
  181.      puts( "]" );
  182.      putchar( '\n' );
  183.       }
  184.       dump_conditionals(cp, cp->ce_cond, flag&F_MULTI, FALSE);
  185.       putchar('\n');
  186.    }
  187.  
  188.    DB_VOID_RETURN;
  189. }
  190.  
  191.  
  192. static void
  193. dump_conditionals( cp, sp, multi, global )
  194. CELLPTR     cp;
  195. STRINGPTR   sp;
  196. int         multi;
  197. int         global;
  198. {
  199.    if (sp) {
  200.       dump_name(cp, FALSE, TRUE);
  201.       printf(".%sCONDITIONALS %s\n", global?"GLOBAL":"",multi?"::":":");
  202.  
  203.       while(sp) {
  204.      printf("\t%s\n",sp->st_string);
  205.      sp=sp->st_next;
  206.       }
  207.    }
  208. }
  209.  
  210.  
  211. static void
  212. dump_macro(hp, flag)
  213. HASHPTR hp;
  214. int     flag;
  215. {
  216.    printf( "%s ", hp->ht_name );
  217.    if(flag & M_EXPANDED)
  218.       putchar( ':' );
  219.  
  220.    printf( "= " );
  221.    if(hp->ht_value != NIL(char))
  222.       printf( "%s",hp->ht_value );
  223.  
  224.    if(flag & M_PRECIOUS)
  225.       printf( "\t # PRECIOUS " );
  226.  
  227.    putchar( '\n' );
  228. }
  229.  
  230.  
  231. static void
  232. dump_prerequisites( lp, namecp, quote, recurse, flag )
  233. LINKPTR lp;
  234. CELLPTR namecp;
  235. int     quote;
  236. int     recurse;
  237. int     flag;
  238. {
  239.    for( ; lp; lp=lp->cl_next )
  240.       if( recurse )
  241.      dump_normal_target(lp->cl_prq, namecp, flag);
  242.       else if( lp->cl_prq )
  243.      dump_name(lp->cl_prq, quote, FALSE);
  244. }
  245.  
  246.  
  247. static void
  248. dump_name( cp, quote, all )/*
  249. =============================
  250.     print out a name */
  251. CELLPTR cp;
  252. int     quote;
  253. int     all;
  254. {
  255.    LINKPTR lp;
  256.  
  257.    for(lp=CeMeToo(cp);lp;lp=lp->cl_next) {
  258.       if( quote ) putchar('\'');
  259.       printf( "%s", lp->cl_prq->CE_NAME );
  260.       if( quote ) putchar('\'');
  261.       putchar(' ');
  262.       if (!all) break;
  263.    }
  264. }
  265.