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 43 TRACE ("cmd_goto (\'%s\')\n", debugstr_aw(param)); 44 45 if (!_tcsncmp (param, _T("/?"), 2)) 46 { 47 ConOutResPaging(TRUE,STRING_GOTO_HELP1); 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 { 59 ConErrResPrintf(STRING_GOTO_ERROR1); 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 size; 84 85 /* Strip out any trailing spaces or control chars */ 86 tmp = textline + _tcslen (textline) - 1; 87 88 while (_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 114 ConErrResPrintf(STRING_GOTO_ERROR2, param); 115 ExitBatch(); 116 return 1; 117 } 118 119 /* EOF */ 120