home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / i2l.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.9 KB  |  115 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 <stdlib.h>
  20.  
  21. #include "prio.h"
  22. #include "prinit.h"
  23. #include "prprf.h"
  24. #include "prlong.h"
  25.  
  26. #include "plerror.h"
  27. #include "plgetopt.h"
  28.  
  29. typedef union Overlay_i
  30. {
  31.     PRInt32 i;
  32.     PRInt64 l;
  33. } Overlay_i;
  34.  
  35. typedef union Overlay_u
  36. {
  37.     PRUint32 i;
  38.     PRUint64 l;
  39. } Overlay_u;
  40.  
  41. static PRFileDesc *err = NULL;
  42.  
  43. static void Help(void)
  44. {
  45.     PR_fprintf(err, "Usage: -i n | -u n | -h\n");
  46.     PR_fprintf(err, "\t-i n treat following number as signed integer\n");
  47.     PR_fprintf(err, "\t-u n treat following number as unsigned integer\n");
  48.     PR_fprintf(err, "\t-h   This message and nothing else\n");
  49. }  /* Help */
  50.  
  51. static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
  52. {
  53.     Overlay_i si;
  54.     Overlay_u ui;
  55.     PLOptStatus os;
  56.     PRBool bsi = PR_FALSE, bui = PR_FALSE;
  57.     PLOptState *opt = PL_CreateOptState(argc, argv, "hi:u:");
  58.     err = PR_GetSpecialFD(PR_StandardError);
  59.  
  60.     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  61.     {
  62.         if (PL_OPT_BAD == os) continue;
  63.         switch (opt->option)
  64.         {
  65.         case 'i':  /* signed integer */
  66.             si.i = (PRInt32)atoi(opt->value);
  67.             bsi = PR_TRUE;
  68.             break;
  69.         case 'u':  /* unsigned */
  70.             ui.i = (PRUint32)atoi(opt->value);
  71.             bui = PR_TRUE;
  72.             break;
  73.         case 'h':  /* user wants some guidance */
  74.          default:
  75.             Help();  /* so give him an earful */
  76.             return 2;  /* but not a lot else */
  77.         }
  78.     }
  79.     PL_DestroyOptState(opt);
  80.  
  81. #if defined(HAVE_LONG_LONG)
  82.     PR_fprintf(err, "We have long long\n");
  83. #else
  84.     PR_fprintf(err, "We don't have long long\n");
  85. #endif
  86.  
  87.     if (bsi)
  88.     {
  89.         PR_fprintf(err, "Converting %ld: ", si.i);
  90.         LL_I2L(si.l, si.i);
  91.         PR_fprintf(err, "%lld\n", si.l);
  92.     }
  93.  
  94.     if (bui)
  95.     {
  96.         PR_fprintf(err, "Converting %lu: ", ui.i);
  97.         LL_I2L(ui.l, ui.i);
  98.         PR_fprintf(err, "%llu\n", ui.l);
  99.     }
  100.     return 0;
  101.  
  102. }  /* main */
  103.  
  104.  
  105. PRIntn main(PRIntn argc, char *argv[])
  106. {
  107.     PRIntn rv;
  108.     
  109.     PR_STDIO_INIT();
  110.     rv = PR_Initialize(RealMain, argc, argv, 0);
  111.     return rv;
  112. }  /* main */
  113.  
  114. /* i2l.c */
  115.