home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / toolkt21 / rexx / samples / pmrexx / pmrexxio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-07  |  119.8 KB  |  2,120 lines

  1. /* static char *SCCSID = "@(#)pmrexxio.c        6.3 91/12/24";                      */
  2. /*********************  START OF SPECIFICATIONS  ******************************/
  3. /*                                                                            */
  4. /*   SOURCE FILE NAME:  pmrexxio.c                                            */
  5. /*                                                                            */
  6. /*   DESCRIPTIVE NAME:  PM I/O environment for REXX command files.            */
  7. /*                                                                            */
  8. /*      Provide a means for REXX command files to do Pull, Say and            */
  9. /*      Trace interactions when called from a PM application by simulating    */
  10. /*      stdin, stdout and stderr I/O operations.                              */
  11. /*                                                                            */
  12. /*   COPYRIGHT:         IBM Corporation 1991                                  */
  13. /*                                                                            */
  14. /*   STATUS:            Version 2.00                                          */
  15. /*                                                                            */
  16. /*   FUNCTION:                                                                */
  17. /*           This program provides a Presentation Manager Shell for           */
  18. /*      RexxStart programs.                                                   */
  19. /*                                                                            */
  20. /*                                                                            */
  21. /*   NOTES:                                                                   */
  22. /*      DEPENDENCIES:                                                         */
  23. /*          This function has dependencies on the following                   */
  24. /*      files for compilation.                                                */
  25. /*          pmrexxio.h - Definitions for control of the PMREXXIO              */
  26. /*                       dialog.                                              */
  27. /*          pmrxiodt.h - Definitions necessary for the resource               */
  28. /*                       file compilation.                                    */
  29. /*          rhdtatyp.h - Macros, structures, typedefs and defines             */
  30. /*                       local to and necessary for this program.             */
  31. /*          The C runtime multi-threaded header files                         */
  32. /*                                                                            */
  33. /*  EXECUTION INSTRUCTIONS:                                                   */
  34. /*          PMREXXIO is invoked via a call to RexxCreateIOWindow.             */
  35. /*      This call redirects stdin, stdout and stderr to pips which            */
  36. /*      are processed by PMREXXIO.  The calling application enables           */
  37. /*      execution of a Rexx program by posting message REXX_STARTPROC,        */
  38. /*      passing the id of the thread the Rexx program will execute on.        */
  39. /*      On completion of the Rexx program, the message REXX_ENDPROC           */
  40. /*      should be sent to the window.  RexxDestroyIOWindow should be          */
  41. /*      called to perform cleanup of the I/O resources at program             */
  42. /*      termination.                                                          */
  43. /*                                                                            */
  44. /*  EXPECTED OUTPUT:                                                          */
  45. /*          The REXX procedure file will be executed with all                 */
  46. /*      output directed into PM windows.                                      */
  47. /*                                                                            */
  48. /*  PROCEDURES:                                                               */
  49. /*    RexxCreateIOWindow:  Initialize I/O subsystem                           */
  50. /*    RexxDestroyIOWindow:  Terminate I/O subsystem                           */
  51. /*    EntryDlgProc:   Dialog procedure for the input entry field              */
  52. /*    initialize:     Initialize data structures and threads                  */
  53. /*    io_routine:     Process the REXX IO system exit                         */
  54. /*    MainWndProc:    Main window procedure                                   */
  55. /*    SizeWindow:     Size the output window and input window                 */
  56. /*    ClipBoard:      Process MLE clipboard functions                         */
  57. /*    RXIOCmds:       Process WM_COMMAND messages from the main window proc   */
  58. /*    Import:         Add information from import buffer to the MLE           */
  59. /*    SelectFont:     Interface to the font selection dialog                  */
  60. /*    stdinpipe:      Send input to the standard input of a child process     */
  61. /*    stdoutpipe:     Send standard output from child proc to output window   */
  62. /*                                                                            */
  63. /***********************  END OF SPECIFICATIONS  ******************************/
  64. #include <malloc.h>
  65. #include <process.h>
  66. #include <stddef.h>
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include <string.h>
  70.  
  71. /* Define the sections of the OS/2 header files that we need.                 */
  72.  
  73. #define  INCL_RXSYSEXIT                /* REXX system exits                   */
  74. #define  INCL_RXARI                    /* REXX Asynchronous Request Interface */
  75. #define  INCL_DOSSEMAPHORES            /* OS/2 semaphore support              */
  76. #define  INCL_DOSERRORS                /* OS/2 errors                         */
  77. #define  INCL_DOSPROCESS               /* Process and thread support          */
  78. #define  INCL_DOSQUEUES                /* Queues                              */
  79. #define  INCL_DOSMISC                  /* Miscellaneous doscalls              */
  80. #define  INCL_DOSNLS                   /* NLS (code page) support             */
  81. #define  INCL_DOSMODULEMGR             /* OS/2 module support                 */
  82. #define  INCL_GPILCIDS                 /* Physical and logical fonts with     */
  83.                                        /* lcids                               */
  84. #define  INCL_GPIPRIMITIVES            /* Drawing primitives and primitive    */
  85.                                        /* attributes                          */
  86. #define  INCL_WINCOUNTRY               /* Code page support                   */
  87. #define  INCL_WINDIALOGS               /* Dialog boxes                        */
  88. #define  INCL_WINENTRYFIELDS           /* Entry fields                        */
  89. #define  INCL_WINFRAMEMGR              /* Frame manager                       */
  90. #define  INCL_WINHELP                  /* Help manager definitions            */
  91. #define  INCL_WININPUT                 /* Mouse and keyboard input            */
  92. #define  INCL_WINMESSAGEMGR            /* Message management                  */
  93. #define  INCL_WINSHELLDATA             /* Profile calls                       */
  94. #define  INCL_WINSWITCHLIST            /* Task list calls                     */
  95. #define  INCL_WINTIMER                 /* Timer routines                      */
  96. #define  INCL_WINWINDOWMGR             /* General window management           */
  97. #define  INCL_WINMENUS                 /* Menu controls                       */
  98. #define  INCL_WINMLE                   /* Multiple line edit fields           */
  99. #define  INCL_WINPOINTERS              /* Mouse pointers                      */
  100. #define  INCL_WINSTDFONT               /* Standard Font dialog                */
  101. #define  INCL_WINERRORS                /* Standard Font dialog                */
  102. #include <os2.h>
  103. #include <rexxsaa.h>                   /* Include the REXX header file        */
  104.  
  105. /* Defines, typedefs and function prototypes for pmrexx                       */
  106.  
  107. #include "rhdtatyp.h"
  108. #include "pmrxiodt.h"
  109. #include "pmrexxio.h"
  110.  
  111. /************************** START OF SPECIFICATIONS ***************************/
  112. /*                                                                            */
  113. /*   SUBROUTINE NAME: RexxCreateIOWindow                                      */
  114. /*                                                                            */
  115. /*   DESCRIPTIVE NAME:                                                        */
  116. /*               Initialize a Rexx stdin/stdout/stderr transaction subsystem. */
  117. /*                                                                            */
  118. /*   FUNCTION:                                                                */
  119. /*               Creates Rexx I/O windows and redirects stdin, stdout, and    */
  120. /*               stderr to pipes.                                             */
  121. /*                                                                            */
  122. /*   NOTES:                                                                   */
  123. /*                                                                            */
  124. /*   ENTRY POINT:                                                             */
  125. /*      LINKAGE:  RexxCreateIOWindow(HWND hwndOwner, PHWND phwndClient)       */
  126. /*                                                                            */
  127. /*   INPUT:                                                                   */
  128. /*       phwndClient is the handle of the I/O window client window.           */
  129. /*                                                                            */
  130. /*   EXIT-NORMAL:                                                             */
  131. /*       Exit with handle to I/O frame window.                                */
  132. /*                                                                            */
  133. /*   EXIT-ERROR:                                                              */
  134. /*       If unable to duplicate the write handle for stderr pipe, exit rc=5.  */
  135. /*       If unable to register the window class, exit rc=1.                   */
  136. /*       If no procedure name was specified, exit with rc=3.                  */
  137. /*       If window was not displayed, exit with return code from the REXX     */
  138. /*         procedure.                                                         */
  139. /*       Otherwise: exit with created frame and client handles.               */
  140. /*                                                                            */
  141. /*   EFFECTS:                                                                 */
  142. /*       Initializes the Rexx Presentation Manager I/O subsystem.             */
  143. /*                                                                            */
  144. /*   INTERNAL REFERENCES:                                                     */
  145. /*      ROUTINES:                                                             */
  146. /*       getstring      - To obtain the title bar name and window name.       */
  147. /*       initialize     - Sets up the environment for the program. Starts all */
  148. /*                        necessary threads, sets up the input queues, etc.   */
  149. /*                                                                            */
  150. /*   EXTERNAL REFERENCES:                                                     */
  151. /*      ROUTINES:                                                             */
  152. /*       WinQueryAnchorBlock         WinRegisterClass                         */
  153. /*       WinCreateStdWindow                                                   */
  154. /*                                                                            */
  155. /**************************** END OF SPECIFICATIONS ***************************/
  156.  
  157. HWND RexxCreateIOWindow(
  158.    HWND hwndOwner,                     /* Owner handle                        */
  159.    PHWND phwndClient)                  /* Returned client window              */
  160.  {
  161.  
  162.    /* We set the creation flags to be the standard window frame flags         */
  163.    /*    but without scroll bars and without a task list entry.               */
  164.  
  165.   ULONG flCreate = FCF_STANDARD&~(FCF_VERTSCROLL|FCF_HORZSCROLL|FCF_ACCELTABLE);
  166.   PUCHAR windowtext;                   /* Text for title bar                  */
  167.   ULONG  argnum = 1;                   /* Counter for looking at arguments    */
  168.   HAB    hab;                          /* anchor block                        */
  169.   HMODULE handle;                      /* module handle                       */
  170.   HWND    hwndFrame;                   /* frame handle                        */
  171.  
  172.                                        /* get desktop anchor                  */
  173.   hab = WinQueryAnchorBlock(hwndOwner);
  174.   if (!hab) {                          /* no anchor block?                    */
  175.     return NULLHANDLE;                 /* return with nothing                 */
  176.   }
  177.  
  178.   if (DosQueryModuleHandle(MODULE_NAME, &handle)) {
  179.     return NULLHANDLE;                 /* return with nothing                 */
  180.   }
  181.  
  182.   if (!WinRegisterClass(               /* Register Window Class               */
  183.       hab,                             /* Anchor block handle                 */
  184.       PMREXXCLASSNAME,                 /* Window Class name                   */
  185.       (PFNWP)MainWndProc,              /* Address of Window Procedure         */
  186.       CS_SIZEREDRAW,                   /* Class Style                         */
  187.       sizeof(PUCHAR))) {               /* Extras words for a far ptr.         */
  188.     return  NULLHANDLE;                /* Exit if we couldn't register the    */
  189.   }                                    /* class                               */
  190.  
  191.    /* Get the title bar text                                                  */
  192.  
  193.   windowtext = getstring(hab, handle, WINDOW_TEXT);
  194.  
  195.    /* Create the standard window                                              */
  196.  
  197.   hwndFrame = WinCreateStdWindow(hwndOwner,/* Supplied owner                  */
  198.       0,                               /* Frame Style                         */
  199.       &flCreate,                       /* Control Data                        */
  200.       PMREXXCLASSNAME,                 /* Window Class name                   */
  201.       NULL,                            /* Window Text                         */
  202.       WS_VISIBLE,                      /* Client style                        */
  203.       handle,                          /* Module handle==this module          */
  204.       RXHOST_WIN,                      /* Window ID                           */
  205.       phwndClient);                    /* Client Window handle                */
  206.                                        /* set the window text                 */
  207.   WinSetWindowText(WinWindowFromID(hwndFrame, (USHORT)FID_TITLEBAR),
  208.       windowtext);
  209.   free(windowtext);                    /* release window text                 */
  210.   return hwndFrame;                    /* return created frame handle         */
  211.  }
  212.  
  213. /************************** START OF SPECIFICATIONS ***************************/
  214. /*                                                                            */
  215. /*   SUBROUTINE NAME: RexxDestroyIOWindow                                     */
  216. /*                                                                            */
  217. /*   DESCRIPTIVE NAME:                                                        */
  218. /*               Terminate a Rexx stdin/stdout/stderr transaction subsystem.  */
  219. /*                                                                            */
  220. /*   FUNCTION:                                                                */
  221. /*               Cleans up the Rexx I/O subsystem.                            */
  222. /*                                                                            */
  223. /*   NOTES:                                                                   */
  224. /*                                                                            */
  225. /*   ENTRY POINT:                                                             */
  226. /*      LINKAGE:  RexxDestroyIOWindow(HWND hwndClient)                        */
  227. /*                                                                            */
  228. /*   INPUT:                                                                   */
  229. /*       phwndClient is the handle of the I/O window client window.           */
  230. /*                                                                            */
  231. /*   EXIT-NORMAL:                                                             */
  232. /*                                                                            */
  233. /*   EXIT-ERROR:                                                              */
  234. /*                                                                            */
  235. /*   EFFECTS:                                                                 */
  236. /*       Terminates the Rexx Presntation Manager I/O subsystem.               */
  237. /*                                                                            */
  238. /*   INTERNAL REFERENCES:                                                     */
  239. /*      ROUTINES:                                                             */
  240. /*                                                                            */
  241. /*   EXTERNAL REFERENCES:                                                     */
  242. /*      ROUTINES:                                                             */
  243. /*       WinQueryWindowPtr           WinDestroyHelpInstance                   */
  244. /*       WinAssociateHelpInstance    WinDestroyWindow                         */
  245. /*       DosSuspendThread            RexxDeregisterExit                       */
  246. /*       DosFreeMem                                                           */
  247. /*                                                                            */
  248. /**************************** END OF SPECIFICATIONS ***************************/
  249.  
  250. void RexxDestroyIOWindow(HWND hwnd)
  251. {
  252.   PRHWINDATA pWinData = NULL;          /* pointer to the windata structure    */
  253.  
  254.   pWinData = WinQueryWindowPtr(WinWindowFromID(hwnd, (USHORT)FID_CLIENT),
  255.       (SHORT)0);
  256.    /* And now, clean everything up.                                    */
  257.    if (pWinData->HelpInst) {
  258.       WinDestroyHelpInstance(pWinData->HelpInst);
  259.       WinAssociateHelpInstance(NULLHANDLE, pWinData->frame);
  260.    }
  261.                                        /* cleanup semaphores                  */
  262.    DosCloseMutexSem(pWinData->pipe_in.q_sem);
  263.    DosCloseMutexSem(pWinData->trace_in.q_sem);
  264.    DosCloseEventSem(pWinData->pipe_in.q_data);
  265.    DosCloseEventSem(pWinData->trace_in.q_data);
  266.  
  267.    RexxDeregisterExit(PMRXIO_EXIT, NULL);
  268.    WinDestroyWindow(pWinData->frame);
  269.    DosFreeMem(pWinData);               /* release storage                     */
  270. }
  271.  
  272. /************************** START OF SPECIFICATIONS ***************************/
  273. /*                                                                            */
  274. /*   SUBROUTINE NAME: initialize                                              */
  275. /*                                                                            */
  276. /*   DESCRIPTIVE NAME:                                                        */
  277. /*               Initialize the data structures and threads necessary for the */
  278. /*               program to operate.                                          */
  279. /*                                                                            */
  280. /*   FUNCTION:                                                                */
  281. /*               Initializes the input queues and their semaphores, set up    */
  282. /*               the file handles for redirection of standard input/output and*/
  283. /*               error streams, allocate stacks for and begin the threads.     /
  284. /*               subcommand environments.                                     */
  285. /*                                                                            */
  286. /*   NOTES:                                                                   */
  287. /*                                                                            */
  288. /*   ENTRY POINT:                                                             */
  289. /*      LINKAGE:  initialize                                                  */
  290. /*                                                                            */
  291. /*   INPUT:       none                                                        */
  292. /*                                                                            */
  293. /*   EXIT-NORMAL: returns 0                                                   */
  294. /*                                                                            */
  295. /*   EXIT-ERROR:  returns error code from call causing the error.             */
  296. /*                                                                            */
  297. /*   EFFECTS:                                                                 */
  298. /*                                                                            */
  299. /*   INTERNAL REFERENCES:                                                     */
  300. /*      ROUTINES:                                                             */
  301. /*       makepipe       - Creates a pipe with the read and write handles at   */
  302. /*                        desired positions.                                  */
  303. /*       setinherit     - Sets the inheritance characteristcs of the passed   */
  304. /*                        file handle.                                        */
  305. /*                                                                            */
  306. /*   EXTERNAL REFERENCES:                                                     */
  307. /*      ROUTINES:                                                             */
  308. /*       DosDupHandle                                                         */
  309. /*       DosCreateMutexSem                                                    */
  310. /*       DosCreateEventSem                                                    */
  311. /*       DosGetInfoBlocks                                                     */
  312. /*       RexxRegisterExitExe                                                  */
  313. /*                                                                            */
  314. /**************************** END OF SPECIFICATIONS ***************************/
  315.  
  316.   LONG initialize(PRHWINDATA pWinData)
  317.   {
  318.     LONG         rc;                   /* return code                         */
  319.     PTIB         TI;                   /* Thread info block pointer           */
  320.     PPIB         PI;                   /* Process info block pointer          */
  321.     PRHWINDATA   userdata[2];          /* registered user data                */
  322.  
  323.    /* Initialization Section:                                                 */
  324.    /* First initialize the semaphores for the input queue.                    */
  325.    /* Using a queue and a separate thread ensures that we don't               */
  326.    /*   tie up the window procedure if the pipe backs up.                     */
  327.  
  328.     DosCreateMutexSem(NULL, &pWinData->pipe_in.q_sem, 0, FALSE);
  329.     DosCreateMutexSem(NULL, &pWinData->trace_in.q_sem, 0, FALSE);
  330.     DosCreateEventSem(NULL, &pWinData->pipe_in.q_data, FALSE, FALSE);
  331.     DosCreateEventSem(NULL, &pWinData->trace_in.q_data, FALSE, FALSE);
  332.  
  333.    /* Next, set up the redirection pipes to capture standard                  */
  334.    /*  I/O from subcommand processing.                                        */
  335.    /* First make sure all C handles are closed.                               */
  336.  
  337.     DosClose(STDIN);                   /* close stdin, stdout, stderr         */
  338.     DosClose(STDOUT);
  339.     DosClose(STDERR);
  340.  
  341.    /* Since we closed all open file handles, we are free to use any *
  342.     * handles we want.                                                        */
  343.    /* First, standard input                                                   */
  344.  
  345.     makepipe(&pWinData->stdin_r, STDIN, &pWinData->stdin_w, 4, PIPE_SIZE);
  346.     setinherit(pWinData->stdin_r, TRUE);
  347.     setinherit(pWinData->stdin_w, FALSE);
  348.  
  349.    /* Next, standard output                                                   */
  350.  
  351.     makepipe(&pWinData->stdout_r, 5, &pWinData->stdout_w, STDOUT, PIPE_SIZE);
  352.     setinherit(pWinData->stdout_w, TRUE);
  353.     setinherit(pWinData->stdout_r, FALSE);
  354.  
  355.    /* And, finally, standard error                                            */
  356.    /* Just dup the standard output and handle it once.                        */
  357.  
  358.     pWinData->stderr_w = STDERR;
  359.  
  360.     if (rc = DosDupHandle(pWinData->stdout_w, &pWinData->stderr_w)) {
  361.       return  rc;
  362.     }
  363.  
  364.     DosGetInfoBlocks(&TI, &PI);        /* Get the thread information          */
  365.     pWinData->proc_id = PI->pib_ulpid; /* set the process id                  */
  366.  
  367.     userdata[0] = pWinData;            /* save our anchor                     */
  368.                                        /* register I/O handler                */
  369.     RexxRegisterExitExe(PMRXIO_EXIT, (PFN)io_routine, (PUCHAR)userdata);
  370.  
  371.    /* And, of course, start the various threads!                              */
  372.  
  373.     rc = DosCreateThread(&pWinData->in_tid, (PFNTHREAD)stdinpipe, (ULONG)pWinData,
  374.         (ULONG)0, STACK_SIZE);
  375.     if (!rc) rc = DosCreateThread(&pWinData->out_tid, (PFNTHREAD)stdoutpipe, (ULONG)pWinData,
  376.         (ULONG)0, STACK_SIZE);
  377.     return rc;
  378.   }
  379.  
  380. /************************** START OF SPECIFICATIONS ***************************/
  381. /*                                                                            */
  382. /*   SUBROUTINE NAME: MainWndProc                                             */
  383. /*                                                                            */
  384. /*   DESCRIPTIVE NAME:                                                        */
  385. /*               Main window procedure for the PMREXX program.                */
  386. /*                                                                            */
  387. /*   FUNCTION:                                                                */
  388. /*               This procedure handles all interesting messages for the      */
  389. /*               client area for the PMREXX program. The messages handled     */
  390. /*               are:                                                         */
  391. /*       WM_CREATE      - Allocates and initializes the RHWINDATA structure   */
  392. /*                        (defined in rhdtatyp.h) and places a pointer to it  */
  393. /*                        into the window words.                              */
  394. /*       WM_TIMER       - A 100 millisecond timer is set when output is added */
  395. /*                        to a buffer for later adding to the MLE output      */
  396. /*                        window. Thus if many lines are being added, output  */
  397. /*                        time is improved, and window flashing is reduced.   */
  398. /*                        If the timer pops, then no output has been          */
  399. /*                        added for the 100 milliseconds and it is time to    */
  400. /*                        add the output to the MLE.                          */
  401. /*       WM_ERASEBACKGROUND - Just return TRUE to force a background erase.   */
  402. /*       WM_SIZE        - Calls routine SizeWindow to re-adjust the sizes     */
  403. /*                        of the MLE and input areas.                         */
  404. /*       WM_PAINT       - Paints the header for the input window, and lets    */
  405. /*                        the child controls do the rest.                     */
  406. /*       WM_COMMAND     - All WM_COMMAND messages are processed in routine    */
  407. /*                        RXIOCmds.                                           */
  408. /*       WM_CHAR        - Handles tab and backtab keys to switch the focus    */
  409. /*                        window and the break key as a halt procedure.       */
  410. /*       REXX_MAKE_VISIBLE - Is a user defined message requesting that        */
  411. /*                        the window be made visible. The window is initially */
  412. /*                        created invisible and is not made visible until     */
  413. /*                        something is output, or until some input is         */
  414. /*                        requested. This way, a REXX procedure that does not */
  415. /*                        need this window, will not clutter up the screen    */
  416. /*                        with it (e.g. a DM exec that uses DM for all I/O).  */
  417. /*       REXX_MAKE_INVISIBLE - Is a user defined message requesting that      */
  418. /*                        the window be made invisible.                       */
  419. /*       REXX_ENDPROC   - This signals the end of a Rexx procedure.  The      */
  420. /*                        I/O subsystem is flushed and reinitialized.         */
  421. /*       REXX_STARTPROC - This signals the start of a Rexx procedure.  This   */
  422. /*                        identifies the thread running the procedure.        */
  423. /*       RXIOB_MSGBOX   - Puts up a message box with the requested message.   */
  424. /*       START_TIMER    - Starts a timer. When the timer pops, the buffered   */
  425. /*                        output is added to the MLE. See also, WM_TIMER and  */
  426. /*                        ADD_STDOUTWIN. This message is posted by the thread */
  427. /*                        reading the input pipe.                             */
  428. /*       ADD_STDOUTWIN  - This user defined message is a request to add       */
  429. /*                        output to the output window. To reduce window       */
  430. /*                        flicker and improve performance, data is internally */
  431. /*                        buffered until the buffer is full, or until there   */
  432. /*                        is a lull in output, before being sent on to the    */
  433. /*                        MLE window. See also the WM_TIMER message.          */
  434. /*       WM_SAVEAPPLICATION - Save the current font and window information    */
  435. /*                                                                            */
  436. /*   NOTES:                                                                   */
  437. /*                                                                            */
  438. /*   ENTRY POINT:                                                             */
  439. /*      LINKAGE:                                                              */
  440. /*               Standard window procedure linkage is followed.               */
  441. /*                                                                            */
  442. /*   INPUT:                                                                   */
  443. /*               Standard window procedure inputs are passed in.              */
  444. /*                                                                            */
  445. /*   EXIT-NORMAL:                                                             */
  446. /*                                                                            */
  447. /*   EXIT-ERROR:                                                              */
  448. /*                                                                            */
  449. /*   EFFECTS:                                                                 */
  450. /*                                                                            */
  451. /*   INTERNAL REFERENCES:                                                     */
  452. /*      ROUTINES:                                                             */
  453. /*       getfixedfont   - Get a fixed font for the default display            */
  454. /*       getstring      - Retrieve a string resource                          */
  455. /*       RestoreWindow  - Gets saved window position from user profile        */
  456. /*       RHWinErrorBox  - Display an error message box                        */
  457. /*       SizeWindow     - Sizes all the child windows (MLE & Entry field) to  */
  458. /*                        fit the frame window.                               */
  459. /*       RXIOCmds       - This routine processes the various WM_COMMAND       */
  460. /*                        messages.                                           */
  461. /*       Import         - Sends the data from the internal buffer to the MLE. */
  462. /*                        See the WM_TIMER and ADD_STDOUTWIN messages.        */
  463. /*       SaveWindow     - Saves current window position to user profile       */
  464. /*       SetCheckMark   - Check/uncheck a menu item                           */
  465. /*       ProcessSaveQuit - Interface to the Save/Quit dialog                  */
  466. /*                                                                            */
  467. /*                                                                            */
  468. /*   EXTERNAL REFERENCES:                                                     */
  469. /*      ROUTINES:                                                             */
  470. /*       DosAllocMem                       WinLoadString                      */
  471. /*       DosCreateMutexSem                 WinMessageBox                      */
  472. /*       DosFreeMem                        WinPostMsg                         */
  473. /*       DosReleaseMutexSem                WinQueryAnchorBlock                */
  474. /*       DosRequestMutexSem                WinQueryWindow                     */
  475. /*       DosSuspendThread                  WinQueryWindowPos                  */
  476. /*       GpiCharStringAt                   WinQueryWindowPtr                  */
  477. /*       GpiQueryCurrentPosition           WinReleasePS                       */
  478. /*       RexxDeregisterExit                WinSendMsg                         */
  479. /*       WinAlarm                          WinSetFocus                        */
  480. /*       WinAssociateHelpInstance          WinSetWindowPtr                    */
  481. /*       WinCreateHelpInstance             WinShowWindow                      */
  482. /*       WinDefWindowProc                  WinStartTimer                      */
  483. /*       WinDestroyHelpInstance            WinStopTimer                       */
  484. /*       WinGetPS                          WinWindowFromID                    */
  485. /*                                                                            */
  486. /**************************** END OF SPECIFICATIONS ***************************/
  487.  
  488.   MRESULT EXPENTRY MainWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  489.   {
  490.     ULONG      rc;                     /* return code                         */
  491.     PRHWINDATA pWinData = NULL;        /* pointer to the windata structure    */
  492.     HPS        hps;                    /* presentation space handle           */
  493.     PIMPORT    im_ptr;                 /* Pointer to buffer for data waiting  */
  494.     ULONG      postcount;              /* number of posted lines              */
  495.     FONTMETRICS fm;                    /* font size information               */
  496.     HWND       hEntry;                 /* entry dialog handle                 */
  497.                                        /* Creation flags for the MLE requests */
  498.                                        /* scroll bars.                        */
  499.     ULONG flCreate = MLS_HSCROLL|MLS_VSCROLL|MLS_BORDER;
  500.  
  501.     pWinData = WinQueryWindowPtr(hwnd, (SHORT)0);
  502.  
  503.     switch (msg) {
  504.  
  505.       case  WM_CREATE :
  506.  
  507.          /* When the window is created, we also create a structure to hold    */
  508.          /*   all the window specific data.                                   */
  509.  
  510.         if (pWinData = malloc(sizeof(*pWinData))) {
  511.           memset(pWinData, '\0', sizeof(*pWinData));
  512.  
  513.           pWinData->hab = WinQueryAnchorBlock(hwnd);
  514.                                        /* and client handle                   */
  515.           pWinData->client = hwnd;
  516.                                        /* save frame handle                   */
  517.           pWinData->frame = WinQueryWindow(hwnd, QW_PARENT);
  518.           if (DosQueryModuleHandle(MODULE_NAME, &pWinData->hResource)) {
  519.             return NULL;               /* return with nothing                 */
  520.           }
  521.           pWinData->imp_ptr = NULL;    /* This is the timer to be used for    */
  522.                                        /* import time-out.                    */
  523.  
  524.           pWinData->timer = (USHORT)WinStartTimer(pWinData->hab, (HWND)0,
  525.                                                  (USHORT)0, (ULONG)0);
  526.                                        /* get code page information           */
  527.           DosQueryCtryInfo(sizeof(COUNTRYINFO), &pWinData->CountryCode,
  528.               &pWinData->CountryInfo, &postcount);
  529.                                        /* Attempt to find a fixed font for the*/
  530.                                        /* display, if we are not successful,  */
  531.                                        /* we will use the system font.        */
  532.           getfixedfont(hwnd, &(pWinData->MleFontAttrs.fAttrs));
  533.                                        /* system font attributes              */
  534.           pWinData->infocus = FALSE;
  535.                                        /* get the input text                  */
  536.                                        /* prompt from the resource file       */
  537.           pWinData->pszInputText = getstring(pWinData->hab,
  538.           pWinData->hResource, INPUT_TITLE);
  539.  
  540.           WinSetWindowPtr(hwnd, (SHORT)0, pWinData);
  541.                                        /* Now allocate a segment for the      */
  542.                                        /* import buffer for the MLE           */
  543.  
  544.           pWinData->imp_ptr = (PIMPORT)(pWinData->ImportBuffer);
  545.                                        /* initialize the buffer               */
  546.           im_ptr = pWinData->imp_ptr;
  547.           im_ptr->total_size = ALLOCSIZE;
  548.           im_ptr->inuse = HDRSIZE;
  549.           *(PUCHAR)(im_ptr->data) = '\0';
  550.                                        /* create the semaphore                */
  551.           DosCreateMutexSem(NULL, &im_ptr->sem, 0, FALSE);
  552.  
  553.    /* Set up the threads and initialize the data structures                   */
  554.  
  555.           rc = initialize(pWinData);
  556.  
  557.    /* If initialization failed, alert the user and exit                       */
  558.  
  559.           if (rc) {
  560.             WinAlarm(HWND_DESKTOP, WA_ERROR);
  561.             WinMessageBox(HWND_DESKTOP, NULLHANDLE,
  562.                 getstring(pWinData->hab, pWinData->hResource, INIT_FAILED),
  563.                 getstring(pWinData->hab, pWinData->hResource, RXHB_MSGBOXHDR), 1,
  564.                 MB_CANCEL|MB_CUACRITICAL|MB_MOVEABLE);
  565.           }
  566.                                        /* Find out the character              */
  567.                                        /* height for the input entry field    */
  568.           hps = WinGetPS(pWinData->client);
  569.           GpiQueryFontMetrics(hps, (LONG)sizeof fm, &fm);
  570.           pWinData->in_hgt = (ULONG )fm.lMaxBaselineExt+2;
  571.           WinReleasePS(hps);
  572.                                        /* Create the child MLE for            */
  573.                                        /* output                              */
  574.           pWinData->outmle = WinCreateWindow(pWinData->client, WC_MLE, NULL,
  575.               flCreate, 0, 0, 0, 0, pWinData->client, HWND_TOP,
  576.               MLE_WNDW, NULL, NULL);
  577.  
  578.           if (!pWinData->outmle) {     /* If we couldn't do it, tell the user */
  579.                                        /* why.                                */
  580.             RHWinErrorBox(pWinData->hab, hwnd, pWinData->hResource,
  581.                 MLE_CREATE_ERROR, MB_OK|MB_CUAWARNING);
  582.           }                            /* Delay redrawing window until        */
  583.                                        /* we're done updating it              */
  584.           WinEnableWindowUpdate(pWinData->client, FALSE);
  585.                                        /* Set the format for the MLE          */
  586.  
  587.           WinSendMsg(pWinData->outmle, MLM_FORMAT, MLE_TXT_FMT, (MPARAM)0);
  588.                                        /* Make the MLE readonly               */
  589.  
  590.           WinSendMsg(pWinData->outmle, MLM_SETREADONLY, MPFROMLONG(TRUE),
  591.               (MPARAM)0);
  592.                                        /* set the new font                    */
  593.           WinSendMsg(pWinData->outmle, MLM_SETFONT,
  594.               &(pWinData->MleFontAttrs.fAttrs), (MPARAM)0);
  595.                                        /* Update the window                   */
  596.           WinShowWindow(pWinData->outmle, TRUE);
  597.                                        /* set the title width                 */
  598.           pWinData->wtitle = (strlen(pWinData->pszInputText)+5)*(USHORT)
  599.               fm.lAveCharWidth;
  600.                                        /* Load the dialog box for the input   */
  601.                                        /* window                              */
  602.           hEntry = WinLoadDlg(pWinData->client, pWinData->client,
  603.               (PFNWP)EntryDlgProc, (HMODULE)pWinData->hResource, RH_EF1, NULL);
  604.  
  605.           pWinData->insle = hEntry;    /* save input window handle Set the    */
  606.                                        /* maximum input length to ANSLEN      */
  607.           WinSendMsg(hEntry, EM_SETTEXTLIMIT, MPFROMSHORT(ANSLEN), (MPARAM)0);
  608.                                        /* Set the offset to the first         */
  609.                                        /* character in the input box to 0     */
  610.           WinSendMsg(hEntry, EM_SETFIRSTCHAR, (MPARAM)0, (MPARAM)0);
  611.                                        /* Set the first character to be       */
  612.                                        /* selected as 0                       */
  613.           WinSendMsg(hEntry, EM_SETSEL, (MPARAM)0, (MPARAM)0);
  614.                                        /* Update the windows                  */
  615.           WinShowWindow(hEntry, TRUE);
  616.           WinEnableWindowUpdate(hEntry, TRUE);
  617.           WinEnableWindowUpdate(pWinData->client, TRUE);
  618.           WinSetFocus(HWND_DESKTOP, pWinData->outmle);
  619.         }
  620.         else {                         /* If we couldn't allocate the data    */
  621.                                        /* structure, then we cannot continue, */
  622.                                        /* so alert the user, and exit.        */
  623.           WinSendMsg(WinWindowFromID(hwnd, (USHORT)FID_CLIENT),
  624.               RXIOB_MSGBOX,
  625.               MPFROM2SHORT(RX_ALLOCERR, RXHB_MSGBOXHDR),
  626.               MPFROMLONG(MB_ENTER|MB_CUACRITICAL|MB_MOVEABLE));
  627.           return (MRESULT)TRUE;
  628.         }
  629.         break;
  630.  
  631.       case  WM_TIMER :
  632.  
  633.         if (hwnd) {                    /* We have gone for the designated time*/
  634.                                        /* without adding any new data to the  */
  635.                                        /* output buffer, so it is now time to */
  636.                                        /* import the information to the MLE   */
  637.                                        /* output window.                      */
  638.           WinStopTimer(pWinData->hab, hwnd, pWinData->timer);
  639.                                        /* Get the semaphore so that the       */
  640.                                        /* input pipe thread won't interfere.  */
  641.  
  642.           DosRequestMutexSem(pWinData->imp_ptr->sem, SEM_INDEFINITE_WAIT);
  643.           Import(pWinData);
  644.                                        /* Now clear the                       */
  645.                                        /* thread so that the input pipe can   */
  646.                                        /* continue.                           */
  647.           DosReleaseMutexSem(pWinData->imp_ptr->sem);
  648.         }
  649.  
  650.         break;
  651.  
  652.       case  WM_ERASEBACKGROUND :
  653.  
  654.         return (MRESULT)TRUE;          /* Return TRUE to indicate we want the */
  655.                                        /* background cleared to the system    */
  656.                                        /* default window background color.    */
  657.       case  WM_SIZE :
  658.  
  659.         SizeWindow(hwnd, pWinData);    /* Re-size the client area windows.    */
  660.         break;
  661.  
  662.       case  WM_PAINT :
  663.  
  664.         if (hps = WinGetPS(hwnd)) {    /* The title for the input window needs*/
  665.                                        /* to be re-painted by us. The child   */
  666.                                        /* windows do all the rest of the      */
  667.                                        /* drawing for us.                     */
  668.           POINTL p;
  669.           SWP wp;
  670.           HWND hOwner;
  671.           PUCHAR ptr;                  /* Ensure that we get a proper handle  */
  672.                                        /* to the client area.                 */
  673.  
  674.           hOwner = WinQueryWindow(hwnd, QW_PARENT);
  675.                                        /* Calculate the proper positioning.   */
  676.           WinQueryWindowPos(WinWindowFromID(hOwner, FID_CLIENT), &wp);
  677.  
  678.           p.x = BORDER_MARGIN *2;
  679.           p.y = wp.cy-pWinData->in_hgt-(BORDER_MARGIN *2);
  680.           ptr = pWinData->pszInputText; /* Output the title, and find the      */
  681.                                        /* resulting position for the next     */
  682.                                        /* character. That is where we will    */
  683.                                        /* start the input box.                */
  684.           GpiCharStringAt(hps, &p, (LONG)strlen(ptr), ptr);
  685.           GpiQueryCurrentPosition(hps, &p);
  686.           pWinData->wtitle = (ULONG )p.x;
  687.           WinReleasePS(hps);
  688.         }
  689.         break;
  690.  
  691.       case  WM_COMMAND :
  692.                                        /* WM_COMMAND processing in RXIOCMDS   */
  693.         return (RXIOCmds(hwnd, mp1, pWinData));
  694.         break;
  695.  
  696.       case  WM_CHAR :
  697.  
  698.          /* Check for a valid (complete) key message.                         */
  699.  
  700.         if (!(SHORT1FROMMP(mp1)&KC_KEYUP) &&
  701.             (SHORT1FROMMP(mp1)&KC_VIRTUALKEY) ) {
  702.  
  703.           switch (SHORT2FROMMP(mp2)) {
  704.             case  VK_TAB :
  705.             case  VK_BACKTAB :         /* For tab and back-tab, switch focus  */
  706.                                        /* windows                             */
  707.               return (MRESULT)WinSetFocus(HWND_DESKTOP,
  708.                   pWinData->infocus?pWinData->outmle: pWinData->insle);
  709.               break;
  710.  
  711.             default  :
  712.               break;
  713.           }                            /* endswitch                           */
  714.         }
  715.         break;
  716.  
  717.       case  REXX_STARTPROC :
  718.  
  719.          /* This is the request to start everything up. It is sent by the     */
  720.          /*   main procedure at startup time.                                 */
  721.  
  722.         pWinData->rexx_tid = LONGFROMMP(mp1);
  723.  
  724.         break;
  725.  
  726.       case  REXX_ENDPROC : {
  727.  
  728.         PLIST_ENTRY q_elem;            /* pointer for an element in the input */
  729.                                        /* queue                               */
  730.                                        /* Clear out any entries on input queue*/
  731.         if (!DosRequestMutexSem(pWinData->pipe_in.q_sem, SEM_INDEFINITE_WAIT)) {
  732.           for (q_elem = pWinData->pipe_in.q_1st; q_elem; q_elem = q_elem->next) {
  733.              free(q_elem->ptr);
  734.              free(q_elem);
  735.           }
  736.                                        /* Set the queue to empty              */
  737.           DosResetEventSem(pWinData->pipe_in.q_data, &postcount);
  738.                                        /* Clear the list                      */
  739.           pWinData->pipe_in.q_1st = NULL;
  740.                                        /* We're done with the queue           */
  741.           DosReleaseMutexSem(pWinData->pipe_in.q_sem);
  742.         }
  743.  
  744.         DosReleaseMutexSem(pWinData->imp_ptr->sem);  
  745.  
  746.          /* Clear the input pipe, so that any unprocessed data is deleted.    */
  747.          /* The only way to do this is to close the pipe, and then reopen it. */
  748.         DosClose(pWinData->stdin_r);
  749.         DosClose(pWinData->stdin_w);
  750.         makepipe(&pWinData->stdin_r, STDIN, &pWinData->stdin_w, 4, PIPE_SIZE);
  751.         setinherit(pWinData->stdin_r, TRUE);
  752.         setinherit(pWinData->stdin_w, FALSE);
  753.  
  754.         pWinData->stopoutpipe = TRUE;   
  755.         DosClose(pWinData->stdout_r);
  756.         DosClose(pWinData->stdout_w);
  757.         makepipe(&pWinData->stdout_r, 5, &pWinData->stdout_w, STDOUT, PIPE_SIZE);
  758.         setinherit(pWinData->stdout_w, TRUE);
  759.         setinherit(pWinData->stdout_r, FALSE);  
  760.  
  761.         if (!pWinData->visible && pWinData->imp_ptr->inuse == HDRSIZE) {
  762.           WinSetFocus(HWND_DESKTOP, pWinData->insle);
  763.           WinPostMsg(pWinData->client, WM_CLOSE, (MPARAM)0, (MPARAM)0);   
  764.         }
  765.         break;
  766.       }
  767.  
  768.       case  REXX_MAKE_INVISIBLE :
  769.  
  770.         if (pWinData->visible) {
  771.           pWinData->visible = FALSE;   /* reset flag to invisible             */
  772.             WinShowWindow(pWinData->frame, FALSE);
  773.                                        /* Make it invisible.                  */
  774.         }
  775.         break;
  776.  
  777.       case  REXX_MAKE_VISIBLE :
  778.  
  779.          /* At start-up, the window is left invisible. When output or         */
  780.          /*   trace mode input occurs for the first time, this message is     */
  781.          /*   sent to make the window visible. It is at this time that        */
  782.          /*   the Help Manager gets initialized.                              */
  783.  
  784.         if (!pWinData->visible) {
  785.           HELPINIT hmiData;
  786.  
  787.           pWinData->visible = TRUE;    /* Set so we don't get called          */
  788.                                        /* unnecessarily                       */
  789.           RestoreWindow(hwnd, pWinData);/* From last invocation               */
  790.           WinShowWindow(pWinData->frame, TRUE);
  791.                                        /* Make it visible. Initialize the Help*/
  792.                                        /* Manager data structure              */
  793.           memset(&hmiData, '\0', sizeof hmiData);
  794.           hmiData.cb = sizeof(hmiData);
  795.           hmiData.pszHelpWindowTitle =
  796.               getstring(pWinData->hab, pWinData->hResource, PMREXX_HELP_TITLE);
  797.           hmiData.phtHelpTable = (PHELPTABLE)(PMREXX_HELPTABLE|RESOURCE_FLAG);
  798.           hmiData.pszHelpLibraryName =
  799.               getstring(pWinData->hab, pWinData->hResource, PMREXX_HELPFILENAME);
  800.           hmiData.fShowPanelId = CMIC_HIDE_PANEL_ID;
  801.           hmiData.hmodHelpTableModule = pWinData->hResource;
  802.           hmiData.hmodAccelActionBarModule = pWinData->hResource;
  803.           hmiData.idAccelTable = 0;
  804.           hmiData.idActionBar = 0;
  805.                                        /* Attempt to create help instance     */
  806.  
  807.           if (pWinData->HelpInst = WinCreateHelpInstance(pWinData->hab,
  808.               &hmiData)) {
  809.                                        /* If the create succeeded, then we    */
  810.                                        /* need to associate it with the frame */
  811.                                        /* window.                             */
  812.  
  813.             if (!WinAssociateHelpInstance(pWinData->HelpInst, pWinData->frame)) {
  814.                                        /* If the associate failed, inform the */
  815.                                        /* user and destroy the instance.      */
  816.               RHWinErrorBox(pWinData->hab, hwnd, pWinData->hResource,
  817.                   ERROR_HELPASSOC, MB_OK|MB_CUAWARNING);
  818.               WinDestroyHelpInstance(pWinData->HelpInst);
  819.               pWinData->HelpInst = NULLHANDLE;
  820.             }
  821.           }
  822.  
  823.           else {
  824.                                        /* If the create failed, inform the    */
  825.                                        /* user.                               */
  826.             RHWinErrorBox(pWinData->hab, hwnd, pWinData->hResource,
  827.                 ERROR_HELPCREATE, MB_OK|MB_CUAWARNING);
  828.           }
  829.           WinSetFocus(HWND_DESKTOP, pWinData->insle);
  830.  
  831.         }
  832.         break;
  833.  
  834.       case  RXIOB_MSGBOX : {           /* Put up a message box. The mp1       */
  835.                                        /* parameter has the resource ids for  */
  836.                                        /* the message and the title.          */
  837.           USHORT msgid = SHORT1FROMMP(mp1);
  838.           PUCHAR header = getstring(pWinData->hab, pWinData->hResource,
  839.               SHORT2FROMMP(mp1));
  840.           PUCHAR content = getstring(pWinData->hab, pWinData->hResource,
  841.               SHORT1FROMMP(mp1));
  842.                                        /* If we are                           */
  843.                                        /* displaying the ended message, set   */
  844.                                        /* the owner to the desktop so we don't*/
  845.                                        /* steal the focus back from other     */
  846.                                        /* apps.                               */
  847.  
  848.           LONG  rc = WinMessageBox(HWND_DESKTOP, hwnd, content, header,
  849.                                    msgid, SHORT1FROMMP(mp2));
  850.           free(header);
  851.           free(content);
  852.           return  MPFROMSHORT(rc);
  853.         }
  854.         break;
  855.  
  856.       case  START_TIMER :
  857.  
  858.          /* Start a timer to force output after a period of inactivity.       */
  859.  
  860.         if (!pWinData->visible) {      /* Make the window visible, if not     */
  861.                                        /* already.                            */
  862.           WinSendMsg(WinWindowFromID(hwnd, (USHORT)FID_CLIENT),
  863.                      REXX_MAKE_VISIBLE, (MPARAM)0, (MPARAM)0);
  864.         }
  865.         WinStartTimer(pWinData->hab, hwnd, pWinData->timer, TIMER_DELAY);
  866.         pWinData->imp_queued = FALSE;
  867.         break;
  868.  
  869.       case  ADD_STDOUTWIN :
  870.  
  871.          /* Add an output line to the MLE buffer, and start the timer.        */
  872.  
  873.         if (!pWinData->visible) {      /* Make the window visible, if not     */
  874.                                        /* already.                            */
  875.           WinSendMsg(WinWindowFromID(hwnd, (USHORT)FID_CLIENT),
  876.                      REXX_MAKE_VISIBLE, (MPARAM)0, (MPARAM)0);
  877.         }
  878.         if (pWinData->client == hwnd) {
  879.           HWND    wnd = pWinData->outmle;
  880.           PIMPORT im_ptr = pWinData->imp_ptr;
  881.           PUCHAR  ptr = (PUCHAR)im_ptr->data;
  882.           PUCHAR  tmp1 = (PUCHAR)mp1;  /* Obtain the buffer semaphore to      */
  883.                                        /* prevent interference with the input */
  884.                                        /* pipe thread.                        */
  885.  
  886.           DosRequestMutexSem(im_ptr->sem, SEM_INDEFINITE_WAIT);
  887.                                        /* If the string is too                */
  888.                                        /* large, break it up into pieces and  */
  889.                                        /* add to the window.                  */
  890.           while (strlen(tmp1) > (ULONG)IMPORTSIZE-HDRSIZE-1) {
  891.                                        /* Save the character we are about to  */
  892.                                        /* null out                            */
  893.             UCHAR tch = *(tmp1+IMPORTSIZE-HDRSIZE-1);
  894.                                        /* Add smaller string to the window    */
  895.             *(tmp1+IMPORTSIZE-HDRSIZE-1) = '\0';
  896.  
  897.             WinSendMsg(hwnd, ADD_STDOUTWIN, tmp1, (MPARAM)mp1);
  898.                                        /* Then bump the pointer and restore   */
  899.                                        /* the character.                      */
  900.             tmp1 += IMPORTSIZE - HDRSIZE - 1;
  901.             *tmp1 = tch;
  902.           }                            /* endwhile See if there is room left  */
  903.                                        /* in the buffer.                      */
  904.  
  905.           while (((im_ptr->total_size)-(im_ptr->inuse)) <= strlen(tmp1)) {
  906.                                        /* need to import what we have         */
  907.             WinStopTimer(pWinData->hab, hwnd, pWinData->timer);
  908.                                        /* empty the buffer                    */
  909.             Import(pWinData);
  910.           }
  911.  
  912.           strcat(ptr, tmp1);           /* Copy the data to the end of the     */
  913.                                        /* buffer                              */
  914.           im_ptr->inuse = HDRSIZE+strlen(ptr);/* Reset the use count          */
  915.                                        /* and free the semaphore              */
  916.           DosReleaseMutexSem(im_ptr->sem);
  917.           free(mp1);                   /* free the text                       */
  918.                                        /* Start the timer to force output if  */
  919.                                        /* nothing added for the specified     */
  920.                                        /* time.                               */
  921.           WinStartTimer(pWinData->hab, hwnd, pWinData->timer, TIMER_DELAY);
  922.           pWinData->imp_queued = FALSE;
  923.           return (MRESULT)TRUE;
  924.         }
  925.  
  926.         return (MRESULT)FALSE;
  927.         break;
  928.  
  929.       case  HM_QUERY_KEYS_HELP :
  930.  
  931.         return (MRESULT)RX_KEYSHELP;
  932.  
  933.       case  WM_SAVEAPPLICATION :
  934.  
  935.         SaveWindow(pWinData);
  936.         break;
  937.  
  938.       default  :
  939.         break;
  940.     }
  941.     return (WinDefWindowProc(hwnd, msg, mp1, mp2));
  942.  
  943.   }
  944.  
  945. /************************** START OF SPECIFICATIONS ***************************/
  946. /*                                                                            */
  947. /*   SUBROUTINE NAME: RXIOCmds                                                */
  948. /*                                                                            */
  949. /*   DESCRIPTIVE NAME:                                                        */
  950. /*               Process WM_COMMAND messages for the window procedure.        */
  951. /*                                                                            */
  952. /*   FUNCTION:                                                                */
  953. /*               This routine processes all the WM_COMMAND messages that have */
  954. /*               been passed into the MainWndProc. The messages handled are:  */
  955. /*       RXIOA_TRCSTEP  - This requests that the REXX trace be advanced one   */
  956. /*                        step. It is equivalent to an input of a blank line  */
  957. /*                        to a REXX trace read. It is only valid when REXX is */
  958. /*                        waiting for trace input.                            */
  959. /*       RXIOA_TRCLAST  - This requests that the REXX re-trace the last       */
  960. /*                        clause executed. Is is equivalent to an input of an */
  961. /*                        equal sign to a REXX trace read. It is only valid   */
  962. /*                        when REXX is waiting for trace input.               */
  963. /*       RXIOA_TRCOFF   - This requests that the REXX turn off interactive    */
  964. /*                        tracing. Is is equivalent to an input of a "TRACE   */
  965. /*                        OFF" statement to a REXX trace read. It is only     */
  966. /*                        valid when REXX is waiting for trace input.         */
  967. /*       RXIOA_TRACE   - This is a request to turn interactive tracing on    */
  968. /*                        or off. It is only valid when the REXX procedure    */
  969. /*                        has ended and the user has not yet restarted it.    */
  970. /*                        This is because REXX only looks at the trace flag   */
  971. /*                        when it is first called to execute a procedure.     */
  972. /*       RXIOA_HALT     - This requests that the REXX HALT indicator be       */
  973. /*                        raised, requesting the procedure to be interrupted. */
  974. /*       RXIOA_CLEAR    - This is a request to clear the marked area of the   */
  975. /*                        focus window.                                       */
  976. /*       RXIOA_PASTE    - Paste from the clipboard into the input window.     */
  977. /*       RXIOA_COPY     - This is a request to copy the marked area of the    */
  978. /*                        focus window into the clipboard.                    */
  979. /*       RXIOA_ALL      - This is a request to mark the entire output area.   */
  980. /*       RXIOA_FONTS    - Present the user with a dialog to select a font for */
  981. /*                        the output window.                                  */
  982. /*                                                                            */
  983. /*   NOTES:                                                                   */
  984. /*                                                                            */
  985. /*   ENTRY POINT:                                                             */
  986. /*      LINKAGE:                                                              */
  987. /*       MRESULT RXIOCmds(HWND hwnd, MPARAM mp1, PRHWINDATA pWinData)         */
  988. /*                                                                            */
  989. /*   INPUT:                                                                   */
  990. /*       hwnd           - The window handle of the window that received the   */
  991. /*                        command.                                            */
  992. /*       mp1            - The first parameter of the WM_COMMAND message.      */
  993. /*       pWinData       - A pointer to the RHWINDATA structure of the window. */
  994. /*                                                                            */
  995. /*   EXIT-NORMAL:                                                             */
  996. /*       returns TRUE if the file was saved successfully or user response     */
  997. /*       from SAVEAS dialog.                                                  */
  998. /*   EXIT-ERROR:                                                              */
  999. /*       returns FALSE if the file was not saved successfully.                */
  1000. /*                                                                            */
  1001. /*   EFFECTS:                                                                 */
  1002. /*                                                                            */
  1003. /*   INTERNAL REFERENCES:                                                     */
  1004. /*      ROUTINES:                                                             */
  1005. /*       Add_Q_Element  - Adds an entry to an input queue.                    */
  1006. /*       RHWinErrorBox  - Display an error message box.                       */
  1007. /*       ClipBoard        - Perform clipboard related commands.               */
  1008. /*       SizeWindow     - Resize the child windows within the client area.  */
  1009. /*       SelectFont     - Interface to the font selection dialog              */
  1010. /*       SetCheckMark   - Check/uncheck a menu item                           */
  1011. /*                                                                            */
  1012. /*   EXTERNAL REFERENCES:                                                     */
  1013. /*      ROUTINES:                                                             */
  1014. /*       DosRequestMutexSem             WinInvalidateRect                     */
  1015. /*       DosReleaseMutexSem             WinLoadDlg                            */
  1016. /*       GpiQueryFontMetrics            WinLoadString                         */
  1017. /*       WinAlarm                       WinPostMessage                        */
  1018. /*       WinCreateWindow                WinReleasePS                          */
  1019. /*       WinDlgBox                      WinSendMsg                            */
  1020. /*       WinEnableWindowUpdate          WinShowWindow                         */
  1021. /*       WinGetPS                       WinWindowFromID                       */
  1022. /*                                                                            */
  1023. /*                                                                            */
  1024. /*                                                                            */
  1025. /*                                                                            */
  1026. /*                                                                            */
  1027. /**************************** END OF SPECIFICATIONS ***************************/
  1028.  
  1029. MRESULT RXIOCmds(HWND hwnd, MPARAM mp1, PRHWINDATA pWinData)
  1030. {
  1031.     CHAR Temp = '\0';                  /* temporary character                 */
  1032.                                        /* dialog                              */
  1033.     PLIST_ENTRY q_elem;                /* pointer for an element in the input */
  1034.                                        /* queue                               */
  1035.  
  1036.     switch (LOUSHORT(mp1)) {
  1037.  
  1038.       case  RXIOA_TRCSTEP :
  1039.  
  1040.          /* Trace the next clause. This is accomplished by inputting a        */
  1041.          /*   null line.                                                      */
  1042.  
  1043.         if (q_elem = malloc(sizeof(*q_elem))) {
  1044.           q_elem->ptr = strdup("");
  1045.           q_elem->len = strlen(q_elem->ptr);
  1046.           Add_Q_Element(&pWinData->trace_in, q_elem);
  1047.         }
  1048.         break;
  1049.  
  1050.       case  RXIOA_TRCLAST :
  1051.  
  1052.          /* Re-trace the previous clause. This is accomplished by             */
  1053.          /*   inputting an equal (=) sign alone on a line.                    */
  1054.  
  1055.         if (q_elem = malloc(sizeof(*q_elem))) {
  1056.           q_elem->ptr = strdup("=");
  1057.           q_elem->len = strlen(q_elem->ptr);
  1058.           Add_Q_Element(&pWinData->trace_in, q_elem);
  1059.         }
  1060.         break;
  1061.  
  1062.       case  RXIOA_TRCOFF :
  1063.  
  1064.          /* Turn tracing off by calling RexxResetTrace                        */
  1065.  
  1066.         RexxResetTrace(pWinData->proc_id, pWinData->rexx_tid);
  1067.         pWinData->tracebit = FALSE;
  1068.                                        /* Clear the checkmark                 */
  1069.         SetCheckMark(pWinData->frame, RXIOA_TRACE, FALSE);
  1070.                                        /* send a null line to end pause       */
  1071.         if (q_elem = malloc(sizeof(*q_elem))) {
  1072.           q_elem->ptr = strdup("");
  1073.           q_elem->len = strlen(q_elem->ptr);
  1074.           Add_Q_Element(&pWinData->trace_in, q_elem);
  1075.         }
  1076.         break;
  1077.  
  1078.       case  RXIOA_TRACE :
  1079.  
  1080.          /* Change the state of the interactive trace indiciator. This        */
  1081.          /*   will turn tracing on immediately (with the next phrase          */
  1082.          /*   executed).                                                      */
  1083.  
  1084.         if (pWinData->tracebit = (BOOL)(!pWinData->tracebit)) {
  1085.           RexxSetTrace(pWinData->proc_id, pWinData->rexx_tid);
  1086.         }
  1087.         else {
  1088.           RexxResetTrace(pWinData->proc_id, pWinData->rexx_tid);
  1089.         }
  1090.         SetCheckMark(pWinData->frame, RXIOA_TRACE, pWinData->tracebit);
  1091.  
  1092.         break;
  1093.  
  1094.       case  RXIOA_HALT :
  1095.  
  1096.          /* Change the Halt Procedure indicator. This will cause REXX to      */
  1097.          /*   terminate execution of the procedure when the next phrase       */
  1098.          /*   is executed.                                                    */
  1099.  
  1100.         RexxSetHalt(pWinData->proc_id, pWinData->rexx_tid);
  1101.  
  1102.         if (!pWinData->RxHalt) {
  1103.           pWinData->RxHalt = TRUE;
  1104.           SetCheckMark(pWinData->frame, RXIOA_HALT, pWinData->RxHalt);
  1105.         }
  1106.         break;
  1107.  
  1108.       /************************************************************************/
  1109.       /* These messages relate to clipboard operations                        */
  1110.       /************************************************************************/
  1111.  
  1112.       case  RXIOA_CLEAR :
  1113.  
  1114.         if (pWinData->infocus) {       /* clear the input window, because it  */
  1115.                                        /* has the focus                       */
  1116.           WinSendMsg(pWinData->insle, EM_CLEAR, (MPARAM)0, (MPARAM)0);
  1117.         }
  1118.         else {                         /* clear the MLE                       */
  1119.           ClipBoard(hwnd, MLM_CLEAR, RXIOH_ERR_CLEAR, pWinData);
  1120.         }
  1121.         break;
  1122.  
  1123.       case  RXIOA_PASTE :
  1124.  
  1125.          /* put the text from the clipboard into the input window             */
  1126.  
  1127.         WinSendMsg(pWinData->insle, EM_PASTE, (MPARAM)0, (MPARAM)0);
  1128.         break;
  1129.  
  1130.       case  RXIOA_COPY :
  1131.  
  1132.         if (pWinData->infocus) {       /* Copy text from input window         */
  1133.           WinSendMsg(pWinData->insle, EM_COPY, (MPARAM)0, (MPARAM)0);
  1134.         }
  1135.         else {                         /* Get the text from the MLE           */
  1136.           ClipBoard(hwnd, MLM_COPY, RXIOH_ERR_COPY, pWinData);
  1137.         }
  1138.         break;
  1139.  
  1140.       /************************************************************************/
  1141.       /* Select all                                                           */
  1142.       /************************************************************************/
  1143.  
  1144.       case  RXIOA_ALL : {
  1145.  
  1146.           ULONG  usFileSize;
  1147.  
  1148.           WinEnableWindowUpdate(hwnd, FALSE);
  1149.                                        /* disable updates Get length of the   */
  1150.                                        /* output in the MLE                   */
  1151.           usFileSize = (ULONG )WinSendMsg(WinWindowFromID(hwnd,
  1152.                                           (USHORT)MLE_WNDW),
  1153.                                           MLM_QUERYTEXTLENGTH,
  1154.                                           (MPARAM)0, (MPARAM)0);
  1155.                                        /* Select all of the output in the MLE */
  1156.           WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  1157.                      MLM_SETSEL, (MPARAM)0L, MPFROMSHORT(usFileSize));
  1158.           WinInvalidateRect(hwnd, NULL, TRUE);
  1159.                                        /* update the window                   */
  1160.           WinEnableWindowUpdate(hwnd, TRUE);
  1161.                                        /* Make MLE so that it can't be undone */
  1162.           WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  1163.                      MLM_RESETUNDO, (MPARAM)0, (MPARAM)0);
  1164.         }
  1165.         break;
  1166.  
  1167.  
  1168.       /************************************************************************/
  1169.       /* Present Font dialog; the dialog will change the PS attribute         */
  1170.       /************************************************************************/
  1171.  
  1172.       case  RXIOA_FONTS :
  1173.         WinSendMsg(WinWindowFromID(hwnd, (USHORT) MLE_WNDW),
  1174.                    MLM_RESETUNDO, (MPARAM)0, (MPARAM)0);
  1175.         SelectFont(pWinData);
  1176.         break;
  1177.  
  1178.       /************************************************************************/
  1179.       /* Display Help for help panel                                          */
  1180.       /************************************************************************/
  1181.  
  1182.       case  RXIOM_HELPHELP :
  1183.  
  1184.         if (pWinData->HelpInst != NULLHANDLE) {
  1185.           WinSendMsg(pWinData->HelpInst, HM_DISPLAY_HELP, (MPARAM)0, (MPARAM)0);
  1186.         }
  1187.         else {
  1188.           WinSendMsg(pWinData->client,
  1189.                      RXIOB_MSGBOX,
  1190.                      MPFROM2SHORT(NO_HELP_MGR, HELP_ERR),
  1191.                      MPFROMLONG(MB_ENTER|MB_CUACRITICAL|MB_MOVEABLE));
  1192.         }
  1193.         break;
  1194.  
  1195.       /************************************************************************/
  1196.       /* Display Extended help panel                                          */
  1197.       /************************************************************************/
  1198.  
  1199.       case  RXIOM_EXTHELP :
  1200.  
  1201.         if (pWinData->HelpInst != NULLHANDLE) {
  1202.           WinSendMsg(pWinData->HelpInst, HM_EXT_HELP, (MPARAM)0, (MPARAM)0);
  1203.         }
  1204.         else {
  1205.           WinSendMsg(pWinData->client,
  1206.                      RXIOB_MSGBOX,
  1207.                      MPFROM2SHORT(NO_HELP_MGR, HELP_ERR),
  1208.                      MPFROMLONG(MB_ENTER|MB_CUACRITICAL|MB_MOVEABLE));
  1209.         }
  1210.         break;
  1211.  
  1212.       /************************************************************************/
  1213.       /* Display keys help panel                                              */
  1214.       /************************************************************************/
  1215.  
  1216.       case  RXIOM_KEYSHELP :
  1217.  
  1218.         if (pWinData->HelpInst != NULLHANDLE) {
  1219.           WinSendMsg(pWinData->HelpInst, HM_KEYS_HELP, (MPARAM)0, (MPARAM)0);
  1220.         }
  1221.         else {
  1222.           WinSendMsg(pWinData->client, RXIOB_MSGBOX,
  1223.                      MPFROM2SHORT(NO_HELP_MGR, HELP_ERR),
  1224.                      MPFROMLONG(MB_ENTER|MB_CUACRITICAL|MB_MOVEABLE));
  1225.         }
  1226.         break;
  1227.  
  1228.       /************************************************************************/
  1229.       /* Display help index                                                   */
  1230.       /************************************************************************/
  1231.  
  1232.       case  RXIOM_INDEXHELP :
  1233.  
  1234.         if (pWinData->HelpInst != NULLHANDLE) {
  1235.           WinSendMsg(pWinData->HelpInst, HM_HELP_INDEX, (MPARAM)0, (MPARAM)0);
  1236.         }
  1237.         else {
  1238.           WinSendMsg(pWinData->client, RXIOB_MSGBOX,
  1239.                      MPFROM2SHORT(NO_HELP_MGR, HELP_ERR),
  1240.                      MPFROMLONG(MB_ENTER|MB_CUACRITICAL|MB_MOVEABLE));
  1241.         }
  1242.         break;
  1243.  
  1244.       /************************************************************************/
  1245.       /* Option not implemented: Warn the user                                */
  1246.       /************************************************************************/
  1247.  
  1248.       default  :
  1249.         WinAlarm(HWND_DESKTOP, WA_ERROR);
  1250.     }                                  /* endswitch                           */
  1251.     return (MRESULT)FALSE;
  1252. }
  1253.  
  1254. /************************** START OF SPECIFICATIONS ***************************/
  1255. /*                                                                            */
  1256. /*   SUBROUTINE NAME: ClipBoard                                               */
  1257. /*                                                                            */
  1258. /*   DESCRIPTIVE NAME:                                                        */
  1259. /*               Process the MLE clipboard functions by passing the message   */
  1260. /*               on to the MLE window.                                        */
  1261. /*                                                                            */
  1262. /*   FUNCTION:                                                                */
  1263. /*               All of the clipboard related functions are handled very      */
  1264. /*               simliarly and so are just passed directly on to the MLE      */
  1265. /*               window for processing. In case of a failure, a message       */
  1266. /*               box is popped up to notify the user.                         */
  1267. /*                                                                            */
  1268. /*   NOTES:                                                                   */
  1269. /*                                                                            */
  1270. /*   ENTRY POINT:                                                             */
  1271. /*      LINKAGE:                                                              */
  1272. /*          CipBoard(hWnd, MLECMsg, ErrMsg, pWinData)                         */
  1273. /*                                                                            */
  1274. /*   INPUT:                                                                   */
  1275. /*       hWnd           - The handle of the window that received the message  */
  1276. /*       MLECMsg        - The message to be processed.                        */
  1277. /*       ErrMsg         - The resource ID of the error message to use in      */
  1278. /*                        case of an error.                                   */
  1279. /*                                                                            */
  1280. /*   EXIT-NORMAL:                                                             */
  1281. /*                                                                            */
  1282. /*   EXIT-ERROR:                                                              */
  1283. /*                                                                            */
  1284. /*   EFFECTS:                                                                 */
  1285. /*                                                                            */
  1286. /*   INTERNAL REFERENCES:                                                     */
  1287. /*      ROUTINES:                                                             */
  1288. /*                                                                            */
  1289. /*   EXTERNAL REFERENCES:                                                     */
  1290. /*      ROUTINES:                                                             */
  1291. /*       WinSendMsg                                                           */
  1292. /*       WinWindowFromID                                                      */
  1293. /*                                                                            */
  1294. /**************************** END OF SPECIFICATIONS ***************************/
  1295.  
  1296.   void ClipBoard(HWND hwnd, USHORT MLECMsg, ULONG ErrMsg,
  1297.       PRHWINDATA pWinData) {
  1298.  
  1299.    /* If an error occurs, put up a message box                                */
  1300.  
  1301.     if (!((MRESULT)WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  1302.         MLECMsg, (MPARAM)0, (MPARAM)0)))
  1303.  
  1304.       WinSendMsg(pWinData->client, RXIOB_MSGBOX,
  1305.                  MPFROM2SHORT(ErrMsg, RXIOH_ERR_CLIPBRD),
  1306.                  MPFROMLONG(MB_ENTER|MB_CUACRITICAL|MB_MOVEABLE));
  1307.   }
  1308.  
  1309. /************************** START OF SPECIFICATIONS ***************************/
  1310. /*                                                                            */
  1311. /*   SUBROUTINE NAME: Import                                                  */
  1312. /*                                                                            */
  1313. /*   DESCRIPTIVE NAME:                                                        */
  1314. /*               Add the information collected into the import buffer into    */
  1315. /*               the MLE window.                                              */
  1316. /*                                                                            */
  1317. /*   FUNCTION:                                                                */
  1318. /*               Adding information to the MLE involves considerable          */
  1319. /*               overhead. To do so on each individual line would be          */
  1320. /*               unacceptably slow for any considerable amount of output.     */
  1321. /*               Therefore, output is collected into a buffer and output      */
  1322. /*               to the MLE when the buffer is full, or there has been no     */
  1323. /*               output added for some period of time. This is the routine    */
  1324. /*               to take the information collected in the buffer area and     */
  1325. /*               add it to the output window.                                 */
  1326. /*                                                                            */
  1327. /*   NOTES:                                                                   */
  1328. /*                                                                            */
  1329. /*   ENTRY POINT:                                                             */
  1330. /*      LINKAGE:                                                              */
  1331. /*          void Import(PRHWINDATA pWinData)                                  */
  1332. /*                                                                            */
  1333. /*   INPUT:                                                                   */
  1334. /*       pWinData       - Pointer to global control block.                    */
  1335. /*                                                                            */
  1336. /*   EXIT-NORMAL:                                                             */
  1337. /*                                                                            */
  1338. /*   EXIT-ERROR:                                                              */
  1339. /*                                                                            */
  1340. /*   EFFECTS:                                                                 */
  1341. /*                                                                            */
  1342. /*   INTERNAL REFERENCES:                                                     */
  1343. /*      ROUTINES:                                                             */
  1344. /*       RHWinErrorBox  - Display an error message box.                       */
  1345. /*                                                                            */
  1346. /*   EXTERNAL REFERENCES:                                                     */
  1347. /*      ROUTINES:                                                             */
  1348. /*       WinPostMsg                                                           */
  1349. /*       WinQueryWindow                                                       */
  1350. /*       WinSendMsg                                                           */
  1351. /*                                                                            */
  1352. /**************************** END OF SPECIFICATIONS ***************************/
  1353.  
  1354.   void Import(PRHWINDATA pWinData) {
  1355.     IPT ipt = (IPT)NULL;               /* Integer pointer type for MLE        */
  1356.  
  1357.  
  1358.     if (pWinData->imp_ptr->inuse > HDRSIZE) {
  1359.  
  1360.       /* Get the number of characters currently in the MLE                    */
  1361.  
  1362.       ipt = (IPT)WinSendMsg(pWinData->outmle, MLM_QUERYTEXTLENGTH,
  1363.           (MPARAM)0, (MPARAM)0);
  1364.  
  1365.       /* If we had an error setting up the transfer buffer, display a message */
  1366.  
  1367.       if (!WinSendMsg(pWinData->outmle, MLM_SETIMPORTEXPORT,
  1368.           pWinData->imp_ptr->data,
  1369.           MPFROMLONG(pWinData->imp_ptr->total_size-HDRSIZE))) {
  1370.         RHWinErrorBox(pWinData->hab, pWinData->outmle, pWinData->hResource,
  1371.             MLE_IMEXPORT_ERROR, MB_OK|MB_CUACRITICAL);
  1372.         WinPostMsg(WinQueryWindow(pWinData->outmle, QW_PARENT),
  1373.                    WM_CLOSE, (MPARAM)0, (MPARAM)0);
  1374.         return ;
  1375.       }
  1376.       WinEnableWindowUpdate(pWinData->outmle, FALSE);
  1377.  
  1378.       /* Set the MLE to not translate the input                               */
  1379.       WinSendMsg(pWinData->outmle, MLM_FORMAT, MPFROMSHORT(MLFIE_NOTRANS),
  1380.           (MPARAM)0);
  1381.  
  1382.       /* Set the MLE so we can add data to it                                 */
  1383.       WinSendMsg(pWinData->outmle, MLM_SETREADONLY, FALSE, (MPARAM)0);
  1384.  
  1385.       /* Add the data to the MLE, if we get an error, display a message       */
  1386.                                        /* upon return, point to end of data   */
  1387.       if (!WinSendMsg(pWinData->outmle, MLM_IMPORT, &ipt,
  1388.           MPFROMLONG(pWinData->imp_ptr->inuse-HDRSIZE))) {
  1389.  
  1390.         RHWinErrorBox(pWinData->hab, pWinData->outmle, pWinData->hResource,
  1391.             MLE_IMPORT_ERROR, MB_OK|MB_CUACRITICAL);
  1392.  
  1393.          /* It probably failed because the line is too long, so append a      */
  1394.          /* new line and try again.                                           */
  1395.         WinSendMsg(pWinData->outmle, MLM_SETSEL, MPFROMLONG(ipt),
  1396.             MPFROMLONG(ipt));
  1397.         WinSendMsg(pWinData->outmle, MLM_INSERT, "\r", (MPARAM)0);
  1398.  
  1399.          /* Move the selection to the end of the input                        */
  1400.         ipt = (IPT)WinSendMsg(pWinData->outmle, MLM_QUERYTEXTLENGTH, (MPARAM)0,
  1401.             (MPARAM)0);
  1402.  
  1403.         if (!WinSendMsg(pWinData->outmle, MLM_IMPORT, &ipt,
  1404.             MPFROMLONG(pWinData->imp_ptr->inuse-HDRSIZE) )) {
  1405.                                        /* If we still couldn't import         */
  1406.                                        /* anything, give up.                  */
  1407.           WinPostMsg(WinQueryWindow(pWinData->outmle, QW_PARENT),
  1408.                      WM_CLOSE, (MPARAM)0, (MPARAM)0);
  1409.         }
  1410.       }
  1411.  
  1412.       /* Update the ptr structure                                             */
  1413.  
  1414.       *(PUCHAR)(pWinData->imp_ptr->data) = '\0';  
  1415.       pWinData->imp_ptr->inuse = HDRSIZE;
  1416.  
  1417.       /* Move the cursor to the end of the new data                           */
  1418.       WinSendMsg(pWinData->outmle, MLM_SETSEL, MPFROMLONG(ipt), MPFROMLONG(ipt));
  1419.  
  1420.       WinEnableWindowUpdate(pWinData->outmle, TRUE);
  1421.  
  1422.       /* Set the MLE to normal export mode                                    */
  1423.       WinSendMsg(pWinData->outmle, MLM_FORMAT, MLE_TXT_FMT, (MPARAM)0);
  1424.  
  1425.       /* Set the MLE back to readonly                                         */
  1426.       WinSendMsg(pWinData->outmle, MLM_SETREADONLY, MPFROMLONG(TRUE), (MPARAM)0);
  1427.  
  1428.     }
  1429.   }
  1430.  
  1431. /************************** START OF SPECIFICATIONS ***************************/
  1432. /*                                                                            */
  1433. /*   SUBROUTINE NAME: SizeWindow                                              */
  1434. /*                                                                            */
  1435. /*   DESCRIPTIVE NAME:                                                        */
  1436. /*               Size the MLE output window and the Entry Field input window  */
  1437. /*               to fit the client area.                                      */
  1438. /*                                                                            */
  1439. /*   FUNCTION:                                                                */
  1440. /*               Whenever the client window is sized, this routine is         */
  1441. /*               called to resize the MLE output window and the Entry Field   */
  1442. /*               control used for input to fit properly within the new        */
  1443. /*               client area.                                                 */
  1444. /*                                                                            */
  1445. /*   NOTES:                                                                   */
  1446. /*                                                                            */
  1447. /*   ENTRY POINT:                                                             */
  1448. /*      LINKAGE:                                                              */
  1449. /*          void SizeWindow(HWND hwnd, PRHWINDATA pWinData)                   */
  1450. /*                                                                            */
  1451. /*   INPUT:                                                                   */
  1452. /*       hwnd           - The handle of the client window.                    */
  1453. /*       pWinData       - A pointer to the RHWINDATA structure of the window. */
  1454. /*                                                                            */
  1455. /*   EXIT-NORMAL:                                                             */
  1456. /*                                                                            */
  1457. /*   EXIT-ERROR:                                                              */
  1458. /*                                                                            */
  1459. /*   EFFECTS:                                                                 */
  1460. /*                                                                            */
  1461. /*   INTERNAL REFERENCES:                                                     */
  1462. /*      ROUTINES:                                                             */
  1463. /*                                                                            */
  1464. /*   EXTERNAL REFERENCES:                                                     */
  1465. /*      ROUTINES:                                                             */
  1466. /*       WinQueryWindow                                                       */
  1467. /*       WinQueryWindowPos                                                    */
  1468. /*       WinSetWindowPos                                                      */
  1469. /*       WinWindowFromID                                                      */
  1470. /*                                                                            */
  1471. /**************************** END OF SPECIFICATIONS ***************************/
  1472.  
  1473.   void SizeWindow(HWND hwnd, PRHWINDATA pWinData) {
  1474.     HWND hOwner;                       /* Window handle of parent window      */
  1475.     SWP windowPos;                     /* info on window position             */
  1476.     ULONG  in_hgt = pWinData->in_hgt;  /* Height for input entry field        */
  1477.  
  1478.  
  1479.     if (!pWinData->visible)
  1480.       return ;                         /* If the window is not visible, do    */
  1481.                                        /* nothing                             */
  1482.     hOwner = WinQueryWindow(hwnd, QW_PARENT);
  1483.  
  1484.    /* Get Window positions                                                    */
  1485.     WinQueryWindowPos(WinWindowFromID(hOwner, (USHORT) FID_CLIENT), &windowPos);
  1486.  
  1487.    /* adjust MLE and input field, if created                                  */
  1488.     if (pWinData->outmle && pWinData->insle) {
  1489.  
  1490.       WinSetWindowPos(pWinData->outmle,   /* set window a bit smaller         */
  1491.                       HWND_TOP,
  1492.                       (SHORT)BORDER_MARGIN,
  1493.                       (SHORT)BORDER_MARGIN-1,
  1494.                       (SHORT)(windowPos.cx-(BORDER_MARGIN *2)+1),
  1495.                       (SHORT)(windowPos.cy-in_hgt-(BORDER_MARGIN *6)),
  1496.                       SWP_SIZE|SWP_MOVE|SWP_ZORDER|SWP_SHOW);
  1497.  
  1498.       WinSetWindowPos(pWinData->insle,   /* set window a bit smaller          */
  1499.                       HWND_TOP,
  1500.                       (SHORT)(BORDER_MARGIN *3+pWinData->wtitle),
  1501.                       (SHORT)(windowPos.cy-in_hgt-BORDER_MARGIN *3),
  1502.                       (SHORT)(windowPos.cx-BORDER_MARGIN *5-pWinData->wtitle),
  1503.                       (SHORT)pWinData->in_hgt,
  1504.                       SWP_SIZE|SWP_MOVE|SWP_ZORDER|SWP_SHOW);
  1505.     }
  1506.     return ;
  1507.   }
  1508.  
  1509. /************************** START OF SPECIFICATIONS ***************************/
  1510. /*                                                                            */
  1511. /*   SUBROUTINE NAME: io_routine                                              */
  1512. /*                                                                            */
  1513. /*   DESCRIPTIVE NAME:                                                        */
  1514. /*               Process the REXX IO exit.                                    */
  1515. /*                                                                            */
  1516. /*   FUNCTION:                                                                */
  1517. /*               This function has been registered to handle the IO exits     */
  1518. /*               for the REXX procedure. The interface is defined by REXXSAA. */
  1519. /*               For the input requests (RXSIOTRD and RXSIODTR), first the    */
  1520. /*               window is made visible, if it isn't already, and then the    */
  1521. /*               trace options are enabled/disabled as appropriate. Then      */
  1522. /*               a return code is set to allow normal operation of I/O by     */
  1523. /*               REXX.                                                        */
  1524. /*                                                                            */
  1525. /*   NOTES:                                                                   */
  1526. /*                                                                            */
  1527. /*   ENTRY POINT:                                                             */
  1528. /*      LINKAGE:                                                              */
  1529. /*          LONG  io_routine( LONG  exitno, LONG  subfunc, PUCHAR parmblock)  */
  1530. /*                                                                            */
  1531. /*   INPUT:                                                                   */
  1532. /*       The arguments are defined by the REXX interface specifications.      */
  1533. /*                                                                            */
  1534. /*   EXIT-NORMAL:                                                             */
  1535. /*                                                                            */
  1536. /*   EXIT-ERROR:                                                              */
  1537. /*                                                                            */
  1538. /*   EFFECTS:                                                                 */
  1539. /*                                                                            */
  1540. /*   INTERNAL REFERENCES:                                                     */
  1541. /*      ROUTINES:                                                             */
  1542. /*       Remove_Q_Element: Remove a queue element, wait if none there         */
  1543. /*       SetCheckMark   - Check/uncheck a menu item                           */
  1544. /*       SetOptions     - Enable/disable menu items.                          */
  1545. /*                                                                            */
  1546. /*   EXTERNAL REFERENCES:                                                     */
  1547. /*      ROUTINES:                                                             */
  1548. /*                                                                            */
  1549. /**************************** END OF SPECIFICATIONS ***************************/
  1550.  
  1551. LONG  io_routine(LONG  exitno, LONG  subfunc, PUCHAR parmblock)
  1552. {
  1553.     LONG           rc;                 /* rc=1 says use standard I/O routines */
  1554.     PLIST_ENTRY    q_elem;             /* entry in queue                      */
  1555.     RXSIOSAY_PARM *sparm = (RXSIOSAY_PARM *)parmblock;/* struc for IO exit    */
  1556.     PRHWINDATA     userdata[2];        /* registered user data                */
  1557.     PRHWINDATA     pWinData;           /* global data anchor                  */
  1558.     USHORT         exists;             /* existance flag                      */
  1559.  
  1560.                                        /* retrieve the anchor                 */
  1561.     if (RexxQueryExit(PMRXIO_EXIT, NULL, &exists, (PUCHAR)userdata))
  1562.                                        /* failed?                             */
  1563.       return RXEXIT_RAISE_ERROR;       /* raise a system failure error        */
  1564.  
  1565.     rc = RXEXIT_NOT_HANDLED;           /* let others go through               */
  1566.     pWinData = userdata[0];            /* get saved global anchor             */
  1567.  
  1568.     if (exitno == RXSIO) {
  1569.  
  1570.       switch (subfunc) {
  1571.  
  1572.         case  RXSIODTR :               /* For trace read we want to enable the*/
  1573.                                        /* trace menu items so we must perform */
  1574.                                        /* the read ourselves.                 */
  1575.                                        /* Enable all the options              */
  1576.           SetOptions(pWinData->frame, RXIOA_TRCSTEP, TRUE);
  1577.           SetOptions(pWinData->frame, RXIOA_TRCLAST, TRUE);
  1578.           SetOptions(pWinData->frame, RXIOA_TRCOFF, TRUE);
  1579.  
  1580.           if (!pWinData->tracebit) {   /* Set tracing active flag in menu     */
  1581.             SetCheckMark(pWinData->frame, RXIOA_TRACE,
  1582.                 (BOOL)(!pWinData->tracebit));
  1583.           }
  1584.           pWinData->trace_inp = TRUE;  /* Set the trace active flag for IO    */
  1585.           pWinData->in_type = TRC_IN;
  1586.  
  1587.           q_elem = Remove_Q_Element(&pWinData->trace_in);/* And get input     */
  1588.           pWinData->in_type = STD_IN;
  1589.           pWinData->trace_inp = FALSE; /* Reset the trace active flag for IO  */
  1590.                                        /* Disable all the options             */
  1591.           SetOptions(pWinData->frame, RXIOA_TRCSTEP, FALSE);
  1592.           SetOptions(pWinData->frame, RXIOA_TRCLAST, FALSE);
  1593.           SetOptions(pWinData->frame, RXIOA_TRCOFF, FALSE);
  1594.  
  1595.           if (!pWinData->tracebit) {   /* Reset the trace flag as appropriate */
  1596.             SetCheckMark(pWinData->frame, RXIOA_TRACE, pWinData->tracebit);
  1597.           }
  1598.  
  1599.          /* Copy the input line to the return area.                           */
  1600.  
  1601.           strcpy(sparm->rxsio_string.strptr, q_elem->ptr);
  1602.           sparm->rxsio_string.strlength = strlen(q_elem->ptr);
  1603.           free(q_elem->ptr);           /* And free the memory.                */
  1604.           free(q_elem);
  1605.           rc = RXEXIT_HANDLED;         /* Set the return code to              */
  1606.           break;                       /* input complete.                     */
  1607.  
  1608.         case  RXSIOTRD :               /* If a read occurs and the window is  */
  1609.                                        /* not visible, make it visible.       */
  1610.  
  1611.           if (!pWinData->visible) {
  1612.  
  1613.             while (!WinPostMsg(pWinData->client, (USHORT)REXX_MAKE_VISIBLE,
  1614.                 (MPARAM)0, (MPARAM)0)) {
  1615.               DosSleep((ULONG)TIMER_DELAY);
  1616.             }
  1617.           }
  1618.           break;
  1619.  
  1620.         default  :                     /* For all else, let REXX do the       */
  1621.           break;                       /* work.                               */
  1622.       }                                /* endswitch                           */
  1623.     }
  1624.     return  rc;
  1625. }
  1626.  
  1627. /************************** START OF SPECIFICATIONS ***************************/
  1628. /*                                                                            */
  1629. /*   SUBROUTINE NAME: stdinpipe                                               */
  1630. /*                                                                            */
  1631. /*   DESCRIPTIVE NAME:                                                        */
  1632. /*               Send input lines to the standard input of child processes.   */
  1633. /*                                                                            */
  1634. /*   FUNCTION:                                                                */
  1635. /*               This function is the thread that waits for input for child   */
  1636. /*               processes started by calls to the subcommand environment,    */
  1637. /*               passes that input through to the pipe connected to their     */
  1638. /*               standard input handle.                                       */
  1639. /*                                                                            */
  1640. /*   NOTES:                                                                   */
  1641. /*                                                                            */
  1642. /*   ENTRY POINT:                                                             */
  1643. /*      LINKAGE:                                                              */
  1644. /*          void stdinpipe()                                                  */
  1645. /*                                                                            */
  1646. /*   INTERNAL REFERENCES:                                                     */
  1647. /*      ROUTINES:                                                             */
  1648. /*       Remove_Q_Element - Removes an entry from an input queue. Waits for   */
  1649. /*                          one if the queue is empty.                        */
  1650. /*                                                                            */
  1651. /*   EXTERNAL REFERENCES:                                                     */
  1652. /*      ROUTINES:                                                             */
  1653. /*       DosWaitEventSem                                                      */
  1654. /*       DosWrite                                                             */
  1655. /*                                                                            */
  1656. /**************************** END OF SPECIFICATIONS ***************************/
  1657.  
  1658.   void stdinpipe(PRHWINDATA pWinData) {
  1659.     PLIST_ENTRY q_elem;                /* element from queue                  */
  1660.     UCHAR       str[ANSLEN+5];         /* data from queue entry               */
  1661.     ULONG       written;               /* bytes written by DosWrite           */
  1662.  
  1663.     while (TRUE) {
  1664.       q_elem = Remove_Q_Element(&pWinData->pipe_in);
  1665.       strcpy(str, q_elem->ptr);
  1666.       strcat(str, "\r\n");
  1667.  
  1668.       DosWrite(pWinData->stdin_w, str, strlen(str), &written);
  1669.       free(q_elem->ptr);
  1670.       free(q_elem);
  1671.     }
  1672.     DosExit(EXIT_THREAD, 0);           /* end the thread                      */
  1673.   }
  1674.  
  1675. /************************** START OF SPECIFICATIONS ***************************/
  1676. /*                                                                            */
  1677. /*   SUBROUTINE NAME: stdoutpipe                                              */
  1678. /*                                                                            */
  1679. /*   DESCRIPTIVE NAME:                                                        */
  1680. /*               Send lines from the standard output of child processes to    */
  1681. /*               the output window.                                           */
  1682. /*                                                                            */
  1683. /*   FUNCTION:                                                                */
  1684. /*               This function is the thread that waits for output from child */
  1685. /*               processes started by calls to the subcommand environment,    */
  1686. /*               passes that output through to the output window.             */
  1687. /*                                                                            */
  1688. /*   NOTES:                                                                   */
  1689. /*                                                                            */
  1690. /*   ENTRY POINT:                                                             */
  1691. /*      LINKAGE:                                                              */
  1692. /*          void stdoutpipe()                                                 */
  1693. /*                                                                            */
  1694. /*   INPUT:                                                                   */
  1695. /*                                                                            */
  1696. /*   EXIT-NORMAL:                                                             */
  1697. /*                                                                            */
  1698. /*   EXIT-ERROR:                                                              */
  1699. /*                                                                            */
  1700. /*   EFFECTS:                                                                 */
  1701. /*                                                                            */
  1702. /*   INTERNAL REFERENCES:                                                     */
  1703. /*      ROUTINES:                                                             */
  1704. /*       addline - Macro to add a line to the output window                   */
  1705. /*                                                                            */
  1706. /*   EXTERNAL REFERENCES:                                                     */
  1707. /*      ROUTINES:                                                             */
  1708. /*       DosPostEventSem                                                      */
  1709. /*       DosRequestMutexSem                                                   */
  1710. /*       DosReleaseMutexSem                                                   */
  1711. /*       DosWaitEventSem                                                      */
  1712. /*       DosSleep                                                             */
  1713. /*                                                                            */
  1714. /**************************** END OF SPECIFICATIONS ***************************/
  1715.  
  1716.   void stdoutpipe(PRHWINDATA pWinData) {
  1717.     UCHAR  buffer[MAXWIDTH];           /* holds data from standard out        */
  1718.     UCHAR  tchar = '\0';               /* temporary character variable        */
  1719.     PUCHAR tptr;                       /* character pointer                   */
  1720.     ULONG  len;                        /* counter                             */
  1721.     ULONG  nread;                      /* bytes read                          */
  1722.  
  1723.     USHORT         exists;             /* existance flag                      */
  1724.  
  1725.                                        /* retrieve the anchor                 */
  1726.     RexxQueryExit(PMRXIO_EXIT, NULL, &exists, NULL);
  1727.  
  1728.     while (!pWinData->stopoutpipe) {
  1729.  
  1730.       len = 0;                         /* initialize count back to 0          */
  1731.       buffer[0] = '\0';                /* initialize buffer                   */
  1732.  
  1733.       /* Loop here until we see a new line, or the buffer is full             */
  1734.       do {
  1735.         if (!DosRead(pWinData->stdout_r,&tchar, 1, &nread) && nread) {
  1736.           if (tchar == '\r') {
  1737.             DosRead(pWinData->stdout_r,&tchar, 1, &nread);
  1738.             if (tchar != '\n')
  1739.               buffer[len++] = '\n';
  1740.           }
  1741.           buffer[len++] = (UCHAR)tchar;
  1742.         }
  1743.       }
  1744.  
  1745.       while (len < MAXWIDTH-1 && tchar != '\n');
  1746.  
  1747.       buffer[len] = END_STR;           /* Terminate the string                */
  1748.  
  1749.       if (pWinData->stopoutpipe)       /* shutdown flag?                      */
  1750.         break;                         /* time to leave                       */
  1751.  
  1752.       /* Now add the data into the import structure, but first get            */
  1753.       /* the semaphore.                                                       */
  1754.  
  1755.       DosRequestMutexSem(pWinData->imp_ptr->sem, SEM_INDEFINITE_WAIT);
  1756.  
  1757.       /* If there is no more room in the import area, add the data            */
  1758.       if (pWinData->imp_ptr->total_size <= pWinData->imp_ptr->inuse+len+2) {
  1759.         DosReleaseMutexSem(pWinData->imp_ptr->sem);
  1760.         addline(pWinData->client, strdup(buffer));
  1761.  
  1762.          /* Give the MLE a chance to add the data                             */
  1763.  
  1764.         DosSleep((ULONG)TIMER_DELAY);
  1765.  
  1766.       /* There is room in the import area, so add the data                    */
  1767.  
  1768.       }
  1769.  
  1770.       else {
  1771.         tptr = (PUCHAR)pWinData->imp_ptr;
  1772.         strcat((tptr + pWinData->imp_ptr->inuse), buffer); 
  1773.         pWinData->imp_ptr->inuse += len;
  1774.         DosReleaseMutexSem(pWinData->imp_ptr->sem);
  1775.  
  1776.          /* Set (or reset) the timer                                          */
  1777.         if (!pWinData->imp_queued) {
  1778.           pWinData->imp_queued = TRUE;
  1779.  
  1780.           while (!WinPostMsg(pWinData->frame, START_TIMER, NULL, NULL)) {
  1781.             DosSleep((ULONG)TIMER_DELAY);
  1782.           }
  1783.         }
  1784.       }
  1785.     }                                  /* endwhile                            */
  1786.     DosExit(EXIT_THREAD, 0);           /* end the thread                      */
  1787.   }
  1788.  
  1789. /************************** START OF SPECIFICATIONS ***************************/
  1790. /*                                                                            */
  1791. /*   SUBROUTINE NAME: EntryDlgProc                                            */
  1792. /*                                                                            */
  1793. /*   DESCRIPTIVE NAME:                                                        */
  1794. /*               Dialog procedure for the input entry field.                  */
  1795. /*                                                                            */
  1796. /*   FUNCTION:                                                                */
  1797. /*               This is the Dialog Procedure that is registered to handle    */
  1798. /*               the messages coming into the dialog that establishes the     */
  1799. /*               input entry field. The messages that are handled are:        */
  1800. /*       WM_BUTTON1DBLCLK - Copy the marked area from the output window into  */
  1801. /*                          the input window.                                 */
  1802. /*       WM_BUTTON2DBLCLK - Same as pressing ENTER in the input window.       */
  1803. /*       WM_CHAR - several characters are processed here. These include:      */
  1804. /*         VK_NEWLINE   - take the data in the input window and place it on   */
  1805. /*                        current input queue, then clear the entry field.    */
  1806. /*         VK_UP        - place the last entered entry into the input field.  */
  1807. /*               All other messages and keys are handled by default           */
  1808. /*               processing.                                                  */
  1809. /*                                                                            */
  1810. /*   NOTES:                                                                   */
  1811. /*                                                                            */
  1812. /*   ENTRY POINT:                                                             */
  1813. /*      LINKAGE:                                                              */
  1814. /*          This is defined by the PM interface for dialog procedures.        */
  1815. /*                                                                            */
  1816. /*   INPUT:                                                                   */
  1817. /*       item           - The id of the item to enable/disable                */
  1818. /*       option         - TRUE to enable the option, FALSE to disable.        */
  1819. /*                                                                            */
  1820. /*   EXIT-NORMAL:                                                             */
  1821. /*                                                                            */
  1822. /*   EXIT-ERROR:                                                              */
  1823. /*                                                                            */
  1824. /*   EFFECTS:                                                                 */
  1825. /*                                                                            */
  1826. /*   INTERNAL REFERENCES:                                                     */
  1827. /*      ROUTINES:                                                             */
  1828. /*       addline        - Macro to add a line to the output window            */
  1829. /*       Add_Q_Element  - Adds an entry to an input queue.                    */
  1830. /*                                                                            */
  1831. /*                                                                            */
  1832. /*   EXTERNAL REFERENCES:                                                     */
  1833. /*      ROUTINES:                                                             */
  1834. /*       WinDefDlgProc                                                        */
  1835. /*       WinQueryWindow                                                       */
  1836. /*       WinQueryWindowPtr                                                    */
  1837. /*       WinQueryWindowText                                                   */
  1838. /*       WinSendMsg                                                           */
  1839. /*       WinSetFocus                                                          */
  1840. /*       WinSetWindowText                                                     */
  1841. /*                                                                            */
  1842. /**************************** END OF SPECIFICATIONS ***************************/
  1843.  
  1844. MRESULT EXPENTRY EntryDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) {
  1845.     static PUCHAR last_str[2] =  { NULL,NULL };
  1846.     LONG       len = ANSLEN;           /* length of input buffer              */
  1847.     UCHAR      str[ANSLEN+1];          /* holds data from input buffer        */
  1848.     LONG       len1;                   /* number of characters input          */
  1849.     WNDPARAMS  wp;                     /* struc to update input window        */
  1850.     HWND       hOwner;                 /* parent window handle                */
  1851.     IPT        start,end;              /* Insertion point for MLE             */
  1852.     PRHWINDATA pWinData;               /* pointer to WinData structure        */
  1853.  
  1854.     hOwner = WinQueryWindow(hwnd, QW_PARENT);
  1855.     pWinData = WinQueryWindowPtr(hOwner, (SHORT)0);
  1856.  
  1857.     switch (msg) {
  1858.  
  1859.       case  WM_SETFOCUS :
  1860.  
  1861.         pWinData->infocus = (BOOL)(mp2?TRUE:FALSE);
  1862.         break;
  1863.  
  1864.       case  WM_BUTTON1DBLCLK :
  1865.  
  1866.         start = (IPT)WinSendMsg(pWinData->outmle, MLM_QUERYSEL,
  1867.             MPFROMSHORT(1), (MPARAM)0);
  1868.         end = (IPT)WinSendMsg(pWinData->outmle, MLM_QUERYSEL,
  1869.                               MPFROMSHORT(2), (MPARAM)0);
  1870.  
  1871.         if (end > start) {
  1872.           PUCHAR ptr = (PUCHAR)malloc((LONG )(end-start+2));
  1873.           ULONG len = end-start;
  1874.           ULONG got;
  1875.  
  1876.           if (ptr && WinSendMsg(pWinData->outmle, MLM_SETIMPORTEXPORT, ptr,
  1877.               MPFROMLONG(end-start+1))) {
  1878.  
  1879.             if (got = (ULONG)WinSendMsg(pWinData->outmle, MLM_EXPORT,
  1880.                 MPFROMLONG(&start), MPFROMLONG(&len))) {
  1881.               PUCHAR ptr1 = ptr;
  1882.               PUCHAR ptr2;
  1883.  
  1884.               while (!*ptr1)
  1885.                 ptr1++;                /* Skip over any nulls.                */
  1886.               ptr2 = ptr1;             /* Now find the end                    */
  1887.  
  1888.               while (*ptr2 &&          /* at NULL, newline or                 */
  1889.                   (*ptr2 != '\n') &&   /* carraige return.                    */
  1890.                   *ptr2 != '\r' && ptr2-ptr < (INT)got)
  1891.                 *ptr2++;
  1892.               *(ptr2) = '\0';
  1893.               WinSetWindowText(hwnd,
  1894.                                ptr1);  /* Put into SLE                        */
  1895.             }
  1896.           }
  1897.  
  1898.           if (ptr) {
  1899.             free(ptr);
  1900.           }
  1901.         }
  1902.         break;
  1903.  
  1904.       case  WM_BUTTON2DBLCLK :
  1905.  
  1906.         WinSendMsg(hwnd, WM_CHAR, MPFROM2SHORT(KC_VIRTUALKEY, NULL),
  1907.                    MPFROM2SHORT(NULL, VK_NEWLINE));
  1908.         break;
  1909.  
  1910.       case  WM_CHAR :
  1911.  
  1912.         if (!(SHORT1FROMMP(mp1)&KC_KEYUP) &&
  1913.             (SHORT1FROMMP(mp1)&KC_VIRTUALKEY) ) {
  1914.  
  1915.           switch (SHORT2FROMMP(mp2)) {
  1916.  
  1917.             case  VK_BREAK :
  1918.               WinSendMsg(pWinData->client, WM_COMMAND,
  1919.                   MPFROMSHORT(RXIOA_HALT), (MPARAM)0);
  1920.               break;
  1921.  
  1922.             case  VK_NEWLINE :
  1923.             case  VK_ENTER : {
  1924.  
  1925.                 PLIST_ENTRY qe = malloc(sizeof *qe);
  1926.  
  1927.                 len1 = WinQueryWindowText(hwnd, (SHORT)len, str);
  1928.  
  1929.                 if (qe) {
  1930.                   PUCHAR str1 = malloc(len1+4);
  1931.  
  1932.                   if (last_str[pWinData->in_type]) {
  1933.                     free(last_str[pWinData->in_type]);
  1934.                   }
  1935.                   memcpy(str1, str, len1);
  1936.                   strcpy(str1+len1, "\n");
  1937.                                        /* only add input if executing         */
  1938.                   last_str[pWinData->in_type] = strdup(str1);
  1939.  
  1940.                   addline(pWinData->client, strdup(str1));
  1941.                   qe->len = len1;
  1942.                   qe->ptr = strdup(str);
  1943.                   *(str+len1) = '\0';
  1944.  
  1945.                   if (pWinData->trace_inp) {
  1946.                     Add_Q_Element(&pWinData->trace_in, qe);
  1947.                   }
  1948.  
  1949.                   else {
  1950.                     Add_Q_Element(&pWinData->pipe_in, qe);
  1951.                   }
  1952.                   free(str1);
  1953.                 }
  1954.               }
  1955.               WinSendMsg(hwnd, EM_SETSEL, MPFROM2SHORT(0, len1), (MPARAM)0);
  1956.               WinSendMsg(hwnd, EM_CLEAR, (MPARAM)0, (MPARAM)0);
  1957.               return (MRESULT)TRUE;
  1958.               break;
  1959.  
  1960.             case  VK_UP :
  1961.  
  1962.               if (last_str[pWinData->in_type]) {
  1963.                 WinSendMsg(hwnd, EM_SETSEL, MPFROM2SHORT(0, len1), (MPARAM)0);
  1964.                 WinSendMsg(hwnd, EM_CLEAR, (MPARAM)0, (MPARAM)0);
  1965.                 *(last_str[pWinData->in_type] +
  1966.                     strlen(last_str[pWinData->in_type])-1) = '\0';
  1967.                 wp.fsStatus = WPM_TEXT+WPM_CCHTEXT;
  1968.                 wp.cchText = (SHORT)strlen(last_str[pWinData->in_type]);
  1969.                 wp.pszText = strdup(last_str[pWinData->in_type]);
  1970.                 WinSendMsg(hwnd, WM_SETWINDOWPARAMS, &wp, (MPARAM)0);
  1971.                 *(last_str[pWinData->in_type] +
  1972.                     strlen(last_str[pWinData->in_type])) = '\r';
  1973.                 return (MRESULT)TRUE;
  1974.               }
  1975.               break;
  1976.  
  1977.             case  VK_TAB :
  1978.             case  VK_BACKTAB :
  1979.  
  1980.               return (MRESULT)WinSetFocus(HWND_DESKTOP,
  1981.                   pWinData->infocus?pWinData->outmle: pWinData->insle);
  1982.               break;
  1983.  
  1984.             default  :
  1985.               break;
  1986.           }
  1987.         }
  1988.       default  :
  1989.         break;
  1990.     }
  1991.     return  WinDefDlgProc(hwnd, msg, mp1, mp2);
  1992.   }
  1993.  
  1994. /************************** START OF SPECIFICATIONS ***************************/
  1995. /*                                                                            */
  1996. /*   SUBROUTINE NAME: SelectFont                                              */
  1997. /*                                                                            */
  1998. /*   DESCRIPTIVE NAME:                                                        */
  1999. /*               Interface to the Font Selection dialog.                      */
  2000. /*                                                                            */
  2001. /*   FUNCTION:                                                                */
  2002. /*               This routine sets up the parameters and calls the Font       */
  2003. /*               Selection dialog routines. Responses from the dialog will    */
  2004. /*               be via WM_CONTROL messages to the parent window procedure.   */
  2005. /*                                                                            */
  2006. /*   NOTES:                                                                   */
  2007. /*                                                                            */
  2008. /*   ENTRY POINT:                                                             */
  2009. /*      LINKAGE:                                                              */
  2010. /*          ULONG  SelectFont(PRHWINDATA pWinData)                            */
  2011. /*                                                                            */
  2012. /*   INPUT:                                                                   */
  2013. /*       pWinData       - Pointer to the WinData structure of the parent      */
  2014. /*                        window.                                             */
  2015. /*                                                                            */
  2016. /*   EXIT-NORMAL:                                                             */
  2017. /*                                                                            */
  2018. /*   EXIT-ERROR:                                                              */
  2019. /*                                                                            */
  2020. /*   EFFECTS:                                                                 */
  2021. /*                                                                            */
  2022. /*   INTERNAL REFERENCES:                                                     */
  2023. /*      ROUTINES:                                                             */
  2024. /*       FontDialog - Load and initialize the Font dialog                     */
  2025. /*                                                                            */
  2026. /*   EXTERNAL REFERENCES:                                                     */
  2027. /*      ROUTINES:                                                             */
  2028. /*       WinProcessDlg                                                        */
  2029. /*       WinSendMsg                                                           */
  2030. /*                                                                            */
  2031. /**************************** END OF SPECIFICATIONS ***************************/
  2032.  
  2033.   ULONG  SelectFont(PRHWINDATA pWinData) {
  2034.     PFONTDLG   fntd;                   /* font dialog control                 */
  2035.     BOOL       rc;                     /* success/failure flag                */
  2036.  
  2037.     fntd = &pWinData->MleFontAttrs;    /* point to control structure          */
  2038.     fntd->cbSize = sizeof(FONTDLG);
  2039.     if (!fntd->pszFamilyname)         {/* do first time set up               */
  2040.                                        /* set the buffer                     */
  2041.       fntd->pszFamilyname = pWinData->MleFamilyName;
  2042.       strcpy(fntd->pszFamilyname, fntd->fAttrs.szFacename);
  2043.       fntd->fxPointSize = MAKEFIXED(8,0);
  2044.     }
  2045.     fntd->pszPreview = getstring(pWinData->hab, pWinData->hResource,
  2046.         SAMPLE_TEXT);
  2047.     fntd->pszTitle = getstring(pWinData->hab, pWinData->hResource,
  2048.         FONT_TITLE);
  2049.     fntd->fl = FNTS_CENTER + FNTS_HELPBUTTON;
  2050.     fntd->clrFore = CLR_NEUTRAL;    /* Selected foreground color */
  2051.     fntd->clrBack = CLR_BACKGROUND; /* Selected Background color */
  2052.     fntd->usWeight = FWEIGHT_NORMAL;
  2053.     fntd->usWidth = FWIDTH_NORMAL;
  2054.     fntd->hpsScreen = WinGetPS(pWinData->outmle);
  2055.     fntd->fAttrs.usCodePage = (USHORT)pWinData->CountryInfo.codepage;
  2056.     fntd->clrFore = CLR_BLACK;
  2057.     fntd->clrBack = CLR_WHITE;
  2058.     fntd->usFamilyBufLen = MAXWIDTH;
  2059.     fntd->pszPtSizeList = NULL;        /* use default point sizes*/
  2060.     rc = TRUE;
  2061.  
  2062.     /* Disable the window for update, and call the font dialog   */
  2063.     WinEnableWindowUpdate(pWinData->outmle, FALSE);  
  2064.     if (!WinFontDlg(HWND_DESKTOP, pWinData->frame, fntd) ||
  2065.         fntd->lReturn != DID_OK) {
  2066.       rc = FALSE;
  2067.       } else {
  2068.  
  2069.        /**********************************************************/
  2070.        /* If outline font, calculate the maxbaselineext and      */
  2071.        /*  avecharwidth for the point size selected              */
  2072.        /**********************************************************/
  2073.        if ( fntd->fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE )  
  2074.        {                                                            
  2075.          HDC   hDC;                                                 
  2076.          LONG  lxFontResolution;                                    
  2077.          LONG  lyFontResolution;                                    
  2078.          SIZEF sizef;                                               
  2079.  
  2080.          /********************************************************/
  2081.          /* Query device context for the screen and then query   */
  2082.          /* the resolution of the device for the device context. */
  2083.          /********************************************************/
  2084.          hDC = GpiQueryDevice(fntd->hpsScreen);                                 
  2085.          DevQueryCaps( hDC, CAPS_HORIZONTAL_FONT_RES,               
  2086.                        (LONG)1, &lxFontResolution);                 
  2087.          DevQueryCaps( hDC, CAPS_VERTICAL_FONT_RES,                 
  2088.                        (LONG)1, &lyFontResolution);                 
  2089.  
  2090.          /********************************************************/
  2091.          /* Calculate the size of the character box, based on the*/
  2092.          /* point size selected and the resolution of the device.*/
  2093.          /* The size parameters are of type FIXED, NOT int.      */
  2094.          /*  NOTE: 1 point == 1/72 of an inch.                   */
  2095.          /********************************************************/
  2096.          sizef.cx = (FIXED)(((fntd->fxPointSize) / 72 ) *       
  2097.                            lxFontResolution );                      
  2098.          sizef.cy = (FIXED)(((fntd->fxPointSize) / 72 ) *       
  2099.                            lyFontResolution );                      
  2100.  
  2101.          fntd->fAttrs.lMaxBaselineExt =                         
  2102.                                MAKELONG( HIUSHORT( sizef.cy ), 0 ); 
  2103.          fntd->fAttrs.lAveCharWidth =                           
  2104.                                MAKELONG( HIUSHORT( sizef.cx ), 0 ); 
  2105.         }/* endif fsFontUse == FATTR_FONTUSE_OUTLINE */          
  2106.  
  2107.  
  2108.       } /* endif !WinFontDlg */
  2109.     WinReleasePS(fntd->hpsScreen);
  2110.  
  2111.     if (rc) {
  2112.       WinSendMsg(pWinData->outmle,     /* set font of multiline edit field    */
  2113.           MLM_SETFONT, MPFROMP((PFATTRS)&fntd->fAttrs), (MPARAM)0);
  2114.     }
  2115.     WinEnableWindowUpdate(pWinData->outmle, TRUE);  
  2116.     free(fntd->pszTitle);
  2117.     free(fntd->pszPreview);
  2118.     return (TRUE);
  2119.   }
  2120.