forked from Terraspace/UASM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgtext.c
114 lines (98 loc) · 3.02 KB
/
msgtext.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/****************************************************************************
*
* This code is Public Domain.
*
* ========================================================================
*
* Description: handle (error) message texts
*
****************************************************************************/
#include "globals.h"
#include "token.h"
#include "tokenize.h"
#include "msgtext.h"
#define USERESOURCES 0 /* 1=use Win string resources, won't work for Linux! */
#if USERESOURCES
/*
If Win32 resource strings are to be used, the
makefiles must contain a call of the resource compiler!
Resource file is H/Uasm.rc.
*/
#include "win32.h"
typedef void *HRSRC;
typedef void *HGLOBAL;
WINBASEAPI HRSRC WINAPI FindResource( void *, char *, uint_32 );
WINBASEAPI HGLOBAL WINAPI LoadResource( void *, HRSRC );
WINBASEAPI void * WINAPI LockResource( HGLOBAL );
WINBASEAPI void WINAPI WideCharToMultiByte( uint_32, uint_32, uint_16 *, uint_32, uint_16 *, uint_32, uint_32, uint_32 );
#else
#ifdef __I86__
#include <i86.h>
#define FPTR( x ) MK_FP( FP_SEG( TX_MSG_USAGE ), x )
#undef pick
#define pick( code, string ) const char __based( __segname("_CODE") ) TX_ ## code[] = string;
#include "msgdef.h"
#undef pick
#define pick( code, string ) TX_ ## code,
static const char __based ( __segname("_CODE") ) * const msgtexts[] = {
#include "msgdef.h"
};
#else
#define FPTR( x ) x
#undef pick
#define pick( code, string ) string,
static const char * const msgtexts[] = {
#include "msgdef.h"
};
#endif
#endif
/* the compiler string stored in CodeView symbolic debugging info */
#ifdef DEBUG_OUT
const char szCVCompiler[] = { "Microsoft (R) Macro Assembler Version 6.15.8803" };
//const char szCVCompiler[] = { "Microsoft (R) Macro Assembler Version 8.00.50727" };
#else
const char szCVCompiler[] = { "Uasm v" _UASM_VERSION_STR_ };
#endif
static const char *MsgGet( int msgid, char *buffer )
/**************************************************/
{
#if USERESOURCES
HRSRC hRsrc;
HGLOBAL hRes;
WORD * pId;
int i;
hRsrc = FindResource( NULL, MAKEINTRESOURCE(1 + (msgid >> 4)), RT_STRING );
if (hRsrc) {
hRes = LoadResource( NULL, hRsrc );
if (hRes) {
pId = LockResource( hRes );
for (i = msgid % 16;i;i--)
pId += *pId + 1;
i = *pId++;
if ( buffer == NULL )
buffer = StringBufferEnd;
WideCharToMultiByte( CP_ACP, 0, pId, i, buffer, -1, 0, 0 );
buffer[i] = NULLC;
return( buffer );
}
}
#else
if ( msgid < MSG_LAST ) {
if ( buffer ) {
strcpy( buffer, FPTR( msgtexts[msgid] ) );
return( buffer );
} else
return( (char *) FPTR( msgtexts[msgid] ) );
}
#endif
DebugMsg(("MsgGet(%u): Msg not found!!!\n", msgid));
if ( buffer == NULL )
buffer = StringBufferEnd;
sprintf( buffer, "Msg %u", msgid );
return( buffer );
}
const char *MsgGetEx( int msgid )
/*******************************/
{
return( MsgGet( msgid, NULL ) );
}