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