2 * GOTO.C - goto internal batch command.
6 * 16 Jul 1998 (Hans B Pufal)
9 * 16 Jul 1998 (John P Price)
10 * Seperated commands into individual files.
12 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
13 * added config.h include
15 * 28 Jul 1998 (Hans B Pufal) [HBP_003]
16 * Terminate label on first space character, use only first 8 chars of
19 * 24-Jan-1999 (Eric Kohl)
20 * Unicode and redirection safe!
22 * 27-Jan-1999 (Eric Kohl)
23 * Added help text ("/?").
25 * 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
26 * Remove all hardcode string to En.rc
33 * Perform GOTO command.
35 * Only valid if batch file current.
39 INT
cmd_goto (LPTSTR cmd
, LPTSTR param
)
41 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
45 TRACE ("cmd_goto (\'%s\', \'%s\'\n", debugstr_aw(cmd
), debugstr_aw(param
));
47 if (!_tcsncmp (param
, _T("/?"), 2))
49 ConOutResPaging(TRUE
,STRING_GOTO_HELP1
);
53 /* if not in batch -- error!! */
59 if (*param
== _T('\0'))
61 LoadString(CMD_ModuleHandle
, STRING_GOTO_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
66 /* terminate label at first space char */
68 while (!_istcntrl (*tmp
) && !_istspace (*tmp
) && (*tmp
!= _T(':')))
72 /* set file pointer to the beginning of the batch file */
75 /* jump to end of the file */
76 if ( _tcsicmp( param
, _T(":eof"))==0)
78 /* when lCallPosition != 0 we have to return to the caller */
79 if (bc
->lCallPosition
== 0)
80 SetFilePointer (bc
->hBatchFile
, 0, &lNewPosHigh
, FILE_END
);
83 SetFilePointer (bc
->hBatchFile
, (LONG
)bc
->lCallPosition
, &bc
->lCallPositionHigh
, FILE_BEGIN
);
84 bc
->lCallPosition
= 0;
85 bc
->lCallPositionHigh
= 0;
90 /* jump to begin of the file */
91 SetFilePointer (bc
->hBatchFile
, 0, &lNewPosHigh
, FILE_BEGIN
);
93 while (FileGetString (bc
->hBatchFile
, textline
, sizeof(textline
) / sizeof(textline
[0])))
98 /* Strip out any trailing spaces or control chars */
99 tmp
= textline
+ _tcslen (textline
) - 1;
101 while (_istcntrl (*tmp
) || _istspace (*tmp
) || (*tmp
== _T(':')))
103 *(tmp
+ 1) = _T('\0');
105 /* Then leading spaces... */
107 while (_istspace (*tmp
))
110 /* All space after leading space terminate the string */
111 size
= _tcslen(tmp
) -1;
113 while (tmp
+pos
< tmp
+size
)
115 if (_istspace(tmp
[pos
]))
121 /* use whole label name */
122 if ((*tmp
== _T(':')) && ((_tcsicmp (++tmp
, param
) == 0) || (_tcsicmp (tmp
, ++tmp2
) == 0)))
127 LoadString(CMD_ModuleHandle
, STRING_GOTO_ERROR2
, szMsg
, RC_STRING_MAX_SIZE
);
128 ConErrPrintf(szMsg
, param
);