1
2
3
|
PACKETtextrowDEFINES TEXTROW,emptytextrow,:=,highestentry,firstentry,nextentry,CONTAINS,link,name,rename,insert,delete,get,top,pop,leftmatchinglinks,rightmatchinglinks,LIKE,REV,+,-,/,*,<,<>,>,<=,=,>=,textrow,thesaurus,FILLBY,:LEThex00="�";LEThexff="�";LEThex0000="��";LEThex0001="��";LEThexfeff="��";LEThexffff="��";TEXT VARindexpat:="��ii��";replace(indexpat,2,1);TEXT VARentrypat;TYPE TEXTROW=TEXT;TEXTROW CONSTemptytextrow:=TEXTROW:(indexpat);OP:=(TEXTROW VARd,TEXTROW CONSTs):CONCR(d):=CONCR(s);END OP:=;PROCcatexpanded(TEXT VARt,TEXT CONSTentry):INT CONSTl:=LENGTHentry;INT VARb:=1;INT VARef:=pos(entry,hexff,b);IFef=0THENef:=l+1FI;INT VARe0:=pos(entry,hex00,b);IFe0=0THENe0:=l+1FI;REP IFe0<efTHENtCATsubtext(entry,b,e0-1);tCAThex0001;b:=e0+1;e0:=pos(entry,hex00,b);IFe0=0THENe0:=l+1FI;ELIFef<e0THENtCATsubtext(entry,b,ef-1);tCAThexfeff;b:=ef+1;ef:=pos(entry,hexff,b);IFef=0THENef:=l+1FI;ELSEtCATsubtext(entry,b);LEAVEcatexpanded;FI;PER;END PROCcatexpanded;PROCcatcompressed(TEXT VARt,TEXT CONSTentry):INT CONSTl:=LENGTHentry;INT VARb:=1;INT VARef:=pos(entry,hexfeff,b);IFef=0THENef:=l+1FI;INT VARe0:=pos(entry,hex0001,b);IFe0=0THENe0:=l+1FI;REP IFe0<efTHENtCATsubtext(entry,b,e0-1);tCAThex00;b:=e0+2;e0:=pos(entry,hex0001,b);IFe0=0THENe0:=l+1FI;ELIFef<e0THENtCATsubtext(entry,b,ef-1);tCAThexff;b:=ef+2;ef:=pos(entry,hexfeff,b);IFef=0THENef:=l+1FI;ELSEtCATsubtext(entry,b);LEAVEcatcompressed;FI;PER;END PROCcatcompressed;INT PROChighestentry(TEXTROW CONSTt):INT VARp:=LENGTH CONCR(t)-5;IFp>0THEN(subtext(CONCR(t),p+2,p+3)ISUB1)-1ELSE0FI END PROChighestentry;INT PROCfirstentry(TEXTROW CONSTdir):nextentry(dir,0)END PROCfirstentry;INT PROCnextentry(TEXTROW CONSTdir,INT CONSTstart):INT VARindex:=start;INT CONSTlimit:=highestentry(dir);WHILEindex<=limitREPindexINCR1UNTILname(dir,index)<>""PER;indexEND PROCnextentry;BOOL OP CONTAINS(TEXTROW CONSTt,TEXT CONSTentry):entrypat:=hexffff;catexpanded(entrypat,entry);entrypatCAThex0000;pos(CONCR(t),entrypat,1)>0END OP CONTAINS;INT PROClink(TEXTROW CONSTt,TEXT CONSTentry):INT VARp;entrypat:=hexffff;catexpanded(entrypat,entry);entrypatCAThex0000;p:=pos(CONCR(t),entrypat,1);IFp>0THENsubtext(CONCR(t),p-2,p-1)ISUB1ELSE0FI END PROClink;INT PROClink(TEXTROW CONSTt,TEXT CONSTentry,INT CONSTstart):INT VARp,index;entrypat:=hexffff;catexpanded(entrypat,entry);entrypatCAThex0000;p:=0;REPp:=pos(CONCR(t),entrypat,p+1);IFp=0THEN LEAVElinkWITH0FI;index:=subtext(CONCR(t),p-2,p-1)ISUB1;UNTILindex>=startPER;indexEND PROClink;TEXT PROCname(TEXTROW CONSTt,INT CONSTindex):replace(indexpat,2,index);INT VARb:=pos(CONCR(t),indexpat,1);IFb=0THEN LEAVEnameWITH""FI;replace(indexpat,2,index+1);INT VARe:=pos(CONCR(t),indexpat,b+6);IFe=0THEN LEAVEnameWITH""FI;entrypat:="";catcompressed(entrypat,subtext(CONCR(t),b+6,e-1));entrypatEND PROCname;PROCrename(TEXTROW VARt,TEXT CONSTold,new):INT VARp,len;entrypat:=hexffff;catexpanded(entrypat,old);entrypatCAThex0000;p:=pos(CONCR(t),entrypat,1);IFp>0THENlen:=LENGTHentrypat;entrypat:="";catexpanded(entrypat,new);change(CONCR(t),p+2,p+len-3,entrypat);FI;END PROCrename;PROCrename(TEXTROW VARt,INT CONSTindex,TEXT CONSTnew):replace(indexpat,2,index);INT VARb:=pos(CONCR(t),indexpat,1);replace(indexpat,2,index+1);INT VARe:=pos(CONCR(t),indexpat,b+6);IFe>0THENchange(CONCR(t),b+6,e-1,new);FI;END PROCrename;PROCinsert(TEXTROW VARt,TEXT CONSTentry,INT VARindex):index:=subtext(CONCR(t),LENGTH CONCR(t)-3)ISUB1;catexpanded(CONCR(t),entry);replace(indexpat,2,index+1);CONCR(t)CATindexpat;END PROCinsert;PROCinsert(TEXTROW VARt,TEXT CONSTentry):INT VARindex;insert(t,entry,index);END PROCinsert;PROCdelete(TEXTROW VARt,TEXT CONSTentry,INT VARindex):INT VARp;entrypat:=hexffff;catexpanded(entrypat,entry);entrypatCAThex0000;p:=pos(CONCR(t),entrypat,1);IFp>0THENindex:=subtext(CONCR(t),p-2,p-1)ISUB1;change(CONCR(t),p+2,p+len-3,"");ELSEindex:=0;FI;END PROCdelete;PROCdelete(TEXTROW VARt,INT CONSTindex):replace(indexpat,2,index);INT VARb:=pos(CONCR(t),indexpat,1)+6;replace(indexpat,2,index+1);INT VARe:=pos(CONCR(t),indexpat,b);
IFe=0THEN LEAVEdeleteFI;IFindex=highestentry(t)THEN CONCR(t):=subtext(CONCR(t),1,b-1);ELSEchange(CONCR(t),b,e-1,"");FI;END PROCdelete;PROCget(TEXTROW CONSTt,TEXT VARentry,INT VARindex):INT VARb,e;indexINCR1;replace(indexpat,2,index);b:=pos(CONCR(t),indexpat,1);entry:="";REPbINCR6;indexINCR1;replace(indexpat,2,index);e:=pos(CONCR(t),indexpat,b);IFe>bTHENindexDECR1;catcompressed(entry,subtext(CONCR(t),b,e-1));LEAVEget;ELIFe=0THENindex:=0;LEAVEget;FI;PER;END PROCget;TEXT PROCtop(TEXTROW CONSTt):name(t,highestentry(t))END PROCtop;TEXT PROCpop(TEXTROW VARt):pop(t,entrypat);entrypatEND PROCpop;PROCpop(TEXTROW VARt,TEXT VARentry):entry:=top(t);delete(t,highestentry(t));END PROCpop;INT PROCleftmatchinglinks(TEXTROW CONSTt,TEXT CONSTentry):INT VARp,l,n;entrypat:=hexffff;catexpanded(entrypat,entry);l:=LENGTHentrypat;n:=0;p:=pos(CONCR(t),entrypat,1);WHILEp>0REPnINCR1;p:=pos(CONCR(t),entrypat,p+l)PER;nEND PROCleftmatchinglinks;INT PROCrightmatchinglinks(TEXTROW CONSTt,TEXT CONSTentry):INT VARp,l,n;entrypat:="";catexpanded(entrypat,entry);entrypatCAThex0000;l:=LENGTHentrypat;n:=0;p:=pos(CONCR(t),entrypat,1);WHILEp>0REPnINCR1;p:=pos(CONCR(t),entrypat,p+l)PER;nEND PROCrightmatchinglinks;TEXTROW OP LIKE(TEXTROW CONSTa,TEXT CONSTpattern):TEXTROW VARlike:=emptytextrow;TEXT VARentry;INT VARindex;FORindexFROM1UPTOhighestentry(a)REPentry:=name(a,index);IFlink(like,entry)=0AND(entryLIKEpattern)THENinsert(like,entry)FI;PER;likeEND OP LIKE;TEXTROW OP REV(TEXTROW CONSTa):TEXTROW VARrev:=emptytextrow;INT VARindex;FORindexFROMhighestentry(a)DOWNTO1REPinsert(rev,name(a,index));PER;revEND OP REV;TEXTROW OP-(TEXTROW CONSTa):textrow(all)-aEND OP-;TEXTROW OP+(TEXTROW CONSTa,b):TEXTROW VARunion:=emptytextrow;TEXT VARentry;INT VARindex;FORindexFROM1UPTOhighestentry(a)REPentry:=name(a,index);IFlink(union,entry)=0THENinsert(union,entry)FI;PER;FORindexFROM1UPTOhighestentry(b)REPentry:=name(b,index);IFlink(union,entry)=0THENinsert(union,entry)FI;PER;unionEND OP+;TEXTROW OP-(TEXTROW CONSTa,b):TEXTROW VARdiff:=emptytextrow;TEXT VARentry;INT VARindex;FORindexFROM1UPTOhighestentry(a)REPentry:=name(a,index);IFlink(diff,entry)=0ANDlink(b,entry)=0THENinsert(diff,entry)FI;PER;diffEND OP-;TEXTROW OP/(TEXTROW CONSTa,b):TEXTROW VARinter:=emptytextrow;TEXT VARentry;INT VARindex;FORindexFROM1UPTOhighestentry(a)REPentry:=name(a,index);IFlink(inter,entry)=0ANDlink(b,entry)>0THENinsert(inter,entry)FI;PER;interEND OP/;TEXTROW OP*(TEXTROW CONSTa,b):TEXTROW VARsdiff:=emptytextrow;TEXT VARentry;INT VARindex;FORindexFROM1UPTOhighestentry(a)REPentry:=name(a,index);IFlink(sdiff,entry)=0ANDlink(b,entry)=0THENinsert(sdiff,entry)FI;PER;FORindexFROM1UPTOhighestentry(b)REPentry:=name(b,index);IFlink(sdiff,entry)=0ANDlink(a,entry)=0THENinsert(sdiff,entry)FI;PER;sdiffEND OP*;BOOL OP<(TEXTROW CONSTa,b):a<=bAND NOT(b<=a)END OP<;BOOL OP<>(TEXTROW CONSTa,b):NOT(a=b)END OP<>;BOOL OP>(TEXTROW CONSTa,b):b<aEND OP>;BOOL OP<=(TEXTROW CONSTa,b):TEXT VARentry;INT VARindex;FORindexFROM1UPTOhighestentry(a)REPentry:=name(a,index);IFlink(b,entry)=0THEN LEAVE<=WITH FALSE FI;PER;TRUE END OP<=;BOOL OP=(TEXTROW CONSTa,b):a<=bANDb<=aEND OP=;BOOL OP>=(TEXTROW CONSTa,b):b<=aEND OP>=;TEXTROW PROCtextrow(THESAURUS CONSTdir):TEXTROW VARres:=emptytextrow;INT VARindex;FORindexFROM1UPTOhighestentry(dir)REPinsert(res,name(dir,index));PER;resEND PROCtextrow;THESAURUS PROCthesaurus(TEXTROW CONSTdir):THESAURUS VARres:=emptythesaurus;INT VARindex;FORindexFROM1UPTOhighestentry(dir)REPinsert(res,name(dir,index));PER;resEND PROCthesaurus;OP FILLBY(FILE VARf,TEXTROW CONSTdir):INT VARindex;output(f);FORindexFROM1UPTOhighestentry(dir)REPputline(f,name(dir,index))PER;END OP FILLBY;OP FILLBY(TEXTROW VARdir,FILE VARf):TEXT VARentry;input(f);WHILE NOTeof(f)REPgetline(f,entry);insert(dir,entry)PER;END OP FILLBY;END PACKETtextrow;
|