home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFPRC1
/
INSERTB.SRF
< prev
next >
Wrap
Text File
|
1997-01-05
|
2KB
|
57 lines
/********************************************************************************/
/* ------------------------- File and string manipulation routines-------- */
/* ----------------------------------------------------------------------- */
/* INSERT_BLOCK
. insert a block (addme) into haystack, right after or before aLabel ,
. where the alabel has the form delim1 label delim2
. Insertion is immediately after delim2, or before delim1
. (if after=1, then after --)
(if after=2, then replace delim1 label delim2 with addme )
. Default values of delim1={, 2=}
. Note that labels must have NO embedded spaces.
.
. Returns the added to (or not added to) haystack
*/
/* ----------------------------------------------------------------------- */
sref_insert_block:
parse arg haystack , alabel , addme , after, delim1 , delim2
if delim1='' then delim1='{'
if delim2='' then delim2='}'
if after=" " then after=1
alabel=translate(alabel)
thaystack=translate(haystack)
/* see any alabel appears anywhere */
foo=pos(alabel,thaystack)
if foo=0 then return haystack /* no match to label name, so no label */
new1=""
do forever
parse var haystack pp1 (delim1) in1 (delim2) haystack
if in1="" & haystack="" then do
return new1||pp1
end
cand=translate(word(in1,1))
if cand=alabel then do
select
when after=2 then
new1=new1||pp1||addme||haystack
when after=1 then
new1=new1||pp1||delim1||in1||delim2||addme||haystack
otherwise
new1=new1||pp1||addme||delim1||in1||delim2||haystack
end
return new1
end
/* else, keep looking */
new1=new1||pp1||delim1||in1||delim2
end
return haystack /* if here, no reasonable match */