update for HEAD-2003091401
[reactos.git] / subsys / system / cmd / shift.c
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 <ekohl@abo.rhein-zeitung.de>)
17  *        Added help text ("shift /?") and cleaned up.
18  *
19  *    20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
20  *        Unicode and redirection safe!
21  */
22
23 #include "config.h"
24
25 #include <windows.h>
26 #include <tchar.h>
27 #include <string.h>
28
29 #include "cmd.h"
30 #include "batch.h"
31
32
33 /*
34  *  Perform the SHIFT command.
35  *
36  * Only valid inside batch files.
37  *
38  * FREEDOS extension : optional parameter DOWN to allow shifting
39  *   parameters backwards.
40  */
41
42 INT cmd_shift (LPTSTR cmd, LPTSTR param)
43 {
44 #ifdef _DEBUG
45         DebugPrintf (_T("cmd_shift: (\'%s\', \'%s\')\n"), cmd, param);
46 #endif
47
48         if (!_tcsncmp (param, _T("/?"), 2))
49         {
50                 ConOutPuts (_T("Changes the position of replaceable parameters in a batch file.\n\n"
51                                            "SHIFT [DOWN]"));
52                 return 0;
53         }
54
55         if (bc == NULL)
56         {
57                 /* not in batch - error!! */
58                 return 1;
59         }
60
61         if (!_tcsicmp (param, _T("down")))
62         {
63                 if (bc->shiftlevel)
64                         bc->shiftlevel--;
65         }
66         else /* shift up */
67                 bc->shiftlevel++;
68
69         return 0;
70 }