-
Notifications
You must be signed in to change notification settings - Fork 0
/
Support.c
318 lines (262 loc) · 10.4 KB
/
Support.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/****************************************************************************
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / INCLUDES / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
\ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
****************************************************************************/
#include "Public.h"
#include "Support.h"
/****************************************************************************
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / \ \ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / USEFUL FUNCTIONS / / / / / / / / / / / / / / / / / / / / / / / / / /
\ \ \ \ \ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
****************************************************************************/
void ShortenString( STRPTR str, int amount )
{
int ctr;
if ( amount > strlen(str) )
return;
for ( ctr = 0; ctr < strlen(str); ctr ++ )
str[ctr] = str[amount + ctr];
}
/***************************************************************************/
void DelLeadingSpaces( STRPTR tmpstr )
{
int ctrb, ctr = 0;
while ((tmpstr[ctr] == ' ') || (tmpstr[ctr] == '\t'))
for (ctrb=ctr; ctrb < strlen(tmpstr); ctrb++)
tmpstr[ctrb] = tmpstr[ctrb+1];
}
/****************************************************************************
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / \ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / RANDOM NUMBERS / / / / / / / / / / / / / / / / / / / / / / / / / / /
\ \ \ \ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
****************************************************************************/
void SeedPRNG( void )
{
srand( time(NULL)^rand() );
}
/***************************************************************************/
ULONG PRNG( ULONG base, BYTE PRNG_type )
{
ULONG randnum, modifier;
switch ( PRNG_type ) {
case RAND_BASIC:
randnum = rand() % base;
break;
case RAND_MODIFIER:
randnum = rand() % base;
modifier = rand() % (base % 10);
if ( rand() & 1L )
modifier *= -1;
randnum += modifier;
break;
case RAND_MD5:
load_seed();
randnum = md5_rnd(0, base);
save_seed();
break;
};
return (randnum);
}
/****************************************************************************
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / DO-ERRORS / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
\ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
****************************************************************************/
BOOL DoErrors( BOOL errortype, STRPTR error, STRPTR solution_orig, STRPTR buttons )
{
char text[255];
char solution_copy[255];
BOOL return_val = TRUE;
int ctr, ctrb;
struct ReqToolsBase *ReqToolsBase; // Base pointer for REQTools library
// copy solution so we don't trash original string
strcpy(solution_copy, solution_orig);
if ( errortype == WARNING )
strcpy( text, "WARNING: " );
else
strcpy( text, "FATAL: " );
// add error info. onto text buffer
strcat( text, error );
// prepare solution lines
strcat( text, "\n\n--- " );
// build up solution lines
do {
if ( solution_copy[0] == '|' )
strcat( text, "\n " );
else
strncat( text, solution_copy, 1 );
// shorten string
for ( ctrb = 0; ctrb < strlen(solution_copy); ctrb ++ )
solution_copy[ctrb] = solution_copy[1 + ctrb];
} while ( solution_copy[0] != '\0' );
if ( ReqToolsBase = (struct ReqToolsBase *) OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION) ) {
struct TagItem tags[] = {
RTEZ_ReqTitle, (ULONG) NAME,
TAG_END };
ULONG what;
what = rtEZRequest( text,
buttons,
NULL,
(struct TagItem *)tags,
NULL );
switch ( what ) {
// the default OR/ leftmost button
case 1:
return_val = TRUE;
break;
// the rightmost button when more than one button
// should be QUIT by convention
case 0:
return_val = FALSE;
break;
}
CloseLibrary ((struct Library *)ReqToolsBase);
} else
puts("text");
return( return_val );
}
/****************************************************************************
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / \ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / DISPLAY ABOUT / / / / / / / / / / / / / / / / / / / / / / / / / / / /
\ \ \ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
****************************************************************************/
void About( void )
{
char info[511];
char byte_txt[16];
// prepare info block
strcpy( info, NAME );
strcat( info, " ");
strcat( info, VERSION );
strcat( info, "\n" );
strcat( info, COPYRIGHT );
strcat( info, " ");
strcat( info, AUTHOR );
strcat( info, "\n" );
strcat( info, ABOUT_TEXT );
if ( _norexx == FALSE ) {
strcat( info, "\n-----\nARexx Port: " );
strcat( info, PORT_NAME );
}
/* the condition is included simply for future versions of Epigrams
where it may be possible to open up the about requester without
an epigram window being open */
if ( interface == TRUE ) {
strcat( info, "\n-----\nData File Used - " );
strcat( info, FilePart(file_used) );
strcat( info, "\n Byte Pos - " );
sprintf( byte_txt, "%ld", byte_pos );
strcat( info, byte_txt );
}
strcat( info, "\n-----\nPRNG method - " );
switch( _random_mode ) {
case RAND_BASIC:
strcat( info, "Basic" );
break;
case RAND_MODIFIER:
strcat( info, "Basic + Modifier" );
break;
case RAND_MD5:
strcat( info, "MD5 Hashing" );
strcat( info, "\n-----\nPRNG code -- ©1997 Rich Skrenta\nMD5 -- ©1993 Ron Rivest");
break;
default:
strcat( info, "Unknown" );
}
if ( (ReqToolsBase = (struct ReqToolsBase *) OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION)) ) {
// dont foget to alter embedded string and screen title
rtEZRequestTags ( info,
"A Marvellous Program",
NULL,
NULL,
RTEZ_ReqTitle, (ULONG) "About " NAME,
RTEZ_Flags, EZREQF_CENTERTEXT,
RT_Window, EpigramsWnd,
RT_LockWindow, TRUE,
TAG_END );
CloseLibrary ((struct Library *)ReqToolsBase);
}
}
/*
void About( void )
{
struct Window * AboutWnd = NULL;
struct IntuiMessage *IMsg;
ULONG MsgClass, MsgID, MsgType;
BOOL waiting_for_close = TRUE;
// SET UP SCREEN
if ( ! SetupScreen )
return; // ---- SILENTLY
// OPEN WINDOW
AboutWnd = OpenWindowTags ( NULL,
// WINDOW DIMENSIONS
WA_Left, 0,
WA_Top, 11,
WA_Width, 200,
WA_Height, 200,
WA_MinWidth, 200,
WA_MinHeight, 200,
WA_MaxWidth, 200,
WA_MaxHeight, 200,
// WINDOW FLAGS
WA_SmartRefresh, TRUE,
WA_Activate, TRUE,
WA_RMBTrap, TRUE,
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_DepthGadget, TRUE,
// OTHER PROPERTIES
WA_Title, "About Epigrams",
WA_ScreenTitle, title_bar,
WA_PubScreen, Scr,
WA_IDCMP, IDCMP_MOUSEBUTTONS |
IDCMP_REFRESHWINDOW |
IDCMP_ACTIVEWINDOW |
IDCMP_INACTIVEWINDOW|
IDCMP_CLOSEWINDOW,
TAG_DONE );
// DUMP SCREEN LOCK NOW -- WE DON'T NEED IT
if ( Scr ) {
UnlockPubScreen( NULL, Scr );
Scr = NULL;
}
// PUT IMAGE IN WINDOW
DrawImage( AboutWnd->RPort, &Logo, 10, 15 );
// DO IDCMP CHECKING
while ( waiting_for_close ) {
while ( IMsg = GT_GetIMsg( AboutWnd->UserPort ) ) {
MsgClass = IMsg->Class;
GT_ReplyIMsg( IMsg );
switch( MsgClass ) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( AboutWnd );
GT_EndRefresh( AboutWnd, TRUE );
break;
case IDCMP_ACTIVEWINDOW:
break;
case IDCMP_INACTIVEWINDOW:
break;
case IDCMP_CLOSEWINDOW:
waiting_for_close = FALSE;
break;
default:
break;
}
}
}
CloseWindow( AboutWnd );
AboutWnd = NULL;
}
*/
/***************************************************************************/