>
> I thought I remembered SPL, but line 8 has me stumped
>
> 1 LOGICAL PROCEDURE MOVEAS(BARRAY);
> 2 BYTE ARRAY BARRAY;
> 3 BEGIN
> 4 ARRAY DUMMY(0:1);
> 5 BYTE ARRAY DUMMYBYTE(*)=DUMMY;
> 6 MOVE DUMMY:=" ";
Put 4 blanks into DUMMY (which is equated to DUMMY, which is 2 16-bit
halfwords long, or 4 bytes).
> 7 MOVE DUMMYBYTE:=BARRAY,(2);
Move 2 bytes from barray into dummybyte.
If we call the first two bytes in BARRAY "x" and "y" (two unknown values),
we now have: "xy " in DUMMY/DUMMYBYTE.
> 8 MOVE DUMMYBYTE:=DUMMYBYTE WHILE AS;
"Move while source byte is ALPHA (i.e., a letter), and upShift while you're
at it".
This will do the following:
1. if "x" is a letter ("A".."Z", "a".."z"), it will be upshifted in place.
(I.e.: "a" --> "A"), and we continue to step 3 below.
2. if "x" is *NOT* a letter, we stop.
3. if "y" is a letter, it will be upshifted in place, and we continue to
step 5 below.
4. if "y" is *NOT* a letter, we stop.
5. if the " " after "xy" is a letter...well, we *know* it isn't a
letter, so we know what happens: we stop.
In short, this will upshift "ab" to "AB", "a3" to "A3", but *not* "3a".
Now...if that's the desired action (i.e., that "3a" isn't upshifted), then
everything is fine.
> 9 MOVEAS:=DUMMY;
Picks up the first 2 bytes (transformed "xy") and returns them as a 16-bit
result.
Personally, I'd replace the MOVE ...:= " " on line 6 with
dummybyte (2) := " ", which will have the same effect, and intuitively
seems a little bit faster.
And, I'd definitely rename the procedure to something like upshift'2'bytes
(and document whether or not both bytes are supposed to be
unconditionally upshifted.)
BTW, if you want both bytes upshifted in all cases, two methods spring
to mind:
1) move dummybyte := dummybyte while ans;
move dummybyte (1) := dummybyte (1) while ans;
or
2) if (move dummybyte := dummybyte while ans) < 2 then
move dummybyte (1) := dummybyte (1) while ans;
or
3) if "a" <= integer (dummybyte) <= "z" then
dummybyte := (dummybyte - "a") + "A";
if "a" <= integer (dummybyte (1)) <= "z" then
dummybyte (1) := (dummybyte (1) - "a") + "A";
(Sure, using TOS/address-equations/X-register would be slightly faster
but would cost more extra time to develop and read than would ever be
saved in the lifetime of the code!)
--
Stan (can you tell I had nothing better to work on :) Sieler
|