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 <stdlib.h>
7
8 #include "prio.h"
9 #include "prinit.h"
10 #include "prprf.h"
11 #include "prlong.h"
12
13 #include "plerror.h"
14 #include "plgetopt.h"
15
16 typedef union Overlay_i
17 {
18 PRInt32 i;
19 PRInt64 l;
20 } Overlay_i;
21
22 typedef union Overlay_u
23 {
24 PRUint32 i;
25 PRUint64 l;
26 } Overlay_u;
27
28 static PRFileDesc *err = NULL;
29
Help(void)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 */
37
RealMain(PRIntn argc,char ** argv)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);
46
47 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
48 {
49 if (PL_OPT_BAD == os) {
50 continue;
51 }
52 switch (opt->option)
53 {
54 case 'i': /* signed integer */
55 si.i = (PRInt32)atoi(opt->value);
56 bsi = PR_TRUE;
57 break;
58 case 'u': /* unsigned */
59 ui.i = (PRUint32)atoi(opt->value);
60 bui = PR_TRUE;
61 break;
62 case 'h': /* user wants some guidance */
63 default:
64 Help(); /* so give him an earful */
65 return 2; /* but not a lot else */
66 }
67 }
68 PL_DestroyOptState(opt);
69
70 #if defined(HAVE_LONG_LONG)
71 PR_fprintf(err, "We have long long\n");
72 #else
73 PR_fprintf(err, "We don't have long long\n");
74 #endif
75
76 if (bsi)
77 {
78 PR_fprintf(err, "Converting %ld: ", si.i);
79 LL_I2L(si.l, si.i);
80 PR_fprintf(err, "%lld\n", si.l);
81 }
82
83 if (bui)
84 {
85 PR_fprintf(err, "Converting %lu: ", ui.i);
86 LL_I2L(ui.l, ui.i);
87 PR_fprintf(err, "%llu\n", ui.l);
88 }
89 return 0;
90
91 } /* main */
92
93
main(int argc,char ** argv)94 int main(int argc, char **argv)
95 {
96 PRIntn rv;
97
98 PR_STDIO_INIT();
99 rv = PR_Initialize(RealMain, argc, argv, 0);
100 return rv;
101 } /* main */
102
103 /* i2l.c */
104