Reformat all C files.

I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
This commit is contained in:
Sean Hunt
2015-05-09 13:43:16 -04:00
parent 167800afdf
commit 97d6fade74
270 changed files with 182649 additions and 173878 deletions
+641 -575
View File
File diff suppressed because it is too large Load Diff
+12 -10
View File
@@ -1,13 +1,13 @@
/* NetHack 3.6 cesound.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 cesound.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.12 $ */
/* NetHack 3.6 cesound.c $Date: 2009/05/06 10:52:00 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)cesound.c 3.5 $NHDT-Date$ */
/* SCCS Id: @(#)cesound.c 3.5 $Date: 2009/05/06 10:52:00 $ */
/* SCCS Id: @(#)cesound.c 3.5 $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ */
/* SCCS Id: @(#)cesound.c 3.5 $Date: 2009/05/06 10:52:00 $ */
/* Copyright (c) NetHack PC Development Team 1993 */
/* NetHack may be freely redistributed. See license for details. */
/* */
/*
* cesound.c - Windows CE NetHack sound support
*
*
*
*/
@@ -16,14 +16,16 @@
#ifdef USER_SOUNDS
void play_usersound(filename, volume)
const char* filename;
void
play_usersound(filename, volume)
const char *filename;
int volume;
{
TCHAR wbuf[MAX_PATH+1];
/* pline("play_usersound: %s (%d).", filename, volume); */
ZeroMemory(wbuf, sizeof(wbuf));
(void)sndPlaySound(NH_A2W(filename, wbuf, MAX_PATH), SND_ASYNC | SND_NODEFAULT);
TCHAR wbuf[MAX_PATH + 1];
/* pline("play_usersound: %s (%d).", filename, volume); */
ZeroMemory(wbuf, sizeof(wbuf));
(void) sndPlaySound(NH_A2W(filename, wbuf, MAX_PATH),
SND_ASYNC | SND_NODEFAULT);
}
#endif /*USER_SOUNDS*/
+4 -4
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhaskyn.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhaskyn.c $NHDT-Date: 1431192787 2015/05/09 17:33:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 mhaskyn.c $Date: 2009/05/06 10:52:00 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)mhaskyn.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -8,8 +8,8 @@
#include "winMS.h"
#include "mhaskyn.h"
int mswin_yes_no_dialog( const char *question, const char *choices, int def)
int
mswin_yes_no_dialog(const char *question, const char *choices, int def)
{
return '\032';
return '\032';
}
+1171 -1066
View File
File diff suppressed because it is too large Load Diff
+176 -161
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhcolor.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhcolor.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */
/* NetHack 3.6 mhcolor.c $Date: 2009/05/06 10:52:03 $ $Revision: 1.3 $ */
/* SCCS Id: @(#)mhcolor.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -9,41 +9,40 @@
#include "winMS.h"
#include "mhcolor.h"
#define TOTAL_BRUSHES 10
#define NHBRUSH_CODE(win, type) ((((win)&0xFF)<<8)|((type)&0xFF))
#define TOTAL_BRUSHES 10
#define NHBRUSH_CODE(win, type) ((((win) &0xFF) << 8) | ((type) &0xFF))
struct t_brush_table {
int code;
HBRUSH brush;
COLORREF color;
int code;
HBRUSH brush;
COLORREF color;
};
static struct t_brush_table brush_table[TOTAL_BRUSHES];
static int max_brush = 0;
static struct t_brush_table default_brush_table[] =
{
{ NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_FG), NULL, RGB(96, 96, 96) },
static struct t_brush_table default_brush_table[] = {
{ NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
{ NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_FG), NULL, RGB(96, 96, 96) },
{ NHBRUSH_CODE(NHW_MENU, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) },
{ NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) },
{ NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) },
{ NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) },
{ NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) },
{ NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) },
{ -1, NULL, RGB(0, 0, 0) }
{ NHBRUSH_CODE(NHW_MENU, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) },
{ NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) },
{ NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) },
{ NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) },
{ NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) },
{ NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) },
{ -1, NULL, RGB(0, 0, 0) }
};
static void mswin_color_from_string(char *colorstring, HBRUSH* brushptr, COLORREF *colorptr);
static void mswin_color_from_string(char *colorstring, HBRUSH *brushptr,
COLORREF *colorptr);
typedef struct ctv
{
const char *colorstring;
COLORREF colorvalue;
typedef struct ctv {
const char *colorstring;
COLORREF colorvalue;
} color_table_value;
/*
@@ -53,168 +52,184 @@ typedef struct ctv
*/
static color_table_value color_table[] = {
/* NetHack colors */
{ "black", RGB(0x55, 0x55, 0x55)},
{ "red", RGB(0xFF, 0x00, 0x00)},
{ "green", RGB(0x00, 0x80, 0x00)},
{ "brown", RGB(0xA5, 0x2A, 0x2A)},
{ "blue", RGB(0x00, 0x00, 0xFF)},
{ "magenta", RGB(0xFF, 0x00, 0xFF)},
{ "cyan", RGB(0x00, 0xFF, 0xFF)},
{ "orange", RGB(0xFF, 0xA5, 0x00)},
{ "brightgreen", RGB(0x00, 0xFF, 0x00)},
{ "yellow", RGB(0xFF, 0xFF, 0x00)},
{ "brightblue", RGB(0x00, 0xC0, 0xFF)},
{ "brightmagenta", RGB(0xFF, 0x80, 0xFF)},
{ "brightcyan", RGB(0x80, 0xFF, 0xFF)},
{ "white", RGB(0xFF, 0xFF, 0xFF)},
/* Remaining HTML colors */
{ "trueblack", RGB(0x00, 0x00, 0x00)},
{ "gray", RGB(0x80, 0x80, 0x80)},
{ "grey", RGB(0x80, 0x80, 0x80)},
{ "purple", RGB(0x80, 0x00, 0x80)},
{ "silver", RGB(0xC0, 0xC0, 0xC0)},
{ "maroon", RGB(0x80, 0x00, 0x00)},
{ "fuchsia", RGB(0xFF, 0x00, 0xFF)}, /* = NetHack magenta */
{ "lime", RGB(0x00, 0xFF, 0x00)}, /* = NetHack bright green */
{ "olive", RGB(0x80, 0x80, 0x00)},
{ "navy", RGB(0x00, 0x00, 0x80)},
{ "teal", RGB(0x00, 0x80, 0x80)},
{ "aqua", RGB(0x00, 0xFF, 0xFF)}, /* = NetHack cyan */
{ "", RGB(0x00, 0x00, 0x00)},
/* NetHack colors */
{ "black", RGB(0x55, 0x55, 0x55) },
{ "red", RGB(0xFF, 0x00, 0x00) },
{ "green", RGB(0x00, 0x80, 0x00) },
{ "brown", RGB(0xA5, 0x2A, 0x2A) },
{ "blue", RGB(0x00, 0x00, 0xFF) },
{ "magenta", RGB(0xFF, 0x00, 0xFF) },
{ "cyan", RGB(0x00, 0xFF, 0xFF) },
{ "orange", RGB(0xFF, 0xA5, 0x00) },
{ "brightgreen", RGB(0x00, 0xFF, 0x00) },
{ "yellow", RGB(0xFF, 0xFF, 0x00) },
{ "brightblue", RGB(0x00, 0xC0, 0xFF) },
{ "brightmagenta", RGB(0xFF, 0x80, 0xFF) },
{ "brightcyan", RGB(0x80, 0xFF, 0xFF) },
{ "white", RGB(0xFF, 0xFF, 0xFF) },
/* Remaining HTML colors */
{ "trueblack", RGB(0x00, 0x00, 0x00) },
{ "gray", RGB(0x80, 0x80, 0x80) },
{ "grey", RGB(0x80, 0x80, 0x80) },
{ "purple", RGB(0x80, 0x00, 0x80) },
{ "silver", RGB(0xC0, 0xC0, 0xC0) },
{ "maroon", RGB(0x80, 0x00, 0x00) },
{ "fuchsia", RGB(0xFF, 0x00, 0xFF) }, /* = NetHack magenta */
{ "lime", RGB(0x00, 0xFF, 0x00) }, /* = NetHack bright green */
{ "olive", RGB(0x80, 0x80, 0x00) },
{ "navy", RGB(0x00, 0x00, 0x80) },
{ "teal", RGB(0x00, 0x80, 0x80) },
{ "aqua", RGB(0x00, 0xFF, 0xFF) }, /* = NetHack cyan */
{ "", RGB(0x00, 0x00, 0x00) },
};
typedef struct ctbv
{
char *colorstring;
int syscolorvalue;
typedef struct ctbv {
char *colorstring;
int syscolorvalue;
} color_table_brush_value;
static color_table_brush_value color_table_brush[] = {
{ "activeborder", COLOR_ACTIVEBORDER },
{ "activecaption", COLOR_ACTIVECAPTION },
{ "appworkspace", COLOR_APPWORKSPACE },
{ "background", COLOR_BACKGROUND },
{ "btnface", COLOR_BTNFACE },
{ "btnshadow", COLOR_BTNSHADOW },
{ "btntext", COLOR_BTNTEXT },
{ "captiontext", COLOR_CAPTIONTEXT },
{ "graytext", COLOR_GRAYTEXT },
{ "greytext", COLOR_GRAYTEXT },
{ "highlight", COLOR_HIGHLIGHT },
{ "highlighttext", COLOR_HIGHLIGHTTEXT },
{ "inactiveborder", COLOR_INACTIVEBORDER },
{ "inactivecaption", COLOR_INACTIVECAPTION },
{ "menu", COLOR_MENU },
{ "menutext", COLOR_MENUTEXT },
{ "scrollbar", COLOR_SCROLLBAR },
{ "window", COLOR_WINDOW },
{ "windowframe", COLOR_WINDOWFRAME },
{ "windowtext", COLOR_WINDOWTEXT },
{ "", -1 },
{ "activeborder", COLOR_ACTIVEBORDER },
{ "activecaption", COLOR_ACTIVECAPTION },
{ "appworkspace", COLOR_APPWORKSPACE },
{ "background", COLOR_BACKGROUND },
{ "btnface", COLOR_BTNFACE },
{ "btnshadow", COLOR_BTNSHADOW },
{ "btntext", COLOR_BTNTEXT },
{ "captiontext", COLOR_CAPTIONTEXT },
{ "graytext", COLOR_GRAYTEXT },
{ "greytext", COLOR_GRAYTEXT },
{ "highlight", COLOR_HIGHLIGHT },
{ "highlighttext", COLOR_HIGHLIGHTTEXT },
{ "inactiveborder", COLOR_INACTIVEBORDER },
{ "inactivecaption", COLOR_INACTIVECAPTION },
{ "menu", COLOR_MENU },
{ "menutext", COLOR_MENUTEXT },
{ "scrollbar", COLOR_SCROLLBAR },
{ "window", COLOR_WINDOW },
{ "windowframe", COLOR_WINDOWFRAME },
{ "windowtext", COLOR_WINDOWTEXT },
{ "", -1 },
};
void mswin_init_color_table()
void
mswin_init_color_table()
{
int i;
struct t_brush_table* p;
int i;
struct t_brush_table *p;
/* cleanup */
for( i=0; i<max_brush; i++ )
DeleteObject(brush_table[i].brush);
max_brush = 0;
/* cleanup */
for (i = 0; i < max_brush; i++)
DeleteObject(brush_table[i].brush);
max_brush = 0;
/* initialize brush table */
#define BRUSHTABLE_ENTRY(opt, win, type) \
brush_table[max_brush].code = NHBRUSH_CODE((win), (type)); \
mswin_color_from_string((opt), &brush_table[max_brush].brush, &brush_table[max_brush].color); \
max_brush++;
/* initialize brush table */
#define BRUSHTABLE_ENTRY(opt, win, type) \
brush_table[max_brush].code = NHBRUSH_CODE((win), (type)); \
mswin_color_from_string((opt), &brush_table[max_brush].brush, \
&brush_table[max_brush].color); \
max_brush++;
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_menu, NHW_MENU, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_message, NHW_MESSAGE, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_status, NHW_STATUS, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_text, NHW_TEXT, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_message, NHW_KEYPAD, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_menu, NHW_MENU, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_message, NHW_MESSAGE, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_status, NHW_STATUS, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_text, NHW_TEXT, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_foregrnd_message, NHW_KEYPAD, MSWIN_COLOR_FG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_menu, NHW_MENU, MSWIN_COLOR_BG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_message, NHW_MESSAGE, MSWIN_COLOR_BG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_status, NHW_STATUS, MSWIN_COLOR_BG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_text, NHW_TEXT, MSWIN_COLOR_BG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_message, NHW_KEYPAD, MSWIN_COLOR_BG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_menu, NHW_MENU, MSWIN_COLOR_BG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_message, NHW_MESSAGE, MSWIN_COLOR_BG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_status, NHW_STATUS, MSWIN_COLOR_BG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_text, NHW_TEXT, MSWIN_COLOR_BG);
BRUSHTABLE_ENTRY(iflags.wc_backgrnd_message, NHW_KEYPAD, MSWIN_COLOR_BG);
#undef BRUSHTABLE_ENTRY
/* go through the values and fill in "blanks" (use default values) */
for( i=0; i<max_brush; i++ ) {
if( !brush_table[i].brush ) {
for( p = default_brush_table; p->code != -1; p++ ) {
if( p->code==brush_table[i].code ) {
brush_table[i].brush = CreateSolidBrush(p->color);
brush_table[i].color = p->color;
}
}
}
}
/* go through the values and fill in "blanks" (use default values) */
for (i = 0; i < max_brush; i++) {
if (!brush_table[i].brush) {
for (p = default_brush_table; p->code != -1; p++) {
if (p->code == brush_table[i].code) {
brush_table[i].brush = CreateSolidBrush(p->color);
brush_table[i].color = p->color;
}
}
}
}
}
HBRUSH mswin_get_brush(int win_type, int color_index)
HBRUSH
mswin_get_brush(int win_type, int color_index)
{
int i;
for(i=0; i<max_brush; i++)
if( brush_table[i].code == NHBRUSH_CODE(win_type, color_index) )
return brush_table[i].brush;
return NULL;
int i;
for (i = 0; i < max_brush; i++)
if (brush_table[i].code == NHBRUSH_CODE(win_type, color_index))
return brush_table[i].brush;
return NULL;
}
COLORREF mswin_get_color(int win_type, int color_index)
COLORREF
mswin_get_color(int win_type, int color_index)
{
int i;
for(i=0; i<max_brush; i++)
if( brush_table[i].code == NHBRUSH_CODE(win_type, color_index) )
return brush_table[i].color;
return RGB(0, 0, 0);
int i;
for (i = 0; i < max_brush; i++)
if (brush_table[i].code == NHBRUSH_CODE(win_type, color_index))
return brush_table[i].color;
return RGB(0, 0, 0);
}
static void mswin_color_from_string(char *colorstring, HBRUSH* brushptr, COLORREF *colorptr)
static void
mswin_color_from_string(char *colorstring, HBRUSH *brushptr,
COLORREF *colorptr)
{
color_table_value *ctv_ptr = color_table;
color_table_brush_value *ctbv_ptr = color_table_brush;
int red_value, blue_value, green_value;
static char *hexadecimals = "0123456789abcdef";
color_table_value *ctv_ptr = color_table;
color_table_brush_value *ctbv_ptr = color_table_brush;
int red_value, blue_value, green_value;
static char *hexadecimals = "0123456789abcdef";
*brushptr = NULL;
*colorptr = RGB(0, 0, 0);
*brushptr = NULL;
*colorptr = RGB(0, 0, 0);
if (colorstring == NULL) return;
if (*colorstring == '#') {
if (strlen(++colorstring) != 6) return;
if (colorstring == NULL)
return;
if (*colorstring == '#') {
if (strlen(++colorstring) != 6)
return;
red_value = index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
red_value *= 16;
red_value += index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
red_value =
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
red_value *= 16;
red_value +=
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
green_value = index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
green_value *= 16;
green_value += index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
green_value =
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
green_value *= 16;
green_value +=
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
blue_value = index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
blue_value *= 16;
blue_value += index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
blue_value =
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
blue_value *= 16;
blue_value +=
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
*colorptr = RGB(red_value, blue_value, green_value);
} else {
while (*ctv_ptr->colorstring && _stricmp(ctv_ptr->colorstring, colorstring))
++ctv_ptr;
if (*ctv_ptr->colorstring) {
*colorptr = ctv_ptr->colorvalue;
} else {
while (*ctbv_ptr->colorstring && _stricmp(ctbv_ptr->colorstring, colorstring))
++ctbv_ptr;
if (*ctbv_ptr->colorstring) {
*brushptr = SYSCLR_TO_BRUSH(ctbv_ptr->syscolorvalue);
*colorptr = GetSysColor(ctbv_ptr->syscolorvalue);
}
}
}
if (max_brush > TOTAL_BRUSHES) panic("Too many colors!");
*brushptr = CreateSolidBrush(*colorptr);
*colorptr = RGB(red_value, blue_value, green_value);
} else {
while (*ctv_ptr->colorstring
&& _stricmp(ctv_ptr->colorstring, colorstring))
++ctv_ptr;
if (*ctv_ptr->colorstring) {
*colorptr = ctv_ptr->colorvalue;
} else {
while (*ctbv_ptr->colorstring
&& _stricmp(ctbv_ptr->colorstring, colorstring))
++ctbv_ptr;
if (*ctbv_ptr->colorstring) {
*brushptr = SYSCLR_TO_BRUSH(ctbv_ptr->syscolorvalue);
*colorptr = GetSysColor(ctbv_ptr->syscolorvalue);
}
}
}
if (max_brush > TOTAL_BRUSHES)
panic("Too many colors!");
*brushptr = CreateSolidBrush(*colorptr);
}
+666 -629
View File
File diff suppressed because it is too large Load Diff
+156 -139
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhfont.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhfont.c $NHDT-Date: 1431192787 2015/05/09 17:33:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.17 $ */
/* NetHack 3.6 mhfont.c $Date: 2009/05/06 10:52:08 $ $Revision: 1.6 $ */
/* SCCS Id: @(#)mhfont.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -8,173 +8,190 @@
#include "mhfont.h"
#define MAXFONTS 64
#define MAXFONTS 64
/* font table - 64 fonts ought to be enough */
static struct font_table_entry {
int code;
HFONT hFont;
} font_table[MAXFONTS] ;
int code;
HFONT hFont;
} font_table[MAXFONTS];
static int font_table_size = 0;
HFONT version_splash_font;
HFONT extrainfo_splash_font;
#define NHFONT_CODE(win, attr) (((attr&0xFF)<<8)|(win_type&0xFF))
#define NHFONT_CODE(win, attr) (((attr & 0xFF) << 8) | (win_type & 0xFF))
static void __cdecl font_table_cleanup(void);
/* create font based on window type, charater attributes and
window device context */
HGDIOBJ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace)
HGDIOBJ
mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace)
{
HFONT fnt = NULL;
LOGFONT lgfnt;
int font_size;
int font_index;
static BOOL once = FALSE;
HFONT fnt = NULL;
LOGFONT lgfnt;
int font_size;
int font_index;
static BOOL once = FALSE;
if( !once ) {
once = TRUE;
atexit(font_table_cleanup);
}
if (!once) {
once = TRUE;
atexit(font_table_cleanup);
}
ZeroMemory( &lgfnt, sizeof(lgfnt) );
ZeroMemory(&lgfnt, sizeof(lgfnt));
/* try find font in the table */
for(font_index=0; font_index<font_table_size; font_index++)
if(NHFONT_CODE(win_type, attr)==font_table[font_index].code)
break;
/* try find font in the table */
for (font_index = 0; font_index < font_table_size; font_index++)
if (NHFONT_CODE(win_type, attr) == font_table[font_index].code)
break;
if( !replace && font_index<font_table_size )
return font_table[font_index].hFont;
if (!replace && font_index < font_table_size)
return font_table[font_index].hFont;
switch(win_type) {
case NHW_STATUS:
lgfnt.lfHeight = -iflags.wc_fontsiz_status*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = FW_NORMAL; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_status &&
*iflags.wc_font_status ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_status, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
switch (win_type) {
case NHW_STATUS:
lgfnt.lfHeight = -iflags.wc_fontsiz_status
* GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = FW_NORMAL; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_status && *iflags.wc_font_status) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_status, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
case NHW_MENU:
lgfnt.lfHeight = -iflags.wc_fontsiz_menu*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_menu &&
*iflags.wc_font_menu ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_menu, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
case NHW_MENU:
lgfnt.lfHeight = -iflags.wc_fontsiz_menu
* GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr == ATR_BOLD || attr == ATR_INVERSE)
? FW_BOLD
: FW_NORMAL; // font weight
lgfnt.lfItalic =
(attr == ATR_BLINK) ? TRUE : FALSE; // italic attribute option
lgfnt.lfUnderline =
(attr == ATR_ULINE) ? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_menu && *iflags.wc_font_menu) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_menu, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
case NHW_MESSAGE:
font_size = (attr==ATR_INVERSE)? iflags.wc_fontsiz_message+1 : iflags.wc_fontsiz_message;
lgfnt.lfHeight = -font_size*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_message &&
*iflags.wc_font_message ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family
}
break;
case NHW_MESSAGE:
font_size = (attr == ATR_INVERSE) ? iflags.wc_fontsiz_message + 1
: iflags.wc_fontsiz_message;
lgfnt.lfHeight = -font_size * GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr == ATR_BOLD || attr == ATR_INVERSE)
? FW_BOLD
: FW_NORMAL; // font weight
lgfnt.lfItalic =
(attr == ATR_BLINK) ? TRUE : FALSE; // italic attribute option
lgfnt.lfUnderline =
(attr == ATR_ULINE) ? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_message && *iflags.wc_font_message) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family
}
break;
case NHW_TEXT:
lgfnt.lfHeight = -iflags.wc_fontsiz_text*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_text &&
*iflags.wc_font_text ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_text, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
}
case NHW_TEXT:
lgfnt.lfHeight = -iflags.wc_fontsiz_text
* GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr == ATR_BOLD || attr == ATR_INVERSE)
? FW_BOLD
: FW_NORMAL; // font weight
lgfnt.lfItalic =
(attr == ATR_BLINK) ? TRUE : FALSE; // italic attribute option
lgfnt.lfUnderline =
(attr == ATR_ULINE) ? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_text && *iflags.wc_font_text) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_text, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
}
fnt = CreateFontIndirect(&lgfnt);
fnt = CreateFontIndirect(&lgfnt);
/* add font to the table */
if( font_index==font_table_size ) {
if( font_table_size>=MAXFONTS ) panic( "font table overflow!" );
font_table_size++;
} else {
DeleteObject(font_table[font_index].hFont);
}
/* add font to the table */
if (font_index == font_table_size) {
if (font_table_size >= MAXFONTS)
panic("font table overflow!");
font_table_size++;
} else {
DeleteObject(font_table[font_index].hFont);
}
font_table[font_index].code = NHFONT_CODE(win_type, attr);
font_table[font_index].hFont = fnt;
return fnt;
font_table[font_index].code = NHFONT_CODE(win_type, attr);
font_table[font_index].hFont = fnt;
return fnt;
}
UINT mswin_charset()
UINT
mswin_charset()
{
CHARSETINFO cis;
if( SYMHANDLING(H_IBM) )
if( TranslateCharsetInfo((DWORD*)GetOEMCP(), &cis, TCI_SRCCODEPAGE) )
return cis.ciCharset;
else
return OEM_CHARSET;
else
if( TranslateCharsetInfo((DWORD*)GetACP(), &cis, TCI_SRCCODEPAGE) )
return cis.ciCharset;
else
return ANSI_CHARSET;
CHARSETINFO cis;
if (SYMHANDLING(H_IBM))
if (TranslateCharsetInfo((DWORD *) GetOEMCP(), &cis, TCI_SRCCODEPAGE))
return cis.ciCharset;
else
return OEM_CHARSET;
else if (TranslateCharsetInfo((DWORD *) GetACP(), &cis, TCI_SRCCODEPAGE))
return cis.ciCharset;
else
return ANSI_CHARSET;
}
void __cdecl font_table_cleanup(void)
{
int i;
for(i=0; i<font_table_size; i++) {
DeleteObject(font_table[i].hFont);
}
font_table_size = 0;
int i;
for (i = 0; i < font_table_size; i++) {
DeleteObject(font_table[i].hFont);
}
font_table_size = 0;
}
+64 -58
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhinput.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhinput.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
/* NetHack 3.6 mhinput.c $Date: 2009/05/06 10:52:10 $ $Revision: 1.5 $ */
/* SCCS Id: @(#)mhinput.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -10,9 +10,9 @@
/* nethack input queue functions */
#define NH_INPUT_BUFFER_SIZE 64
#define NH_INPUT_BUFFER_SIZE 64
/* as it stands right now we need only one slot
/* as it stands right now we need only one slot
since events are processed almost the same time as
they occur but I like large round numbers */
@@ -22,93 +22,99 @@ static int nhi_read_pos = 0;
static int nhi_write_pos = 0;
/* initialize input queue */
void mswin_nh_input_init()
void
mswin_nh_input_init()
{
if( !nhi_init_input ) {
nhi_init_input = 1;
if (!nhi_init_input) {
nhi_init_input = 1;
ZeroMemory( nhi_input_buffer, sizeof(nhi_input_buffer) );
nhi_read_pos = 0;
nhi_write_pos = 0;
}
ZeroMemory(nhi_input_buffer, sizeof(nhi_input_buffer));
nhi_read_pos = 0;
nhi_write_pos = 0;
}
}
/* check for input */
int mswin_have_input()
int
mswin_have_input()
{
return
return
#ifdef SAFERHANGUP
/* we always have input (ESC) if hangup was requested */
program_state.done_hup ||
/* we always have input (ESC) if hangup was requested */
program_state.done_hup ||
#endif
(nhi_read_pos!=nhi_write_pos);
(nhi_read_pos != nhi_write_pos);
}
/* add event to the queue */
void mswin_input_push(PMSNHEvent event)
void
mswin_input_push(PMSNHEvent event)
{
int new_write_pos;
int new_write_pos;
if( !nhi_init_input ) mswin_nh_input_init();
if (!nhi_init_input)
mswin_nh_input_init();
new_write_pos = (nhi_write_pos+1) % NH_INPUT_BUFFER_SIZE;
if(new_write_pos!=nhi_read_pos) {
memcpy(nhi_input_buffer+nhi_write_pos, event, sizeof(*event));
nhi_write_pos = new_write_pos;
}
new_write_pos = (nhi_write_pos + 1) % NH_INPUT_BUFFER_SIZE;
if (new_write_pos != nhi_read_pos) {
memcpy(nhi_input_buffer + nhi_write_pos, event, sizeof(*event));
nhi_write_pos = new_write_pos;
}
}
/* get event from the queue and delete it */
PMSNHEvent mswin_input_pop()
PMSNHEvent
mswin_input_pop()
{
PMSNHEvent retval;
PMSNHEvent retval;
#ifdef SAFERHANGUP
/* always return ESC when hangup was requested */
if( program_state.done_hup ) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
/* always return ESC when hangup was requested */
if (program_state.done_hup) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
#endif
if( !nhi_init_input ) mswin_nh_input_init();
if (!nhi_init_input)
mswin_nh_input_init();
if( nhi_read_pos!=nhi_write_pos ) {
retval = &nhi_input_buffer[nhi_read_pos];
nhi_read_pos = (nhi_read_pos+1) % NH_INPUT_BUFFER_SIZE;
} else {
retval = NULL;
}
if (nhi_read_pos != nhi_write_pos) {
retval = &nhi_input_buffer[nhi_read_pos];
nhi_read_pos = (nhi_read_pos + 1) % NH_INPUT_BUFFER_SIZE;
} else {
retval = NULL;
}
return retval;
return retval;
}
/* get event from the queue but leave it there */
PMSNHEvent mswin_input_peek()
PMSNHEvent
mswin_input_peek()
{
PMSNHEvent retval;
PMSNHEvent retval;
#ifdef SAFERHANGUP
/* always return ESC when hangup was requested */
if( program_state.done_hup ) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
/* always return ESC when hangup was requested */
if (program_state.done_hup) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
#endif
if( !nhi_init_input ) mswin_nh_input_init();
if (!nhi_init_input)
mswin_nh_input_init();
if( nhi_read_pos!=nhi_write_pos ) {
retval = &nhi_input_buffer[nhi_read_pos];
} else {
retval = NULL;
}
return retval;
if (nhi_read_pos != nhi_write_pos) {
retval = &nhi_input_buffer[nhi_read_pos];
} else {
retval = NULL;
}
return retval;
}
+891 -934
View File
File diff suppressed because it is too large Load Diff
+765 -726
View File
File diff suppressed because it is too large Load Diff
+1333 -1294
View File
File diff suppressed because it is too large Load Diff
+537 -519
View File
File diff suppressed because it is too large Load Diff
+7 -6
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhrip.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhrip.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 mhrip.c $Date: 2009/05/06 10:52:26 $ $Revision: 1.5 $ */
/* SCCS Id: @(#)mhrip.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -8,13 +8,14 @@
#include "mhrip.h"
#include "mhtext.h"
HWND mswin_init_RIP_window ()
HWND
mswin_init_RIP_window()
{
return mswin_init_text_window();
return mswin_init_text_window();
}
void mswin_display_RIP_window (HWND hWnd)
void
mswin_display_RIP_window(HWND hWnd)
{
mswin_display_text_window(hWnd);
mswin_display_text_window(hWnd);
}
+233 -221
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhstatus.c $NHDT-Date: 1425083082 2015/02/28 00:24:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 mhstatus.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */
/* NetHack 3.6 mhstatus.c $Date: 2009/05/06 10:52:28 $ $Revision: 1.7 $ */
/* SCCS Id: @(#)mhstatus.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -12,259 +12,271 @@
#define MAXWINDOWTEXT 255
#define NHSTAT_LINES_2 2
#define NHSTAT_LINES_4 4
#define NHSTAT_LINES_2 2
#define NHSTAT_LINES_4 4
typedef struct mswin_nethack_status_window {
int nhstat_format;
char window_text[MAXWINDOWTEXT];
int nhstat_format;
char window_text[MAXWINDOWTEXT];
} NHStatusWindow, *PNHStatusWindow;
static TCHAR szStatusWindowClass[] = TEXT("MSNHStatusWndClass");
LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
static void register_status_window_class(void);
static void FormatStatusString(char* text, int format);
static void FormatStatusString(char *text, int format);
HWND mswin_init_status_window () {
static int run_once = 0;
HWND ret;
NHStatusWindow* data;
if( !run_once ) {
register_status_window_class( );
run_once = 1;
}
ret = CreateWindow(
szStatusWindowClass,
NULL,
WS_CHILD | WS_DISABLED | WS_CLIPSIBLINGS,
0, /* x position */
0, /* y position */
0, /* x-size - we will set it later */
0, /* y-size - we will set it later */
GetNHApp()->hMainWnd,
NULL,
GetNHApp()->hApp,
NULL );
if( !ret ) panic("Cannot create status window");
EnableWindow(ret, FALSE);
data = (PNHStatusWindow)malloc(sizeof(NHStatusWindow));
if( !data ) panic("out of memory");
ZeroMemory(data, sizeof(NHStatusWindow));
data->nhstat_format = NHSTAT_LINES_4;
SetWindowLong(ret, GWL_USERDATA, (LONG)data);
return ret;
}
void register_status_window_class()
HWND
mswin_init_status_window()
{
WNDCLASS wcex;
ZeroMemory( &wcex, sizeof(wcex));
wcex.style = CS_NOCLOSE;
wcex.lpfnWndProc = (WNDPROC)StatusWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetNHApp()->hApp;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = mswin_get_brush(NHW_STATUS, MSWIN_COLOR_BG);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szStatusWindowClass;
static int run_once = 0;
HWND ret;
NHStatusWindow *data;
RegisterClass(&wcex);
if (!run_once) {
register_status_window_class();
run_once = 1;
}
ret = CreateWindow(szStatusWindowClass, NULL,
WS_CHILD | WS_DISABLED | WS_CLIPSIBLINGS,
0, /* x position */
0, /* y position */
0, /* x-size - we will set it later */
0, /* y-size - we will set it later */
GetNHApp()->hMainWnd, NULL, GetNHApp()->hApp, NULL);
if (!ret)
panic("Cannot create status window");
EnableWindow(ret, FALSE);
data = (PNHStatusWindow) malloc(sizeof(NHStatusWindow));
if (!data)
panic("out of memory");
ZeroMemory(data, sizeof(NHStatusWindow));
data->nhstat_format = NHSTAT_LINES_4;
SetWindowLong(ret, GWL_USERDATA, (LONG) data);
return ret;
}
LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
void
register_status_window_class()
{
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
data = (PNHStatusWindow)GetWindowLong(hWnd, GWL_USERDATA);
switch (message)
{
case WM_MSNH_COMMAND: {
switch( wParam ) {
case MSNH_MSG_PUTSTR:
case MSNH_MSG_CLEAR_WINDOW:
ZeroMemory(data->window_text, sizeof(data->window_text));
FormatStatusString(data->window_text, data->nhstat_format);
break;
WNDCLASS wcex;
case MSNH_MSG_CURSOR: {
PMSNHMsgCursor msg_data = (PMSNHMsgCursor)lParam;
if( msg_data->y==0 ) {
InvalidateRect(hWnd, NULL, TRUE);
}
} break;
}
} break;
ZeroMemory(&wcex, sizeof(wcex));
wcex.style = CS_NOCLOSE;
wcex.lpfnWndProc = (WNDPROC) StatusWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetNHApp()->hApp;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = mswin_get_brush(NHW_STATUS, MSWIN_COLOR_BG);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szStatusWindowClass;
case WM_PAINT: {
HGDIOBJ oldFont;
TCHAR wbuf[MAXWINDOWTEXT];
COLORREF OldBg, OldFg;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
oldFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
OldBg = SetBkColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_BG));
OldFg = SetTextColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_FG));
DrawText(hdc,
NH_A2W(data->window_text, wbuf, MAXWINDOWTEXT),
strlen(data->window_text),
&rt,
DT_LEFT | DT_NOPREFIX);
SetTextColor (hdc, OldFg);
SetBkColor (hdc, OldBg);
SelectObject(hdc, oldFont);
EndPaint(hWnd, &ps);
} break;
case WM_DESTROY:
free(data);
SetWindowLong(hWnd, GWL_USERDATA, (LONG)0);
break;
case WM_SETFOCUS:
SetFocus(GetNHApp()->hMainWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
RegisterClass(&wcex);
}
void mswin_status_window_size (HWND hWnd, LPSIZE sz)
LRESULT CALLBACK
StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
data = (PNHStatusWindow) GetWindowLong(hWnd, GWL_USERDATA);
switch (message) {
case WM_MSNH_COMMAND: {
switch (wParam) {
case MSNH_MSG_PUTSTR:
case MSNH_MSG_CLEAR_WINDOW:
ZeroMemory(data->window_text, sizeof(data->window_text));
FormatStatusString(data->window_text, data->nhstat_format);
break;
case MSNH_MSG_CURSOR: {
PMSNHMsgCursor msg_data = (PMSNHMsgCursor) lParam;
if (msg_data->y == 0) {
InvalidateRect(hWnd, NULL, TRUE);
}
} break;
}
} break;
case WM_PAINT: {
HGDIOBJ oldFont;
TCHAR wbuf[MAXWINDOWTEXT];
COLORREF OldBg, OldFg;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
oldFont = SelectObject(
hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
OldBg = SetBkColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_BG));
OldFg =
SetTextColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_FG));
DrawText(hdc, NH_A2W(data->window_text, wbuf, MAXWINDOWTEXT),
strlen(data->window_text), &rt, DT_LEFT | DT_NOPREFIX);
SetTextColor(hdc, OldFg);
SetBkColor(hdc, OldBg);
SelectObject(hdc, oldFont);
EndPaint(hWnd, &ps);
} break;
case WM_DESTROY:
free(data);
SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0);
break;
case WM_SETFOCUS:
SetFocus(GetNHApp()->hMainWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void
mswin_status_window_size(HWND hWnd, LPSIZE sz)
{
TEXTMETRIC tm;
HGDIOBJ saveFont;
HDC hdc;
PNHStatusWindow data;
RECT rt;
GetWindowRect(hWnd, &rt);
sz->cx = rt.right - rt.left;
sz->cy = rt.bottom - rt.top;
HGDIOBJ saveFont;
HDC hdc;
PNHStatusWindow data;
RECT rt;
GetWindowRect(hWnd, &rt);
sz->cx = rt.right - rt.left;
sz->cy = rt.bottom - rt.top;
data = (PNHStatusWindow)GetWindowLong(hWnd, GWL_USERDATA);
if(data) {
hdc = GetDC(hWnd);
saveFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
GetTextMetrics(hdc, &tm);
data = (PNHStatusWindow) GetWindowLong(hWnd, GWL_USERDATA);
if (data) {
hdc = GetDC(hWnd);
saveFont = SelectObject(
hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
GetTextMetrics(hdc, &tm);
/* see if the status window can fit 80 characters per line */
if( (80*tm.tmMaxCharWidth)>=sz->cx ) data->nhstat_format = NHSTAT_LINES_4;
else data->nhstat_format = NHSTAT_LINES_2;
/* see if the status window can fit 80 characters per line */
if ((80 * tm.tmMaxCharWidth) >= sz->cx)
data->nhstat_format = NHSTAT_LINES_4;
else
data->nhstat_format = NHSTAT_LINES_2;
/* set height of the status box */
sz->cy = tm.tmHeight * data->nhstat_format;
/* set height of the status box */
sz->cy = tm.tmHeight * data->nhstat_format;
SelectObject(hdc, saveFont);
ReleaseDC(hWnd, hdc);
}
SelectObject(hdc, saveFont);
ReleaseDC(hWnd, hdc);
}
}
extern const char *hu_stat[]; /* defined in eat.c */
extern const char *hu_stat[]; /* defined in eat.c */
extern const char *enc_stat[]; /* define in botl.c */
void FormatStatusString(char* text, int format)
void
FormatStatusString(char *text, int format)
{
register char *nb;
int hp, hpmax;
int cap = near_capacity();
register char *nb;
int hp, hpmax;
int cap = near_capacity();
Strcpy(text, plname);
if('a' <= text[0] && text[0] <= 'z') text[0] += 'A'-'a';
text[10] = 0;
Sprintf(nb = eos(text)," the ");
Strcpy(text, plname);
if ('a' <= text[0] && text[0] <= 'z')
text[0] += 'A' - 'a';
text[10] = 0;
Sprintf(nb = eos(text), " the ");
if (Upolyd) {
char mbot[BUFSZ];
int k = 0;
if (Upolyd) {
char mbot[BUFSZ];
int k = 0;
Strcpy(mbot, mons[u.umonnum].mname);
while(mbot[k] != 0) {
if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) &&
'a' <= mbot[k] && mbot[k] <= 'z')
mbot[k] += 'A' - 'a';
k++;
}
Sprintf(nb = eos(nb), mbot);
} else
Sprintf(nb = eos(nb), rank_of(u.ulevel, Role_switch, flags.female));
Strcpy(mbot, mons[u.umonnum].mname);
while (mbot[k] != 0) {
if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
&& mbot[k] <= 'z')
mbot[k] += 'A' - 'a';
k++;
}
Sprintf(nb = eos(nb), mbot);
} else
Sprintf(nb = eos(nb), rank_of(u.ulevel, Role_switch, flags.female));
if( format==NHSTAT_LINES_4 ) Sprintf(nb = eos(nb),"\r\n");
if (format == NHSTAT_LINES_4)
Sprintf(nb = eos(nb), "\r\n");
if (ACURR(A_STR) > 18) {
if (ACURR(A_STR) > STR18(100))
Sprintf(nb = eos(nb),"St:%2d ",ACURR(A_STR)-100);
else if (ACURR(A_STR) < STR18(100))
Sprintf(nb = eos(nb), "St:18/%02d ",ACURR(A_STR)-18);
else
Sprintf(nb = eos(nb),"St:18/** ");
} else
Sprintf(nb = eos(nb), "St:%-1d ",ACURR(A_STR));
Sprintf(nb = eos(nb),
"Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), ACURR(A_CHA));
Sprintf(nb = eos(nb), (u.ualign.type == A_CHAOTIC) ? " Chaotic" :
(u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful");
if (ACURR(A_STR) > 18) {
if (ACURR(A_STR) > STR18(100))
Sprintf(nb = eos(nb), "St:%2d ", ACURR(A_STR) - 100);
else if (ACURR(A_STR) < STR18(100))
Sprintf(nb = eos(nb), "St:18/%02d ", ACURR(A_STR) - 18);
else
Sprintf(nb = eos(nb), "St:18/** ");
} else
Sprintf(nb = eos(nb), "St:%-1d ", ACURR(A_STR));
Sprintf(nb = eos(nb), "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS),
ACURR(A_CHA));
Sprintf(nb = eos(nb),
(u.ualign.type == A_CHAOTIC)
? " Chaotic"
: (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful");
#ifdef SCORE_ON_BOTL
if (flags.showscore)
Sprintf(nb = eos(nb), " S:%ld", botl_score());
if (flags.showscore)
Sprintf(nb = eos(nb), " S:%ld", botl_score());
#endif
if( format==NHSTAT_LINES_4 ||
format==NHSTAT_LINES_2 ) strcat(text, "\r\n");
if (format == NHSTAT_LINES_4 || format == NHSTAT_LINES_2)
strcat(text, "\r\n");
/* third line */
hp = Upolyd ? u.mh : u.uhp;
hpmax = Upolyd ? u.mhmax : u.uhpmax;
/* third line */
hp = Upolyd ? u.mh : u.uhp;
hpmax = Upolyd ? u.mhmax : u.uhpmax;
if(hp < 0) hp = 0;
(void) describe_level(nb=eos(nb));
Sprintf(nb = eos(nb),
"%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", showsyms[COIN_CLASS + SYM_OFF_O],
money_cnt(invent),
hp, hpmax, u.uen, u.uenmax, u.uac);
if (hp < 0)
hp = 0;
(void) describe_level(nb = eos(nb));
Sprintf(nb = eos(nb), "%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d",
showsyms[COIN_CLASS + SYM_OFF_O], money_cnt(invent), hp, hpmax,
u.uen, u.uenmax, u.uac);
if (Upolyd)
Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
else if(flags.showexp)
Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel,u.uexp);
else
Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
if( format==NHSTAT_LINES_4 ) strcat(text, "\r\n");
else strcat(text, " ");
if (Upolyd)
Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
else if (flags.showexp)
Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel, u.uexp);
else
Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
if (format == NHSTAT_LINES_4)
strcat(text, "\r\n");
else
strcat(text, " ");
/* forth line */
if(flags.time)
Sprintf(nb = eos(nb), "T:%ld ", moves);
/* forth line */
if (flags.time)
Sprintf(nb = eos(nb), "T:%ld ", moves);
if(strcmp(hu_stat[u.uhs], " ")) {
Strcat(text, hu_stat[u.uhs]);
Sprintf(nb = eos(nb), " ");
}
if(Confusion) Sprintf(nb = eos(nb), "Conf");
if(Sick) {
if (u.usick_type & SICK_VOMITABLE)
Sprintf(nb = eos(nb), " FoodPois");
if (u.usick_type & SICK_NONVOMITABLE)
Sprintf(nb = eos(nb), " Ill");
}
if(Blind) Sprintf(nb = eos(nb), " Blind");
if(Stunned) Sprintf(nb = eos(nb), " Stun");
if(Hallucination) Sprintf(nb = eos(nb), " Hallu");
if(Slimed) Sprintf(nb = eos(nb), " Slime");
if(cap > UNENCUMBERED)
Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
if (strcmp(hu_stat[u.uhs], " ")) {
Strcat(text, hu_stat[u.uhs]);
Sprintf(nb = eos(nb), " ");
}
if (Confusion)
Sprintf(nb = eos(nb), "Conf");
if (Sick) {
if (u.usick_type & SICK_VOMITABLE)
Sprintf(nb = eos(nb), " FoodPois");
if (u.usick_type & SICK_NONVOMITABLE)
Sprintf(nb = eos(nb), " Ill");
}
if (Blind)
Sprintf(nb = eos(nb), " Blind");
if (Stunned)
Sprintf(nb = eos(nb), " Stun");
if (Hallucination)
Sprintf(nb = eos(nb), " Hallu");
if (Slimed)
Sprintf(nb = eos(nb), " Slime");
if (cap > UNENCUMBERED)
Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
}
+239 -235
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhtext.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhtext.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.21 $ */
/* NetHack 3.6 mhtext.c $Date: 2009/10/22 02:59:34 $ $Revision: 1.8 $ */
/* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -11,292 +11,296 @@
#include "mhtxtbuf.h"
typedef struct mswin_nethack_text_window {
PNHTextBuffer window_text;
int done;
PNHTextBuffer window_text;
int done;
} NHTextWindow, *PNHTextWindow;
static WNDPROC editControlWndProc = NULL;
LRESULT CALLBACK TextWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK NHTextControlWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK TextWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK NHTextControlWndProc(HWND, UINT, WPARAM, LPARAM);
static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
static void LayoutText(HWND hwnd);
static void ToggleWrapStatus(HWND hDlg, BOOL bWrap);
HWND mswin_init_text_window () {
HWND ret;
PNHTextWindow data;
HWND
mswin_init_text_window()
{
HWND ret;
PNHTextWindow data;
ret = CreateDialog(
GetNHApp()->hApp,
MAKEINTRESOURCE(IDD_NHTEXT),
GetNHApp()->hMainWnd,
TextWndProc
);
if( !ret ) panic("Cannot create text window");
ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_NHTEXT),
GetNHApp()->hMainWnd, TextWndProc);
if (!ret)
panic("Cannot create text window");
data = (PNHTextWindow)malloc(sizeof(NHTextWindow));
if( !data ) panic("out of memory");
data = (PNHTextWindow) malloc(sizeof(NHTextWindow));
if (!data)
panic("out of memory");
ZeroMemory(data, sizeof(NHTextWindow));
data->window_text = mswin_init_text_buffer(
program_state.gameover? FALSE : GetNHApp()->bWrapText
);
SetWindowLong(ret, GWL_USERDATA, (LONG)data);
return ret;
ZeroMemory(data, sizeof(NHTextWindow));
data->window_text = mswin_init_text_buffer(
program_state.gameover ? FALSE : GetNHApp()->bWrapText);
SetWindowLong(ret, GWL_USERDATA, (LONG) data);
return ret;
}
void mswin_display_text_window (HWND hWnd)
void
mswin_display_text_window(HWND hWnd)
{
PNHTextWindow data;
data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA);
if( data ) {
ToggleWrapStatus(hWnd, mswin_get_text_wrap(data->window_text));
data->done = 0;
mswin_popup_display(hWnd, &data->done);
mswin_popup_destroy(hWnd);
}
}
LRESULT CALLBACK TextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND control;
HDC hdc;
PNHTextWindow data;
data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA);
switch (message)
{
case WM_INITDIALOG:
/* set text control font */
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
if( !control ) {
panic("cannot get text view window");
}
PNHTextWindow data;
hdc = GetDC(control);
SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
ReleaseDC(control, hdc);
data = (PNHTextWindow) GetWindowLong(hWnd, GWL_USERDATA);
if (data) {
ToggleWrapStatus(hWnd, mswin_get_text_wrap(data->window_text));
data->done = 0;
mswin_popup_display(hWnd, &data->done);
mswin_popup_destroy(hWnd);
}
}
LRESULT CALLBACK
TextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND control;
HDC hdc;
PNHTextWindow data;
data = (PNHTextWindow) GetWindowLong(hWnd, GWL_USERDATA);
switch (message) {
case WM_INITDIALOG:
/* set text control font */
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
if (!control) {
panic("cannot get text view window");
}
hdc = GetDC(control);
SendMessage(control, WM_SETFONT,
(WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
0);
ReleaseDC(control, hdc);
#if defined(WIN_CE_SMARTPHONE)
/* special initialization for SmartPhone dialogs */
NHSPhoneDialogSetup(hWnd, IDC_SPHONE_TEXTDIALOGBAR, FALSE, GetNHApp()->bFullScreen);
/* special initialization for SmartPhone dialogs */
NHSPhoneDialogSetup(hWnd, IDC_SPHONE_TEXTDIALOGBAR, FALSE,
GetNHApp()->bFullScreen);
#endif
/* subclass edit control */
editControlWndProc = (WNDPROC)GetWindowLong(control, GWL_WNDPROC);
SetWindowLong(control, GWL_WNDPROC, (LONG)NHTextControlWndProc);
/* subclass edit control */
editControlWndProc = (WNDPROC) GetWindowLong(control, GWL_WNDPROC);
SetWindowLong(control, GWL_WNDPROC, (LONG) NHTextControlWndProc);
SetFocus(control);
return FALSE;
SetFocus(control);
return FALSE;
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
case WM_SIZE:
LayoutText(hWnd);
return FALSE;
case WM_SIZE:
LayoutText(hWnd);
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
data->done = 1;
return TRUE;
case IDC_TEXT_TOGGLE_WRAP:
ToggleWrapStatus(hWnd, !mswin_get_text_wrap(data->window_text));
return TRUE;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
data->done = 1;
return TRUE;
case IDC_TEXT_TOGGLE_WRAP:
ToggleWrapStatus(hWnd, !mswin_get_text_wrap(data->window_text));
return TRUE;
}
break;
case WM_CTLCOLORBTN:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */
HDC hdcEdit = (HDC) wParam;
HWND hwndEdit = (HWND) lParam;
if( hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL) ) {
SetBkColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_BG));
SetTextColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_FG));
return (BOOL)mswin_get_brush(NHW_TEXT, MSWIN_COLOR_BG);
}
} return FALSE;
case WM_CTLCOLORBTN:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */
HDC hdcEdit = (HDC) wParam;
HWND hwndEdit = (HWND) lParam;
if (hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL)) {
SetBkColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_BG));
SetTextColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_FG));
return (BOOL) mswin_get_brush(NHW_TEXT, MSWIN_COLOR_BG);
}
}
return FALSE;
case WM_DESTROY:
if( data ) {
mswin_free_text_buffer(data->window_text);
free(data);
SetWindowLong(hWnd, GWL_USERDATA, (LONG)0);
}
break;
}
return FALSE;
case WM_DESTROY:
if (data) {
mswin_free_text_buffer(data->window_text);
free(data);
SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0);
}
break;
}
return FALSE;
}
void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
void
onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PNHTextWindow data;
data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA);
switch( wParam ) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
mswin_add_text(data->window_text, msg_data->attr, msg_data->text);
break;
}
}
PNHTextWindow data;
data = (PNHTextWindow) GetWindowLong(hWnd, GWL_USERDATA);
switch (wParam) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam;
mswin_add_text(data->window_text, msg_data->attr, msg_data->text);
break;
}
}
}
void ToggleWrapStatus(HWND hDlg, BOOL bWrap)
void
ToggleWrapStatus(HWND hDlg, BOOL bWrap)
{
DWORD styles;
PNHTextWindow data;
HWND control;
TCHAR wbuf[BUFSZ];
data = (PNHTextWindow)GetWindowLong(hDlg, GWL_USERDATA);
DWORD styles;
PNHTextWindow data;
HWND control;
TCHAR wbuf[BUFSZ];
control = GetDlgItem(hDlg, IDC_TEXT_CONTROL);
if( !control ) {
panic("cannot get text view window");
}
data = (PNHTextWindow) GetWindowLong(hDlg, GWL_USERDATA);
/* set horizontal scrollbar status */
styles = GetWindowLong(control, GWL_STYLE);
if( styles ) {
SetWindowLong(control, GWL_STYLE, (bWrap? (styles & (~WS_HSCROLL)) : (styles | WS_HSCROLL)));
SetWindowPos(control, NULL, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE );
}
control = GetDlgItem(hDlg, IDC_TEXT_CONTROL);
if (!control) {
panic("cannot get text view window");
}
/* set text wrap mode */
mswin_set_text_wrap(data->window_text, bWrap);
mswin_render_text(data->window_text, control);
/* set horizontal scrollbar status */
styles = GetWindowLong(control, GWL_STYLE);
if (styles) {
SetWindowLong(control, GWL_STYLE, (bWrap ? (styles & (~WS_HSCROLL))
: (styles | WS_HSCROLL)));
SetWindowPos(control, NULL, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE
| SWP_NOSIZE);
}
/* change button status */
ZeroMemory( wbuf, sizeof(wbuf) );
if( !LoadString(
GetNHApp()->hApp,
(bWrap? IDS_TEXT_UNWRAP : IDS_TEXT_WRAP),
wbuf,
BUFSZ) ) {
panic("cannot load text window strings");
}
/* set text wrap mode */
mswin_set_text_wrap(data->window_text, bWrap);
mswin_render_text(data->window_text, control);
/* change button status */
ZeroMemory(wbuf, sizeof(wbuf));
if (!LoadString(GetNHApp()->hApp,
(bWrap ? IDS_TEXT_UNWRAP : IDS_TEXT_WRAP), wbuf, BUFSZ)) {
panic("cannot load text window strings");
}
#if defined(WIN_CE_SMARTPHONE)
{
TBBUTTONINFO tbbi;
{
TBBUTTONINFO tbbi;
ZeroMemory( &tbbi, sizeof(tbbi) );
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_TEXT;
tbbi.pszText = wbuf;
if( !SendMessage(
SHFindMenuBar(hDlg),
TB_SETBUTTONINFO,
IDC_TEXT_TOGGLE_WRAP,
(LPARAM)&tbbi) ) {
error( "Cannot update IDC_TEXT_TOGGLE_WRAP menu item." );
}
}
ZeroMemory(&tbbi, sizeof(tbbi));
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_TEXT;
tbbi.pszText = wbuf;
if (!SendMessage(SHFindMenuBar(hDlg), TB_SETBUTTONINFO,
IDC_TEXT_TOGGLE_WRAP, (LPARAM) &tbbi)) {
error("Cannot update IDC_TEXT_TOGGLE_WRAP menu item.");
}
}
#else
SendDlgItemMessage(
hDlg,
IDC_TEXT_TOGGLE_WRAP,
WM_SETTEXT,
(WPARAM)0,
(LPARAM)wbuf
);
SendDlgItemMessage(hDlg, IDC_TEXT_TOGGLE_WRAP, WM_SETTEXT, (WPARAM) 0,
(LPARAM) wbuf);
#endif
}
void LayoutText(HWND hWnd)
void
LayoutText(HWND hWnd)
{
HWND btn_ok, btn_wrap;
HWND text;
RECT clrt, rt;
POINT pt_elem, pt_ok, pt_wrap;
SIZE sz_elem, sz_ok, sz_wrap;
HWND btn_ok, btn_wrap;
HWND text;
RECT clrt, rt;
POINT pt_elem, pt_ok, pt_wrap;
SIZE sz_elem, sz_ok, sz_wrap;
text = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
btn_ok = GetDlgItem(hWnd, IDOK);
btn_wrap = GetDlgItem(hWnd, IDC_TEXT_TOGGLE_WRAP);
text = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
btn_ok = GetDlgItem(hWnd, IDOK);
btn_wrap = GetDlgItem(hWnd, IDC_TEXT_TOGGLE_WRAP);
/* get window coordinates */
GetClientRect(hWnd, &clrt );
/* set window placements */
if( IsWindow(btn_ok) ) {
GetWindowRect(btn_ok, &rt);
sz_ok.cx = (clrt.right - clrt.left)/2;
sz_ok.cy = rt.bottom-rt.top;
pt_ok.x = clrt.left;
pt_ok.y = clrt.bottom - sz_ok.cy;
MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE );
/* get window coordinates */
GetClientRect(hWnd, &clrt);
sz_wrap.cx = (clrt.right - clrt.left)/2;
sz_wrap.cy = rt.bottom-rt.top;
pt_wrap.x = clrt.left + sz_ok.cx;
pt_wrap.y = clrt.bottom - sz_ok.cy;
MoveWindow(btn_wrap, pt_wrap.x, pt_wrap.y, sz_wrap.cx, sz_wrap.cy, TRUE );
/* set window placements */
if (IsWindow(btn_ok)) {
GetWindowRect(btn_ok, &rt);
sz_ok.cx = (clrt.right - clrt.left) / 2;
sz_ok.cy = rt.bottom - rt.top;
pt_ok.x = clrt.left;
pt_ok.y = clrt.bottom - sz_ok.cy;
MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE);
pt_elem.x = clrt.left;
pt_elem.y = clrt.top;
sz_elem.cx = clrt.right - clrt.left;
sz_elem.cy = pt_ok.y;
MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE );
} else {
pt_elem.x = clrt.left;
pt_elem.y = clrt.top;
sz_elem.cx = clrt.right - clrt.left;
sz_elem.cy = clrt.bottom - clrt.top;
MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE );
}
sz_wrap.cx = (clrt.right - clrt.left) / 2;
sz_wrap.cy = rt.bottom - rt.top;
pt_wrap.x = clrt.left + sz_ok.cx;
pt_wrap.y = clrt.bottom - sz_ok.cy;
MoveWindow(btn_wrap, pt_wrap.x, pt_wrap.y, sz_wrap.cx, sz_wrap.cy,
TRUE);
pt_elem.x = clrt.left;
pt_elem.y = clrt.top;
sz_elem.cx = clrt.right - clrt.left;
sz_elem.cy = pt_ok.y;
MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE);
} else {
pt_elem.x = clrt.left;
pt_elem.y = clrt.top;
sz_elem.cx = clrt.right - clrt.left;
sz_elem.cy = clrt.bottom - clrt.top;
MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE);
}
}
/* Text control window proc - implements close on space and scrolling on arrows */
LRESULT CALLBACK NHTextControlWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
/* Text control window proc - implements close on space and scrolling on
* arrows */
LRESULT CALLBACK
NHTextControlWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
/* tell Windows not to process arrow keys (we want them) */
case WM_GETDLGCODE:
return DLGC_WANTARROWS;
switch (message) {
/* tell Windows not to process arrow keys (we want them) */
case WM_GETDLGCODE:
return DLGC_WANTARROWS;
case WM_KEYDOWN:
switch( wParam ) {
case VK_SPACE:
case VK_RETURN:
/* close on space */
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0);
return 0;
case VK_UP:
/* scoll up */
PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM)NULL);
return 0;
case WM_KEYDOWN:
switch (wParam) {
case VK_SPACE:
case VK_RETURN:
/* close on space */
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0);
return 0;
case VK_DOWN:
/* scoll down */
PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM)NULL);
return 0;
case VK_UP:
/* scoll up */
PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0),
(LPARAM) NULL);
return 0;
case VK_LEFT:
/* scoll left */
PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINELEFT, 0), (LPARAM)NULL);
return 0;
case VK_DOWN:
/* scoll down */
PostMessage(hWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0),
(LPARAM) NULL);
return 0;
case VK_RIGHT:
/* scoll right */
PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINERIGHT, 0), (LPARAM)NULL);
return 0;
}
break; /* case WM_KEYDOWN: */
}
case VK_LEFT:
/* scoll left */
PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINELEFT, 0),
(LPARAM) NULL);
return 0;
if( editControlWndProc )
return CallWindowProc(editControlWndProc, hWnd, message, wParam, lParam);
else
return 0;
case VK_RIGHT:
/* scoll right */
PostMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_LINERIGHT, 0),
(LPARAM) NULL);
return 0;
}
break; /* case WM_KEYDOWN: */
}
if (editControlWndProc)
return CallWindowProc(editControlWndProc, hWnd, message, wParam,
lParam);
else
return 0;
}
+208 -190
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhtxtbuf.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhtxtbuf.c $NHDT-Date: 1431192788 2015/05/09 17:33:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
/* NetHack 3.6 mhtxtbuf.c $Date: 2009/10/13 01:55:12 $ $Revision: 1.6 $ */
/* Copyright (C) 2003 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -10,7 +10,7 @@
Recognize formatted lines as having more that 4 consecutive.
spaces inside the string.
Strip leading and trailing spaces.
Always break at the original line end (do not merge text that comes
Always break at the original line end (do not merge text that comes
from NetHack engine)
*/
@@ -18,235 +18,253 @@
#define NHTEXT_BUFFER_INCREMENT 10
/*----------------------------------------------------------------*/
struct text_buffer_line {
int attr;
short beg_padding;
short end_padding;
BOOL formatted;
char* text;
int attr;
short beg_padding;
short end_padding;
BOOL formatted;
char *text;
};
/*----------------------------------------------------------------*/
typedef struct mswin_nethack_text_buffer {
BOOL b_wrap_text;
int n_size;
int n_used;
struct text_buffer_line *text_buffer_line;
BOOL b_wrap_text;
int n_size;
int n_used;
struct text_buffer_line *text_buffer_line;
} NHTextBuffer, *PNHTextBuffer;
/*----------------------------------------------------------------*/
#define NHTextLine(pb,i) ((pb)->text_buffer_line[(i)])
static TCHAR* nh_append( TCHAR* s, int* size, const char* ap );
#define NHTextLine(pb, i) ((pb)->text_buffer_line[(i)])
static TCHAR *nh_append(TCHAR *s, int *size, const char *ap);
/*----------------------------------------------------------------*/
PNHTextBuffer mswin_init_text_buffer(BOOL wrap_text)
PNHTextBuffer
mswin_init_text_buffer(BOOL wrap_text)
{
PNHTextBuffer pb = (PNHTextBuffer)malloc(sizeof(NHTextBuffer));
if( !pb ) panic("Out of memory");
ZeroMemory(pb, sizeof(NHTextBuffer));
pb->b_wrap_text = wrap_text;
pb->n_size = 0;
pb->n_used = 0;
pb->text_buffer_line = NULL;
return pb;
PNHTextBuffer pb = (PNHTextBuffer) malloc(sizeof(NHTextBuffer));
if (!pb)
panic("Out of memory");
ZeroMemory(pb, sizeof(NHTextBuffer));
pb->b_wrap_text = wrap_text;
pb->n_size = 0;
pb->n_used = 0;
pb->text_buffer_line = NULL;
return pb;
}
/*----------------------------------------------------------------*/
void mswin_free_text_buffer(PNHTextBuffer pb)
void
mswin_free_text_buffer(PNHTextBuffer pb)
{
int i;
if( !pb ) return;
int i;
for(i=0; i<pb->n_used; i++ ) {
free(pb->text_buffer_line[i].text);
}
free( pb->text_buffer_line );
free( pb );
if (!pb)
return;
for (i = 0; i < pb->n_used; i++) {
free(pb->text_buffer_line[i].text);
}
free(pb->text_buffer_line);
free(pb);
}
/*----------------------------------------------------------------*/
void mswin_add_text(PNHTextBuffer pb, int attr, const char* text)
void
mswin_add_text(PNHTextBuffer pb, int attr, const char *text)
{
char* p;
struct text_buffer_line* new_line;
char *p;
struct text_buffer_line *new_line;
/* grow buffer */
if( pb->n_used >= pb->n_size ) {
pb->n_size += NHTEXT_BUFFER_INCREMENT;
pb->text_buffer_line =
(struct text_buffer_line*)realloc( pb->text_buffer_line, pb->n_size*sizeof(struct text_buffer_line) );
if( !pb->text_buffer_line ) panic("Memory allocation error");
}
/* grow buffer */
if (pb->n_used >= pb->n_size) {
pb->n_size += NHTEXT_BUFFER_INCREMENT;
pb->text_buffer_line = (struct text_buffer_line *) realloc(
pb->text_buffer_line,
pb->n_size * sizeof(struct text_buffer_line));
if (!pb->text_buffer_line)
panic("Memory allocation error");
}
/* analyze the new line of text */
new_line = &NHTextLine(pb, pb->n_used);
new_line->attr = attr;
new_line->beg_padding = 0;
new_line->text = strdup(text);
for( p = new_line->text; *p && isspace(*p); p++ ) {
new_line->beg_padding++;
}
if( *p ) {
memmove(new_line->text,
new_line->text + new_line->beg_padding,
strlen(new_line->text) - new_line->beg_padding + 1
);
for( p = new_line->text+strlen(new_line->text);
p>=new_line->text && isspace(*p);
p-- ) {
new_line->end_padding++;
*p = 0;
}
/* analyze the new line of text */
new_line = &NHTextLine(pb, pb->n_used);
new_line->attr = attr;
new_line->beg_padding = 0;
new_line->text = strdup(text);
for (p = new_line->text; *p && isspace(*p); p++) {
new_line->beg_padding++;
}
if (*p) {
memmove(new_line->text, new_line->text + new_line->beg_padding,
strlen(new_line->text) - new_line->beg_padding + 1);
for (p = new_line->text + strlen(new_line->text);
p >= new_line->text && isspace(*p); p--) {
new_line->end_padding++;
*p = 0;
}
/* if there are 3 (or more) consecutive spaces inside the string
consider it formatted */
new_line->formatted =
(strstr(new_line->text, " ")!=NULL)
|| (new_line->beg_padding>8);
} else {
new_line->end_padding = 0;
new_line->text[0] = 0;
new_line->formatted = FALSE;
}
pb->n_used++;
/* if there are 3 (or more) consecutive spaces inside the string
consider it formatted */
new_line->formatted = (strstr(new_line->text, " ") != NULL)
|| (new_line->beg_padding > 8);
} else {
new_line->end_padding = 0;
new_line->text[0] = 0;
new_line->formatted = FALSE;
}
pb->n_used++;
}
/*----------------------------------------------------------------*/
void mswin_set_text_wrap(PNHTextBuffer pb, BOOL wrap_text)
void
mswin_set_text_wrap(PNHTextBuffer pb, BOOL wrap_text)
{
pb->b_wrap_text = wrap_text;
pb->b_wrap_text = wrap_text;
}
/*----------------------------------------------------------------*/
BOOL mswin_get_text_wrap(PNHTextBuffer pb)
BOOL
mswin_get_text_wrap(PNHTextBuffer pb)
{
return pb->b_wrap_text;
return pb->b_wrap_text;
}
/*----------------------------------------------------------------*/
static TCHAR* nh_append( TCHAR* s, int* size, const char* ap )
static TCHAR *
nh_append(TCHAR *s, int *size, const char *ap)
{
int tlen, tnewlen;
int tlen, tnewlen;
if( !(ap && *ap) ) return s;
if (!(ap && *ap))
return s;
/* append the calculated line to the text buffer */
tlen = s? _tcslen(s) : 0;
tnewlen = tlen+strlen(ap);
if( tnewlen>=*size ) {
*size = max(tnewlen, *size + BUFSZ);
s = (TCHAR*)realloc(s, *size * sizeof(TCHAR));
if( !s ) panic("Out of memory");
ZeroMemory(s+tlen, (*size-tlen)*sizeof(TCHAR));
}
if( strcmp(ap, "\r\n")==0 ) {
_tcscat(s, TEXT("\r\n"));
} else {
NH_A2W(ap, s+tlen, strlen(ap));
s[tnewlen] = 0;
}
return s;
/* append the calculated line to the text buffer */
tlen = s ? _tcslen(s) : 0;
tnewlen = tlen + strlen(ap);
if (tnewlen >= *size) {
*size = max(tnewlen, *size + BUFSZ);
s = (TCHAR *) realloc(s, *size * sizeof(TCHAR));
if (!s)
panic("Out of memory");
ZeroMemory(s + tlen, (*size - tlen) * sizeof(TCHAR));
}
if (strcmp(ap, "\r\n") == 0) {
_tcscat(s, TEXT("\r\n"));
} else {
NH_A2W(ap, s + tlen, strlen(ap));
s[tnewlen] = 0;
}
return s;
}
/*----------------------------------------------------------------*/
void mswin_render_text(PNHTextBuffer pb, HWND edit_control)
void
mswin_render_text(PNHTextBuffer pb, HWND edit_control)
{
RECT rt_client; /* boundaries of the client area of the edit control */
SIZE size_text; /* size of the edit control */
RECT rt_text; /* calculated text rectangle for the visible line */
char buf[BUFSZ]; /* buffer for the visible line */
TCHAR tbuf[BUFSZ]; /* temp buffer for DrawText */
TCHAR* pText = NULL; /* resulting text (formatted) */
int pTextSize = 0; /* resulting text size */
char* p_cur = NULL; /* current position in the NHTextBuffer->text_buffer_line->text */
char* p_buf_cur = NULL; /* current position in the visible line buffer */
int i;
HDC hdcEdit; /* device context for the edit control */
HFONT hFont, hOldFont; /* edit control font */
RECT rt_client; /* boundaries of the client area of the edit control */
SIZE size_text; /* size of the edit control */
RECT rt_text; /* calculated text rectangle for the visible line */
char buf[BUFSZ]; /* buffer for the visible line */
TCHAR tbuf[BUFSZ]; /* temp buffer for DrawText */
TCHAR *pText = NULL; /* resulting text (formatted) */
int pTextSize = 0; /* resulting text size */
char *p_cur = NULL; /* current position in the
NHTextBuffer->text_buffer_line->text */
char *p_buf_cur = NULL; /* current position in the visible line buffer */
int i;
HDC hdcEdit; /* device context for the edit control */
HFONT hFont, hOldFont; /* edit control font */
GetClientRect(edit_control, &rt_client );
size_text.cx = rt_client.right - rt_client.left;
size_text.cy = rt_client.bottom - rt_client.top;
size_text.cx -= GetSystemMetrics(SM_CXVSCROLL); /* add a slight right margin - the text looks better that way */
hdcEdit = GetDC(edit_control);
hFont = (HFONT)SendMessage(edit_control, WM_GETFONT, 0, 0);
if( hFont ) hOldFont = SelectObject(hdcEdit, hFont);
GetClientRect(edit_control, &rt_client);
size_text.cx = rt_client.right - rt_client.left;
size_text.cy = rt_client.bottom - rt_client.top;
size_text.cx -=
GetSystemMetrics(SM_CXVSCROLL); /* add a slight right margin - the
text looks better that way */
hdcEdit = GetDC(edit_control);
hFont = (HFONT) SendMessage(edit_control, WM_GETFONT, 0, 0);
if (hFont)
hOldFont = SelectObject(hdcEdit, hFont);
/* loop through each line (outer loop) and wrap it around (inner loop) */
ZeroMemory(buf, sizeof(buf));
p_buf_cur = buf;
for( i=0; i<pb->n_used; i++ ) {
if( pb->b_wrap_text ) {
p_cur = NHTextLine(pb,i).text;
/* loop through each line (outer loop) and wrap it around (inner loop) */
ZeroMemory(buf, sizeof(buf));
p_buf_cur = buf;
for (i = 0; i < pb->n_used; i++) {
if (pb->b_wrap_text) {
p_cur = NHTextLine(pb, i).text;
/* insert an line break for the empty string */
if( !NHTextLine(pb,i).text[0] ) {
pText = nh_append(pText, &pTextSize, "\r\n");
continue;
}
/* insert an line break for the empty string */
if (!NHTextLine(pb, i).text[0]) {
pText = nh_append(pText, &pTextSize, "\r\n");
continue;
}
/* add margin to the "formatted" line of text */
if( NHTextLine(pb,i).formatted ) {
strcpy(buf, " ");
p_buf_cur += 3;
}
/* add margin to the "formatted" line of text */
if (NHTextLine(pb, i).formatted) {
strcpy(buf, " ");
p_buf_cur += 3;
}
/* scroll thourgh the current line of text and wrap it
so it fits to width of the edit control */
while( *p_cur ) {
char *p_word_pos = p_buf_cur;
/* scroll thourgh the current line of text and wrap it
so it fits to width of the edit control */
while (*p_cur) {
char *p_word_pos = p_buf_cur;
/* copy one word into the buffer */
while( *p_cur && isspace(*p_cur) )
if( p_buf_cur!=buf ) *p_buf_cur++ = *p_cur++;
else p_cur++;
/* copy one word into the buffer */
while (*p_cur && isspace(*p_cur))
if (p_buf_cur != buf)
*p_buf_cur++ = *p_cur++;
else
p_cur++;
while( *p_cur && !isspace(*p_cur) )
*p_buf_cur++ = *p_cur++;
while (*p_cur && !isspace(*p_cur))
*p_buf_cur++ = *p_cur++;
/* check if it fits */
SetRect( &rt_text, 0, 0, size_text.cx, size_text.cy );
DrawText(hdcEdit, NH_A2W(buf, tbuf, p_buf_cur-buf), p_buf_cur-buf, &rt_text, DT_CALCRECT | DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
if( (rt_text.right - rt_text.left)>=size_text.cx ) {
/* Backtrack.
Only backtrack if the last word caused the overflow -
do not backtrack if the entire current line does not fit the visible area.
Otherwise it is a infinite loop.
*/
if( p_word_pos>buf ) {
p_cur -= (p_buf_cur-p_word_pos);
p_buf_cur = p_word_pos;
}
*p_buf_cur = 0; /* break the line */
/* check if it fits */
SetRect(&rt_text, 0, 0, size_text.cx, size_text.cy);
DrawText(hdcEdit, NH_A2W(buf, tbuf, p_buf_cur - buf),
p_buf_cur - buf, &rt_text,
DT_CALCRECT | DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
if ((rt_text.right - rt_text.left) >= size_text.cx) {
/* Backtrack.
Only backtrack if the last word caused the overflow -
do not backtrack if the entire current line does not
fit the visible area.
Otherwise it is a infinite loop.
*/
if (p_word_pos > buf) {
p_cur -= (p_buf_cur - p_word_pos);
p_buf_cur = p_word_pos;
}
*p_buf_cur = 0; /* break the line */
/* append the calculated line to the text buffer */
pText = nh_append(pText, &pTextSize, buf);
pText = nh_append(pText, &pTextSize, "\r\n");
ZeroMemory(buf, sizeof(buf));
p_buf_cur = buf;
}
}
/* append the calculated line to the text buffer */
pText = nh_append(pText, &pTextSize, buf);
pText = nh_append(pText, &pTextSize, "\r\n");
ZeroMemory(buf, sizeof(buf));
p_buf_cur = buf;
}
}
/* always break the line at the end of the buffer text */
if( p_buf_cur != buf ) {
/* flush the current buffrer */
*p_buf_cur = 0; /* break the line */
pText = nh_append(pText, &pTextSize, buf);
pText = nh_append(pText, &pTextSize, "\r\n");
ZeroMemory(buf, sizeof(buf));
p_buf_cur = buf;
}
} else { /* do not wrap text */
int j;
for( j=0; j<NHTextLine(pb,i).beg_padding; j++ )
pText = nh_append(pText, &pTextSize, " ");
pText = nh_append(pText, &pTextSize, NHTextLine(pb,i).text);
pText = nh_append(pText, &pTextSize, "\r\n");
}
}
/* cleanup */
if( hFont ) SelectObject(hdcEdit, hOldFont);
ReleaseDC(edit_control, hdcEdit);
/* always break the line at the end of the buffer text */
if (p_buf_cur != buf) {
/* flush the current buffrer */
*p_buf_cur = 0; /* break the line */
pText = nh_append(pText, &pTextSize, buf);
pText = nh_append(pText, &pTextSize, "\r\n");
ZeroMemory(buf, sizeof(buf));
p_buf_cur = buf;
}
} else { /* do not wrap text */
int j;
for (j = 0; j < NHTextLine(pb, i).beg_padding; j++)
pText = nh_append(pText, &pTextSize, " ");
pText = nh_append(pText, &pTextSize, NHTextLine(pb, i).text);
pText = nh_append(pText, &pTextSize, "\r\n");
}
}
/* update edit control text */
if( pText ) {
SendMessage(edit_control, EM_FMTLINES, 1, 0 );
SetWindowText(edit_control, pText);
free(pText);
}
/* cleanup */
if (hFont)
SelectObject(hdcEdit, hOldFont);
ReleaseDC(edit_control, hdcEdit);
/* update edit control text */
if (pText) {
SendMessage(edit_control, EM_FMTLINES, 1, 0);
SetWindowText(edit_control, pText);
free(pText);
}
}
/*----------------------------------------------------------------*/
+1312 -1311
View File
File diff suppressed because it is too large Load Diff
+242 -243
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 winhack.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 winhack.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */
/* NetHack 3.6 winhack.c $Date: 2009/10/22 02:59:35 $ $Revision: 1.11 $ */
/* Copyright (C) 2001 by Alex Kompel */
// winhack.cpp : Defines the entry point for the application.
@@ -10,125 +10,128 @@
#include "mhmain.h"
#include "mhmap.h"
extern char orgdir[PATHLEN]; /* also used in pcsys.c, amidos.c */
extern char orgdir[PATHLEN]; /* also used in pcsys.c, amidos.c */
extern void FDECL(nethack_exit,(int));
static TCHAR* _get_cmd_arg(TCHAR* pCmdLine);
extern void FDECL(nethack_exit, (int));
static TCHAR *_get_cmd_arg(TCHAR *pCmdLine);
// Global Variables:
NHWinApp _nethack_app;
// Foward declarations of functions included in this code module:
BOOL InitInstance(HINSTANCE, int);
BOOL InitInstance(HINSTANCE, int);
static void win_hack_init(int, char **);
static void __cdecl mswin_moveloop(void *);
static BOOL setMapTiles(const char* fname);
static BOOL setMapTiles(const char *fname);
extern boolean FDECL(pcmain, (int,char **));
extern boolean FDECL(pcmain, (int, char **));
#define MAX_CMDLINE_PARAM 255
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow)
int APIENTRY
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine,
int nCmdShow)
{
INITCOMMONCONTROLSEX InitCtrls;
HWND nethackWnd;
int argc;
char* argv[MAX_CMDLINE_PARAM];
size_t len;
TCHAR* p;
TCHAR wbuf[NHSTR_BUFSIZE];
char buf[NHSTR_BUFSIZE];
INITCOMMONCONTROLSEX InitCtrls;
HWND nethackWnd;
int argc;
char *argv[MAX_CMDLINE_PARAM];
size_t len;
TCHAR *p;
TCHAR wbuf[NHSTR_BUFSIZE];
char buf[NHSTR_BUFSIZE];
boolean resuming;
sys_early_init();
sys_early_init();
/* ensure that we don't access violate on a panic() */
windowprocs.win_raw_print = mswin_raw_print;
windowprocs.win_raw_print_bold = mswin_raw_print_bold;
/* ensure that we don't access violate on a panic() */
windowprocs.win_raw_print = mswin_raw_print;
windowprocs.win_raw_print_bold = mswin_raw_print_bold;
/* init applicatio structure */
_nethack_app.hApp = hInstance;
_nethack_app.nCmdShow = nCmdShow;
_nethack_app.hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WINHACK);
_nethack_app.hMainWnd = NULL;
_nethack_app.hPopupWnd = NULL;
_nethack_app.hMenuBar = NULL;
_nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES));
if( _nethack_app.bmpTiles==NULL ) panic("cannot load tiles bitmap");
_nethack_app.bmpPetMark = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK));
if( _nethack_app.bmpPetMark==NULL ) panic("cannot load pet mark bitmap");
_nethack_app.bmpMapTiles = _nethack_app.bmpTiles;
_nethack_app.mapTile_X = TILE_X;
_nethack_app.mapTile_Y = TILE_Y;
_nethack_app.mapTilesPerLine = TILES_PER_LINE;
_nethack_app.bNoHScroll = FALSE;
_nethack_app.bNoVScroll = FALSE;
/* init applicatio structure */
_nethack_app.hApp = hInstance;
_nethack_app.nCmdShow = nCmdShow;
_nethack_app.hAccelTable =
LoadAccelerators(hInstance, (LPCTSTR) IDC_WINHACK);
_nethack_app.hMainWnd = NULL;
_nethack_app.hPopupWnd = NULL;
_nethack_app.hMenuBar = NULL;
_nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES));
if (_nethack_app.bmpTiles == NULL)
panic("cannot load tiles bitmap");
_nethack_app.bmpPetMark =
LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK));
if (_nethack_app.bmpPetMark == NULL)
panic("cannot load pet mark bitmap");
_nethack_app.bmpMapTiles = _nethack_app.bmpTiles;
_nethack_app.mapTile_X = TILE_X;
_nethack_app.mapTile_Y = TILE_Y;
_nethack_app.mapTilesPerLine = TILES_PER_LINE;
_nethack_app.bNoHScroll = FALSE;
_nethack_app.bNoVScroll = FALSE;
_nethack_app.bCmdPad = !mswin_has_keyboard();
_nethack_app.bCmdPad = !mswin_has_keyboard();
_nethack_app.bWrapText = TRUE;
_nethack_app.bFullScreen = TRUE;
_nethack_app.bWrapText = TRUE;
_nethack_app.bFullScreen = TRUE;
#if defined(WIN_CE_SMARTPHONE)
_nethack_app.bHideScrollBars = TRUE;
_nethack_app.bHideScrollBars = TRUE;
#else
_nethack_app.bHideScrollBars = FALSE;
_nethack_app.bHideScrollBars = FALSE;
#endif
_nethack_app.bUseSIP = TRUE;
_nethack_app.bUseSIP = TRUE;
// check for running nethack programs
nethackWnd = FindWindow(szMainWindowClass, NULL);
if( nethackWnd ) {
// bring on top
SetForegroundWindow(nethackWnd);
return FALSE;
}
// check for running nethack programs
nethackWnd = FindWindow(szMainWindowClass, NULL);
if (nethackWnd) {
// bring on top
SetForegroundWindow(nethackWnd);
return FALSE;
}
// init controls
ZeroMemory(&InitCtrls, sizeof(InitCtrls));
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES;
if( !InitCommonControlsEx(&InitCtrls) ) {
MessageBox(NULL, TEXT("Cannot init common controls"), TEXT("ERROR"), MB_OK | MB_ICONSTOP);
return FALSE;
}
// init controls
ZeroMemory(&InitCtrls, sizeof(InitCtrls));
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES;
if (!InitCommonControlsEx(&InitCtrls)) {
MessageBox(NULL, TEXT("Cannot init common controls"), TEXT("ERROR"),
MB_OK | MB_ICONSTOP);
return FALSE;
}
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow)) {
return FALSE;
}
/* get command line parameters */
p = _get_cmd_arg(
/* get command line parameters */
p = _get_cmd_arg(
#if defined(WIN_CE_PS2xx) || defined(WIN32_PLATFORM_HPCPRO)
lpCmdLine
lpCmdLine
#else
GetCommandLine()
GetCommandLine()
#endif
);
for( argc = 1; p && argc<MAX_CMDLINE_PARAM; argc++ ) {
len = _tcslen(p);
if( len>0 ) {
argv[argc] = _strdup( NH_W2A(p, buf, BUFSZ) );
} else {
argv[argc] = "";
}
p = _get_cmd_arg(NULL);
}
GetModuleFileName(NULL, wbuf, BUFSZ);
argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ));
);
for (argc = 1; p && argc < MAX_CMDLINE_PARAM; argc++) {
len = _tcslen(p);
if (len > 0) {
argv[argc] = _strdup(NH_W2A(p, buf, BUFSZ));
} else {
argv[argc] = "";
}
p = _get_cmd_arg(NULL);
}
GetModuleFileName(NULL, wbuf, BUFSZ);
argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ));
resuming = pcmain(argc,argv);
resuming = pcmain(argc, argv);
moveloop(resuming);
moveloop(resuming);
return 0;
return 0;
}
//
@@ -138,218 +141,214 @@ int APIENTRY WinMain(HINSTANCE hInstance,
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// In this function, we save the instance handle in a global variable
// and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
BOOL
InitInstance(HINSTANCE hInstance, int nCmdShow)
{
return TRUE;
return TRUE;
}
PNHWinApp GetNHApp()
PNHWinApp
GetNHApp()
{
return &_nethack_app;
return &_nethack_app;
}
static int
eraseoldlocks()
{
register int i;
register int i;
/* cannot use maxledgerno() here, because we need to find a lock name
* before starting everything (including the dungeon initialization
* that sets astral_level, needed for maxledgerno()) up
*/
for(i = 1; i <= MAXDUNGEON*MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(lock, i);
(void) unlink(fqname(lock, LEVELPREFIX, 0));
}
set_levelfile_name(lock, 0);
if(unlink(fqname(lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return(1); /* success! */
/* cannot use maxledgerno() here, because we need to find a lock name
* before starting everything (including the dungeon initialization
* that sets astral_level, needed for maxledgerno()) up
*/
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(lock, i);
(void) unlink(fqname(lock, LEVELPREFIX, 0));
}
set_levelfile_name(lock, 0);
if (unlink(fqname(lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return (1); /* success! */
}
void
getlock()
{
const char *fq_lock;
char tbuf[BUFSZ];
TCHAR wbuf[BUFSZ];
HANDLE f;
int fd;
int choice;
const char *fq_lock;
char tbuf[BUFSZ];
TCHAR wbuf[BUFSZ];
HANDLE f;
int fd;
int choice;
/* regularize(lock); */ /* already done in pcmain */
Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0));
set_levelfile_name(lock, 0);
fq_lock = fqname(lock, LEVELPREFIX, 1);
/* regularize(lock); */ /* already done in pcmain */
Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0));
set_levelfile_name(lock, 0);
fq_lock = fqname(lock, LEVELPREFIX, 1);
f = CreateFile(
NH_A2W(fq_lock, wbuf, BUFSZ),
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if( f==INVALID_HANDLE_VALUE ) {
if(GetLastError()==ERROR_FILE_NOT_FOUND) goto gotlock; /* no such file */
error("Cannot open %s", fq_lock);
}
f = CreateFile(NH_A2W(fq_lock, wbuf, BUFSZ), GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (f == INVALID_HANDLE_VALUE) {
if (GetLastError() == ERROR_FILE_NOT_FOUND)
goto gotlock; /* no such file */
error("Cannot open %s", fq_lock);
}
CloseHandle(f);
CloseHandle(f);
/* prompt user that the game alredy exist */
choice = MessageBox(
GetNHApp()->hMainWnd,
TEXT("There are files from a game in progress under your name. Recover?"),
TEXT("Nethack"),
MB_YESNO | MB_DEFBUTTON1
);
switch(choice) {
case IDYES:
if(recover_savefile()) {
goto gotlock;
} else {
error("Couldn't recover old game.");
}
break;
/* prompt user that the game alredy exist */
choice = MessageBox(GetNHApp()->hMainWnd,
TEXT("There are files from a game in progress under "
"your name. Recover?"),
TEXT("Nethack"), MB_YESNO | MB_DEFBUTTON1);
switch (choice) {
case IDYES:
if (recover_savefile()) {
goto gotlock;
} else {
error("Couldn't recover old game.");
}
break;
case IDNO:
unlock_file(HLOCK);
error("%s", "Cannot start a new game.");
break;
};
case IDNO:
unlock_file(HLOCK);
error("%s", "Cannot start a new game.");
break;
};
gotlock:
fd = creat(fq_lock, FCMASK);
if(fd == -1) {
error("cannot creat lock file (%s.)", fq_lock);
} else {
if(write(fd, (char *) &hackpid, sizeof(hackpid))
!= sizeof(hackpid)){
error("cannot write lock (%s)", fq_lock);
}
if(close(fd) == -1) {
error("cannot close lock (%s)", fq_lock);
}
}
fd = creat(fq_lock, FCMASK);
if (fd == -1) {
error("cannot creat lock file (%s.)", fq_lock);
} else {
if (write(fd, (char *) &hackpid, sizeof(hackpid))
!= sizeof(hackpid)) {
error("cannot write lock (%s)", fq_lock);
}
if (close(fd) == -1) {
error("cannot close lock (%s)", fq_lock);
}
}
}
/* misc functions */
void
error VA_DECL(const char *,s)
TCHAR wbuf[1024];
char buf[1024];
DWORD last_error = GetLastError();
void error
VA_DECL(const char *, s)
TCHAR wbuf[1024];
char buf[1024];
DWORD last_error = GetLastError();
VA_START(s);
VA_INIT(s, const char *);
/* error() may get called before tty is initialized */
if (iflags.window_inited) end_screen();
vsprintf(buf, s, VA_ARGS);
NH_A2W(buf, wbuf, sizeof(wbuf)/sizeof(wbuf[0]));
if( last_error>0 ) {
LPVOID lpMsgBuf;
if( FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
last_error,
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
)
)
{
_tcsncat(wbuf, TEXT("\nSystem Error: "), sizeof(wbuf)/sizeof(wbuf[0]) - _tcslen(wbuf) );
_tcsncat(wbuf, lpMsgBuf, sizeof(wbuf)/sizeof(wbuf[0]) - _tcslen(wbuf) );
VA_START(s);
VA_INIT(s, const char *);
/* error() may get called before tty is initialized */
if (iflags.window_inited)
end_screen();
// Free the buffer.
LocalFree( lpMsgBuf );
}
}
VA_END();
vsprintf(buf, s, VA_ARGS);
NH_A2W(buf, wbuf, sizeof(wbuf) / sizeof(wbuf[0]));
if (last_error > 0) {
LPVOID lpMsgBuf;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, last_error,
0, // Default language
(LPTSTR) &lpMsgBuf, 0, NULL)) {
_tcsncat(wbuf, TEXT("\nSystem Error: "),
sizeof(wbuf) / sizeof(wbuf[0]) - _tcslen(wbuf));
_tcsncat(wbuf, lpMsgBuf,
sizeof(wbuf) / sizeof(wbuf[0]) - _tcslen(wbuf));
MessageBox( NULL, wbuf, TEXT("Error"), MB_OK | MB_ICONERROR );
exit(EXIT_FAILURE);
// Free the buffer.
LocalFree(lpMsgBuf);
}
}
VA_END();
MessageBox(NULL, wbuf, TEXT("Error"), MB_OK | MB_ICONERROR);
exit(EXIT_FAILURE);
}
TCHAR* _get_cmd_arg(TCHAR* pCmdLine)
TCHAR *
_get_cmd_arg(TCHAR *pCmdLine)
{
static TCHAR* pArgs = NULL;
TCHAR *pRetArg;
BOOL bQuoted;
static TCHAR *pArgs = NULL;
TCHAR *pRetArg;
BOOL bQuoted;
if( !pCmdLine && !pArgs ) return NULL;
if( !pArgs ) pArgs = pCmdLine;
if (!pCmdLine && !pArgs)
return NULL;
if (!pArgs)
pArgs = pCmdLine;
/* skip whitespace */
for(pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); pRetArg = CharNext(pRetArg));
if( !*pRetArg ) {
pArgs = NULL;
return NULL;
}
for (pRetArg = pArgs; *pRetArg && _istspace(*pRetArg);
pRetArg = CharNext(pRetArg))
;
if (!*pRetArg) {
pArgs = NULL;
return NULL;
}
/* check for quote */
if( *pRetArg==TEXT('"') ) {
bQuoted = TRUE;
pRetArg = CharNext(pRetArg);
pArgs = _tcschr(pRetArg, TEXT('"'));
} else {
/* skip to whitespace */
for(pArgs = pRetArg; *pArgs && !_istspace(*pArgs); pArgs = CharNext(pArgs));
}
if( pArgs && *pArgs ) {
TCHAR* p;
p = pArgs;
pArgs = CharNext(pArgs);
*p = (TCHAR)0;
} else {
pArgs = NULL;
}
if (*pRetArg == TEXT('"')) {
bQuoted = TRUE;
pRetArg = CharNext(pRetArg);
pArgs = _tcschr(pRetArg, TEXT('"'));
} else {
/* skip to whitespace */
for (pArgs = pRetArg; *pArgs && !_istspace(*pArgs);
pArgs = CharNext(pArgs))
;
}
return pRetArg;
if (pArgs && *pArgs) {
TCHAR *p;
p = pArgs;
pArgs = CharNext(pArgs);
*p = (TCHAR) 0;
} else {
pArgs = NULL;
}
return pRetArg;
}
/*
/*
* Strip out troublesome file system characters.
*/
void
nt_regularize(s) /* normalize file name */
void nt_regularize(s) /* normalize file name */
register char *s;
{
register unsigned char *lp;
register unsigned char *lp;
for (lp = s; *lp; lp++)
if ( *lp == '?' || *lp == '"' || *lp == '\\' ||
*lp == '/' || *lp == '>' || *lp == '<' ||
*lp == '*' || *lp == '|' || *lp == ':' || (*lp > 127))
*lp = '_';
for (lp = s; *lp; lp++)
if (*lp == '?' || *lp == '"' || *lp == '\\' || *lp == '/'
|| *lp == '>' || *lp == '<' || *lp == '*' || *lp == '|'
|| *lp == ':' || (*lp > 127))
*lp = '_';
}
void win32_abort()
void
win32_abort()
{
if (wizard)
DebugBreak();
abort();
if (wizard)
DebugBreak();
abort();
}
void
append_port_id(buf)
char *buf;
{
char *portstr = PORT_CE_PLATFORM " " PORT_CE_CPU;
Sprintf(eos(buf), " %s", portstr);
char *portstr = PORT_CE_PLATFORM " " PORT_CE_CPU;
Sprintf(eos(buf), " %s", portstr);
}
+81 -74
View File
@@ -1,6 +1,6 @@
// winmain.cpp : Defines the entry point for the application.
//
// $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$
// $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $
// $Date: 2002/12/18 03:51:34 $ $Revision: 1.2 $
#include "winMS.h"
@@ -8,106 +8,113 @@
#define MAX_CMDLINE_PARAM 255
extern int FDECL (main, (int,char **));
static TCHAR* _get_cmd_arg(TCHAR* pCmdLine);
extern int FDECL(main, (int, char **));
static TCHAR *_get_cmd_arg(TCHAR *pCmdLine);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow)
int APIENTRY
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine,
int nCmdShow)
{
int argc;
char* argv[MAX_CMDLINE_PARAM];
size_t len;
TCHAR* p;
TCHAR wbuf[NHSTR_BUFSIZE];
char buf[NHSTR_BUFSIZE];
int argc;
char *argv[MAX_CMDLINE_PARAM];
size_t len;
TCHAR *p;
TCHAR wbuf[NHSTR_BUFSIZE];
char buf[NHSTR_BUFSIZE];
/* get command line parameters */
p = _get_cmd_arg(
/* get command line parameters */
p = _get_cmd_arg(
#if defined(WIN_CE_PS2xx) || defined(WIN32_PLATFORM_HPCPRO)
lpCmdLine
lpCmdLine
#else
GetCommandLine()
GetCommandLine()
#endif
);
for( argc = 1; p && argc<MAX_CMDLINE_PARAM; argc++ ) {
len = _tcslen(p);
if( len>0 ) {
argv[argc] = _strdup( NH_W2A(p, buf, BUFSZ) );
} else {
argv[argc] = "";
}
p = _get_cmd_arg(NULL);
}
GetModuleFileName(NULL, wbuf, BUFSZ);
argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ));
);
for (argc = 1; p && argc < MAX_CMDLINE_PARAM; argc++) {
len = _tcslen(p);
if (len > 0) {
argv[argc] = _strdup(NH_W2A(p, buf, BUFSZ));
} else {
argv[argc] = "";
}
p = _get_cmd_arg(NULL);
}
GetModuleFileName(NULL, wbuf, BUFSZ);
argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ));
main(argc, argv);
main(argc, argv);
return 0;
return 0;
}
TCHAR* _get_cmd_arg(TCHAR* pCmdLine)
TCHAR *
_get_cmd_arg(TCHAR *pCmdLine)
{
static TCHAR* pArgs = NULL;
TCHAR *pRetArg;
BOOL bQuoted;
static TCHAR *pArgs = NULL;
TCHAR *pRetArg;
BOOL bQuoted;
if( !pCmdLine && !pArgs ) return NULL;
if( !pArgs ) pArgs = pCmdLine;
if (!pCmdLine && !pArgs)
return NULL;
if (!pArgs)
pArgs = pCmdLine;
/* skip whitespace */
for(pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); pRetArg = CharNext(pRetArg));
if( !*pRetArg ) {
pArgs = NULL;
return NULL;
}
for (pRetArg = pArgs; *pRetArg && _istspace(*pRetArg);
pRetArg = CharNext(pRetArg))
;
if (!*pRetArg) {
pArgs = NULL;
return NULL;
}
/* check for quote */
if( *pRetArg==TEXT('"') ) {
if (*pRetArg == TEXT('"')) {
bQuoted = TRUE;
pRetArg = CharNext(pRetArg);
pArgs = _tcschr(pRetArg, TEXT('"'));
} else {
/* skip to whitespace */
for(pArgs = pRetArg; *pArgs && !_istspace(*pArgs); pArgs = CharNext(pArgs));
}
if( pArgs && *pArgs ) {
TCHAR* p;
p = pArgs;
pArgs = CharNext(pArgs);
*p = (TCHAR)0;
} else {
pArgs = NULL;
}
pArgs = _tcschr(pRetArg, TEXT('"'));
} else {
/* skip to whitespace */
for (pArgs = pRetArg; *pArgs && !_istspace(*pArgs);
pArgs = CharNext(pArgs))
;
}
return pRetArg;
if (pArgs && *pArgs) {
TCHAR *p;
p = pArgs;
pArgs = CharNext(pArgs);
*p = (TCHAR) 0;
} else {
pArgs = NULL;
}
return pRetArg;
}
#ifndef STRNCMPI
char
lowc(c) /* force 'c' into lowercase */
char c;
char lowc(c) /* force 'c' into lowercase */
char c;
{
return((char)(('A' <= c && c <= 'Z') ? (c | 040) : c));
return ((char) (('A' <= c && c <= 'Z') ? (c | 040) : c));
}
int
strncmpi(s1, s2, n) /* case insensitive counted string comparison */
register const char *s1, *s2;
register int n; /*(should probably be size_t, which is usually unsigned)*/
{ /*{ aka strncasecmp }*/
int strncmpi(s1, s2, n) /* case insensitive counted string comparison */
register const char *s1, *s2;
register int n; /*(should probably be size_t, which is usually unsigned)*/
{ /*{ aka strncasecmp }*/
register char t1, t2;
while (n--) {
if (!*s2) return (*s1 != 0); /* s1 >= s2 */
else if (!*s1) return -1; /* s1 < s2 */
t1 = lowc(*s1++);
t2 = lowc(*s2++);
if (t1 != t2) return (t1 > t2) ? 1 : -1;
if (!*s2)
return (*s1 != 0); /* s1 >= s2 */
else if (!*s1)
return -1; /* s1 < s2 */
t1 = lowc(*s1++);
t2 = lowc(*s2++);
if (t1 != t2)
return (t1 > t2) ? 1 : -1;
}
return 0; /* s1 == s2 */
return 0; /* s1 == s2 */
}
#endif /* STRNCMPI */
#endif /* STRNCMPI */