home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / thesrc15.zip / rexx.c < prev    next >
C/C++ Source or Header  |  1993-11-26  |  29KB  |  759 lines

  1. /***********************************************************************/
  2. /* REXX.C - REXX interface routines.                                   */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1993 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 5314
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38.  
  39. /*
  40. $Header: C:\THE\RCS\rexx.c 1.4 1993/09/01 16:27:12 MH Interim MH $
  41. */
  42.  
  43. #if !defined(NOREXX)
  44. /*--------------------------- global data -----------------------------*/
  45. /* these are here because EMX include REXX definitions from within os2.h */
  46. /*---------------------------------------------------------------------*/
  47. #  define INCL_RXSUBCOM       /* Subcommand handler values */
  48. #  define INCL_RXSHV          /* Shared variable support */
  49. #  define INCL_RXSYSEXIT      /* System exit routines */
  50. #  define INCL_DOSPROCESS     /* Process/Thread Info */
  51. #  define INCL_RXFUNC         /* External functions */
  52.  
  53. #include "the.h"
  54. #include "proto.h"
  55. #include "query.h"
  56. #include "rexx.h"
  57.  
  58. RexxSubcomHandler THE_Commands;
  59. RexxExitHandler THE_Exit_Handler;
  60. RexxFunctionHandler THE_Function_Handler;
  61.  
  62. FILE *rexxoutfp;
  63. static unsigned short y,x;
  64. static long captured_lines;
  65. static bool rexx_halted;
  66.  
  67.  
  68. struct function_item
  69.  {
  70.   char *name;                      /* name of item */
  71.   int item_number;                  /* unique number for item */
  72.   int item_index;                  /* index value for the whole item */
  73.   char query;                         /* valid query response ? */
  74.  };
  75. typedef struct function_item FUNCTION_ITEM;
  76.  
  77.  static FUNCTION_ITEM item[] =
  78.   {
  79.    {"ALT.0",ITEM_ALT,0,QUERY_FUNCTION},
  80.    {"ALT.1",ITEM_ALT,1,QUERY_FUNCTION},
  81.    {"ALT.2",ITEM_ALT,2,QUERY_FUNCTION},
  82.    {"ARBCHAR.0",ITEM_ARBCHAR,0,QUERY_FUNCTION},
  83.    {"ARBCHAR.1",ITEM_ARBCHAR,1,QUERY_FUNCTION},
  84.    {"ARBCHAR.2",ITEM_ARBCHAR,2,QUERY_FUNCTION},
  85.    {"AUTOSAVE.0",ITEM_AUTOSAVE,0,QUERY_FUNCTION},
  86.    {"AUTOSAVE.1",ITEM_AUTOSAVE,1,QUERY_FUNCTION},
  87.    {"BACKUP.0",ITEM_BACKUP,0,QUERY_FUNCTION},
  88.    {"BACKUP.1",ITEM_BACKUP,1,QUERY_FUNCTION},
  89.    {"BEEP.0",ITEM_BEEP,0,QUERY_FUNCTION},
  90.    {"BEEP.1",ITEM_BEEP,1,QUERY_FUNCTION},
  91.    {"BLOCK.0",ITEM_BLOCK,0,QUERY_FUNCTION},
  92.    {"BLOCK.1",ITEM_BLOCK,1,QUERY_FUNCTION},
  93.    {"BLOCK.2",ITEM_BLOCK,2,QUERY_FUNCTION},
  94.    {"BLOCK.3",ITEM_BLOCK,3,QUERY_FUNCTION},
  95.    {"BLOCK.4",ITEM_BLOCK,4,QUERY_FUNCTION},
  96.    {"BLOCK.5",ITEM_BLOCK,5,QUERY_FUNCTION},
  97.    {"BLOCK.6",ITEM_BLOCK,6,QUERY_FUNCTION},
  98.    {"CASE.0",ITEM_CASE,0,QUERY_FUNCTION},
  99.    {"CASE.1",ITEM_CASE,1,QUERY_FUNCTION},
  100.    {"CASE.2",ITEM_CASE,2,QUERY_FUNCTION},
  101.    {"CASE.3",ITEM_CASE,3,QUERY_FUNCTION},
  102.    {"CASE.4",ITEM_CASE,4,QUERY_FUNCTION},
  103.    {"CLEARSCREEN.0",ITEM_CLEARSCREEN,0,QUERY_FUNCTION},
  104.    {"CLEARSCREEN.1",ITEM_CLEARSCREEN,1,QUERY_FUNCTION},
  105.    {"CLOCK.0",ITEM_CLOCK,0,QUERY_FUNCTION},
  106.    {"CLOCK.1",ITEM_CLOCK,1,QUERY_FUNCTION},
  107.    {"CMDARROWS.0",ITEM_CMDARROWS,0,QUERY_FUNCTION},
  108.    {"CMDARROWS.1",ITEM_CMDARROWS,1,QUERY_FUNCTION},
  109.    {"CMDARROWS.2",ITEM_CMDARROWS,2,QUERY_FUNCTION},
  110.    {"CMDARROWS.3",ITEM_CMDARROWS,3,QUERY_FUNCTION},
  111.    {"CMDLINE.0",ITEM_CMDLINE,0,QUERY_FUNCTION},
  112.    {"CMDLINE.1",ITEM_CMDLINE,1,QUERY_FUNCTION},
  113.    {"CMDLINE.2",ITEM_CMDLINE,2,QUERY_FUNCTION},
  114.    {"CURLINE.0",ITEM_CURLINE,0,QUERY_FUNCTION},
  115.    {"CURLINE.1",ITEM_CURLINE,1,QUERY_FUNCTION},
  116.    {"CURLINE.2",ITEM_CURLINE,2,QUERY_FUNCTION},
  117.    {"CURLINE.3",ITEM_CURLINE,3,QUERY_FUNCTION},
  118.    {"DIRFILEID.0",ITEM_DIRFILEID,0,QUERY_FUNCTION},
  119.    {"DIRFILEID.1",ITEM_DIRFILEID,1,QUERY_FUNCTION},
  120.    {"DIRFILEID.2",ITEM_DIRFILEID,2,QUERY_FUNCTION},
  121.    {"EOF.0",ITEM_EOF,0,QUERY_FUNCTION},
  122.    {"EOF.1",ITEM_EOF,1,QUERY_FUNCTION},
  123.    {"EOLOUT.0",ITEM_EOLOUT,0,QUERY_FUNCTION},
  124.    {"EOLOUT.1",ITEM_EOLOUT,1,QUERY_FUNCTION},
  125.    {"ETMODE.0",ITEM_ETMODE,0,QUERY_FUNCTION},
  126.    {"ETMODE.1",ITEM_ETMODE,1,QUERY_FUNCTION},
  127.    {"FNAME.0",ITEM_FNAME,0,QUERY_FUNCTION},
  128.    {"FNAME.1",ITEM_FNAME,1,QUERY_FUNCTION},
  129.    {"FPATH.0",ITEM_FPATH,0,QUERY_FUNCTION},
  130.    {"FPATH.1",ITEM_FPATH,1,QUERY_FUNCTION},
  131.    {"FTYPE.0",ITEM_FTYPE,0,QUERY_FUNCTION},
  132.    {"FTYPE.1",ITEM_FTYPE,1,QUERY_FUNCTION},
  133.    {"GETENV.0",ITEM_GETENV,0,QUERY_FUNCTION},
  134.    {"GETENV.1",ITEM_GETENV,1,QUERY_FUNCTION},
  135.    {"HEX.0",ITEM_HEX,0,QUERY_FUNCTION},
  136.    {"HEX.1",ITEM_HEX,1,QUERY_FUNCTION},
  137.    {"HEXDISPLAY.0",ITEM_HEXDISPLAY,0,QUERY_FUNCTION},
  138.    {"HEXDISPLAY.1",ITEM_HEXDISPLAY,1,QUERY_FUNCTION},
  139.    {"IMPMACRO.0",ITEM_IMPMACRO,0,QUERY_FUNCTION},
  140.    {"IMPMACRO.1",ITEM_IMPMACRO,1,QUERY_FUNCTION},
  141.    {"IMPMOS.0",ITEM_IMPOS,0,QUERY_FUNCTION},
  142.    {"IMPMOS.1",ITEM_IMPOS,1,QUERY_FUNCTION},
  143.    {"INSERTMODE.0",ITEM_INSERTMODE,0,QUERY_FUNCTION},
  144.    {"INSERTMODE.1",ITEM_INSERTMODE,1,QUERY_FUNCTION},
  145.    {"LASTMSG.0",ITEM_LASTMSG,0,QUERY_FUNCTION},
  146.    {"LASTMSG.1",ITEM_LASTMSG,1,QUERY_FUNCTION},
  147.    {"LASTRC.0",ITEM_LASTRC,0,QUERY_FUNCTION},
  148.    {"LASTRC.1",ITEM_LASTRC,1,QUERY_FUNCTION},
  149.    {"LENGTH.0",ITEM_LENGTH,0,QUERY_FUNCTION},
  150.    {"LENGTH.1",ITEM_LENGTH,1,QUERY_FUNCTION},
  151.    {"LINE.0",ITEM_LINE,0,QUERY_FUNCTION},
  152.    {"LINE.1",ITEM_LINE,1,QUERY_FUNCTION},
  153.    {"LINEND.0",ITEM_LINEND,0,QUERY_FUNCTION},
  154.    {"LINEND.1",ITEM_LINEND,1,QUERY_FUNCTION},
  155.    {"LINEND.2",ITEM_LINEND,2,QUERY_FUNCTION},
  156.    {"MACROEXT.0",ITEM_MACROEXT,0,QUERY_FUNCTION},
  157.    {"MACROEXT.1",ITEM_MACROEXT,1,QUERY_FUNCTION},
  158.    {"MACROPATH.0",ITEM_MACROPATH,0,QUERY_FUNCTION},
  159.    {"MACROPATH.1",ITEM_MACROPATH,1,QUERY_FUNCTION},
  160.    {"MARGINS.0",ITEM_MARGINS,0,QUERY_FUNCTION},
  161.    {"MARGINS.1",ITEM_MARGINS,1,QUERY_FUNCTION},
  162.    {"MARGINS.2",ITEM_MARGINS,2,QUERY_FUNCTION},
  163.    {"MARGINS.3",ITEM_MARGINS,3,QUERY_FUNCTION},
  164.    {"MONITOR.0",ITEM_MONITOR,0,QUERY_FUNCTION},
  165.    {"MONITOR.1",ITEM_MONITOR,1,QUERY_FUNCTION},
  166.    {"MONITOR.2",ITEM_MONITOR,2,QUERY_FUNCTION},
  167.    {"MSGMODE.0",ITEM_MSGMODE,0,QUERY_FUNCTION},
  168.    {"MSGMODE.1",ITEM_MSGMODE,1,QUERY_FUNCTION},
  169.    {"NBFILE.0",ITEM_NBFILE,0,QUERY_FUNCTION},
  170.    {"NBFILE.1",ITEM_NBFILE,1,QUERY_FUNCTION},
  171.    {"NEWLINES.0",ITEM_NEWLINES,0,QUERY_FUNCTION},
  172.    {"NEWLINES.1",ITEM_NEWLINES,1,QUERY_FUNCTION},
  173.    {"NONDISP.0",ITEM_NONDISP,0,QUERY_FUNCTION},
  174.    {"NONDISP.1",ITEM_NONDISP,1,QUERY_FUNCTION},
  175.    {"NUMBER.0",ITEM_NUMBER,0,QUERY_FUNCTION},
  176.    {"NUMBER.1",ITEM_NUMBER,1,QUERY_FUNCTION},
  177.    {"PREFIX.0",ITEM_PREFIX,0,QUERY_FUNCTION},
  178.    {"PREFIX.1",ITEM_PREFIX,1,QUERY_FUNCTION},
  179.    {"PREFIX.2",ITEM_PREFIX,2,QUERY_FUNCTION},
  180.    {"PRINTER.0",ITEM_PRINTER,0,QUERY_FUNCTION},
  181.    {"PRINTER.1",ITEM_PRINTER,1,QUERY_FUNCTION},
  182.    {"REPROFILE.0",ITEM_REPROFILE,0,QUERY_FUNCTION},
  183.    {"REPROFILE.1",ITEM_REPROFILE,1,QUERY_FUNCTION},
  184.    {"REXXOUTPUT.0",ITEM_REXXOUTPUT,0,QUERY_FUNCTION},
  185.    {"REXXOUTPUT.1",ITEM_REXXOUTPUT,1,QUERY_FUNCTION},
  186.    {"REXXOUTPUT.2",ITEM_REXXOUTPUT,2,QUERY_FUNCTION},
  187.    {"SIZE.0",ITEM_SIZE,0,QUERY_FUNCTION},
  188.    {"SIZE.1",ITEM_SIZE,1,QUERY_FUNCTION},
  189.    {"STAY.0",ITEM_STAY,0,QUERY_FUNCTION},
  190.    {"STAY.1",ITEM_STAY,1,QUERY_FUNCTION},
  191.    {"TABKEY.0",ITEM_TABKEY,0,QUERY_FUNCTION},
  192.    {"TABKEY.1",ITEM_TABKEY,1,QUERY_FUNCTION},
  193.    {"TABKEY.2",ITEM_TABKEY,2,QUERY_FUNCTION},
  194.    {"TABS.0",ITEM_TABS,0,QUERY_FUNCTION},
  195.    {"TABS.1",ITEM_TABS,1,QUERY_FUNCTION},
  196.    {"TABSIN.0",ITEM_TABSIN,0,QUERY_FUNCTION},
  197.    {"TABSIN.1",ITEM_TABSIN,1,QUERY_FUNCTION},
  198.    {"TABSIN.2",ITEM_TABSIN,2,QUERY_FUNCTION},
  199.    {"TABSOUT.0",ITEM_TABSOUT,0,QUERY_FUNCTION},
  200.    {"TABSOUT.1",ITEM_TABSOUT,1,QUERY_FUNCTION},
  201.    {"TABSOUT.2",ITEM_TABSOUT,2,QUERY_FUNCTION},
  202.    {"TERMINAL.0",ITEM_TERMINAL,0,QUERY_FUNCTION},
  203.    {"TERMINAL.1",ITEM_TERMINAL,1,QUERY_FUNCTION},
  204.    {"TOF.0",ITEM_TOF,0,QUERY_FUNCTION},
  205.    {"TOF.1",ITEM_TOF,1,QUERY_FUNCTION},
  206.    {"VERIFY.0",ITEM_VERIFY,0,QUERY_FUNCTION},
  207.    {"VERIFY.1",ITEM_VERIFY,1,QUERY_FUNCTION},
  208.    {"VERSION.0",ITEM_VERSION,0,QUERY_FUNCTION},
  209.    {"VERSION.1",ITEM_VERSION,1,QUERY_FUNCTION},
  210.    {"VERSION.2",ITEM_VERSION,2,QUERY_FUNCTION},
  211.    {"VERSION.3",ITEM_VERSION,3,QUERY_FUNCTION},
  212.    {"VERSION.4",ITEM_VERSION,4,QUERY_FUNCTION},
  213.    {"WIDTH.0",ITEM_WIDTH,0,QUERY_FUNCTION},
  214.    {"WIDTH.1",ITEM_WIDTH,1,QUERY_FUNCTION},
  215.    {"WORDWRAP.0",ITEM_WORDWRAP,0,QUERY_FUNCTION},
  216.    {"WORDWRAP.1",ITEM_WORDWRAP,1,QUERY_FUNCTION},
  217.    {"ZONE.0",ITEM_ZONE,0,QUERY_FUNCTION},
  218.    {"ZONE.1",ITEM_ZONE,1,QUERY_FUNCTION},
  219.    {"ZONE.2",ITEM_ZONE,2,QUERY_FUNCTION},
  220.    {"AFTER",ITEM_AFTER_FUNCTION,1,QUERY_FUNCTION},
  221.    {"BEFORE",ITEM_BEFORE_FUNCTION,1,QUERY_FUNCTION},
  222.    {"BLANK",ITEM_BLANK_FUNCTION,1,QUERY_FUNCTION},
  223.    {"BLOCK",ITEM_BLOCK_FUNCTION,1,QUERY_FUNCTION},
  224.    {"BOTTOMEDGE",ITEM_BOTTOMEDGE_FUNCTION,1,QUERY_FUNCTION},
  225.    {"COMMAND",ITEM_COMMAND_FUNCTION,1,QUERY_FUNCTION},
  226.    {"CURRENT",ITEM_CURRENT_FUNCTION,1,QUERY_FUNCTION},
  227.    {"DIR",ITEM_DIR_FUNCTION,1,QUERY_FUNCTION},
  228.    {"END",ITEM_END_FUNCTION,1,QUERY_FUNCTION},
  229.    {"EOF",ITEM_EOF_FUNCTION,1,QUERY_FUNCTION},
  230.    {"FIRST",ITEM_FIRST_FUNCTION,1,QUERY_FUNCTION},
  231.    {"FOCUSEOF",ITEM_FOCUSEOF_FUNCTION,1,QUERY_FUNCTION},
  232.    {"FOCUSTOF",ITEM_FOCUSTOF_FUNCTION,1,QUERY_FUNCTION},
  233.    {"INBLOCK",ITEM_INBLOCK_FUNCTION,1,QUERY_FUNCTION},
  234.    {"INITIAL",ITEM_INITIAL_FUNCTION,1,QUERY_FUNCTION},
  235.    {"INPREFIX",ITEM_INPREFIX_FUNCTION,1,QUERY_FUNCTION},
  236.    {"LEFTEDGE",ITEM_LEFTEDGE_FUNCTION,1,QUERY_FUNCTION},
  237.    {"MODIFIABLE",ITEM_MODIFIABLE_FUNCTION,1,QUERY_FUNCTION},
  238.    {"RIGHTEDGE",ITEM_RIGHTEDGE_FUNCTION,1,QUERY_FUNCTION},
  239.    {"SPACECHAR",ITEM_SPACECHAR_FUNCTION,1,QUERY_FUNCTION},
  240.    {"TOF",ITEM_TOF_FUNCTION,1,QUERY_FUNCTION},
  241.    {"TOPEDGE",ITEM_TOPEDGE_FUNCTION,1,QUERY_FUNCTION},
  242.    {"VERONE",ITEM_VERONE_FUNCTION,1,QUERY_FUNCTION},
  243.    {"VALID_TARGET",ITEM_VALID_TARGET_FUNCTION,1,QUERY_FUNCTION},
  244.    {NULL,0,0,0},
  245.   };
  246.  
  247. /*-------------------------- external data ----------------------------*/
  248. extern char *temp_cmd;
  249. extern char rexx_filename[10];
  250. extern char rexx_pathname[MAX_FILE_NAME+1];
  251. extern bool CAPREXXOUTx;
  252. extern long CAPREXXMAXx;
  253. extern bool rexx_output;
  254. /***********************************************************************/
  255. ULONG THE_Commands(
  256.    PRXSTRING Command,    /* Command string passed from the caller    */
  257.    PUSHORT   Flags,      /* pointer to short for return of flags     */
  258.    PRXSTRING Retstr)     /* pointer to RXSTRING for RC return        */
  259. {
  260. /***********************************************************************/
  261. /*--------------------------- local data ------------------------------*/
  262.  int rc;
  263.  SHVBLOCK shv;
  264.  RXSTRING argstr;
  265. /*--------------------------- processing ------------------------------*/
  266.  if (allocate_temp_space(Command->strlength,TEMP_TEMP_CMD) != RC_OK)
  267.    {
  268.     display_error(30,(char *)"");
  269.     *Flags = RXSUBCOM_ERROR;       /* raise an error condition   */
  270.     sprintf(Retstr->strptr, "%d", rc);   /* format return code string  */
  271.                                          /* and set the correct length */
  272.     Retstr->strlength = strlen(Retstr->strptr);
  273.     return 0;                            /* processing completed       */
  274.    }
  275.  memcpy((char *)temp_cmd,Command->strptr,Command->strlength);
  276.  temp_cmd[Command->strlength] = '\0';
  277.  
  278.  if (strcmp("XXYYZZ",temp_cmd) == 0)
  279.    {
  280.     shv.shvnext=NULL;                     /* only one block */
  281.     shv.shvcode=RXSHV_NEXTV;              /* direct set */
  282.  
  283.     argstr.strptr=NULL;
  284.     argstr.strlength=0;
  285.     shv.shvname=argstr;
  286.     rc = 0;
  287.     while(rc != 2)
  288.      {
  289.       rc = RexxVariablePool(&shv);     /* get the next variable */
  290.       if (rc != 2)
  291.         {
  292.          sprintf(temp_cmd,"i <%s> <%s> <%d>",
  293.              shv.shvname.strptr,shv.shvvalue.strptr,shv.shvvalue.strlength);
  294.          command_line(temp_cmd,COMMAND_ONLY_FALSE);
  295.         }
  296.      }
  297.    }
  298.  else
  299.    rc = command_line(temp_cmd,COMMAND_ONLY_FALSE);
  300.  if (rc < 0)
  301.     *Flags = RXSUBCOM_ERROR;       /* raise an error condition   */
  302.  else
  303.     *Flags = RXSUBCOM_OK;            /* not found is not an error  */
  304.  
  305.  sprintf(Retstr->strptr, "%d", rc);   /* format return code string  */
  306.                                       /* and set the correct length */
  307.  Retstr->strlength = strlen(Retstr->strptr);
  308.  return 0;                            /* processing completed       */
  309. }
  310. /***********************************************************************/
  311. LONG THE_Exit_Handler(
  312.       LONG  ExitNumber,    /* code defining the exit function    */
  313.       LONG  Subfunction,   /* code defining the exit subfunction */
  314.       PEXIT ParmBlock)     /* function dependent control block   */
  315. /***********************************************************************/
  316. {
  317. /*-------------------------- external data ----------------------------*/
  318. extern VIEW_DETAILS *vd_current;
  319. extern WINDOW *foot;
  320. extern char in_profile;
  321. /*--------------------------- local data ------------------------------*/
  322.  RXSIOTRC_PARM *trc_parm = (RXSIOTRC_PARM *)ParmBlock;
  323.  LONG rc;
  324. /*--------------------------- processing ------------------------------*/
  325.  if (Subfunction != RXSIOSAY   /* ignore all but RXSIOSAY and RXSIOTRC */
  326.  &&  Subfunction != RXSIOTRC)
  327.     return(RXEXIT_NOT_HANDLED);
  328. /*---------------------------------------------------------------------*/
  329. /* If this is the first time this exit handler is called, set up the   */
  330. /* handling of the result; either open the capture file, or set the    */
  331. /* terminal out of curses mode so scrolling etc. work.                 */
  332. /*---------------------------------------------------------------------*/
  333.  if (!rexx_output)
  334.    {
  335.     rexx_output = TRUE;
  336.     if (CAPREXXOUTx)
  337.       {
  338.        strcpy(temp_cmd,rexx_pathname);
  339.        strcat(temp_cmd,rexx_filename);
  340.        rexxoutfp = fopen(temp_cmd,"w");
  341.       }
  342.     else
  343.       {
  344.        if (!in_profile)
  345.          {
  346.           wmove(foot,0,COLS-1);
  347.           wrefresh(foot);
  348.           suspend_curses();
  349.          }
  350.        printf("\n");                       /* scroll the screen 1 line */
  351.        fflush(stdout);
  352.       }
  353.    }
  354. /*---------------------------------------------------------------------*/
  355. /* If the REXX interpreter has been halted by line limit exceeded, just*/
  356. /* return to the interpreter indicating that THE is hadnling the output*/
  357. /* of messages. This is done to stop the "cluter" that comes back as   */
  358. /* the interpreter tries to tell us that it is stopping.               */
  359. /*---------------------------------------------------------------------*/
  360.  if (rexx_halted)
  361.     return(RXEXIT_HANDLED);
  362. /*---------------------------------------------------------------------*/
  363. /* If we are capturing the rexx output, print the string to the file.  */
  364. /*---------------------------------------------------------------------*/
  365.  if (CAPREXXOUTx)
  366.    {
  367.     fprintf(rexxoutfp,"%s\n",trc_parm->rxsio_string.strptr);
  368.     rc = RXEXIT_HANDLED;
  369.    }
  370.  else
  371.     rc = RXEXIT_NOT_HANDLED;
  372. /*---------------------------------------------------------------------*/
  373. /* If the number of lines processed exceeds the line limit, display our*/
  374. /* own message telling what has happened and exit with                 */
  375. /* RXEXIT_RAISE_ERROR. This tells the interpreter that it is to stop.  */
  376. /*---------------------------------------------------------------------*/
  377.  if (++captured_lines > CAPREXXMAXx)
  378.    {
  379.     if (CAPREXXOUTx)
  380.        fprintf(rexxoutfp,"THE: REXX macro halted - line limit (%d) exceeded\n",CAPREXXMAXx);
  381.     else
  382.        printf("THE: REXX macro halted - line limit (%d) exceeded\n",CAPREXXMAXx);
  383.     rc = RXEXIT_RAISE_ERROR;
  384.     rexx_halted = TRUE;
  385.    }
  386.  return(rc);
  387. }
  388. /***********************************************************************/
  389. ULONG THE_Function_Handler(
  390. #if defined(EMX)
  391.       CPSZ   FunctionName,  /* name of function */
  392.       ULONG Argc,          /* number of arguments    */
  393.       RXSTRING Argv[],     /* array of arguments in RXSTRINGs */
  394.       CPSZ   QueueName,     /* name of queue */
  395.       PRXSTRING Retstr)    /* return string   */
  396. #else
  397.       PSZ   FunctionName,  /* name of function */
  398.       ULONG Argc,          /* number of arguments    */
  399.       RXSTRING Argv[],     /* array of arguments in RXSTRINGs */
  400.       PSZ   QueueName,     /* name of queue */
  401.       PRXSTRING Retstr)    /* return string   */
  402. #endif
  403. /***********************************************************************/
  404. {
  405. /*-------------------------- external data ----------------------------*/
  406. extern VALUE item_values[MAX_VARIABLES_RETURNED];
  407. /*--------------------------- local data ------------------------------*/
  408.  ULONG rc;
  409.  register int i;
  410. /*--------------------------- processing ------------------------------*/
  411. /*---------------------------------------------------------------------*/
  412. /* Find the external function name in the array. Error if not found.   */
  413. /*---------------------------------------------------------------------*/
  414.  for (i=0;item[i].name != NULL;i++)
  415.    {
  416. /*  if (equal(FunctionName,item[i].name,strlen(FunctionName)))*/
  417.     if (memcmpi(FunctionName,item[i].name,strlen(item[i].name))==0)
  418.       {
  419.        (void)get_item_values(item[i].item_number,"",item[i].query,Argc,Argv[0].strptr,Argv[0].strlength);
  420.        Retstr->strptr = item_values[item[i].item_index].value;
  421.        Retstr->strlength = item_values[item[i].item_index].len;
  422.        return(0);
  423.        break;
  424.       }
  425.    }
  426.  return(1);                                    /* fatal error for REXX */
  427. }
  428. /***********************************************************************/
  429. #ifdef PROTO
  430. int initialise_rexx(void)
  431. #else
  432. int initialise_rexx()
  433. #endif
  434. /***********************************************************************/
  435. {
  436. /*--------------------------- local data ------------------------------*/
  437.  APIRET rc;
  438.  register int i;
  439. /*--------------------------- processing ------------------------------*/
  440. #ifdef TRACE
  441.  trace_function("rexx.c:    initialise_rexx");
  442. #endif
  443.  
  444. #if defined(USE_AIXREXX)
  445.  rc = RexxRegisterSubcom((PSZ)"THE",
  446.                          (PRXSUBCOM)&THE_Commands,
  447.                          (PUCHAR)NULL);
  448. #else
  449.  rc = RexxRegisterSubcomExe((PSZ)"THE",
  450.                            (PFN)&THE_Commands,
  451.                            (PUCHAR)NULL);
  452. #endif
  453.  
  454.  if (rc != RXSUBCOM_OK)
  455.     return((int)rc);
  456.  
  457. #if defined(USE_AIXREXX)
  458.  rc = RexxRegisterExit((PSZ)"THE_EXIT",
  459.                        (PRXEXIT)&THE_Exit_Handler,
  460.                        (PUCHAR)NULL);
  461. #else
  462.  rc = RexxRegisterExitExe((PSZ)"THE_EXIT",
  463.                           (PFN)&THE_Exit_Handler,
  464.                           (PUCHAR)NULL);
  465. #endif
  466.  if (rc != RXEXIT_OK)
  467.     return((int)rc);
  468.  
  469.  for (i=0;item[i].name != NULL;i++)
  470.    {
  471. #if defined(USE_AIXREXX)
  472.     rc = RexxRegisterFunction((PSZ)item[i].name,
  473.                               (PRXFUNC)&THE_Function_Handler);
  474. #else
  475.     rc = RexxRegisterFunctionExe((PSZ)item[i].name,
  476.                                  (PFN)&THE_Function_Handler);
  477. #endif
  478.     if (rc != RXFUNC_OK)
  479.        return((int)rc);
  480.    }
  481.  
  482. #ifdef TRACE
  483.  trace_return();
  484. #endif
  485.  return((int)rc);
  486. }
  487. /***********************************************************************/
  488. #ifdef PROTO
  489. int finalise_rexx(void)
  490. #else
  491. int finalise_rexx()
  492. #endif
  493. /***********************************************************************/
  494. {
  495. /*--------------------------- local data ------------------------------*/
  496.  APIRET rc;
  497.  register int i;
  498. /*--------------------------- processing ------------------------------*/
  499. #ifdef TRACE
  500.  trace_function("rexx.c:    finalise_rexx");
  501. #endif
  502.  
  503. #if defined(USE_AIXREXX)
  504.  rc = RexxDeregisterSubcom((PSZ)"THE");
  505.  rc = RexxDeregisterExit((PSZ)"THE_EXIT");
  506. #else
  507.  rc = RexxDeregisterSubcom((PSZ)"THE",(PSZ)NULL);
  508.  rc = RexxDeregisterExit((PSZ)"THE_EXIT",(PSZ)NULL);
  509. #endif
  510.  for (i=0;item[i].name != NULL;i++)
  511.    {
  512.     rc = RexxDeregisterFunction((PSZ)item[i].name);
  513.    }
  514. #ifdef TRACE
  515.  trace_return();
  516. #endif
  517.  return((int)rc);
  518. }
  519.  
  520. /***********************************************************************/
  521. #ifdef PROTO
  522. int execute_macro_file(char *filename,char *params)
  523. #else
  524. int execute_macro_file(filename,params)
  525. char *filename;
  526. char *params;
  527. #endif
  528. /***********************************************************************/
  529. {
  530. /*-------------------------- external data ----------------------------*/
  531. extern VIEW_DETAILS *vd_current;
  532. extern WINDOW *foot;
  533. extern char in_profile;
  534. extern bool error_on_screen;
  535. extern char number_of_files;
  536. /*--------------------------- local data ------------------------------*/
  537. #if defined(USE_REGINA) || defined(USE_AIXREXX)
  538.  LONG rexxrc;
  539. #else
  540.  USHORT rexxrc;
  541. #endif
  542.  RXSTRING retstr;
  543.  RXSTRING argstr;
  544.  APIRET rc;
  545.  CHAR retbuf[250];
  546.  LONG num_params;
  547.  char *rexx_args=NULL;
  548.  RXSYSEXIT exit_list[2];                /* system exit list           */
  549. /*--------------------------- processing ------------------------------*/
  550. #ifdef TRACE
  551.  trace_function("rexx.c:    execute_macro_file");
  552. #endif
  553. /*---------------------------------------------------------------------*/
  554. /* Determine how many parameters are to be passed to the interpreter.  */
  555. /* Only 0 or 1 are valid values.                                       */
  556. /*---------------------------------------------------------------------*/
  557.  if (params == NULL
  558.  || strcmp(params,"") == 0)
  559.    {
  560.     num_params = 0;
  561.     MAKERXSTRING(argstr,"",0);
  562.    }
  563.  else
  564.    {
  565.     num_params = 1;
  566.     if ((rexx_args = (char *)malloc(strlen(params)+1)) == (char *)NULL)
  567.       {
  568.        display_error(30,(char *)"");
  569. #ifdef TRACE
  570.        trace_return();
  571. #endif
  572.        return(RC_OUT_OF_MEMORY);
  573.       }
  574.     strcpy(rexx_args,params);
  575.     MAKERXSTRING(argstr,rexx_args,strlen(rexx_args));
  576.    }
  577.  
  578.  MAKERXSTRING(retstr,retbuf,sizeof(retbuf));
  579.  
  580. /*---------------------------------------------------------------------*/
  581. /* Set up pointer to REXX Exit Handler.                                */
  582. /*---------------------------------------------------------------------*/
  583.  exit_list[0].sysexit_name = "THE_EXIT";
  584.  exit_list[0].sysexit_code = RXSIO;
  585.  exit_list[1].sysexit_code = RXENDLST;
  586.  
  587.  captured_lines = 0L;
  588.  rexx_output = FALSE;
  589.  rexx_halted = FALSE;
  590. /*---------------------------------------------------------------------*/
  591. /* Call the REXX interpreter.                                          */
  592. /*---------------------------------------------------------------------*/
  593.  rc = RexxStart((LONG)num_params,
  594.                (PRXSTRING)&argstr,
  595.                (PSZ)filename,
  596.                (PRXSTRING)NULL,
  597.                (PSZ)"THE",
  598.                (LONG)RXCOMMAND,
  599.                (PRXSYSEXIT)exit_list,
  600. #if defined(USE_OS2REXX)
  601.                (PSHORT)&rexxrc,
  602. #else
  603.                (PLONG)&rexxrc,
  604. #endif
  605.                (PRXSTRING)&retstr);
  606.  
  607. /*---------------------------------------------------------------------*/
  608. /* Edit the captured file or clean up after REXX output displays.      */
  609. /*---------------------------------------------------------------------*/
  610.  if (rexx_output)
  611.    {
  612.     rexx_output = FALSE;
  613.     if (CAPREXXOUTx)
  614.       {
  615.        fclose(rexxoutfp);
  616.        strcpy(temp_cmd,rexx_pathname);
  617.        strcat(temp_cmd,rexx_filename);
  618.        if (!in_profile)
  619.           Xedit(temp_cmd);
  620.       }
  621.     else
  622.       {
  623.        if (in_profile)
  624.           error_on_screen = TRUE;
  625.        else
  626. /*---------------------------------------------------------------------*/
  627. /* Pause for operator intervention and restore the screen to the       */
  628. /* current screen if there are still file(s) in the ring.              */
  629. /*---------------------------------------------------------------------*/
  630.          {
  631.           printf("\n%s",HIT_ANY_KEY);
  632.           fflush(stdout);
  633.           resume_curses();
  634.           (void)my_getch(foot);
  635.           if (number_of_files > 0)
  636.              restore_THE();
  637.          }
  638.       }
  639.    }
  640.  
  641.  if (rexx_args != NULL)
  642.     free(rexx_args);
  643. #ifdef TRACE
  644.  trace_return();
  645. #endif
  646.  return((int)rc);
  647. }
  648. /***********************************************************************/
  649. #ifdef PROTO
  650. int set_extract_variables(char *item)
  651. #else
  652. int set_extract_variables(item)
  653. char *item;
  654. #endif
  655. /***********************************************************************/
  656. {
  657. /*-------------------------- external data ----------------------------*/
  658. extern VALUE item_values[MAX_VARIABLES_RETURNED];
  659. /*--------------------------- local data ------------------------------*/
  660.  register int i;
  661.  int rc,number_values;
  662. /*--------------------------- processing ------------------------------*/
  663. #ifdef TRACE
  664.  trace_function("rexx.c:    set_extract_variables");
  665. #endif
  666.  number_values = atoi(item_values[0].value);
  667.  for (i=0;i<number_values+1;i++)
  668.   {
  669.    rc = set_rexx_variable(item,item_values[i].value,i);
  670.    if (rc != RXSHV_OK && rc != RXSHV_NEWV)
  671.      {
  672.       display_error(25,(char *)"");
  673.       rc = RC_SYSTEM_ERROR;
  674.       break;
  675.      }
  676.    else
  677.       rc = RC_OK;
  678.   } 
  679.  return(rc);
  680. }
  681. /***********************************************************************/
  682. #ifdef PROTO
  683. int set_rexx_variable(char *name,char *value,int suffix)
  684. #else
  685. int set_rexx_variable(name,value,suffix)
  686. char *name;
  687. char *value;
  688. int suffix;
  689. #endif
  690. /***********************************************************************/
  691. {
  692. /*-------------------------- external data ----------------------------*/
  693. /*--------------------------- local data ------------------------------*/
  694.  SHVBLOCK shv;
  695.  CHAR variable_name[50];
  696.  int rc;
  697. /*--------------------------- processing ------------------------------*/
  698. #ifdef TRACE
  699.  trace_function("rexx.c:    set_rexx_variable");
  700. #endif
  701.  
  702.  shv.shvnext=NULL;                                   /* only one block */
  703.  shv.shvcode=RXSHV_SYSET;                          /* symbolic set set */
  704. /*---------------------------------------------------------------------*/
  705. /* This calls the RexxVariablePool() function for each value. This is  */
  706. /* not the most efficient way of doing this.                           */
  707. /*---------------------------------------------------------------------*/
  708.  sprintf(variable_name,"%s.%-d",name,suffix);
  709.  make_upper(variable_name);            /* make variable name uppercase */
  710. /*---------------------------------------------------------------------*/
  711. /* Now (attempt to) set the REXX variable                              */
  712. /* Add name/value to SHVBLOCK                                          */
  713. /*---------------------------------------------------------------------*/
  714.  MAKERXSTRING(shv.shvname, variable_name, strlen(variable_name));
  715.  MAKERXSTRING(shv.shvvalue,value,strlen(value));
  716. /*---------------------------------------------------------------------*/
  717. /* One or both of these is needed, too <sigh>                          */
  718. /*---------------------------------------------------------------------*/
  719.  shv.shvnamelen=strlen(variable_name);
  720.  shv.shvvaluelen=strlen(value);
  721.  
  722. #if defined(USE_OS2REXX) || defined(USE_AIXREXX)
  723.  rc=(int)RexxVariablePool(&shv);              /* Set the REXX variable */
  724. #else
  725.  rc = RexxVariablePool(&shv);                 /* Set the REXX variable */
  726.  rc = RXSHV_OK;
  727. #endif
  728.  if (rc != RXSHV_OK && rc != RXSHV_NEWV)
  729.    {
  730.     display_error(25,(char *)"");
  731.     rc = RC_SYSTEM_ERROR;
  732.    }
  733.  else
  734.     rc = RC_OK;
  735.  return(rc);
  736. }
  737. #else
  738. /***********************************************************************/
  739. #ifdef PROTO
  740. int set_rexx_variable(char *name,char *value,int suffix)
  741. #else
  742. int set_rexx_variable(name,value,suffix)
  743. char *name;
  744. char *value;
  745. int suffix;
  746. #endif
  747. /***********************************************************************/
  748. {
  749. /*-------------------------- external data ----------------------------*/
  750. /*--------------------------- local data ------------------------------*/
  751. /*--------------------------- processing ------------------------------*/
  752. /*---------------------------------------------------------------------*/
  753. /* This is a dummy routine because this function is referenced in      */
  754. /* query.c.                                                            */
  755. /*---------------------------------------------------------------------*/
  756.  return(0);
  757. }
  758. #endif
  759.