Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / c / shellcommands / Skip.c
blob50a28ce82b7cf89b61adf943ebda5dc4b4acd614
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
21 Workbench:C
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], a = 0;
84 LONG status;
85 BOOL quit = FALSE;
87 SelectInput(cli->cli_CurrentInput);
89 if (SHArg(BACK))
91 Flush(Input());
92 Seek(Input(), 0, OFFSET_BEGINNING);
95 while (!quit)
97 status = ReadItem(buffer, sizeof(buffer), NULL);
99 if (status == ITEM_ERROR)
101 break;
104 if (status == ITEM_NOTHING)
106 if (a == ENDSTREAMCH)
107 break;
108 else
109 continue;
112 switch (FindArg("LAB,ENDSKIP", buffer))
114 case 0:
115 if (SHArg(LABEL) != NULL)
117 ReadItem(buffer, sizeof(buffer), NULL);
119 if (FindArg(SHArg(LABEL), buffer) == 0)
121 quit = TRUE;
122 labelFound = TRUE;
125 break;
127 case 1:
128 quit = TRUE;
129 break;
132 /* Skip to the next line */
135 a = FGetC(Input());
136 } while (a != '\n' && a != ENDSTREAMCH);
140 if (!labelFound && SHArg(LABEL) != NULL)
142 SetIoErr(ERROR_OBJECT_NOT_FOUND);
143 PrintFault(ERROR_OBJECT_NOT_FOUND, "Skip");
145 return RETURN_FAIL;
148 return RETURN_OK;
150 AROS_SHCOMMAND_EXIT