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) {
436 SetFilePointer (context -> h, 0, NULL, FILE_BEGIN);
437 while (WCMD_fgets (string, sizeof(string), context -> h)) {
438 if ((string[0] == ':') && (lstrcmpi (&string[1], param1) == 0)) return;
440 WCMD_output ("Target to GOTO not found\n");
446 /****************************************************************************
449 * Batch file conditional.
450 * FIXME: Much more syntax checking needed!
453 void WCMD_if (char *p) {
455 int negate = 0, test = 0;
456 char condition[MAX_PATH], *command, *s;
458 if (!lstrcmpi (param1, "not")) {
460 lstrcpy (condition, param2);
463 lstrcpy (condition, param1);
465 if (!lstrcmpi (condition, "errorlevel")) {
466 if (errorlevel >= atoi(WCMD_parameter (p, 1+negate, NULL))) test = 1;
467 WCMD_parameter (p, 2+negate, &command);
469 else if (!lstrcmpi (condition, "exist")) {
470 if (GetFileAttributesA(WCMD_parameter (p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES) {
473 WCMD_parameter (p, 2+negate, &command);
475 else if ((s = strstr (p, "=="))) {
477 if (!lstrcmpi (condition, WCMD_parameter (s, 0, NULL))) test = 1;
478 WCMD_parameter (s, 1, &command);
481 WCMD_output ("Syntax error\n");
484 if (test != negate) {
485 command = strdup (command);
486 WCMD_process_command (command);
491 /****************************************************************************
494 * Move a file, directory tree or wildcarded set of files.
495 * FIXME: Needs input and output files to be fully specified.
498 void WCMD_move (void) {
501 char outpath[MAX_PATH], inpath[MAX_PATH], *infile;
505 if (param1[0] == 0x00) {
506 WCMD_output ("Argument missing\n");
510 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
511 WCMD_output ("Wildcards not yet supported\n");
515 /* If no destination supplied, assume current directory */
516 if (param2[0] == 0x00) {
520 /* If 2nd parm is directory, then use original filename */
521 GetFullPathName (param2, sizeof(outpath), outpath, NULL);
522 hff = FindFirstFile (outpath, &fd);
523 if (hff != INVALID_HANDLE_VALUE) {
524 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
525 GetFullPathName (param1, sizeof(inpath), inpath, &infile);
526 strcat (outpath, "\\");
527 strcat (outpath, infile);
532 status = MoveFile (param1, outpath);
533 if (!status) WCMD_print_error ();
536 /****************************************************************************
539 * Wait for keyboard input.
542 void WCMD_pause (void) {
547 WCMD_output (anykey);
548 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
551 /****************************************************************************
554 * Delete a directory.
557 void WCMD_remove_dir (void) {
559 if (param1[0] == 0x00) {
560 WCMD_output ("Argument missing\n");
563 if (!RemoveDirectory (param1)) WCMD_print_error ();
566 /****************************************************************************
570 * FIXME: Needs input and output files to be fully specified.
573 void WCMD_rename (void) {
577 if (param1[0] == 0x00 || param2[0] == 0x00) {
578 WCMD_output ("Argument missing\n");
581 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
582 WCMD_output ("Wildcards not yet supported\n");
585 status = MoveFile (param1, param2);
586 if (!status) WCMD_print_error ();
589 /*****************************************************************************
592 * Make a copy of the environment.
594 static WCHAR *WCMD_dupenv( const WCHAR *env )
604 len += (lstrlenW(&env[len]) + 1);
606 env_copy = LocalAlloc (LMEM_FIXED, (len+1) * sizeof (WCHAR) );
609 WCMD_output ("out of memory\n");
612 memcpy (env_copy, env, len*sizeof (WCHAR));
618 /*****************************************************************************
621 * setlocal pushes the environment onto a stack
622 * Save the environment as unicode so we don't screw anything up.
624 void WCMD_setlocal (const char *s) {
626 struct env_stack *env_copy;
628 /* DISABLEEXTENSIONS ignored */
630 env_copy = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack));
633 WCMD_output ("out of memory\n");
637 env = GetEnvironmentStringsW ();
639 env_copy->strings = WCMD_dupenv (env);
640 if (env_copy->strings)
642 env_copy->next = saved_environment;
643 saved_environment = env_copy;
646 LocalFree (env_copy);
648 FreeEnvironmentStringsW (env);
651 /*****************************************************************************
654 static inline WCHAR *WCMD_strchrW(WCHAR *str, WCHAR ch)
665 /*****************************************************************************
668 * endlocal pops the environment off a stack
670 void WCMD_endlocal (void) {
671 WCHAR *env, *old, *p;
672 struct env_stack *temp;
675 if (!saved_environment)
678 /* pop the old environment from the stack */
679 temp = saved_environment;
680 saved_environment = temp->next;
682 /* delete the current environment, totally */
683 env = GetEnvironmentStringsW ();
684 old = WCMD_dupenv (GetEnvironmentStringsW ());
687 n = lstrlenW(&old[len]) + 1;
688 p = WCMD_strchrW(&old[len], '=');
692 SetEnvironmentVariableW (&old[len], NULL);
697 FreeEnvironmentStringsW (env);
699 /* restore old environment */
703 n = lstrlenW(&env[len]) + 1;
704 p = WCMD_strchrW(&env[len], '=');
708 SetEnvironmentVariableW (&env[len], p);
716 /*****************************************************************************
717 * WCMD_setshow_attrib
719 * Display and optionally sets DOS attributes on a file or directory
721 * FIXME: Wine currently uses the Unix stat() function to get file attributes.
722 * As a result only the Readonly flag is correctly reported, the Archive bit
723 * is always set and the rest are not implemented. We do the Right Thing anyway.
725 * FIXME: No SET functionality.
729 void WCMD_setshow_attrib (void) {
734 char flags[9] = {" "};
736 if (param1[0] == '-') {
741 if (lstrlen(param1) == 0) {
742 GetCurrentDirectory (sizeof(param1), param1);
743 strcat (param1, "\\*");
746 hff = FindFirstFile (param1, &fd);
747 if (hff == INVALID_HANDLE_VALUE) {
748 WCMD_output ("%s: File Not Found\n",param1);
752 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
753 if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
756 if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
759 if (fd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
762 if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
765 if (fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) {
768 if (fd.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) {
771 WCMD_output ("%s %s\n", flags, fd.cFileName);
772 for (count=0; count < 8; count++) flags[count] = ' ';
774 } while (FindNextFile(hff, &fd) != 0);
779 /*****************************************************************************
780 * WCMD_setshow_default
782 * Set/Show the current default directory
785 void WCMD_setshow_default (void) {
790 if (strlen(param1) == 0) {
791 GetCurrentDirectory (sizeof(string), string);
792 strcat (string, "\n");
793 WCMD_output (string);
796 status = SetCurrentDirectory (param1);
805 /****************************************************************************
808 * Set/Show the system date
809 * FIXME: Can't change date yet
812 void WCMD_setshow_date (void) {
814 char curdate[64], buffer[64];
817 if (lstrlen(param1) == 0) {
818 if (GetDateFormat (LOCALE_USER_DEFAULT, 0, NULL, NULL,
819 curdate, sizeof(curdate))) {
820 WCMD_output ("Current Date is %s\nEnter new date: ", curdate);
821 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
826 else WCMD_print_error ();
833 /****************************************************************************
836 static int WCMD_compare( const void *a, const void *b )
839 const char * const *str_a = a, * const *str_b = b;
840 r = CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
841 *str_a, -1, *str_b, -1 );
842 if( r == CSTR_LESS_THAN ) return -1;
843 if( r == CSTR_GREATER_THAN ) return 1;
847 /****************************************************************************
848 * WCMD_setshow_sortenv
850 * sort variables into order for display
852 static void WCMD_setshow_sortenv(const char *s)
854 UINT count=0, len=0, i;
857 /* count the number of strings, and the total length */
859 len += (lstrlen(&s[len]) + 1);
863 /* add the strings to an array */
864 str = LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, count * sizeof (char*) );
868 for( i=1; i<count; i++ )
869 str[i] = str[i-1] + lstrlen(str[i-1]) + 1;
872 qsort( str, count, sizeof (char*), WCMD_compare );
875 for( i=0; i<count; i++ ) {
876 WCMD_output_asis(str[i]);
877 WCMD_output_asis("\n");
883 /****************************************************************************
886 * Set/Show the environment variables
889 void WCMD_setshow_env (char *s) {
896 if (strlen(param1) == 0) {
897 env = GetEnvironmentStrings ();
898 WCMD_setshow_sortenv( env );
904 /* FIXME: Emulate Win98 for now, ie "SET C" looks ONLY for an
905 environment variable C, whereas on NT it shows ALL variables
908 status = GetEnvironmentVariable(s, buffer, sizeof(buffer));
910 WCMD_output_asis( s);
911 WCMD_output_asis( "=");
912 WCMD_output_asis( buffer);
913 WCMD_output_asis( "\n");
915 WCMD_output ("Environment variable %s not defined\n", s);
921 if (strlen(p) == 0) p = NULL;
922 status = SetEnvironmentVariable (s, p);
923 if ((!status) & (GetLastError() != ERROR_ENVVAR_NOT_FOUND)) WCMD_print_error();
925 /* WCMD_output (newline); @JED*/
928 /****************************************************************************
931 * Set/Show the path environment variable
934 void WCMD_setshow_path (char *command) {
939 if (strlen(param1) == 0) {
940 status = GetEnvironmentVariable ("PATH", string, sizeof(string));
942 WCMD_output_asis ( "PATH=");
943 WCMD_output_asis ( string);
944 WCMD_output_asis ( "\n");
947 WCMD_output ("PATH not found\n");
951 status = SetEnvironmentVariable ("PATH", command);
952 if (!status) WCMD_print_error();
956 /****************************************************************************
957 * WCMD_setshow_prompt
959 * Set or show the command prompt.
962 void WCMD_setshow_prompt (void) {
966 if (strlen(param1) == 0) {
967 SetEnvironmentVariable ("PROMPT", NULL);
971 while ((*s == '=') || (*s == ' ')) s++;
972 if (strlen(s) == 0) {
973 SetEnvironmentVariable ("PROMPT", NULL);
975 else SetEnvironmentVariable ("PROMPT", s);
979 /****************************************************************************
982 * Set/Show the system time
983 * FIXME: Can't change time yet
986 void WCMD_setshow_time (void) {
988 char curtime[64], buffer[64];
992 if (strlen(param1) == 0) {
994 if (GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, NULL,
995 curtime, sizeof(curtime))) {
996 WCMD_output ("Current Time is %s\nEnter new time: ", curtime);
997 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
1002 else WCMD_print_error ();
1009 /****************************************************************************
1012 * Shift batch parameters.
1015 void WCMD_shift (void) {
1017 if (context != NULL) context -> shift_count++;
1021 /****************************************************************************
1024 * Set the console title
1026 void WCMD_title (char *command) {
1027 SetConsoleTitle(command);
1030 /****************************************************************************
1033 * Copy a file to standard output.
1036 void WCMD_type (void) {
1042 if (param1[0] == 0x00) {
1043 WCMD_output ("Argument missing\n");
1046 h = CreateFile (param1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1047 FILE_ATTRIBUTE_NORMAL, NULL);
1048 if (h == INVALID_HANDLE_VALUE) {
1049 WCMD_print_error ();
1052 while (ReadFile (h, buffer, sizeof(buffer), &count, NULL)) {
1053 if (count == 0) break; /* ReadFile reports success on EOF! */
1055 WCMD_output_asis (buffer);
1060 /****************************************************************************
1063 * Display verify flag.
1064 * FIXME: We don't actually do anything with the verify flag other than toggle
1068 void WCMD_verify (char *command) {
1070 static const char von[] = "Verify is ON\n", voff[] = "Verify is OFF\n";
1073 count = strlen(command);
1075 if (verify_mode) WCMD_output (von);
1076 else WCMD_output (voff);
1079 if (lstrcmpi(command, "ON") == 0) {
1083 else if (lstrcmpi(command, "OFF") == 0) {
1087 else WCMD_output ("Verify must be ON or OFF\n");
1090 /****************************************************************************
1093 * Display version info.
1096 void WCMD_version (void) {
1098 WCMD_output (version_string);
1102 /****************************************************************************
1105 * Display volume info and/or set volume label. Returns 0 if error.
1108 int WCMD_volume (int mode, char *path) {
1110 DWORD count, serial;
1111 char string[MAX_PATH], label[MAX_PATH], curdir[MAX_PATH];
1114 if (lstrlen(path) == 0) {
1115 status = GetCurrentDirectory (sizeof(curdir), curdir);
1117 WCMD_print_error ();
1120 status = GetVolumeInformation (NULL, label, sizeof(label), &serial, NULL,
1124 if ((path[1] != ':') || (lstrlen(path) != 2)) {
1125 WCMD_output_asis("Syntax Error\n\n");
1128 wsprintf (curdir, "%s\\", path);
1129 status = GetVolumeInformation (curdir, label, sizeof(label), &serial, NULL,
1133 WCMD_print_error ();
1136 WCMD_output ("Volume in drive %c is %s\nVolume Serial Number is %04x-%04x\n\n",
1137 curdir[0], label, HIWORD(serial), LOWORD(serial));
1139 WCMD_output ("Volume label (11 characters, ENTER for none)?");
1140 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
1142 string[count-1] = '\0'; /* ReadFile output is not null-terminated! */
1143 if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */
1145 if (lstrlen(path) != 0) {
1146 if (!SetVolumeLabel (curdir, string)) WCMD_print_error ();
1149 if (!SetVolumeLabel (NULL, string)) WCMD_print_error ();