windows/hostemu.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 2009-2010 Rexx Language Association. All rights reserved. */
4 /* */
5 /* This program and the accompanying materials are made available under */
6 /* the terms of the Common Public License v1.0 which accompanies this */
7 /* distribution. A copy is also available at the following address: */
8 /* http://www.oorexx.org/license.html */
9 /* */
10 /* Redistribution and use in source and binary forms, with or */
11 /* without modification, are permitted provided that the following */
12 /* conditions are met: */
13 /* */
14 /* Redistributions of source code must retain the above copyright */
15 /* notice, this list of conditions and the following disclaimer. */
16 /* Redistributions in binary form must reproduce the above copyright */
17 /* notice, this list of conditions and the following disclaimer in */
18 /* the documentation and/or other materials provided with the distribution. */
19 /* */
20 /* Neither the name of Rexx Language Association nor the names */
21 /* of its contributors may be used to endorse or promote products */
22 /* derived from this software without specific prior written permission. */
23 /* */
24 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
25 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
26 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
27 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
28 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
29 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
30 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
31 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
32 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
33 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
34 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
35 /* */
36 /* Authors; */
37 /* W. David Ashley <dashley@us.ibm.com> */
38 /* */
39 /*----------------------------------------------------------------------------*/
40 
41 
42 #include <stdlib.h>
43 #include <string.h>
44 #include <stdio.h>
45 #include <sys/types.h>
46 #include <windows.h>
47 #include <rexx.h>
48 #include <oorexxapi.h>
49 
50 #include "../../hostemu.h"
51 
52 
53 /*--------------------------------------------------------------------*/
54 /* */
55 /* Global variables */
56 /* */
57 /*--------------------------------------------------------------------*/
58 
59 // #define HOSTEMU_DEBUG
60 
63 long lCmdPtr;
64 unsigned long ulNumSym;
66 char szInline[1000];
67 long lStmtType;
68 
69 
70 /*--------------------------------------------------------------------*/
71 /* */
72 /* Local definitions */
73 /* */
74 /*--------------------------------------------------------------------*/
75 
76 typedef struct _LL
77  {
78  struct _LL * prev;
79  struct _LL * next;
80  char FileName [1024];
81  FILE * pFile;
82  } LL;
83 typedef LL * PLL;
84 
85 
86 /*--------------------------------------------------------------------*/
87 /* */
88 /* Local variables */
89 /* */
90 /*--------------------------------------------------------------------*/
91 
92 static HANDLE htmxExecIO = NULL;
93 static PLL pHead = NULL;
94 static PLL pTail = NULL;
95 
96 
97 /*--------------------------------------------------------------------*/
98 /* */
99 /* Local function prototypes */
100 /* */
101 /*--------------------------------------------------------------------*/
102 
103 static unsigned long ExecIO_Write_From_Stem(
104  PLL pll); /* Pointer to file linked list item */
105 static unsigned long ExecIO_Write_From_Queue(
106  PLL pll); /* Pointer to file linked list item */
107 static unsigned long ExecIO_Read_To_Stem(
108  PLL pll); /* Pointer to file linked list item */
109 static unsigned long ExecIO_Read_To_Queue(
110  PLL pll); /* Pointer to file linked list item */
111 static PLL Search_LL(
112  char * SFilename); /* Source file name */
113 static void Insert_LL(
114  PLL pll); /* Pointer to the new item */
115 static void Delete_LL(
116  PLL pll); /* Pointer to the item to be deleted */
117 static long queued(
118  void); /* No arguments */
119 static void push(
120  char * pushstr, /* String to be pushed onto queue */
121  long lOp); /* 0 = FIFO, 1 = LIFO */
122 static char * pull(
123  void); /* No arguments */
124 
125 /*--------------------------------------------------------------------*/
126 /* */
127 /* Function: FetchRexxVar() */
128 /* */
129 /* Description: Fetch contents of a REXX variable from the current */
130 /* variable pool. The caller is responsible for freeing */
131 /* the buffer pointed to by the return value via */
132 /* DosFreeMem(). */
133 /* */
134 /* Input: PSZ - name of the REXX variable to be fetched */
135 /* PRXSTRING - pointer to the return RXSTRING structure */
136 /* */
137 /* Returns: ULONG - return code from RexxVariablePool() */
138 /* */
139 /* Notes: None. */
140 /* */
141 /*--------------------------------------------------------------------*/
142 
143 unsigned long FetchRexxVar (
144  char * pszVar, /* Variable name */
145  PRXSTRING prxVar) /* REXX variable contents */
146  {
147 
148  /* local function variables */
149  SHVBLOCK RxVarBlock;
150  unsigned long ulRetc;
151  char * pszTemp;
152 
153  /* initialize the shared variable block */
154  RxVarBlock.shvnext = NULL;
155  RxVarBlock.shvname.strptr = pszVar;
156  RxVarBlock.shvname.strlength = strlen(pszVar);
157  RxVarBlock.shvnamelen = RxVarBlock.shvname.strlength;
158  RxVarBlock.shvvalue.strptr = NULL;
159  RxVarBlock.shvvalue.strlength = 0;
160  RxVarBlock.shvvaluelen = 0;
161  RxVarBlock.shvcode = RXSHV_SYFET;
162  RxVarBlock.shvret = RXSHV_OK;
163 
164  /* fetch variable from pool */
165  ulRetc = RexxVariablePool(&RxVarBlock);
166 
167  /* test return code */
168  if (ulRetc != RXSHV_OK && ulRetc != RXSHV_NEWV) {
169  prxVar -> strptr = NULL;
170  prxVar -> strlength = 0;
171  }
172  else {
173  /* allocate a new buffer for the Rexx variable pool value */
174  pszTemp = (char *) RexxAllocateMemory(RxVarBlock.shvvalue.strlength + 1);
175  if (pszTemp == NULL) {
176  /* no buffer available so return a NULL Rexx value */
177  prxVar -> strptr = NULL;
178  prxVar -> strlength = 0;
179  ulRetc = RXSHV_MEMFL;
180  }
181  else {
182  /* copy to new buffer and zero-terminate */
183  memmove(pszTemp, RxVarBlock.shvvalue.strptr,
184  RxVarBlock.shvvalue.strlength);
185  *(pszTemp + RxVarBlock.shvvalue.strlength) = '\0';
186  prxVar -> strptr = pszTemp;
187  prxVar -> strlength = RxVarBlock.shvvalue.strlength;
188  }
189  // free memory returned from RexxVariablePool API
190  RexxFreeMemory(RxVarBlock.shvvalue.strptr);
191  }
192 
193  return ulRetc;
194  }
195 
196 
197 /*--------------------------------------------------------------------*/
198 /* */
199 /* Function: SetRexxVar() */
200 /* */
201 /* Description: Sets the contents of a variable in the REXX variable */
202 /* pool. */
203 /* */
204 /* Input: PSZ - name of the REXX variable to be set */
205 /* PVOID - pointer to new contents for variable */
206 /* ULONG - buffer size of new contents */
207 /* */
208 /* Returns: ULONG - return code from RexxVariablePool() */
209 /* */
210 /* Notes: None. */
211 /* */
212 /*--------------------------------------------------------------------*/
213 
214 unsigned long SetRexxVar (
215  char * pszVar, /* Variable name to be set */
216  char * pValue, /* Ptr to new value */
217  size_t ulLen) /* Value length */
218  {
219 
220  /* local function data */
221  SHVBLOCK RxVarBlock;
222  unsigned long ulRetc;
223 
224  /* initialize RxVarBlock */
225  RxVarBlock.shvnext = NULL;
226  RxVarBlock.shvname.strptr = pszVar;
227  RxVarBlock.shvname.strlength = strlen(pszVar);
228  RxVarBlock.shvnamelen = RxVarBlock.shvname.strlength;
229  RxVarBlock.shvvalue.strptr = pValue;
230  RxVarBlock.shvvalue.strlength = ulLen;
231  RxVarBlock.shvvaluelen = ulLen;
232  RxVarBlock.shvcode = RXSHV_SYSET;
233  RxVarBlock.shvret = RXSHV_OK;
234 
235  /* set variable in pool */
236  ulRetc = RexxVariablePool(&RxVarBlock);
237 
238  /* test return code */
239  if (ulRetc == RXSHV_NEWV) {
240  ulRetc = RXSHV_OK;
241  }
242 
243  return ulRetc;
244  }
245 
246 
247 /*--------------------------------------------------------------------*/
248 /* */
249 /* Function: GrxHost() */
250 /* */
251 /* Description: Emulates the IBM host environment commands. */
252 /* */
253 /* Input: Command string */
254 /* Pointer to return flags */
255 /* Pointer to return string */
256 /* */
257 /* Returns: Return indicating success or failure */
258 /* */
259 /* References: None. */
260 /* */
261 /* Notes: */
262 /* */
263 /*--------------------------------------------------------------------*/
264 
266  unsigned short int *flags,
267  PRXSTRING retc)
268  {
269 
270  /* Local function variables */
271  unsigned long i, rc = 0;
272  PLL pll;
273 
274  #ifdef HOSTEMU_DEBUG
275  printf("HOSTEMU: Subcom called.\n");
276  #endif
277 
278  /* request the semaphore so we can get exclusive access to */
279  /* our variables */
280  WaitForSingleObject(htmxExecIO, INFINITE);
281 
282  /* initialize the global variables */
283  memset(&ExecIO_Options, '\0', sizeof(EXECIO_OPTIONS));
285  prxCmd = command;
286  lCmdPtr = 0;
287  ulNumSym = 0;
288  *flags = RXSUBCOM_OK;
289 
290  /* parse the command */
291  if (!yyparse ()) {
292  #ifdef HOSTEMU_DEBUG
293  printf("HOSTEMU: Parse complete.\n");
294  #endif
295  if (lStmtType == HI_STMT) {
296  RexxSetHalt(GetCurrentProcessId(), GetCurrentThreadId());
297  }
298  else if (lStmtType == TE_STMT) {
299  RexxResetTrace(GetCurrentProcessId(), GetCurrentThreadId());
300  }
301  else if (lStmtType == TS_STMT) {
302  RexxSetTrace(GetCurrentProcessId(), GetCurrentThreadId());
303  }
304  else if (lStmtType == EXECIO_STMT) {
305  #ifdef HOSTEMU_DEBUG
306  printf("HOSTEMU: Executing execio statement.\n");
307  #endif
308  /* check to see if the file is already open */
310  if (pll == NULL) {
311  /* it is a new file, so open it and add to the list */
312  pll = (PLL)malloc(sizeof (LL));
313  if (pll == NULL) {
314  rc = 20;
315  *flags = RXSUBCOM_FAILURE;
316  goto return_point;
317  }
318  memset(pll, '\0', sizeof (LL));
319  strcpy(pll -> FileName, ExecIO_Options.aFilename);
320 
321  /* try to open an existing file */
322  pll -> pFile = fopen(pll -> FileName, "r+");
323 
324  /* read only files can not be opened in read / write mode (r+) */
325  if ( pll -> pFile == NULL && ! ExecIO_Options.fRW ) {
326  pll -> pFile = fopen(pll -> FileName, "r");
327  }
328  if (pll -> pFile == NULL) {
329  /* no existing file, so open a new file */
330  pll -> pFile = fopen(pll -> FileName, "w+");
331  }
332  if (pll -> pFile == NULL) {
333  /* nothing could be opened so return an error */
334  free(pll);
335  rc = 20;
336  *flags = RXSUBCOM_FAILURE;
337  goto return_point;
338  }
339  Insert_LL(pll);
340  }
341  /* is this a read or write operation? */
342  if (ExecIO_Options.fRW) {
343  /* DISKW */
344  /* is this a stem or queue operation? */
345  if (strlen (ExecIO_Options.aStem)) {
346  rc = ExecIO_Write_From_Stem(pll);
347  }
348  else {
349  rc = ExecIO_Write_From_Queue(pll);
350  }
351  }
352  else {
353  /* DISKR */
354  /* is this a stem or queue operation? */
355  if (strlen(ExecIO_Options.aStem)) {
356  rc = ExecIO_Read_To_Stem(pll);
357  }
358  else {
359  rc = ExecIO_Read_To_Queue(pll);
360  }
361  }
362  /* process the FINIS option */
363  if (ExecIO_Options.fFinis) {
364  fclose(pll -> pFile);
365  Delete_LL(pll);
366  }
367  /* if the return code is 20 then set the failure flag */
368  if (rc == 20) {
369  *flags = RXSUBCOM_FAILURE;
370  }
371  }
372  else { /* bad statement type */
373  *flags = RXSUBCOM_ERROR;
374  rc = 20;
375  }
376  }
377  else { /* parse failed */
378  *flags = RXSUBCOM_ERROR;
379  rc = 20;
380  }
381 
382  return_point:
383 
384  /* release our symbol table memory */
385  if (ulNumSym != 0) {
386  for (i = 0; i < ulNumSym; i++) {
387  free(pszSymbol[i]);
388  }
389  }
390 
391  ReleaseMutex(htmxExecIO);
392 
393  sprintf(retc->strptr, "%u", rc);
394  retc->strlength = strlen(retc->strptr);
395  #ifdef HOSTEMU_DEBUG
396  printf("HOSTEMU: Subcom return code = %u.\n", rc);
397  #endif
398  return rc;
399  }
400 
401 
402 /*--------------------------------------------------------------------*/
403 /* */
404 /* Function: ExecIO_Write_From_Stem */
405 /* */
406 /* Description: ExecIO write from a stem to a file. */
407 /* */
408 /* Input: Pointer to file linked list item */
409 /* */
410 /* Returns: Return indicating success or failure */
411 /* */
412 /* References: None. */
413 /* */
414 /* Notes: */
415 /* */
416 /* */
417 /*--------------------------------------------------------------------*/
418 
419 static unsigned long ExecIO_Write_From_Stem (
420  PLL pll) /* Pointer to file linked list item */
421  {
422 
423  /* Local function variables */
424  char * Stem; /* Stem variable name */
425  char * Index; /* Stem index value (string) */
426  RXSTRING rxVal; /* Rexx stem variable value */
427  int elements;
428 
429  /* process request */
430  if (ExecIO_Options.lRcdCnt == 0)
431  return 0;
432  Stem = (char *)malloc(strlen(ExecIO_Options.aStem) + 33);
433  if (Stem == NULL) {
434  return 20;
435  }
436  strcpy(Stem, ExecIO_Options.aStem);
437  Index = Stem + strlen(Stem);
438  if (ExecIO_Options.lRcdCnt == -1) {
439  /* process an "*" record count */
440  // get the number of elements
441  sprintf(Index, "%u", 0);
442  FetchRexxVar(Stem, &rxVal);
443  elements = atoi(rxVal.strptr);
444  RexxFreeMemory(rxVal.strptr);
445  while (ExecIO_Options.lStartRcd <= elements) {
446  sprintf(Index, "%d", ExecIO_Options.lStartRcd);
447  FetchRexxVar(Stem, &rxVal);
448  fputs(rxVal.strptr, pll -> pFile);
449  fputs("\n", pll -> pFile);
450  RexxFreeMemory(rxVal.strptr);
452  }
453  }
454  else {
455  /* process a specific record count */
457  sprintf(Index, "%u", ExecIO_Options.lStartRcd);
458  FetchRexxVar(Stem, &rxVal);
459  fputs(rxVal.strptr, pll -> pFile);
460  fputs("\n", pll -> pFile);
461  RexxFreeMemory(rxVal.strptr);
463  }
464  }
465  fflush (pll -> pFile);
466 
467  /* return with successful return code */
468  return 0;
469  }
470 
471 
472 /*--------------------------------------------------------------------*/
473 /* */
474 /* Function: ExecIO_Write_From_Queue */
475 /* */
476 /* Description: ExecIO write from the queue to a file. */
477 /* */
478 /* Input: Pointer to file linked list item */
479 /* */
480 /* Returns: Return indicating success or failure */
481 /* */
482 /* References: None. */
483 /* */
484 /* Notes: */
485 /* */
486 /*--------------------------------------------------------------------*/
487 
488 static unsigned long ExecIO_Write_From_Queue (
489  PLL pll) /* Pointer to file linked list item */
490  {
491 
492  /* Local function variables */
493  char * Item; /* Item pulled from the queue */
494  long items;
495 
496  /* process request */
497  if (ExecIO_Options.lRcdCnt == 0) {
498  return 0;
499  }
500  /* start at the proper place in the queue */
501  while (ExecIO_Options.lStartRcd > 1 && queued() > 0) {
502  Item = pull();
503  if (Item != NULL) {
504  RexxFreeMemory(Item);
505  }
507  }
508  if (ExecIO_Options.lRcdCnt == -1) {
509  /* process an "*" record count */
510  items = queued();
511  while (items > 0) {
512  Item = pull();
513  if (Item != NULL) {
514  fputs(Item, pll -> pFile);
515  fputs("\n", pll -> pFile);
516  RexxFreeMemory(Item);
517  }
518  else {
519  goto return_point;
520  }
521  items--;
522  }
523  }
524  else {
525  /* process a specific record count */
526  while (ExecIO_Options.lRcdCnt > 0) {
527  if (queued() == 0)
528  break;
529  Item = pull();
530  if (Item != NULL) {
531  fputs(Item, pll -> pFile);
532  fputs("\n", pll -> pFile);
533  RexxFreeMemory(Item);
534  }
535  else {
536  goto return_point;
537  }
539  }
540  }
541 
542  return_point:
543  fflush (pll -> pFile);
544 
545  /* return with successful return code */
546  return 0;
547  }
548 
549 
550 /*--------------------------------------------------------------------*/
551 /* */
552 /* Function: ExecIO_Read_To_Stem */
553 /* */
554 /* Description: ExecIO read from a file to a stem. */
555 /* */
556 /* Input: Pointer to file linked list item */
557 /* */
558 /* Returns: Return indicating success or failure */
559 /* */
560 /* References: None. */
561 /* */
562 /* Notes: */
563 /* */
564 /* */
565 /*--------------------------------------------------------------------*/
566 
567 static unsigned long ExecIO_Read_To_Stem (
568  PLL pll) /* Pointer to file linked list item */
569  {
570 
571  /* Local function variables */
572  char * Stem; /* Stem variable name */
573  char * Index; /* Stem index value (string) */
574  unsigned long ulRc = 0; /* Return code */
575 
576  /* process request */
577  if (ExecIO_Options.lRcdCnt == 0) {
578  return 0;
579  }
580  Stem = (char *)malloc(strlen(ExecIO_Options.aStem) + 33);
581  if (Stem == NULL) {
582  return 20;
583  }
584  strcpy(Stem, ExecIO_Options.aStem);
585  Index = Stem + strlen(Stem);
586  if (ExecIO_Options.lRcdCnt == -1) {
587  /* process an "*" record count */
588  while (fgets(szInline, sizeof (szInline), pll -> pFile)) {
589  if (*(szInline + strlen(szInline) - 1) == '\n')
590  *(szInline + strlen(szInline) - 1) = '\0';
591  sprintf(Index, "%u", ExecIO_Options.lStartRcd);
592  SetRexxVar(Stem, szInline, strlen(szInline));
594  }
595  }
596  else {
597  /* process a specific record count */
598  while (ExecIO_Options.lRcdCnt > 0) {
599  if (fgets(szInline, sizeof(szInline), pll -> pFile)) {
600  if (*(szInline + strlen(szInline) - 1) == '\n') {
601  *(szInline + strlen(szInline) - 1) = '\0';
602  }
603  sprintf(Index, "%u", ExecIO_Options.lStartRcd);
604  SetRexxVar(Stem, szInline, strlen(szInline));
606  }
607  else {
608  ulRc = 2;
609  break;
610  }
612  }
613  }
615  sprintf(szInline, "%u", ExecIO_Options.lStartRcd);
616  sprintf(Index, "%u", 0);
617  SetRexxVar(Stem, szInline, strlen (szInline));
618  free(Stem);
619 
620  /* return with successful return code */
621  return ulRc;
622  }
623 
624 
625 /*--------------------------------------------------------------------*/
626 /* */
627 /* Function: ExecIO_Read_To_Queue */
628 /* */
629 /* Description: ExecIO read file to the current queue. */
630 /* */
631 /* Input: Pointer to file linked list item */
632 /* */
633 /* Returns: Return indicating success or failure */
634 /* */
635 /* References: None. */
636 /* */
637 /* Notes: */
638 /* */
639 /*--------------------------------------------------------------------*/
640 
641 static unsigned long ExecIO_Read_To_Queue (
642  PLL pll) /* Pointer to file linked list item */
643  {
644 
645  /* Local function variables */
646 
647  /* process request */
648  if (ExecIO_Options.lRcdCnt == 0) {
649  return 0;
650  }
651  if (ExecIO_Options.lRcdCnt == -1) {
652  /* process an "*" record count */
653  while (fgets (szInline, sizeof (szInline), pll -> pFile)) {
654  if (*(szInline + strlen (szInline) - 1) == '\n') {
655  *(szInline + strlen (szInline) - 1) = '\0';
656  }
657  if (ExecIO_Options.lDirection != 2) {
659  }
660  }
661  }
662  else {
663  /* process a specific record count */
664  while (ExecIO_Options.lRcdCnt > 0) {
665  if (fgets (szInline, sizeof (szInline), pll -> pFile)) {
666  if (*(szInline + strlen (szInline) - 1) == '\n') {
667  *(szInline + strlen (szInline) - 1) = '\0';
668  }
669  if (ExecIO_Options.lDirection != 2) {
671  }
672  }
673  else {
674  return 2;
675  }
677  }
678  }
679 
680  /* return with successful return code */
681  return 0;
682  }
683 
684 
685 /*--------------------------------------------------------------------*/
686 /* */
687 /* Function: Search_LL */
688 /* */
689 /* Description: Search the linked list of files for a match. */
690 /* */
691 /* Input: Filename */
692 /* */
693 /* Returns: Pointer to found struct or NULL if not found */
694 /* */
695 /* References: None. */
696 /* */
697 /* Notes: */
698 /* */
699 /*--------------------------------------------------------------------*/
700 
701 static PLL Search_LL (
702  char * SFilename) /* Source file name */
703  {
704 
705  /* Local function variables */
706  PLL pll = pHead;
707 
708  while (pll != NULL) {
709  if (!strcmp (SFilename, pll -> FileName)) {
710  return pll;
711  }
712  pll = pll -> next;
713  }
714  return pll;
715  }
716 
717 
718 /*--------------------------------------------------------------------*/
719 /* */
720 /* Function: Insert_LL */
721 /* */
722 /* Description: Insert a new item at the end of the list. */
723 /* */
724 /* Input: Pointer to new item struct. */
725 /* */
726 /* Returns: None. */
727 /* */
728 /* References: None. */
729 /* */
730 /* Notes: */
731 /* */
732 /*--------------------------------------------------------------------*/
733 
734 static void Insert_LL (
735  PLL pll) /* Pointer to the new item */
736  {
737 
738  if (pHead == NULL) {
739  pHead = pll;
740  }
741  else {
742  pTail -> next = pll;
743  }
744  pll -> prev = pTail;
745  pll -> next = NULL;
746  pTail = pll;
747  return;
748  }
749 
750 
751 /*--------------------------------------------------------------------*/
752 /* */
753 /* Function: Delete_LL */
754 /* */
755 /* Description: Delete an item from the list. */
756 /* */
757 /* Input: Pointer to item to be deleted. */
758 /* */
759 /* Returns: None. */
760 /* */
761 /* References: None. */
762 /* */
763 /* Notes: */
764 /* */
765 /*--------------------------------------------------------------------*/
766 
767 static void Delete_LL (
768  PLL pll) /* Pointer to the item to be deleted */
769  {
770 
771  if (pHead == pll) {
772  pHead = pll -> next;
773  }
774  if (pTail == pll) {
775  pTail = pll -> prev;
776  }
777  if (pll -> next != NULL) {
778  pll -> next -> prev = pll -> prev;
779  }
780  if (pll -> prev != NULL) {
781  pll -> prev -> next = pll -> next;
782  }
783  free(pll);
784  return;
785  }
786 
787 
788 /*--------------------------------------------------------------------*/
789 /* */
790 /* Function: queued */
791 /* */
792 /* Description: Returns the number of items in the current Rexx queue */
793 /* */
794 /* Input: None. */
795 /* */
796 /* Returns: Number of queued items */
797 /* */
798 /* References: None. */
799 /* */
800 /* Notes: */
801 /* */
802 /*--------------------------------------------------------------------*/
803 
804 static long queued (
805  void) /* No arguments */
806  {
807 
808  /* local function variables */
809  size_t elements;
810 
811  RexxQueryQueue("SESSION", &elements);
812  return (long)elements;
813  }
814 
815 
816 /*--------------------------------------------------------------------*/
817 /* */
818 /* Function: push */
819 /* */
820 /* Description: Push an item onto the current Rexx queue. */
821 /* */
822 /* Input: Pointer to the string to be pushed */
823 /* */
824 /* Returns: Number of queued items */
825 /* */
826 /* References: None. */
827 /* */
828 /* Notes: */
829 /* */
830 /*--------------------------------------------------------------------*/
831 
832 static void push (
833  char * pushstr, /* String to be pushed onto queue */
834  long lOp) /* 0 = FIFO, 1 = LIFO */
835  {
836 
837  CONSTRXSTRING rxstr;
838 
839  rxstr.strptr = pushstr;
840  rxstr.strlength = strlen(pushstr);
841  RexxAddQueue("SESSION", &rxstr, (size_t)lOp);
842  return;
843  }
844 
845 
846 /*--------------------------------------------------------------------*/
847 /* */
848 /* Function: pull */
849 /* */
850 /* Description: Pull an item off the current Rexx queue. */
851 /* */
852 /* Input: None */
853 /* */
854 /* Returns: Pointer to the pulled string */
855 /* */
856 /* References: None. */
857 /* */
858 /* Notes: */
859 /* */
860 /*--------------------------------------------------------------------*/
861 
862 static char * pull (
863  void) /* No arguments */
864  {
865 
866  /* local function variables */
867  RXSTRING result = {0, NULL};
868  RexxReturnCode rc;
869 
870  rc = RexxPullFromQueue("SESSION", &result, NULL, RXQUEUE_WAIT);
871  return result.strptr;
872  }
873 
874 
876  RexxReturnCode rc;
877 
878  rc = RexxRegisterSubcomExe("HostEmu", (REXXPFN)GrxHost, NULL);
879  htmxExecIO = CreateMutex(NULL, false, NULL);
880  #ifdef HOSTEMU_DEBUG
881  printf("HOSTEMU: Library loaded.\n");
882  printf("HOSTEMU: RexxRegisterSubcomExe retc = %d.\n", rc);
883  printf("HOSTEMU: CreateMutex htmxExecIO = %d.\n", htmxExecIO);
884  #endif
885  }
886 
887 
889  PLL pll;
890 
891  /* close all our open files */
892  pll = pHead;
893  while (pll != NULL) {
894  fclose (pll -> pFile);
895  pll = pll -> next;
896  }
897  }
898 
899 
902  REXX_INTERPRETER_4_0_0, // anything after 4.0.0 will work
903  "HostEmu", // name of the package
904  "1.0.0", // package information
905  hostemu_loader, // load function
906  hostemu_unloader, // unload function
907  NULL, // the exported routines
908  NULL // the exported methods
909  };
910 
911 // package loading stub.
913 
RexxReturnCode RexxEntry RexxVariablePool(PSHVBLOCK pshvblock)
RexxReturnCode REXXENTRY RexxResetTrace(process_id_t procid, thread_id_t threadid)
RexxReturnCode REXXENTRY RexxSetTrace(process_id_t procid, thread_id_t threadid)
RexxReturnCode REXXENTRY RexxSetHalt(process_id_t procid, thread_id_t threadid)
#define HI_STMT
Definition: hostemu.h:70
#define TS_STMT
Definition: hostemu.h:72
int yyparse(void)
Definition: cmdparse.cpp:493
#define EXECIO_STMT
Definition: hostemu.h:69
#define SYMTABLESIZE
Definition: hostemu.h:68
#define TE_STMT
Definition: hostemu.h:71
#define REXX_INTERPRETER_4_0_0
Definition: oorexxapi.h:216
#define STANDARD_PACKAGE_HEADER
Definition: oorexxapi.h:230
RexxReturnCode REXXENTRY RexxRegisterSubcomExe(CONSTANT_STRING, REXXPFN, CONSTANT_STRING)
RexxReturnCode REXXENTRY RexxPullFromQueue(CONSTANT_STRING, PRXSTRING, RexxQueueTime *, size_t)
RexxReturnCode REXXENTRY RexxFreeMemory(void *)
RexxReturnCode REXXENTRY RexxAddQueue(CONSTANT_STRING, PCONSTRXSTRING, size_t)
CONSTANT_RXSTRING * PCONSTRXSTRING
Definition: rexx.h:186
RexxReturnCode REXXENTRY RexxQueryQueue(CONSTANT_STRING, size_t *)
void *REXXENTRY RexxAllocateMemory(size_t)
int RexxReturnCode
Definition: rexx.h:73
#define RexxEntry
Definition: rexx.h:412
#define RXSHV_NEWV
Definition: rexxapidefs.h:113
#define RXQUEUE_WAIT
Definition: rexxapidefs.h:243
#define RXSHV_SYFET
Definition: rexxapidefs.h:101
#define RXSUBCOM_OK
Definition: rexxapidefs.h:85
#define RXSUBCOM_ERROR
Definition: rexxapidefs.h:79
#define RXSHV_OK
Definition: rexxapidefs.h:112
#define RXSHV_SYSET
Definition: rexxapidefs.h:100
#define RXSUBCOM_FAILURE
Definition: rexxapidefs.h:80
#define RXSHV_MEMFL
Definition: rexxapidefs.h:117
const char * strptr
Definition: rexx.h:163
size_t strlength
Definition: rexx.h:162
long lStartRcd
Definition: hostemu.h:80
char aFilename[1024]
Definition: hostemu.h:77
long lRcdCnt
Definition: hostemu.h:75
char aStem[251]
Definition: hostemu.h:78
long lDirection
Definition: hostemu.h:81
struct _LL * prev
FILE * pFile
struct _LL * next
char FileName[1024]
size_t strlength
Definition: rexx.h:157
char * strptr
Definition: rexx.h:158
Definition: oorexxapi.h:242
size_t shvvaluelen
Definition: rexx.h:209
CONSTANT_RXSTRING shvname
Definition: rexx.h:206
unsigned char shvret
Definition: rexx.h:211
unsigned char shvcode
Definition: rexx.h:210
RXSTRING shvvalue
Definition: rexx.h:207
size_t shvnamelen
Definition: rexx.h:208
struct _SHVBLOCK * shvnext
Definition: rexx.h:205
void * REXXPFN
RexxReturnCode RexxEntry GrxHost(PCONSTRXSTRING command, unsigned short int *flags, PRXSTRING retc)
OOREXX_GET_PACKAGE(hostemu)
static unsigned long ExecIO_Write_From_Stem(PLL pll)
static unsigned long ExecIO_Read_To_Queue(PLL pll)
static void push(char *pushstr, long lOp)
unsigned long SetRexxVar(char *pszVar, char *pValue, size_t ulLen)
long lStmtType
struct _LL LL
char * pszSymbol[SYMTABLESIZE]
LL * PLL
static HANDLE htmxExecIO
static void Delete_LL(PLL pll)
long lCmdPtr
static PLL pTail
unsigned long FetchRexxVar(char *pszVar, PRXSTRING prxVar)
static char * pull(void)
RexxPackageEntry hostemu_package_entry
static void RexxEntry hostemu_unloader(RexxThreadContext *context)
static PLL pHead
static PLL Search_LL(char *SFilename)
static unsigned long ExecIO_Read_To_Stem(PLL pll)
static void RexxEntry hostemu_loader(RexxThreadContext *context)
static void Insert_LL(PLL pll)
char szInline[1000]
unsigned long ulNumSym
static long queued(void)
static unsigned long ExecIO_Write_From_Queue(PLL pll)
EXECIO_OPTIONS ExecIO_Options
PCONSTRXSTRING prxCmd