nsprpub/lib/tests/getopt.c

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include <stdio.h>
michael@0 6 #include <string.h>
michael@0 7 #include <stdlib.h>
michael@0 8
michael@0 9 #include "nspr.h"
michael@0 10 #include "plgetopt.h"
michael@0 11
michael@0 12
michael@0 13
michael@0 14 static const PLLongOpt optArray[] = {
michael@0 15 { "longa", 'a' , PR_TRUE },
michael@0 16 { "longb", 'b' , PR_TRUE },
michael@0 17 { "longc", 'c' , PR_FALSE },
michael@0 18 { "longd", 'd' | 0x100, PR_TRUE },
michael@0 19 { "longe", 'e' | 0x100, PR_FALSE },
michael@0 20 { NULL, }
michael@0 21 };
michael@0 22
michael@0 23 int
michael@0 24 main(int argc, char **argv)
michael@0 25 {
michael@0 26 PLOptState *opt;
michael@0 27 PLOptStatus ostat;
michael@0 28
michael@0 29 opt = PL_CreateLongOptState(argc, argv, "a:b:c", optArray);
michael@0 30
michael@0 31 while (PL_OPT_OK == (ostat = PL_GetNextOpt(opt))) {
michael@0 32 if (opt->option == 0 && opt->longOptIndex < 0)
michael@0 33 printf("Positional parameter: \"%s\"\n", opt->value);
michael@0 34 else
michael@0 35 printf("%s option: %x (\'%c\', index %d), argument: \"%s\"\n",
michael@0 36 (ostat == PL_OPT_BAD) ? "BAD" : "GOOD",
michael@0 37 opt->longOption, opt->option ? opt->option : ' ',
michael@0 38 opt->longOptIndex, opt->value);
michael@0 39
michael@0 40 }
michael@0 41 printf("last result was %s\n", (ostat == PL_OPT_BAD) ? "BAD" : "EOL");
michael@0 42 PL_DestroyOptState(opt);
michael@0 43 return 0;
michael@0 44 }

mercurial