Skip to content

Latest commit

 

History

History
631 lines (521 loc) · 17.3 KB

gui_stdio.c

File metadata and controls

631 lines (521 loc) · 17.3 KB
 
May 12, 2007
May 12, 2007
1
2
3
4
5
6
7
8
/**
* MojoSetup; a portable, flexible installation application.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
Dec 9, 2006
Dec 9, 2006
9
10
11
12
#if !SUPPORT_GUI_STDIO
#error Something is wrong in the build system.
#endif
Mar 25, 2006
Mar 25, 2006
13
#define BUILDING_EXTERNAL_PLUGIN 1
May 8, 2007
May 8, 2007
14
#include "gui.h"
Mar 27, 2006
Mar 27, 2006
15
Dec 7, 2006
Dec 7, 2006
16
17
18
19
20
21
MOJOGUI_PLUGIN(stdio)
#if !GUI_STATIC_LINK_STDIO
CREATE_MOJOGUI_ENTRY_POINT(stdio)
#endif
22
23
#include <ctype.h>
May 20, 2007
May 20, 2007
24
static char *lastProgressType = NULL;
May 7, 2007
May 7, 2007
25
26
27
static char *lastComponent = NULL;
static uint32 percentTicks = 0;
Dec 27, 2006
Dec 27, 2006
28
29
30
31
32
33
34
35
36
37
38
39
40
static int read_stdin(char *buf, int len)
{
if (fgets(buf, len, stdin) == NULL)
return -1;
len = strlen(buf) - 1;
while ( (len >= 0) && ((buf[len] == '\n') || (buf[len] == '\r')) )
buf[len--] = '\0';
return len+1;
} // read_stdin
Dec 28, 2006
Dec 28, 2006
41
42
static int readstr(const char *prompt, char *buf, int len,
boolean back, boolean fwd)
Dec 27, 2006
Dec 27, 2006
43
{
Dec 5, 2007
Dec 5, 2007
44
45
46
47
// !!! FIXME: if read_stdin() returns -1, we return 0, which makes it
// !!! FIXME: indistinguishable from "user hit enter" ... maybe we should
// !!! FIXME: abort in read_stdin() if i/o fails?
Dec 27, 2006
Dec 27, 2006
48
int retval = 0;
Mar 2, 2008
Mar 2, 2008
49
char *backstr = (back) ? xstrdup(_("back")) : NULL;
Dec 27, 2006
Dec 27, 2006
50
51
52
53
54
55
if (prompt != NULL)
printf("%s\n", prompt);
if (back)
{
Mar 2, 2008
Mar 2, 2008
56
57
char *fmt = xstrdup(_("Type '%0' to go back."));
char *msg = format(fmt, backstr);
Jan 12, 2008
Jan 12, 2008
58
59
60
printf("%s\n", msg);
free(msg);
free(fmt);
Dec 27, 2006
Dec 27, 2006
61
62
} // if
Dec 28, 2006
Dec 28, 2006
63
64
if (fwd)
{
Jun 15, 2009
Jun 15, 2009
65
printf("%s", _("Press enter to continue."));
Dec 28, 2006
Dec 28, 2006
66
67
68
printf("\n");
} // if
Jun 15, 2009
Jun 15, 2009
69
printf("%s",_("> "));
Dec 27, 2006
Dec 27, 2006
70
71
72
73
fflush(stdout);
if ((retval = read_stdin(buf, len)) >= 0)
{
Dec 5, 2007
Dec 5, 2007
74
if ((back) && (strcmp(buf, backstr) == 0)) // !!! FIXME: utf8casecmp?
Dec 27, 2006
Dec 27, 2006
75
76
77
retval = -1;
} // if
Jan 12, 2008
Jan 12, 2008
78
free(backstr);
Dec 27, 2006
Dec 27, 2006
79
return retval;
Dec 5, 2007
Dec 5, 2007
80
} // readstr
Dec 27, 2006
Dec 27, 2006
81
82
Nov 21, 2007
Nov 21, 2007
83
static uint8 MojoGui_stdio_priority(boolean istty)
Nov 21, 2007
Nov 21, 2007
85
86
87
88
89
90
91
92
// if not a tty and no other GUI plugins worked out, let the base
// application try to spawn a terminal and try again. If it can't do so,
// it will panic() and thus end the process, so we don't end up blocking
// on some prompt the user can't see.
if (!istty)
return MOJOGUI_PRIORITY_NEVER_TRY;
May 18, 2007
May 18, 2007
93
return MOJOGUI_PRIORITY_TRY_ABSOLUTELY_LAST; // always a last resort.
Dec 27, 2006
Dec 27, 2006
94
95
} // MojoGui_stdio_priority
Dec 7, 2006
Dec 7, 2006
97
static boolean MojoGui_stdio_init(void)
May 7, 2007
May 7, 2007
99
percentTicks = 0;
Nov 21, 2007
Nov 21, 2007
100
return true; // always succeeds.
Dec 27, 2006
Dec 27, 2006
101
102
} // MojoGui_stdio_init
Dec 7, 2006
Dec 7, 2006
104
static void MojoGui_stdio_deinit(void)
May 20, 2007
May 20, 2007
106
free(lastProgressType);
May 12, 2007
May 12, 2007
107
free(lastComponent);
May 20, 2007
May 20, 2007
108
lastProgressType = NULL;
May 12, 2007
May 12, 2007
109
lastComponent = NULL;
Dec 27, 2006
Dec 27, 2006
110
111
} // MojoGui_stdio_deinit
Dec 7, 2006
Dec 7, 2006
113
static void MojoGui_stdio_msgbox(const char *title, const char *text)
Dec 27, 2006
Dec 27, 2006
115
char buf[128];
Mar 2, 2008
Mar 2, 2008
116
117
char *fmt = xstrdup(_("NOTICE: %0\n[hit enter]"));
char *msg = format(fmt, text);
Jan 12, 2008
Jan 12, 2008
118
119
120
printf("%s\n", msg);
free(msg);
free(fmt);
121
fflush(stdout);
Dec 27, 2006
Dec 27, 2006
122
read_stdin(buf, sizeof (buf));
Dec 20, 2006
Dec 20, 2006
123
} // MojoGui_stdio_msgbox
Dec 27, 2006
Dec 27, 2006
125
Jul 2, 2007
Jul 2, 2007
126
127
static boolean MojoGui_stdio_promptyn(const char *title, const char *text,
boolean defval)
Dec 27, 2006
Dec 27, 2006
129
130
boolean retval = false;
if (!feof(stdin))
Mar 2, 2008
Mar 2, 2008
132
133
134
135
136
const char *_fmt = ((defval) ? _("%0 [Y/n]: ") : _("%0 [y/N]: "));
char *fmt = xstrdup(_fmt);
char *msg = format(fmt, text);
char *localized_no = xstrdup(_("N"));
char *localized_yes = xstrdup(_("Y"));
Dec 27, 2006
Dec 27, 2006
137
boolean getout = false;
Dec 20, 2006
Dec 20, 2006
138
char buf[128];
Dec 5, 2007
Dec 5, 2007
139
Dec 27, 2006
Dec 27, 2006
140
while (!getout)
Dec 20, 2006
Dec 20, 2006
141
{
Dec 5, 2007
Dec 5, 2007
142
143
144
int rc = 0;
getout = true; // we may reset this later.
Jan 23, 2008
Jan 23, 2008
145
printf("%s", msg);
Dec 20, 2006
Dec 20, 2006
146
fflush(stdout);
Dec 5, 2007
Dec 5, 2007
147
148
149
150
151
152
rc = read_stdin(buf, sizeof (buf));
if (rc < 0)
retval = false;
else if (rc == 0)
retval = defval;
Dec 27, 2006
Dec 27, 2006
153
else if (strcasecmp(buf, localized_no) == 0)
Dec 5, 2007
Dec 5, 2007
154
retval = false;
Dec 20, 2006
Dec 20, 2006
155
else if (strcasecmp(buf, localized_yes) == 0)
Dec 5, 2007
Dec 5, 2007
156
157
158
retval = true;
else
getout = false; // try again.
Dec 20, 2006
Dec 20, 2006
159
} // while
Dec 5, 2007
Dec 5, 2007
160
Jan 12, 2008
Jan 12, 2008
161
162
163
164
free(localized_yes);
free(localized_no);
free(msg);
free(fmt);
Dec 27, 2006
Dec 27, 2006
165
} // if
Dec 27, 2006
Dec 27, 2006
167
return retval;
Dec 20, 2006
Dec 20, 2006
168
} // MojoGui_stdio_promptyn
May 7, 2007
May 7, 2007
170
Jul 2, 2007
Jul 2, 2007
171
172
static MojoGuiYNAN MojoGui_stdio_promptynan(const char *title, const char *txt,
boolean defval)
May 17, 2007
May 17, 2007
173
174
175
176
{
MojoGuiYNAN retval = MOJOGUI_NO;
if (!feof(stdin))
{
Mar 2, 2008
Mar 2, 2008
177
178
179
180
181
182
char *fmt = xstrdup(_("%0\n[y/n/Always/Never]: "));
char *msg = format(fmt, txt);
char *localized_no = xstrdup(_("N"));
char *localized_yes = xstrdup(_("Y"));
char *localized_always = xstrdup(_("Always"));
char *localized_never = xstrdup(_("Never"));
May 17, 2007
May 17, 2007
183
184
boolean getout = false;
char buf[128];
Dec 5, 2007
Dec 5, 2007
185
May 17, 2007
May 17, 2007
186
187
while (!getout)
{
Dec 5, 2007
Dec 5, 2007
188
189
190
int rc = 0;
getout = true; // we may reset this later.
Jan 12, 2008
Jan 12, 2008
191
printf("%s\n", msg);
May 17, 2007
May 17, 2007
192
fflush(stdout);
Dec 5, 2007
Dec 5, 2007
193
194
195
196
197
198
rc = read_stdin(buf, sizeof (buf));
if (rc < 0)
retval = MOJOGUI_NO;
else if (rc == 0)
retval = (defval) ? MOJOGUI_YES : MOJOGUI_NO;
May 17, 2007
May 17, 2007
199
else if (strcasecmp(buf, localized_no) == 0)
Dec 5, 2007
Dec 5, 2007
200
retval = MOJOGUI_NO;
May 17, 2007
May 17, 2007
201
202
203
204
205
206
else if (strcasecmp(buf, localized_yes) == 0)
retval = MOJOGUI_YES;
else if (strcasecmp(buf, localized_always) == 0)
retval = MOJOGUI_ALWAYS;
else if (strcasecmp(buf, localized_never) == 0)
retval = MOJOGUI_NEVER;
Dec 5, 2007
Dec 5, 2007
207
208
else
getout = false; // try again.
May 17, 2007
May 17, 2007
209
} // while
Dec 5, 2007
Dec 5, 2007
210
Jan 12, 2008
Jan 12, 2008
211
212
213
214
215
216
free(localized_never);
free(localized_always);
free(localized_yes);
free(localized_no);
free(msg);
free(fmt);
May 17, 2007
May 17, 2007
217
218
219
220
221
222
} // if
return retval;
} // MojoGui_stdio_promptynan
Nov 24, 2007
Nov 24, 2007
223
224
static boolean MojoGui_stdio_start(const char *title,
const MojoGuiSplash *splash)
Dec 12, 2006
Dec 12, 2006
225
226
227
{
printf("%s\n", title);
return true;
Dec 20, 2006
Dec 20, 2006
228
} // MojoGui_stdio_start
Dec 12, 2006
Dec 12, 2006
229
230
Dec 20, 2006
Dec 20, 2006
231
static void MojoGui_stdio_stop(void)
Dec 12, 2006
Dec 12, 2006
232
233
{
// no-op.
Dec 20, 2006
Dec 20, 2006
234
235
236
} // MojoGui_stdio_stop
Dec 5, 2007
Dec 5, 2007
237
238
239
static void dumb_pager(const char *name, const char *data, size_t datalen)
{
const int MAX_PAGE_LINES = 21;
Mar 2, 2008
Mar 2, 2008
240
char *fmt = xstrdup(_("(%0-%1 of %2 lines, see more?)"));
Dec 5, 2007
Dec 5, 2007
241
242
243
int i = 0;
int w = 0;
int linecount = 0;
Dec 27, 2006
Dec 27, 2006
244
boolean getout = false;
Mar 3, 2008
Mar 3, 2008
245
char **lines = splitText(data, 80, &linecount, &w);
Dec 5, 2007
Dec 5, 2007
246
247
assert(linecount >= 0);
Dec 27, 2006
Dec 27, 2006
248
Dec 5, 2007
Dec 5, 2007
249
250
251
252
253
printf("%s\n", name);
if (lines == NULL) // failed to parse?!
printf("%s\n", data); // just dump it all. Oh well.
else
Dec 27, 2006
Dec 27, 2006
254
{
Dec 5, 2007
Dec 5, 2007
255
256
int printed = 0;
do
May 10, 2007
May 10, 2007
257
{
Dec 5, 2007
Dec 5, 2007
258
for (i = 0; (i < MAX_PAGE_LINES) && (printed < linecount); i++)
Aug 8, 2008
Aug 8, 2008
259
printf("%s", lines[printed++]);
Dec 5, 2007
Dec 5, 2007
260
261
262
263
264
if (printed >= linecount)
getout = true;
else
{
Jan 12, 2008
Jan 12, 2008
265
char *msg = NULL;
Dec 5, 2007
Dec 5, 2007
266
printf("\n");
Mar 2, 2008
Mar 2, 2008
267
268
msg = format(fmt, numstr((printed-i)+1),
numstr(printed), numstr(linecount));
Jan 12, 2008
Jan 12, 2008
269
270
getout = !MojoGui_stdio_promptyn("", msg, true);
free(msg);
Dec 5, 2007
Dec 5, 2007
271
272
273
printf("\n");
} // else
} while (!getout);
Dec 27, 2006
Dec 27, 2006
274
275
} // while
Dec 5, 2007
Dec 5, 2007
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
for (i = 0; i < linecount; i++)
free(lines[i]);
free(lines);
free(fmt);
} // dumb_pager
static int MojoGui_stdio_readme(const char *name, const uint8 *_data,
size_t datalen, boolean can_back,
boolean can_fwd)
{
const char *data = (const char *) _data;
char buf[256];
int retval = -1;
boolean failed = true;
Dec 5, 2007
Dec 5, 2007
292
293
// !!! FIXME: popen() isn't reliable.
#if 0 //PLATFORM_UNIX
Dec 5, 2007
Dec 5, 2007
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
const size_t namelen = strlen(name);
const char *programs[] = { getenv("PAGER"), "more", "less -M", "less" };
int i = 0;
// flush streams, so output doesn't mingle with the popen()'d process.
fflush(stdout);
fflush(stderr);
for (i = 0; i < STATICARRAYLEN(programs); i++)
{
const char *cmd = programs[i];
if (cmd != NULL)
{
FILE *io = popen(cmd, "w");
if (io != NULL)
{
failed = false;
if (!failed) failed = (fwrite("\n", 1, 1, io) != 1);
if (!failed) failed = (fwrite(name, namelen, 1, io) != 1);
if (!failed) failed = (fwrite("\n", 1, 1, io) != 1);
if (!failed) failed = (fwrite(data, datalen, 1, io) != 1);
if (!failed) failed = (fwrite("\n", 1, 1, io) != 1);
failed |= (pclose(io) != 0); // call whether we failed or not.
if (!failed)
break; // it worked, we're done!
} // if
} // if
} // for
#endif // PLATFORM_UNIX
if (failed) // We're not Unix, or none of the pagers worked?
dumb_pager(name, data, datalen);
Dec 16, 2007
Dec 16, 2007
327
328
329
// Put up the "hit enter to continue (or 'back' to go back)" prompt,
// but only if there's an choice to be made here.
if ((!can_back) || (readstr(NULL, buf, sizeof (buf), can_back, true) >= 0))
Dec 5, 2007
Dec 5, 2007
330
331
retval = 1;
Dec 27, 2006
Dec 27, 2006
332
return retval;
Dec 20, 2006
Dec 20, 2006
333
} // MojoGui_stdio_readme
Dec 12, 2006
Dec 12, 2006
334
Dec 27, 2006
Dec 27, 2006
335
Dec 27, 2006
Dec 27, 2006
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
372
373
374
375
376
377
378
static void toggle_option(MojoGuiSetupOptions *parent,
MojoGuiSetupOptions *opts, int *line, int target)
{
if ((opts != NULL) && (target > *line))
{
if (!opts->is_group_parent)
{
if (++(*line) == target)
{
const boolean toggled = ((opts->value) ? false : true);
// "radio buttons" in a group?
if ((parent) && (parent->is_group_parent))
{
if (toggled) // drop unless we weren't the current toggle.
{
// set all siblings to false...
MojoGuiSetupOptions *i = parent->child;
while (i != NULL)
{
i->value = false;
i = i->next_sibling;
} // while
opts->value = true; // reset us to be true.
} // if
} // if
else // individual "check box" was chosen.
{
opts->value = toggled;
} // else
return; // we found it, bail.
} // if
} // if
if (opts->value) // if option is toggled on, descend to children.
toggle_option(opts, opts->child, line, target);
toggle_option(parent, opts->next_sibling, line, target);
} // if
} // toggle_option
Dec 27, 2006
Dec 27, 2006
379
380
381
382
383
384
385
static void print_options(MojoGuiSetupOptions *opts, int *line, int level)
{
if (opts != NULL)
{
int i;
int spacing = 1;
if (opts->is_group_parent)
May 12, 2007
May 12, 2007
386
spacing += 6;
Dec 27, 2006
Dec 27, 2006
387
else
Dec 27, 2006
Dec 27, 2006
388
389
{
(*line)++;
Dec 27, 2006
Dec 27, 2006
390
printf("%2d [%c]", *line, opts->value ? 'X' : ' ');
Dec 27, 2006
Dec 27, 2006
391
} // else
Dec 27, 2006
Dec 27, 2006
392
May 12, 2007
May 12, 2007
393
for (i = 0; i < (level + spacing); i++)
Dec 27, 2006
Dec 27, 2006
394
395
putchar(' ');
May 12, 2007
May 12, 2007
396
printf("%s%s\n", opts->description, opts->is_group_parent ? ":" : "");
Dec 27, 2006
Dec 27, 2006
397
May 12, 2007
May 12, 2007
398
if ((opts->value) || (opts->is_group_parent))
Dec 27, 2006
Dec 27, 2006
399
print_options(opts->child, line, level+1);
Dec 27, 2006
Dec 27, 2006
400
401
402
403
404
print_options(opts->next_sibling, line, level);
} // if
} // print_options
May 10, 2007
May 10, 2007
405
static int MojoGui_stdio_options(MojoGuiSetupOptions *opts,
May 10, 2007
May 10, 2007
406
boolean can_back, boolean can_fwd)
Dec 27, 2006
Dec 27, 2006
407
{
Mar 2, 2008
Mar 2, 2008
408
409
const char *inst_opts_str = xstrdup(_("Options"));
const char *prompt = xstrdup(_("Choose number to change."));
May 10, 2007
May 10, 2007
410
int retval = -1;
Dec 27, 2006
Dec 27, 2006
411
412
413
414
415
416
417
418
419
boolean getout = false;
char buf[128];
int len = 0;
while (!getout)
{
int line = 0;
printf("\n\n");
Jun 15, 2009
Jun 15, 2009
420
printf("%s", inst_opts_str);
Dec 27, 2006
Dec 27, 2006
421
422
423
424
printf("\n");
print_options(opts, &line, 1);
printf("\n");
May 10, 2007
May 10, 2007
425
if ((len = readstr(prompt, buf, sizeof (buf), can_back, true)) < 0)
Dec 27, 2006
Dec 27, 2006
426
427
getout = true;
else if (len == 0)
May 10, 2007
May 10, 2007
428
429
430
431
{
getout = true;
retval = 1;
} // else if
Dec 27, 2006
Dec 27, 2006
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
else
{
char *endptr = NULL;
int target = (int) strtol(buf, &endptr, 10);
if (*endptr == '\0') // complete string was a valid number?
{
line = 0;
toggle_option(NULL, opts, &line, target);
} // if
} // else
} // while
free((void *) inst_opts_str);
free((void *) prompt);
return retval;
Dec 27, 2006
Dec 27, 2006
448
449
} // MojoGui_stdio_options
Dec 28, 2006
Dec 28, 2006
450
May 10, 2007
May 10, 2007
451
452
453
static char *MojoGui_stdio_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
Dec 28, 2006
Dec 28, 2006
454
{
Mar 2, 2008
Mar 2, 2008
455
const char *instdeststr = xstrdup(_("Destination"));
Dec 28, 2006
Dec 28, 2006
456
457
458
459
const char *prompt = NULL;
char *retval = NULL;
boolean getout = false;
char buf[128];
Dec 28, 2006
Dec 28, 2006
460
int len = 0;
Dec 28, 2006
Dec 28, 2006
461
462
int i = 0;
May 10, 2007
May 10, 2007
463
464
465
*command = -1;
if (recnum > 0)
Mar 2, 2008
Mar 2, 2008
466
prompt = xstrdup(_("Choose install destination by number (hit enter for #1), or enter your own."));
Dec 28, 2006
Dec 28, 2006
467
else
Mar 2, 2008
Mar 2, 2008
468
prompt = xstrdup(_("Enter path where files will be installed."));
Dec 28, 2006
Dec 28, 2006
469
470
471
472
while (!getout)
{
printf("\n\n%s\n", instdeststr);
May 10, 2007
May 10, 2007
473
for (i = 0; i < recnum; i++)
Dec 28, 2006
Dec 28, 2006
474
475
476
printf(" %2d %s\n", i+1, recommends[i]);
printf("\n");
May 10, 2007
May 10, 2007
477
if ((len = readstr(prompt, buf, sizeof (buf), can_back, false)) < 0)
Dec 28, 2006
Dec 28, 2006
478
getout = true;
May 17, 2007
May 17, 2007
479
480
481
else if ((len == 0) && (recnum > 0)) // default to first in list.
{
Mar 2, 2008
Mar 2, 2008
482
retval = xstrdup(recommends[0]);
May 17, 2007
May 17, 2007
483
484
485
486
*command = 1;
getout = true;
} // else if
Dec 28, 2006
Dec 28, 2006
487
else if (len > 0)
Dec 28, 2006
Dec 28, 2006
488
489
490
491
{
char *endptr = NULL;
int target = (int) strtol(buf, &endptr, 10);
// complete string was a valid number?
May 10, 2007
May 10, 2007
492
if ((*endptr == '\0') && (target > 0) && (target <= recnum))
Mar 2, 2008
Mar 2, 2008
493
retval = xstrdup(recommends[target-1]);
Dec 28, 2006
Dec 28, 2006
494
else
Mar 2, 2008
Mar 2, 2008
495
retval = xstrdup(buf);
Dec 28, 2006
Dec 28, 2006
496
May 10, 2007
May 10, 2007
497
*command = 1;
Dec 28, 2006
Dec 28, 2006
498
499
500
501
502
503
504
505
506
507
getout = true;
} // else
} // while
free((void *) prompt);
free((void *) instdeststr);
return retval;
} // MojoGui_stdio_destination
Apr 21, 2007
Apr 21, 2007
508
Apr 25, 2009
Apr 25, 2009
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
static int MojoGui_stdio_productkey(const char *desc, const char *fmt,
char *buf, const int buflen,
boolean can_back, boolean can_fwd)
{
const char *prompt = xstrdup(_("Please enter your product key"));
char *defval = ((*buf) ? xstrdup(buf) : NULL);
boolean getout = false;
int retval = -1;
char *msg = NULL;
if (defval != NULL)
{
char *locfmt = xstrdup(_("(just press enter to use '%0')"));
msg = format(locfmt, defval);
free(locfmt);
} // if
while (!getout)
{
int len;
printf("\n\n%s\n", desc);
if (msg != NULL)
printf("%s\n", msg);
if ((len = readstr(prompt, buf, buflen, can_back, false)) < 0)
getout = true;
else
{
if ((len == 0) && (defval != NULL))
strcpy(buf, defval);
Apr 25, 2009
Apr 25, 2009
539
if (isValidProductKey(fmt, buf))
Apr 25, 2009
Apr 25, 2009
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
{
retval = 1;
getout = true;
} // else if
else
{
// We can't check the input character-by-character, so reuse
// the failed-verification localized string.
printf("\n%s\n\n",
_("That key appears to be invalid. Please try again."));
} // else
} // else
} // while
free(msg);
free(defval);
free((void *) prompt);
return retval;
} // MojoGui_stdio_productkey
Apr 21, 2007
Apr 21, 2007
562
563
564
static boolean MojoGui_stdio_insertmedia(const char *medianame)
{
char buf[32];
Mar 2, 2008
Mar 2, 2008
565
566
567
char *fmt = xstrdup(_("Please insert '%0'"));
char *msg = format(fmt, medianame);
printf("%s\n", _("Media change"));
Jan 12, 2008
Jan 12, 2008
568
569
570
printf("%s\n", msg);
free(msg);
free(fmt);
Apr 22, 2007
Apr 22, 2007
571
return (readstr(NULL, buf, sizeof (buf), false, true) >= 0);
Apr 21, 2007
Apr 21, 2007
572
573
} // MojoGui_stdio_insertmedia
Apr 22, 2007
Apr 22, 2007
574
Feb 20, 2008
Feb 20, 2008
575
576
577
578
579
580
581
static void MojoGui_stdio_progressitem(void)
{
// force new line of output on next call to MojoGui_stdio_progress()
percentTicks = 0;
} // MojoGui_stdio_progressitem
May 7, 2007
May 7, 2007
582
static boolean MojoGui_stdio_progress(const char *type, const char *component,
Jan 24, 2008
Jan 24, 2008
583
584
int percent, const char *item,
boolean can_cancel)
Apr 22, 2007
Apr 22, 2007
585
{
Mar 2, 2008
Mar 2, 2008
586
const uint32 now = ticks();
May 20, 2007
May 20, 2007
587
588
589
590
591
if ( (lastComponent == NULL) ||
(strcmp(lastComponent, component) != 0) ||
(lastProgressType == NULL) ||
(strcmp(lastProgressType, type) != 0) )
May 7, 2007
May 7, 2007
592
{
May 20, 2007
May 20, 2007
593
free(lastProgressType);
May 7, 2007
May 7, 2007
594
free(lastComponent);
Mar 2, 2008
Mar 2, 2008
595
596
lastProgressType = xstrdup(type);
lastComponent = xstrdup(component);
May 9, 2007
May 9, 2007
597
printf("%s\n%s\n", type, component);
May 7, 2007
May 7, 2007
598
599
} // if
Feb 20, 2008
Feb 20, 2008
600
601
602
// limit update spam... will only write every one second, tops,
// on any given filename, but it writes each filename at least once
// so it doesn't look like we only installed a few things.
May 7, 2007
May 7, 2007
603
604
if (percentTicks <= now)
{
Jan 12, 2008
Jan 12, 2008
605
606
char *fmt = NULL;
char *msg = NULL;
May 9, 2007
May 9, 2007
607
percentTicks = now + 1000;
May 17, 2007
May 17, 2007
608
if (percent < 0)
Jan 12, 2008
Jan 12, 2008
609
printf("%s\n", item);
May 17, 2007
May 17, 2007
610
else
Jan 12, 2008
Jan 12, 2008
611
{
Mar 2, 2008
Mar 2, 2008
612
613
fmt = xstrdup(_("%0 (total progress: %1%%)"));
msg = format(fmt, item, numstr(percent));
Jan 12, 2008
Jan 12, 2008
614
615
616
617
printf("%s\n", msg);
free(msg);
free(fmt);
} // else
May 7, 2007
May 7, 2007
618
} // if
Apr 22, 2007
Apr 22, 2007
619
May 7, 2007
May 7, 2007
620
621
return true;
} // MojoGui_stdio_progress
Apr 22, 2007
Apr 22, 2007
622
May 12, 2007
May 12, 2007
623
624
625
626
627
628
629
static void MojoGui_stdio_final(const char *msg)
{
printf("%s\n\n", msg);
fflush(stdout);
} // MojoGui_stdio_final
Mar 27, 2006
Mar 27, 2006
630
// end of gui_stdio.c ...