home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d523 / bmake.lha / BMake / source.lzh / guimain.c < prev    next >
C/C++ Source or Header  |  1991-07-28  |  5KB  |  237 lines

  1. /*    guimain.c
  2.  *    (c) Copyright 1991 by Ben Eng, All Rights Reserved
  3.  *
  4.  */
  5.  
  6. #include <ctype.h>
  7.  
  8. #include <exec/exec.h>
  9. #include <exec/execbase.h>
  10.  
  11. #include <intuition/intuitionbase.h>
  12. #include <graphics/gfxbase.h>
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/dos_protos.h>
  16.  
  17. extern struct GfxBase *GfxBase;
  18. extern struct IntuitionBase *IntuitionBase;
  19.  
  20. #include "make.h"
  21. #include "depend.h"
  22.  
  23. /* Globals */
  24. struct globals Global = {
  25.     NULL,    /* me */
  26.     NULL,    /* logfile */
  27.  
  28.     {
  29.     (struct Node *)&Global.targetlist.lh_Tail,    /* lh_Head */
  30.     (struct Node *)NULL,                        /* lh_Tail */
  31.     (struct Node *)&Global.targetlist.lh_Head,    /* lh_TailPred */
  32.     (UBYTE)NT_USER,
  33.     (UBYTE)0
  34.     },    /* targetlist */
  35.     {
  36.     (struct Node *)&Global.speciallist.lh_Tail,    /* lh_Head */
  37.     (struct Node *)NULL,                        /* lh_Tail */
  38.     (struct Node *)&Global.speciallist.lh_Head,    /* lh_TailPred */
  39.     (UBYTE)NT_USER,
  40.     (UBYTE)0
  41.     },    /* speciallist */
  42.     {
  43.     (struct Node *)&Global.patternlist.lh_Tail,    /* lh_Head */
  44.     (struct Node *)NULL,                        /* lh_Tail */
  45.     (struct Node *)&Global.patternlist.lh_Head,    /* lh_TailPred */
  46.     (UBYTE)NT_USER,
  47.     (UBYTE)0
  48.     },    /* patternlist */
  49.     {
  50.     (struct Node *)&Global.macrolist.lh_Tail,    /* lh_Head */
  51.     (struct Node *)NULL,                        /* lh_Tail */
  52.     (struct Node *)&Global.macrolist.lh_Head,    /* lh_TailPred */
  53.     (UBYTE)NT_USER,
  54.     (UBYTE)0
  55.     },    /* macrolist */
  56.     0,    /* builtin flag */
  57.     0,    /* recursion level */
  58.     0L    /* oldcwd */
  59. };
  60.  
  61. static int
  62. open_libraries( void )
  63. {
  64. #ifndef _DCC
  65.     if( !( IntuitionBase = OpenLibrary( "intuition.library", 33 ))) {
  66.         return( 1 );
  67.     }
  68.     if( !( GfxBase = OpenLibrary( "graphics.library", 33 ))) {
  69.         return( 1 );
  70.     }
  71. #endif
  72.     return( 0 );
  73. }
  74.  
  75. static void
  76. close_libraries( void )
  77. {
  78. #ifndef _DCC
  79.     if( IntuitionBase )
  80.         CloseLibrary( IntuitionBase );
  81.  
  82.     if( GfxBase )
  83.         CloseLibrary( GfxBase );
  84. #endif
  85. }
  86.  
  87. static int
  88. new_globals( struct globals *globptr )
  89. {
  90.     globptr->me = (struct Process *) FindTask( NULL ); /* find this task */
  91.     return( 0 );
  92. death:
  93.     printf( "problem initializing globals\n" );
  94.     return( 1 );
  95. }
  96.  
  97. static int
  98. delete_globals( struct globals *globptr )
  99. {
  100.     if( Global.oldcwd ) {
  101.         UnLock( CurrentDir( Global.oldcwd ));
  102.     }
  103.  
  104.     memset( globptr, 0, sizeof(struct globals));
  105.  
  106.     /*    just allow exit() to take care of free()ing all of our
  107.      *    allocations, because I don't feel like doing it right now
  108.      */
  109.     NewList( &globptr->targetlist );
  110.     NewList( &globptr->speciallist );
  111.     NewList( &globptr->patternlist );
  112.     NewList( &globptr->macrolist );
  113. }
  114.  
  115.  
  116. static void
  117. die( void )
  118. {
  119.     delete_params();
  120.  
  121.     close_logfile();
  122.  
  123.     delete_globals( &Global );
  124.     close_libraries();
  125. }
  126.  
  127. static int
  128. init( void )
  129. {
  130.     if( open_libraries()) goto death;
  131.     if( new_globals( &Global )) goto death;
  132.  
  133.     return( 0 );
  134. death:
  135.     return( 1 );
  136. }
  137.  
  138. static long
  139. do_cl_macro( struct string_node *one )
  140. {
  141.     long retval;
  142.     int made;
  143.  
  144.     if( strchr( one->data, '=' )) {
  145.         process_macroline( one->data );
  146.         if( !Global.builtin_flag ) {
  147.             logprintf( "\t%s\n", one->data );
  148.             Remove( &one->node );
  149.             delete_snode( one );
  150.         }
  151.     }
  152.     return( 0 );
  153. }
  154.  
  155. static long
  156. run_one( struct string_node *one )
  157. {
  158.     long retval;
  159.     int made;
  160.  
  161.     debugprintf( 2, ("\n** run_one Make %s **\n", one->data ));
  162.     retval = (long) make_filename( one->data, &made );
  163.     if( !retval && !made ) {
  164.         logprintf( "\"%s\" is up to date\n", one->data );
  165.     }
  166.     return( retval );
  167. }
  168.  
  169. static void
  170. run_it( void )
  171. {
  172.     long retval;
  173.     int made;
  174.  
  175.     if( Param.filelist.lh_Head->ln_Succ )
  176.         (void)for_list( &Param.filelist, do_cl_macro );
  177.     if( Param.filelist.lh_Head->ln_Succ ) {
  178.         (void)for_list( &Param.filelist, run_one );
  179.     }
  180.     else {
  181.         struct target *first_goal;
  182.         for( first_goal = (struct target *)Global.targetlist.lh_Head;
  183.             first_goal->node.ln_Succ;
  184.             first_goal = first_goal->node.ln_Succ ) {
  185.             if( !(first_goal->flags & (TF_PATTERN|TF_BUILTIN ))) break;
  186.         }
  187.         if( first_goal->node.ln_Succ ) {
  188.             debugprintf( 2, ("\n** first_goal Make %s **\n",
  189.                 first_goal->name ));
  190.             retval = make_filename( first_goal->name, &made );
  191.             if( !retval && !made ) {
  192.                 logprintf( "\"%s\" is up to date\n", first_goal->name );
  193.             }
  194.         }
  195.     }
  196.     logprintf( "\tMake done.\n" );
  197. }
  198.  
  199. int
  200. main( int argc, char *argv[] )
  201. {
  202. /*    Allow it to work with limitations on xsystem() and scdir()
  203.     if( GfxBase->LibNode.lib_Version < 36L ) {
  204.         printf( "This program requires Amiga OS 2.0\n" );
  205.         return( 20 );
  206.     }
  207. */
  208.     atexit( die );    /* add die() to normal exit procedure */
  209.  
  210.     if( parse_parameters( argc, argv )) goto bailout;
  211.  
  212.     logprintf( "%s %s\n", version_string+7, verdate_string );
  213.     logprintf( "%s\n", copyright_string );
  214.  
  215.     if( init() ) goto bailout;
  216.     Global.builtin_flag = 1;
  217.     if( init_builtins()) goto bailout;
  218.     if( Param.filelist.lh_Head->ln_Succ )
  219.         (void)for_list( &Param.filelist, do_cl_macro );
  220.     Global.builtin_flag = 0;
  221.  
  222.     if( input_makefile( Param.makefile )) goto bailout;
  223. #if DEBUG
  224.     if( Param.print_database ) dump_all();
  225.     else run_it();
  226. #else
  227.     run_it();
  228. #endif
  229.  
  230.     return( 0 );
  231.  
  232. bailout:
  233.     /* die(); is called by atexit */
  234.     return( 20 );
  235. }
  236.  
  237.