PS> To:   scoug-programming@scoug.com 
PS> Subject: SCOUG-Programming:   Q. Rexx stem variables as parameters? 
PS> 
PS> ........................................................... 
PS> 
PS> but I'm writing a library routine so I won't know what the stem 
PS> variable's name is. 
PS> 
PS> ............................................................ 
PS> 
Tell us about these libraries - do you really want ot re-use them that 
much? 
I suppose you might be using several routines from these libraries, 
causing name conflicts between their internal variables vrs. 
the ones in the main routine you're writing, but is this certain? 
##################################################################### 
Pure 'indexed' Queue Approach: 
/* REXX - How do you pass stem variables as parameters? */ 
/*        Answer: Use a queue instead of a stem variable.   */ 
/* derived from ps1.cmd        */ 
/*      Define 'object' Queue 'AQ'   and it's properties      */ 
A = 'AQ' 
CALL DefineQ A 
/* 2. Show what's in it. */ 
CALL ShowQ '2-' A 
/* 3. Now call a procedure and see if you can display and modify the values. */ 
/* call stemvar A.  Note I'm calling with "A.", not "A".  "A" fails too. */ 
call stemvar A  /* Note I'm calling with "A.", not "A".  "A" fails too. */ 
/* 4. Show what's in it after returning. */ 
CALL ShowQ '4-' A 
/* 5. Now call a function and see if you can display, modify and return the val 
ues. */ 
/* say '5a-' stemfunc(A.)   "stemfunc()" returns a value. */ 
say '5a-' stemfunc( A )           /* "stemfunc()" returns a value. */ 
/* 6. Show what's in the stem variable now. */ 
CALL ShowQ '6-' A 
CALL DelQ A 
exit 
/*************************************************************/ 
/* SUBROUTINES FOLLOW */ 
stemvar:  PROCEDURE 
/*        This might be external            */ 
PARSE ARG X 
/*     Here, download the values from the Queue    */ 
CALL RXQUEUE 'SET', X 
        /*     It might be good to have a check here that X's value 
               was a valid queue name, but for now 
               skip this after all the RXQUEUE 'SET' calls. 
               */ 
xcount = Queued() 
DO xcount 
  PARSE VALUE LINEIN('QUEUE:') WITH itemno ':' xelement.itemno 
END 
/*   Do some things with the queue         */ 
say "3- In StemVar ..." 
say '3-' xelement.1 
xelement.2 = 'New line 2' 
/*     Here, relaod the queue           */ 
CALL RXQUEUE 'SET', X 
DO index = 1 TO xcount 
  QUEUE index || ':' || xelement.index 
END 
say "3-' Exiting ..." 
return arg(1). 
/*************************************************************/ 
stemfunc:  PROCEDURE 
/*        This might be external            */ 
PARSE ARG X 
/*     Here, download the values from the Queue    */ 
CALL RXQUEUE 'SET', X 
xcount = Queued() 
DO xcount 
  PARSE VALUE LINEIN('QUEUE:') WITH itemno ':' xelement.itemno 
END 
/*      Do some things to the queue elements        */ 
say "5- In StemFunc ..." 
say '5-' xelement.2 
xelement.2 = "Hello, World" 
/*     Here, reload the QUEUE       */ 
CALL RXQUEUE 'SET', X 
DO index = 1 TO xcount 
  QUEUE index || ':' || xelement.index 
END 
say "5- Exiting ..." 
return xelement.2 
/************************************************************** 
     define 'Object'  Queue ' 
     **********************************************************/ 
DefineQ:  PROCEDURE 
PARSE ARG A 
/* 1. Initialize a queue structure. */ 
DHammer: 
SAY 'A is: 'A 
TrueName = RXQUEUE( 'CREATE', A) 
IF ( TrueName >< A ) THEN 
  DO 
  /*      Some steps to prevent queue leaks - might need to be    */ 
  /*       different if program intended to be multitasked.       */ 
  CALL RXQUEUE 'Delete', A 
  CALL RXQUEUE 'Delete', TrueName 
  SIGNAL DHammer 
  END 
SAY 'Using Queue: 'A 
CALL RXQUEUE 'SET', A 
/*     Stuff values into the queue         */ 
QUEUE 1 || ':' || 'Line 1' 
QUEUE 2 || ':' || 'Line 2' 
QUEUE 3 || ':' || 'Line 3' 
return 
/*************************************************************/ 
DelQ:  PROCEDURE 
PARSE ARG X 
/*     Delete the QUEUE when finished with it.      */ 
CALL RXQUEUE 'Delete', X 
RETURN 
/*************************************************************/ 
ShowQ:  PROCEDURE 
PARSE ARG PREFIX X 
/*    Routine to display elements in the Queue           */ 
CALL RXQUEUE 'SET', X 
do Queued() 
  /*     Fanning Through the queue          */ 
  PARSE VALUE LINEIN('QUEUE:') WITH itemno ':' xelement.itemno 
  /*       Get index and value off the queue       */ 
  say PREFIX || xelement.itemno 
  /*        Doing something with the item taken off the queue    */ 
  QUEUE itemno || ':' || xelement.itemno 
  /*     Reloading the item number and value onto the queue    */ 
  end  /* I indent my "end" statements. :) */ 
return 
/*         End of REXX  Program         */ 
############################################################# 
A simple example of what could be done with 'sed', (Stream Editor): 
#  File 'Cleanup.SED' 
#  Lines starting with '#' are comments, SED is too simple 
#   to cope with comment delimiters in other locations 
#     (at least officially) 
# 
#  A SED script to clean up an input file 
s/Sentence/Line/g 
s/ A/ 1/g 
s/ B/ 2/g 
s/ C/ 3/g 
.  .   . 
.  .   . 
.  .   . 
s/GarbageX//g 
#     The above substitutions default to all lines of the input file. 
# 
#     The above are the important ones for this hypothetical 
#         example case 
# 
#         now some just to show a little more of sed's capabilities: 
# 
# 
5,81s/GarbageY/Important character string/g 
# 
#      this last one will happen only to lines 5 to 81 of the input file. 
# 
s@Garbage/Z@GarbageZ@ 
# 
#     character following "s" instead of "/" to delimit 
#     target and substitution strings 
# 
#      continuing with straight substitutions to be made to the file 
#    SED's  "s" command just substitutes first item with second 
# 
#     Just to keep things as simple as possible 
#     this example does not use any 'Regular Expressions' or 
#       'Wild Cards' in the string changed to some other string. 
# 
#     End of File 'Cleanup.SED' 
EXAMPLE input, we'll call it InA.txt: 
GarbageXSentence A GarbageX 
GarbageXSentence B GarbageX 
GarbageXSentence C GarbageX 
          . 
          . 
          . 
Example output, we'll call it OutB.txt: 
Line 1 
Line 2 
Line 3 
  . 
  . 
  . 
Example invocation: 
sed -f cleanup.sed  < InA.txt  > OutB.txt 
>>>>>>>>Question for Peter Skye: Does the above look like something 
that could chop a lot of clutter out of the Rexx script, 
if run before hand? 
My suspicion is yes. 
Question for Steve Lavine: 
I think you raised the question whether queue's and named pipes were 
the same.  I think you said you had worked with named pipes before. 
Do you or anyone else out there remember if named pipes were one way only? 
Program A  transfers data to program B, but not the other way 
around for one case of running a named pipe between A and B? 
I think A and B, running at the same time, could both put 
things on both ends of some arbitrary external queueh, 
and either could take stuff off the top. 
Regards, 
Dallas E. Legan II 
(562) 862 - 4854 ext. '*' 
L 
E 
G 
A 
N 
@ 
A 
C 
M 
. 
O 
R 
G 
===================================================== 
To unsubscribe from this list, send an email message 
to "steward@scoug.com". In the body of the message, 
put the command "unsubscribe scoug-programming". 
For problems, contact the list owner at 
"rollin@scoug.com". 
===================================================== 
 >> Next Message >>
Return to [ 22 | 
November | 
1998 ]
The Southern California OS/2 User Group
P.O. Box 26904
Santa Ana, CA  92799-6904, USA
Copyright 2001 the Southern California OS/2 User Group.  ALL RIGHTS 
RESERVED. 
SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group.
OS/2, Workplace Shell, and IBM are registered trademarks of International 
Business Machines Corporation.
All other trademarks remain the property of their respective owners.