home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / dvips / amiga / rexx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-19  |  2.9 KB  |  115 lines

  1. /*
  2.  * This file "AMIGA/PASTEX/REXX.C" works in addition to `dvips'
  3.  * in that it calls an ARexx script via the `call_rexx' function
  4.  * defined below.
  5.  *
  6.  * Georg Heßmann   <hessmann@informatik.uni-hamburg.de>, 25th August 1991.
  7.  * Andreas Scherer <scherer@genesis.informatik.rwth-aachen.de>, 20th January 1994.
  8.  * Giuseppe Ghibò  <ghibo@galileo.polito.it>, 18th September 1994. Removed pragmas.
  9.  *
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <libraries/dos.h>
  14. #include <rexx/rxslib.h>
  15. #include <rexx/errors.h>
  16.  
  17. #include <proto/exec.h>
  18. #include <proto/dos.h>
  19. #include <clib/rexxsyslib_protos.h>
  20. #include <pragmas/rexxsyslib_pragmas.h>
  21.  
  22. #include <string.h>
  23. #include <dos.h>
  24. #include <rexx_protos.h>
  25.  
  26. extern struct ExecBase *SysBase;
  27. struct RxsLib *RexxSysBase = NULL;
  28.  
  29.  
  30. #define PORTNAME    "Call-MF"
  31. #define RXEXTENS    "rexx"
  32.  
  33. static int PutRexxMsg(struct MsgPort *mp, long action, STRPTR arg0,
  34.         struct RexxMsg *arg1)
  35. {
  36.   struct RexxMsg *rm;
  37.   struct MsgPort *rp;
  38.  
  39.   if ((rm = CreateRexxMsg(mp, RXEXTENS, mp->mp_Node.ln_Name)) != NULL) {
  40.     rm->rm_Action  = action;
  41.     rm->rm_Args[0] = arg0;
  42.     rm->rm_Args[1] = (STRPTR)arg1;
  43. /*    rm->rm_Stdin   = Output(); */
  44. /*    rm->rm_Stdout  = Output(); */
  45.     Forbid();
  46.     if ((rp = FindPort(RXSDIR)) != NULL) {
  47.       PutMsg(rp, (struct Message *)rm);
  48.     }
  49.     Permit();
  50.     if (rp == NULL) {
  51.       DeleteRexxMsg(rm);
  52.     }
  53.   }
  54.   return rm != NULL && rp != NULL;
  55. }
  56.  
  57. int __stdargs call_rexx(char *str, long *result)
  58. {
  59.   char *arg;
  60.   struct MsgPort *mp;
  61.   struct RexxMsg *rm, *rm2;
  62.   int ret = FALSE;
  63.   int pend;
  64.  
  65.   if (!(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME, 0 /*RXSVERS*/)))
  66.     return(ret);
  67.  
  68.   Forbid();
  69.  
  70.   if (FindPort(PORTNAME) == NULL)
  71.     mp = CreatePort(PORTNAME, 0);
  72.  
  73.   Permit();
  74.  
  75.   if (mp != NULL) {
  76.     if ((arg = CreateArgstring(str, strlen(str))) != NULL) {
  77.       if (PutRexxMsg(mp, RXCOMM | RXFF_STRING, arg, NULL)) {
  78.         for (pend = 1; pend != 0; ) {
  79.           if (WaitPort(mp) != NULL) {
  80.             while ((rm = (struct RexxMsg *)GetMsg(mp)) != NULL) {
  81.               if (rm->rm_Node.mn_Node.ln_Type == NT_REPLYMSG) {
  82.                 ret = TRUE;
  83.                 *result = rm->rm_Result1;
  84.                 if ((rm2 = (struct RexxMsg *)rm->rm_Args[1]) != NULL) {
  85.                   rm2->rm_Result1 = rm->rm_Result1;
  86.                   rm2->rm_Result2 = 0;
  87.                   ReplyMsg((struct Message *)rm2);
  88.                 }
  89.                 DeleteRexxMsg(rm);
  90.                 pend--;
  91.               }
  92.               else {
  93.                 rm->rm_Result2 = 0;
  94.                 if (PutRexxMsg(mp, rm->rm_Action, rm->rm_Args[0], rm)) {
  95.                   pend++;
  96.                 }
  97.                 else {
  98.                   rm->rm_Result1 = RC_FATAL;
  99.                   ReplyMsg((struct Message *)rm);
  100.                 }
  101.               }
  102.             }
  103.           }
  104.         } /* for */
  105.       }
  106.       DeleteArgstring(arg);
  107.     }
  108.     DeletePort(mp);
  109.   }
  110.  
  111.   CloseLibrary((struct Library *)RexxSysBase);
  112.  
  113.   return ret;
  114. }
  115.