michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: michael@0: #include "prio.h" michael@0: #include "prinit.h" michael@0: #include "prprf.h" michael@0: #include "prlong.h" michael@0: michael@0: #include "plerror.h" michael@0: #include "plgetopt.h" michael@0: michael@0: typedef union Overlay_i michael@0: { michael@0: PRInt32 i; michael@0: PRInt64 l; michael@0: } Overlay_i; michael@0: michael@0: typedef union Overlay_u michael@0: { michael@0: PRUint32 i; michael@0: PRUint64 l; michael@0: } Overlay_u; michael@0: michael@0: static PRFileDesc *err = NULL; michael@0: michael@0: static void Help(void) michael@0: { michael@0: PR_fprintf(err, "Usage: -i n | -u n | -h\n"); michael@0: PR_fprintf(err, "\t-i n treat following number as signed integer\n"); michael@0: PR_fprintf(err, "\t-u n treat following number as unsigned integer\n"); michael@0: PR_fprintf(err, "\t-h This message and nothing else\n"); michael@0: } /* Help */ michael@0: michael@0: static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv) michael@0: { michael@0: Overlay_i si; michael@0: Overlay_u ui; michael@0: PLOptStatus os; michael@0: PRBool bsi = PR_FALSE, bui = PR_FALSE; michael@0: PLOptState *opt = PL_CreateOptState(argc, argv, "hi:u:"); michael@0: err = PR_GetSpecialFD(PR_StandardError); michael@0: michael@0: while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) michael@0: { michael@0: if (PL_OPT_BAD == os) continue; michael@0: switch (opt->option) michael@0: { michael@0: case 'i': /* signed integer */ michael@0: si.i = (PRInt32)atoi(opt->value); michael@0: bsi = PR_TRUE; michael@0: break; michael@0: case 'u': /* unsigned */ michael@0: ui.i = (PRUint32)atoi(opt->value); michael@0: bui = PR_TRUE; michael@0: break; michael@0: case 'h': /* user wants some guidance */ michael@0: default: michael@0: Help(); /* so give him an earful */ michael@0: return 2; /* but not a lot else */ michael@0: } michael@0: } michael@0: PL_DestroyOptState(opt); michael@0: michael@0: #if defined(HAVE_LONG_LONG) michael@0: PR_fprintf(err, "We have long long\n"); michael@0: #else michael@0: PR_fprintf(err, "We don't have long long\n"); michael@0: #endif michael@0: michael@0: if (bsi) michael@0: { michael@0: PR_fprintf(err, "Converting %ld: ", si.i); michael@0: LL_I2L(si.l, si.i); michael@0: PR_fprintf(err, "%lld\n", si.l); michael@0: } michael@0: michael@0: if (bui) michael@0: { michael@0: PR_fprintf(err, "Converting %lu: ", ui.i); michael@0: LL_I2L(ui.l, ui.i); michael@0: PR_fprintf(err, "%llu\n", ui.l); michael@0: } michael@0: return 0; michael@0: michael@0: } /* main */ michael@0: michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRIntn rv; michael@0: michael@0: PR_STDIO_INIT(); michael@0: rv = PR_Initialize(RealMain, argc, argv, 0); michael@0: return rv; michael@0: } /* main */ michael@0: michael@0: /* i2l.c */