Skip to content

Commit 042609c

Browse files
author
Vladimir Kotal
committed
translate long options processing
1 parent 2178995 commit 042609c

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

intro.tex

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,81 +2187,81 @@
21872187
\pdfbookmark[1]{getopt\_long}{getoptlong}
21882188

21892189
\begin{slide}
2190-
\sltitle{Dlouhý tvar pøepínaèù}
2190+
\sltitle{Processing long options}
21912191
\setlength{\baselineskip}{0.8\baselineskip}
21922192
\begin{itemize}
2193-
\item poprvé se objevilo v GNU knihovnì \texttt{libiberty}:
2193+
\item first appeared in GNU library \texttt{libiberty}:
21942194
\begin{verbatim}
2195-
--jméno nebo --jméno=hodnota
2195+
--name or --name=value
21962196
\end{verbatim}
2197-
\item argumenty se permutují tak, aby pøepínaèe byly na zaèátku, napø.
2198-
\verb#ls * -l# je toté¾ jako \verb#ls -l *#, standardní chování lze docílit
2199-
nastavením promìnné \verb#POSIXLY_CORRECT#.
2200-
\item zpracovávají se funkcí \texttt{\funnm{getopt\_long}()}, která pou¾ívá
2201-
pole struktur popisujících jednotlivé pøepínaèe:
2197+
\item the arguments are permuted so that e.g.
2198+
\verb#ls * -l# is the same as \verb#ls -l *#, standard behavior can be enabled
2199+
by setting the \verb#POSIXLY_CORRECT# environment variable.
2200+
\item the long options are processed using the \texttt{\funnm{getopt\_long}()}
2201+
function using these variables and structures:
22022202
{\tt
22032203
\begin{tabbing}
22042204
stru\=ct \funnm{option} \{\\
2205-
\>const char *name; \textrm{/* jméno pøepínaèe */} \\
2206-
\>int has\_arg; \textrm{/* hodnota: ano, ne, \emsl{volitelnì} */} \\
2207-
\>int *flag; \textrm{/*~}\=\textrm{kdy¾ je \texttt{NULL}, funkce vrací
2208-
\texttt{val}, jinak vrací 0}\\\>\>\textrm{a dá \texttt{val} do \texttt{*flag}
2209-
*/} \\
2210-
\>int val; \textrm{/* návratová hodnota */} \\
2205+
\>const char *name; \textrm{/* name of the option */} \\
2206+
\>int has\_arg; \textrm{/* value: yes, no, \emsl{optional} */} \\
2207+
\>int *flag; \textrm{/*~}\=\textrm{if \texttt{NULL}, the function returns
2208+
\texttt{val}}, \\
2209+
\>\>\textrm{otherwise returns 0}
2210+
\textrm{and }\texttt{*flag = val}\textrm{ */} \\
2211+
\>int val; \textrm{/* return value */} \\
22112212
\};
22122213
\end{tabbing}}
22132214
\end{itemize}
22142215
\end{slide}
22152216

2216-
verze jak se objevila ve FreeBSD (funkce \textrm{getopt\_long} není
2217-
standarizovaná), má následující vlastnosti:
2218-
2219-
\begin{itemize}
2220-
\item pokud v¹echny dlouhé pøepínaèe mají nastaveny krátkou variantu
2221-
ve \texttt{val}, je chování \texttt{getopt\_long} kompatibilní s
2222-
\texttt{getopt}
2223-
\item je mo¾né zadávat argument k dlouhému pøepínaèi i s mezerou
2224-
(na\-pøí\-klad \texttt{--color~green})
2225-
\item pokud je nastaven \texttt{flag}, tak \texttt{getopt\_long}
2226-
vrací 0, èím¾ se tyto dlouhé pøe\-\-na\-èe bez krátké varianty zpracují v
2227-
jedné vìtvi pøíkazu \texttt{case}
2228-
\item existuje i volání \texttt{getopt\_long\_only}, které povoluje
2229-
i dlouhé pøepínaèe uvozené jednou uvozovkou (\texttt{-option})
2230-
\item funkci \texttt{getopt\_long} je mo¾né pou¾ívat dvìmi zpùsoby.
2231-
První zpùsob je, ¾e ka¾dý dlouhý pøepínaè má korespondující krátký
2232-
-- takto lze jednodu¹e pøidat dlouhé pøepínaèe do existujícího
2233-
programu a je \emsl{kompatibilní s getopt}. Druhý zpùsob umo¾òuje
2234-
mít samostatné dlouhé pøepínaèe. V tom pøípadì funkce vrací v¾dy 0
2235-
(nekompatibilita s \texttt{getopt}) a promìnná \texttt{*flag} se
2236-
nastaví na \texttt{val}.
2237-
\item na konkrétním pøíkladu na následující stránce je vidìt, jak to
2238-
celé funguje
2217+
The version that appeared in FreeBSD (\textrm{getopt\_long} is not part
2218+
of the standard), has the following properties:
2219+
2220+
\begin{itemize}
2221+
\item If all long options have the short variant set in \texttt{val}, the
2222+
behavior of \texttt{getopt\_long} is compatible with that of \texttt{getopt}.
2223+
\item It is possible to specify value of long option also with a space
2224+
(for example \texttt{--color~green}).
2225+
\item If \texttt{flag} is set, \texttt{getopt\_long} returns 0, which makes
2226+
these long options without short variant processed in single branch of
2227+
\texttt{case}.
2228+
\item There is also \texttt{getopt\_long\_only}, that allows long options
2229+
to begin with single dash (\texttt{-option}).
2230+
\item The \texttt{getopt\_long} function is possible to use in two ways.
2231+
The first way is that each long option has a corresponding short variant
2232+
-- this way it is possible to introduce long options to existing program
2233+
in \emsl{getopt compatible} way. The second way makes it possible to have
2234+
independent long options. In this case the function returns always 0
2235+
(non-compatible with \texttt{getopt}) and the \texttt{*flag} variable
2236+
is set to \texttt{val}.
2237+
\item The next slide demonstrates how it works.
22392238
\end{itemize}
22402239

22412240
%%%%%
22422241

22432242
\begin{slide}
2244-
\sltitle{Dlouhé pøepínaèe (pokraèování)}
2243+
\sltitle{Processing long options (cont.)}
22452244
{\tt\begin{tabbing}
22462245
int \funnm{getopt\_long}(\=int \emph{argc}, char * const \emph{argv}[],\\
22472246
\>const char *\emph{optstring},\\
22482247
\>const struct option *\emph{longopts},\\
22492248
\>int *\emph{longindex});
22502249
\end{tabbing}}
22512250
\begin{itemize}
2252-
\item \texttt{optstring} obsahuje jednopísmenné pøepínaèe,
2253-
\texttt{longopts} obsahuje adresu pole struktur pro dlouhé pøepínaèe
2254-
(poslední záznam pole obsahuje samé nuly)
2255-
\item pokud funkce narazí na dlouhý pøepínaè, vrací odpovídající
2256-
\texttt{val} nebo nulu (pokud \texttt{flag} nebyl \texttt{NULL}),
2257-
jinak je chování shodné s \texttt{getopt}.
2258-
\item do \texttt{*longindex} (kdy¾ není \texttt{NULL}) dá navíc
2259-
in{}dex nalezeného pøepínaèe v \texttt{longopts}.
2251+
\item \texttt{optstring} contains short options,
2252+
\texttt{longopts} contains address of array of structures for long options
2253+
(last record contains all zeroes)
2254+
\item if the function hits a long option, it returns corresponding
2255+
\texttt{val} or zero (if \texttt{flag} was not \texttt{NULL}),
2256+
otherwise the behavior is the same as \texttt{getopt}.
2257+
\item it will also put the index of the found option in \texttt{longopts}
2258+
to \texttt{*longindex} (if not \texttt{NULL})
22602259
\end{itemize}
22612260
\end{slide}
22622261

22632262
\begin{itemize}
2264-
\item toto je upravený pøíklad z manuálové stránky na FreeBSD:
2263+
\item This is slightly modified example from the \texttt{getopt\_long}
2264+
FreeBSD man page:
22652265
{\footnotesize
22662266
\begin{verbatim}
22672267
#include <stdio.h>

0 commit comments

Comments
 (0)