home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0975.lha / CLIExchange / CLIExchange.c < prev    next >
C/C++ Source or Header  |  1994-01-20  |  4KB  |  186 lines

  1. /*
  2. **  CLIExchange : Gael Marziou
  3. **
  4. **  A simple CLI replacement for standard utility Exchange
  5. **  Without any argument it applies the command specified to
  6. **  all running commodities.
  7. **  Arguments must be a list of Commodities.names
  8. **  Names are case sensitive.
  9. **  Of course, it is a 2.04 only command.
  10. **
  11. **    Compiled with SAS C 6.50
  12. **
  13. **  1.0: 15 Jan. 1994, first release, size = 688 bytes
  14. **  1.1: 19 Jan. 1994, size = 672 bytes
  15. **  1.2: 20 Jan. 1994, size = 592 bytes
  16. */
  17.  
  18.  
  19. #include <dos/dos.h>
  20. #include <exec/exec.h>
  21. #include <libraries/commodities.h>
  22. #include <string.h>
  23.  
  24. #include <clib/alib_protos.h>
  25. #include <clib/commodities_protos.h>
  26. #include <clib/dos_protos.h>
  27. #include <clib/exec_protos.h>
  28.  
  29. #ifdef __SASC
  30. #   define __USE_SYSBASE
  31. #   include <pragmas/commodities_pragmas.h>
  32. #   include <pragmas/dos_pragmas.h>
  33. #   include <pragmas/exec_pragmas.h>
  34. #endif
  35.  
  36. UBYTE *version = "$VER: CLIExchange 1.2 (1.20.94)";
  37.  
  38. #define TEMPLATE  "KILL/S,ENABLE/S,DISABLE/S,APPEAR/S,DISAPPEAR/S,UNIQUE/S,CXNAME/M"
  39.  
  40. #define OPT_KILL          0
  41. #define OPT_ENABLE        1
  42. #define OPT_DISABLE        2
  43. #define OPT_APPEAR         3
  44. #define OPT_DISAPPEAR     4
  45. #define OPT_UNIQUE        5
  46. #define OPT_CXNAME      6
  47. #define OPT_COUNT         7
  48.  
  49.  
  50. /****************************************************/
  51. /* The following definitions have been found in the */
  52. /* source of MUI-Exchange written by Klaus Melchior */
  53. /****************************************************/
  54.  
  55. /***  private functions of "commodities.library"  ***/
  56.  
  57. #pragma libcall CxBase FindBroker 6c 801
  58. #pragma libcall CxBase CopyBrokerList ba 801
  59. #pragma libcall CxBase FreeBrokerList c0 801
  60. #pragma libcall CxBase BrokerCommand c6 802
  61.  
  62. CxObj *FindBroker(char *);
  63. LONG CopyBrokerList(struct List *);
  64. LONG FreeBrokerList(struct List *);
  65. LONG BrokerCommand(char *, LONG id);
  66.  
  67.  
  68. /*** private structures & defines ***/
  69.  
  70. struct BrokerCopy    {
  71.     struct Node    bc_Node;
  72.     char    bc_Name[CBD_NAMELEN];
  73.     char    bc_Title[CBD_TITLELEN];
  74.     char    bc_Descr[CBD_DESCRLEN];
  75.     LONG    bc_Task;
  76.     LONG    bc_Dummy1;
  77.     LONG    bc_Dummy2;
  78.     UWORD    bc_Flags;
  79. };
  80.  
  81.  
  82.  
  83. ULONG
  84. CLIExchange(void)
  85. {
  86.     struct Library    *CxBase;
  87.     struct DosLibrary *DOSBase;
  88.     ULONG  rc = RETURN_FAIL;
  89.     UBYTE  i;
  90.     LONG   opts[OPT_COUNT];
  91.     LONG   Command;
  92.     struct RDArgs *rdargs;
  93.     char  *curarg, **argptr;
  94.     struct List *l;
  95.     struct Node *n, *nn;
  96.     UBYTE  OptCommand[OPT_CXNAME] =
  97.     {
  98.         CXCMD_KILL,
  99.         CXCMD_ENABLE,
  100.         CXCMD_DISABLE,
  101.         CXCMD_APPEAR,
  102.         CXCMD_DISAPPEAR,
  103.         CXCMD_UNIQUE
  104.     };
  105.  
  106.  
  107.     /* Before bothering with anything else, open the libraries we need */
  108.     DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37L);
  109.     CxBase = OpenLibrary("commodities.library", 37L);
  110.  
  111.     if (CxBase && DOSBase)
  112.     {
  113.         /* Clear the options array, just to be on the safe side... */
  114.         memset((char *)opts, 0, sizeof(opts));
  115.  
  116.         /* Parse the command line. */
  117.         rdargs = ReadArgs(TEMPLATE, opts, NULL);
  118.             
  119.         if (rdargs == NULL)
  120.         {
  121.             PrintFault(IoErr(), NULL);
  122.         }
  123.         else
  124.         {
  125.             rc = RETURN_OK;
  126.                     
  127.             /* Find which option has been set by user */
  128.             i = OPT_KILL;
  129.             while (!opts[i] && (i<OPT_CXNAME))
  130.             {
  131.                 i++;
  132.             }
  133.             if (i < OPT_CXNAME)
  134.             {
  135.                 Command = OptCommand[i];
  136.             }
  137.  
  138.             /* Initialize for MultiArgs handling */
  139.             argptr = (char **)opts[OPT_CXNAME];
  140.                 
  141.             if ((argptr == NULL) || (i == OPT_CXNAME))
  142.             {
  143.                 /* no commodities names means ALL commodities */
  144.  
  145.                 if (l = AllocVec(sizeof(struct List),MEMF_PUBLIC)) 
  146.                 {
  147.                     NewList(l);
  148.                     CopyBrokerList(l);
  149.  
  150.                     for (n = l->lh_Head; n && (nn = n->ln_Succ); n = nn)
  151.                     {
  152.                         if (i == OPT_CXNAME)
  153.                         {
  154.                             Printf("%s\n",(char *)((struct BrokerCopy *)n)->bc_Name);
  155.                         }
  156.                         else
  157.                         {
  158.                             BrokerCommand((char *)((struct BrokerCopy *)n)->bc_Name, 
  159.                                           Command);
  160.                         }
  161.                     }
  162.                     FreeBrokerList(l);
  163.                     FreeVec(l);
  164.                 }
  165.             }
  166.             else
  167.             {
  168.                 /* The following while loop handles the MultiArgs spec. */
  169.                         
  170.                 while (curarg = *argptr++)
  171.                 {
  172.                     BrokerCommand ((char *)curarg, Command);
  173.                 }      
  174.             }
  175.         }
  176.     }   
  177.     CloseLibrary(CxBase);
  178.     CloseLibrary((struct Library *)DOSBase);
  179.     return(rc);
  180. }
  181.  
  182.  
  183.  
  184.  
  185.  
  186.