home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / cdity / EasyTM_src.lha / EasyTM-src / EasyTM.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-27  |  4.9 KB  |  156 lines

  1. //************************************
  2. //
  3. // Name : main.c
  4. //
  5. //************************************
  6.  
  7. //**** Header files
  8.  
  9. //** OS Include files
  10. #include <workbench/startup.h>
  11. #include <workbench/workbench.h>
  12. #include <libraries/dos.h>
  13. #include <libraries/wbstart.h>
  14. #include <libraries/commodities.h>
  15.  
  16. //** OS function prototypes
  17. #include <clib/exec_protos.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/wb_protos.h>
  20. #include <clib/commodities_protos.h>
  21.  
  22. //** OS function inline calls
  23. #include <pragmas/exec_pragmas.h>
  24. #include <pragmas/dos_pragmas.h>
  25. #include <pragmas/wb_pragmas.h>
  26. #include <pragmas/commodities_pragmas.h>
  27.  
  28. //** ANSI C includes
  29.  
  30. //** application include
  31. #include "Read.h"
  32. #include "Node.h"
  33. #include "Launch.h"
  34. #include "Janitor.h"
  35. #include "Prefs.h"
  36. #include "Librarian.h"
  37.  
  38.  
  39. //**** Local storage
  40.  
  41. static char VersTag[]="\0$VER: EasyTM v1.1 (28 May 1996)";
  42.  
  43.  
  44. //**** Main
  45.  
  46. void main(int argc, char **argv) {
  47.   struct AppMessage   *appmsg;
  48.   CxMsg *msg;
  49.   ULONG sig_a,sig_n, sret;
  50.   BOOL running=FALSE;
  51.   BOOL Active=TRUE;
  52.   struct NewBroker nb = {
  53.     NB_VERSION,
  54.     "EasyTM",
  55.     &VersTag[7],
  56.     "Easy Tools Menu manager commidity",
  57.     NBU_UNIQUE | NBU_NOTIFY,
  58.     COF_SHOW_HIDE,
  59.     0,
  60.     NULL,
  61.     0
  62.   };
  63.   CxObj *broker=NULL;
  64.   struct Task *t;
  65.  
  66.  
  67.   if (1==InitList()) {
  68.     if (1==OpenLibs() ) {
  69.       if (1==ReadIcon(argc,argv) ) {
  70.         if (1==OpenPorts()) {
  71.           nb.nb_Pri = my_cx_pri;
  72.           nb.nb_Port = StarPort[0];
  73.           sig_n = 1 << StarPort[0]->mp_SigBit;
  74.           if (broker = CxBroker(&nb, NULL)) {
  75.             ActivateCxObj(broker, 1L);
  76.             sig_a = 1 << StarPort[1]->mp_SigBit;
  77.             ReadFile(ToolsFileName);
  78.             if (1==BindMenus()) {
  79.               for ( running=TRUE ; TRUE==running ; ) {
  80.                 sret = Wait(SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | sig_a | sig_n);
  81.                 if (sret & sig_a) {
  82.                   while(appmsg=(struct AppMessage *)GetMsg(StarPort[1])) {
  83.                     Launch( (struct ProgNode *)appmsg->am_UserData,
  84.                             (long)appmsg->am_NumArgs,
  85.                             (struct WBArg *)appmsg->am_ArgList);
  86.                     // Let workbench know we're done with the message
  87.                     ReplyMsg((struct Message *)appmsg);
  88.                   } // while GetMsg
  89.                 } // if sig_a
  90.                 if (sret & sig_n) {
  91.                   while(msg = (CxMsg *)GetMsg(nb.nb_Port)) {
  92.                     switch(CxMsgType(msg)) {
  93.                       case CXM_COMMAND:
  94.                         switch(CxMsgID(msg)) {
  95.                           case CXCMD_DISABLE:
  96.                             if (TRUE==Active) {
  97.                               ActivateCxObj(broker, 0L);
  98.                               Active = FALSE;
  99.                               FreeMenus();
  100.                             }; // if
  101.                             break;
  102.                           case CXCMD_ENABLE:
  103.                             if (FALSE==Active) {
  104.                               ActivateCxObj(broker, 1L);
  105.                               Active = TRUE;
  106.                               if (0==BindMenus()) running=FALSE; // error restarting
  107.                             }; // if
  108.                             break;
  109.                           case CXCMD_APPEAR:
  110.                             Launch(NULL,0,NULL); // launch prefs
  111.                             break;
  112.                           case CXCMD_DISAPPEAR:
  113.                             if (t=FindTask("EasyTM-Prefs")) {
  114.                               Signal(t,SIGBREAKF_CTRL_D);
  115.                             } // if
  116.                             break;
  117.                           case CXCMD_KILL:
  118.                             running=FALSE;
  119.                             break;
  120.                           case CXCMD_UNIQUE:
  121.                             Launch(NULL,0,NULL); // launch prefs
  122.                             break;
  123.                         } // switch
  124.                         break;
  125.                     } // switch
  126.                     ReplyMsg((struct Message *)msg);
  127.                   } // while GetMsg
  128.                 } // if sig_n
  129.                 if (sret & SIGBREAKF_CTRL_C) running=FALSE;
  130.                 if (sret & SIGBREAKF_CTRL_D) {
  131.                   if (TRUE==Active) FreeMenus();
  132.                   if (1==ReadFile(ToolsFileName)) {
  133.                     if (TRUE==Active)
  134.                       if (0==BindMenus()) running=FALSE;
  135.                   } else running=FALSE;
  136.                 } // if CTRL_D
  137.               } // while !quit
  138.               FreeMenus();
  139.             } // if BindMenus
  140.  
  141.             ActivateCxObj(broker, 0L);
  142.             DeleteCxObj(broker);
  143.           } // if CreateBroker
  144.         } // if OpenPort
  145.         ClosePorts(); // yes, this is in the correct place
  146.         FreeVec(ToolsFileName);
  147.         FreeVec(PrefsProgDir);
  148.       } // if ReadIcon
  149.     } // if OpenLibs
  150.     CloseLibs(); // yes, this is in the correct place
  151.     FreeList(1);
  152.   } // if InitList
  153. } // main
  154.  
  155. //**** End of file
  156.