TSE: Sort

28 views
Skip to first unread message

knud van eeden

unread,
Mar 24, 2026, 11:14:50 AM (9 days ago) Mar 24
to SemWare TSE Pro Text Editor, S.E. Mitchell
Hello,

Question: 

1. How to do a NUMERICAL sort?

E.g. One wants to numerically sort

21
2
1115
1
123

to

1
2
21
123
1115

2. How to do a combinations,  of a UNIQUE which uses ExecMacro( "sort -k" ) and a NUMERICAL sort (which uses _DECIMAL_)?

Would that mean doing e.g. 2 different sorts after each other (first sort the block numerical, and then sort the block sort unique)?

Note:

3. The documentation in TSE SAL about Sort() is not complete, e.g. _DECIMAL_ is missing.

===

Ad 1: NUMERICAL SORT

1. Tested in TSE for Microsoft Windows version 4.50 RC24 and latest version 4.50.20.

2. I am not sure if this _DECIMAL_ parameter is working as it should.

3. How to do a numerical sort, e.g.

4. TSE SAL program:

PROC Main()
 Sort( _DECIMAL_ ) // sort numerical and ascending
END

5. Before sort:

23
2
15
1
6

6. After sort: RESULT (not sure about why this result):

1
15
2
23
6

7. But: Instead after sort EXPECTED (that is the order is in increasing *numerical* value, like when using TSE SAL VAL():

1
2
6
15
23

===

Ad 2: TESTING DIFFERENT TSE SORT() OPTIONS:

1. Using this given test block to sort:

 // 3
 // 5a
 // z
 // c
 // C
 // b
 // 10
 // 6
 // ABC
 // ab
 // 6
 // W
 // a
 // 6
 // 0006
 // 6
 // 100
 // 100
 // 100
 // 2
 // 1

2. See also attached file:
tsesaltestsortoptions.s
Download the latest version here:
or here (click in the right top on the download button)

3. This is that program:

PROC Main()
 //
 // given fixed test block to sort
 //
 // 3
 // 5a
 // z
 // c
 // C
 // b
 // 10
 // 6
 // ABC
 // ab
 // 6
 // W
 // a
 // 6
 // 0006
 // 6
 // 100
 // 100
 // 100
 // 2
 // 1
 //
 Sort() // sort lexicographical (alphabetical / not-numeric / in ASCII order) and ascending and case-sensitive
 //
 // 0006
 // 1
 // 10
 // 100
 // 100
 // 100
 // 2
 // 3
 // 5a
 // 6
 // 6
 // 6
 // 6
 // ABC
 // C
 // W
 // a
 // ab
 // b
 // c
 // z
 //
 // Sort( _IGNORE_CASE_ ) // sort lexicographical (alphabetical / not-numeric / in ASCII order) and ascending and case-insensitive
 //
 // 0006
 // 1
 // 10
 // 100
 // 100
 // 100
 // 2
 // 3
 // 5a
 // 6
 // 6
 // 6
 // 6
 // a
 // ab
 // ABC
 // b
 // c
 // C
 // W
 // z
 //
 // Sort( _DESCENDING_ ) // sort lexicographical (alphabetical / not-numeric / in ASCII order) and descending and case-sensitive
 //
 // z
 // c
 // b
 // ab
 // a
 // W
 // C
 // ABC
 // 6
 // 6
 // 6
 // 6
 // 5a
 // 3
 // 2
 // 100
 // 100
 // 100
 // 10
 // 1
 // 0006
 //
 // Sort( _DESCENDING_ | _IGNORE_CASE_ ) // sort lexicographical (alphabetical / not-numeric / in ASCII order) and descending and case-insensitive
 //
 // z
 // W
 // c
 // C
 // b
 // ABC
 // ab
 // a
 // 6
 // 6
 // 6
 // 6
 // 5a
 // 3
 // 2
 // 100
 // 100
 // 100
 // 10
 // 1
 // 0006
 //
 // Sort( _DECIMAL_ ) // sort numerical and ascending
 //
 // 3
 // z
 // c
 // C
 // b
 // 6
 // 6
 // W
 // a
 // 6
 // 6
 // 2
 // 1
 // 5a
 // 10
 // ab
 // ABC
 // 100
 // 100
 // 100
 // 0006
 //
 // Sort( _DECIMAL_ | _DESCENDING_ ) // sort numerical and descending
 //
 // 0006
 // ABC
 // 100
 // 100
 // 100
 // 5a
 // 10
 // ab
 // 3
 // z
 // c
 // C
 // b
 // 6
 // 6
 // W
 // a
 // 6
 // 6
 // 2
 // 1
 //
 // ExecMacro( "sort -k" ) // sort unique (=remove any sorted duplicates)
 //
 // 0006
 // 1
 // 10
 // 100
 // 2
 // 3
 // 5a
 // 6
 // ABC
 // C
 // W
 // a
 // ab
 // b
 // c
 // z
 //
 // ExecMacro( "sort -k _DECIMAL_" ) // sort unique (=remove any sorted duplicates) and numerical and ascending
 //
 // 0006
 // 1
 // 10
 // 100
 // 2
 // 3
 // 5a
 // 6
 // ABC
 // C
 // W
 // a
 // ab
 // b
 // c
 // z
 //
 // ExecMacro( "sort -k _DECIMAL_ | _DESCENDING_" ) // sort unique (=remove any sorted duplicates) and numerical and descending
 //
 // 0006
 // 1
 // 10
 // 100
 // 2
 // 3
 // 5a
 // 6
 // ABC
 // C
 // W
 // a
 // ab
 // b
 // c
 // z
 //
END



with friendly greetings
Knud van Eeden


Inline image


Inline image
Inline image

tsesaltestsortoptions.s

knud van eeden

unread,
Mar 24, 2026, 12:58:01 PM (9 days ago) Mar 24
to SemWare TSE Pro Text Editor, S.E. Mitchell
FYI: Some additional documentation from the file sort.s in the \MAC directory of TSE for Microsoft Windows version 4.50.20:

  DOCUMENTATION

  This tool sorts those lines in the current buffer that overlap with a marked
  block.

  If the block is a column block, then the column is the sort key, otherwise
  the whole line is the sort key.

  Column sorts are stable, meaning that for lines with the same sort key their
  relative positions remain the same.
  This allows us to sort on multiple columns, one at a time.

  This tool can be called manually from TSE's Macro Execute menu with
    sort [option] ...
  or from a macro with
    ExecMacro("sort [option] ...")

  Options:
    -i          Ignore case. A letter being upper or lower case sorts the same.
    -d          Descending. Sort on the sort key in reverse order.
    -k          Kill duplicates. Remove duplicate lines after sorting.

    --internal  Requires the sort tool to use TSE's internal Sort() command.
    --external  requires the sort tool to use TSE's external tsort.exe tool.

  Options are case-insensitive.

  The "--internal" and "--external" options are for testing the sort tool.
  They should not be used for regular use.

  Example:
    sort -i -k  Sort the marked lines, ignoring case and removing duplicates.



--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/semware/685479983.2328922.1774365285681%40mail.yahoo.com.

knud van eeden

unread,
Mar 24, 2026, 2:06:15 PM (9 days ago) Mar 24
to SemWare TSE Pro Text Editor, S.E. Mitchell
And I assume this assumption is correct?

Internal sort: The TSE SAL command keyword 'Sort()' is thus the so called 'internal' sort.

External sort: The TSE SAL macro f:\wordproc\tse_beta\mac\sort.s is thus the so called 'external' sort.

knud van eeden

unread,
Mar 24, 2026, 4:07:59 PM (9 days ago) Mar 24
to SemWare TSE Pro Text Editor, S.E. Mitchell
> --external  requires the sort tool to use TSE's external tsort.exe tool.

I see..., there are thus 3 different sort methods:

(I searched earlier for sort.exe, not for tsort.exe)

 1. Internal sort: that is TSE Sort() keyword

 2. External sort: that is tsort.exe (earlier it was a long time tsort.com instead) located in the TSE directory

 3. TSE external macro 'sort.s', located in the TSE \MAC subdirectory.


knud van eeden

unread,
Mar 24, 2026, 4:42:25 PM (9 days ago) Mar 24
to SemWare TSE Pro Text Editor, S.E. Mitchell
FYI: Regarding the documentation for the external 'tsort.exe':

f:\wordproc\tse_beta Tue  3/24/26 21:38:35>tsort.exe

tsort v1.45 [08 Dec 2025] Windows MingW32

total: 32,560 mb largest: 1,048,576,000 total alloc: 2,097,152,000 divider: 1

tsort fn1 fn2 -q -a -r -+99:99

where
   -q  quiet
   -a  ascii or case-sensitive sort
   -r  reverse or decending sort
   -efilename - specify and error output file
   -+nn:xx use column nn as start of key
       for a length of xx

nn defaults to 1 and xx defaults to 16000


zhong zhao

unread,
Mar 24, 2026, 9:09:58 PM (9 days ago) Mar 24
to SemWare TSE Pro text editor
Intuitively, 0006 should be treated as 6 when setting the sorting by _DECIMAL_

knud van eeden

unread,
Mar 24, 2026, 9:28:05 PM (9 days ago) Mar 24
to SemWare TSE Pro text editor, S.E. Mitchell
Yes,

Given:

21
2
1115
1
123

I did the sort with Cygwin sort:

g:\cygwin\bin Wed  3/25/26  2:24:00>sort.exe --general-numeric-sort c:\temp\dddsort.txt

1
2
21
123
1115

and that is exactly what is expected.

So at this moment I am not sure exactly what this _DECIMAL_ option is exactly doing and giving as output:

Inline image



Guy Rouillier

unread,
Mar 25, 2026, 3:50:30 AM (9 days ago) Mar 25
to sem...@googlegroups.com
Huh, well, I got a result I wasn't anticipated.  In Linux, I put your 5 values into a text file sorttest.txt, then from a command prompt ran:

uyr@asus:~/bin/tse/mac$ tsort sorttest.txt
tsort: sorttest.txt: input contains an odd number of tokens

Since when does sorting dictate we need to supply only an even number of tokens?

This was such an unexpected result, I fired up my Windows 11 VM, and tried the same in Windows TSE tsort.exe.  It gladly sorted an input file.  Of course, the file was sorted alphabetically, with no apparent way to specify a decimal sort.

Both Windows and Linux TSE versions are 4.50.20.
--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/semware/685479983.2328922.1774365285681%40mail.yahoo.com.

-- 
Guy Rouillier

S.E. Mitchell

unread,
Mar 25, 2026, 6:48:10 AM (8 days ago) Mar 25
to sem...@googlegroups.com
Make sure you are getting the right tsort.
That message is not from TSE's tsort.
--

Guy Rouillier

unread,
Mar 26, 2026, 6:22:18 AM (7 days ago) Mar 26
to sem...@googlegroups.com
Hahaha! You're right.  I had put the TSE executable directory on my PATH, so I could execute it from anywhere.  I didn't expect that Linux had a tsort as well. :)

guyr@asus:~/bin/tse/mac$ which tsort
/usr/bin/tsort

When I provided an explicit path to TSE's tsort, I got the expected result.
-- 
Guy Rouillier

knud van eeden

unread,
Mar 26, 2026, 9:15:25 AM (7 days ago) Mar 26
to sem...@googlegroups.com
tsort (topological sort) is a command-line utility in Linux and Unix-like operating systems that performs a topological sort on a given set of data. It takes an unordered list of ordered pairs (representing dependencies) and produces a linear ordering that respects those dependencies.

e.g. a file containing two lines 

a b
b c

outputs 

a b c


Thus the equivalent of

a -> b
b -> c

gives 

a -> b -> c

(for '->' read 'follows')

See also Google: 'what is tsort in Linux' for more information. 

with friendly greetings 
Knud van Eeden 

Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

knud van eeden

unread,
Mar 26, 2026, 10:39:08 AM (7 days ago) Mar 26
to sem...@googlegroups.com
FYIO:

Linux tsort "input contains an odd number of tokens"
This error means tsort expects input as pairs of tokens (one pair per line), but you have given it a line with only one token (or some other odd count.


g:\cygwin\bin Thu  3/26/26 15:36:46>echo "a b c" | tsort.exe
/usr/bin/tsort: -: input contains an odd number of tokens

g:\cygwin\bin Thu  3/26/26 15:36:52>echo "a" | tsort.exe
/usr/bin/tsort: -: input contains an odd number of tokens

g:\cygwin\bin Thu  3/26/26 15:36:59>echo "" | tsort.exe
/usr/bin/tsort: -: input contains an odd number of tokens

g:\cygwin\bin Thu  3/26/26 15:37:04>echo "a b" | tsort.exe
"a
b"

g:\cygwin\bin Thu  3/26/26 15:37:12>


Reply all
Reply to author
Forward
0 new messages