2 * WCMD - 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
37 void WCMD_execute (char *orig_command
, char *parameter
, char *substitution
);
41 struct env_stack
*next
;
45 struct env_stack
*saved_environment
;
47 extern HINSTANCE hinst
;
48 extern char *inbuilt
[];
49 extern int echo_mode
, verify_mode
;
50 extern char quals
[MAX_PATH
], param1
[MAX_PATH
], param2
[MAX_PATH
];
51 extern BATCH_CONTEXT
*context
;
52 extern DWORD errorlevel
;
56 /****************************************************************************
59 * Clear the terminal screen.
62 void WCMD_clear_screen (void) {
64 /* Emulate by filling the screen from the top left to bottom right with
65 spaces, then moving the cursor to the top left afterwards */
66 CONSOLE_SCREEN_BUFFER_INFO consoleInfo
;
67 HANDLE hStdOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
69 if (GetConsoleScreenBufferInfo(hStdOut
, &consoleInfo
))
74 screenSize
= consoleInfo
.dwSize
.X
* (consoleInfo
.dwSize
.Y
+ 1);
78 FillConsoleOutputCharacter(hStdOut
, ' ', screenSize
, topLeft
, &screenSize
);
79 SetConsoleCursorPosition(hStdOut
, topLeft
);
83 /****************************************************************************
86 * Change the default i/o device (ie redirect STDin/STDout).
89 void WCMD_change_tty (void) {
95 /****************************************************************************
98 * Copy a file or wildcarded set.
99 * FIXME: No wildcard support
102 void WCMD_copy (void) {
108 static const char overwrite
[] = "Overwrite file (Y/N)?";
109 char string
[8], outpath
[MAX_PATH
], inpath
[MAX_PATH
], *infile
;
111 if ((strchr(param1
,'*') != NULL
) && (strchr(param1
,'%') != NULL
)) {
112 WCMD_output ("Wildcards not yet supported\n");
116 /* If no destination supplied, assume current directory */
117 if (param2
[0] == 0x00) {
121 GetFullPathName (param2
, sizeof(outpath
), outpath
, NULL
);
122 hff
= FindFirstFile (outpath
, &fd
);
123 if (hff
!= INVALID_HANDLE_VALUE
) {
124 if (fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
125 GetFullPathName (param1
, sizeof(inpath
), inpath
, &infile
);
126 strcat (outpath
, "\\");
127 strcat (outpath
, infile
);
132 force
= (strstr (quals
, "/Y") != NULL
);
134 hff
= FindFirstFile (outpath
, &fd
);
135 if (hff
!= INVALID_HANDLE_VALUE
) {
137 WCMD_output (overwrite
);
138 ReadFile (GetStdHandle(STD_INPUT_HANDLE
), string
, sizeof(string
), &count
, NULL
);
139 if (toupper(string
[0]) == 'Y') force
= TRUE
;
144 status
= CopyFile (param1
, outpath
, FALSE
);
145 if (!status
) WCMD_print_error ();
149 /****************************************************************************
152 * Create a directory.
154 * this works recursivly. so mkdir dir1\dir2\dir3 will create dir1 and dir2 if
155 * they do not already exist.
158 BOOL
create_full_path(CHAR
* path
)
164 new_path
= HeapAlloc(GetProcessHeap(),0,strlen(path
)+1);
165 strcpy(new_path
,path
);
167 while ((len
= strlen(new_path
)) && new_path
[len
- 1] == '\\')
168 new_path
[len
- 1] = 0;
170 while (!CreateDirectory(new_path
,NULL
))
173 DWORD last_error
= GetLastError();
174 if (last_error
== ERROR_ALREADY_EXISTS
)
177 if (last_error
!= ERROR_PATH_NOT_FOUND
)
183 if (!(slash
= strrchr(new_path
,'\\')) && ! (slash
= strrchr(new_path
,'/')))
189 len
= slash
- new_path
;
191 if (!create_full_path(new_path
))
196 new_path
[len
] = '\\';
198 HeapFree(GetProcessHeap(),0,new_path
);
202 void WCMD_create_dir (void) {
204 if (!create_full_path(param1
)) WCMD_print_error ();
207 /****************************************************************************
210 * Delete a file or wildcarded set.
214 void WCMD_delete (int recurse
) {
218 char fpath
[MAX_PATH
];
221 hff
= FindFirstFile (param1
, &fd
);
222 if (hff
== INVALID_HANDLE_VALUE
) {
223 WCMD_output ("%s :File Not Found\n",param1
);
226 if ((strchr(param1
,'*') == NULL
) && (strchr(param1
,'?') == NULL
)
227 && (!recurse
) && (fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
228 strcat (param1
, "\\*");
233 if ((strchr(param1
,'*') != NULL
) || (strchr(param1
,'?') != NULL
)) {
234 strcpy (fpath
, param1
);
236 p
= strrchr (fpath
, '\\');
239 strcat (fpath
, fd
.cFileName
);
241 else strcpy (fpath
, fd
.cFileName
);
242 if (!(fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
243 if (!DeleteFile (fpath
)) WCMD_print_error ();
245 } while (FindNextFile(hff
, &fd
) != 0);
249 if (!DeleteFile (param1
)) WCMD_print_error ();
254 /****************************************************************************
257 * Echo input to the screen (or not). We don't try to emulate the bugs
258 * in DOS (try typing "ECHO ON AGAIN" for an example).
261 void WCMD_echo (const char *command
) {
263 static const char eon
[] = "Echo is ON\n", eoff
[] = "Echo is OFF\n";
266 if ((command
[0] == '.') && (command
[1] == 0)) {
267 WCMD_output (newline
);
272 count
= strlen(command
);
274 if (echo_mode
) WCMD_output (eon
);
275 else WCMD_output (eoff
);
278 if (lstrcmpi(command
, "ON") == 0) {
282 if (lstrcmpi(command
, "OFF") == 0) {
286 WCMD_output_asis (command
);
287 WCMD_output (newline
);
291 /**************************************************************************
294 * Batch file loop processing.
295 * FIXME: We don't exhaustively check syntax. Any command which works in MessDOS
296 * will probably work here, but the reverse is not necessarily the case...
299 void WCMD_for (char *p
) {
304 char set
[MAX_PATH
], param
[MAX_PATH
];
307 if (lstrcmpi (WCMD_parameter (p
, 1, NULL
), "in")
308 || lstrcmpi (WCMD_parameter (p
, 3, NULL
), "do")
309 || (param1
[0] != '%')) {
310 WCMD_output ("Syntax error\n");
313 lstrcpyn (set
, WCMD_parameter (p
, 2, NULL
), sizeof(set
));
314 WCMD_parameter (p
, 4, &cmd
);
315 lstrcpy (param
, param1
);
318 * If the parameter within the set has a wildcard then search for matching files
319 * otherwise do a literal substitution.
323 while (*(item
= WCMD_parameter (set
, i
, NULL
))) {
324 if (strpbrk (item
, "*?")) {
325 hff
= FindFirstFile (item
, &fd
);
326 if (hff
== INVALID_HANDLE_VALUE
) {
330 WCMD_execute (cmd
, param
, fd
.cFileName
);
331 } while (FindNextFile(hff
, &fd
) != 0);
335 WCMD_execute (cmd
, param
, item
);
341 /*****************************************************************************
344 * Execute a command after substituting variable text for the supplied parameter
347 void WCMD_execute (char *orig_cmd
, char *param
, char *subst
) {
349 char *new_cmd
, *p
, *s
, *dup
;
352 size
= lstrlen (orig_cmd
);
353 new_cmd
= (char *) LocalAlloc (LMEM_FIXED
| LMEM_ZEROINIT
, size
);
354 dup
= s
= strdup (orig_cmd
);
356 while ((p
= strstr (s
, param
))) {
358 size
+= lstrlen (subst
);
359 new_cmd
= (char *) LocalReAlloc ((HANDLE
)new_cmd
, size
, 0);
361 strcat (new_cmd
, subst
);
362 s
= p
+ lstrlen (param
);
365 WCMD_process_command (new_cmd
);
367 LocalFree ((HANDLE
)new_cmd
);
371 /**************************************************************************
374 * Simple on-line help. Help text is stored in the resource file.
377 void WCMD_give_help (char *command
) {
382 command
= WCMD_strtrim_leading_spaces(command
);
383 if (lstrlen(command
) == 0) {
384 LoadString (hinst
, 1000, buffer
, sizeof(buffer
));
385 WCMD_output_asis (buffer
);
388 for (i
=0; i
<=WCMD_EXIT
; i
++) {
389 if (CompareString (LOCALE_USER_DEFAULT
, NORM_IGNORECASE
| SORT_STRINGSORT
,
390 param1
, -1, inbuilt
[i
], -1) == 2) {
391 LoadString (hinst
, i
, buffer
, sizeof(buffer
));
392 WCMD_output_asis (buffer
);
396 WCMD_output ("No help available for %s\n", param1
);
401 /****************************************************************************
404 * Batch file jump instruction. Not the most efficient algorithm ;-)
405 * Prints error message if the specified label cannot be found - the file pointer is
406 * then at EOF, effectively stopping the batch file.
407 * FIXME: DOS is supposed to allow labels with spaces - we don't.
410 void WCMD_goto (void) {
412 char string
[MAX_PATH
];
414 if (context
!= NULL
) {
415 SetFilePointer (context
-> h
, 0, NULL
, FILE_BEGIN
);
416 while (WCMD_fgets (string
, sizeof(string
), context
-> h
)) {
417 if ((string
[0] == ':') && (strcmp (&string
[1], param1
) == 0)) return;
419 WCMD_output ("Target to GOTO not found\n");
425 /****************************************************************************
428 * Batch file conditional.
429 * FIXME: Much more syntax checking needed!
432 void WCMD_if (char *p
) {
434 int negate
= 0, test
= 0;
435 char condition
[MAX_PATH
], *command
, *s
;
437 if (!lstrcmpi (param1
, "not")) {
439 lstrcpy (condition
, param2
);
442 lstrcpy (condition
, param1
);
444 if (!lstrcmpi (condition
, "errorlevel")) {
445 if (errorlevel
>= atoi(WCMD_parameter (p
, 1+negate
, NULL
))) test
= 1;
447 WCMD_parameter (p
, 2+negate
, &command
);
449 else if (!lstrcmpi (condition
, "exist")) {
450 if (GetFileAttributesA(WCMD_parameter (p
, 1+negate
, NULL
)) != INVALID_FILE_ATTRIBUTES
) {
453 WCMD_parameter (p
, 2+negate
, &command
);
455 else if ((s
= strstr (p
, "=="))) {
457 if (!lstrcmpi (condition
, WCMD_parameter (s
, 0, NULL
))) test
= 1;
458 WCMD_parameter (s
, 1, &command
);
461 WCMD_output ("Syntax error\n");
464 if (test
!= negate
) {
465 command
= strdup (command
);
466 WCMD_process_command (command
);
471 /****************************************************************************
474 * Move a file, directory tree or wildcarded set of files.
475 * FIXME: Needs input and output files to be fully specified.
478 void WCMD_move (void) {
481 char outpath
[MAX_PATH
], inpath
[MAX_PATH
], *infile
;
485 if ((strchr(param1
,'*') != NULL
) || (strchr(param1
,'%') != NULL
)) {
486 WCMD_output ("Wildcards not yet supported\n");
490 /* If no destination supplied, assume current directory */
491 if (param2
[0] == 0x00) {
495 /* If 2nd parm is directory, then use original filename */
496 GetFullPathName (param2
, sizeof(outpath
), outpath
, NULL
);
497 hff
= FindFirstFile (outpath
, &fd
);
498 if (hff
!= INVALID_HANDLE_VALUE
) {
499 if (fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
500 GetFullPathName (param1
, sizeof(inpath
), inpath
, &infile
);
501 strcat (outpath
, "\\");
502 strcat (outpath
, infile
);
507 status
= MoveFile (param1
, outpath
);
508 if (!status
) WCMD_print_error ();
511 /****************************************************************************
514 * Wait for keyboard input.
517 void WCMD_pause (void) {
522 WCMD_output (anykey
);
523 ReadFile (GetStdHandle(STD_INPUT_HANDLE
), string
, sizeof(string
), &count
, NULL
);
526 /****************************************************************************
529 * Delete a directory.
532 void WCMD_remove_dir (void) {
534 if (!RemoveDirectory (param1
)) WCMD_print_error ();
537 /****************************************************************************
541 * FIXME: Needs input and output files to be fully specified.
544 void WCMD_rename (void) {
548 if ((strchr(param1
,'*') != NULL
) || (strchr(param1
,'%') != NULL
)) {
549 WCMD_output ("Wildcards not yet supported\n");
552 status
= MoveFile (param1
, param2
);
553 if (!status
) WCMD_print_error ();
556 /*****************************************************************************
559 * Make a copy of the environment.
561 static WCHAR
*WCMD_dupenv( const WCHAR
*env
)
571 len
+= (lstrlenW(&env
[len
]) + 1);
573 env_copy
= LocalAlloc (LMEM_FIXED
, (len
+1) * sizeof (WCHAR
) );
576 WCMD_output ("out of memory\n");
579 memcpy (env_copy
, env
, len
*sizeof (WCHAR
));
585 /*****************************************************************************
588 * setlocal pushes the environment onto a stack
589 * Save the environment as unicode so we don't screw anything up.
591 void WCMD_setlocal (const char *s
) {
593 struct env_stack
*env_copy
;
595 /* DISABLEEXTENSIONS ignored */
597 env_copy
= LocalAlloc (LMEM_FIXED
, sizeof (struct env_stack
));
600 WCMD_output ("out of memory\n");
604 env
= GetEnvironmentStringsW ();
606 env_copy
->strings
= WCMD_dupenv (env
);
607 if (env_copy
->strings
)
609 env_copy
->next
= saved_environment
;
610 saved_environment
= env_copy
;
613 LocalFree (env_copy
);
615 FreeEnvironmentStringsW (env
);
618 /*****************************************************************************
621 static inline WCHAR
*WCMD_strchrW(WCHAR
*str
, WCHAR ch
)
632 /*****************************************************************************
635 * endlocal pops the environment off a stack
637 void WCMD_endlocal (void) {
638 WCHAR
*env
, *old
, *p
;
639 struct env_stack
*temp
;
642 if (!saved_environment
)
645 /* pop the old environment from the stack */
646 temp
= saved_environment
;
647 saved_environment
= temp
->next
;
649 /* delete the current environment, totally */
650 env
= GetEnvironmentStringsW ();
651 old
= WCMD_dupenv (GetEnvironmentStringsW ());
654 n
= lstrlenW(&old
[len
]) + 1;
655 p
= WCMD_strchrW(&old
[len
], '=');
659 SetEnvironmentVariableW (&old
[len
], NULL
);
664 FreeEnvironmentStringsW (env
);
666 /* restore old environment */
670 n
= lstrlenW(&env
[len
]) + 1;
671 p
= WCMD_strchrW(&env
[len
], '=');
675 SetEnvironmentVariableW (&env
[len
], p
);
683 /*****************************************************************************
684 * WCMD_setshow_attrib
686 * Display and optionally sets DOS attributes on a file or directory
688 * FIXME: Wine currently uses the Unix stat() function to get file attributes.
689 * As a result only the Readonly flag is correctly reported, the Archive bit
690 * is always set and the rest are not implemented. We do the Right Thing anyway.
692 * FIXME: No SET functionality.
696 void WCMD_setshow_attrib (void) {
701 char flags
[9] = {" "};
703 if (param1
[0] == '-') {
708 if (lstrlen(param1
) == 0) {
709 GetCurrentDirectory (sizeof(param1
), param1
);
710 strcat (param1
, "\\*");
713 hff
= FindFirstFile (param1
, &fd
);
714 if (hff
== INVALID_HANDLE_VALUE
) {
715 WCMD_output ("%s: File Not Found\n",param1
);
719 if (!(fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
720 if (fd
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
) {
723 if (fd
.dwFileAttributes
& FILE_ATTRIBUTE_SYSTEM
) {
726 if (fd
.dwFileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) {
729 if (fd
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
) {
732 if (fd
.dwFileAttributes
& FILE_ATTRIBUTE_TEMPORARY
) {
735 if (fd
.dwFileAttributes
& FILE_ATTRIBUTE_COMPRESSED
) {
738 WCMD_output ("%s %s\n", flags
, fd
.cFileName
);
739 for (count
=0; count
< 8; count
++) flags
[count
] = ' ';
741 } while (FindNextFile(hff
, &fd
) != 0);
746 /*****************************************************************************
747 * WCMD_setshow_default
749 * Set/Show the current default directory
752 void WCMD_setshow_default (void) {
757 if (strlen(param1
) == 0) {
758 GetCurrentDirectory (sizeof(string
), string
);
759 strcat (string
, "\n");
760 WCMD_output (string
);
763 status
= SetCurrentDirectory (param1
);
772 /****************************************************************************
775 * Set/Show the system date
776 * FIXME: Can't change date yet
779 void WCMD_setshow_date (void) {
781 char curdate
[64], buffer
[64];
784 if (lstrlen(param1
) == 0) {
785 if (GetDateFormat (LOCALE_USER_DEFAULT
, 0, NULL
, NULL
,
786 curdate
, sizeof(curdate
))) {
787 WCMD_output ("Current Date is %s\nEnter new date: ", curdate
);
788 ReadFile (GetStdHandle(STD_INPUT_HANDLE
), buffer
, sizeof(buffer
), &count
, NULL
);
793 else WCMD_print_error ();
800 /****************************************************************************
803 static int WCMD_compare( const void *a
, const void *b
)
806 const char * const *str_a
= a
, * const *str_b
= b
;
807 r
= CompareString( LOCALE_USER_DEFAULT
, NORM_IGNORECASE
| SORT_STRINGSORT
,
808 *str_a
, -1, *str_b
, -1 );
809 if( r
== CSTR_LESS_THAN
) return -1;
810 if( r
== CSTR_GREATER_THAN
) return 1;
814 /****************************************************************************
815 * WCMD_setshow_sortenv
817 * sort variables into order for display
819 static void WCMD_setshow_sortenv(const char *s
)
821 UINT count
=0, len
=0, i
;
824 /* count the number of strings, and the total length */
826 len
+= (lstrlen(&s
[len
]) + 1);
830 /* add the strings to an array */
831 str
= LocalAlloc (LMEM_FIXED
| LMEM_ZEROINIT
, count
* sizeof (char*) );
835 for( i
=1; i
<count
; i
++ )
836 str
[i
] = str
[i
-1] + lstrlen(str
[i
-1]) + 1;
839 qsort( str
, count
, sizeof (char*), WCMD_compare
);
842 for( i
=0; i
<count
; i
++ ) {
843 WCMD_output_asis(str
[i
]);
844 WCMD_output_asis("\n");
850 /****************************************************************************
853 * Set/Show the environment variables
856 void WCMD_setshow_env (char *s
) {
863 if (strlen(param1
) == 0) {
864 env
= GetEnvironmentStrings ();
865 WCMD_setshow_sortenv( env
);
871 /* FIXME: Emulate Win98 for now, ie "SET C" looks ONLY for an
872 environment variable C, whereas on NT it shows ALL variables
875 status
= GetEnvironmentVariable(s
, buffer
, sizeof(buffer
));
877 WCMD_output_asis( s
);
878 WCMD_output_asis( "=");
879 WCMD_output_asis( buffer
);
880 WCMD_output_asis( "\n");
882 WCMD_output ("Environment variable %s not defined\n", s
);
888 if (strlen(p
) == 0) p
= NULL
;
889 status
= SetEnvironmentVariable (s
, p
);
890 if ((!status
) & (GetLastError() != ERROR_ENVVAR_NOT_FOUND
)) WCMD_print_error();
892 /* WCMD_output (newline); @JED*/
895 /****************************************************************************
898 * Set/Show the path environment variable
901 void WCMD_setshow_path (char *command
) {
906 if (strlen(param1
) == 0) {
907 status
= GetEnvironmentVariable ("PATH", string
, sizeof(string
));
909 WCMD_output_asis ( "PATH=");
910 WCMD_output_asis ( string
);
911 WCMD_output_asis ( "\n");
914 WCMD_output ("PATH not found\n");
918 status
= SetEnvironmentVariable ("PATH", command
);
919 if (!status
) WCMD_print_error();
923 /****************************************************************************
924 * WCMD_setshow_prompt
926 * Set or show the command prompt.
929 void WCMD_setshow_prompt (void) {
933 if (strlen(param1
) == 0) {
934 SetEnvironmentVariable ("PROMPT", NULL
);
938 while ((*s
== '=') || (*s
== ' ')) s
++;
939 if (strlen(s
) == 0) {
940 SetEnvironmentVariable ("PROMPT", NULL
);
942 else SetEnvironmentVariable ("PROMPT", s
);
946 /****************************************************************************
949 * Set/Show the system time
950 * FIXME: Can't change time yet
953 void WCMD_setshow_time (void) {
955 char curtime
[64], buffer
[64];
959 if (strlen(param1
) == 0) {
961 if (GetTimeFormat (LOCALE_USER_DEFAULT
, 0, &st
, NULL
,
962 curtime
, sizeof(curtime
))) {
963 WCMD_output ("Current Time is %s\nEnter new time: ", curtime
);
964 ReadFile (GetStdHandle(STD_INPUT_HANDLE
), buffer
, sizeof(buffer
), &count
, NULL
);
969 else WCMD_print_error ();
976 /****************************************************************************
979 * Shift batch parameters.
982 void WCMD_shift (void) {
984 if (context
!= NULL
) context
-> shift_count
++;
988 /****************************************************************************
991 * Set the console title
993 void WCMD_title (char *command
) {
994 SetConsoleTitle(command
);
997 /****************************************************************************
1000 * Copy a file to standard output.
1003 void WCMD_type (void) {
1009 h
= CreateFile (param1
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1010 FILE_ATTRIBUTE_NORMAL
, NULL
);
1011 if (h
== INVALID_HANDLE_VALUE
) {
1012 WCMD_print_error ();
1015 while (ReadFile (h
, buffer
, sizeof(buffer
), &count
, NULL
)) {
1016 if (count
== 0) break; /* ReadFile reports success on EOF! */
1018 WCMD_output_asis (buffer
);
1023 /****************************************************************************
1026 * Display verify flag.
1027 * FIXME: We don't actually do anything with the verify flag other than toggle
1031 void WCMD_verify (char *command
) {
1033 static const char von
[] = "Verify is ON\n", voff
[] = "Verify is OFF\n";
1036 count
= strlen(command
);
1038 if (verify_mode
) WCMD_output (von
);
1039 else WCMD_output (voff
);
1042 if (lstrcmpi(command
, "ON") == 0) {
1046 else if (lstrcmpi(command
, "OFF") == 0) {
1050 else WCMD_output ("Verify must be ON or OFF\n");
1053 /****************************************************************************
1056 * Display version info.
1059 void WCMD_version (void) {
1061 WCMD_output (version_string
);
1065 /****************************************************************************
1068 * Display volume info and/or set volume label. Returns 0 if error.
1071 int WCMD_volume (int mode
, char *path
) {
1073 DWORD count
, serial
;
1074 char string
[MAX_PATH
], label
[MAX_PATH
], curdir
[MAX_PATH
];
1077 if (lstrlen(path
) == 0) {
1078 status
= GetCurrentDirectory (sizeof(curdir
), curdir
);
1080 WCMD_print_error ();
1083 status
= GetVolumeInformation (NULL
, label
, sizeof(label
), &serial
, NULL
,
1087 if ((path
[1] != ':') || (lstrlen(path
) != 2)) {
1088 WCMD_output_asis("Syntax Error\n\n");
1091 wsprintf (curdir
, "%s\\", path
);
1092 status
= GetVolumeInformation (curdir
, label
, sizeof(label
), &serial
, NULL
,
1096 WCMD_print_error ();
1099 WCMD_output ("Volume in drive %c is %s\nVolume Serial Number is %04x-%04x\n\n",
1100 curdir
[0], label
, HIWORD(serial
), LOWORD(serial
));
1102 WCMD_output ("Volume label (11 characters, ENTER for none)?");
1103 ReadFile (GetStdHandle(STD_INPUT_HANDLE
), string
, sizeof(string
), &count
, NULL
);
1105 string
[count
-1] = '\0'; /* ReadFile output is not null-terminated! */
1106 if (string
[count
-2] == '\r') string
[count
-2] = '\0'; /* Under Windoze we get CRLF! */
1108 if (lstrlen(path
) != 0) {
1109 if (!SetVolumeLabel (curdir
, string
)) WCMD_print_error ();
1112 if (!SetVolumeLabel (NULL
, string
)) WCMD_print_error ();