Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
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/. */
6 #include <stdlib.h>
8 #include "prio.h"
9 #include "prinit.h"
10 #include "prprf.h"
11 #include "prlong.h"
13 #include "plerror.h"
14 #include "plgetopt.h"
16 typedef union Overlay_i
17 {
18 PRInt32 i;
19 PRInt64 l;
20 } Overlay_i;
22 typedef union Overlay_u
23 {
24 PRUint32 i;
25 PRUint64 l;
26 } Overlay_u;
28 static PRFileDesc *err = NULL;
30 static void Help(void)
31 {
32 PR_fprintf(err, "Usage: -i n | -u n | -h\n");
33 PR_fprintf(err, "\t-i n treat following number as signed integer\n");
34 PR_fprintf(err, "\t-u n treat following number as unsigned integer\n");
35 PR_fprintf(err, "\t-h This message and nothing else\n");
36 } /* Help */
38 static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
39 {
40 Overlay_i si;
41 Overlay_u ui;
42 PLOptStatus os;
43 PRBool bsi = PR_FALSE, bui = PR_FALSE;
44 PLOptState *opt = PL_CreateOptState(argc, argv, "hi:u:");
45 err = PR_GetSpecialFD(PR_StandardError);
47 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
48 {
49 if (PL_OPT_BAD == os) continue;
50 switch (opt->option)
51 {
52 case 'i': /* signed integer */
53 si.i = (PRInt32)atoi(opt->value);
54 bsi = PR_TRUE;
55 break;
56 case 'u': /* unsigned */
57 ui.i = (PRUint32)atoi(opt->value);
58 bui = PR_TRUE;
59 break;
60 case 'h': /* user wants some guidance */
61 default:
62 Help(); /* so give him an earful */
63 return 2; /* but not a lot else */
64 }
65 }
66 PL_DestroyOptState(opt);
68 #if defined(HAVE_LONG_LONG)
69 PR_fprintf(err, "We have long long\n");
70 #else
71 PR_fprintf(err, "We don't have long long\n");
72 #endif
74 if (bsi)
75 {
76 PR_fprintf(err, "Converting %ld: ", si.i);
77 LL_I2L(si.l, si.i);
78 PR_fprintf(err, "%lld\n", si.l);
79 }
81 if (bui)
82 {
83 PR_fprintf(err, "Converting %lu: ", ui.i);
84 LL_I2L(ui.l, ui.i);
85 PR_fprintf(err, "%llu\n", ui.l);
86 }
87 return 0;
89 } /* main */
92 int main(int argc, char **argv)
93 {
94 PRIntn rv;
96 PR_STDIO_INIT();
97 rv = PR_Initialize(RealMain, argc, argv, 0);
98 return rv;
99 } /* main */
101 /* i2l.c */