1 #include "args.ih"
2 
3 static char *str;
4 static int option;
5 
6 // The full string is a string containing all the single-letter options that
7 // were specified. E.g., DDvD if -D -D -v -D was specified. When called with a
8 // non-0 argument str and searchStr are (re)initialized to the beginning of
9 // the string. Then, and at each subsequent call using a zero-arg the saved
10 // opchar is searched from where searchStr points. Following this search
11 // searchStr is incremented, unless it points to the option string's 0-byte
12 // The location of the optchar in str is then used as index in the array of
13 // args.d_optarg, returning the associated value.
14 
args_multiarg(int optchar)15 char const *args_multiarg(int optchar)
16 {
17     if (optchar)                                    // new option:
18     {
19         if (!str)
20             str = (char *)string_str(&args.d_option); // use full string
21 
22         option = optchar;                           // save the option char
23     }
24 
25     register char *pos = strchr(str, option);
26 
27     if (pos)
28     {
29         size_t idx = pos - str;
30         *pos = ' ';                                 // this option has now
31                                                     // been processed.
32 
33         return args.d_optarg[idx];                  // return optionstr.
34     }
35 
36     return PFAILED;                                 // or return PFAILED
37                                                     // in which case there was
38                                                     // no option argument
39 }
40