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