home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / examples / add / baserel / CED_Support.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  4.6 KB  |  217 lines

  1. /*-- Rev Header - do NOT edit!
  2.  *
  3.  *  Filename : CED_Support.c
  4.  *  Purpose  : Einige Hilfsroutinen für CED
  5.  *
  6.  *  Program  : -
  7.  *  Author   : Gerhard Müller
  8.  *  Copyright: (c) by Gerhard Müller
  9.  *  Creation : Fri Sep 10 00:41:01 1993
  10.  *
  11.  *  compile  : makefile
  12.  *
  13.  *  Compile version  : 0.1
  14.  *  Ext. Version     : 0.1
  15.  *
  16.  *  REVISION HISTORY
  17.  *
  18.  *  Date                     Comment
  19.  *  ------------------------ -------------------------------------------------
  20.  *  Fri Sep 17 00:34:04 1993 Taken from CED_Help, works only with CED 3.5 and
  21.  *                           above
  22.  *
  23.  *
  24.  *
  25.  *-- REV_END --
  26.  */
  27.  
  28.     /*
  29.      * C-Includes, C-Definitionen
  30.      *
  31.      */
  32.  
  33. #include <exec/types.h>
  34. #include <exec/ports.h>
  35. #include <exec/memory.h>
  36. #include <dos/dos.h>
  37. #include <dos/dosextens.h>
  38. #include <dos/exall.h>
  39. #include <clib/alib_protos.h>
  40. #include <clib/alib_stdio_protos.h>
  41. #include <rexx/storage.h>
  42. #include <inline/stubs.h>
  43. #ifdef __OPTIMIZE__
  44. #include <inline/exec.h>
  45. #include <inline/dos.h>
  46. #else
  47. #include <clib/exec_protos.h>
  48. #include <clib/dos_protos.h>
  49. #endif
  50.  
  51. #include "CED_Support.h"
  52.  
  53. struct RexxMsg    TheMessage;
  54.  
  55.  
  56. /*
  57.     This   routine   sends   an   ascii   string  command  to  CygnusEd
  58. Professional.   It  deals with the messy business of setting up the message
  59. etc.   It  returns  TRUE or FALSE to say whether or not the send succeeded.
  60. Any  error  codes  from  CygnusEd  Professional  will  be  returned  in the
  61. rm_Result1 field of the message.
  62.  
  63. */
  64.  
  65. BOOL SendCygnusEdMessage(char *thecommand)
  66. {
  67.     struct MsgPort    *CedPort, *MyPort;
  68.  
  69.     TheMessage.rm_Args[0] = (STRPTR)thecommand;
  70.     TheMessage.rm_Node.mn_Node.ln_Type = NT_MESSAGE;
  71.     TheMessage.rm_Node.mn_Length = sizeof(struct RexxMsg);
  72.     TheMessage.rm_Action = 0;    /* We don't want results. */
  73.     TheMessage.rm_Result2 = 0;    /* clear out the last result. */
  74.  
  75.     Forbid();
  76.  
  77.     if (!(CedPort = FindPort((UBYTE *)"rexx_ced")))
  78.     {
  79.         Permit();
  80.         return((BOOL)FALSE);
  81.     }
  82.  
  83.     if (!(MyPort = CreateMsgPort())) {
  84.         Permit();
  85.         return((BOOL)FALSE);
  86.     }
  87.  
  88.     TheMessage.rm_Node.mn_ReplyPort = MyPort;
  89.     PutMsg(CedPort, (struct Message *)&TheMessage.rm_Node);
  90.     WaitPort(MyPort);
  91.     DeleteMsgPort(MyPort);
  92.     Permit();
  93.     return((BOOL)TRUE);
  94. }
  95.  
  96.  
  97.  
  98. /*
  99.     This  routine is used for sending commands to CygnusEd Professional
  100. when you want a response.  Certain commands, such as the status command can
  101. return  strings  or  numbers  telling  you  something  about the success or
  102. failure  of the command or about the internal status of the editor.  If the
  103. command  returns  a string, you are responsible for freeing the memory used
  104. to  store  the  string.   The  FreeMyString  command  is  provided for this
  105. purpose.
  106.  
  107. */
  108.  
  109. BOOL SendCygnusEdMessageGetReply(char *thecommand)
  110. {
  111.     struct MsgPort    *CedPort, *MyPort;
  112.  
  113.     TheMessage.rm_Args[0] = (STRPTR)thecommand;
  114.     TheMessage.rm_Node.mn_Node.ln_Type = NT_MESSAGE;
  115.     TheMessage.rm_Node.mn_Length = sizeof(struct RexxMsg);
  116.     TheMessage.rm_Action = 1L << RXFB_RESULT;    /* We do want results. */
  117.     TheMessage.rm_Result2 = 0;    /* clear out the last result. */
  118.  
  119.     Forbid();
  120.     if (!(CedPort = FindPort((UBYTE *)"rexx_ced")))
  121.     {
  122.         Permit();
  123.         return((BOOL)FALSE);
  124.     }
  125.  
  126.     if (!(MyPort = CreateMsgPort()))
  127.     {
  128.         Permit();
  129.         return((BOOL)FALSE);
  130.     }
  131.  
  132.     TheMessage.rm_Node.mn_ReplyPort = MyPort;
  133.     PutMsg(CedPort, (struct Message *)&TheMessage.rm_Node);
  134.     WaitPort(MyPort);
  135.     DeleteMsgPort(MyPort);
  136.     Permit();
  137.     return((BOOL)TRUE);
  138. }
  139.  
  140.  
  141.  
  142.     /*
  143.      * char *GetStringFromArexx();
  144.      *
  145.      * Function that gets a string from CED. Allocates the memory via AllocVec.
  146.      * The user is responsible for calling FreeVec !
  147.      *
  148.      */
  149.  
  150.  
  151. char *GetStringFromArexx()
  152. {
  153.     struct RexxArg *rexxarg;
  154.     char *mem=0;
  155.  
  156.     if(TheMessage.rm_Result2)
  157.     {
  158.         rexxarg=(struct RexxArg *)(TheMessage.rm_Result2 -8);
  159.         mem=(char *)AllocVec(rexxarg->ra_Length+1,MEMF_CLEAR);
  160.         if(mem)
  161.         {
  162.             CopyMem((char *)TheMessage.rm_Result2,mem,rexxarg->ra_Length);
  163.         }
  164.         if(rexxarg->ra_Size)
  165.             FreeMem(rexxarg, rexxarg->ra_Size);
  166.     }
  167.     return mem;
  168. }
  169.  
  170.  
  171.     /*
  172.      * BOOL GetNumberFromArexx(LONG *number)
  173.      *
  174.      * Gets a number from CED.
  175.      *
  176.      */
  177.  
  178.  
  179. BOOL GetNumberFromArexx(LONG *number)
  180. {
  181.     struct RexxArg *rexxarg;
  182.  
  183.     if(TheMessage.rm_Result2)
  184.     {
  185.         StrToLong((UBYTE *)TheMessage.rm_Result2,number);
  186.  
  187.         rexxarg=(struct RexxArg *)(TheMessage.rm_Result2 -8);
  188.         if(rexxarg->ra_Size)
  189.             FreeMem(rexxarg, rexxarg->ra_Size);
  190.         return TRUE;
  191.     }
  192.     else return FALSE;
  193. }
  194.  
  195.  
  196.  
  197.     /*
  198.      * void GetNothingFromArexx()
  199.      *
  200.      * Frees memory occupied via a call to CED through
  201.      * SendCygnusEdMessageGetReply(char *thecommand);
  202.      *
  203.      */
  204.  
  205.  
  206. void GetNothingFromArexx()
  207. {
  208.     struct RexxArg *rexxarg;
  209.  
  210.     if(TheMessage.rm_Result2)
  211.     {
  212.         rexxarg=(struct RexxArg *)(TheMessage.rm_Result2 -8);
  213.         if(rexxarg->ra_Size)
  214.             FreeMem(rexxarg, rexxarg->ra_Size);
  215.     }
  216. }
  217.