2 * CMD - Wine-compatible command line interface - built-in functions.
4 * Copyright (C) 1999 D A Pickles
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * On entry to each function, global variables quals, param1, param2 contain
24 * the qualifiers (uppercased and concatenated) and parameters entered, with
25 * environment-variable and batch parameter substitution already done.
30 * - No support for pipes, shell parameters
31 * - Lots of functionality missing from builtins
32 * - Messages etc need international support
35 #define WIN32_LEAN_AND_MEAN
39 void WCMD_execute (char *orig_command, char *parameter, char *substitution);
43 struct env_stack *next;
47 struct env_stack *saved_environment;
49 extern HINSTANCE hinst;
50 extern char *inbuilt[];
51 extern int echo_mode, verify_mode;
52 extern char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH];
53 extern BATCH_CONTEXT *context;
54 extern DWORD errorlevel;
58 /****************************************************************************
61 * Clear the terminal screen.
64 void WCMD_clear_screen (void) {
66 /* Emulate by filling the screen from the top left to bottom right with
67 spaces, then moving the cursor to the top left afterwards */
68 CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
69 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
71 if (GetConsoleScreenBufferInfo(hStdOut, &consoleInfo))
76 screenSize = consoleInfo.dwSize.X * (consoleInfo.dwSize.Y + 1);
80 FillConsoleOutputCharacter(hStdOut, ' ', screenSize, topLeft, &screenSize);
81 SetConsoleCursorPosition(hStdOut, topLeft);
85 /****************************************************************************
88 * Change the default i/o device (ie redirect STDin/STDout).
91 void WCMD_change_tty (void) {
97 /****************************************************************************
100 * Copy a file or wildcarded set.
101 * FIXME: No wildcard support
104 void WCMD_copy (void) {
110 static const char overwrite[] = "Overwrite file (Y/N)?";
111 char string[8], outpath[MAX_PATH], inpath[MAX_PATH], *infile;
113 if (param1[0] == 0x00) {
114 WCMD_output ("Argument missing\n");
118 if ((strchr(param1,'*') != NULL) && (strchr(param1,'%') != NULL)) {
119 WCMD_output ("Wildcards not yet supported\n");
123 /* If no destination supplied, assume current directory */
124 if (param2[0] == 0x00) {
128 GetFullPathName (param2, sizeof(outpath), outpath, NULL);
129 if (outpath[strlen(outpath) - 1] == '\\')
130 outpath[strlen(outpath) - 1] = '\0';
131 hff = FindFirstFile (outpath, &fd);
132 if (hff != INVALID_HANDLE_VALUE) {
133 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
134 GetFullPathName (param1, sizeof(inpath), inpath, &infile);
135 strcat (outpath, "\\");
136 strcat (outpath, infile);
141 force = (strstr (quals, "/Y") != NULL);
143 hff = FindFirstFile (outpath, &fd);
144 if (hff != INVALID_HANDLE_VALUE) {
146 WCMD_output (overwrite);
147 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
148 if (toupper(string[0]) == 'Y') force = TRUE;
153 status = CopyFile (param1, outpath, FALSE);
154 if (!status) WCMD_print_error ();
158 /****************************************************************************
161 * Create a directory.
163 * this works recursivly. so mkdir dir1\dir2\dir3 will create dir1 and dir2 if
164 * they do not already exist.
167 BOOL create_full_path(CHAR* path)
173 new_path = HeapAlloc(GetProcessHeap(),0,strlen(path)+1);
174 strcpy(new_path,path);
176 while ((len = strlen(new_path)) && new_path[len - 1] == '\\')
177 new_path[len - 1] = 0;
179 while (!CreateDirectory(new_path,NULL))
182 DWORD last_error = GetLastError();
183 if (last_error == ERROR_ALREADY_EXISTS)
186 if (last_error != ERROR_PATH_NOT_FOUND)
192 if (!(slash = strrchr(new_path,'\\')) && ! (slash = strrchr(new_path,'/')))
198 len = slash - new_path;
200 if (!create_full_path(new_path))
205 new_path[len] = '\\';
207 HeapFree(GetProcessHeap(),0,new_path);
211 void WCMD_create_dir (void) {
213 if (param1[0] == 0x00) {
214 WCMD_output ("Argument missing\n");
217 if (!create_full_path(param1)) WCMD_print_error ();
220 /****************************************************************************
223 * Delete a file or wildcarded set.
227 void WCMD_delete (int recurse) {
231 char fpath[MAX_PATH];
234 if (param1[0] == 0x00) {
235 WCMD_output ("Argument missing\n");
238 hff = FindFirstFile (param1, &fd);
239 if (hff == INVALID_HANDLE_VALUE) {
240 WCMD_output ("%s :File Not Found\n",param1);
243 if ((strchr(param1,'*') == NULL) && (strchr(param1,'?') == NULL)
244 && (!recurse) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
245 strcat (param1, "\\*");
250 if ((strchr(param1,'*') != NULL) || (strchr(param1,'?') != NULL)) {
251 strcpy (fpath, param1);
253 p = strrchr (fpath, '\\');
256 strcat (fpath, fd.cFileName);
258 else strcpy (fpath, fd.cFileName);
259 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
260 if (!DeleteFile (fpath)) WCMD_print_error ();
262 } while (FindNextFile(hff, &fd) != 0);
266 if (!DeleteFile (param1)) WCMD_print_error ();
271 /****************************************************************************
274 * Echo input to the screen (or not). We don't try to emulate the bugs
275 * in DOS (try typing "ECHO ON AGAIN" for an example).
278 void WCMD_echo (const char *command) {
280 static const char eon[] = "Echo is ON\n", eoff[] = "Echo is OFF\n";
283 if ((command[0] == '.') && (command[1] == 0)) {
284 WCMD_output (newline);
289 count = strlen(command);
291 if (echo_mode) WCMD_output (eon);
292 else WCMD_output (eoff);
295 if (lstrcmpi(command, "ON") == 0) {
299 if (lstrcmpi(command, "OFF") == 0) {
303 WCMD_output_asis (command);
304 WCMD_output (newline);
308 /**************************************************************************
311 * Batch file loop processing.
312 * FIXME: We don't exhaustively check syntax. Any command which works in MessDOS
313 * will probably work here, but the reverse is not necessarily the case...
316 void WCMD_for (char *p) {
321 char set[MAX_PATH], param[MAX_PATH];
324 if (lstrcmpi (WCMD_parameter (p, 1, NULL), "in")
325 || lstrcmpi (WCMD_parameter (p, 3, NULL), "do")
326 || (param1[0] != '%')) {
327 WCMD_output ("Syntax error\n");
330 lstrcpyn (set, WCMD_parameter (p, 2, NULL), sizeof(set));
331 WCMD_parameter (p, 4, &cmd);
332 lstrcpy (param, param1);
335 * If the parameter within the set has a wildcard then search for matching files
336 * otherwise do a literal substitution.
340 while (*(item = WCMD_parameter (set, i, NULL))) {
341 if (strpbrk (item, "*?")) {
342 hff = FindFirstFile (item, &fd);
343 if (hff == INVALID_HANDLE_VALUE) {
347 WCMD_execute (cmd, param, fd.cFileName);
348 } while (FindNextFile(hff, &fd) != 0);
352 WCMD_execute (cmd, param, item);
358 /*****************************************************************************
361 * Execute a command after substituting variable text for the supplied parameter
364 void WCMD_execute (char *orig_cmd, char *param, char *subst) {
366 char *new_cmd, *p, *s, *dup;
369 size = lstrlen (orig_cmd);
370 new_cmd = (char *) LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, size);
371 dup = s = strdup (orig_cmd);
373 while ((p = strstr (s, param))) {
375 size += lstrlen (subst);
376 new_cmd = (char *) LocalReAlloc ((HANDLE)new_cmd, size, 0);
378 strcat (new_cmd, subst);
379 s = p + lstrlen (param);
382 WCMD_process_command (new_cmd);
384 LocalFree ((HANDLE)new_cmd);
388 /**************************************************************************
391 * Simple on-line help. Help text is stored in the resource file.
394 void WCMD_give_help (char *command) {
399 command = WCMD_strtrim_leading_spaces(command);
400 if (lstrlen(command) == 0) {
401 LoadString (hinst, 1000, buffer, sizeof(buffer));
402 WCMD_output_asis (buffer);
405 for (i=0; i<=WCMD_EXIT; i++) {
406 if (CompareString (LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
407 param1, -1, inbuilt[i], -1) == 2) {
408 LoadString (hinst, i, buffer, sizeof(buffer));
409 WCMD_output_asis (buffer);
413 WCMD_output ("No help available for %s\n", param1);
418 /****************************************************************************
421 * Batch file jump instruction. Not the most efficient algorithm ;-)
422 * Prints error message if the specified label cannot be found - the file pointer is
423 * then at EOF, effectively stopping the batch file.
424 * FIXME: DOS is supposed to allow labels with spaces - we don't.
427 void WCMD_goto (void) {
429 char string[MAX_PATH];
431 if (param1[0] == 0x00) {
432 WCMD_output ("Argument missing\n");
435 if (context != NULL) {
437 /* Handle special :EOF label */
438 if (lstrcmpi (":eof", param1) == 0) {
439 context -> skip_rest = TRUE;
443 SetFilePointer (context -> h, 0, NULL, FILE_BEGIN);
444 while (WCMD_fgets (string, sizeof(string), context -> h)) {
445 if ((string[0] == ':') && (lstrcmpi (&string[1], param1) == 0)) return;
447 WCMD_output ("Target to GOTO not found\n");
453 /****************************************************************************
456 * Batch file conditional.
457 * FIXME: Much more syntax checking needed!
460 void WCMD_if (char *p) {
462 int negate = 0, test = 0;
463 char condition[MAX_PATH], *command, *s;
465 if (!lstrcmpi (param1, "not")) {
467 lstrcpy (condition, param2);
470 lstrcpy (condition, param1);
472 if (!lstrcmpi (condition, "errorlevel")) {
473 if (errorlevel >= atoi(WCMD_parameter (p, 1+negate, NULL))) test = 1;
474 WCMD_parameter (p, 2+negate, &command);
476 else if (!lstrcmpi (condition, "exist")) {
477 if (GetFileAttributesA(WCMD_parameter (p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES) {
480 WCMD_parameter (p, 2+negate, &command);
482 else if (!lstrcmpi (condition, "defined")) {
483 if (GetEnvironmentVariableA(WCMD_parameter (p, 1+negate, NULL), NULL, 0) > 0) {
486 WCMD_parameter (p, 2+negate, &command);
488 else if ((s = strstr (p, "=="))) {
490 if (!lstrcmpi (condition, WCMD_parameter (s, 0, NULL))) test = 1;
491 WCMD_parameter (s, 1, &command);
494 WCMD_output ("Syntax error\n");
497 if (test != negate) {
498 command = strdup (command);
499 WCMD_process_command (command);
504 /****************************************************************************
507 * Move a file, directory tree or wildcarded set of files.
508 * FIXME: Needs input and output files to be fully specified.
511 void WCMD_move (void) {
514 char outpath[MAX_PATH], inpath[MAX_PATH], *infile;
518 if (param1[0] == 0x00) {
519 WCMD_output ("Argument missing\n");
523 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
524 WCMD_output ("Wildcards not yet supported\n");
528 /* If no destination supplied, assume current directory */
529 if (param2[0] == 0x00) {
533 /* If 2nd parm is directory, then use original filename */
534 GetFullPathName (param2, sizeof(outpath), outpath, NULL);
535 if (outpath[strlen(outpath) - 1] == '\\')
536 outpath[strlen(outpath) - 1] = '\0';
537 hff = FindFirstFile (outpath, &fd);
538 if (hff != INVALID_HANDLE_VALUE) {
539 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
540 GetFullPathName (param1, sizeof(inpath), inpath, &infile);
541 strcat (outpath, "\\");
542 strcat (outpath, infile);
547 status = MoveFile (param1, outpath);
548 if (!status) WCMD_print_error ();
551 /****************************************************************************
554 * Wait for keyboard input.
557 void WCMD_pause (void) {
562 WCMD_output (anykey);
563 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
566 /****************************************************************************
569 * Delete a directory.
572 void WCMD_remove_dir (void) {
574 if (param1[0] == 0x00) {
575 WCMD_output ("Argument missing\n");
578 if (!RemoveDirectory (param1)) WCMD_print_error ();
581 /****************************************************************************
585 * FIXME: Needs input and output files to be fully specified.
588 void WCMD_rename (void) {
592 if (param1[0] == 0x00 || param2[0] == 0x00) {
593 WCMD_output ("Argument missing\n");
596 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
597 WCMD_output ("Wildcards not yet supported\n");
600 status = MoveFile (param1, param2);
601 if (!status) WCMD_print_error ();
604 /*****************************************************************************
607 * Make a copy of the environment.
609 static WCHAR *WCMD_dupenv( const WCHAR *env )
619 len += (lstrlenW(&env[len]) + 1);
621 env_copy = LocalAlloc (LMEM_FIXED, (len+1) * sizeof (WCHAR) );
624 WCMD_output ("out of memory\n");
627 memcpy (env_copy, env, len*sizeof (WCHAR));
633 /*****************************************************************************
636 * setlocal pushes the environment onto a stack
637 * Save the environment as unicode so we don't screw anything up.
639 void WCMD_setlocal (const char *s) {
641 struct env_stack *env_copy;
643 /* DISABLEEXTENSIONS ignored */
645 env_copy = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack));
648 WCMD_output ("out of memory\n");
652 env = GetEnvironmentStringsW ();
654 env_copy->strings = WCMD_dupenv (env);
655 if (env_copy->strings)
657 env_copy->next = saved_environment;
658 saved_environment = env_copy;
661 LocalFree (env_copy);
663 FreeEnvironmentStringsW (env);
666 /*****************************************************************************
669 static inline WCHAR *WCMD_strchrW(WCHAR *str, WCHAR ch)
680 /*****************************************************************************
683 * endlocal pops the environment off a stack
685 void WCMD_endlocal (void) {
686 WCHAR *env, *old, *p;
687 struct env_stack *temp;
690 if (!saved_environment)
693 /* pop the old environment from the stack */
694 temp = saved_environment;
695 saved_environment = temp->next;
697 /* delete the current environment, totally */
698 env = GetEnvironmentStringsW ();
699 old = WCMD_dupenv (GetEnvironmentStringsW ());
702 n = lstrlenW(&old[len]) + 1;
703 p = WCMD_strchrW(&old[len], '=');
707 SetEnvironmentVariableW (&old[len], NULL);
712 FreeEnvironmentStringsW (env);
714 /* restore old environment */
718 n = lstrlenW(&env[len]) + 1;
719 p = WCMD_strchrW(&env[len], '=');
723 SetEnvironmentVariableW (&env[len], p);
731 /*****************************************************************************
732 * WCMD_setshow_attrib
734 * Display and optionally sets DOS attributes on a file or directory
736 * FIXME: Wine currently uses the Unix stat() function to get file attributes.
737 * As a result only the Readonly flag is correctly reported, the Archive bit
738 * is always set and the rest are not implemented. We do the Right Thing anyway.
740 * FIXME: No SET functionality.
744 void WCMD_setshow_attrib (void) {
749 char flags[9] = {" "};
751 if (param1[0] == '-') {
756 if (lstrlen(param1) == 0) {
757 GetCurrentDirectory (sizeof(param1), param1);
758 strcat (param1, "\\*");
761 hff = FindFirstFile (param1, &fd);
762 if (hff == INVALID_HANDLE_VALUE) {
763 WCMD_output ("%s: File Not Found\n",param1);
767 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
768 if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
771 if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
774 if (fd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
777 if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
780 if (fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) {
783 if (fd.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) {
786 WCMD_output ("%s %s\n", flags, fd.cFileName);
787 for (count=0; count < 8; count++) flags[count] = ' ';
789 } while (FindNextFile(hff, &fd) != 0);
794 /*****************************************************************************
795 * WCMD_setshow_default
797 * Set/Show the current default directory
800 void WCMD_setshow_default (void) {
805 if (strlen(param1) == 0) {
806 GetCurrentDirectory (sizeof(string), string);
807 strcat (string, "\n");
808 WCMD_output (string);
811 status = SetCurrentDirectory (param1);
820 /****************************************************************************
823 * Set/Show the system date
824 * FIXME: Can't change date yet
827 void WCMD_setshow_date (void) {
829 char curdate[64], buffer[64];
832 if (lstrlen(param1) == 0) {
833 if (GetDateFormat (LOCALE_USER_DEFAULT, 0, NULL, NULL,
834 curdate, sizeof(curdate))) {
835 WCMD_output ("Current Date is %s\nEnter new date: ", curdate);
836 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
841 else WCMD_print_error ();
848 /****************************************************************************
851 static int WCMD_compare( const void *a, const void *b )
854 const char * const *str_a = a, * const *str_b = b;
855 r = CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
856 *str_a, -1, *str_b, -1 );
857 if( r == CSTR_LESS_THAN ) return -1;
858 if( r == CSTR_GREATER_THAN ) return 1;
862 /****************************************************************************
863 * WCMD_setshow_sortenv
865 * sort variables into order for display
867 static void WCMD_setshow_sortenv(const char *s)
869 UINT count=0, len=0, i;
872 /* count the number of strings, and the total length */
874 len += (lstrlen(&s[len]) + 1);
878 /* add the strings to an array */
879 str = LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, count * sizeof (char*) );
883 for( i=1; i<count; i++ )
884 str[i] = str[i-1] + lstrlen(str[i-1]) + 1;
887 qsort( str, count, sizeof (char*), WCMD_compare );
890 for( i=0; i<count; i++ ) {
891 WCMD_output_asis(str[i]);
892 WCMD_output_asis("\n");
898 /****************************************************************************
901 * Set/Show the environment variables
904 void WCMD_setshow_env (char *s) {
911 if (strlen(param1) == 0) {
912 env = GetEnvironmentStrings ();
913 WCMD_setshow_sortenv( env );
919 /* FIXME: Emulate Win98 for now, ie "SET C" looks ONLY for an
920 environment variable C, whereas on NT it shows ALL variables
923 status = GetEnvironmentVariable(s, buffer, sizeof(buffer));
925 WCMD_output_asis( s);
926 WCMD_output_asis( "=");
927 WCMD_output_asis( buffer);
928 WCMD_output_asis( "\n");
930 WCMD_output ("Environment variable %s not defined\n", s);
936 if (strlen(p) == 0) p = NULL;
937 status = SetEnvironmentVariable (s, p);
938 if ((!status) & (GetLastError() != ERROR_ENVVAR_NOT_FOUND)) WCMD_print_error();
940 /* WCMD_output (newline); @JED*/
943 /****************************************************************************
946 * Set/Show the path environment variable
949 void WCMD_setshow_path (char *command) {
954 if (strlen(param1) == 0) {
955 status = GetEnvironmentVariable ("PATH", string, sizeof(string));
957 WCMD_output_asis ( "PATH=");
958 WCMD_output_asis ( string);
959 WCMD_output_asis ( "\n");
962 WCMD_output ("PATH not found\n");
966 if (*command == '=') command++; /* Skip leading '=' */
967 status = SetEnvironmentVariable ("PATH", command);
968 if (!status) WCMD_print_error();
972 /****************************************************************************
973 * WCMD_setshow_prompt
975 * Set or show the command prompt.
978 void WCMD_setshow_prompt (void) {
982 if (strlen(param1) == 0) {
983 SetEnvironmentVariable ("PROMPT", NULL);
987 while ((*s == '=') || (*s == ' ')) s++;
988 if (strlen(s) == 0) {
989 SetEnvironmentVariable ("PROMPT", NULL);
991 else SetEnvironmentVariable ("PROMPT", s);
995 /****************************************************************************
998 * Set/Show the system time
999 * FIXME: Can't change time yet
1002 void WCMD_setshow_time (void) {
1004 char curtime[64], buffer[64];
1008 if (strlen(param1) == 0) {
1010 if (GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, NULL,
1011 curtime, sizeof(curtime))) {
1012 WCMD_output ("Current Time is %s\nEnter new time: ", curtime);
1013 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
1018 else WCMD_print_error ();
1025 /****************************************************************************
1028 * Shift batch parameters.
1031 void WCMD_shift (void) {
1033 if (context != NULL) context -> shift_count++;
1037 /****************************************************************************
1040 * Set the console title
1042 void WCMD_title (char *command) {
1043 SetConsoleTitle(command);
1046 /****************************************************************************
1049 * Copy a file to standard output.
1052 void WCMD_type (void) {
1058 if (param1[0] == 0x00) {
1059 WCMD_output ("Argument missing\n");
1062 h = CreateFile (param1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1063 FILE_ATTRIBUTE_NORMAL, NULL);
1064 if (h == INVALID_HANDLE_VALUE) {
1065 WCMD_print_error ();
1068 while (ReadFile (h, buffer, sizeof(buffer), &count, NULL)) {
1069 if (count == 0) break; /* ReadFile reports success on EOF! */
1071 WCMD_output_asis (buffer);
1076 /****************************************************************************
1079 * Display verify flag.
1080 * FIXME: We don't actually do anything with the verify flag other than toggle
1084 void WCMD_verify (char *command) {
1086 static const char von[] = "Verify is ON\n", voff[] = "Verify is OFF\n";
1089 count = strlen(command);
1091 if (verify_mode) WCMD_output (von);
1092 else WCMD_output (voff);
1095 if (lstrcmpi(command, "ON") == 0) {
1099 else if (lstrcmpi(command, "OFF") == 0) {
1103 else WCMD_output ("Verify must be ON or OFF\n");
1106 /****************************************************************************
1109 * Display version info.
1112 void WCMD_version (void) {
1114 WCMD_output (version_string);
1118 /****************************************************************************
1121 * Display volume info and/or set volume label. Returns 0 if error.
1124 int WCMD_volume (int mode, char *path) {
1126 DWORD count, serial;
1127 char string[MAX_PATH], label[MAX_PATH], curdir[MAX_PATH];
1130 if (lstrlen(path) == 0) {
1131 status = GetCurrentDirectory (sizeof(curdir), curdir);
1133 WCMD_print_error ();
1136 status = GetVolumeInformation (NULL, label, sizeof(label), &serial, NULL,
1140 if ((path[1] != ':') || (lstrlen(path) != 2)) {
1141 WCMD_output_asis("Syntax Error\n\n");
1144 wsprintf (curdir, "%s\\", path);
1145 status = GetVolumeInformation (curdir, label, sizeof(label), &serial, NULL,
1149 WCMD_print_error ();
1152 WCMD_output ("Volume in drive %c is %s\nVolume Serial Number is %04x-%04x\n\n",
1153 curdir[0], label, HIWORD(serial), LOWORD(serial));
1155 WCMD_output ("Volume label (11 characters, ENTER for none)?");
1156 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
1158 string[count-1] = '\0'; /* ReadFile output is not null-terminated! */
1159 if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */
1161 if (lstrlen(path) != 0) {
1162 if (!SetVolumeLabel (curdir, string)) WCMD_print_error ();
1165 if (!SetVolumeLabel (NULL, string)) WCMD_print_error ();
1171 /**************************************************************************
1174 * Exit either the process, or just this batch program
1178 void WCMD_exit (void) {
1180 int rc = atoi(param1); /* Note: atoi of empty parameter is 0 */
1182 if (context && lstrcmpi(quals, "/B") == 0) {
1184 context -> skip_rest = TRUE;