News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_FloppySoftware

SamaruX - Unix-like shell for CP/M

Started by FloppySoftware, 00:24, 24 February 15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

FloppySoftware

Hello!

I'm proud of announce the release of SamaruX v1.00, my Unix-like Shell Project for CP/M.
Also, it's ready a new release of MESCC (v1.03), my Small-C compiler version.
They can be download from my website.
Suggestions, comments, etc. are welcome!
--
SamaruX
(c) Miguel I. Garcia Lopez / FloppySoftware
FloppySoftware
cpm-connections.blogspot.com
floppysoftware@gmail.com
Overview
SamaruX is a Unix-like shell for the CP/M operating system & the Z80 CPU.
It has been developed with MESCC, my Small-C compiler version for CP/M and Z80.
Instead of write separate commands for each task as in real Unix, the shell has some built-in commands.
Of course, it's not at all a new idea (see BusyBox, for example), but I believe this scheme has a lot of advantages in a small environment like CP/M.
For example, we can save some bytes on disk by joining some commands in one file, instead of writing them as separated ones, because we don't have to repeat some shared code in each of them.
Obviously, SamaruX doesn't have all functionalities of Unix, but it has some nice and useful commands, to work in a Unix-like system, under our beloved CP/M operating system.
Some SamaruX functionalities are:
-Redirection of stdin and stdout with > and <.
-Piping with |.
-Environment with variables $TERM, $USER, etc.
-Command line history.
-Profiling for environment customization.
-Command aliasing.
-Batch processing with flow control and arguments passing.
-Complete on-line manual.
-Prompt customization.
-Built-in commands: cp, rm, mv, man, cat, more, grep ...
This document is not an exhaustive reference of SamaruX, but only an overview, in order to show some of its capabilities.
Please, refer to the manual for a complete description.
Execution modes
There are two execution modes:
-CP/M mode: The SamaruX shell will execute only a command and will return to CP/M.
-Interactive mode: The SamaruX shell will read and execute your commands from the keyboard, until you return to CP/M.
CP/M mode example:
A>sx echo Hello world!
Hello world!
A>

Interactive mode example:
A>sx
Samarux v1.00 / 29 Dec 2014 - (c) FloppySoftware, Spain
CP/M version 2.2
28 built-in commands
Hi FloppySoftware welcome to Samarux!
[FloppySoftware at B00:] $ env
TERM = vt52
USER = FloppySoftware
PROMPT = [%u at %w] %$
[FloppySoftware at B00:] $ exit
A>

Profiling
With profiling, you can customize your SamaruX environment.
Its use it's not compulsory, but highly recommended (and useful).
There are two files for profiling::
-profile.sx: For the CP/M mode.
-profcpm.sx: For the interactive mode.
An example of profiling in interactive mode:
# -------------------------- #
# SAMARUX START-UP PROFILE   #
# -------------------------- #
env TERM vt52
env USER FloppySoftware
env PROMPT [%u at %w] %$
#
alias h history 0
alias logout exit
#
echo Hi $USER welcome to Samarux!
echo

Piping and redirection
With SamaruX, you can enter useful command lines like:
-cat letter.txt | more
-grep 'Gary Kildall' cpm.txt article.doc news.txt > refs.txt
-ls -l *.h *.c > cfiles.txt
-man cat | more
Command line
You can separate commands in the same line with the semicolon ( ;) :
man cp > cp.txt ; clear ; cat cp.txt | more 
You can include environment variables in your command lines:
env NAME Julius ; echo My name is $NAME 
An argument can contain spaces if it is surrounded by single quotes ('):
env NAME 'Julius Smith' ; echo My name is $NAME 
SamaruX has a command line history facility.
To see the history, just type:
history 
And the history command will reply something like:
[FloppySoftware at B00:] $ history
0: cat manual.doc | more
1: ed letter.txt
2: ls *.c
3: man cat

To select a history command entry, just type its number:
history 2 
And the shell will present a command line, ready to be edited and / or executed:
[FloppySoftware at B00:] $ ls *.c 
Executing CP/M commands
You can execute CP/M commands by using the cpm command:
cpm PIP A:=M:*.COM 
You will return to SamaruX, once the CP/M command had finished its work.
Aliases
You can make aliases for your most frequently used commands:
alias dirall ls -f 
Then, you can enter the defined alias as a single word:
dirall 
Small text editor
SamaruX has the ed command, a very humble text editor, but very useful to create and edit small text files in a fast way.

[FloppySoftware at B00:] $ ed profile.sx
File :  profile.sx
Lines:  14/48
ed> print
    0: # -------------------------- #
    1: # SAMARUX START-UP PROFILE   #
    2: # -------------------------- #
    3: # env HOME A00:
    4: env TERM vt52
    5: # env TEMP M00:
    6: env USER FloppySoftware
    7: env PROMPT [%u at %w] %$
    8: #
    9: alias h history 0
   10: alias logout exit
   11: #
   12: echo Hi $USER welcome to Samarux!
   13: echo
ed> edit 8
    8: # This is a comment

Help!
SamaruX has a built-in command named man, to offer on-line help about commands an other topics.
The help contents is stored in the man.sx file.
As this file is an ordinary text file with a simple structure, you can even add or modify topics.
To see the available topics, just type:
man | more 
To read about a topic in particular, say cat, just type:
man cat | more 
In addition to this, SamaruX has a built-in command named builtin, that prints the name of all available built-in commands. Just type:
builtin 
Batch processing and flow control
With the batch command, you can process files with commands as if they were typed on the keyboard.
Some other SamaruX commands will help you with flow control in batch processing:
-if
-goto
-read
-exit
An example:
# ----------- #
# TEST SCRIPT #
# ----------- #
#
echo Test Script
echo ===========
# Menu:
echo
echo 1 : Option One
echo 2 : Option Two
echo 0 : Exit
echo
echo -n Your choice:
read OP
echo
if $OP eq 1 goto One
if $OP eq 2 goto Two
if $OP eq 0 goto Exit
echo Bad choice, try again.
goto Menu
# One:
echo Your choice was Option One.
goto Menu
# Two:
echo Your choice was Option Two.
goto Menu
# Exit:
env OP

You can include arguments in batch processing.
If you have a file named write.sx with this contents:
echo $1 $2 $3

And you type:
batch write.sx How are you? 
The system will reply with:
How are you? 

License
Copyright (c) Miguel I. Garcia Lopez / FloppySoftware, Spain
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

--






floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

Munchausen

#1
This looks great  ;D ! Can you run CP/M software from SamaruX?

EDIT: I see that it can... what's the $$$.SUB trick?!

Munchausen

Also, I guess this should work fine on the CPC under CP/M?

I'm also very interested in MESCC... again does it work for CPC? And what features does it have vs normal C? I ask because the "standard" small C only implements a relatively small part of the C standard (no structs, no floats, no unsigned types, no for loops, no goto, no switch statements, etc), is K&R rather than ANSI, and doesn't do any optimisation. I'm also wondering what optimisations you do?

Awesome stuff :)

FloppySoftware

Quote from: Munchausen on 02:02, 24 February 15
This looks great  ;D ! Can you run CP/M software from SamaruX?

EDIT: I see that it can... what's the $$$.SUB trick?!
Under CP/M 2, to chain from a program to another, we can use the $$$.SUB feature of the CCP.
As far as I know, SUBMIT uses that procedure.
In fact, in a $$$.SUB file we can write more than one command, one 128 byte record for each one in reverse order.
Some CP/M MENU programs use that.
Under CP/M 3, this feature is supported for compatibility, but there is a "new" BDOS function (CHAIN TO PROGRAM) to perform that without tricks.
SUBMIT for CP/M 3 uses a RSX, not the $$$.SUB feature.
In SamaruX I used the $$$.SUB file method for compatibility.
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

FloppySoftware

Quote from: Munchausen on 02:17, 24 February 15
Also, I guess this should work fine on the CPC under CP/M?

I'm also very interested in MESCC... again does it work for CPC? And what features does it have vs normal C? I ask because the "standard" small C only implements a relatively small part of the C standard (no structs, no floats, no unsigned types, no for loops, no goto, no switch statements, etc), is K&R rather than ANSI, and doesn't do any optimisation. I'm also wondering what optimisations you do?

Awesome stuff :)
Yes, it would run perfectly in a CPC under CP/M 2 or 3.  8)
In fact, this should run in any CP/M computer with a Z80 cpu.
Regarding MESCC, it's a Small C derived version that supports for, switch, unsigned types, a better CPP, etc.
But sorry, no floats or structs, no ANSI.  :'(
It's a CP/M compiler and should run in any CP/M computer with a Z80 cpu, but the generated assembler code it's not CP/M dependant by itself.
It's has good libraries with optional support for stdin, stdout, stderr and redirection in the command line.
The priority to generate assembler code is small size, not speed (but don't expect 100% optimized assembler code!).  ;)
I use it for nearly all my projects for CP/M and/or the PCW.
Why?
Well, it has limitations, of course, but I understand the source code and I can mantain it an modify it if something goes wrong.  :-\
And as far as i know, is very stable. That's very important to me, because I prefer to search bugs in my programs, not in the compiler!  :laugh:


floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

TFM

Quote from: FloppySoftware on 00:24, 24 February 15
Hello!

I'm proud of announce the release of SamaruX v1.00


I wonder if you ever worked with Z3Plus for CP/M. If yes, does it work with SamaruX?

TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

FloppySoftware

Quote from: TFM on 19:49, 24 February 15

I wonder if you ever worked with Z3Plus for CP/M. If yes, does it work with SamaruX?
SamaruX is an standard CP/M program.
If Z3Plus accepts standard CP/M programs, the reply would be YES.
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

TFM

Get information about Z3Plus, you will not regret it! It replaces the CCP and BDOS for CP/M Plus. Has terminal descriptors and and and... so similar to SamuraX. It was commercial back the day. Wordstar 4 supported it. The cp-m 2.2 version was called nzcom. I don't want to derail the thread, but I think that SamuraX and Z3Plus would be a great team.

TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

FloppySoftware

New available version!
SamaruX v1.02, 27 Feb 2015
--------------------------

Last changes.

New control characters for command line edition:
------------------------------------------------

To delete the entire line:
     CTRL-U (0x15)
     CTRL-X (0x18)

To retype the line:
     CTRL-R (0x12)

New environment variables:
--------------------------

- LINES   : Number of console lines
- COLUMNS : Number of console columns
- TMPDIR  : Temporary directory (used by pipes)

The use of these environment variables is optional.
When a builtin command asks for a system variable,
the procedure is as follows:

- If the corresponding environment variable exists and
  has a legal value, use it.

- Under CP/M 3, use the value from the SCB.
- Otherwise, use the default values (for the console dimensions,
  the values #defined in the source code; for the temporary
  drive, the current drive).

floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

Prodatron

#9
Wow that's very impressive!!
Did you implement Piping with temporary files?
Have to try it out soon. What kind of search strings does Grep accept?

CU,
Prodatron

*EDIT* Sorry, I already got the answers from the package, really cool!

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

FloppySoftware

Quote from: Prodatron on 22:24, 27 February 15
Sorry, I already got the answers from the package, really cool!

Yeah! The man command is useful, isn't it?  ;)
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

FloppySoftware

Hi all!
New versión available!

SamaruX v2.00, 09 Apr 2015
--------------------------

Last changes.

Added support for SamaruX external commands:
--------------------------------------------

As an example, the game robots has been included.

New built-in commands:
----------------------

date  : Print and set the system date and time (only CP/M 3).
mem   : Show memory usage.
sort  : Sort text lines.
wc    : Count text lines, words and characters.
tee   : Copy standard input to standard output and to a file.


Improved commands:
-----------------

batch : Default file type for batch files - ".sx".
cat   : Added -k and -n options.
cd    : Added support for $HOME.
cpm   : Under CP/M 3, it uses the BDOS fn. CHAIN TO PROGRAM.
ed    : Added COPY and PASTE commands.
env   : Added -s option.
if    : Added in_env test for environment variables.
man   : Added support for $MANPATH and external manuals.
        Default file type for manual files - ".man".


New environment variables:
--------------------------

- HOME    : Default user directory.
- BINDIR  : Directory for SamaruX external commands.
- MANPATH : Path for manuals.


FloppySoftware
CP/M CONNECTIONS

floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

Munchausen

Nice to see that you're continually improving this! Will we soon get sed, &, fg, bg and grep?! :D

Prodatron


GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

Munchausen

Quote from: Prodatron on 13:41, 13 April 15
GREP is already included :)

Aha, great :D I wonder how much reg ex it supports?

BTW prodatron, I was thinking last night that it would be so nice if there was a bash like shell for symbos... as well as utilities like sed, grep etc. Then I started thinking about how great it would be if there was a native assembler, C compiler, flex, bison etc etc, I got a little carried away! But still a unix shell would be cool.

(I'd also like to see the source of the "SymbosMake" utility from the symbos C bindings so that C bindings can be used on linux. The same author has an assembler and basic for symbos that are unreleased).

Prodatron

Quote from: Munchausen on 14:03, 13 April 15
BTW prodatron, I was thinking last night that it would be so nice if there was a bash like shell for symbos... as well as utilities like sed, grep etc. Then I started thinking about how great it would be if there was a native assembler, C compiler, flex, bison etc etc, I got a little carried away! But still a unix shell would be cool.

(I'd also like to see the source of the "SymbosMake" utility from the symbos C bindings so that C bindings can be used on linux. The same author has an assembler and basic for symbos that are unreleased).
For not going Offtopic, let's continue this here:
SymShell 2.0 beta [SymbOS command line interface] released

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

FloppySoftware

Hi all!

I've just uploaded to my website a new release of SamaruX (v2.02 / 22 Ago 2015):

       
  • Enhanced support of SamaruX external commands.
  • New examples of SamaruX external commands: banner, cal, head, whoami, strings.
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

Prodatron

Cool new external commands, it's always fun to play around with "banner" etc :)

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

FloppySoftware

New in v2.03 / 03 Sep 2015:
 
- New built-in command: diralias.

SamaruX has now support for named directories

With the use of diralias, you can reference a directory (a drive and user specification) with a name. IE:
 
diralias system a0:
diralias temp m0:
diralias mescc a3:

cat mescc:sx.c | more
ls system:*.x
cd temp:


 
It's a good idea to include the diralias commands in the SamaruX profile.
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

TFM

Hi! Are the named directories compatible to the Z system?
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

FloppySoftware

Quote from: TFM on 16:50, 04 September 15
Hi! Are the named directories compatible to the Z system?
No.

The directory names (or alias) are managed in a different way.

They are not saved in any place.

That's the reason why I suggest to include them in the profile that runs on start-up of SamaruX.
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

TFM

TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

FloppySoftware

New in v2.05 / 06 Jun 2016                   

       
  • New built-in commands: false, head, tail, true, tty, whoami.
Some built-in commands can be compiled as external ones.

Compile SamaruX with SX_MINIMAL for a minimal number of built-in commands. Then execute make_all_ext2 to build the excluded built-in commands as external.

You can download sources and binaries (compiled as SX_MINIMAL) from my github account:

GitHub - MiguelVis/RetroProjects: My retro programming projects for some
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

litwr

#23
MSX-DOS may use redirections and DOS like pipes since 80s.  CP/M+  also has redirections but misses pipes.  I've just tried Samarux.  It works!  :) However I have to note the several quirks.  The first minor problem is the names.  Unix uses 'od' instead of 'dump'.  Linux uses 'free' instead of 'mem'. There is no Unix shell with 'goto'.  The other minor problem is the parser.  It is a bit different from Unix.  For example, echo hello >file.txt requires space around > in Samarux but in Unix shell >-sign is special.  The third problem is builtin command set.  It has no ls, cat, ...  Another problem is clear command. However the project is great!  :) It is sad that Digital Research did almost nothing since 1983 for CP/M. :( BTW MSX-DOS and Unix supports >> redirections.  ;)
I've just note yet another difference from Unix.  The command `echo *` works similar to `ls' with Unix.

FloppySoftware

Quote from: litwr on 06:39, 02 November 16
MSX-DOS may use redirections and DOS like pipes since 80s.  CP/M+  also has redirections but misses pipes.  I've just tried Samarux.  It works!

Oh, yes, I hope it works! :)
Ah, ok, you mean it works under MSX-DOS... if that's the case, it's normal: MS copied the CP/M BDOS interface for their MS-DOS, and MSX-DOS is the MS-DOS version for MSX / Z80 computers (as you already know). :)

Quote from: litwr
However I have to note the several quirks.  The first minor problem is the names.  Unix uses 'od' instead of 'dump'.  Linux uses 'free' instead of 'mem'.

If you prefer the Unix names, just use the command alias:

alias od dump

Alias for free / mem is already in the profile.sx file that is loaded on each Samarux start-up (include your own aliases there).

Quote from: litwr
There is no Unix shell with 'goto'.
Yes, this is my little contribution to the Unix world. :)

Quote from: litwr
The other minor problem is the parser.  It is a bit different from Unix.  For example, echo hello >file.txt requires space around > in Samarux but in Unix shell >-sign is special.
You are right. Maybe it would not be too dificult to support both syntax.

Quote from: litwr
The third problem is builtin command set.  It has no ls, cat, ...
Right now, they are included as external commands, but it's very easy to include them as internal (builtin) ones.
One fast method is to compile Samarux with SX_MINIMAL undefined. Another way is just to get out these commands of the corresponding #ifndef SX_MINIMAL in the source code.

Quote from: litwr
Another problem is clear command.
Clear knows three tty types currently:
- vt52
- vt100 or ansi
- ascii
But it's extremely easy to add more.
Anyway, as far as I know, MSX systems use a VT52 like terminal emulation (as Amstrad CPC / PCW do). If that's the case, just include this line in your profile.sx file:

env TERM vt52

Quote from: litwr
I've just note yet another difference from Unix.  The command `echo *` works similar to `ls' with Unix.
SamaruX does not support file name expansion... yet!

Thanks for trying SamaruX!
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

Powered by SMFPacks Menu Editor Mod