|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "prinit.h" |
|
7 #include "prio.h" |
|
8 #include "prprf.h" |
|
9 #include "prdtoa.h" |
|
10 #include "plgetopt.h" |
|
11 |
|
12 #include <stdlib.h> |
|
13 |
|
14 static void Help(void) |
|
15 { |
|
16 PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); |
|
17 PR_fprintf(err, "Usage: /.strod [-n n] [-l n] [-h]\n"); |
|
18 PR_fprintf(err, "\t-n n Number to translate (default: 1234567890123456789)\n"); |
|
19 PR_fprintf(err, "\t-l n Times to loop the test (default: 1)\n"); |
|
20 PR_fprintf(err, "\t-h This message and nothing else\n"); |
|
21 } /* Help */ |
|
22 |
|
23 static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv) |
|
24 { |
|
25 PLOptStatus os; |
|
26 PRIntn loops = 1; |
|
27 PRFloat64 answer; |
|
28 const char *number = "1234567890123456789"; |
|
29 PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); |
|
30 PLOptState *opt = PL_CreateOptState(argc, argv, "hc:l:"); |
|
31 |
|
32 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
|
33 { |
|
34 if (PL_OPT_BAD == os) continue; |
|
35 switch (opt->option) |
|
36 { |
|
37 case 'n': /* number to translate */ |
|
38 number = opt->value; |
|
39 break; |
|
40 case 'l': /* number of times to run the tests */ |
|
41 loops = atoi(opt->value); |
|
42 break; |
|
43 case 'h': /* user wants some guidance */ |
|
44 Help(); /* so give him an earful */ |
|
45 return 2; /* but not a lot else */ |
|
46 break; |
|
47 default: |
|
48 break; |
|
49 } |
|
50 } |
|
51 PL_DestroyOptState(opt); |
|
52 |
|
53 PR_fprintf(err, "Settings\n"); |
|
54 PR_fprintf(err, "\tNumber to translate %s\n", number); |
|
55 PR_fprintf(err, "\tLoops to run test: %d\n", loops); |
|
56 |
|
57 while (loops--) |
|
58 { |
|
59 answer = PR_strtod(number, NULL); |
|
60 PR_fprintf(err, "Translation = %20.0f\n", answer); |
|
61 } |
|
62 return 0; |
|
63 } |
|
64 |
|
65 |
|
66 |
|
67 int main(int argc, char **argv) |
|
68 { |
|
69 PRIntn rv; |
|
70 |
|
71 PR_STDIO_INIT(); |
|
72 rv = PR_Initialize(RealMain, argc, argv, 0); |
|
73 return rv; |
|
74 } /* main */ |