962 |
mateusz.vi |
1 |
/* This file is part of the SvarCOM project and is published under the terms
|
|
|
2 |
* of the MIT license.
|
|
|
3 |
*
|
|
|
4 |
* Copyright (C) 2021 Mateusz Viste
|
|
|
5 |
*
|
|
|
6 |
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
7 |
* copy of this software and associated documentation files (the "Software"),
|
|
|
8 |
* to deal in the Software without restriction, including without limitation
|
|
|
9 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
10 |
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
11 |
* Software is furnished to do so, subject to the following conditions:
|
|
|
12 |
*
|
|
|
13 |
* The above copyright notice and this permission notice shall be included in
|
|
|
14 |
* all copies or substantial portions of the Software.
|
|
|
15 |
*
|
|
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
19 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
21 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
22 |
* DEALINGS IN THE SOFTWARE.
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/*
|
|
|
26 |
* goto label
|
|
|
27 |
*
|
|
|
28 |
* if label does not exist in the currently processed batch file, then a error
|
|
|
29 |
* "Label not found" is displayed and the batch file is aborted. Any parent
|
|
|
30 |
* batches are ALSO aborted. Same behavior if called without any parameter.
|
|
|
31 |
*
|
|
|
32 |
* if called outside of a batch file, this command has no effect (and does not
|
|
|
33 |
* display any error, even when called without any argument).
|
|
|
34 |
*
|
|
|
35 |
* it reacts to /? by outputing its help screen
|
|
|
36 |
*
|
|
|
37 |
* only 1st argument is processed, any extra arguments are ignored (even /?).
|
|
|
38 |
*
|
|
|
39 |
* Labels can be written as:
|
|
|
40 |
* :LABEL
|
|
|
41 |
* :LABEL
|
|
|
42 |
* : LABEL
|
|
|
43 |
*
|
|
|
44 |
* Labels are searched in the batch file from top to bottom and first match
|
|
|
45 |
* is jumped to.
|
|
|
46 |
*/
|
|
|
47 |
|
|
|
48 |
static enum cmd_result cmd_goto(struct cmd_funcparam *p) {
|
|
|
49 |
|
|
|
50 |
/* help? reacts only to /? being passed as FIRST argument */
|
|
|
51 |
if ((p->argc > 0) && imatch(p->argv[0], "/?")) {
|
|
|
52 |
outputnl("Directs batch processing to a labelled line in the batch program.");
|
|
|
53 |
outputnl("");
|
|
|
54 |
outputnl("GOTO LABEL");
|
|
|
55 |
outputnl("");
|
|
|
56 |
outputnl("LABEL specifies a text string used in the batch program as a label.");
|
|
|
57 |
outputnl("");
|
|
|
58 |
outputnl("A label is on a line by itself and must be preceded by a colon.");
|
|
|
59 |
return(CMD_OK);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/* not inside a batch file? then do nothing */
|
|
|
63 |
if (p->rmod->bat == NULL) return(CMD_OK);
|
|
|
64 |
|
|
|
65 |
/* TODO open batch file and read it line by line until label is found or EOF */
|
|
|
66 |
|
|
|
67 |
/* TODO if label not found, display error message and abort all batch scripts */
|
|
|
68 |
|
|
|
69 |
return(CMD_OK);
|
|
|
70 |
}
|