-
Notifications
You must be signed in to change notification settings - Fork 0
/
lmenu.c
371 lines (299 loc) · 7.95 KB
/
lmenu.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/* Copyright 1995-2000 Just For Fun Software, Inc. */
/* Author: George Woltman */
/* Email: [email protected] */
/* Adapted for LLR program by Jean Penné */
/* Email : [email protected] */
/* Include files */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#if !defined (__linux__) && !defined (__FreeBSD__) && !defined (__APPLE__)
#include <io.h>
#else
#include <dirent.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#endif
#include "lprime.h"
/* Routine definitions */
void options_cpu ();
/* Get line from the user (stdin) */
void get_line (
char *buf)
{
char c;
int i;
for (i = 0; ; i++) {
if (_read (0, &c, 1) != 1) break;
if (c == '\n' || c == 0) break;
if (i < 260) *buf++ = c;
}
*buf++ = 0;
}
/* Get a number from the user */
unsigned long get_number (
unsigned long dflt)
{
char line[80];
get_line (line);
if (line[0] == 0) return (dflt);
return (atol (line));
}
/* Ask a Yes/No question */
void askYN (
char *str,
int *val)
{
char buf[80];
printf ("%s (%s): ", str, *val ? "Y" : "N");
get_line (buf);
if (buf[0] == 0) return;
*val = (buf[0] == 'Y' || buf[0] == 'y');
}
/* Ask a number question */
void askNum (
char *str,
unsigned long *val,
unsigned long min,
unsigned long max)
{
char buf[80];
unsigned long newval;
printf ("%s (%ld): ", str, *val);
loop: get_line (buf);
if (buf[0] == 0) return;
newval = atol (buf);
if (min || max) {
if (newval < min || newval > max) {
printf ("Please enter a value between %ld and %ld. ",
min, max);
goto loop;
}
}
*val = newval;
}
/* Ask a number question */
void askNumNoDflt (
char *str,
unsigned long *val,
unsigned long min,
unsigned long max)
{
char buf[80];
unsigned long newval;
printf ("%s: ", str);
loop: get_line (buf);
if (buf[0] == 0) goto loop;
newval = atol (buf);
if (min || max) {
if (newval < min || newval > max) {
printf ("Please enter a value between %ld and %ld. ",
min, max);
goto loop;
}
}
*val = newval;
}
/* Ask a string question */
void askStr (
char *str,
char *val,
unsigned long maxlen)
{
char buf[260];
if (val[0])
printf ("%s (%s): ", str, val);
else
printf ("%s: ", str);
loop: get_line (buf);
if (buf[0] == 0) return;
if (strlen (buf) > maxlen) {
printf ("Maximum string length is %ld characters. ", maxlen);
goto loop;
}
strcpy (val, buf);
}
/* Wait for user input - gives the user time to read the screen */
void askOK ()
{
char str[80];
if (THREAD_KILL) return;
printf ("\nHit enter to continue: ");
get_line (str);
}
/* Ask user if he is satisfied with his dialog responses */
int askOkCancel ()
{
char buf[80];
if (THREAD_KILL) return (FALSE);
printf ("\nAccept the answers above? (Y): ");
get_line (buf);
return (buf[0] == 0 || buf[0] == 'Y' || buf[0] == 'y');
}
/* Ask user if he is satisfied with his dialog responses */
int askYesNo (
char dflt)
{
char buf[80];
if (THREAD_KILL) return (FALSE);
printf (" (%c): ", dflt);
get_line (buf);
if (buf[0] == 0) buf[0] = dflt;
return (buf[0] == 'Y' || buf[0] == 'y');
}
/* Output a long string with a max of 75 characters to a line */
void outputLongLine (
char *buf)
{
char line[80];
char *p;
int i, j;
for (p = buf; ; ) {
for (i = 0; i < 75; i++) {
line[i] = p[i];
if (p[i] == 0 || p[i] == '\n') { j = i; break; }
if (p[i] == ' ' || p[i] == '.' || p[i] == ',') j = i;
}
line[j+1] = 0;
printf ("%s", line);
if (p[j] == 0) break;
if (p[j] != '\n') printf ("\n");
p += j + 1;
while (*p == ' ') p++;
}
}
/* Test/InputData dialog */
void test_inputdata ()
{
char m_pgen_input[260], m_pgen_output[260];
unsigned long m_pgen_line;
IniGetString (INI_FILE, "PgenInputFile", m_pgen_input, 260, NULL);
IniGetString (INI_FILE, "PgenOutputFile", m_pgen_output, 260, NULL);
m_pgen_line = IniGetInt (INI_FILE, "PgenLine", 1);
askStr ("Input file (from NewPgen): ", m_pgen_input, 256);
askStr ("Output file (Results): ", m_pgen_output, 256);
askNum ("Line number", &m_pgen_line, 1, 999999999);
if (askOkCancel ()) {
IniWriteInt (INI_FILE, "Work", 0);
IniWriteString (INI_FILE, "PgenInputFile", m_pgen_input);
IniWriteString (INI_FILE, "PgenOutputFile", m_pgen_output);
IniWriteInt (INI_FILE, "PgenLine", m_pgen_line);
IniWriteInt (INI_FILE, "WorkDone", 0);
}
}
/* Advanced/Priority dialog */
void advanced_priority ()
{
unsigned long m_priority;
m_priority = PRIORITY;
outputLongLine ("Pick a priority between 1 and 10 where 1 is the lowest priority and 10 is the highest.\n");
outputLongLine ("It is strongly recommended that you use the default priority of 1. Your throughput will probably not improve by using a higher priority. The only time you should raise the priority is when another process, such as a screen saver, is stealing CPU cycles from this program.\n");
askNum ("Priority", &m_priority, 1, 10);
if (askOkCancel ()) {
PRIORITY = m_priority;
IniWriteInt (INI_FILE, "Priority", PRIORITY);
}
}
/* Options/CPU dialog */
void options_cpu ()
{
char buf[4096];
getCpuDescription (buf, 1);
if (!IniGetInt (INI_FILE, "OutputTopology", 0))
printf ("CPU Information:\n%s\n", buf);
askOK ();
}
/* Options/Preferences dialog */
void options_preferences ()
{
unsigned long m_iter, m_r_iter, m_disk_write_time;
int m_backup;
m_iter = ITER_OUTPUT;
m_r_iter = ITER_OUTPUT_RES;
m_disk_write_time = DISK_WRITE_TIME;
m_backup = TWO_BACKUP_FILES;
askNum ("Iterations between screen outputs", &m_iter, 1, 999999999);
askNum ("Iterations between results file outputs",
&m_r_iter, 10000, 999999999);
askNum ("Minutes between disk writes", &m_disk_write_time, 10, 999999);
askYN ("Create Two Backup Files", &m_backup);
if (askOkCancel ()) {
ITER_OUTPUT = m_iter;
ITER_OUTPUT_RES = m_r_iter;
DISK_WRITE_TIME = m_disk_write_time;
TWO_BACKUP_FILES = m_backup;
IniWriteInt (INI_FILE, "OutputIterations", ITER_OUTPUT);
IniWriteInt (INI_FILE, "ResultsFileIterations", ITER_OUTPUT_RES);
IniWriteInt (INI_FILE, "DiskWriteTime", DISK_WRITE_TIME);
IniWriteInt (INI_FILE, "TwoBackupFiles", TWO_BACKUP_FILES);
}
}
/* Help/About */
void help_about ()
{
printf ("Primality Testing of k*b^n+/-1 Program - PC/MacIntel Version "LLR_VERSION"\n");
printf ("Using new Gwnum library (V"GWNUM_VERSION") and IBDWT for k's up to 22 bits\n");
printf ("(Copyright 1996-2021 Just For Fun Software, Inc.\n");
printf ("Author: George Woltman\n");
printf ("Email: [email protected])\n");
printf ("Written : May 2021 by Jean Penne\n");
printf ("Email : [email protected]\n");
askOK ();
}
/* Display the main menu */
void main_menu ()
{
unsigned long choice;
mloop: if (THREAD_KILL) return;
printf ("\t Main Menu\n");
loop: printf ("\n");
printf ("\t 1. Test/Input Data\n");
printf ("\t 2. Test/Continue\n");
printf ("\t 3. Test/Exit\n");
printf ("\n");
printf ("\t 4. Options/CPU\n");
printf ("\t 5. Options/Preferences\n");
printf ("\t 6. Advanced/Priority\n");
printf ("\n");
printf ("\t 7. Help/About\n");
printf ("Your choice: ");
choice = get_number (0);
if (choice <= 0 || choice >= 8) {
printf ("\t Invalid choice\n");
goto loop;
}
/* Display the main menu and switch off the users choice */
printf ("\n");
switch (choice) {
/* Test/Primenet dialog */
case 1:
test_inputdata ();
break;
/* Test/Continue */
case 2:
linuxContinue ("Another llr is running.\n");
askOK ();
break;
/* Test/Exit */
case 3:
return;
/* Options/CPU dialog */
case 4:
options_cpu ();
break;
/* Options/Preferences dialog */
case 5:
options_preferences ();
break;
/* Advanced/Priority dialog */
case 6:
advanced_priority ();
break;
/* Help/About */
case 7:
help_about ();
break;
}
goto mloop;
}