some more win32k 64 bit fixes
[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 cmd, LPTSTR param)
40 {
41 TCHAR szMsg[RC_STRING_MAX_SIZE];
42 LPTSTR tmp, tmp2;
43 LONG lNewPosHigh = 0;
44
45 TRACE ("cmd_goto (\'%s\', \'%s\'\n", debugstr_aw(cmd), debugstr_aw(param));
46
47 if (!_tcsncmp (param, _T("/?"), 2))
48 {
49 ConOutResPaging(TRUE,STRING_GOTO_HELP1);
50 return 0;
51 }
52
53 /* if not in batch -- error!! */
54 if (bc == NULL)
55 {
56 return 1;
57 }
58
59 if (*param == _T('\0'))
60 {
61 LoadString(CMD_ModuleHandle, STRING_GOTO_ERROR1, szMsg, RC_STRING_MAX_SIZE);
62 ExitBatch(szMsg);
63 return 1;
64 }
65
66 /* terminate label at first space char */
67 tmp = param+1;
68 while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':')))
69 tmp++;
70 *(tmp) = _T('\0');
71
72 /* set file pointer to the beginning of the batch file */
73 lNewPosHigh = 0;
74
75 /* jump to end of the file */
76 if ( _tcsicmp( param, _T(":eof"))==0)
77 {
78 /* when lCallPosition != 0 we have to return to the caller */
79 if (bc->lCallPosition == 0)
80 SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_END);
81 else
82 {
83 SetFilePointer (bc->hBatchFile, (LONG)bc->lCallPosition, &bc->lCallPositionHigh, FILE_BEGIN);
84 bc->lCallPosition = 0;
85 bc->lCallPositionHigh = 0;
86 }
87 return 0;
88 }
89
90 /* jump to begin of the file */
91 SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_BEGIN);
92
93 while (FileGetString (bc->hBatchFile, textline, sizeof(textline) / sizeof(textline[0])))
94 {
95 int pos;
96 int size;
97
98 /* Strip out any trailing spaces or control chars */
99 tmp = textline + _tcslen (textline) - 1;
100
101 while (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':')))
102 tmp--;
103 *(tmp + 1) = _T('\0');
104
105 /* Then leading spaces... */
106 tmp = textline;
107 while (_istspace (*tmp))
108 tmp++;
109
110 /* All space after leading space terminate the string */
111 size = _tcslen(tmp) -1;
112 pos=0;
113 while (tmp+pos < tmp+size)
114 {
115 if (_istspace(tmp[pos]))
116 tmp[pos]=_T('\0');
117 pos++;
118 }
119
120 tmp2 = param;
121 /* use whole label name */
122 if ((*tmp == _T(':')) && ((_tcsicmp (++tmp, param) == 0) || (_tcsicmp (tmp, ++tmp2) == 0)))
123 return 0;
124
125 }
126
127 LoadString(CMD_ModuleHandle, STRING_GOTO_ERROR2, szMsg, RC_STRING_MAX_SIZE);
128 ConErrPrintf(szMsg, param);
129 ExitBatch(NULL);
130 return 1;
131 }
132
133 /* EOF */