Define GL_EXT_framebuffer_object and GL_EXT_pixelbuffer_object openGL
[wine.git] / programs / wcmd / builtins.c
blob0d1a2594c5ac330779a747244a84082a833a8ba1
1 /*
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
22 * NOTES:
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.
29 * FIXME:
30 * - No support for pipes, shell parameters
31 * - Lots of functionality missing from builtins
32 * - Messages etc need international support
35 #include "wcmd.h"
37 void WCMD_execute (char *orig_command, char *parameter, char *substitution);
39 struct env_stack
41 struct env_stack *next;
42 WCHAR *strings;
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 /****************************************************************************
57 * WCMD_clear_screen
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))
71 COORD topLeft;
72 DWORD screenSize;
74 screenSize = consoleInfo.dwSize.X * (consoleInfo.dwSize.Y + 1);
76 topLeft.X = 0;
77 topLeft.Y = 0;
78 FillConsoleOutputCharacter(hStdOut, ' ', screenSize, topLeft, &screenSize);
79 SetConsoleCursorPosition(hStdOut, topLeft);
83 /****************************************************************************
84 * WCMD_change_tty
86 * Change the default i/o device (ie redirect STDin/STDout).
89 void WCMD_change_tty (void) {
91 WCMD_output (nyi);
95 /****************************************************************************
96 * WCMD_copy
98 * Copy a file or wildcarded set.
99 * FIXME: No wildcard support
102 void WCMD_copy (void) {
104 DWORD count;
105 WIN32_FIND_DATA fd;
106 HANDLE hff;
107 BOOL force, status;
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");
113 return;
116 /* If no destination supplied, assume current directory */
117 if (param2[0] == 0x00) {
118 strcpy(param2, ".");
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);
129 FindClose (hff);
132 force = (strstr (quals, "/Y") != NULL);
133 if (!force) {
134 hff = FindFirstFile (outpath, &fd);
135 if (hff != INVALID_HANDLE_VALUE) {
136 FindClose (hff);
137 WCMD_output (overwrite);
138 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
139 if (toupper(string[0]) == 'Y') force = TRUE;
141 else force = TRUE;
143 if (force) {
144 status = CopyFile (param1, outpath, FALSE);
145 if (!status) WCMD_print_error ();
149 /****************************************************************************
150 * WCMD_create_dir
152 * Create a directory.
155 void WCMD_create_dir (void) {
157 if (!CreateDirectory (param1, NULL)) WCMD_print_error ();
160 /****************************************************************************
161 * WCMD_delete
163 * Delete a file or wildcarded set.
167 void WCMD_delete (int recurse) {
169 WIN32_FIND_DATA fd;
170 HANDLE hff;
171 char fpath[MAX_PATH];
172 char *p;
174 hff = FindFirstFile (param1, &fd);
175 if (hff == INVALID_HANDLE_VALUE) {
176 WCMD_output ("%s :File Not Found\n",param1);
177 return;
179 if ((strchr(param1,'*') == NULL) && (strchr(param1,'?') == NULL)
180 && (!recurse) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
181 strcat (param1, "\\*");
182 FindClose(hff);
183 WCMD_delete (1);
184 return;
186 if ((strchr(param1,'*') != NULL) || (strchr(param1,'?') != NULL)) {
187 strcpy (fpath, param1);
188 do {
189 p = strrchr (fpath, '\\');
190 if (p != NULL) {
191 *++p = '\0';
192 strcat (fpath, fd.cFileName);
194 else strcpy (fpath, fd.cFileName);
195 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
196 if (!DeleteFile (fpath)) WCMD_print_error ();
198 } while (FindNextFile(hff, &fd) != 0);
199 FindClose (hff);
201 else {
202 if (!DeleteFile (param1)) WCMD_print_error ();
203 FindClose (hff);
207 /****************************************************************************
208 * WCMD_echo
210 * Echo input to the screen (or not). We don't try to emulate the bugs
211 * in DOS (try typing "ECHO ON AGAIN" for an example).
214 void WCMD_echo (const char *command) {
216 static const char eon[] = "Echo is ON\n", eoff[] = "Echo is OFF\n";
217 int count;
219 if ((command[0] == '.') && (command[1] == 0)) {
220 WCMD_output (newline);
221 return;
223 if (command[0]==' ')
224 command++;
225 count = strlen(command);
226 if (count == 0) {
227 if (echo_mode) WCMD_output (eon);
228 else WCMD_output (eoff);
229 return;
231 if (lstrcmpi(command, "ON") == 0) {
232 echo_mode = 1;
233 return;
235 if (lstrcmpi(command, "OFF") == 0) {
236 echo_mode = 0;
237 return;
239 WCMD_output_asis (command);
240 WCMD_output (newline);
244 /**************************************************************************
245 * WCMD_for
247 * Batch file loop processing.
248 * FIXME: We don't exhaustively check syntax. Any command which works in MessDOS
249 * will probably work here, but the reverse is not necessarily the case...
252 void WCMD_for (char *p) {
254 WIN32_FIND_DATA fd;
255 HANDLE hff;
256 char *cmd, *item;
257 char set[MAX_PATH], param[MAX_PATH];
258 int i;
260 if (lstrcmpi (WCMD_parameter (p, 1, NULL), "in")
261 || lstrcmpi (WCMD_parameter (p, 3, NULL), "do")
262 || (param1[0] != '%')) {
263 WCMD_output ("Syntax error\n");
264 return;
266 lstrcpyn (set, WCMD_parameter (p, 2, NULL), sizeof(set));
267 WCMD_parameter (p, 4, &cmd);
268 lstrcpy (param, param1);
271 * If the parameter within the set has a wildcard then search for matching files
272 * otherwise do a literal substitution.
275 i = 0;
276 while (*(item = WCMD_parameter (set, i, NULL))) {
277 if (strpbrk (item, "*?")) {
278 hff = FindFirstFile (item, &fd);
279 if (hff == INVALID_HANDLE_VALUE) {
280 return;
282 do {
283 WCMD_execute (cmd, param, fd.cFileName);
284 } while (FindNextFile(hff, &fd) != 0);
285 FindClose (hff);
287 else {
288 WCMD_execute (cmd, param, item);
290 i++;
294 /*****************************************************************************
295 * WCMD_Execute
297 * Execute a command after substituting variable text for the supplied parameter
300 void WCMD_execute (char *orig_cmd, char *param, char *subst) {
302 char *new_cmd, *p, *s, *dup;
303 int size;
305 size = lstrlen (orig_cmd);
306 new_cmd = (char *) LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, size);
307 dup = s = strdup (orig_cmd);
309 while ((p = strstr (s, param))) {
310 *p = '\0';
311 size += lstrlen (subst);
312 new_cmd = (char *) LocalReAlloc ((HANDLE)new_cmd, size, 0);
313 strcat (new_cmd, s);
314 strcat (new_cmd, subst);
315 s = p + lstrlen (param);
317 strcat (new_cmd, s);
318 WCMD_process_command (new_cmd);
319 free (dup);
320 LocalFree ((HANDLE)new_cmd);
324 /**************************************************************************
325 * WCMD_give_help
327 * Simple on-line help. Help text is stored in the resource file.
330 void WCMD_give_help (char *command) {
332 int i;
333 char buffer[2048];
335 command = WCMD_strtrim_leading_spaces(command);
336 if (lstrlen(command) == 0) {
337 LoadString (hinst, 1000, buffer, sizeof(buffer));
338 WCMD_output_asis (buffer);
340 else {
341 for (i=0; i<=WCMD_EXIT; i++) {
342 if (CompareString (LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
343 param1, -1, inbuilt[i], -1) == 2) {
344 LoadString (hinst, i, buffer, sizeof(buffer));
345 WCMD_output_asis (buffer);
346 return;
349 WCMD_output ("No help available for %s\n", param1);
351 return;
354 /****************************************************************************
355 * WCMD_go_to
357 * Batch file jump instruction. Not the most efficient algorithm ;-)
358 * Prints error message if the specified label cannot be found - the file pointer is
359 * then at EOF, effectively stopping the batch file.
360 * FIXME: DOS is supposed to allow labels with spaces - we don't.
363 void WCMD_goto (void) {
365 char string[MAX_PATH];
367 if (context != NULL) {
368 SetFilePointer (context -> h, 0, NULL, FILE_BEGIN);
369 while (WCMD_fgets (string, sizeof(string), context -> h)) {
370 if ((string[0] == ':') && (strcmp (&string[1], param1) == 0)) return;
372 WCMD_output ("Target to GOTO not found\n");
374 return;
378 /****************************************************************************
379 * WCMD_if
381 * Batch file conditional.
382 * FIXME: Much more syntax checking needed!
385 void WCMD_if (char *p) {
387 int negate = 0, test = 0;
388 char condition[MAX_PATH], *command, *s;
390 if (!lstrcmpi (param1, "not")) {
391 negate = 1;
392 lstrcpy (condition, param2);
394 else {
395 lstrcpy (condition, param1);
397 if (!lstrcmpi (condition, "errorlevel")) {
398 if (errorlevel >= atoi(WCMD_parameter (p, 1+negate, NULL))) test = 1;
399 return;
400 WCMD_parameter (p, 2+negate, &command);
402 else if (!lstrcmpi (condition, "exist")) {
403 if (GetFileAttributesA(WCMD_parameter (p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES) {
404 test = 1;
406 WCMD_parameter (p, 2+negate, &command);
408 else if ((s = strstr (p, "=="))) {
409 s += 2;
410 if (!lstrcmpi (condition, WCMD_parameter (s, 0, NULL))) test = 1;
411 WCMD_parameter (s, 1, &command);
413 else {
414 WCMD_output ("Syntax error\n");
415 return;
417 if (test != negate) {
418 command = strdup (command);
419 WCMD_process_command (command);
420 free (command);
424 /****************************************************************************
425 * WCMD_move
427 * Move a file, directory tree or wildcarded set of files.
428 * FIXME: Needs input and output files to be fully specified.
431 void WCMD_move (void) {
433 int status;
434 char outpath[MAX_PATH], inpath[MAX_PATH], *infile;
435 WIN32_FIND_DATA fd;
436 HANDLE hff;
438 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
439 WCMD_output ("Wildcards not yet supported\n");
440 return;
443 /* If no destination supplied, assume current directory */
444 if (param2[0] == 0x00) {
445 strcpy(param2, ".");
448 /* If 2nd parm is directory, then use original filename */
449 GetFullPathName (param2, sizeof(outpath), outpath, NULL);
450 hff = FindFirstFile (outpath, &fd);
451 if (hff != INVALID_HANDLE_VALUE) {
452 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
453 GetFullPathName (param1, sizeof(inpath), inpath, &infile);
454 strcat (outpath, "\\");
455 strcat (outpath, infile);
457 FindClose (hff);
460 status = MoveFile (param1, outpath);
461 if (!status) WCMD_print_error ();
464 /****************************************************************************
465 * WCMD_pause
467 * Wait for keyboard input.
470 void WCMD_pause (void) {
472 DWORD count;
473 char string[32];
475 WCMD_output (anykey);
476 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
479 /****************************************************************************
480 * WCMD_remove_dir
482 * Delete a directory.
485 void WCMD_remove_dir (void) {
487 if (!RemoveDirectory (param1)) WCMD_print_error ();
490 /****************************************************************************
491 * WCMD_rename
493 * Rename a file.
494 * FIXME: Needs input and output files to be fully specified.
497 void WCMD_rename (void) {
499 int status;
501 if ((strchr(param1,'*') != NULL) || (strchr(param1,'%') != NULL)) {
502 WCMD_output ("Wildcards not yet supported\n");
503 return;
505 status = MoveFile (param1, param2);
506 if (!status) WCMD_print_error ();
509 /*****************************************************************************
510 * WCMD_dupenv
512 * Make a copy of the environment.
514 static WCHAR *WCMD_dupenv( const WCHAR *env )
516 WCHAR *env_copy;
517 int len;
519 if( !env )
520 return NULL;
522 len = 0;
523 while ( env[len] )
524 len += (lstrlenW(&env[len]) + 1);
526 env_copy = LocalAlloc (LMEM_FIXED, (len+1) * sizeof (WCHAR) );
527 if (!env_copy)
529 WCMD_output ("out of memory\n");
530 return env_copy;
532 memcpy (env_copy, env, len*sizeof (WCHAR));
533 env_copy[len] = 0;
535 return env_copy;
538 /*****************************************************************************
539 * WCMD_setlocal
541 * setlocal pushes the environment onto a stack
542 * Save the environment as unicode so we don't screw anything up.
544 void WCMD_setlocal (const char *s) {
545 WCHAR *env;
546 struct env_stack *env_copy;
548 /* DISABLEEXTENSIONS ignored */
550 env_copy = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack));
551 if( !env_copy )
553 WCMD_output ("out of memory\n");
554 return;
557 env = GetEnvironmentStringsW ();
559 env_copy->strings = WCMD_dupenv (env);
560 if (env_copy->strings)
562 env_copy->next = saved_environment;
563 saved_environment = env_copy;
565 else
566 LocalFree (env_copy);
568 FreeEnvironmentStringsW (env);
571 /*****************************************************************************
572 * WCMD_strchrW
574 static inline WCHAR *WCMD_strchrW(WCHAR *str, WCHAR ch)
576 while(*str)
578 if(*str == ch)
579 return str;
580 str++;
582 return NULL;
585 /*****************************************************************************
586 * WCMD_endlocal
588 * endlocal pops the environment off a stack
590 void WCMD_endlocal (void) {
591 WCHAR *env, *old, *p;
592 struct env_stack *temp;
593 int len, n;
595 if (!saved_environment)
596 return;
598 /* pop the old environment from the stack */
599 temp = saved_environment;
600 saved_environment = temp->next;
602 /* delete the current environment, totally */
603 env = GetEnvironmentStringsW ();
604 old = WCMD_dupenv (GetEnvironmentStringsW ());
605 len = 0;
606 while (old[len]) {
607 n = lstrlenW(&old[len]) + 1;
608 p = WCMD_strchrW(&old[len], '=');
609 if (p)
611 *p++ = 0;
612 SetEnvironmentVariableW (&old[len], NULL);
614 len += n;
616 LocalFree (old);
617 FreeEnvironmentStringsW (env);
619 /* restore old environment */
620 env = temp->strings;
621 len = 0;
622 while (env[len]) {
623 n = lstrlenW(&env[len]) + 1;
624 p = WCMD_strchrW(&env[len], '=');
625 if (p)
627 *p++ = 0;
628 SetEnvironmentVariableW (&env[len], p);
630 len += n;
632 LocalFree (env);
633 LocalFree (temp);
636 /*****************************************************************************
637 * WCMD_setshow_attrib
639 * Display and optionally sets DOS attributes on a file or directory
641 * FIXME: Wine currently uses the Unix stat() function to get file attributes.
642 * As a result only the Readonly flag is correctly reported, the Archive bit
643 * is always set and the rest are not implemented. We do the Right Thing anyway.
645 * FIXME: No SET functionality.
649 void WCMD_setshow_attrib (void) {
651 DWORD count;
652 HANDLE hff;
653 WIN32_FIND_DATA fd;
654 char flags[9] = {" "};
656 if (param1[0] == '-') {
657 WCMD_output (nyi);
658 return;
661 if (lstrlen(param1) == 0) {
662 GetCurrentDirectory (sizeof(param1), param1);
663 strcat (param1, "\\*");
666 hff = FindFirstFile (param1, &fd);
667 if (hff == INVALID_HANDLE_VALUE) {
668 WCMD_output ("%s: File Not Found\n",param1);
670 else {
671 do {
672 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
673 if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
674 flags[0] = 'H';
676 if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
677 flags[1] = 'S';
679 if (fd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
680 flags[2] = 'A';
682 if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
683 flags[3] = 'R';
685 if (fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) {
686 flags[4] = 'T';
688 if (fd.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) {
689 flags[5] = 'C';
691 WCMD_output ("%s %s\n", flags, fd.cFileName);
692 for (count=0; count < 8; count++) flags[count] = ' ';
694 } while (FindNextFile(hff, &fd) != 0);
696 FindClose (hff);
699 /*****************************************************************************
700 * WCMD_setshow_default
702 * Set/Show the current default directory
705 void WCMD_setshow_default (void) {
707 BOOL status;
708 char string[1024];
710 if (strlen(param1) == 0) {
711 GetCurrentDirectory (sizeof(string), string);
712 strcat (string, "\n");
713 WCMD_output (string);
715 else {
716 status = SetCurrentDirectory (param1);
717 if (!status) {
718 WCMD_print_error ();
719 return;
722 return;
725 /****************************************************************************
726 * WCMD_setshow_date
728 * Set/Show the system date
729 * FIXME: Can't change date yet
732 void WCMD_setshow_date (void) {
734 char curdate[64], buffer[64];
735 DWORD count;
737 if (lstrlen(param1) == 0) {
738 if (GetDateFormat (LOCALE_USER_DEFAULT, 0, NULL, NULL,
739 curdate, sizeof(curdate))) {
740 WCMD_output ("Current Date is %s\nEnter new date: ", curdate);
741 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
742 if (count > 2) {
743 WCMD_output (nyi);
746 else WCMD_print_error ();
748 else {
749 WCMD_output (nyi);
753 /****************************************************************************
754 * WCMD_compare
756 static int WCMD_compare( const void *a, const void *b )
758 int r;
759 const char * const *str_a = a, * const *str_b = b;
760 r = CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
761 *str_a, -1, *str_b, -1 );
762 if( r == CSTR_LESS_THAN ) return -1;
763 if( r == CSTR_GREATER_THAN ) return 1;
764 return 0;
767 /****************************************************************************
768 * WCMD_setshow_sortenv
770 * sort variables into order for display
772 static void WCMD_setshow_sortenv(const char *s)
774 UINT count=0, len=0, i;
775 const char **str;
777 /* count the number of strings, and the total length */
778 while ( s[len] ) {
779 len += (lstrlen(&s[len]) + 1);
780 count++;
783 /* add the strings to an array */
784 str = LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, count * sizeof (char*) );
785 if( !str )
786 return;
787 str[0] = s;
788 for( i=1; i<count; i++ )
789 str[i] = str[i-1] + lstrlen(str[i-1]) + 1;
791 /* sort the array */
792 qsort( str, count, sizeof (char*), WCMD_compare );
794 /* print it */
795 for( i=0; i<count; i++ )
796 WCMD_output("%s\n", str[i] );
798 LocalFree( str );
801 /****************************************************************************
802 * WCMD_setshow_env
804 * Set/Show the environment variables
807 void WCMD_setshow_env (char *s) {
809 LPVOID env;
810 char *p;
811 int status;
812 char buffer[1048];
814 if (strlen(param1) == 0) {
815 env = GetEnvironmentStrings ();
816 WCMD_setshow_sortenv( env );
818 else {
819 p = strchr (s, '=');
820 if (p == NULL) {
822 /* FIXME: Emulate Win98 for now, ie "SET C" looks ONLY for an
823 environment variable C, whereas on NT it shows ALL variables
824 starting with C.
826 status = GetEnvironmentVariable(s, buffer, sizeof(buffer));
827 if (status) {
828 WCMD_output("%s=%s\n", s, buffer);
829 } else {
830 WCMD_output ("Environment variable %s not defined\n", s);
832 return;
834 *p++ = '\0';
836 if (strlen(p) == 0) p = NULL;
837 status = SetEnvironmentVariable (s, p);
838 if ((!status) & (GetLastError() != ERROR_ENVVAR_NOT_FOUND)) WCMD_print_error();
840 /* WCMD_output (newline); @JED*/
843 /****************************************************************************
844 * WCMD_setshow_path
846 * Set/Show the path environment variable
849 void WCMD_setshow_path (char *command) {
851 char string[1024];
852 DWORD status;
854 if (strlen(param1) == 0) {
855 status = GetEnvironmentVariable ("PATH", string, sizeof(string));
856 if (status != 0) {
857 WCMD_output ("PATH=%s\n", string);
859 else {
860 WCMD_output ("PATH not found\n");
863 else {
864 status = SetEnvironmentVariable ("PATH", command);
865 if (!status) WCMD_print_error();
869 /****************************************************************************
870 * WCMD_setshow_prompt
872 * Set or show the command prompt.
875 void WCMD_setshow_prompt (void) {
877 char *s;
879 if (strlen(param1) == 0) {
880 SetEnvironmentVariable ("PROMPT", NULL);
882 else {
883 s = param1;
884 while ((*s == '=') || (*s == ' ')) s++;
885 if (strlen(s) == 0) {
886 SetEnvironmentVariable ("PROMPT", NULL);
888 else SetEnvironmentVariable ("PROMPT", s);
892 /****************************************************************************
893 * WCMD_setshow_time
895 * Set/Show the system time
896 * FIXME: Can't change time yet
899 void WCMD_setshow_time (void) {
901 char curtime[64], buffer[64];
902 DWORD count;
903 SYSTEMTIME st;
905 if (strlen(param1) == 0) {
906 GetLocalTime(&st);
907 if (GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, NULL,
908 curtime, sizeof(curtime))) {
909 WCMD_output ("Current Time is %s\nEnter new time: ", curtime);
910 ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
911 if (count > 2) {
912 WCMD_output (nyi);
915 else WCMD_print_error ();
917 else {
918 WCMD_output (nyi);
922 /****************************************************************************
923 * WCMD_shift
925 * Shift batch parameters.
928 void WCMD_shift (void) {
930 if (context != NULL) context -> shift_count++;
934 /****************************************************************************
935 * WCMD_title
937 * Set the console title
939 void WCMD_title (char *command) {
940 SetConsoleTitle(command);
943 /****************************************************************************
944 * WCMD_type
946 * Copy a file to standard output.
949 void WCMD_type (void) {
951 HANDLE h;
952 char buffer[512];
953 DWORD count;
955 h = CreateFile (param1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
956 FILE_ATTRIBUTE_NORMAL, NULL);
957 if (h == INVALID_HANDLE_VALUE) {
958 WCMD_print_error ();
959 return;
961 while (ReadFile (h, buffer, sizeof(buffer), &count, NULL)) {
962 if (count == 0) break; /* ReadFile reports success on EOF! */
963 buffer[count] = 0;
964 WCMD_output_asis (buffer);
966 CloseHandle (h);
969 /****************************************************************************
970 * WCMD_verify
972 * Display verify flag.
973 * FIXME: We don't actually do anything with the verify flag other than toggle
974 * it...
977 void WCMD_verify (char *command) {
979 static const char von[] = "Verify is ON\n", voff[] = "Verify is OFF\n";
980 int count;
982 count = strlen(command);
983 if (count == 0) {
984 if (verify_mode) WCMD_output (von);
985 else WCMD_output (voff);
986 return;
988 if (lstrcmpi(command, "ON") == 0) {
989 verify_mode = 1;
990 return;
992 else if (lstrcmpi(command, "OFF") == 0) {
993 verify_mode = 0;
994 return;
996 else WCMD_output ("Verify must be ON or OFF\n");
999 /****************************************************************************
1000 * WCMD_version
1002 * Display version info.
1005 void WCMD_version (void) {
1007 WCMD_output (version_string);
1011 /****************************************************************************
1012 * WCMD_volume
1014 * Display volume info and/or set volume label. Returns 0 if error.
1017 int WCMD_volume (int mode, char *path) {
1019 DWORD count, serial;
1020 char string[MAX_PATH], label[MAX_PATH], curdir[MAX_PATH];
1021 BOOL status;
1023 if (lstrlen(path) == 0) {
1024 status = GetCurrentDirectory (sizeof(curdir), curdir);
1025 if (!status) {
1026 WCMD_print_error ();
1027 return 0;
1029 status = GetVolumeInformation (NULL, label, sizeof(label), &serial, NULL,
1030 NULL, NULL, 0);
1032 else {
1033 if ((path[1] != ':') || (lstrlen(path) != 2)) {
1034 WCMD_output_asis("Syntax Error\n\n");
1035 return 0;
1037 wsprintf (curdir, "%s\\", path);
1038 status = GetVolumeInformation (curdir, label, sizeof(label), &serial, NULL,
1039 NULL, NULL, 0);
1041 if (!status) {
1042 WCMD_print_error ();
1043 return 0;
1045 WCMD_output ("Volume in drive %c is %s\nVolume Serial Number is %04x-%04x\n\n",
1046 curdir[0], label, HIWORD(serial), LOWORD(serial));
1047 if (mode) {
1048 WCMD_output ("Volume label (11 characters, ENTER for none)?");
1049 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
1050 if (count > 1) {
1051 string[count-1] = '\0'; /* ReadFile output is not null-terminated! */
1052 if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */
1054 if (lstrlen(path) != 0) {
1055 if (!SetVolumeLabel (curdir, string)) WCMD_print_error ();
1057 else {
1058 if (!SetVolumeLabel (NULL, string)) WCMD_print_error ();
1061 return 1;