test_getopt_long.c
Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
00003 All rights reserved.
00004 
00005 This file is part of the VLFeat library and is made available under
00006 the terms of the BSD license (see the COPYING file).
00007 */
00008 
00009 #include <stdio.h>
00010 #include <assert.h>
00011 
00012 #include <vl/getopt_long.h>
00013 
00014 int daggerset;
00015 
00016 /* options descriptor */
00017 static struct option longopts[] = {
00018   { "help",         no_argument,            0,           'h' },
00019   { "buffy",        no_argument,            0,           'b' },
00020   { "fluoride",     required_argument,      0,           'f' },
00021   { "daggerset",    no_argument,            &daggerset,   1000  },
00022   { "daggerunset",  no_argument,            &daggerset,   1001  },
00023   { "spike",        optional_argument,      0,            1002  },
00024   { NULL,           0,                      0,            0  }
00025 };
00026 
00027 int
00028 main (int argc, char *argv[])
00029 {
00030   int ch ;
00031 
00032   printf("*** parsing options: start\n") ;
00033 
00034   while ((ch = getopt_long(argc, argv, "hbf:", longopts, 0)) != -1) {
00035 
00036     switch (ch) {
00037 
00038     case 'h':
00039         printf("test_getopt_long: test VLFeat implementation of this function.\n"
00040                " --help -h      this message\n"
00041                " --buffy -b     option with no arguments\n"
00042                " --fluoride -f  option with required argument\n"
00043                " --daggerset    auto option with no arguments\n"
00044                " --daggerrunset auto option with no argument\n"
00045                " --spike        long option with optional argument\n") ;
00046         break;
00047 
00048     case 'b':
00049       printf("option `b' or `buffy'\n") ;
00050       break;
00051 
00052     case 'f':
00053       printf("option `f' or `flouride' with arg `%s'\n", optarg) ;
00054       break ;
00055 
00056     case 1002 :
00057       printf("option `spike' with arg `%s'\n", optarg) ;
00058       break ;
00059 
00060     case 0:
00061       printf("automatic longoption (daggerset=%d)\n", daggerset) ;
00062       break ;
00063 
00064     case  '?' :
00065       printf("illegal option or missing argument\n") ;
00066       break ;
00067 
00068     case ':'  :
00069       printf("illegal option\n") ;
00070       break ;
00071 
00072     default:
00073       abort() ;
00074     }
00075   }
00076 
00077   printf("*** parsing options: end\n");
00078   {
00079     int i ;
00080     for(i = optind ; i < argc ; ++i)
00081                 printf("non-option: '%s'\n", argv[i]) ;
00082   }
00083 
00084   return 0 ;
00085 }


libvlfeat
Author(s): Andrea Vedaldi
autogenerated on Thu Jun 6 2019 20:25:51