TSE: Linux: How to convert TSE for Microsoft Windows grep.s to run on Linux?

12 views
Skip to first unread message

knud van eeden

unread,
Sep 4, 2025, 2:36:49 PMSep 4
to SemWare TSE Pro Text Editor
TSE: Linux: How to convert TSE for Microsoft Windows grep.s to run on Linux?

Hello,

a. Maybe Semware could consider adding this grep.s to one of the next TSE for Microsoft Windows and TSE for Linux distributions.

b. See the attached grep.s (which should work on both Microsoft Windows and Linux (WSL) (Ubuntu)).

c. Tested successfully with:

TSE for Linux version 4.50.8
grep for Linux version 211
Linux WSL (Ubuntu) 2.0

d. to run it 

1. You will have to inform once where your grep version 211 or higher is located on your disk. 
   Do this once in the top of the program, save and recompile

(Note: I changed also before all this the Linux filename 'grep' to 'greplinux' to distinguish the grep versions between the
one for Microsoft Windows and the one for Linux)

---

#IFDEF LINUX
string grepLinuxPathS[255] = "/mnt/c/temp/tse_linux/greplinux" // change this to the location of greplinux on your disk
#ENDIF

---

2. I changed the following:

In the original grep.s there was this line for Microsoft Windows only:

         ok = lDOS(tee32, format(grep;options;"-n";QuotePath(search);files;">";grep_fn),_DONT_PROMPT_|_TEE_OUTPUT_)

So I changed to (all 1 liners) to include also Linux:

        #IFDEF WIN32
         ok = lDOS(tee32, format(grep;options;"-n";QuotePath(search);files;">";grep_fn),_DONT_PROMPT_|_TEE_OUTPUT_)
        #ELSE
         #IFDEF LINUX
          ok = DOS(format( "/mnt/c/temp/tse_linux/greplinux", " ", options, " ", "-n" , " ", QuotePath(search), " ", files, " ", "|", " ", 'sed -r "s/\x1B\[[0-9;]*[A-Za-z]//g"', " ", ">", " ", grep_fn, " ", "&" ), DOS_SYNC_CALL_FLAGS )
          Warn( "<Press any key>" )
         #ENDIF
        #ENDIF

3. The output of greplinux and redirecting it '>' into a file was originally full of XTerminal escape codes.

4. So I had to convert this. The easiest was with some out of the box command present on (all) Linux distributions.

5. I tried it with 'sed'.

6. That worked OK.

7. I had to add a 'Press any key' Warn() box, without it one did not get a result. Not sure why, but OK it works.

8. So as the output file (=grep_fn) now was then in about plain ASCII so everything started to work as expected (it looks at this moment) 
and it behaved like TSE grep for Microsoft Windows.

1. Run the grep.s program (after changing the path to your TSE for Linux 'grep' file once and recompiling
and input your search string, the files in which to search (use the /mnt/c/ ... notation)
and the search options (e.g. -i = ignore case, -o shows only the filename, -s searches subdirectories,
-x searches with regular expressions, ...)
Then press <Enter>

Inline image

2. I had to add a Warn() box to interrupt otherwise nothing found.

Inline image


3. Before the output text that grep found and redirected using '>' into a file
was full of XTerminal escape codes.


Inline image

4. But after filtering out these escape codes (e.g. using 'sed'), and only after that
redirecting it to a file, you got about
plain ASCII text, which TSE could handle as usual.


Inline image

5. As usual you can open each of the found files by clicking on it
and inspecting it individually.

Inline image

6. For comparison purposes, if you run the same grep search on TSE for Microsoft 
Windows, then this is the result:

Inline image


with friendly greetings
Knud van Eeden


grep.s

knud van eeden

unread,
Sep 4, 2025, 3:01:28 PMSep 4
to SemWare TSE Pro Text Editor, S.E. Mitchell
1. In this latest grep.s version I have made it even simpler.

2. It now uses as usual

LoadDir() 

to locate where grep is.

3. So just unzip or copy your TSE grep into your tse directory from where
you start your TSE once
(that action is thus mandatory in this version of TSE for Linux to have it run).

4. Then run the grep.s program as usual (in Linux WSL).

5. Note: In the next version of TSE version 4.50.10 and or higher I 
assume that Semware will already add and place that TSE 'grep' file in the
'tse' directory, so also the previous step will not be necessary
at all anymore and you can run grep.s out of the box without further
manual actions or extra installations.
grep.s

knud van eeden

unread,
Sep 4, 2025, 3:21:32 PMSep 4
to SemWare TSE Pro Text Editor, S.E. Mitchell
OK, one more thing ;-)

In this latest grep.s version:

Changed the warning message to be more informative
(it reminds to use <CtrlAlt G> to see the grep
search result again, which should be very handy,
this in both TSE for Microsoft Windows and TSE for Linux (WSL))
grep.s

knud van eeden

unread,
Sep 4, 2025, 3:58:22 PMSep 4
to SemWare TSE Pro Text Editor, S.E. Mitchell
That latest grep.s version + grep 211 has been tested on 
Linux non-WSL Ubuntu and also works there.

Steps:

copy grep.s to Linux non-WSL
copy grep211.zip to Linux non-WSL (use the unzip command to unzip)
copy grep.s to the tse directory
copy the grep from grep211.zip into the tse directory
run TSE via ./e
load grep.s
compile grep.s
run grep.s
input the grep search information
press <Enter> to execute the grep search.

with friendly greetings
Knud van Eeden

Inline image

grep.s

S.E. Mitchell

unread,
Sep 4, 2025, 6:46:09 PMSep 4
to knud van eeden, SemWare TSE Pro Text Editor
Good job Knud!

I took a slightly different route, but they both end up working about the same.
--

knud van eeden

unread,
Sep 4, 2025, 6:54:16 PMSep 4
to sem...@googlegroups.com
1. So you also independently developed a working grep.s
for TSE for Linux already?

2. To be published in e.g. the next TSE for Linux?

Thanks

with friendly greetings
Knud van Eeden

--

---
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/CA%2BgEvkYd0mQJAUNW8R4WOipB0AyogLBSmq4VeJwWwWrw3DrL5A%40mail.gmail.com.

S.E. Mitchell

unread,
Sep 4, 2025, 7:02:02 PMSep 4
to sem...@googlegroups.com
Yep, I finished it yesterday evening around midnight.
5:30 am the next morning came too quickly! :)
Main difference is that I don't like the defines(1).  And I also piped through tee:
if WhichOS() == _LINUX_                                                                                            
    // Need to call grep through the shell for piping                                                              
    ok = DOS(grep + " " +  options + " -n " + QuotePath(search) + " " + files + " | tee " + grep_fn, _DONT_PROMPT_)
else                                                                                                                

    ok = lDOS(tee32, format(grep;options;"-n";QuotePath(search);files;">";grep_fn),_DONT_PROMPT_ | _TEE_OUTPUT_)    
endif            

And I'm not smart enough to use sed - it makes my head hurt :)
So I used this to clean up the escape sequences:
lReplace("\x1b\[\d\d?m", "", "xn")              

Anyway, we both had the same general idea!

(1) Before sending out the linux version, I compare all the .mac for linux with the .mac for Windows.  If defines are used, then they won't compare, and I have to do a little extra work.  Yes, I am _very_ lazy!
                                                                                     

knud van eeden

unread,
Sep 4, 2025, 7:25:34 PMSep 4
to sem...@googlegroups.com
Those #DEFINE are not relevant at all, I just copied that setup from runblsal.s (=load block of URLs), which I in turn copied from
Carlo Hogeveen's source code after searching how he circumvented that Dos() with parameters bug / issue.

The problem was/is thus that TSE for Linux Dos() with parameters does all kind of strange things, like hanging 
TSE, ... It should be checked, debugged.
So one must use workaround redirect '>' and null, dev, &1 &2 and '&' maybe (that last '&' seems to work, that has something to do with processes in Linux/Unix as far as I know, not sure).

So:

#DEFINE DOS_ASYNC_CALL_FLAGS _DONT_PROMPT_|_DONT_CLEAR_|_START_HIDDEN_|_RETURN_CODE_|_RUN_DETACHED_|_DONT_WAIT_
#DEFINE DOS_SYNC_CALL_FLAGS _DONT_PROMPT_|_DONT_CLEAR_|_START_HIDDEN_|_RETURN_CODE_

It can of course be completely removed and instead used directly as in plain TSE

_DONT_PROMPT_|_DONT_CLEAR_|_START_HIDDEN_|_RETURN_CODE_

===

And I'm not smart enough to use sed - it makes my head hurt :)
So I used this to clean up the escape sequences:
lReplace("\x1b\[\d\d?m", "", "xn")              

= Thank you ChatGPT ;-)

Wanting it to do as generic as possible, no installations,
no to compile extra programs, ...

So maybe there was a Linux/Unix command for that.

So it gave me a couple of options, like ' col -b ' but that 
did not work. 

That SED option worked great immediately.

That 'sed' is of course also just some regular expression engine,
so TSE can usually do quite often similar.

===

That 'tee' option I will investigate, maybe that is some interesting
option to resolve that TSE for Linux Dos() with parameters issue.

===

PS: I am probably even lazier, if I can automate it or outsource it in general, I probably will ;-)


knud van eeden

unread,
Sep 4, 2025, 7:35:14 PMSep 4
to sem...@googlegroups.com
> lReplace("\x1b\[\d\d?m", "", "xn")   


After some analyzing, this is of course the best option if it always works.

Because one does not need any external program, like SED,

one needs only TSE, so decreasing the dependence on what is available in the outside (Linux) world.



S.E. Mitchell

unread,
Sep 4, 2025, 7:46:33 PMSep 4
to sem...@googlegroups.com
I should have been clearer, re: the defines.
I don't mind defines at all.

#define foo 3 *2  
Is no problem at all.
But what causes problems for my comparisons is the:
#ifdef LINUX
#ifdef WIN32

Which causes code to be conditionally compiled, which makes the .mac files different, depending on which compiler they were compiled with.
So, I usually use "if WhichOS() == __LINUX__", which compiles to the same code, no matter what system it is compiled on.
Of course you can't use that all the time, there are some cases when you need to use the other.

So feel free to use defines all you like :)
--


Reply all
Reply to author
Forward
0 new messages