home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / cdity / smartwin_src.lha / SmartWIN / source / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-16  |  4.4 KB  |  257 lines

  1. /*
  2. **    SmartWIN
  3. **
  4. **        © 1996 by Timo C. Nentwig
  5. **        All Rights Reserved !
  6. **
  7. **        Tcn@oxygen.in-berlin.de
  8. **
  9. */
  10.  
  11. /// #include
  12.  
  13. #include "GST.h"
  14. #include "Protos.h"
  15.  
  16. ///
  17. /// proto
  18.  
  19. static BOOL    OpenLibs     (VOID);
  20. static VOID    CloseLibs    (VOID);
  21.  
  22. ///
  23.  
  24.     // System libraries
  25.  
  26. struct    Library         *CxBase;
  27. struct    Library         *IconBase;
  28. struct    IntuitionBase   *IntuitionBase;
  29. struct    Library         *UtilityBase;
  30.  
  31.     // Settings struct
  32.  
  33. struct    Settings        *Set;
  34.  
  35.     // C:Version string
  36.  
  37. static const STRPTR    __ver = "$VER: " PRG_TITLE " " PRG_VERSION " " __AMIGADATE__;
  38.  
  39.     // Libraries
  40.  
  41. static const struct { STRPTR Name; ULONG Version; APTR *Library; } Table [] =
  42. {
  43.  
  44.     "commodities.library", LIBRARY_MINIMUM, (APTR *) &CxBase,
  45.     "dos.library",         LIBRARY_MINIMUM, (APTR *) &DOSBase,
  46.     "icon.library",        LIBRARY_MINIMUM, (APTR *) &IconBase,
  47.     "intuition.library",   LIBRARY_MINIMUM, (APTR *) &IntuitionBase,
  48.     "utility.library",     LIBRARY_MINIMUM, (APTR *) &UtilityBase,
  49.  
  50.     NULL,
  51.  
  52. };
  53.  
  54. /// main()
  55.  
  56. LONG
  57. main (VOID)
  58. {
  59.  
  60.     LONG    Result = RETURN_FAIL;
  61.  
  62.         // Open libraries
  63.  
  64.     if (OpenLibs())
  65.     {
  66.  
  67.             // Alloc mem for settings struct
  68.  
  69.         if (Set = AllocStruct (Settings))
  70.         {
  71.  
  72.                 // Initialize settings
  73.  
  74.             InitSettings();
  75.  
  76.                 // Evaluate ToolTypes
  77.  
  78.             EvalTTypes();
  79.  
  80.                 // Evaluate Shell arguments
  81.  
  82.             EvalArgs();
  83.  
  84.                 // Setup commodity
  85.  
  86.             if (SetupCx())
  87.             {
  88.  
  89.                 BOOL     Done = FALSE;
  90.                 ULONG    Signals;
  91.  
  92.                     // Install the patch
  93.  
  94.                 if (InstallWedge())
  95.                 {
  96.  
  97.                     Result = RETURN_OK;
  98.  
  99.                     Signals = PortMask (CxPort);
  100.  
  101.                     do
  102.                     {
  103.  
  104.                             // Got commodity signal
  105.  
  106.                         if (Signals & PortMask (CxPort))
  107.                         {
  108.  
  109.                             CxMsg   *GMsg;
  110.  
  111.                             while (GMsg = (CxMsg *) GetMsg (CxPort))
  112.                             {
  113.  
  114.                                 if (HandleCx (GMsg))
  115.                                 {
  116.  
  117.                                     Done = TRUE;
  118.                                     break;
  119.  
  120.                                 }
  121.  
  122.                             }
  123.  
  124.                         }
  125.  
  126.                             // Got DOS signal: CTRL-C
  127.  
  128.                         if (Signals & SIGBREAKF_CTRL_C)
  129.                         {
  130.  
  131.                             Done = TRUE;
  132.  
  133.                         }
  134.  
  135.                             // Wait for signals
  136.  
  137.                         if ( ! (Done))
  138.                         {
  139.  
  140.                             Signals = Wait (SIGBREAKF_CTRL_C | PortMask (CxPort));
  141.  
  142.                         }
  143.  
  144.                     }
  145.                     while ( ! (Done));
  146.  
  147.  
  148.                         // Remove the patch
  149.  
  150.                     RemoveWedge();
  151.  
  152.                 }
  153.                 else
  154.                 {
  155.  
  156.                     FPrintf (Output(), "Failed to install patch !\n");
  157.  
  158.                 }
  159.  
  160.             }
  161.  
  162.                 // Quit program
  163.  
  164.             QuitCx();
  165.  
  166.                 // Free settings structure
  167.  
  168.             FreeStruct (Set);
  169.  
  170.         }
  171.         else
  172.         {
  173.  
  174.             FPrintf (Output(), "Out of memory !\n");
  175.  
  176.         }
  177.  
  178.         CloseLibs();
  179.  
  180.     }
  181.  
  182.     return (Result);
  183.  
  184. }
  185.  
  186. ///
  187. /// OpenLibs ()
  188.  
  189.     /*
  190.      *    FUNCTION    Open a required libraries.
  191.      *
  192.      *    NOTE        <Table> is defined above.
  193.      *
  194.      *    EXAMPLE     OpenLibs ();
  195.      *
  196.      */
  197.  
  198.  
  199. static BOOL
  200. OpenLibs (VOID)
  201. {
  202.  
  203.     LONG    i;
  204.  
  205.         // Open libraries
  206.  
  207.     for (i = 0; Table [i] . Name; i ++)
  208.     {
  209.  
  210.             // Failed to open a library
  211.  
  212.         if ( ! (*Table [i] . Library = OpenLibrary (Table [i] . Name, Table [i] . Version)))
  213.         {
  214.  
  215.             FPrintf (Output(), PRG_TITLE ": Failed to open \"%s\" v%ld+ !\n", Table [i] . Name, Table [i] . Version);
  216.             return (FALSE);
  217.  
  218.         }
  219.  
  220.     }
  221.  
  222.     return (TRUE);
  223.  
  224. }
  225.  
  226. ///
  227. /// CloseLibs ()
  228.  
  229.     /*
  230.      *    FUNCTION    Close all opened libraries.
  231.      *
  232.      *    NOTE        <Table> is defined above.
  233.      *
  234.      *    EXAMPLE     CloseLibs ();
  235.      *
  236.      */
  237.  
  238.  
  239. static VOID
  240. CloseLibs (VOID)
  241. {
  242.  
  243.     LONG    i;
  244.  
  245.         // Close libraries
  246.  
  247.     for (i = 0; Table [i] . Library; i ++)
  248.     {
  249.  
  250.         CloseLib (*Table [i] . Library);
  251.  
  252.     }
  253.  
  254. }
  255.  
  256. ///
  257.