]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/getopt-min.c
778258d52b9f9790e7d34dc33a45415e7527423c
2 #include <avr/pgmspace.h>
6 * Minimum getopt, original version was:
10 getopt -- public domain version of standard System V routine
12 Strictly enforces the System V Command Syntax Standard;
13 provided by D A Gwyn of BRL for generic ANSI C implementations
15 /* $Id: getopt.c,v 1.2 1992/12/07 11:12:52 nickc Exp $ */
19 int optind
= 1; /* next argv[] index */
20 char *optarg
; /* option parameter if any */
24 getopt( /* returns letter, '?', EOF */
25 int argc
, /* argument count from main */
26 char *const argv
[], /* argument vector from main */
27 const FLASH
char *optstring
) /* allowed args, e.g. "ab:c" */
29 static int sp
= 1; /* position within argument */
30 int osp
; /* saved `sp' for param test */
31 int c
; /* option letter */
32 const FLASH
char *cp
; /* -> option in `optstring' */
36 if ( sp
== 1 ) /* fresh argument */
38 if ( optind
>= argc
/* no more arguments */
39 || argv
[optind
][0] != '-' /* no more options */
40 || argv
[optind
][1] == '\0' /* not option; stdin */
45 c
= argv
[optind
][sp
]; /* option letter */
46 osp
= sp
++; /* get ready for next letter */
48 if ( argv
[optind
][sp
] == '\0' ) /* end of argument */
50 ++optind
; /* get ready for next try */
51 sp
= 1; /* beginning of next argument */
54 if ( c
== ':' /* optstring syntax conflict */
55 || (cp
= strchr_P( optstring
, c
)) == NULL
/* not found */
59 if ( cp
[1] == ':' ) /* option takes parameter */
64 if ( sp
!= 1 ) /* reset by end of argument */
70 optarg
= argv
[optind
]; /* make parameter available */
71 ++optind
; /* skip over parameter */