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) {
437 char *paramStart = param1;
439 /* Handle special :EOF label */
440 if (lstrcmpi (":eof", param1) == 0) {
441 context -> skip_rest = TRUE;
445 /* Support goto :label as well as goto label */
446 if (*paramStart == ':') paramStart++;
448 SetFilePointer (context -> h, 0, NULL, FILE_BEGIN);
449 while (WCMD_fgets (string, sizeof(string), context -> h)) {
450 if ((string[0] == ':') && (lstrcmpi (&string[1], paramStart) == 0)) return;
452 WCMD_output ("Target to GOTO not found\n");
457 /*****************************************************************************
460 * Push a directory onto the stack
463 void WCMD_pushd (void) {
464 struct env_stack *curdir;
468 curdir = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack));
469 thisdir = LocalAlloc (LMEM_FIXED, 1024 * sizeof(WCHAR));
470 if( !curdir || !thisdir ) {
473 WCMD_output ("out of memory\n");
477 GetCurrentDirectoryW (1024, thisdir);
478 status = SetCurrentDirectoryA (param1);
485 curdir -> next = pushd_directories;
486 curdir -> strings = thisdir;
487 pushd_directories = curdir;
492 /*****************************************************************************
495 * Pop a directory from the stack
498 void WCMD_popd (void) {
499 struct env_stack *temp = pushd_directories;
501 if (!pushd_directories)
504 /* pop the old environment from the stack, and make it the current dir */
505 pushd_directories = temp->next;
506 SetCurrentDirectoryW(temp->strings);
507 LocalFree (temp->strings);
511 /****************************************************************************
514 * Batch file conditional.
515 * FIXME: Much more syntax checking needed!
518 void WCMD_if (char *p) {
520 int negate = 0, test = 0;
521 char condition[MAX_PATH], *command, *s;
523 if (!lstrcmpi (param1, "not")) {
525 lstrcpy (condition, param2);
528 lstrcpy (condition, param1);
530 if (!lstrcmpi (condition, "errorlevel")) {
531 if (errorlevel >= atoi(WCMD_parameter (p, 1+negate, NULL))) test = 1;
532 WCMD_parameter (p, 2+negate, &command);
534 else if (!lstrcmpi (condition, "exist")) {
535 if (GetFileAttributesA(WCMD_parameter (p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES) {
538 WCMD_parameter (p, 2+negate, &command);
540 else if (!lstrcmpi (condition, "defined")) {
541 if (GetEnvironmentVariableA(WCMD_parameter (p, 1+negate, NULL), NULL, 0) > 0) {
544 WCMD_parameter (p, 2+negate, &command);
546 else if ((s = strstr (p, "=="))) {
548 if (!lstrcmpi (condition, WCMD_parameter (s, 0, NULL))) test = 1;
549 WCMD_parameter (s, 1, &command);
552 WCMD_output ("Syntax error\n");
555 if (test != negate) {
556 command = strdup (command);
557 WCMD_process_command (command);
562 /****************************************************************************
565 * Move a file, directory tree or wildcarded set of files.
566 * FIXME: Needs input and output files to be fully specified.
569 void WCMD_move (void) {
572 char outpath[MAX_PATH], inpath[MAX_PATH], *infile;
576 if (param1[0] == 0x00) {
577 WCMD_output ("Argument missing\n");
581 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
582 WCMD_output ("Wildcards not yet supported\n");
586 /* If no destination supplied, assume current directory */
587 if (param2[0] == 0x00) {
591 /* If 2nd parm is directory, then use original filename */
592 GetFullPathName (param2, sizeof(outpath), outpath, NULL);
593 if (outpath[strlen(outpath) - 1] == '\\')
594 outpath[strlen(outpath) - 1] = '\0';
595 hff = FindFirstFile (outpath, &fd);
596 if (hff != INVALID_HANDLE_VALUE) {
597 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
598 GetFullPathName (param1, sizeof(inpath), inpath, &infile);
599 strcat (outpath, "\\");
600 strcat (outpath, infile);
605 status = MoveFile (param1, outpath);
606 if (!status) WCMD_print_error ();
609 /****************************************************************************
612 * Wait for keyboard input.
615 void WCMD_pause (void) {
620 WCMD_output (anykey);
621 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
624 /****************************************************************************
627 * Delete a directory.
630 void WCMD_remove_dir (void) {
632 if (param1[0] == 0x00) {
633 WCMD_output ("Argument missing\n");
636 if (!RemoveDirectory (param1)) WCMD_print_error ();
639 /****************************************************************************
643 * FIXME: Needs input and output files to be fully specified.
646 void WCMD_rename (void) {
650 if (param1[0] == 0x00 || param2[0] == 0x00) {
651 WCMD_output ("Argument missing\n");
654 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
655 WCMD_output ("Wildcards not yet supported\n");
658 status = MoveFile (param1, param2);
659 if (!status) WCMD_print_error ();
662 /*****************************************************************************
665 * Make a copy of the environment.
667 static WCHAR *WCMD_dupenv( const WCHAR *env )
677 len += (lstrlenW(&env[len]) + 1);
679 env_copy = LocalAlloc (LMEM_FIXED, (len+1) * sizeof (WCHAR) );
682 WCMD_output ("out of memory\n");
685 memcpy (env_copy, env, len*sizeof (WCHAR));
691 /*****************************************************************************
694 * setlocal pushes the environment onto a stack
695 * Save the environment as unicode so we don't screw anything up.
697 void WCMD_setlocal (const char *s) {
699 struct env_stack *env_copy;
701 /* DISABLEEXTENSIONS ignored */
703 env_copy = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack));
706 WCMD_output ("out of memory\n");
710 env = GetEnvironmentStringsW ();
712 env_copy->strings = WCMD_dupenv (env);
713 if (env_copy->strings)
715 env_copy->next = saved_environment;
716 saved_environment = env_copy;
719 LocalFree (env_copy);
721 FreeEnvironmentStringsW (env);
724 /*****************************************************************************
727 static inline WCHAR *WCMD_strchrW(WCHAR *str, WCHAR ch)
738 /*****************************************************************************
741 * endlocal pops the environment off a stack
743 void WCMD_endlocal (void) {
744 WCHAR *env, *old, *p;
745 struct env_stack *temp;
748 if (!saved_environment)
751 /* pop the old environment from the stack */
752 temp = saved_environment;
753 saved_environment = temp->next;
755 /* delete the current environment, totally */
756 env = GetEnvironmentStringsW ();
757 old = WCMD_dupenv (GetEnvironmentStringsW ());
760 n = lstrlenW(&old[len]) + 1;
761 p = WCMD_strchrW(&old[len], '=');
765 SetEnvironmentVariableW (&old[len], NULL);
770 FreeEnvironmentStringsW (env);
772 /* restore old environment */
776 n = lstrlenW(&env[len]) + 1;
777 p = WCMD_strchrW(&env[len], '=');
781 SetEnvironmentVariableW (&env[len], p);
789 /*****************************************************************************
790 * WCMD_setshow_attrib
792 * Display and optionally sets DOS attributes on a file or directory
794 * FIXME: Wine currently uses the Unix stat() function to get file attributes.
795 * As a result only the Readonly flag is correctly reported, the Archive bit
796 * is always set and the rest are not implemented. We do the Right Thing anyway.
798 * FIXME: No SET functionality.
802 void WCMD_setshow_attrib (void) {
807 char flags[9] = {" "};
809 if (param1[0] == '-') {
814 if (lstrlen(param1) == 0) {
815 GetCurrentDirectory (sizeof(param1), param1);
816 strcat (param1, "\\*");
819 hff = FindFirstFile (param1, &fd);
820 if (hff == INVALID_HANDLE_VALUE) {
821 WCMD_output ("%s: File Not Found\n",param1);
825 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
826 if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
829 if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
832 if (fd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
835 if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
838 if (fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) {
841 if (fd.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) {
844 WCMD_output ("%s %s\n", flags, fd.cFileName);
845 for (count=0; count < 8; count++) flags[count] = ' ';
847 } while (FindNextFile(hff, &fd) != 0);
852 /*****************************************************************************
853 * WCMD_setshow_default
855 * Set/Show the current default directory
858 void WCMD_setshow_default (void) {
863 if (strlen(param1) == 0) {
864 GetCurrentDirectory (sizeof(string), string);
865 strcat (string, "\n");
866 WCMD_output (string);
869 status = SetCurrentDirectory (param1);
878 /****************************************************************************
881 * Set/Show the system date
882 * FIXME: Can't change date yet
885 void WCMD_setshow_date (void) {
887 char curdate[64], buffer[64];
890 if (lstrlen(param1) == 0) {
891 if (GetDateFormat (LOCALE_USER_DEFAULT, 0, NULL, NULL,
892 curdate, sizeof(curdate))) {
893 WCMD_output ("Current Date is %s\nEnter new date: ", curdate);
894 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
899 else WCMD_print_error ();
906 /****************************************************************************
909 static int WCMD_compare( const void *a, const void *b )
912 const char * const *str_a = a, * const *str_b = b;
913 r = CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
914 *str_a, -1, *str_b, -1 );
915 if( r == CSTR_LESS_THAN ) return -1;
916 if( r == CSTR_GREATER_THAN ) return 1;
920 /****************************************************************************
921 * WCMD_setshow_sortenv
923 * sort variables into order for display
925 static void WCMD_setshow_sortenv(const char *s)
927 UINT count=0, len=0, i;
930 /* count the number of strings, and the total length */
932 len += (lstrlen(&s[len]) + 1);
936 /* add the strings to an array */
937 str = LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, count * sizeof (char*) );
941 for( i=1; i<count; i++ )
942 str[i] = str[i-1] + lstrlen(str[i-1]) + 1;
945 qsort( str, count, sizeof (char*), WCMD_compare );
948 for( i=0; i<count; i++ ) {
949 WCMD_output_asis(str[i]);
950 WCMD_output_asis("\n");
956 /****************************************************************************
959 * Set/Show the environment variables
962 void WCMD_setshow_env (char *s) {
969 if (strlen(param1) == 0) {
970 env = GetEnvironmentStrings ();
971 WCMD_setshow_sortenv( env );
977 /* FIXME: Emulate Win98 for now, ie "SET C" looks ONLY for an
978 environment variable C, whereas on NT it shows ALL variables
981 status = GetEnvironmentVariable(s, buffer, sizeof(buffer));
983 WCMD_output_asis( s);
984 WCMD_output_asis( "=");
985 WCMD_output_asis( buffer);
986 WCMD_output_asis( "\n");
988 WCMD_output ("Environment variable %s not defined\n", s);
994 if (strlen(p) == 0) p = NULL;
995 status = SetEnvironmentVariable (s, p);
996 if ((!status) & (GetLastError() != ERROR_ENVVAR_NOT_FOUND)) WCMD_print_error();
998 /* WCMD_output (newline); @JED*/
1001 /****************************************************************************
1004 * Set/Show the path environment variable
1007 void WCMD_setshow_path (char *command) {
1012 if (strlen(param1) == 0) {
1013 status = GetEnvironmentVariable ("PATH", string, sizeof(string));
1015 WCMD_output_asis ( "PATH=");
1016 WCMD_output_asis ( string);
1017 WCMD_output_asis ( "\n");
1020 WCMD_output ("PATH not found\n");
1024 if (*command == '=') command++; /* Skip leading '=' */
1025 status = SetEnvironmentVariable ("PATH", command);
1026 if (!status) WCMD_print_error();
1030 /****************************************************************************
1031 * WCMD_setshow_prompt
1033 * Set or show the command prompt.
1036 void WCMD_setshow_prompt (void) {
1040 if (strlen(param1) == 0) {
1041 SetEnvironmentVariable ("PROMPT", NULL);
1045 while ((*s == '=') || (*s == ' ')) s++;
1046 if (strlen(s) == 0) {
1047 SetEnvironmentVariable ("PROMPT", NULL);
1049 else SetEnvironmentVariable ("PROMPT", s);
1053 /****************************************************************************
1056 * Set/Show the system time
1057 * FIXME: Can't change time yet
1060 void WCMD_setshow_time (void) {
1062 char curtime[64], buffer[64];
1066 if (strlen(param1) == 0) {
1068 if (GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, NULL,
1069 curtime, sizeof(curtime))) {
1070 WCMD_output ("Current Time is %s\nEnter new time: ", curtime);
1071 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
1076 else WCMD_print_error ();
1083 /****************************************************************************
1086 * Shift batch parameters.
1089 void WCMD_shift (void) {
1091 if (context != NULL) context -> shift_count++;
1095 /****************************************************************************
1098 * Set the console title
1100 void WCMD_title (char *command) {
1101 SetConsoleTitle(command);
1104 /****************************************************************************
1107 * Copy a file to standard output.
1110 void WCMD_type (void) {
1116 if (param1[0] == 0x00) {
1117 WCMD_output ("Argument missing\n");
1120 h = CreateFile (param1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1121 FILE_ATTRIBUTE_NORMAL, NULL);
1122 if (h == INVALID_HANDLE_VALUE) {
1123 WCMD_print_error ();
1126 while (ReadFile (h, buffer, sizeof(buffer), &count, NULL)) {
1127 if (count == 0) break; /* ReadFile reports success on EOF! */
1129 WCMD_output_asis (buffer);
1134 /****************************************************************************
1137 * Display verify flag.
1138 * FIXME: We don't actually do anything with the verify flag other than toggle
1142 void WCMD_verify (char *command) {
1144 static const char von[] = "Verify is ON\n", voff[] = "Verify is OFF\n";
1147 count = strlen(command);
1149 if (verify_mode) WCMD_output (von);
1150 else WCMD_output (voff);
1153 if (lstrcmpi(command, "ON") == 0) {
1157 else if (lstrcmpi(command, "OFF") == 0) {
1161 else WCMD_output ("Verify must be ON or OFF\n");
1164 /****************************************************************************
1167 * Display version info.
1170 void WCMD_version (void) {
1172 WCMD_output (version_string);
1176 /****************************************************************************
1179 * Display volume info and/or set volume label. Returns 0 if error.
1182 int WCMD_volume (int mode, char *path) {
1184 DWORD count, serial;
1185 char string[MAX_PATH], label[MAX_PATH], curdir[MAX_PATH];
1188 if (lstrlen(path) == 0) {
1189 status = GetCurrentDirectory (sizeof(curdir), curdir);
1191 WCMD_print_error ();
1194 status = GetVolumeInformation (NULL, label, sizeof(label), &serial, NULL,
1198 if ((path[1] != ':') || (lstrlen(path) != 2)) {
1199 WCMD_output_asis("Syntax Error\n\n");
1202 wsprintf (curdir, "%s\\", path);
1203 status = GetVolumeInformation (curdir, label, sizeof(label), &serial, NULL,
1207 WCMD_print_error ();
1210 WCMD_output ("Volume in drive %c is %s\nVolume Serial Number is %04x-%04x\n\n",
1211 curdir[0], label, HIWORD(serial), LOWORD(serial));
1213 WCMD_output ("Volume label (11 characters, ENTER for none)?");
1214 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
1216 string[count-1] = '\0'; /* ReadFile output is not null-terminated! */
1217 if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */
1219 if (lstrlen(path) != 0) {
1220 if (!SetVolumeLabel (curdir, string)) WCMD_print_error ();
1223 if (!SetVolumeLabel (NULL, string)) WCMD_print_error ();
1229 /**************************************************************************
1232 * Exit either the process, or just this batch program
1236 void WCMD_exit (void) {
1238 int rc = atoi(param1); /* Note: atoi of empty parameter is 0 */
1240 if (context && lstrcmpi(quals, "/B") == 0) {
1242 context -> skip_rest = TRUE;