-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgtext.c
187 lines (164 loc) · 5.17 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: handle/display (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! */
char banner_printed = FALSE;
#if USERESOURCES
/*
If Win32 resource strings are to be used, the
makefiles must contain a call of the resource compiler!
Resource file is H/JWasm.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
static const char usage[] = {
#include "usage.h"
};
/* 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[] = { "JWasm v" _JWASM_VERSION_ };
#endif
void MsgInit( void )
/******************/
{
}
void MsgFini( void )
/******************/
{
#if 0 /* set to 1 to display all error texts and numbers */
int i;
for ( i = 0; i < MSG_LAST; i++ ) {
printf("%3u: %s\n", i, msgtexts[i] );
}
#endif
}
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 );
}
char *MsgGetEx( int msgid )
/*************************/
{
return( MsgGet( msgid, NULL ) );
}
void MsgPrintUsage( void )
/************************/
{
const char *p;
write_logo();
for ( p = usage; *p != '\n'; ) {
const char *p2 = p + strlen( p ) + 1;
printf("%-20s %s\n", p, p2 );
p = p2 + strlen( p2 ) + 1;
}
}
char *MsgGetJWasmName( char *buffer )
/***********************************/
{
sprintf( buffer, MsgGetEx( MSG_JWASM ), _JWASM_VERSION_, __DATE__ );
return( buffer );
}
int write_logo( void )
/********************/
{
char buffer[128];
if( banner_printed == FALSE ) {
banner_printed = TRUE;
printf( MsgGetEx( MSG_BANNER ), MsgGetJWasmName( buffer ) );
return( 4 ); /* return number of lines printed */
}
return( 0 );
}