From e3ea9032f6e3105d9c0a720db8bc413b4a3e016f Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 24 Feb 2013 13:34:10 +0100 Subject: moved QuickSort macros from symbols-extract script into own string.tes macro library * therefore for bootstrapping to work, the SCITECOPATH is always set explicitly --- lib/string.tes | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/string.tes (limited to 'lib/string.tes') diff --git a/lib/string.tes b/lib/string.tes new file mode 100644 index 0000000..274873b --- /dev/null +++ b/lib/string.tes @@ -0,0 +1,45 @@ +! String utility macros ! + +! M{symcasecmp} - Compare symbol at pos1 with symbol at pos2 (caseless) ! +@{symcasecmp}{ + U.2U.1 -.%.1 -.%.2 + @.#lo{ + U.v Q.v"W a-A%.v | Q.v"CQ.v|0' ' + } + + Q.c +} + +! M{exchange} - Exchange line at I with line at J (I < J), returning new J ! +@{exchange}{ + U.jU.i + Q.jJ X.xK + Q.iJ G.x .-Q.i%.j .-(X.xL.)%.j -K + Q.jJ G.x + Q.j +} + +! M{qsort} - Sort lines beginning at I until J using Quicksort algorithm ! +@{qsort}{ + U.rU.l + + Q.l-Q.r"< + Q.lU.i Q.rJB .U.j + + < + Q.iJ <.,Q.rM{symcasecmp}-1; .-Q.r; L> .U.i + Q.jJ <.,Q.rM{symcasecmp}:; .-Q.l-1:; B> .U.j + + Q.i-Q.j; + + Q.i,Q.jM{exchange}U.j + > + + Q.i,Q.rM{symcasecmp}"> Q.i,Q.rM{exchange}U.r ' + + Q.l-Q.i"< Q.iJB Q.l,.M{qsort} ' + Q.i-Q.r"< Q.iJL .,Q.rM{qsort} ' + ' +} -- cgit v1.2.3