Hi Jack: ( no pun intended - also, not funny at the airport )
JS>About the most useful sort routine for me is a UNIQUE sort that removes
JS>duplicate lines, and for some reason, only the UNIX ports of sort routines
se
JS>to have that function.
Your message has bothered me a bit since I first read it. The UNIQUE
function (in my empirical experience) seems to have emanated from the
mainframe & early minicomputer days when sorting algorithms used
multiple sequential media (ie, tapes, sequential record disk data sets,
or [hold on here ] _cards_). During this era, sort packages normally
had MERGE routines -- since merging was an integral part of a multidevice
sequential sort. But I digress.
Adding this sort of functionality is one of the great strengths of TSE.
// NoDups.S Remove duplicate lines from the current buffer
---------------------------------------------------------------------
proc main()
string lastLine[255], thisline[255]
integer killstate = set(killmax,0) // don't worry about delete buffer
begfile()
lastline = GetText(1,255)
down()
repeat
thisline = GetText(1,255)
if ThisLine == LastLine // if first 255 chars of this line
DelLine() // and prev line are same, kill it
else
LastLine = ThisLine
Down()
endif
until CurrLine() == NumLines()
set(killmax,killstate) // back the way we found it.
end
This can be executed manually (CTRL-X), added to the POTPOURRI or
attached to your user interface (\tsepro\ui\tse.ui):
ExecMacro('NoDups')
NOTE: At first I tried this with the sort build into it through an
EXECMACRO('sort') call. Two problems with this: If the sort
fails, you DON'T want to execute the NoDups function, as it
will wax your file: The sort could fail, for example because
you forgot to block a key area for it to use -- or other reasons.
Second, integrating the access to the sort flags would require
more extensive tinkering with the TSE.UI to provide seemless
behavior with case and sort-order options.
There are a lot of ways to enhance/extend this, eg., delete based on
duplicate keys, delete based on duplication from the cursor column
position, etc.
Have fun.
Mike.
---
þ SLMR 2.1a þ TSEPro 2.5: Text Editor of Champions
--- FidoPCB v1.4 [ff151/a]
---------------
* Origin: SemWare Support BBS * 404-641-8968 * (1:133/314)
|