home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / develop / gadtoolsbox / gengtxsource / source / main.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  5KB  |  150 lines

  1. /*
  2. **      $Filename: Main.c $
  3. **      $Release: 1.0 $
  4. **      $Revision: 38.1 $
  5. **
  6. **      GenGTXSource main source file.
  7. **
  8. **      (C) Copyright 1992 Jaba Development.
  9. **          Written by Jan van den Baard
  10. **/
  11.  
  12. #include "GenGTXSource.h"
  13.  
  14. /*
  15.  *      Get the necessary resources.
  16.  */
  17. Local BOOL GetResources( void )
  18. {
  19.     UWORD           n;
  20.  
  21.     NewList(( struct List * )&Strings );
  22.     NewList(( struct List * )&Arrays );
  23.  
  24.     LocaleBase = ( struct LocaleBase * )OpenLibrary( "locale.library", 38L );
  25.  
  26.    /*
  27.     *       Setup catalog.
  28.     */
  29.     if ( LocaleBase ) {
  30.         if ( Catalog = OpenCatalog( NULL, "GenGTXSource.catalog", OC_BuiltInLanguage, "english",
  31.                                                                   OC_Version,         1,
  32.                                                                   TAG_END )) {
  33.             for( n = 0; n < NumAppStrings; n++ )
  34.                 AppStrings[ n ].as_Str = GetCatalogStr( Catalog, n, AppStrings[ n ].as_Str );
  35.         }
  36.     }
  37.  
  38.    /*
  39.     *       Open the libraries.
  40.     */
  41.     if ( ! ( IntuitionBase = ( struct IntuitionBase * )OpenLibrary( "intuition.library", 37L ))) {
  42.         Print( STRING( MSG_INTUITION_ERROR ));
  43.         return( FALSE );
  44.     }
  45.  
  46.     if ( ! ( GTXBase = ( struct GTXBase * )OpenDiskLibrary( GTXNAME, GTXVERSION ))) {
  47.         Print( STRING( MSG_GTX_ERROR ));
  48.         return( FALSE );
  49.     }
  50.  
  51.     GfxBase         =   ( struct Library * )GTXBase->GfxBase;
  52.     NoFragBase      =   GTXBase->NoFragBase;
  53.     GadToolsBase    =   GTXBase->GadToolsBase;
  54.     UtilityBase     =   GTXBase->UtilityBase;
  55.  
  56.    /*
  57.     *       Get a MemoryChain.
  58.     */
  59.     if ( ! ( Chain = GetMemoryChain( 4096L ))) {
  60.         Print( STRING( MSG_OUT_OF_MEMORY ));
  61.         return( FALSE );
  62.     }
  63. }
  64.  
  65. /*
  66.  *      Free the used resources.
  67.  */
  68. Local VOID FreeResources( void )
  69. {
  70.    /*
  71.     *       Close the libraries and dellocate the memory.
  72.     */
  73.     if ( GTXBase ) {
  74.         FreeDuplicates();
  75.         if ( Chain )            FreeMemoryChain( Chain, TRUE );
  76.         CloseLibrary(( struct Library * )GTXBase );
  77.     }
  78.  
  79.     if ( IntuitionBase )    CloseLibrary(( struct Library * )IntuitionBase );
  80.  
  81.    /*
  82.     *       Close up locale stuff.
  83.     */
  84.     if ( LocaleBase ) {
  85.         if ( Catalog )      CloseCatalog( Catalog );
  86.         CloseLibrary(( struct Library * )LocaleBase );
  87.     }
  88. }
  89.  
  90. /*
  91.  *      Main entry point.
  92.  */
  93. LONG _main( void )
  94. {
  95.     LONG error = 0;
  96.  
  97.     stdOut = Output();
  98.  
  99.     if ( GetResources()) {
  100.         if ( SArgs = ReadArgs( Template, (LONG *)&Arguments, NULL )) {
  101.             Print( "GenGTXSource 1.0 - (C) Copyright 1992 Jaba Development\n\t%s Jan van den Baard\n", STRING( MSG_BY ));
  102.             Print( STRING( MSG_LOADING ));
  103.             if ( ! ( error = GTX_LoadGUI( Chain, Arguments.Name, RG_GUI,            &GuiInfo,
  104.                                                                  RG_Config,         &MainConfig,
  105.                                                                  RG_CConfig,        &SourceConfig,
  106.                                                                  RG_WindowList,     &Windows,
  107.                                                                  RG_Valid,          &ValidBits,
  108.                                                                  TAG_END ))) {
  109.                 Generate();
  110.                 Print( STRING( MSG_DONE ));
  111.             } else {
  112.                 switch ( error ) {
  113.                     case    ERROR_NOMEM:
  114.                         Print( STRING( MSG_OUT_OF_MEMORY ));
  115.                         break;
  116.                     case    ERROR_OPEN:
  117.                         Print( STRING( MSG_OPEN_FILE_ERROR ));
  118.                         break;
  119.                     case    ERROR_READ:
  120.                         Print( STRING( MSG_READ_ERROR ));
  121.                         break;
  122.                     case    ERROR_WRITE:
  123.                         Print( STRING( MSG_WRITE_ERROR ));
  124.                         break;
  125.                     case    ERROR_PARSE:
  126.                         Print( STRING( MSG_PARSE_ERROR ));
  127.                         break;
  128.                     case    ERROR_PACKER:
  129.                         Print( STRING( MSG_DECRUNCH_ERROR ));
  130.                         break;
  131.                     case    ERROR_PPLIB:
  132.                         Print( STRING( MSG_PPLIB_ERROR ));
  133.                         break;
  134.                     case    ERROR_NOTGUIFILE:
  135.                         Print( STRING( MSG_NOT_GUI_FILE_ERROR ));
  136.                         break;
  137.                 }
  138.                 error = 0;
  139.             }
  140.             GTX_FreeWindows( Chain, &Windows );
  141.             FreeArgs( SArgs );
  142.         } else
  143.             PrintFault( error = IoErr(), STRING( MSG_ERROR ));
  144.     }
  145.  
  146.     FreeResources();
  147.  
  148.     _exit( error );
  149. }
  150.