home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / strod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.6 KB  |  88 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "prinit.h"
  20. #include "prio.h"
  21. #include "prprf.h"
  22. #include "prdtoa.h"
  23. #include "plgetopt.h"
  24.  
  25. #include <stdlib.h>
  26.  
  27. static void Help(void)
  28. {
  29.     PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
  30.     PR_fprintf(err, "Usage: /.strod [-c n] [-l n] [-h]\n");
  31.     PR_fprintf(err, "\t-n n Number to translate    (default: 1234567890123456789)\n");
  32.     PR_fprintf(err, "\t-l n Times to loop the test (default: 1)\n");
  33.     PR_fprintf(err, "\t-h   This message and nothing else\n");
  34. }  /* Help */
  35.  
  36. static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
  37. {
  38.     PLOptStatus os;
  39.     PRIntn loops = 1;
  40.     PRFloat64 answer;
  41.     const char *number = "1234567890123456789";
  42.     PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
  43.     PLOptState *opt = PL_CreateOptState(argc, argv, "hc:l:");
  44.  
  45.     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  46.     {
  47.         if (PL_OPT_BAD == os) continue;
  48.         switch (opt->option)
  49.         {
  50.         case 'n':  /* number to translate */
  51.             number = opt->value;
  52.             break;
  53.         case 'l':  /* number of times to run the tests */
  54.             loops = atoi(opt->value);
  55.             break;
  56.         case 'h':  /* user wants some guidance */
  57.             Help();  /* so give him an earful */
  58.             return 2;  /* but not a lot else */
  59.             break;
  60.          default:
  61.             break;
  62.         }
  63.     }
  64.     PL_DestroyOptState(opt);
  65.  
  66.     PR_fprintf(err, "Settings\n");
  67.     PR_fprintf(err, "\tNumber to translate %s\n", number);
  68.     PR_fprintf(err, "\tLoops to run test: %d\n", loops);
  69.  
  70.     while (loops--)
  71.     {
  72.         answer = PR_strtod(number, NULL);
  73.         PR_fprintf(err, "Translation = %20.0f\n", answer);
  74.     }
  75.     return 2;
  76. }
  77.  
  78.  
  79.  
  80. PRIntn main(PRIntn argc, char *argv[])
  81. {
  82.     PRIntn rv;
  83.     
  84.     PR_STDIO_INIT();
  85.     rv = PR_Initialize(RealMain, argc, argv, 0);
  86.     return rv;
  87. }  /* main */
  88.