|
2243 | 2243 | int \funnm{getopt\_long}(\=int \emph{argc}, char * const \emph{argv}[],\\ |
2244 | 2244 | \>const char *\emph{optstring},\\ |
2245 | 2245 | \>const struct option *\emph{longopts},\\ |
2246 | | -\>int *\emph{longindex}); |
| 2246 | +\>int *\emph{longindex}); |
2247 | 2247 | \end{tabbing}} |
2248 | 2248 | ]]]) |
2249 | 2249 | \begin{itemize} |
2250 | 2250 | \item \texttt{optstring} contains short options, |
2251 | 2251 | \texttt{longopts} contains the address of an array of structures for long options |
2252 | | -(last record contains all zeroes) |
| 2252 | +(last record contains all zeroes) |
2253 | 2253 | \item if the function hits a long option, it returns the corresponding |
2254 | 2254 | \texttt{val} or zero (if \texttt{flag} was not \texttt{NULL}), |
2255 | 2255 | otherwise the behavior is the same as \texttt{getopt}. |
|
2259 | 2259 | \end{slide} |
2260 | 2260 |
|
2261 | 2261 | \begin{itemize} |
2262 | | -\item This is slightly modified example from the \texttt{getopt\_long} |
2263 | | -FreeBSD man page: |
2264 | | -ifdef([[[NOSPELLCHECK]]], [[[ |
2265 | | -{\footnotesize |
2266 | | -\begin{verbatim} |
2267 | | -#include <stdio.h> |
2268 | | -#include <getopt.h> |
2269 | | -#include <fcntl.h> |
2270 | | -
|
2271 | | -int ch, fd, daggerset, bflag = 0; |
2272 | | -
|
2273 | | -static struct option longopts[] = { |
2274 | | - { "buffy", no_argument, NULL, 'b' }, |
2275 | | - { "fluoride", required_argument, NULL, 'f' }, |
2276 | | - { "daggerset", no_argument, &daggerset, 1 }, |
2277 | | - { NULL, 0, NULL, 0 }}; |
2278 | | -
|
2279 | | -int main(int argc, char **argv) |
2280 | | -{ |
2281 | | - while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) |
2282 | | - switch (ch) { |
2283 | | - case 'b': |
2284 | | - bflag = 1; break; |
2285 | | - case 'f': |
2286 | | - if ((fd = open(optarg, O_RDONLY, 0)) == -1) |
2287 | | - printf("unable to open %s", optarg); |
2288 | | - break; |
2289 | | - case 0: |
2290 | | - if (daggerset) { |
2291 | | - printf("Buffy will use her dagger to " |
2292 | | - "apply fluoride to dracula's teeth\n"); |
2293 | | - } |
2294 | | - break; |
2295 | | - default: printf("usage: ...\n"); |
2296 | | - } |
2297 | | - argc -= optind; argv += optind; |
2298 | | - return 0; |
2299 | | -} |
2300 | | -\end{verbatim} |
2301 | | -]]]) |
2302 | | -} |
| 2262 | +\item See \example{getopt/getopt\_long.c} |
2303 | 2263 | \end{itemize} |
2304 | 2264 |
|
2305 | 2265 | %%%%% |
|
0 commit comments