[go: up one dir, main page]

File: client.c

package info (click to toggle)
regina 0.08h-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,724 kB
  • ctags: 4,101
  • sloc: ansic: 33,311; lex: 1,881; sh: 1,565; yacc: 1,129; makefile: 624
file content (1080 lines) | stat: -rw-r--r-- 27,541 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
#ifndef lint
static char *RCSid = "$Id: client.c,v 1.7 2000/01/09 08:51:49 mark Exp $";
#endif

/*
 *  The Regina Rexx Interpreter
 *  Copyright (C) 1993-1994  Anders Christensen <anders@pvv.unit.no>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
/****************************************************************************
*   This code modified for Multithread Win32 port by Les Moull April 1999.  *
****************************************************************************/
/* JH 20-10-99 */  /* To make Direct setting of stems Direct and not Symbolic. */
#if defined(WIN32) && defined(__IBMC__)
# include <windows.h>
# pragma warning(default: 4115 4201 4214)
#else
# if defined(__WATCOMC__) && defined(__NT__)
#  undef APIENTRY
#  include <windows.h>
# else
#  if defined(__EMX__) && defined(OS2)
#   define DONT_TYPEDEF_PFN
#   undef APIENTRY
#   include <os2emx.h>
#  else
#   if defined(__WATCOMC__) && defined(OS2)
#    undef APIENTRY
#    define DONT_TYPEDEF_PFN
#    include <os2.h>
#   else
#    if defined(_MSC_VER)
#     undef APIENTRY
#     if _MSC_VER >= 1100
/* Stupid MSC can't compile own headers without warning at least in VC 5.0 */
#      pragma warning(disable: 4115 4201 4214)
#     endif
#     include <windows.h>
#     if _MSC_VER >= 1100
#      pragma warning(default: 4115 4201 4214)
#     endif
#    else
#     define APIENTRY
#    endif
#   endif
#  endif
# endif
#endif

#include "rexx.h"

#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

#include "rxiface.h"
#include <stdio.h>
#include <string.h>

#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif

#ifdef HAVE_ASSERT_H
# include <assert.h>
#endif

#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif

#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif

#if !defined(HAVE_WINMULTITHREADING)
extern int isclient ;
int var_indicator=0 ;
#endif

int dummyzero2=0;

/* #define DEBUG_CLIENT */

int ReMapHook( int NetHook ) ;


static streng *wrapstring( char *string, int length )
{
   streng *result=NULL ;

   if (length>=0 && string)
   {
      result = Str_make( length ) ;
      memcpy( result->value, string, length ) ;
      result->len = length ;
   }
   else
      result = NULL ;

   return result ;
}


int map_type( int in )
{
   if (in==RX_TYPE_COMMAND)
      return INVO_COMMAND ;
   else if (in==RX_TYPE_FUNCTION)
      return INVO_FUNCTION ;
   else
   {
      assert( in == RX_TYPE_SUBROUTINE ) ;
      return INVO_SUBROUTINE ;
   }
}


void closedown( void )
{
   CloseOpenFiles( );
   exit( 0 ) ;
}

int APIENTRY dummy_main( int argc, char *argv[] ) ;
int IfcStartUp( char *dummy, int *Major, int *Minor )
{
   static char *args[] = { "regina", "-Ci,foo", NULL } ;
   int rc=0 ;

   rc = dummy_main( 2, args ) ;

   *Major = RXVERSION_MAJ ;
   *Minor = RXVERSION_MIN ;
   return rc ;
}


static paramboxptr parametrize( int ArgCount, int *ParLengths, char *ParStrings[] )
{
   paramboxptr parms=NULL, root=NULL ;
   int count=0, i=0 ;

   count = ArgCount ;
   for (i=0; count--; i++ )
   {
      if (parms)
      {
         parms->next = Malloc( sizeof(parambox)) ;
         parms = parms->next ;
      }
      else
         parms = root = Malloc( sizeof(parambox )) ;

      parms->value = wrapstring( ParStrings[i], ParLengths[i] ) ;
   }

   if (parms)
      parms->next = NULL ;

   return root ;
}

int IfcExecScript( int NameLen, char *Name,
                   int ArgCount, int *ParLengths, char *ParStrings[],
                   int CallType, int ExitFlags, int EnvLen, char *EnvName,
                   int WhereCode, char *WherePtr, int WhereLen,
                   int *RetLen, char **RetString, int *instore_idx )
{
   streng *command=NULL ;
   int RetCode=0 ;
   int num=0 ;
   int type=0 ;
   int panicked=0;
   paramboxptr params=NULL ;
   volatile int hooks=0, ctype=0 ;
   volatile streng * volatile environment=NULL ;
   volatile streng * volatile result=NULL ;
   jmp_buf panic, *oldpanic ;
#include "multi.h"

   *instore_idx=0;
   command = wrapstring( Name, NameLen ) ;
   assert(command) ;
   params = parametrize( ArgCount, ParLengths, ParStrings ) ;

   ctype = map_type(CallType) ;

   for (hooks=num=0; num<30; num++)
      if ((ExitFlags>>num) & 0x01)
         hooks |= (1 << (ReMapHook(num))) ;

   environment = wrapstring( EnvName, EnvLen ) ;
   if (!environment)
      environment = Str_cre( "DEFAULT" ) ;

   add_envir( Str_dup((streng *)environment), ENVIR_PIPE, 0 ) ;

#ifdef FGC
   /* It may be that systeminfo->panic is not set. This may lead to
    * an exit() call, e.g. at Rexx "EXIT". We set systeminfo->panic if it
    * is not set. If a problem occurs we will be informed by a longjmp and
    * we will not completely been killed by an exit(). Remember: This
    * function is typically called if a program uses "us" as a subroutine.
    * Exiting is very harmful in this case.
    * Note: The memory allocated within called subsoutines will NOT be
    * freed. We must change many things to do this. Maybe, it's a good
    * idea to traverse all called subroutine trees and free the leaves.
    * FGC
    */
#if !defined(HAVE_WINMULTITHREADING)
   if ( ( oldpanic = systeminfo->panic ) == NULL )
   {
      systeminfo->panic = &panic;
      if ( setjmp( *systeminfo->panic ) )
      {
         if (result == NULL)
            result= nullstringptr() ;
         if (!RetCode)
            RetCode = -1 ;
         panicked++ ;
      }
   }
   if ( !panicked )
   {
      type = WhereCode ;
      if (type==RX_TYPE_EXTERNAL)
      {
         result=execute_external(command,params,(streng *) environment,
                                 &RetCode,hooks,ctype);
         Free_string( command );
      }
      else if (type==RX_TYPE_INSTORE)
      {
         streng *sptr = wrapstring( WherePtr, WhereLen ) ;
         int serial = atopos( sptr, "instore", 1 ) ;
         Free_string( sptr ) ;
         result=do_instore(command,params,(streng *) environment,&RetCode,
                           hooks,type,serial,ctype);
      }
      else if (type==RX_TYPE_MACRO)
         result= nullstringptr() ;
      else if (type==RX_TYPE_SOURCE)
      {
         streng *SrcStr = wrapstring( WherePtr, WhereLen ) ;
         int serial ;
         *instore_idx = serial=enter_macro( SrcStr, command ) ;
         Free_string( SrcStr ) ;
/*
 *       SendNumber( RX_INSTORE ) ;
 *       SendNumber( serial ) ;
 */
         result=do_instore(command,params,(streng *) environment,&RetCode,
                           hooks,type,serial,ctype);
      }
      else
      {
         exiterror( ERR_INTERPRETER_FAILURE, 0 )  ;
         return 0 ;
      }
   }
#endif
#else
   oldpanic = systeminfo->panic; /* don't let exit been called! */
   if ( oldpanic == NULL )
      systeminfo->panic = &panic;
   if ( setjmp( *systeminfo->panic ) )
   {
      if (result == NULL)
         result= nullstringptr() ;
      if (!RetCode)
         RetCode = -1 ;
   }
   else
   {
      type = WhereCode ;
      if (type==RX_TYPE_EXTERNAL)
      {
         result=execute_external(command,params,environment,&RetCode,hooks,
                                 ctype);
         Free_string( command );
      }
      else if (type==RX_TYPE_INSTORE)
      {
         streng *sptr = wrapstring( WherePtr, WhereLen ) ;
         int serial = atopos( sptr, "instore", 1 ) ;
         Free_string( sptr ) ;
         result=do_instore(command,params,environment,&RetCode,hooks,type,
                           serial, ctype);
      }
      else if (type==RX_TYPE_MACRO)
         result= nullstringptr() ;
      else if (type==RX_TYPE_SOURCE)
      {
         streng *SrcStr = wrapstring( WherePtr, WhereLen ) ;
         int serial ;
         *instore_idx = serial=enter_macro( SrcStr, command ) ;
         Free_string( SrcStr ) ;
/*
 *       SendNumber( RX_INSTORE ) ;
 *       SendNumber( serial ) ;
 */
         result=do_instore(command,params,environment,&RetCode,hooks,type,
                           serial,ctype);
      }
      else
      {
         exiterror( ERR_INTERPRETER_FAILURE, 0 )  ;
         return 0 ;
      }
   }
#endif

#if !defined(HAVE_WINMULTITHREADING)
   systeminfo->panic = oldpanic;
#endif
   del_envir( (streng *) environment ) ;
   Free_string( (streng *) environment ) ;

   if (result && result->len)
   {
      *RetLen = result->len ;
      *RetString=(char *)IfcAllocateMemory(result->len+1);
      if ( *RetString )
      {
         memcpy(*RetString,result->value,result->len);
         *(*RetString+(result->len)) = '\0';
      }
      else
         *RetLen = RX_NO_STRING ;
   }
   else
      *RetLen = RX_NO_STRING ;
   if (result)
      Free(result);

   return RetCode ;
#include "unmulti.h"
}


static int handle_source( int *Length, char **String )
{
   int infile=0, total=0, invoked=0 ;
   char *stype=NULL, *ctmp=NULL ;
   int sleng=0 ;
#if defined(HAVE_WINMULTITHREADING)
# include "unmulti.h"
# include "multi.h"
#else
   extern sysinfo systeminfo ;
#endif

   stype = system_type() ;
   sleng = strlen( stype ) ;
   infile = systeminfo->input_file->len ;
   invoked = strlen(invo_strings[systeminfo->invoked]) ;
   total = sleng + 1 + invoked + 1 + infile ;

   ctmp = *String = Malloc( (*Length=total)+2 ) ;
   sprintf( ctmp, "%s %s ", stype, invo_strings[systeminfo->invoked]) ;
   strncat( ctmp, systeminfo->input_file->value, infile ) ;

   return RX_CODE_OK ;
#include "unmulti.h"
}

static int handle_param( int *Length, char **String )
{
   paramboxptr ptr=NULL ;
   streng *value=NULL ;
   int number=0 ;
#if !defined(HAVE_WINMULTITHREADING)
   extern proclevel currlevel ;
#else
# include "multi.h"
#endif

   ptr = currlevel->args ;
   value = wrapstring( *String, *Length ) ;
   number = atopos( value, "internal", 1 ) ;
   Free_string( value ) ;
   value = get_parameter( ptr, number ) ;

   if (value)
   {
      *(Length+1) = value->len ;
      *(String+1) = value->value ;
   }
   else
      *(Length+1) = RX_NO_STRING ;

   return RX_CODE_OK ;
#include "unmulti.h"
}


void SetupClient( char *dummy ) {}
void SetupInternal( char *dummy )
{
#include "multi.h"
 isclient=2 ;
#include "unmulti.h"
}


static int handle_no_of_params( int *Length, char **String )
{
   paramboxptr ptr=NULL ;
   static char scratch[32] ;
   int count=0 ;
#if !defined(HAVE_WINMULTITHREADING)
   extern proclevel currlevel ;
#else
# include "multi.h"
#endif

   ptr = currlevel->args ;
   count = count_params( ptr, PARAM_TYPE_HARD ) ;

   sprintf( *String=scratch, "%d", count ) ;
   *Length = strlen(*String) ;

   return RX_CODE_OK ;
#include "unmulti.h"
}



static int get_next_var( int *Lengths, char **Strings )
{
   variableptr value=NULL, rval=NULL, rrval=NULL ;
#include "multi.h"

   if (var_indicator==0)
   {
      get_next_variable( 1 ) ;
      var_indicator = 1 ;
   }

   for (;;)
   {
      value = get_next_variable( 0 ) ;
      for (rval=value; rval && rval->realbox; rval=rval->realbox) ;
      if (rval && !(rval->flag & VFLAG_STR))
      {
         if (rval->flag & VFLAG_NUM)
         {
            expand_to_str( rval ) ;
            break ;
         }

         if (!rval->stem)
            continue ;

         for (rrval=rval->stem; rrval && rrval->realbox; rrval=rrval->realbox);
         if (rrval && !(rrval->flag & VFLAG_STR))
         {
            if (rval->flag & VFLAG_NUM)
            {
               expand_to_str( rval );
               break ;
            }
            else
               continue ;
         }
      }
      break ;
   }

   if (rval)
   {
      if (rval->stem)
      {
         Lengths[0] = rval->stem->name->len + rval->name->len ;
         Strings[0] = Malloc( Lengths[0] ) ;
         memcpy(Strings[0], rval->stem->name->value, rval->stem->name->len);
         memcpy(Strings[0]+rval->stem->name->len,
                                      rval->name->value, rval->name->len ) ;
      }
      else
      {
         Lengths[0] = rval->name->len ;
         Strings[0] = rval->name->value ;
      }

      if (rval->value)
      {
         Lengths[1] = rval->value->len ;
         Strings[1] = rval->value->value ;
      }
      else
      {
         assert( rval->stem && rrval->value ) ;
         Lengths[1] = rval->stem->name->len + rval->name->len ;
         Strings[1] = Malloc( Lengths[1] ) ;
         memcpy( Strings[1], rval->stem->name->value, value->stem->name->len );
         memcpy( Strings[1]+value->stem->name->len,
                                        rval->name->value, rval->name->len ) ;
      }

      return 2 ;
   }
   else
   {
      /*
       * Once we have reached the end of all variables, reset var_indicator
       * so next time we can start from the beginning again.
       */
      var_indicator = 0 ;
      return 0 ;
   }
#include "unmulti.h"
}



void RunClient( void )
{
/*
   int code=0 ;

   while (1)
   {
      code = ReadNumber() ;
      if (code==RX_EXECUTE)
         execute_an_external() ;
      else if (code==RX_DROP_INSTORE)
      {
         kill_macro( NULL, ReadNumber()) ;
         SendNumber( RX_RETVOID ) ;
      }
      else
         exiterror( ERR_INTERPRETER_FAILURE, 0 )  ;

   }
 */

/*
   Free_string( WaitForReturn( &rc ) ) ;
 */
}


int MapHook( int RexxHook )
{
   switch ( RexxHook )
   {
      case HOOK_STDOUT: return RX_EXIT_STDOUT ;
      case HOOK_STDERR: return RX_EXIT_STDERR ;
      case HOOK_TRCIN:  return RX_EXIT_TRCIN ;
      case HOOK_PULL:   return RX_EXIT_PULL ;

      case HOOK_INIT:   return RX_EXIT_INIT ;
      case HOOK_TERMIN: return RX_EXIT_TERMIN ;
      case HOOK_SUBCOM: return RX_EXIT_SUBCOM ;

      default:
         closedown() ;
   }

   return 0 ;
}


int ReMapHook( int NetHook )
{
   switch ( NetHook )
   {
      case RX_EXIT_STDOUT: return HOOK_STDOUT ;
      case RX_EXIT_STDERR: return HOOK_STDERR ;
      case RX_EXIT_TRCIN:  return HOOK_TRCIN ;
      case RX_EXIT_PULL:   return HOOK_PULL ;

      case RX_EXIT_TERMIN: return HOOK_TERMIN ;
      case RX_EXIT_INIT:   return HOOK_INIT ;
      case RX_EXIT_SUBCOM: return HOOK_SUBCOM ;
      case RX_EXIT_FUNC:   return HOOK_FUNC ;

      default:
         closedown() ;
   }

   return 0 ;
}



int hookup( int hook )
{
   int rcode=0, code=0;

   code = MapHook ( hook );
   assert (code == RX_EXIT_INIT || code == RX_EXIT_TERMIN );
   rcode = IfcDoExit( code, NULL, NULL ) ;
   if (rcode==RX_HOOK_ERROR)
       exiterror( ERR_SYSTEM_FAILURE, 0 )  ;
   else if (rcode==RX_HOOK_GO_ON)
      rcode = HOOK_GO_ON ;
   else if (rcode==RX_HOOK_NOPE)
      rcode = HOOK_NOPE ;
   else
       exiterror( ERR_INTERPRETER_FAILURE, 0 )  ;
   return rcode ;
}

int hookup_output( int hook, streng *outdata )
{
   int rcode=0, code=0 ;
   char RetString[256] ;
   int RetLength=0 ;
   char *retstr=NULL;
   int retlen = 0;

   strcpy(RetString,"");

   code = MapHook( hook );
   assert (code == RX_EXIT_STDOUT || code == RX_EXIT_STDERR );
   if (outdata)
   {
      retstr = outdata->value ;
      retlen = outdata->len ;
      rcode = IfcDoExit( code, &retlen, &retstr ) ;
   }
   else
   {
      RetLength = 0;
      retstr = RetString;
      rcode = IfcDoExit( code, &RetLength, &retstr ) ;
   }

   if (rcode==RX_HOOK_ERROR)
       exiterror( ERR_SYSTEM_FAILURE, 0 )  ;
   else if (rcode==RX_HOOK_GO_ON)
      rcode = HOOK_GO_ON ;
   else if (rcode==RX_HOOK_NOPE)
      rcode = HOOK_NOPE ;
   else
      exiterror( ERR_INTERPRETER_FAILURE, 0 )  ;

   return rcode ;
}

int hookup_input( int hook, streng **indata )
{
   int rcode=0, code=0 ;
   char RetString[256] ;
   int RetLength=0 ;
   char *retstr=NULL;

   strcpy(RetString,"");
   code = MapHook( hook );
   assert (code == RX_EXIT_PULL || code == RX_EXIT_TRCIN );
   retstr = RetString;
   rcode = IfcDoExit( code, &RetLength, &retstr ) ;
   if (rcode==RX_HOOK_ERROR)
      exiterror( ERR_SYSTEM_FAILURE, 0 )  ;
   else if (rcode==RX_HOOK_GO_ON)
      rcode = HOOK_GO_ON ;
   else if (rcode==RX_HOOK_NOPE)
      rcode = HOOK_NOPE ;
   else
      exiterror( ERR_INTERPRETER_FAILURE, 0 )  ;

#ifdef FGC
   /* Attention: retstr might not be the same as RetString! Look at the
    * ampersand in IfcDoExit. Some things might go wrong with interactive
    * Rexx (which invokes this function) if we believe in same values.
    */
   (*indata) = wrapstring( retstr, RetLength ) ;
#else
   (*indata) = wrapstring( RetString, RetLength ) ;
#endif
   if (!*indata)
      *indata = Str_cre("") ;
   return rcode ;
}



streng *SubCom( streng *command, streng *envir, int *rc )
{
   int tmplen=0 ;
   char *tmpptr=NULL ;

   *rc = IfcSubCmd( (envir ? envir->len : RX_NO_STRING),
                    (envir ? envir->value : NULL),
                     command->len, command->value, &tmplen, &tmpptr ) ;

   return wrapstring( tmpptr, tmplen ) ;
}


/****************************************************************************
 *
 *  JH 13/12/1999 Trying to satisfy both BUG031 and BUG022.
 *
 *  BUG022  To make Direct setting of stems Direct and not Symbolic.
 *   - Added new parameter, "Code".  Assumed values are RX_GETSVAR, and
 *     RX_GETVAR.  They denote that the actiion is symbolic, or direct
 *     (respectively).
 *   - if direct call getdirvalue()
 *
 *  BUG031
 *   - if default value is being returned, uppercase the whole name for
 *     symbolics, and only the stem for directs.  This should be a moot
 *     issue, as there is code in variable.c to return default values.
 *
 *
 ****************************************************************************/
int GetVariable( int Code, int *Lengths, char *Strings[] )    /* JH 20-10-99 */
{
   streng *varbl=NULL, *value=NULL ;
   int rcode=0, i ;

   varbl = wrapstring( Strings[0], Lengths[0] ) ;
   assert( varbl ) ;

   rcode = RX_CODE_OK ;
   if (!valid_var_symbol(varbl))
   {
      rcode = RX_CODE_INVNAME ;
      Lengths[1] = RX_NO_STRING ;
   }
   else
   {
      if(Code == RX_GETSVAR) value = getvalue( varbl, 1 ) ;   /* JH 20-10-99 */
      else value = getdirvalue( varbl, 1 ) ;                  /* JH 20-10-99 */
      if (!var_was_found())
      {
         if(Code == RX_GETSVAR) value = Str_upper(Str_dup(value)) ; /* FGC uppercased           */
         else {                                               /* JH 13-12-99 */
           /*  If this is a direct variable, only uppercase the stem name.   */
           value = Str_dup(value) ;                           /* JH 13-12-99 */
           for(i=0;i<value->len && '.' != value->value[i];i++)value->value[i] = toupper(value->value[i]);  /* JH 13-12-99 */
           }                                                  /* JH 13-12-99 */
         rcode = RX_CODE_NOVALUE ;
      }
      Lengths[1] = value->len ;
      Strings[1] = value->value ;
   }

   Free_string( varbl ) ;
   return rcode ;
}

/****************************************************************************
 *
 *  JH 13/12/1999 Trying to satisfy both BUG031 and BUG022.
 *
 *  BUG022  To make Direct setting of stems Direct and not Symbolic.
 *   - Added new parameter, "Code".  Assumed values are RX_SETSVAR, and
 *     RX_SETVAR.  They denote that the actiion is symbolic, or direct
 *     (respectively).
 *  Until this point setting and dropping variables have been treated as
 *  the same.  If there is a value, then it is a set, otherwise drop it.
 *   - if direct call setdirvalue()
 *   - if direct call drop_dirvar()
 *  BUG031
 *   - uppercase the whole name for symbolics, and only the stem for directs.
 *
 *
 *
 ****************************************************************************/
int SetVariable(int Code, int *Lengths, char *Strings[] )     /* JH 20-10-99 */
{
   streng *varbl=NULL, *value=NULL ;
   int rcode=0, i ;

   /*    Removed by JH on 13/12/99.  This is good logic, for symbolic only.
    *  Trying to satisfy both BUG031 and BUG022.
    * varbl = Str_upper( wrapstring( Strings[0], Lengths[0] ) ); -- MH - uppercase variable name - BUG031 *
    */
   varbl = wrapstring( Strings[0], Lengths[0] ) ;             /* JH 13-12-99 */
   if(Code == RX_SETSVAR) varbl = Str_upper(Str_dup(varbl)) ; /* JH 13-12-99 */
   else {                                                     /* JH 13-12-99 */
     /*  If this is a direct variable, only uppercase the stem name.   */
     varbl = Str_dup(varbl) ;                                 /* JH 13-12-99 */
     for(i=0;i<varbl->len && '.' != varbl->value[i];i++)varbl->value[i] = toupper(varbl->value[i]);  /* JH 13-12-99 */
     }                                                        /* JH 13-12-99 */
   value = wrapstring( Strings[1], Lengths[1] ) ;
   assert( varbl ) ;

   rcode = RX_CODE_OK ;
   if (!valid_var_symbol(varbl))
   {
      rcode = RX_CODE_INVNAME ;
   }
   else
   {
      if (value)
      {
         if (Code == RX_SETSVAR) setvalue( varbl, value ) ;   /* JH 20-10-99 */
         else setdirvalue( varbl, value ) ;                   /* JH 20-10-99 */
      }
      else
      {
         if(Code == RX_SETSVAR) drop_var( varbl ) ;           /* JH 20-10-99 */
         else drop_dirvar( varbl ) ;                          /* JH 20-10-99 */
      }
      if (!var_was_found())
         rcode = RX_CODE_NOVALUE ;
   }

   Free_string( varbl ) ;
   return rcode ;
}

static int handle_version( int *Length, char **String )
{
   *Length = strlen(PARSE_VERSION_STRING) ;
   *String = PARSE_VERSION_STRING ;
   return RX_CODE_OK ;
}


static int handle_queue( int *Length, char **String )
{
   *Length = 7 ;
   *String = "default" ;
   return RX_CODE_OK ;
}




/****************************************************************************
 *
 *  JH 13/12/1999
 *
 *  BUG022  To make Direct setting of stems Direct and not Symbolic.
 *   - Added checks for the direct variable functions RX_GETVAR and RX_SETVAR.
 *
 *
 *
 ****************************************************************************/
int IfcVarPool( int Code, int *Lengths, char *Strings[] )
{
   int rc=0 ;

   if (Code==RX_GETSVAR ||Code==RX_GETVAR )                   /* JH 20-10-99 */
      rc = GetVariable( Code, Lengths, Strings ) ;            /* JH 20-10-99 */
   else if (Code==RX_SETSVAR ||Code==RX_SETVAR )              /* JH 20-10-99 */
      rc = SetVariable( Code, Lengths, Strings ) ;            /* JH 20-10-99 */
   else if (Code==RX_NEXTVAR)
      rc = get_next_var( Lengths, Strings ) ;
   else if (Code==RX_CODE_VERSION)
      rc = handle_version( Lengths, Strings ) ;
   else if (Code==RX_CODE_SOURCE)
      rc = handle_source( Lengths, Strings ) ;
   else if (Code==RX_CODE_QUEUE)
      rc = handle_queue( Lengths, Strings ) ;
   else if (Code==RX_CODE_PARAMS)
      rc = handle_no_of_params( Lengths, Strings ) ;
   else if (Code==RX_CODE_PARAM)
      rc = handle_param( Lengths, Strings ) ;
   else
      assert( dummyzero2 ) ;

   return rc ;
}




int IfcRegFunc( char *Name )
{
   assert( Name ) ;
   addfunc( Str_cre( Name ), 1 ) ;
   return RX_CODE_OK ;
}


int IfcDelFunc( char *Name )
{
   streng *name;

   assert( Name ) ;
   name = Str_upper( Str_cre( Name ) );
   return(rex_rxfuncdlldrop(name));
}

int IfcQueryFunc( char *Name )
{
   streng *name;

   assert( Name ) ;
   name = Str_upper( Str_cre( Name ) );
   return(rex_rxfuncdllquery(name));
}

void *IfcAllocateMemory( unsigned long size )
{
   void *ret;
#if defined( WIN32 )
   ret = (void *)( GlobalLock( GlobalAlloc ( GMEM_FIXED, size ) ) );
   return ret;
#elif defined( OS2 )
   if ( ( BOOL )DosAllocMem( &ret, size, fPERM|PAG_COMMIT ) )
      return NULL;
   else
      return ret;
#else
   ret = (void *)malloc( size );
   return ret;
#endif
}

unsigned long IfcFreeMemory( void *ptr )
{
#if defined( WIN32 )
   GlobalFree( ptr );
#elif defined( OS2 )
   DosFreeMem( ptr );
#else
   free( ptr );
#endif
   return 0;
}


streng *do_an_external( streng *name, paramboxptr parms, char exitonly, char called )
{
   static char *namespc=NULL ;
   static int namelen=(-1) ;
   static int *Lengths=NULL ;
   static int strlen=(-1) ;
   static char **Strings=NULL ;
   int RetLength=0 ;
   char *RetString=NULL ;
   streng *retval=NULL ;
   int rc=0 ;
   int RC=0 ;
   int i=0, j=0 ;
   paramboxptr p=NULL ;

   if (name->len>=namelen)
   {
      if (namespc)
         Free( namespc ) ;

      namespc = Malloc( name->len + 1 ) ;
   }
   memcpy( namespc, name->value, name->len ) ;
   namespc[name->len] = 0x00 ;

   for (j=i=0,p=parms; p; p=p->next,i++)
      if (p->value)
         j=i+1 ;

   if (j>strlen)
   {
      if (Lengths)
         Free( Lengths ) ;

      if (Strings)
         Free( Strings ) ;

#if FGC
      /* FGC: i loops until j including in */
      /* next "for": use j+1 instead       */
      /* of j                              */
      Lengths = Malloc( sizeof(int)*(j+1) ) ;
      Strings = Malloc( sizeof(char*)*(j+1) ) ;
#else
      Lengths = Malloc( sizeof(int)*j ) ;
      Strings = Malloc( sizeof(char*)*j ) ;
#endif
      strlen = j ;
   }

   for (i=0,p=parms; p && i<=j; p=p->next,i++)
      if (p->value)
      {
         p->value = Str_ify( p->value );
         Lengths[i] = p->value->len ;
         Strings[i] = p->value->value ;
      }
      else
         Lengths[i] = RX_NO_STRING ;

   rc = IfcExecFunc( NULL, namespc, j, Lengths, Strings,
                     &RetLength, &RetString, &RC, exitonly, called );

   if (RC)
   {
      exiterror( RC, 0) ;
      retval = NULL ;
   }
   else
   {
      retval = Str_make( RetLength ) ;
      memcpy( retval->value, RetString, RetLength ) ;
      retval->len = RetLength ;
   }
   return retval ;
}

streng *do_an_external_dll( void *vbox, paramboxptr parms, char called )
{
   static int *Lengths=NULL ;
   static int strlen=(-1) ;
   static char **Strings=NULL ;
   int RetLength=0 ;
   char *RetString=NULL ;
   streng *retval=NULL ;
   int rc=0 ;
   int RC=0 ;
   int i=0, j=0 ;
   paramboxptr p=NULL ;
   struct library_func *box=NULL ;

   assert( vbox );
   box = (struct library_func*)(vbox) ;

   for (j=i=0,p=parms; p; p=p->next,i++)
      if (p->value)
         j=i+1 ;

   if (j>strlen)
   {
      if (Lengths)
         Free( Lengths ) ;

      if (Strings)
         Free( Strings ) ;

#if FGC
      /*
       * FGC: i loops until j included in next "for": use j+1 instead
       */
      Lengths = Malloc( sizeof(int)*(j+1) ) ;
      Strings = Malloc( sizeof(char*)*(j+1) ) ;
#else
      Lengths = Malloc( sizeof(int)*j ) ;
      Strings = Malloc( sizeof(char*)*j ) ;
#endif
      strlen = j ;
   }

   for (i=0,p=parms; p && i<=j; p=p->next,i++)
      if (p->value)
      {
         p->value = Str_ify( p->value );
         Lengths[i] = p->value->len ;
         Strings[i] = p->value->value ;
      }
      else
         Lengths[i] = RX_NO_STRING ;

   rc = IfcExecFunc( box->addr, box->name->value, j, Lengths, Strings,
                     &RetLength, &RetString, &RC, 0, called );

   if (RC)
   {
      exiterror( RC, 0 ) ;
      retval = NULL ;
   }
   else
   {
      retval = Str_make( RetLength ) ;
      memcpy( retval->value, RetString, RetLength ) ;
      retval->len = RetLength ;
   }

   return retval ;
}