This is the mail archive of the
cygwin-patches@cygwin.com
mailing list for the Cygwin project.
Re: [Patch]: Ncurses frame drawing
- From: Micha Nelissen <M dot Nelissen at student dot tue dot nl>
- To: cygwin-patches at cygwin dot com
- Date: Wed, 15 Oct 2003 20:46:57 +0200
- Subject: Re: [Patch]: Ncurses frame drawing
- References: <20031015082724.GJ14344@cygbert.vinschen.de>
Corinna Vinschen wrote:
On Wed, Oct 15, 2003 at 08:50:09AM +0200, Micha Nelissen wrote:
Pierre A. Humblet wrote:
FWIW, wouldn't it be cleaner to make "alternate_charset_active" a
member of dev_state instead of introducing a new global variable?
1) that alternate_charset check which currently is in str_to_con
(centralized), needs to dispersed over all calls to str_to_con.
(Currently, 1, AFAICS). Prone to bugs, if you ask me because this could
be forgotten in the future, unless this one call will remain the only one.
2) str_to_con has to become a member of dev_state too.
Point 2 has some merits. Are you interested to do that change, Micha?
Of course, con_to_str should become a dev_state member then, too.
Ok, attached is a patch with the requested changes.
Regards,
Micha.
Index: dcrt0.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/dcrt0.cc,v
retrieving revision 1.188
diff -u -r1.188 dcrt0.cc
--- dcrt0.cc 15 Oct 2003 08:23:26 -0000 1.188
+++ dcrt0.cc 15 Oct 2003 18:28:00 -0000
@@ -57,7 +57,6 @@
bool strip_title_path;
bool allow_glob = TRUE;
codepage_type current_codepage = ansi_cp;
-bool alternate_charset_active;
int cygwin_finished_initializing;
Index: fhandler.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler.h,v
retrieving revision 1.170
diff -u -r1.170 fhandler.h
--- fhandler.h 1 Oct 2003 12:36:39 -0000 1.170
+++ fhandler.h 15 Oct 2003 18:28:00 -0000
@@ -752,6 +752,7 @@
int nargs_;
unsigned rarg;
bool saw_question_mark;
+ bool alternate_charset_active;
char my_title_buf [TITLESIZE + 1];
@@ -788,6 +789,10 @@
bool insert_mode;
bool use_mouse;
bool raw_win32_keyboard_mode;
+
+ BOOL con_to_str (char *d, const char *s, DWORD sz);
+ BOOL str_to_con (char *d, const char *s, DWORD sz);
+
friend class fhandler_console;
};
Index: fhandler_console.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_console.cc,v
retrieving revision 1.116
diff -u -r1.116 fhandler_console.cc
--- fhandler_console.cc 15 Oct 2003 08:23:26 -0000 1.116
+++ fhandler_console.cc 15 Oct 2003 18:28:03 -0000
@@ -54,27 +54,6 @@
return TRUE;
}
-/* The results of GetConsoleCP() and GetConsoleOutputCP() cannot be
- cached, because a program or the user can change these values at
- any time. */
-inline BOOL
-con_to_str (char *d, const char *s, DWORD sz)
-{
- return cp_convert (get_cp (), d, GetConsoleCP (), s, sz);
-}
-
-inline BOOL
-str_to_con (char *d, const char *s, DWORD sz)
-{
- if (alternate_charset_active)
- {
- /* no translation when alternate charset is active */
- memcpy(d, s, sz);
- return TRUE;
- }
- return cp_convert (GetConsoleOutputCP (), d, get_cp (), s, sz);
-}
-
/*
* Scroll the screen context.
* x1, y1 - ul corner
@@ -187,6 +166,27 @@
return 1;
}
+/* The results of GetConsoleCP() and GetConsoleOutputCP() cannot be
+ cached, because a program or the user can change these values at
+ any time. */
+inline BOOL
+dev_console::con_to_str (char *d, const char *s, DWORD sz)
+{
+ return cp_convert (get_cp (), d, GetConsoleCP (), s, sz);
+}
+
+inline BOOL
+dev_console::str_to_con (char *d, const char *s, DWORD sz)
+{
+ if (alternate_charset_active)
+ {
+ /* no translation when alternate charset is active */
+ memcpy(d, s, sz);
+ return TRUE;
+ }
+ return cp_convert (GetConsoleOutputCP (), d, get_cp (), s, sz);
+}
+
BOOL
fhandler_console::set_raw_win32_keyboard_mode (BOOL new_mode)
{
@@ -375,7 +375,7 @@
/* Need this check since US code page seems to have a bug when
converting a CTRL-U. */
if ((unsigned char) ich > 0x7f)
- con_to_str (tmp + 1, tmp + 1, 1);
+ dev_state->con_to_str (tmp + 1, tmp + 1, 1);
/* Determine if the keystroke is modified by META. The tricky
part is to distinguish whether the right Alt key should be
recognized as Alt, or as AltGr. */
@@ -1118,10 +1118,10 @@
dev_state->intensity = INTENSITY_DIM;
break;
case 10: /* end alternate charset */
- alternate_charset_active = FALSE;
+ dev_state->alternate_charset_active = FALSE;
break;
case 11: /* start alternate charset */
- alternate_charset_active = TRUE;
+ dev_state->alternate_charset_active = TRUE;
break;
case 24:
dev_state->underline = FALSE;
@@ -1434,7 +1434,7 @@
DWORD buf_len;
char buf[CONVERT_LIMIT];
done = buf_len = min (sizeof (buf), len);
- if (!str_to_con (buf, (const char *) src, buf_len))
+ if (!dev_state->str_to_con (buf, (const char *) src, buf_len))
{
debug_printf ("conversion error, handle %p",
get_output_handle ());
Index: winsup.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/winsup.h,v
retrieving revision 1.121
diff -u -r1.121 winsup.h
--- winsup.h 15 Oct 2003 08:23:26 -0000 1.121
+++ winsup.h 15 Oct 2003 18:28:04 -0000
@@ -90,7 +90,6 @@
enum codepage_type {ansi_cp, oem_cp};
extern codepage_type current_codepage;
-extern bool alternate_charset_active;
UINT get_cp ();
2003-10-15 Micha Nelissen <M.Nelissen@student.tue.nl>
* dcrt0.cc: Remove local variable alternate_charset_active.
* fhandler.h: Add variable alternate_charset_active, functions
str_to_con, con_to_str to dev_console structure.
* fhandler_console.cc (con_to_str, str_to_con): Move functions to
into dev_console class.
(read): Call con_to_str on dev_state.
(write_normal): Call str_to_con on dev_state.
(char_command): Change active_charset_active assignment to be on
dev_state.
* winsup.h: Remove global external variable alternate_charset_active.