ReactOS  0.4.15-dev-506-ga3ec01c
goto.c
Go to the documentation of this file.
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  * Separated 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 hardcoded strings in 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 
40 {
41  LPTSTR tmp, tmp2;
42 
43  TRACE ("cmd_goto (\'%s\')\n", debugstr_aw(param));
44 
45  if (!_tcsncmp (param, _T("/?"), 2))
46  {
48  return 0;
49  }
50 
51  /* if not in batch -- error!! */
52  if (bc == NULL)
53  {
54  return 1;
55  }
56 
57  if (*param == _T('\0'))
58  {
60  ExitBatch();
61  return 1;
62  }
63 
64  /* terminate label at first space char */
65  tmp = param+1;
66  while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':')))
67  tmp++;
68  *(tmp) = _T('\0');
69 
70  /* jump to end of the file */
71  if ( _tcsicmp( param, _T(":eof"))==0)
72  {
73  bc->mempos=bc->memsize; /* position at the end of the batchfile */
74  return 0;
75  }
76 
77  /* jump to begin of the file */
78  bc->mempos=0;
79 
80  while (BatchGetString (textline, sizeof(textline) / sizeof(textline[0])))
81  {
82  int pos;
83  INT_PTR size;
84 
85  /* Strip out any trailing spaces or control chars */
86  tmp = textline + _tcslen (textline) - 1;
87 
88  while (tmp > textline && (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':'))))
89  tmp--;
90  *(tmp + 1) = _T('\0');
91 
92  /* Then leading spaces... */
93  tmp = textline;
94  while (_istspace (*tmp))
95  tmp++;
96 
97  /* All space after leading space terminate the string */
98  size = _tcslen(tmp) -1;
99  pos=0;
100  while (tmp+pos < tmp+size)
101  {
102  if (_istspace(tmp[pos]))
103  tmp[pos]=_T('\0');
104  pos++;
105  }
106 
107  tmp2 = param;
108  /* use whole label name */
109  if ((*tmp == _T(':')) && ((_tcsicmp (++tmp, param) == 0) || (_tcsicmp (tmp, ++tmp2) == 0)))
110  return 0;
111 
112  }
113 
115  ExitBatch();
116  return 1;
117 }
118 
119 /* EOF */
#define TRUE
Definition: types.h:120
DWORD mempos
Definition: batch.h:12
#define _tcsicmp
Definition: xmlstorage.h:205
LPBATCH_CONTEXT bc
Definition: batch.c:66
#define debugstr_aw
Definition: precomp.h:43
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT_PTR
Definition: typedefs.h:63
int32_t INT
Definition: typedefs.h:57
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength)
Definition: batch.c:391
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define STRING_GOTO_HELP1
Definition: resource.h:135
#define ConErrResPrintf(uID,...)
Definition: console.h:51
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
VOID ExitBatch(VOID)
Definition: batch.c:186
#define STRING_GOTO_ERROR2
Definition: resource.h:52
TCHAR textline[BATCH_BUFFSIZE]
Definition: batch.c:73
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
GLfloat param
Definition: glext.h:5796
#define _istcntrl
Definition: tchar.h:739
INT cmd_goto(LPTSTR param)
Definition: goto.c:39
#define STRING_GOTO_ERROR1
Definition: resource.h:51
DWORD memsize
Definition: batch.h:11
#define _istspace
Definition: tchar.h:1504
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9