2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
9 #include "vg_platform.h"
15 * short options | -a value
16 * multi-set options | -ab value
18 * long gnu options | --long-value=test
19 * standard agument | regular_thing
22 static int vg_argi
= 1;
23 static int vg_argj
= 1;
24 static int vg_argc
= 0;
25 static int vg_consume_next
= 0;
26 static char **vg_argv
;
28 /* Will return 0 if exhausted */
29 int vg_argp( int argc
, char *argv
[] )
34 static int delta_i
= 0;
35 static int delta_j
= 0;
37 if( vg_argj
!= 1 && !vg_argv
[ vg_argi
][ vg_argj
] )
52 if( (delta_i
== vg_argi
) && (delta_j
== vg_argj
) )
54 char *cur
= &vg_argv
[ vg_argi
][ vg_argj
];
58 vg_error( "Unknown opt '-%c'\n", *cur
);
62 vg_error( "Unknown opt '--%s'\n", cur
+ 1 );
74 /* Example: see if -c is set */
77 char *carg
= vg_argv
[ vg_argi
];
84 if( carg
[ vg_argj
] == c
)
95 /* Example: get -c *value* */
96 char *vg_opt_arg( char c
)
100 if( vg_argi
< vg_argc
-1 )
102 if( vg_argv
[ vg_argi
+ 1 ][0] != '-' )
105 return vg_argv
[ vg_argi
+ 1 ];
109 vg_error( "Option '%c' requires argument!\n", c
);
116 /* Example see if --big is set */
117 int vg_long_opt( char *name
)
119 char *carg
= vg_argv
[ vg_argi
];
125 if( !strcmp( name
, carg
+2 ) )
136 /* Example: get --big=value */
137 char *vg_long_opt_arg( char *name
)
139 char *carg
= vg_argv
[ vg_argi
];
145 int k
= 2; int set
= 0;
148 if( carg
[ k
] == '=' )
157 if( !strncmp( name
, carg
+2, k
-2 ) )
168 vg_error( "Long option '%s' requires argument\n", name
);
177 /* Example: get regular_thing */
180 char *carg
= vg_argv
[ vg_argi
];