grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / c / shellcommands / FailAt.c
blob6e5e53c147c978b4f660463a7e2d2e160ea95734
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: FailAt - Set the failure level of a process
6 Lang: English
7 */
9 /**************************************************************************
11 NAME
12 FailAt
14 FORMAT
15 FailAt <limit>
17 SYNOPSIS
18 RCLIM/N
20 LOCATION
23 FUNCTION
24 FailAt sets the return code limit of the current shell script. If
25 any command returns with a failure code of this value or higher
26 the script shall abort.
28 Common failure codes are:
29 0 - No error
30 5 - Warning
31 10 - Error
32 20 - Failure
34 The normal value for the return code limit is 10.
36 NOTES
37 If this command is called in a script that is executed from another
38 script, the new fail level will be inherited by the parent script.
40 EXAMPLE
41 If we have a script with the commands
43 Copy RAM:SomeFile DF0:
44 Echo "Done!"
46 and the file RAM:SomeFile does not exist, the Copy command will
47 return with:
49 Copy: object not found
50 Copy: returned with error code 20
52 and the script will abort. However if you include the command
54 FailAt 21
56 then the script will complete since the return code from Copy is
57 less than the return code limit.
59 **************************************************************************/
61 #include <exec/types.h>
62 #include <exec/tasks.h>
63 #include <dos/dosextens.h>
64 #include <dos/rdargs.h>
65 #include <proto/exec.h>
66 #include <proto/dos.h>
67 #include <utility/tagitem.h>
69 #include <aros/shcommands.h>
71 AROS_SH1H(FailAt, 41.1, "Set the return code failure limit of the current script",
72 AROS_SHAH(LONG *, , RCLIM,/N, NULL, "The new return code limit"))
74 AROS_SHCOMMAND_INIT
76 struct CommandLineInterface *cli = Cli();
79 if (cli == NULL)
81 return RETURN_FAIL;
84 /* Write current fail level */
85 if (SHArg(RCLIM) == NULL)
87 Printf("Fail limit: %ld\n", cli->cli_FailLevel);
89 /* Set new fail level */
90 else
92 cli->cli_FailLevel = *SHArg(RCLIM);
95 return RETURN_OK;
97 AROS_SHCOMMAND_EXIT