use m4_normalize on the output strings to remove trailing spaces/tabs and consolidate...
[AROS.git] / workbench / c / shellcommands / Skip.c
blob7b5cece92a41b0470239715fe3056d497d913bbf
1 /*
2 Copyright © 1995-2016, 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 Jump to a new position in a script. If a label is specified, control
26 goes to the first Lab command found that has the same label. If no
27 label is specified, control goes to the first EndSkip command found.
29 If the BACK switch is given, the search for a matching Lab or
30 EndSkip command starts at the beginning of the script; otherwise the
31 search starts at the Skip command. If a matching Lab/EndSkip is not
32 found, an error is returned.
34 INPUTS
36 LABEL -- The label to skip to.
38 BACK -- Specify this if the label appears before the Skip statement
39 in the script file.
41 RESULT
43 NOTES
44 This command can only be used in scripts.
46 EXAMPLE
48 BUGS
50 SEE ALSO
52 Lab, EndSkip
54 INTERNALS
56 ******************************************************************************/
58 #include <proto/dos.h>
59 #include <dos/dos.h>
60 #include <dos/dosextens.h>
61 #include <dos/rdargs.h>
62 #include "dos_commanderrors.h"
63 #include <dos/stdio.h>
65 #include <aros/shcommands.h>
67 AROS_SH2(Skip, 41.2,
68 AROS_SHA(STRPTR, , LABEL, , NULL),
69 AROS_SHA(BOOL, , BACK, /S, FALSE))
71 AROS_SHCOMMAND_INIT
73 struct CommandLineInterface *cli = Cli();
74 BOOL labelFound = FALSE;
77 if (cli == NULL || cli->cli_CurrentInput == cli->cli_StandardInput)
79 PrintFault(ERROR_SCRIPT_ONLY, "Skip");
81 return RETURN_FAIL;
85 char buffer[256];
86 int a = 0;
87 LONG status;
88 BOOL quit = FALSE;
90 SelectInput(cli->cli_CurrentInput);
92 if (SHArg(BACK))
94 Flush(Input());
95 Seek(Input(), 0, OFFSET_BEGINNING);
98 while (!quit)
100 status = ReadItem(buffer, sizeof(buffer), NULL);
102 if (status == ITEM_ERROR)
104 break;
107 if (status != ITEM_NOTHING)
109 switch (FindArg("LAB,ENDSKIP", buffer))
111 case 0:
112 if (SHArg(LABEL) != NULL)
114 ReadItem(buffer, sizeof(buffer), NULL);
116 if (FindArg(SHArg(LABEL), buffer) == 0)
118 quit = TRUE;
119 labelFound = TRUE;
122 break;
124 case 1:
125 quit = TRUE;
126 break;
130 /* Skip to the next line */
133 a = FGetC(Input());
134 } while (a != '\n' && a != ENDSTREAMCH);
136 if (a == ENDSTREAMCH)
137 break;
141 if (!labelFound && SHArg(LABEL) != NULL)
143 SetIoErr(ERROR_OBJECT_NOT_FOUND);
144 PrintFault(ERROR_OBJECT_NOT_FOUND, "Skip");
146 return RETURN_FAIL;
149 return RETURN_OK;
151 AROS_SHCOMMAND_EXIT