forked from FDOS/freecom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoto.c
87 lines (73 loc) · 1.6 KB
/
goto.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* $Id$
* GOTO.C - goto command.
*
* Comments:
*
* 16 Jul 1998 (Hans B Pufal)
* started.
*
* 16 Jul 1998 (John P Price)
* Seperated commands into individual files.
*
* 27-Jul-1998 (John P Price <[email protected]>)
* - added config.h include
*
* 28 Jul 1998 (Hans B Pufal) [HBP_003]
* Terminate label on first space character, use only first 8 chars of
* label string
*
* 10-Aug-1998 ska
* - moved code into readbatchline() that automatically supports
* modifyable scripts & ^Break checks
*
* 1999/11/02 ska
* bugfix: some DOS shells except a colon before the label
*
* 2000/07/05 Ron Cemer
* bugfix: renamed skipwd() -> skip_word() to prevent duplicate symbol
*/
#include "../config.h"
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../include/batch.h"
#include "../include/cmdline.h"
#include "../include/command.h"
#include "../err_fcts.h"
#include "../strings.h"
int cmd_goto(char *param)
{
/*
* Perform GOTO command.
*
* Only valid if batch file current.
*/
char *tmp;
while(bc && bc->forvar) /* is FOR context */
exit_batch(); /* remove it */
if(bc == 0) {
/*!! not in batch error */
return 1;
}
assert(param);
if(*param == ':') /* some old DOS shell excepts a colon */
param = skipdm(param + 1);
if(*param == '\0') {
error_goto_label();
exit_batch();
return 1;
}
tmp = skip_word(param);
*tmp = '\0';
tmp = strdup(param);
if(!tmp) {
error_out_of_memory();
return 1;
}
/* Restart the batch file from the beginning */
bc->brewind = 1;
bc->blabel = tmp;
return 0;
}