I've been thinking of ways to get new developers interested in working on FreeDOS, or at least contributing to FreeDOS in some way. I recognize that DOS is an old concept for some, and as a result, the way you construct programs for DOS can differ to how you'd construct programs for other operating systems such as Linux.
Sure, programs like Choice and Type and Find and other everyday command-line utilities are pretty straightforward. You'd probably write a DOS Type command in the same way you'd write a Unix ‘cat’ command (using streams). But other programs require different methods.
So I thought some kind of “code review” would be helpful, as a way to demonstrate certain DOS programming methods. I'll plan to examine a FreeDOS program and pull apart a specific function or method or programming trick to show how you can use these methods in your own programs.
It will be easiest for me to do a code review on my own programs, and I may start there. But I will try to explore different FreeDOS programs written by different people, so you can see a variety of methods. Every programmer is different, and this will highlight different ways to implement features or optimize execution or minimize footprint when programming in DOS.
Do you have a program you'd like to highlight? I welcome any guest posts in this series. If you have something you'd like to show off, please email me or leave a comment below. I'd be happy to include your article as a guest post here. (If you submit a guest post, it will be easiest if you can share your contribution under the Creative Commons Sharealike [cc-by] public license.)
What programs or methods would you like to see? If you have a suggestion for a “deep dive” into a FreeDOS utility, let me know! My expertise is C, so I am more likely to do code reviews for programs written in C.
Tuesday, August 21, 2018
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 (
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:
As in current DOS batch, 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
And surround a variable with
Possibly allow (probably a special case here, for compatibility; see later)
Use DOS batch's
Support the standard DOS batch programming tests, such as
And:
And it makes sense that brackets can be used for equivalent standard evaluation too (for example,
The
Or as the traditional DOS for-do one-line shortcut:
And add a special
(If the language allows
Similar to both BASIC and DOS batch,
And of course, comments remain the same from BASIC and DOS batch programming:
If you called the BASIC-like "shell" using a special parameter (like
Also other internal constructs for
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?
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
As in current DOS batch, 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 that also supports arithmetic evaluation.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%
%% as a prefix to reference the value from a variable, interchangeably:SET A=4 LET A=%%A + 1 ECHO %%A
Output
Use DOS batch's
ECHO to display output instead of BASIC's 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 assume 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 it makes sense that brackets can be used for equivalent standard evaluation too (for example,
EQ for ==). I'm using Fortran-style comparison operators here:IF [ %VALUE% EQ 5 ] ECHO Equal IF [ %VALUE% NE 5 ] ECHO Not equal IF [ %VALUE% GT 5 ] ECHO Greater than IF [ %VALUE% GE 5 ] ECHO Greater or equal IF [ %VALUE% LT 5 ] ECHO Less than IF [ %VALUE% LE 5 ] ECHO Less or equal
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, same as DOS batch:FOR %%N IN (1 2 3 4 5 6 7 8 9 10) DO ECHO %%N FOR %%F IN (*.TXT) DO ECHO %%F
(If the language allows
%A% and %%A for single-letter variables, then DOS batch programs would probably work seamlessly. But it seems like sloppy coding here, because %% appears as a variable name and a variable reference in DOS batch programming. Maybe restrict %% to the special case of IN (…) and only single-letter variables, to keep DOS batch compatibility Other ideas?)Branching
Similar to both BASIC and DOS batch,
GOTO should continue to 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 else 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.
Subscribe to:
Posts (Atom)
About Me
- Jim Hall
- I'm Jim Hall, the founder and Project Coordinator for the FreeDOS Project. I started FreeDOS in 1994, when I was an undergraduate physics student at the University of Wisconsin-River Falls. Other developers got in touch with me, and we began work creating our own version of DOS that would be compatible with MS-DOS. I shared the extended DOS utilities that I had written for myself, as did others. We also found public domain or open source programs that replaced other DOS commands. A few months later, we released our first FreeDOS “Alpha” distribution. And from there, FreeDOS grew into what you see today!