Thursday, August 2, 2018

Expanding the FreeDOS COMMAND.COM

The FreeDOS COMMAND.COM (also known as "FreeCOM") is a compatible equivalent to MS-DOS COMMAND.COM. FreeCOM doesn't do anything special; it just creates a command prompt that lets you run programs.

FreeCOM also supports the standard MS-DOS batch programming syntax. Any batch script that runs in MS-DOS should run in FreeCOM. And any batch script you write for FreeCOM will run in MS-DOS COMMAND.COM.

From a recent discussion on the email list, I'd like to suggest an extension to FreeCOM. Maybe this would be better implemented as part of a new alternative shell, but it would be really interesting to see it added as a feature to FreeCOM.

Here's my idea: create a BASIC-like programming language that also supports MS-DOS batch scripts.

DOS batch scripts are simple affairs. Really, the idea behind the MS-DOS batch was to "batch up" a bunch of simple commands. DOS batch programming supports minimal flow control. You can query the exit status (ERRORLEVEL) of the previous command, and you can jump around the script (GOTO) but DOS batch programming doesn't support much else.

I'd love to see an extension to DOS batch programming. Something like a BASIC interpreter would be interesting, if it executed commands in the PATH if the instruction wasn't a keyword.

I wonder if someone is interested in writing a BASIC-like "shell"? Something that uses a combination of BASIC and COMMAND.COM syntax would make the interpreter a "superset" of COMMAND.COM, and an interesting new alternative shell.

Some suggestions for how to extend BASIC and DOS batch programming include:

Variables


Variables can store either numerical or string data. Variable names can be of any reasonable length, and can be referenced in uppercase or lowercase.

Use SET to assign values to variables, and BASIC's LET to assign values based on arithmetic. LET becomes a superset of SET:
SET A=4
SET DIR=C:\FDOS\BIN

And surround a variable with % to reference its value:
SET A=4
LET A=%A%​ ​+​ ​1
ECHO %A%​

Possibly allow %% as a prefix to reference the value from a variable, interchangeably: (sloppy, but see later)
SET A=4
LET A=%%A + 1
ECHO %%A

Output


Use ECHO to display output instead of PRINT:
ECHO Hello world

Tests


Support the standard DOS batch programming tests, such as == to test equality, and NOT to negate a test. Add extra constructs to test inequality, greater-than and less-than. One possible solution is to support simple DOS batch programming IF constructs and use Unix-style brackets for the extra constructs:
IF ERRORLEVEL 0 ECHO Success
IF NOT ERRORLEVEL 0 ECHO Fail
IF EXIST FILE.TXT ECHO Exists

And:
IF %VALUE%==1 ECHO Equal
IF NOT %VALUE%==1 ECHO Not equal

And:
IF [ %VALUE% EQ 1 ] ECHO Equal
IF [ %VALUE% NE 1 ] ECHO Not equal
IF [ %VALUE% GT 1 ] ECHO Greater
IF [ %VALUE% GE 1 ] ECHO Greater or equal
IF [ %STR% LT "ABC" ] ECHO Less

Looping


The FOR statement would need to be extended as a for-next loop:
FOR N IN 1 TO 10
ECHO %N%
NEXT

Or as the traditional DOS for-do one-line shortcut:
FOR N IN 1 TO 10 DO ECHO %N%

And add a special IN (…) construct to create an iteration over a set:
FOR %%N IN (1 2 3 4 5 6 7 8 9 10) DO ECHO %%N
FOR %%FILE IN (*.TXT) DO ECHO %%F

​(If the language allows %A% and %%A then DOS batch programs would probably work seamlessly. But it's sloppy coding. Other ideas?)

Branching


Similar to both BASIC and DOS batch programming, GOTO could use : to mark labels:
SET N=1
:LOOP
ECHO %N%
LET N=%N% + 1
IF %N% LT 10 GOTO LOOP

Comments


And of course, comments remain the same from BASIC and DOS batch programming:
REM This is a comment

Execution


If you called the BASIC-like "shell" using a special parameter (like /P) then it would be nice for anything e​lse you specify that isn't recognized as a shell statement (assuming other syntax is correct) get treated like an external command. That would make this more like a shell:
IF EXIST FILE.TXT EDIT FILE.TXT

Also other internal constructs for CALL and ERRORLEVEL and SHIFT and PATH, but you get the idea.

If you can preserve COMMAND.COM syntax and add a BASIC-like programming language behind it, that would make this an interesting extended shell. Maybe an idea for an interested developer?
Note: Tom points out that Microsoft similarly extended the COMMAND.COM batch programming language when creating CMD.EXE. For example, for /L %%N in (1,1,10) do echo %%N (iterative loops) and SET /A A=%%A + 1 (arithmetic). So this hybrid BASIC-like batch programming language idea is not new.

5 comments:

  1. Would be a nice project, even thought more time consuming that it seems (IMHO).

    ReplyDelete
  2. How about recreating some of the core functionality found in 4dos. 4dos was even easier to use than basic and was built for enhancing the terminal. It's command-line editing was the most useful I've ever tried: even if you didn't type anything and simply pressed the [TAB] key, it would cycle through the filenames and directories.

    It also had lots of useful built-ins, color control for creating great looking menus and even ascii (and ansi-like) animations. Honestly think we should be looking at 4dos as a standard.

    ReplyDelete
  3. Maybe would be easier finding a new Revived 4DOS project mantainer.

    ReplyDelete
  4. A similar alternative shell like that would be great! I mention that here as "3DOS":
    https://freedos-project.blogspot.com/2018/01/a-new-alternative-shell.html

    Also, 4DOS is discussed here:
    http://wiki.freedos.org/wiki/index.php/4DOS

    ReplyDelete
    Replies
    1. You can refer here from an update on 4DOS license: https://www.4dos.info/sources.htm

      contrary to the above permission "to deal without restriction". When asked "what about MS-DOS, PC-DOS, DR DOS etcetera?", Rex Conn answered:

      I don't have any problems with people using it on those OS's (although

      I'd be surprised if there was a lot of MS-DOS or PC-DOS action left).

      That license was written by the FreeDOS people – it was probably worded

      that way because it's impossible to list every possible variation of the DOS OS's.


      So, if 4DOS is limited to any DOS flavour, it will be fine.

      Delete