home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d7xx / d786 / hyper.lha / Hyper / help.c < prev    next >
C/C++ Source or Header  |  1992-12-24  |  7KB  |  199 lines

  1. /*******************  help.c  ********************
  2.  *                                               *
  3.  *                                               *
  4.  *                     v1.15                     *
  5.  *                                               *
  6.  *                  © by Koessi                  *
  7.  *                                               *
  8.  *             Tuesday, 21 Nov 1992              *
  9.  *                                               *
  10.  *                                               *
  11.  *  this is an help showing the usage of         *
  12.  *  "hyper" from inside another program          *
  13.  *                                               *
  14.  *  Compile with DICE:                           *
  15.  *  dcc help.c -ohelp -rr -2.0                   *
  16.  *                                               *
  17.  *************************************************/
  18.  
  19. #include <exec/types.h>
  20. #include <exec/execbase.h>
  21. #include <exec/memory.h>
  22. #include <dos/dos.h>
  23. #include <dos/dostags.h>
  24. #include <rexx/storage.h>
  25.  
  26. /* Prototypes */
  27. #include <clib/exec_protos.h>
  28. #include <clib/dos_protos.h>
  29. #include <clib/alib_protos.h>
  30. #include <clib/rexxsyslib_protos.h>
  31.  
  32. #define  MSG struct Message
  33. #define RMSG struct RexxMsg
  34. #define MSGP struct MsgPort
  35. #define SIZE 32
  36.  
  37. extern void SendRxMsg(char *);
  38. extern __stkargs void _main(short, char *);
  39. extern int main(int, char **);
  40.  
  41. #define NUMARGS 12
  42.  
  43. const char version[]    = {'$','V','E','R',':',' ' };
  44. const char taskname[]   = "Help  v1.15 © Koessi 92 - Funware\n";
  45. const char exthelpstr[] = "›32mUsage:\tHelp [FILENAME] [DOC chapter]"
  46.                                            "[SCREEN publicscreen]\n"
  47.                           "\t\t[X n] [Y n] [WIDTH n] [HEIGHT n] [GADS ON|OFF]\n"
  48.                           "\t\t[FONT name.font<n>] [SLEEP] [QUIT]›0m\n"
  49.                           "\n\tcall Hyper (>= Ver1.15) via its ARexx-port:\n"
  50.                           "\tFILENAME\tshould be a hyper-text-file\n"
  51.                           "\tDOC/K\t\trequest a special chapter\n"
  52.                           "\tSCREEN/K\tmake Hyper appear on that screen\n"
  53.                           "\tX/N, Y/N\n"
  54.                           "\tW=WIDTH/N\n"
  55.                           "\tH=HEIGHT/N\tset position&size for the window\n"
  56.                           "\tG=GADS/T\ttoggle gadgets ON/OFF (default is OFF)\n"
  57.                           "\tF=FONT/K\tuse this font to render text (default is \"pearl.font8\")\n"
  58.                           "\tonly if Hyper is already running:\n"
  59.                           "\tS=SLEEP/S\tstart Hyper into the background\n"
  60.                           "\tQ=QUIT/S\tend Hyper and free memory\n"
  61.                           "\t\t\t";
  62.  
  63. const char template[]   = "FILENAME,DOC/K,SCREEN/K,X/N,Y/N,W=WIDTH/N,H=HEIGHT/N,"
  64.                           "G=GADS/T,F=FONT/K,S=SLEEP/S,Q=QUIT/S";
  65. const char portname[]   = "HYPER_RXPORT";
  66. const char command[]    = "SYS:Utilities/hyper S";
  67. const char error[]      = "\n\n›32m***ERROR›0m";
  68.  
  69. const void *argarray[NUMARGS] = {0};                  /*  holds argptrs   */
  70.  
  71.  
  72. /*************************************************
  73.  *                                               *
  74.  *                                               *
  75.  *    FUNCTION: _main                            *
  76.  *                                               *
  77.  *                                               *
  78.  *    INPUT:    short len                        *
  79.  *              char *arg                        *
  80.  *                                               *
  81.  *    OUTPUT:   __stkargs void                   *
  82.  *                                               *
  83.  *    NOTE:                                      *
  84.  *                                               *
  85.  *************************************************/
  86.  
  87.  
  88. __stkargs void
  89. _main(short len, char *arg)
  90. {
  91.   PutStr(taskname);
  92.   int errorcode = ERROR_REQUIRED_ARG_MISSING;
  93.   if (len > 1)          /*  args ? */
  94.   {
  95.     struct RDArgs *rdargs;
  96.     if (rdargs = AllocVec(sizeof(struct RDArgs), MEMF_PUBLIC|MEMF_CLEAR))
  97.     {
  98.       rdargs->RDA_ExtHelp = exthelpstr;   /*  shown if 2 x ? */
  99.  
  100.       struct RDArgs *rda;
  101.       if (rda = ReadArgs(template, argarray, rdargs))
  102.       {
  103.         long **argptr = argarray;
  104.         for (BYTE i = 0; i < NUMARGS; ++i)
  105.         {
  106.           if (argptr && *argptr)
  107.           {
  108.             errorcode = RETURN_OK;
  109.             break;
  110.           }
  111.           ++argptr;
  112.         }
  113.         if (errorcode == RETURN_OK)
  114.         {
  115.           MSGP *port;
  116.           if (!(port = FindPort(portname)))
  117.           {
  118.             SystemTags(command, SYS_Asynch, TRUE,
  119.                                 SYS_Output, NULL,
  120.                                 SYS_Input,  NULL,
  121.                                 TAG_DONE);
  122.  
  123.             for (BYTE i = 10; i; --i)
  124.             {
  125.               Delay(20);
  126.               if (port = FindPort(portname))
  127.                 break;
  128.             }
  129.           }
  130.           PutStr("\n");
  131.           if (port)
  132.             SendRxMsg(arg);
  133.           else
  134.             PrintFault(ERROR_OBJECT_NOT_FOUND, portname);
  135.         }
  136.         FreeArgs(rda);
  137.       }
  138.       else
  139.         errorcode = IoErr();
  140.  
  141.       FreeVec(rdargs);
  142.     }
  143.     else
  144.       errorcode = ERROR_NO_FREE_STORE;
  145.   }
  146.   if (errorcode)
  147.   {
  148.     PutStr(exthelpstr);
  149.     PrintFault(errorcode, error);
  150.   }
  151. }
  152.  
  153. /*************************************************
  154.  *                                               *
  155.  *                                               *
  156.  *    FUNCTION: SendRxMsg                        *
  157.  *                                               *
  158.  *                                               *
  159.  *    INPUT:    char *msgtxt                     *
  160.  *                                               *
  161.  *    OUTPUT:   void                             *
  162.  *                                               *
  163.  *    NOTE:     like cmdline                     *
  164.  *                                               *
  165.  *************************************************/
  166.  
  167.  
  168. void
  169. SendRxMsg(char *msgtxt)
  170. {
  171.   MSGP *reply_port;
  172.   if (reply_port = CreateMsgPort())
  173.   {
  174.     void *rx_msg;       /*  casted to parts of a RexxMsg struct */
  175.     if (rx_msg = AllocVec(sizeof(RMSG), MEMF_PUBLIC|MEMF_CLEAR))
  176.     {
  177.       ((struct Node *)rx_msg)->ln_Type      = NT_MESSAGE;
  178.       ((MSG         *)rx_msg)->mn_ReplyPort = reply_port;
  179.       ((MSG         *)rx_msg)->mn_Length    = sizeof(RMSG);
  180.       ((RMSG        *)rx_msg)->rm_Args[0]   = msgtxt;
  181.  
  182.       Forbid();
  183.       MSGP *rx_port;
  184.       if (rx_port = (MSGP *)FindPort(portname))
  185.       {
  186.         PutMsg(rx_port, (MSG *)rx_msg);
  187.         Permit();
  188.         WaitPort(reply_port);
  189.         ReplyMsg(GetMsg(reply_port));
  190.       }
  191.       else
  192.         Permit();
  193.  
  194.       FreeVec(rx_msg);
  195.     }
  196.     DeleteMsgPort(reply_port);
  197.   }
  198. }
  199.