strod.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen/* ***** BEGIN LICENSE BLOCK *****
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen *
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * The contents of this file are subject to the Mozilla Public License Version
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * 1.1 (the "License"); you may not use this file except in compliance with
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * the License. You may obtain a copy of the License at
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * http://www.mozilla.org/MPL/
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen *
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * Software distributed under the License is distributed on an "AS IS" basis,
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * for the specific language governing rights and limitations under the
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * License.
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen *
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * The Original Code is the Netscape Portable Runtime (NSPR).
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen *
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * The Initial Developer of the Original Code is
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * Netscape Communications Corporation.
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * Portions created by the Initial Developer are Copyright (C) 1998-2000
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * the Initial Developer. All Rights Reserved.
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen *
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * Contributor(s):
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen *
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * Alternatively, the contents of this file may be used under the terms of
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * either the GNU General Public License Version 2 or later (the "GPL"), or
2bb0656f94af82b1ff5e3e77a99b4427c52e4953rbowen * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * in which case the provisions of the GPL or the LGPL are applicable instead
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * of those above. If you wish to allow use of your version of this file only
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * under the terms of either the GPL or the LGPL, and not to allow others to
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * use your version of this file under the terms of the MPL, indicate your
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * decision by deleting the provisions above and replace them with the notice
5727d620998bb261ce947ba5f530c94f3e464ae8rbowen * and other provisions required by the GPL or the LGPL. If you do not delete
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * the provisions above, a recipient may use your version of this file under
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * the terms of any one of the MPL, the GPL or the LGPL.
5727d620998bb261ce947ba5f530c94f3e464ae8rbowen *
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen * ***** END LICENSE BLOCK ***** */
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen#include "prinit.h"
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen#include "prio.h"
6c1d5074d9ce7e7ffbf344cc73acce10bbbb77c9rbowen#include "prprf.h"
a66737adf71cba4fa315b7802e12cde3d887ee92rbowen#include "prdtoa.h"
8b79a240383bcecf28b75d4803683a7d101d2713rbowen#include "plgetopt.h"
623c623a55d08be1d0e5295f5896aa391904b39brbowen
623c623a55d08be1d0e5295f5896aa391904b39brbowen#include <stdlib.h>
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowenstatic void Help(void)
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen{
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PR_fprintf(err, "Usage: /.strod [-n n] [-l n] [-h]\n");
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PR_fprintf(err, "\t-n n Number to translate (default: 1234567890123456789)\n");
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PR_fprintf(err, "\t-l n Times to loop the test (default: 1)\n");
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PR_fprintf(err, "\t-h This message and nothing else\n");
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen} /* Help */
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowenstatic PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen{
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PLOptStatus os;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PRIntn loops = 1;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PRFloat64 answer;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen const char *number = "1234567890123456789";
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PLOptState *opt = PL_CreateOptState(argc, argv, "hc:l:");
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen {
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen if (PL_OPT_BAD == os) continue;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen switch (opt->option)
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen {
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen case 'n': /* number to translate */
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen number = opt->value;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen break;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen case 'l': /* number of times to run the tests */
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen loops = atoi(opt->value);
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen break;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen case 'h': /* user wants some guidance */
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen Help(); /* so give him an earful */
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen return 2; /* but not a lot else */
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen break;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen default:
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen break;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen }
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen }
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PL_DestroyOptState(opt);
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PR_fprintf(err, "Settings\n");
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PR_fprintf(err, "\tNumber to translate %s\n", number);
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PR_fprintf(err, "\tLoops to run test: %d\n", loops);
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen while (loops--)
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen {
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen answer = PR_strtod(number, NULL);
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PR_fprintf(err, "Translation = %20.0f\n", answer);
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen }
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen return 0;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen}
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowenPRIntn main(PRIntn argc, char *argv[])
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen{
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PRIntn rv;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen PR_STDIO_INIT();
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen rv = PR_Initialize(RealMain, argc, argv, 0);
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen return rv;
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen} /* main */
7ff40e17761fc92c8480c9403e5404927c4c6c23rbowen