The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

option.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Classes

struct  option

Defines

#define N_OPTS   256

Typedefs

typedef option option

Functions

int getoptions (int argc, char **argv, char *opts, option *optv)
char * getoptval (option *optv, char opt, int subopt)


Define Documentation

#define N_OPTS   256
 

Definition at line 20 of file option.h.

Referenced by getoptions(), and main().


Typedef Documentation

typedef struct option option
 


Function Documentation

int getoptions int  argc,
char **  argv,
char *  opts,
option optv
 

Definition at line 21 of file option.c.

References f(), i, and N_OPTS.

Referenced by main().

00026 {
00027     int i;
00028     int optc = N_OPTS;
00029 
00030     memset( (char *)optv, '\0', sizeof( *optv ) * N_OPTS );
00031 
00032     for( i = 0; i < argc; i++ )
00033     {
00034         char *arg;
00035 
00036         if( argv[i][0] != '-' || ( argv[i][1] != '-' && !isalpha( argv[i][1] ) ) )
00037             break;
00038 
00039         if( !optc-- )
00040         {
00041             printf( "too many options (%d max)\n", N_OPTS );
00042             return -1;
00043         }
00044 
00045         for( arg = &argv[i][1]; *arg; arg++ )
00046         {
00047             char *f;
00048 
00049             for( f = opts; *f; f++ )
00050                 if( *f == *arg )
00051                     break;
00052 
00053             if( !*f )
00054             {
00055                 printf( "Invalid option: -%c\n", *arg );
00056                 return -1;
00057             }
00058 
00059             optv->flag = *f;
00060 
00061             if( f[1] != ':' )
00062             {
00063                 optv++->val = "true";
00064             }
00065             else if( arg[1] )
00066             {
00067                 optv++->val = &arg[1];
00068                 break;
00069             }
00070             else if( ++i < argc )
00071             {
00072                 optv++->val = argv[i];
00073                 break;
00074             }
00075             else
00076             {
00077                 printf( "option: -%c needs argument\n", *f );
00078                 return -1;
00079             }
00080         }
00081     }
00082 
00083     return i;
00084 }

Here is the call graph for this function:

char* getoptval option optv,
char  opt,
int  subopt
 

Definition at line 91 of file option.c.

References option::flag, i, and option::val.

Referenced by main().

00095 {
00096         int i;
00097 
00098         for( i = 0; i < N_OPTS; i++, optv++ )
00099             if( optv->flag == opt && !subopt-- )
00100                 return optv->val;
00101 
00102         return 0;
00103 }


Generated on Mon Nov 8 17:08:15 2004 for MPT by  doxygen 1.3.9.1