home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 529b.lha / BMake_v1.1 / depend.c < prev    next >
C/C++ Source or Header  |  1991-07-02  |  3KB  |  146 lines

  1. /*    depend.c
  2.  *    (c) Copyright 1991 by Ben Eng, All Rights Reserved
  3.  *
  4.  */
  5.  
  6. #include <clib/exec_protos.h>
  7.  
  8. #include "make.h"
  9. #include "depend.h"
  10.  
  11. struct target *default_target = NULL;
  12.  
  13. struct target *
  14. find_target( char *targetname )
  15. {
  16.     struct target *targ = NULL;
  17.  
  18.     for( struct target *ln = Global.targetlist.lh_Head; ln->node.ln_Succ;
  19.         ln = ln->node.ln_Succ ) {
  20.         if( !strcmp( targetname, ln->name )) {
  21.             targ = ln;
  22.             break;
  23.         }
  24.     }
  25.  
  26.     return( targ );
  27. }
  28.  
  29. struct target *
  30. new_target( char *targetname )
  31. {
  32.     long size;
  33.     struct target *new = NULL;
  34.  
  35.     if( targetname && *targetname ) {
  36.         size = sizeof(struct target) + strlen( targetname );
  37.         new = (struct target *)malloc( size );
  38.         if( new ) {
  39.             NewList( &new->dependlist );
  40.             NewList( &new->commandlist );
  41.             new->alternate = NULL;
  42.             new->mtime = 0L;
  43.             new->flags = 0L;
  44.             if( targetname ) strcpy( new->name, targetname );
  45.             else *targetname = (char)0;
  46.         }
  47.     }
  48.     return( new );
  49. }
  50.  
  51. int
  52. delete_target( struct target *targ )
  53. {
  54.     if( (targ->flags & TF_OWNER) && targ->commandlist.lh_Head )
  55.         delete_commandlist( &targ->commandlist );
  56.     if( targ->dependlist.lh_Head )
  57.         delete_dependlist( &targ->dependlist );
  58.     free( targ );
  59.     return( 0 );
  60. }
  61.  
  62. void
  63. delete_targetlist( struct List *list )
  64. {
  65.     for_list( list, delete_target );
  66.     NewList( list );
  67. }
  68.  
  69. void
  70. set_default_target( struct target *targ )
  71. {
  72.     if( default_target ) {
  73.         delete_target( default_target );
  74.     }
  75.     default_target = targ;
  76.     debugprintf( 4, ( "Setting .DEFAULT target\n" ));
  77. }
  78.  
  79. struct depend *
  80. new_depend( char *dependname )
  81. {
  82.     struct depend *new = NULL;
  83.     long size;
  84.  
  85.     if( dependname ) {
  86.         size = sizeof(struct depend) + strlen( dependname );
  87.         if( new = (struct depend *)malloc( size )) {
  88.             strcpy( new->name, dependname );
  89.         }
  90.     }
  91.     return( new );
  92. }
  93.  
  94. int
  95. delete_depend( struct depend *dep )
  96. {
  97.     free( dep );
  98.     return( 0 );
  99. }
  100.  
  101. void
  102. delete_dependlist( struct List *list )
  103. {
  104.     for_list( list, delete_depend );
  105.     NewList( list );
  106. }
  107.  
  108. struct command *
  109. new_command( char *cmd )
  110. {
  111.     long size;
  112.     struct command *new = NULL;
  113.     if( cmd && *cmd ) {
  114.         size = sizeof(struct command) + strlen( cmd );
  115.         new = (struct command *)malloc( size );
  116.         if( new ) {
  117.             if( *cmd == '-' ) {
  118.                 new->flags = CF_IGNORE;
  119.                 cmd++;
  120.             }
  121.             else if( *cmd == '@' ) {
  122.                 new->flags = CF_NOECHO;
  123.                 cmd++;
  124.             }
  125.             else new->flags = 0;
  126.             strcpy( new->cmd, cmd );
  127.         }
  128.     }
  129.     return( new );
  130. }
  131.  
  132. int
  133. delete_command( struct command *cmd )
  134. {
  135.     free( cmd );
  136.     return( 0 );
  137. }
  138.  
  139. void
  140. delete_commandlist( struct List *list )
  141. {
  142.     for_list( list, delete_command );
  143.     NewList( list );
  144. }
  145.  
  146.