nsprpub/pr/tests/strod.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/strod.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "prinit.h"
    1.10 +#include "prio.h"
    1.11 +#include "prprf.h"
    1.12 +#include "prdtoa.h"
    1.13 +#include "plgetopt.h"
    1.14 +
    1.15 +#include <stdlib.h>
    1.16 +
    1.17 +static void Help(void)
    1.18 +{
    1.19 +    PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
    1.20 +    PR_fprintf(err, "Usage: /.strod [-n n] [-l n] [-h]\n");
    1.21 +    PR_fprintf(err, "\t-n n Number to translate    (default: 1234567890123456789)\n");
    1.22 +    PR_fprintf(err, "\t-l n Times to loop the test (default: 1)\n");
    1.23 +    PR_fprintf(err, "\t-h   This message and nothing else\n");
    1.24 +}  /* Help */
    1.25 +
    1.26 +static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
    1.27 +{
    1.28 +    PLOptStatus os;
    1.29 +    PRIntn loops = 1;
    1.30 +    PRFloat64 answer;
    1.31 +    const char *number = "1234567890123456789";
    1.32 +    PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
    1.33 +    PLOptState *opt = PL_CreateOptState(argc, argv, "hc:l:");
    1.34 +
    1.35 +    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    1.36 +    {
    1.37 +        if (PL_OPT_BAD == os) continue;
    1.38 +        switch (opt->option)
    1.39 +        {
    1.40 +        case 'n':  /* number to translate */
    1.41 +            number = opt->value;
    1.42 +            break;
    1.43 +        case 'l':  /* number of times to run the tests */
    1.44 +            loops = atoi(opt->value);
    1.45 +            break;
    1.46 +        case 'h':  /* user wants some guidance */
    1.47 +            Help();  /* so give him an earful */
    1.48 +            return 2;  /* but not a lot else */
    1.49 +            break;
    1.50 +         default:
    1.51 +            break;
    1.52 +        }
    1.53 +    }
    1.54 +    PL_DestroyOptState(opt);
    1.55 +
    1.56 +    PR_fprintf(err, "Settings\n");
    1.57 +    PR_fprintf(err, "\tNumber to translate %s\n", number);
    1.58 +    PR_fprintf(err, "\tLoops to run test: %d\n", loops);
    1.59 +
    1.60 +    while (loops--)
    1.61 +    {
    1.62 +        answer = PR_strtod(number, NULL);
    1.63 +        PR_fprintf(err, "Translation = %20.0f\n", answer);
    1.64 +    }
    1.65 +    return 0;
    1.66 +}
    1.67 +
    1.68 +
    1.69 +
    1.70 +int main(int argc, char **argv)
    1.71 +{
    1.72 +    PRIntn rv;
    1.73 +    
    1.74 +    PR_STDIO_INIT();
    1.75 +    rv = PR_Initialize(RealMain, argc, argv, 0);
    1.76 +    return rv;
    1.77 +}  /* main */

mercurial