home *** CD-ROM | disk | FTP | other *** search
- /*
- NAME
- CLIExchange
-
- FUNCTION
- replacement command for the Exchange utility
-
- INPUTS
- cxlist - list of commodity names
- command - switch associated with a message of type CXM_COMMAND
-
- RESULT
- success/failure indicator
-
- REQUIREMENTS
- dos.library V36+
- commodities.library V36+
-
- AUTHORS
- written by Gael Marziou and Reza Elghazi
-
- HISTORY
- +---------+----------+---------+--------------------------+
- | version | creation | size in | comment |
- | number | date | bytes | |
- +---------+----------+---------+--------------------------+
- | 1.0 | 15/01/94 | 688 | very first release |
- | 1.1 | 19/01/94 | 672 | |
- | 1.2 | 20/01/94 | 592 | |
- | 1.3 | 28/01/94 | 504 | added missing FreeArgs() |
- | 1.4 | 04/02/94 | 584 | added INFO switch |
- +---------+----------+---------+--------------------------+
- */
-
- #include <string.h>
-
- #include <clib/alib_protos.h>
- #include <clib/commodities_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/exec_protos.h>
-
- #include <pragmas/commodities_pragmas.h>
- #include <pragmas/dos_pragmas.h>
- #include <pragmas/exec_pragmas.h>
-
- #define TEMPLATE "CXNAME/M,DISABLE/S,ENABLE/S,APPEAR/S,DISAPPEAR/S,KILL/S,UNIQUE/S,INFO/S"
-
- #define OPT_CXNAME 0
- #define OPT_DISABLE 1
- #define OPT_ENABLE 2
- #define OPT_APPEAR 3
- #define OPT_DISAPPEAR 4
- #define OPT_KILL 5
- #define OPT_UNIQUE 6
- #define OPT_INFO 7
-
- #define OPT_COUNT 8
-
- /*****************************************************************/
- /* The following definitions have been found in the MUI-Exchange */
- /* source code (written by Klaus Melchior) */
- /*****************************************************************/
-
- /*** commodities.library private functions ***/
- #pragma libcall CxBase CopyBrokerList ba 801
- #pragma libcall CxBase FreeBrokerList c0 801
- #pragma libcall CxBase BrokerCommand c6 802
-
- LONG CopyBrokerList(struct List *);
- LONG FreeBrokerList(struct List *);
- LONG BrokerCommand(BYTE *,LONG);
-
- /*** private structures ***/
- struct BrokerCopy {
- struct Node bc_Node;
- char bc_Name[CBD_NAMELEN];
- char bc_Title[CBD_TITLELEN];
- char bc_Descr[CBD_DESCRLEN];
- LONG bc_Task;
- LONG bc_Dummy1;
- LONG bc_Dummy2;
- UWORD bc_Flags;
- };
-
- LONG
- CLIExchange (VOID)
- {
- struct DosLibrary *DOSBase;
- struct Library *CxBase;
- struct RDArgs *rdargs;
- struct Node *n,*nn;
- struct List l;
- LONG i,cmd,opts[OPT_COUNT],rc = RETURN_FAIL;
- UBYTE *name,*title,*descr,**argptr,
- *version = "$VER:CLIExchange 1.4 (4.2.94)";
-
- /* before bothering with anything else, open the libraries we need */
- DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",36L);
- CxBase = OpenLibrary("commodities.library",36L);
-
- if (DOSBase && CxBase) {
- memset(opts,NULL,sizeof(opts));
-
- /* parse the command line */
- if (rdargs = ReadArgs(TEMPLATE,opts,NULL)) {
- /* find out which option the user has set */
- for (i=OPT_DISABLE; !opts[i] && i<OPT_INFO; i++);
- if (i<OPT_INFO) cmd = CXCMD_DISABLE+2*i-2;
-
- NewList(&l);
- CopyBrokerList(&l);
-
- for (n = l.lh_Head; n && (nn = n->ln_Succ); n = nn) {
- name = ((struct BrokerCopy *)n)->bc_Name;
-
- if (opts[OPT_CXNAME]) {
- for (argptr = (BYTE **)opts[OPT_CXNAME]; *argptr && strcmp(*argptr,name); *argptr++);
- if (!*argptr) continue;
- }
-
- if (opts[OPT_INFO]) {
- title = ((struct BrokerCopy *)n)->bc_Title;
- descr = ((struct BrokerCopy *)n)->bc_Descr;
-
- Printf("%-39s:%s\n",title,descr);
- }
- else if (i != OPT_INFO) BrokerCommand(name,cmd);
- else if (!opts[OPT_CXNAME]) Printf("%s\n",name);
- }
-
- FreeBrokerList(&l);
- FreeArgs(rdargs);
- rc = RETURN_OK;
- }
- else PrintFault(IoErr(),NULL);
- }
- CloseLibrary(CxBase);
- CloseLibrary((struct Library *)DOSBase);
- return(rc);
- }
-