Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include <stdlib.h> |
michael@0 | 7 | |
michael@0 | 8 | #include "prio.h" |
michael@0 | 9 | #include "prinit.h" |
michael@0 | 10 | #include "prprf.h" |
michael@0 | 11 | #include "prlong.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "plerror.h" |
michael@0 | 14 | #include "plgetopt.h" |
michael@0 | 15 | |
michael@0 | 16 | typedef union Overlay_i |
michael@0 | 17 | { |
michael@0 | 18 | PRInt32 i; |
michael@0 | 19 | PRInt64 l; |
michael@0 | 20 | } Overlay_i; |
michael@0 | 21 | |
michael@0 | 22 | typedef union Overlay_u |
michael@0 | 23 | { |
michael@0 | 24 | PRUint32 i; |
michael@0 | 25 | PRUint64 l; |
michael@0 | 26 | } Overlay_u; |
michael@0 | 27 | |
michael@0 | 28 | static PRFileDesc *err = NULL; |
michael@0 | 29 | |
michael@0 | 30 | static void Help(void) |
michael@0 | 31 | { |
michael@0 | 32 | PR_fprintf(err, "Usage: -i n | -u n | -h\n"); |
michael@0 | 33 | PR_fprintf(err, "\t-i n treat following number as signed integer\n"); |
michael@0 | 34 | PR_fprintf(err, "\t-u n treat following number as unsigned integer\n"); |
michael@0 | 35 | PR_fprintf(err, "\t-h This message and nothing else\n"); |
michael@0 | 36 | } /* Help */ |
michael@0 | 37 | |
michael@0 | 38 | static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv) |
michael@0 | 39 | { |
michael@0 | 40 | Overlay_i si; |
michael@0 | 41 | Overlay_u ui; |
michael@0 | 42 | PLOptStatus os; |
michael@0 | 43 | PRBool bsi = PR_FALSE, bui = PR_FALSE; |
michael@0 | 44 | PLOptState *opt = PL_CreateOptState(argc, argv, "hi:u:"); |
michael@0 | 45 | err = PR_GetSpecialFD(PR_StandardError); |
michael@0 | 46 | |
michael@0 | 47 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
michael@0 | 48 | { |
michael@0 | 49 | if (PL_OPT_BAD == os) continue; |
michael@0 | 50 | switch (opt->option) |
michael@0 | 51 | { |
michael@0 | 52 | case 'i': /* signed integer */ |
michael@0 | 53 | si.i = (PRInt32)atoi(opt->value); |
michael@0 | 54 | bsi = PR_TRUE; |
michael@0 | 55 | break; |
michael@0 | 56 | case 'u': /* unsigned */ |
michael@0 | 57 | ui.i = (PRUint32)atoi(opt->value); |
michael@0 | 58 | bui = PR_TRUE; |
michael@0 | 59 | break; |
michael@0 | 60 | case 'h': /* user wants some guidance */ |
michael@0 | 61 | default: |
michael@0 | 62 | Help(); /* so give him an earful */ |
michael@0 | 63 | return 2; /* but not a lot else */ |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | PL_DestroyOptState(opt); |
michael@0 | 67 | |
michael@0 | 68 | #if defined(HAVE_LONG_LONG) |
michael@0 | 69 | PR_fprintf(err, "We have long long\n"); |
michael@0 | 70 | #else |
michael@0 | 71 | PR_fprintf(err, "We don't have long long\n"); |
michael@0 | 72 | #endif |
michael@0 | 73 | |
michael@0 | 74 | if (bsi) |
michael@0 | 75 | { |
michael@0 | 76 | PR_fprintf(err, "Converting %ld: ", si.i); |
michael@0 | 77 | LL_I2L(si.l, si.i); |
michael@0 | 78 | PR_fprintf(err, "%lld\n", si.l); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | if (bui) |
michael@0 | 82 | { |
michael@0 | 83 | PR_fprintf(err, "Converting %lu: ", ui.i); |
michael@0 | 84 | LL_I2L(ui.l, ui.i); |
michael@0 | 85 | PR_fprintf(err, "%llu\n", ui.l); |
michael@0 | 86 | } |
michael@0 | 87 | return 0; |
michael@0 | 88 | |
michael@0 | 89 | } /* main */ |
michael@0 | 90 | |
michael@0 | 91 | |
michael@0 | 92 | int main(int argc, char **argv) |
michael@0 | 93 | { |
michael@0 | 94 | PRIntn rv; |
michael@0 | 95 | |
michael@0 | 96 | PR_STDIO_INIT(); |
michael@0 | 97 | rv = PR_Initialize(RealMain, argc, argv, 0); |
michael@0 | 98 | return rv; |
michael@0 | 99 | } /* main */ |
michael@0 | 100 | |
michael@0 | 101 | /* i2l.c */ |