home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DMAKE38A.ZIP / DMDUMP.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  6KB  |  208 lines

  1. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/dmdump.c,v 1.1 1992/01/24 03:28:51 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) 1990 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  1992/01/24  03:28:51  dvadura
  33.  * dmake Version 3.8, 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((HASHPTR, int));
  42. static    void    dump_normal_target ANSI((CELLPTR, int));
  43. static  void    dump_prerequisites ANSI((LINKPTR, int, int, int));
  44.  
  45.  
  46. PUBLIC void
  47. Dump()/*
  48. ========  Dump onto standard output the digested makefile.  Note that
  49.       the form of the dump is not representative of the contents
  50.       of the original makefile contents at all */
  51. {
  52.    HASHPTR      hp;
  53.    int          i;
  54.  
  55.    DB_ENTER( "Dump" );
  56.  
  57.    puts( "# Dump of dmake macro variables:" );
  58.    for( i=0; i<HASH_TABLE_SIZE; i++)
  59.       for( hp=Macs[i]; hp != NIL(HASH); hp = hp->ht_next ) {
  60.      int flag = hp->ht_flag;
  61.  
  62.      printf( "%s ", hp->ht_name );
  63.      if( flag & M_EXPANDED ) putchar( ':' );
  64.      printf( "= " );
  65.      if( hp->ht_value != NIL(char) ) printf( "%s",hp->ht_value );
  66.      if( flag & M_PRECIOUS )
  67.         printf( "\t # PRECIOUS " );
  68.      putchar( '\n' );
  69.       }
  70.  
  71.    puts( "\n#====================================" );
  72.    puts( "# Dump of targets:\n" );
  73.  
  74.    for( i=0; i<HASH_TABLE_SIZE; i++ )
  75.       for( hp = Defs[i]; hp != NIL(HASH); hp = hp->ht_next )
  76.          if( !(hp->CP_OWNR->ce_flag & F_PERCENT) ) {
  77.         if( Root->ce_prq && hp->CP_OWNR == Root->ce_prq->cl_prq )
  78.            puts( "# ******* FIRST TARGET ********" );
  79.         dump_normal_target( hp->CP_OWNR, hp->CP_OWNR->ce_flag );
  80.      }
  81.  
  82.    puts( "\n#====================================" );
  83.    puts( "# Dump of inference graph\n" );
  84.  
  85.    for( i=0; i<HASH_TABLE_SIZE; i++ )
  86.       for( hp = Defs[i]; hp != NIL(HASH); hp = hp->ht_next )
  87.          if( (hp->CP_OWNR->ce_flag & F_PERCENT) &&
  88.         !(hp->CP_OWNR->ce_flag & F_MAGIC) )
  89.         dump_normal_target( hp->CP_OWNR, hp->CP_OWNR->ce_flag );
  90.  
  91.    DB_VOID_RETURN;
  92. }
  93.  
  94.  
  95.  
  96. PUBLIC void
  97. Dump_recipe( sp )/*
  98. ===================
  99.    Given a string pointer print the recipe line out */
  100. STRINGPTR sp;
  101. {
  102.    char *st;
  103.    char *nl;
  104.  
  105.    if( sp == NIL(STRING) ) return;
  106.  
  107.    putchar( '\t' );
  108.    if( sp->st_attr & A_SILENT ) putchar( '@' );
  109.    if( sp->st_attr & A_IGNORE ) putchar( '-' );
  110.    if( sp->st_attr & A_SHELL  ) putchar( '+' );
  111.    if( sp->st_attr & A_SWAP   ) putchar( '%' );
  112.  
  113.    st = sp->st_string;
  114.    for( nl=strchr(st,'\n'); nl != NIL( char); nl=strchr(st,'\n') ) {
  115.       *nl = '\0';
  116.       printf( "%s\\\n", st );
  117.       *nl = '\n';
  118.       st  = nl+1;
  119.    }
  120.    printf( "%s\n", st );
  121. }
  122.  
  123.  
  124. static char *_attrs[] = { ".PRECIOUS", ".SILENT", ".LIBRARY",
  125.    ".EPILOG", ".PROLOG", ".IGNORE", ".SYMBOL", ".NOINFER",
  126.    ".UPDATEALL", ".SEQUENTIAL", ".SETDIR=", ".USESHELL", ".SWAP", ".MKSARGS",
  127.    ".PHONY", ".NOSTATE" };
  128.  
  129. static void
  130. dump_normal_target( cp, flag )/*
  131. ================================
  132.     Dump in makefile like format the dag information */
  133. CELLPTR cp;
  134. int     flag;
  135. {
  136.    register LINKPTR   lp;
  137.    register STRINGPTR sp;
  138.    t_attr          attr;
  139.    unsigned int          k;
  140.  
  141.    DB_ENTER( "dump_normal_target" );
  142.  
  143.    if( !(cp->ce_flag & F_TARGET) && !cp->ce_attr ) { DB_VOID_RETURN; }
  144.  
  145.    if( cp->ce_flag & F_MULTI ) {
  146.       int tflag = cp->ce_prq->cl_prq->ce_flag;
  147.       if( !(cp->ce_flag & F_PERCENT) ) tflag |= F_MULTI;
  148.       dump_prerequisites(cp->ce_prq, FALSE, TRUE, tflag);
  149.    }
  150.    else {
  151.       dump_name( cp->ce_name, FALSE );
  152.  
  153.       for( k=0, attr=1; attr <= MAX_ATTR; attr <<= 1, k++ )
  154.      if( cp->ce_attr & attr ) {
  155.         printf( "%s%s ", _attrs[k],
  156.             (attr != A_SETDIR) ? "" : (cp->ce_dir?cp->ce_dir:"") );
  157.      }
  158.         
  159.       putchar( ':' );
  160.  
  161.       if( flag & F_MULTI )  putchar( ':' );
  162.       if( flag & F_SINGLE ) putchar( '!' );
  163.       putchar( ' ' );
  164.  
  165.       dump_prerequisites( cp->ce_prq, FALSE, FALSE, F_DEFAULT);
  166.       dump_prerequisites( cp->ce_indprq, TRUE, FALSE, F_DEFAULT);
  167.  
  168.       putchar( '\n' );
  169.       if( cp->ce_flag & F_GROUP ) puts( "[" );
  170.       for( sp = cp->ce_recipe; sp != NIL(STRING); sp = sp->st_next )
  171.      Dump_recipe( sp );
  172.       if( cp->ce_flag & F_GROUP ) puts( "]" );
  173.  
  174.       putchar( '\n' );
  175.    }
  176.  
  177.    DB_VOID_RETURN;
  178. }
  179.  
  180.  
  181. static void
  182. dump_prerequisites( lp, quote, recurse, flag )
  183. LINKPTR lp;
  184. int     quote;
  185. int     recurse;
  186. int     flag;
  187. {
  188.    for( ; lp; lp=lp->cl_next )
  189.       if( recurse )
  190.      dump_normal_target(lp->cl_prq, flag);
  191.       else if( lp->cl_prq )
  192.      dump_name(lp->cl_prq->ce_name, quote);
  193. }
  194.  
  195.  
  196. static void
  197. dump_name( hp, quote )/*
  198. ========================
  199.     print out a name */
  200. HASHPTR hp;
  201. int     quote;
  202. {
  203.    if( quote ) putchar('\'');
  204.    printf( "%s", hp->ht_name );
  205.    if( quote ) putchar('\'');
  206.    putchar(' ');
  207. }
  208.