Skip to content

Commit ddf587d

Browse files
author
Vladimir Kotal
committed
move getopt_long() example to src repo
1 parent 120e5a6 commit ddf587d

File tree

1 file changed

+3
-43
lines changed

1 file changed

+3
-43
lines changed

intro.tex

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,13 +2243,13 @@
22432243
int \funnm{getopt\_long}(\=int \emph{argc}, char * const \emph{argv}[],\\
22442244
\>const char *\emph{optstring},\\
22452245
\>const struct option *\emph{longopts},\\
2246-
\>int *\emph{longindex});
2246+
\>int *\emph{longindex});
22472247
\end{tabbing}}
22482248
]]])
22492249
\begin{itemize}
22502250
\item \texttt{optstring} contains short options,
22512251
\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)
22532253
\item if the function hits a long option, it returns the corresponding
22542254
\texttt{val} or zero (if \texttt{flag} was not \texttt{NULL}),
22552255
otherwise the behavior is the same as \texttt{getopt}.
@@ -2259,47 +2259,7 @@
22592259
\end{slide}
22602260

22612261
\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}
23032263
\end{itemize}
23042264

23052265
%%%%%

0 commit comments

Comments
 (0)