tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

getopt.c (1414B)


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