Before Dan gets a sore throat by screaming out too loud, it's time to
remove the console creation code from our CUI programs
It's not the purpose of a CUI program to dictate its environment, but
rather to make the best efforts to behave in the context its creator
have(th) given it... (including console, input/output stream...)
it means that running a CUI program (let's call it foo):
wine foo => will use a a very primitive console (as if foo's output was
printf:ed on stdout, and foo's input was read on stdin). no fancy
support (like cursor pos, colors, scrolling...) will be available
wineconsole foo => will use the ncurse backend of wineconsole (on
current terminal) and will provide a full featured console
I'll provide a bit later a way (for those who really like the user
backend) to use it the same way as wineconsole foo (yes, don't always
believe what's said on wine-devel, those people exist !!)
let's start with wcmd
A+
--
Eric Pouech
Name: wcmd_con
ChangeLog:
- don't create a new console upon startup
- no longer assume we're always attached to a console
License: X11
GenDate: 2003/02/26 19:47:24 UTC
ModifiedFiles: programs/wcmd/builtins.c programs/wcmd/directory.c programs/wcmd/wcmdmain.c
AddedFiles:
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/wcmd/builtins.c,v
retrieving revision 1.17
diff -u -u -r1.17 builtins.c
--- programs/wcmd/builtins.c 11 Feb 2003 22:01:11 -0000 1.17
+++ programs/wcmd/builtins.c 26 Feb 2003 19:36:01 -0000
@@ -55,22 +55,25 @@
* Clear the terminal screen.
*/
-void WCMD_clear_screen () {
+void WCMD_clear_screen (void) {
/* Emulate by filling the screen from the top left to bottom right with
spaces, then moving the cursor to the top left afterwards */
- COORD topLeft;
- long screenSize;
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- GetConsoleScreenBufferInfo(hStdOut, &consoleInfo);
- screenSize = consoleInfo.dwSize.X * (consoleInfo.dwSize.Y + 1);
-
- topLeft.X = 0;
- topLeft.Y = 0;
- FillConsoleOutputCharacter(hStdOut, ' ', screenSize, topLeft, &screenSize);
- SetConsoleCursorPosition(hStdOut, topLeft);
+ if (GetConsoleScreenBufferInfo(hStdOut, &consoleInfo))
+ {
+ COORD topLeft;
+ long screenSize;
+
+ screenSize = consoleInfo.dwSize.X * (consoleInfo.dwSize.Y + 1);
+
+ topLeft.X = 0;
+ topLeft.Y = 0;
+ FillConsoleOutputCharacter(hStdOut, ' ', screenSize, topLeft, &screenSize);
+ SetConsoleCursorPosition(hStdOut, topLeft);
+ }
}
/****************************************************************************
@@ -79,7 +82,7 @@
* Change the default i/o device (ie redirect STDin/STDout).
*/
-void WCMD_change_tty () {
+void WCMD_change_tty (void) {
WCMD_output (nyi);
@@ -92,7 +95,7 @@
* FIXME: No wildcard support
*/
-void WCMD_copy () {
+void WCMD_copy (void) {
DWORD count;
WIN32_FIND_DATA fd;
@@ -145,7 +148,7 @@
* Create a directory.
*/
-void WCMD_create_dir () {
+void WCMD_create_dir (void) {
if (!CreateDirectory (param1, NULL)) WCMD_print_error ();
}
@@ -351,7 +354,7 @@
* FIXME: DOS is supposed to allow labels with spaces - we don't.
*/
-void WCMD_goto () {
+void WCMD_goto (void) {
char string[MAX_PATH];
@@ -423,7 +426,7 @@
* FIXME: Needs input and output files to be fully specified.
*/
-void WCMD_move () {
+void WCMD_move (void) {
int status;
char outpath[MAX_PATH], inpath[MAX_PATH], *infile;
@@ -462,7 +465,7 @@
* Wait for keyboard input.
*/
-void WCMD_pause () {
+void WCMD_pause (void) {
DWORD count;
char string[32];
@@ -477,7 +480,7 @@
* Delete a directory.
*/
-void WCMD_remove_dir () {
+void WCMD_remove_dir (void) {
if (!RemoveDirectory (param1)) WCMD_print_error ();
}
@@ -489,7 +492,7 @@
* FIXME: Needs input and output files to be fully specified.
*/
-void WCMD_rename () {
+void WCMD_rename (void) {
int status;
@@ -514,7 +517,7 @@
*
*/
-void WCMD_setshow_attrib () {
+void WCMD_setshow_attrib (void) {
DWORD count;
HANDLE hff;
@@ -570,7 +573,7 @@
* Set/Show the current default directory
*/
-void WCMD_setshow_default () {
+void WCMD_setshow_default (void) {
BOOL status;
char string[1024];
@@ -597,7 +600,7 @@
* FIXME: Can't change date yet
*/
-void WCMD_setshow_date () {
+void WCMD_setshow_date (void) {
char curdate[64], buffer[64];
DWORD count;
@@ -698,7 +701,7 @@
* Set or show the command prompt.
*/
-void WCMD_setshow_prompt () {
+void WCMD_setshow_prompt (void) {
char *s;
@@ -722,7 +725,7 @@
* FIXME: Can't change time yet
*/
-void WCMD_setshow_time () {
+void WCMD_setshow_time (void) {
char curtime[64], buffer[64];
DWORD count;
@@ -751,7 +754,7 @@
* Shift batch parameters.
*/
-void WCMD_shift () {
+void WCMD_shift (void) {
if (context != NULL) context -> shift_count++;
@@ -772,7 +775,7 @@
* Copy a file to standard output.
*/
-void WCMD_type () {
+void WCMD_type (void) {
HANDLE h;
char buffer[512];
@@ -786,7 +789,8 @@
}
while (ReadFile (h, buffer, sizeof(buffer), &count, NULL)) {
if (count == 0) break; /* ReadFile reports success on EOF! */
- WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buffer, count, &count, NULL);
+ buffer[count] = 0;
+ WCMD_output_asis (buffer);
}
CloseHandle (h);
}
@@ -827,7 +831,7 @@
* Display version info.
*/
-void WCMD_version () {
+void WCMD_version (void) {
WCMD_output (version_string);
@@ -857,7 +861,7 @@
}
else {
if ((path[1] != ':') || (lstrlen(path) != 2)) {
- WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), syntax, strlen(syntax), &count, NULL);
+ WCMD_output_asis(syntax);
return 0;
}
wsprintf (curdir, "%s\", path);
Index: programs/wcmd/directory.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/wcmd/directory.c,v
retrieving revision 1.16
diff -u -u -r1.16 directory.c
--- programs/wcmd/directory.c 25 Feb 2003 03:58:42 -0000 1.16
+++ programs/wcmd/directory.c 26 Feb 2003 19:22:40 -0000
@@ -73,8 +73,10 @@
if (bare) wide = FALSE;
if (wide) {
- GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo);
- max_width = consoleInfo.dwSize.X;
+ if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo))
+ max_width = consoleInfo.dwSize.X;
+ else
+ max_width = 80;
}
if (paged_mode) {
WCMD_enter_paged_mode();
Index: programs/wcmd/wcmdmain.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/wcmd/wcmdmain.c,v
retrieving revision 1.24
diff -u -u -r1.24 wcmdmain.c
--- programs/wcmd/wcmdmain.c 25 Feb 2003 03:58:42 -0000 1.24
+++ programs/wcmd/wcmdmain.c 26 Feb 2003 19:36:00 -0000
@@ -50,7 +50,7 @@
int main (int argc, char *argv[]) {
char string[1024], args[MAX_PATH], param[MAX_PATH];
-int status, i;
+int i;
DWORD count;
HANDLE h;
@@ -77,14 +77,6 @@
return 0;
}
-/*
- * Allocate a console and set it up.
- */
-
- status = FreeConsole ();
- if (!status) WCMD_print_error();
- status = AllocConsole();
- if (!status) WCMD_print_error();
SetConsoleMode (GetStdHandle(STD_INPUT_HANDLE), ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT |
ENABLE_PROCESSED_INPUT);
SetConsoleTitle("Wine Command Prompt");
@@ -425,7 +417,7 @@
*
*/
-void WCMD_show_prompt () {
+void WCMD_show_prompt (void) {
int status;
char out_string[MAX_PATH], curdir[MAX_PATH], prompt_string[MAX_PATH];
@@ -506,7 +498,7 @@
* Print the message for GetLastError
*/
-void WCMD_print_error () {
+void WCMD_print_error (void) {
LPVOID lpMsgBuf;
DWORD error_code;
int status;
@@ -603,8 +595,10 @@
{
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
- GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo);
- max_height = consoleInfo.dwSize.Y;
+ if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo))
+ max_height = consoleInfo.dwSize.Y;
+ else
+ max_height = 25;
paged_mode = TRUE;
line_count = 5; /* keep 5 lines from previous output */
}