Fixed out-by-one error in previous commit.
[AROS.git] / workbench / c / shellcommands / Skip.c
blobdae7fa30d9dba3d40ca78e22528899f5cd19192f
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /******************************************************************************
11 NAME
13 Skip
15 SYNOPSIS
17 LABEL, BACK/S
19 LOCATION
23 FUNCTION
25 Skip commands in a script file until a certain label (declared with
26 Lab) or an EndSkip command is reached.
28 INPUTS
30 LABEL -- The label to skip to.
32 BACK -- Specify this if the label appears before the Skip statement
33 in the script file.
35 RESULT
37 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
45 Lab, EndSkip
47 INTERNALS
49 HISTORY
51 09.03.2009 OTigreat 41.2 Let's find Lab even after an empty line
52 14.01.2000 SDuvan 41.1 Implemented
54 ******************************************************************************/
56 #include <proto/dos.h>
57 #include <dos/dos.h>
58 #include <dos/dosextens.h>
59 #include <dos/rdargs.h>
60 #include "dos_commanderrors.h"
61 #include <dos/stdio.h>
63 #include <aros/shcommands.h>
65 AROS_SH2(Skip, 41.2,
66 AROS_SHA(STRPTR, , LABEL, , NULL),
67 AROS_SHA(BOOL, , BACK, /S, FALSE))
69 AROS_SHCOMMAND_INIT
71 struct CommandLineInterface *cli = Cli();
72 BOOL labelFound = FALSE;
75 if(cli == NULL || cli->cli_CurrentInput == cli->cli_StandardInput)
77 PrintFault(ERROR_SCRIPT_ONLY, "Skip");
79 return RETURN_FAIL;
83 char buffer[256];
84 int a = 0;
85 LONG status;
86 BOOL quit = FALSE;
88 SelectInput(cli->cli_CurrentInput);
90 if (SHArg(BACK))
92 Flush(Input());
93 Seek(Input(), 0, OFFSET_BEGINNING);
96 while (!quit)
98 status = ReadItem(buffer, sizeof(buffer), NULL);
100 if (status == ITEM_ERROR)
102 break;
105 if (status != ITEM_NOTHING) {
106 switch (FindArg("LAB,ENDSKIP", buffer))
108 case 0:
109 if (SHArg(LABEL) != NULL)
111 ReadItem(buffer, sizeof(buffer), NULL);
113 if (FindArg(SHArg(LABEL), buffer) == 0)
115 quit = TRUE;
116 labelFound = TRUE;
119 break;
121 case 1:
122 quit = TRUE;
123 break;
127 /* Skip to the next line */
130 a = FGetC(Input());
131 } while (a != '\n' && a != ENDSTREAMCH);
135 if (!labelFound && SHArg(LABEL) != NULL)
137 SetIoErr(ERROR_OBJECT_NOT_FOUND);
138 PrintFault(ERROR_OBJECT_NOT_FOUND, "Skip");
140 return RETURN_FAIL;
143 return RETURN_OK;
145 AROS_SHCOMMAND_EXIT