On Tue, Jun 9, 2026 at 3:48 PM victoria crenshaw wrote:
>
[..]
>
> a note for Jerome:
> The error levels is what i am going to focus next but i need to be in a
> voice chat with you or someone and discuss the error levels for the program
>
> because i never actually implemented error levels in any program before.
> so this is exciting
>
> i know where to implement them is in src/fdnpkg16.c
> with the QUIT(0) code lines
>

Error levels are really easy: it's just whatever int the main()
program returns, and that gets returned to the operating system. For
DOS, use an error level that's greater than or equal to zero. (Zero
usually indicates success, some other value indicates an error or
warning.)

Here's a sample program that just reads a single value from the
command line, and returns that int. (It returns zero otherwise.)


#include <stdio.h>
#include <stdlib.h> /* atoi */

int main(int argc, char **argv)
{
  int errlevel;

  if (argc == 1) { return 0; }

  /* at least one command line argument. assume the first arg is an
     integer, and use that for the error level. Should be greater than
     or equal to zero. */

  errlevel = atoi(argv[1]);

  if (errlevel<0) { return 0; }

  return errlevel;
}



Save that as errlev.c then compile that and run it, you can generate
whatever error level you like. FreeDOS (actually FreeCOM) lets you
print the value using the %ERRORLEVEL% built-in environment variable,
so you can just echo %ERRORLEVEL% to see the value.

Here's a simple bat that prints the values 1 to 5: (I called it errlevel.bat)

errlev 1
echo %errorlevel%
errlev 2
echo %errorlevel%
errlev 3
echo %errorlevel%
errlev 4
echo %errorlevel%
errlev 5
echo %errorlevel%



This doesn't use @ECHO OFF so you can see everything that it's doing.
Here's a sample run: (I'm running this in my D:\SRC directory)

D:\SRC>errlevel.bat
D:\SRC>errlev 1
D:\SRC>echo 1
1
D:\SRC>errlev 2
D:\SRC>echo 2
2
D:\SRC>errlev 3
D:\SRC>echo 3
3
D:\SRC>errlev 4
D:\SRC>echo 4
4
D:\SRC>errlev 5
D:\SRC>echo 5
5


_______________________________________________
Freedos-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freedos-devel

Reply via email to