tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

strod.c (2007B)


      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  PRFileDesc* err = PR_GetSpecialFD(PR_StandardError);
     16  PR_fprintf(err, "Usage: /.strod [-n n] [-l n] [-h]\n");
     17  PR_fprintf(err,
     18             "\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  PLOptStatus os;
     25  PRIntn loops = 1;
     26  PRFloat64 answer;
     27  const char* number = "1234567890123456789";
     28  PRFileDesc* err = PR_GetSpecialFD(PR_StandardError);
     29  PLOptState* opt = PL_CreateOptState(argc, argv, "hc:l:");
     30 
     31  while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) {
     32    if (PL_OPT_BAD == os) {
     33      continue;
     34    }
     35    switch (opt->option) {
     36      case 'n': /* number to translate */
     37        number = opt->value;
     38        break;
     39      case 'l': /* number of times to run the tests */
     40        loops = atoi(opt->value);
     41        break;
     42      case 'h':   /* user wants some guidance */
     43        Help();   /* so give him an earful */
     44        return 2; /* but not a lot else */
     45        break;
     46      default:
     47        break;
     48    }
     49  }
     50  PL_DestroyOptState(opt);
     51 
     52  PR_fprintf(err, "Settings\n");
     53  PR_fprintf(err, "\tNumber to translate %s\n", number);
     54  PR_fprintf(err, "\tLoops to run test: %d\n", loops);
     55 
     56  while (loops--) {
     57    answer = PR_strtod(number, NULL);
     58    PR_fprintf(err, "Translation = %20.0f\n", answer);
     59  }
     60  return 0;
     61 }
     62 
     63 int main(int argc, char** argv) {
     64  PRIntn rv;
     65 
     66  rv = PR_Initialize(RealMain, argc, argv, 0);
     67  return rv;
     68 } /* main */