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;
48 struct env_stack *pushd_directories;
50 extern HINSTANCE hinst;
51 extern char *inbuilt[];
52 extern int echo_mode, verify_mode;
53 extern char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH];
54 extern BATCH_CONTEXT *context;
55 extern DWORD errorlevel;
59 /****************************************************************************
62 * Clear the terminal screen.
65 void WCMD_clear_screen (void) {
67 /* Emulate by filling the screen from the top left to bottom right with
68 spaces, then moving the cursor to the top left afterwards */
69 CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
70 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
72 if (GetConsoleScreenBufferInfo(hStdOut, &consoleInfo))
77 screenSize = consoleInfo.dwSize.X * (consoleInfo.dwSize.Y + 1);
81 FillConsoleOutputCharacter(hStdOut, ' ', screenSize, topLeft, &screenSize);
82 SetConsoleCursorPosition(hStdOut, topLeft);
86 /****************************************************************************
89 * Change the default i/o device (ie redirect STDin/STDout).
92 void WCMD_change_tty (void) {
98 /****************************************************************************
101 * Copy a file or wildcarded set.
102 * FIXME: No wildcard support
105 void WCMD_copy (void) {
111 static const char overwrite[] = "Overwrite file (Y/N)?";
112 char string[8], outpath[MAX_PATH], inpath[MAX_PATH], *infile;
114 if (param1[0] == 0x00) {
115 WCMD_output ("Argument missing\n");
119 if ((strchr(param1,'*') != NULL) && (strchr(param1,'%') != NULL)) {
120 WCMD_output ("Wildcards not yet supported\n");
124 /* If no destination supplied, assume current directory */
125 if (param2[0] == 0x00) {
129 GetFullPathName (param2, sizeof(outpath), outpath, NULL);
130 if (outpath[strlen(outpath) - 1] == '\\')
131 outpath[strlen(outpath) - 1] = '\0';
132 hff = FindFirstFile (outpath, &fd);
133 if (hff != INVALID_HANDLE_VALUE) {
134 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
135 GetFullPathName (param1, sizeof(inpath), inpath, &infile);
136 strcat (outpath, "\\");
137 strcat (outpath, infile);
142 force = (strstr (quals, "/Y") != NULL);
144 hff = FindFirstFile (outpath, &fd);
145 if (hff != INVALID_HANDLE_VALUE) {
147 WCMD_output (overwrite);
148 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
149 if (toupper(string[0]) == 'Y') force = TRUE;
154 status = CopyFile (param1, outpath, FALSE);
155 if (!status) WCMD_print_error ();
159 /****************************************************************************
162 * Create a directory.
164 * this works recursivly. so mkdir dir1\dir2\dir3 will create dir1 and dir2 if
165 * they do not already exist.
168 BOOL create_full_path(CHAR* path)
174 new_path = HeapAlloc(GetProcessHeap(),0,strlen(path)+1);
175 strcpy(new_path,path);
177 while ((len = strlen(new_path)) && new_path[len - 1] == '\\')
178 new_path[len - 1] = 0;
180 while (!CreateDirectory(new_path,NULL))
183 DWORD last_error = GetLastError();
184 if (last_error == ERROR_ALREADY_EXISTS)
187 if (last_error != ERROR_PATH_NOT_FOUND)
193 if (!(slash = strrchr(new_path,'\\')) && ! (slash = strrchr(new_path,'/')))
199 len = slash - new_path;
201 if (!create_full_path(new_path))
206 new_path[len] = '\\';
208 HeapFree(GetProcessHeap(),0,new_path);
212 void WCMD_create_dir (void) {
214 if (param1[0] == 0x00) {
215 WCMD_output ("Argument missing\n");
218 if (!create_full_path(param1)) WCMD_print_error ();
221 /****************************************************************************
224 * Delete a file or wildcarded set.
228 void WCMD_delete (int recurse) {
232 char fpath[MAX_PATH];
235 if (param1[0] == 0x00) {
236 WCMD_output ("Argument missing\n");
239 hff = FindFirstFile (param1, &fd);
240 if (hff == INVALID_HANDLE_VALUE) {
241 WCMD_output ("%s :File Not Found\n",param1);
244 if ((strchr(param1,'*') == NULL) && (strchr(param1,'?') == NULL)
245 && (!recurse) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
246 strcat (param1, "\\*");
251 if ((strchr(param1,'*') != NULL) || (strchr(param1,'?') != NULL)) {
252 strcpy (fpath, param1);
254 p = strrchr (fpath, '\\');
257 strcat (fpath, fd.cFileName);
259 else strcpy (fpath, fd.cFileName);
260 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
261 if (!DeleteFile (fpath)) WCMD_print_error ();
263 } while (FindNextFile(hff, &fd) != 0);
267 if (!DeleteFile (param1)) WCMD_print_error ();
272 /****************************************************************************
275 * Echo input to the screen (or not). We don't try to emulate the bugs
276 * in DOS (try typing "ECHO ON AGAIN" for an example).
279 void WCMD_echo (const char *command) {
281 static const char eon[] = "Echo is ON\n", eoff[] = "Echo is OFF\n";
284 if ((command[0] == '.') && (command[1] == 0)) {
285 WCMD_output (newline);
290 count = strlen(command);
292 if (echo_mode) WCMD_output (eon);
293 else WCMD_output (eoff);
296 if (lstrcmpi(command, "ON") == 0) {
300 if (lstrcmpi(command, "OFF") == 0) {
304 WCMD_output_asis (command);
305 WCMD_output (newline);
309 /**************************************************************************
312 * Batch file loop processing.
313 * FIXME: We don't exhaustively check syntax. Any command which works in MessDOS
314 * will probably work here, but the reverse is not necessarily the case...
317 void WCMD_for (char *p) {
322 char set[MAX_PATH], param[MAX_PATH];
325 if (lstrcmpi (WCMD_parameter (p, 1, NULL), "in")
326 || lstrcmpi (WCMD_parameter (p, 3, NULL), "do")
327 || (param1[0] != '%')) {
328 WCMD_output ("Syntax error\n");
331 lstrcpyn (set, WCMD_parameter (p, 2, NULL), sizeof(set));
332 WCMD_parameter (p, 4, &cmd);
333 lstrcpy (param, param1);
336 * If the parameter within the set has a wildcard then search for matching files
337 * otherwise do a literal substitution.
341 while (*(item = WCMD_parameter (set, i, NULL))) {
342 if (strpbrk (item, "*?")) {
343 hff = FindFirstFile (item, &fd);
344 if (hff == INVALID_HANDLE_VALUE) {
348 WCMD_execute (cmd, param, fd.cFileName);
349 } while (FindNextFile(hff, &fd) != 0);
353 WCMD_execute (cmd, param, item);
359 /*****************************************************************************
362 * Execute a command after substituting variable text for the supplied parameter
365 void WCMD_execute (char *orig_cmd, char *param, char *subst) {
367 char *new_cmd, *p, *s, *dup;
370 size = lstrlen (orig_cmd);
371 new_cmd = (char *) LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, size);
372 dup = s = strdup (orig_cmd);
374 while ((p = strstr (s, param))) {
376 size += lstrlen (subst);
377 new_cmd = (char *) LocalReAlloc ((HANDLE)new_cmd, size, 0);
379 strcat (new_cmd, subst);
380 s = p + lstrlen (param);
383 WCMD_process_command (new_cmd);
385 LocalFree ((HANDLE)new_cmd);
389 /**************************************************************************
392 * Simple on-line help. Help text is stored in the resource file.
395 void WCMD_give_help (char *command) {
400 command = WCMD_strtrim_leading_spaces(command);
401 if (lstrlen(command) == 0) {
402 LoadString (hinst, 1000, buffer, sizeof(buffer));
403 WCMD_output_asis (buffer);
406 for (i=0; i<=WCMD_EXIT; i++) {
407 if (CompareString (LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
408 param1, -1, inbuilt[i], -1) == 2) {
409 LoadString (hinst, i, buffer, sizeof(buffer));
410 WCMD_output_asis (buffer);
414 WCMD_output ("No help available for %s\n", param1);
419 /****************************************************************************
422 * Batch file jump instruction. Not the most efficient algorithm ;-)
423 * Prints error message if the specified label cannot be found - the file pointer is
424 * then at EOF, effectively stopping the batch file.
425 * FIXME: DOS is supposed to allow labels with spaces - we don't.
428 void WCMD_goto (void) {
430 char string[MAX_PATH];
432 if (param1[0] == 0x00) {
433 WCMD_output ("Argument missing\n");
436 if (context != NULL) {
438 /* Handle special :EOF label */
439 if (lstrcmpi (":eof", param1) == 0) {
440 context -> skip_rest = TRUE;
444 SetFilePointer (context -> h, 0, NULL, FILE_BEGIN);
445 while (WCMD_fgets (string, sizeof(string), context -> h)) {
446 if ((string[0] == ':') && (lstrcmpi (&string[1], param1) == 0)) return;
448 WCMD_output ("Target to GOTO not found\n");
453 /*****************************************************************************
456 * Push a directory onto the stack
459 void WCMD_pushd (void) {
460 struct env_stack *curdir;
464 curdir = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack));
465 thisdir = LocalAlloc (LMEM_FIXED, 1024 * sizeof(WCHAR));
466 if( !curdir || !thisdir ) {
469 WCMD_output ("out of memory\n");
473 GetCurrentDirectoryW (1024, thisdir);
474 status = SetCurrentDirectoryA (param1);
481 curdir -> next = pushd_directories;
482 curdir -> strings = thisdir;
483 pushd_directories = curdir;
488 /*****************************************************************************
491 * Pop a directory from the stack
494 void WCMD_popd (void) {
495 struct env_stack *temp = pushd_directories;
497 if (!pushd_directories)
500 /* pop the old environment from the stack, and make it the current dir */
501 pushd_directories = temp->next;
502 SetCurrentDirectoryW(temp->strings);
503 LocalFree (temp->strings);
507 /****************************************************************************
510 * Batch file conditional.
511 * FIXME: Much more syntax checking needed!
514 void WCMD_if (char *p) {
516 int negate = 0, test = 0;
517 char condition[MAX_PATH], *command, *s;
519 if (!lstrcmpi (param1, "not")) {
521 lstrcpy (condition, param2);
524 lstrcpy (condition, param1);
526 if (!lstrcmpi (condition, "errorlevel")) {
527 if (errorlevel >= atoi(WCMD_parameter (p, 1+negate, NULL))) test = 1;
528 WCMD_parameter (p, 2+negate, &command);
530 else if (!lstrcmpi (condition, "exist")) {
531 if (GetFileAttributesA(WCMD_parameter (p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES) {
534 WCMD_parameter (p, 2+negate, &command);
536 else if (!lstrcmpi (condition, "defined")) {
537 if (GetEnvironmentVariableA(WCMD_parameter (p, 1+negate, NULL), NULL, 0) > 0) {
540 WCMD_parameter (p, 2+negate, &command);
542 else if ((s = strstr (p, "=="))) {
544 if (!lstrcmpi (condition, WCMD_parameter (s, 0, NULL))) test = 1;
545 WCMD_parameter (s, 1, &command);
548 WCMD_output ("Syntax error\n");
551 if (test != negate) {
552 command = strdup (command);
553 WCMD_process_command (command);
558 /****************************************************************************
561 * Move a file, directory tree or wildcarded set of files.
562 * FIXME: Needs input and output files to be fully specified.
565 void WCMD_move (void) {
568 char outpath[MAX_PATH], inpath[MAX_PATH], *infile;
572 if (param1[0] == 0x00) {
573 WCMD_output ("Argument missing\n");
577 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
578 WCMD_output ("Wildcards not yet supported\n");
582 /* If no destination supplied, assume current directory */
583 if (param2[0] == 0x00) {
587 /* If 2nd parm is directory, then use original filename */
588 GetFullPathName (param2, sizeof(outpath), outpath, NULL);
589 if (outpath[strlen(outpath) - 1] == '\\')
590 outpath[strlen(outpath) - 1] = '\0';
591 hff = FindFirstFile (outpath, &fd);
592 if (hff != INVALID_HANDLE_VALUE) {
593 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
594 GetFullPathName (param1, sizeof(inpath), inpath, &infile);
595 strcat (outpath, "\\");
596 strcat (outpath, infile);
601 status = MoveFile (param1, outpath);
602 if (!status) WCMD_print_error ();
605 /****************************************************************************
608 * Wait for keyboard input.
611 void WCMD_pause (void) {
616 WCMD_output (anykey);
617 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
620 /****************************************************************************
623 * Delete a directory.
626 void WCMD_remove_dir (void) {
628 if (param1[0] == 0x00) {
629 WCMD_output ("Argument missing\n");
632 if (!RemoveDirectory (param1)) WCMD_print_error ();
635 /****************************************************************************
639 * FIXME: Needs input and output files to be fully specified.
642 void WCMD_rename (void) {
646 if (param1[0] == 0x00 || param2[0] == 0x00) {
647 WCMD_output ("Argument missing\n");
650 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
651 WCMD_output ("Wildcards not yet supported\n");
654 status = MoveFile (param1, param2);
655 if (!status) WCMD_print_error ();
658 /*****************************************************************************
661 * Make a copy of the environment.
663 static WCHAR *WCMD_dupenv( const WCHAR *env )
673 len += (lstrlenW(&env[len]) + 1);
675 env_copy = LocalAlloc (LMEM_FIXED, (len+1) * sizeof (WCHAR) );
678 WCMD_output ("out of memory\n");
681 memcpy (env_copy, env, len*sizeof (WCHAR));
687 /*****************************************************************************
690 * setlocal pushes the environment onto a stack
691 * Save the environment as unicode so we don't screw anything up.
693 void WCMD_setlocal (const char *s) {
695 struct env_stack *env_copy;
697 /* DISABLEEXTENSIONS ignored */
699 env_copy = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack));
702 WCMD_output ("out of memory\n");
706 env = GetEnvironmentStringsW ();
708 env_copy->strings = WCMD_dupenv (env);
709 if (env_copy->strings)
711 env_copy->next = saved_environment;
712 saved_environment = env_copy;
715 LocalFree (env_copy);
717 FreeEnvironmentStringsW (env);
720 /*****************************************************************************
723 static inline WCHAR *WCMD_strchrW(WCHAR *str, WCHAR ch)
734 /*****************************************************************************
737 * endlocal pops the environment off a stack
739 void WCMD_endlocal (void) {
740 WCHAR *env, *old, *p;
741 struct env_stack *temp;
744 if (!saved_environment)
747 /* pop the old environment from the stack */
748 temp = saved_environment;
749 saved_environment = temp->next;
751 /* delete the current environment, totally */
752 env = GetEnvironmentStringsW ();
753 old = WCMD_dupenv (GetEnvironmentStringsW ());
756 n = lstrlenW(&old[len]) + 1;
757 p = WCMD_strchrW(&old[len], '=');
761 SetEnvironmentVariableW (&old[len], NULL);
766 FreeEnvironmentStringsW (env);
768 /* restore old environment */
772 n = lstrlenW(&env[len]) + 1;
773 p = WCMD_strchrW(&env[len], '=');
777 SetEnvironmentVariableW (&env[len], p);
785 /*****************************************************************************
786 * WCMD_setshow_attrib
788 * Display and optionally sets DOS attributes on a file or directory
790 * FIXME: Wine currently uses the Unix stat() function to get file attributes.
791 * As a result only the Readonly flag is correctly reported, the Archive bit
792 * is always set and the rest are not implemented. We do the Right Thing anyway.
794 * FIXME: No SET functionality.
798 void WCMD_setshow_attrib (void) {
803 char flags[9] = {" "};
805 if (param1[0] == '-') {
810 if (lstrlen(param1) == 0) {
811 GetCurrentDirectory (sizeof(param1), param1);
812 strcat (param1, "\\*");
815 hff = FindFirstFile (param1, &fd);
816 if (hff == INVALID_HANDLE_VALUE) {
817 WCMD_output ("%s: File Not Found\n",param1);
821 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
822 if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
825 if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
828 if (fd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
831 if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
834 if (fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) {
837 if (fd.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) {
840 WCMD_output ("%s %s\n", flags, fd.cFileName);
841 for (count=0; count < 8; count++) flags[count] = ' ';
843 } while (FindNextFile(hff, &fd) != 0);
848 /*****************************************************************************
849 * WCMD_setshow_default
851 * Set/Show the current default directory
854 void WCMD_setshow_default (void) {
859 if (strlen(param1) == 0) {
860 GetCurrentDirectory (sizeof(string), string);
861 strcat (string, "\n");
862 WCMD_output (string);
865 status = SetCurrentDirectory (param1);
874 /****************************************************************************
877 * Set/Show the system date
878 * FIXME: Can't change date yet
881 void WCMD_setshow_date (void) {
883 char curdate[64], buffer[64];
886 if (lstrlen(param1) == 0) {
887 if (GetDateFormat (LOCALE_USER_DEFAULT, 0, NULL, NULL,
888 curdate, sizeof(curdate))) {
889 WCMD_output ("Current Date is %s\nEnter new date: ", curdate);
890 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
895 else WCMD_print_error ();
902 /****************************************************************************
905 static int WCMD_compare( const void *a, const void *b )
908 const char * const *str_a = a, * const *str_b = b;
909 r = CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
910 *str_a, -1, *str_b, -1 );
911 if( r == CSTR_LESS_THAN ) return -1;
912 if( r == CSTR_GREATER_THAN ) return 1;
916 /****************************************************************************
917 * WCMD_setshow_sortenv
919 * sort variables into order for display
921 static void WCMD_setshow_sortenv(const char *s)
923 UINT count=0, len=0, i;
926 /* count the number of strings, and the total length */
928 len += (lstrlen(&s[len]) + 1);
932 /* add the strings to an array */
933 str = LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, count * sizeof (char*) );
937 for( i=1; i<count; i++ )
938 str[i] = str[i-1] + lstrlen(str[i-1]) + 1;
941 qsort( str, count, sizeof (char*), WCMD_compare );
944 for( i=0; i<count; i++ ) {
945 WCMD_output_asis(str[i]);
946 WCMD_output_asis("\n");
952 /****************************************************************************
955 * Set/Show the environment variables
958 void WCMD_setshow_env (char *s) {
965 if (strlen(param1) == 0) {
966 env = GetEnvironmentStrings ();
967 WCMD_setshow_sortenv( env );
973 /* FIXME: Emulate Win98 for now, ie "SET C" looks ONLY for an
974 environment variable C, whereas on NT it shows ALL variables
977 status = GetEnvironmentVariable(s, buffer, sizeof(buffer));
979 WCMD_output_asis( s);
980 WCMD_output_asis( "=");
981 WCMD_output_asis( buffer);
982 WCMD_output_asis( "\n");
984 WCMD_output ("Environment variable %s not defined\n", s);
990 if (strlen(p) == 0) p = NULL;
991 status = SetEnvironmentVariable (s, p);
992 if ((!status) & (GetLastError() != ERROR_ENVVAR_NOT_FOUND)) WCMD_print_error();
994 /* WCMD_output (newline); @JED*/
997 /****************************************************************************
1000 * Set/Show the path environment variable
1003 void WCMD_setshow_path (char *command) {
1008 if (strlen(param1) == 0) {
1009 status = GetEnvironmentVariable ("PATH", string, sizeof(string));
1011 WCMD_output_asis ( "PATH=");
1012 WCMD_output_asis ( string);
1013 WCMD_output_asis ( "\n");
1016 WCMD_output ("PATH not found\n");
1020 if (*command == '=') command++; /* Skip leading '=' */
1021 status = SetEnvironmentVariable ("PATH", command);
1022 if (!status) WCMD_print_error();
1026 /****************************************************************************
1027 * WCMD_setshow_prompt
1029 * Set or show the command prompt.
1032 void WCMD_setshow_prompt (void) {
1036 if (strlen(param1) == 0) {
1037 SetEnvironmentVariable ("PROMPT", NULL);
1041 while ((*s == '=') || (*s == ' ')) s++;
1042 if (strlen(s) == 0) {
1043 SetEnvironmentVariable ("PROMPT", NULL);
1045 else SetEnvironmentVariable ("PROMPT", s);
1049 /****************************************************************************
1052 * Set/Show the system time
1053 * FIXME: Can't change time yet
1056 void WCMD_setshow_time (void) {
1058 char curtime[64], buffer[64];
1062 if (strlen(param1) == 0) {
1064 if (GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, NULL,
1065 curtime, sizeof(curtime))) {
1066 WCMD_output ("Current Time is %s\nEnter new time: ", curtime);
1067 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
1072 else WCMD_print_error ();
1079 /****************************************************************************
1082 * Shift batch parameters.
1085 void WCMD_shift (void) {
1087 if (context != NULL) context -> shift_count++;
1091 /****************************************************************************
1094 * Set the console title
1096 void WCMD_title (char *command) {
1097 SetConsoleTitle(command);
1100 /****************************************************************************
1103 * Copy a file to standard output.
1106 void WCMD_type (void) {
1112 if (param1[0] == 0x00) {
1113 WCMD_output ("Argument missing\n");
1116 h = CreateFile (param1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1117 FILE_ATTRIBUTE_NORMAL, NULL);
1118 if (h == INVALID_HANDLE_VALUE) {
1119 WCMD_print_error ();
1122 while (ReadFile (h, buffer, sizeof(buffer), &count, NULL)) {
1123 if (count == 0) break; /* ReadFile reports success on EOF! */
1125 WCMD_output_asis (buffer);
1130 /****************************************************************************
1133 * Display verify flag.
1134 * FIXME: We don't actually do anything with the verify flag other than toggle
1138 void WCMD_verify (char *command) {
1140 static const char von[] = "Verify is ON\n", voff[] = "Verify is OFF\n";
1143 count = strlen(command);
1145 if (verify_mode) WCMD_output (von);
1146 else WCMD_output (voff);
1149 if (lstrcmpi(command, "ON") == 0) {
1153 else if (lstrcmpi(command, "OFF") == 0) {
1157 else WCMD_output ("Verify must be ON or OFF\n");
1160 /****************************************************************************
1163 * Display version info.
1166 void WCMD_version (void) {
1168 WCMD_output (version_string);
1172 /****************************************************************************
1175 * Display volume info and/or set volume label. Returns 0 if error.
1178 int WCMD_volume (int mode, char *path) {
1180 DWORD count, serial;
1181 char string[MAX_PATH], label[MAX_PATH], curdir[MAX_PATH];
1184 if (lstrlen(path) == 0) {
1185 status = GetCurrentDirectory (sizeof(curdir), curdir);
1187 WCMD_print_error ();
1190 status = GetVolumeInformation (NULL, label, sizeof(label), &serial, NULL,
1194 if ((path[1] != ':') || (lstrlen(path) != 2)) {
1195 WCMD_output_asis("Syntax Error\n\n");
1198 wsprintf (curdir, "%s\\", path);
1199 status = GetVolumeInformation (curdir, label, sizeof(label), &serial, NULL,
1203 WCMD_print_error ();
1206 WCMD_output ("Volume in drive %c is %s\nVolume Serial Number is %04x-%04x\n\n",
1207 curdir[0], label, HIWORD(serial), LOWORD(serial));
1209 WCMD_output ("Volume label (11 characters, ENTER for none)?");
1210 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
1212 string[count-1] = '\0'; /* ReadFile output is not null-terminated! */
1213 if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */
1215 if (lstrlen(path) != 0) {
1216 if (!SetVolumeLabel (curdir, string)) WCMD_print_error ();
1219 if (!SetVolumeLabel (NULL, string)) WCMD_print_error ();
1225 /**************************************************************************
1228 * Exit either the process, or just this batch program
1232 void WCMD_exit (void) {
1234 int rc = atoi(param1); /* Note: atoi of empty parameter is 0 */
1236 if (context && lstrcmpi(quals, "/B") == 0) {
1238 context -> skip_rest = TRUE;