APCUTOKN ; CONVERT INPUT LINE TO TOKENS ; [ 08/21/86 10:52 AM ]
K WT
S SWB="",STATE="SKIP",I=0,LLEN=$L(L)
CHLOOP S I=I+1 G:I>LLEN EXIT
S C=$E(L,I)
S OSTATE=STATE
I OSTATE="SKIP",(C'?1P!("'~"[C&(($E(L,I+1)?1U)!("'~"[$E(L,I+1))))) S STATE="SCAN",WS=I
I OSTATE="SCAN",C?1P,"-'~"'[C S END=0 D ENDWORD S STATE="SKIP"
G CHLOOP
EXIT I STATE="SCAN" S END=1 D ENDWORD
K SWB,OSTATE,STATE,LLEN,C,J,WF,WS,WD,WD2,WL,END,Q
Q
ENDWORD S WL=I-WS,WD=$E(L,WS,I-1)
I WL=1 S SWB=SWB_WD I END S WD=SWB D STOREWD
I WL>1 D STOREWD I SWB'="" S WD=SWB,SWB="" D STOREWD
Q
STOREWD ;
S J=$S($E(WD)="'":2,$E(WD,1,2)="~'":3,1:1)
RMQ S J=$F(WD,"'",J) I J S WD=$E(WD,1,J-2)_$E(WD,J,255),J=J-1 G RMQ
I WD'["-" S WT(WD)="" Q
S WD2="" F J=1:1 S WF=$P(WD,"-",J) Q:WF="" Q:$L(WF)>2 S WD2=WD2_WF
I WF="" S WT(WD2)="" Q
S WD2=WD F J=1:1 S WF=$P(WD2,"-",J) Q:WF="" S WT(WF)=""
Q