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
Help(void)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
RealMain(PRIntn argc,char ** argv)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) {
35 continue;
36 }
37 switch (opt->option)
38 {
39 case 'n': /* number to translate */
40 number = opt->value;
41 break;
42 case 'l': /* number of times to run the tests */
43 loops = atoi(opt->value);
44 break;
45 case 'h': /* user wants some guidance */
46 Help(); /* so give him an earful */
47 return 2; /* but not a lot else */
48 break;
49 default:
50 break;
51 }
52 }
53 PL_DestroyOptState(opt);
54
55 PR_fprintf(err, "Settings\n");
56 PR_fprintf(err, "\tNumber to translate %s\n", number);
57 PR_fprintf(err, "\tLoops to run test: %d\n", loops);
58
59 while (loops--)
60 {
61 answer = PR_strtod(number, NULL);
62 PR_fprintf(err, "Translation = %20.0f\n", answer);
63 }
64 return 0;
65 }
66
67
68
main(int argc,char ** argv)69 int main(int argc, char **argv)
70 {
71 PRIntn rv;
72
73 PR_STDIO_INIT();
74 rv = PR_Initialize(RealMain, argc, argv, 0);
75 return rv;
76 } /* main */
77