2 * WCMD - Wine-compatible command line interface - batch interface.
11 void WCMD_batch_command (HANDLE h
, char *command
);
12 char *WCMD_parameter (char *s
, int n
);
13 BOOL
WCMD_go_to (HANDLE h
, char *label
);
15 extern HANDLE STDin
, STDout
;
17 extern char newline
[];
18 extern char version_string
[];
20 extern char quals
[MAX_PATH
], param1
[MAX_PATH
], param2
[MAX_PATH
];
24 /****************************************************************************
27 * Open and execute a batch file.
28 * On entry *command includes the complete command line beginning with the name
29 * of the batch file (if a CALL command was entered the CALL has been removed).
30 * *file is the name of the file, which might not exist and may not have the
33 * We need to handle recursion correctly, since one batch program might call another.
36 void WCMD_batch (char *file
, char *command
) {
39 char string
[MAX_PATH
];
42 strcpy (string
, file
);
44 if (strstr (string
, ".bat") == NULL
) strcat (string
, ".bat");
45 h
= CreateFile (string
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0);
46 if (h
== INVALID_HANDLE_VALUE
) {
47 WCMD_output ("File %s not found\n", string
);
52 * Work through the file line by line. Specific batch commands are processed here,
53 * the rest are handled by the main command processor.
56 while (WCMD_fgets (string
, sizeof(string
), h
)) {
58 if (string
[n
-1] == '\n') string
[n
-1] = '\0';
59 if (string
[n
-2] == '\r') string
[n
-2] = '\0'; /* Under Windoze we get CRLF! */
60 WCMD_batch_command (h
, string
);
65 /****************************************************************************
68 * Execute one line from a batch file.
71 void WCMD_batch_command (HANDLE h
, char *command
) {
76 if (echo_mode
&& (command
[0] != '@')) WCMD_output ("%s", command
);
77 status
= ExpandEnvironmentStrings (command
, cmd
, sizeof(cmd
));
82 WCMD_process_command (cmd
);
85 /****************************************************************************
88 * Batch file jump instruction. Not the most efficient algorithm ;-)
89 * Returns FALSE if the specified label cannot be found - the file pointer is
93 BOOL
WCMD_go_to (HANDLE h
, char *label
) {
95 char string
[MAX_PATH
];
97 SetFilePointer (h
, 0, NULL
, FILE_BEGIN
);
98 while (WCMD_fgets (string
, sizeof(string
), h
)) {
99 if ((string
[0] == ':') && (strcmp (&string
[1], label
) == 0)) return TRUE
;
104 /*******************************************************************
105 * WCMD_parameter - extract a parameter from a command line.
107 * Returns the 'n'th space-delimited parameter on the command line.
108 * Parameter is in static storage overwritten on the next call.
109 * Parameters in quotes are handled.
112 char *WCMD_parameter (char *s
, int n
) {
115 static char param
[MAX_PATH
];
126 while ((*s
!= '\0') && (*s
!= '"')) {
142 while ((*s
!= '\0') && (*s
!= ' ')) {
157 /****************************************************************************
160 * Get one line from a batch file. We can't use the native f* functions because
161 * of the filename syntax differences between DOS and Unix.
164 char *WCMD_fgets (char *s
, int n
, HANDLE h
) {
172 status
= ReadFile (h
, s
, 1, &bytes
, NULL
);
173 if ((status
== 0) || (bytes
== 0)) return NULL
;
174 if (*s
== '\n') bytes
= 0;
177 } while ((bytes
== 1) && (n
> 1));