- Remove the remaining __USE_W32API, deprecated for ages.
[reactos.git] / reactos / base / shell / cmd / goto.c
1 /*
2 * GOTO.C - goto internal batch command.
3 *
4 * History:
5 *
6 * 16 Jul 1998 (Hans B Pufal)
7 * started.
8 *
9 * 16 Jul 1998 (John P Price)
10 * Seperated commands into individual files.
11 *
12 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
13 * added config.h include
14 *
15 * 28 Jul 1998 (Hans B Pufal) [HBP_003]
16 * Terminate label on first space character, use only first 8 chars of
17 * label string
18 *
19 * 24-Jan-1999 (Eric Kohl)
20 * Unicode and redirection safe!
21 *
22 * 27-Jan-1999 (Eric Kohl)
23 * Added help text ("/?").
24 *
25 * 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
26 * Remove all hardcode string to En.rc
27 */
28
29 #include <precomp.h>
30
31
32 /*
33 * Perform GOTO command.
34 *
35 * Only valid if batch file current.
36 *
37 */
38
39 INT cmd_goto (LPTSTR param)
40 {
41 LPTSTR tmp, tmp2;
42 LONG lNewPosHigh = 0;
43
44 TRACE ("cmd_goto (\'%s\')\n", debugstr_aw(param));
45
46 if (!_tcsncmp (param, _T("/?"), 2))
47 {
48 ConOutResPaging(TRUE,STRING_GOTO_HELP1);
49 return 0;
50 }
51
52 /* if not in batch -- error!! */
53 if (bc == NULL)
54 {
55 return 1;
56 }
57
58 if (*param == _T('\0'))
59 {
60 ConErrResPrintf(STRING_GOTO_ERROR1);
61 ExitBatch();
62 return 1;
63 }
64
65 /* terminate label at first space char */
66 tmp = param+1;
67 while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':')))
68 tmp++;
69 *(tmp) = _T('\0');
70
71 /* set file pointer to the beginning of the batch file */
72 lNewPosHigh = 0;
73
74 /* jump to end of the file */
75 if ( _tcsicmp( param, _T(":eof"))==0)
76 {
77 SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_END);
78 return 0;
79 }
80
81 /* jump to begin of the file */
82 SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_BEGIN);
83
84 while (FileGetString (bc->hBatchFile, textline, sizeof(textline) / sizeof(textline[0])))
85 {
86 int pos;
87 int size;
88
89 /* Strip out any trailing spaces or control chars */
90 tmp = textline + _tcslen (textline) - 1;
91
92 while (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':')))
93 tmp--;
94 *(tmp + 1) = _T('\0');
95
96 /* Then leading spaces... */
97 tmp = textline;
98 while (_istspace (*tmp))
99 tmp++;
100
101 /* All space after leading space terminate the string */
102 size = _tcslen(tmp) -1;
103 pos=0;
104 while (tmp+pos < tmp+size)
105 {
106 if (_istspace(tmp[pos]))
107 tmp[pos]=_T('\0');
108 pos++;
109 }
110
111 tmp2 = param;
112 /* use whole label name */
113 if ((*tmp == _T(':')) && ((_tcsicmp (++tmp, param) == 0) || (_tcsicmp (tmp, ++tmp2) == 0)))
114 return 0;
115
116 }
117
118 ConErrResPrintf(STRING_GOTO_ERROR2, param);
119 ExitBatch();
120 return 1;
121 }
122
123 /* EOF */