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