xref: /reactos/base/shell/cmd/shift.c (revision 2b82fe44)
1 /*
2  *  SHIFT.C - shift internal batch command
3  *
4  *
5  *  History:
6  *
7  *    16 Jul 1998 (Hans B Pufal)
8  *        started.
9  *
10  *    16 Jul 1998 (John P Price)
11  *        Separated commands into individual files.
12  *
13  *    27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
14  *        added config.h include
15  *
16  *    07-Jan-1999 (Eric Kohl)
17  *        Added help text ("shift /?") and cleaned up.
18  *
19  *    20-Jan-1999 (Eric Kohl)
20  *        Unicode and redirection safe!
21  *
22  *    30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
23  *        Remove all hardcode string to En.rc
24  */
25 
26 #include <precomp.h>
27 
28 
29 /*
30  *  Perform the SHIFT command.
31  *
32  * Only valid inside batch files.
33  *
34  * FREEDOS extension : optional parameter DOWN to allow shifting
35  *   parameters backwards.
36  *
37  */
38 
39 INT cmd_shift (LPTSTR param)
40 {
41 	INT i = 0;
42 	TRACE ("cmd_shift: (\'%s\')\n", debugstr_aw(param));
43 
44 	if (!_tcsncmp (param, _T("/?"), 2))
45 	{
46 		ConOutResPaging(TRUE,STRING_SHIFT_HELP);
47 		return 0;
48 	}
49 
50 	nErrorLevel = 0;
51 
52 	if (bc == NULL)
53 	{
54 		/* not in batch - error!! */
55 		nErrorLevel = 1;
56 		return 1;
57 	}
58 
59 	if (!_tcsicmp (param, _T("down")))
60 	{
61 		if (bc->shiftlevel[0])
62 			for (; i <= 9; i++)
63 				bc->shiftlevel[i]--;
64 	}
65 	else /* shift up */
66 	{
67 		if (*param == _T('/'))
68 		{
69 			if (param[1] < '0' || param[1] > '9')
70 			{
71 				error_invalid_switch(param[1]);
72 				return 1;
73 			}
74 			i = param[1] - '0';
75 		}
76 
77 		for (; i < 9; i++)
78 			bc->shiftlevel[i] = bc->shiftlevel[i + 1];
79 		bc->shiftlevel[i]++;
80 	}
81 
82 	return 0;
83 }
84 
85 /* EOF */
86