~ubuntu-branches/ubuntu/natty/libofx/natty

« back to all changes in this revision

Viewing changes to doc/html/fx-0_87_80_2lib_2getopt1_8c-source.html

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2005-11-29 00:12:00 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051129001200-aplj8zbj80f68xby
Tags: 1:0.8.0-9
Generate autotools using Debian libtool (rerun libtoolize --copy
--force, aclocal-1.9, autoconf). (Closes: #341190)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
 
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3
 
<title>LibOFX: getopt1.c Source File</title>
4
 
<link href="doxygen.css" rel="stylesheet" type="text/css">
5
 
</head><body>
6
 
<!-- Generated by Doxygen 1.3.7 -->
7
 
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div>
8
 
<h1>getopt1.c</h1><pre class="fragment"><div>00001 <span class="comment">/* getopt_long and getopt_long_only entry points for GNU getopt.</span>
9
 
00002 <span class="comment">   Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98</span>
10
 
00003 <span class="comment">     Free Software Foundation, Inc.</span>
11
 
00004 <span class="comment">   This file is part of the GNU C Library.</span>
12
 
00005 <span class="comment"></span>
13
 
00006 <span class="comment">   The GNU C Library is free software; you can redistribute it and/or</span>
14
 
00007 <span class="comment">   modify it under the terms of the GNU Lesser General Public</span>
15
 
00008 <span class="comment">   License as published by the Free Software Foundation; either</span>
16
 
00009 <span class="comment">   version 2.1 of the License, or (at your option) any later version.</span>
17
 
00010 <span class="comment"></span>
18
 
00011 <span class="comment">   The GNU C Library is distributed in the hope that it will be useful,</span>
19
 
00012 <span class="comment">   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
20
 
00013 <span class="comment">   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
21
 
00014 <span class="comment">   Lesser General Public License for more details.</span>
22
 
00015 <span class="comment"></span>
23
 
00016 <span class="comment">   You should have received a copy of the GNU Lesser General Public</span>
24
 
00017 <span class="comment">   License along with the GNU C Library; if not, write to the Free</span>
25
 
00018 <span class="comment">   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA</span>
26
 
00019 <span class="comment">   02111-1307 USA.  */</span>
27
 
00020 
28
 
00021 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
29
 
00022 <span class="preprocessor"></span><span class="preprocessor">#include &lt;config.h&gt;</span>
30
 
00023 <span class="preprocessor">#endif</span>
31
 
00024 <span class="preprocessor"></span>
32
 
00025 <span class="preprocessor">#include "getopt.h"</span>
33
 
00026 
34
 
00027 <span class="preprocessor">#if !defined __STDC__ || !__STDC__</span>
35
 
00028 <span class="preprocessor"></span><span class="comment">/* This is a separate conditional since some stdc systems</span>
36
 
00029 <span class="comment">   reject `defined (const)'.  */</span>
37
 
00030 <span class="preprocessor">#ifndef const</span>
38
 
00031 <span class="preprocessor"></span><span class="preprocessor">#define const</span>
39
 
00032 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
40
 
00033 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
41
 
00034 <span class="preprocessor"></span>
42
 
00035 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
43
 
00036 
44
 
00037 <span class="comment">/* Comment out all this code if we are using the GNU C Library, and are not</span>
45
 
00038 <span class="comment">   actually compiling the library itself.  This code is part of the GNU C</span>
46
 
00039 <span class="comment">   Library, but also included in many other GNU distributions.  Compiling</span>
47
 
00040 <span class="comment">   and linking in this code is a waste when using the GNU C library</span>
48
 
00041 <span class="comment">   (especially if it is a shared library).  Rather than having every GNU</span>
49
 
00042 <span class="comment">   program understand `configure --with-gnu-libc' and omit the object files,</span>
50
 
00043 <span class="comment">   it is simpler to just do this in the source for each such file.  */</span>
51
 
00044 
52
 
00045 <span class="preprocessor">#define GETOPT_INTERFACE_VERSION 2</span>
53
 
00046 <span class="preprocessor"></span><span class="preprocessor">#if !defined _LIBC &amp;&amp; defined __GLIBC__ &amp;&amp; __GLIBC__ &gt;= 2</span>
54
 
00047 <span class="preprocessor"></span><span class="preprocessor">#include &lt;gnu-versions.h&gt;</span>
55
 
00048 <span class="preprocessor">#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION</span>
56
 
00049 <span class="preprocessor"></span><span class="preprocessor">#define ELIDE_CODE</span>
57
 
00050 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
58
 
00051 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
59
 
00052 <span class="preprocessor"></span>
60
 
00053 <span class="preprocessor">#ifndef ELIDE_CODE</span>
61
 
00054 <span class="preprocessor"></span>
62
 
00055 
63
 
00056 <span class="comment">/* This needs to come after some library #include</span>
64
 
00057 <span class="comment">   to get __GNU_LIBRARY__ defined.  */</span>
65
 
00058 <span class="preprocessor">#ifdef __GNU_LIBRARY__</span>
66
 
00059 <span class="preprocessor"></span><span class="preprocessor">#include &lt;stdlib.h&gt;</span>
67
 
00060 <span class="preprocessor">#endif</span>
68
 
00061 <span class="preprocessor"></span>
69
 
00062 <span class="preprocessor">#ifndef NULL</span>
70
 
00063 <span class="preprocessor"></span><span class="preprocessor">#define NULL 0</span>
71
 
00064 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
72
 
00065 <span class="preprocessor"></span>
73
 
00066 <span class="keywordtype">int</span>
74
 
00067 getopt_long (argc, argv, options, long_options, opt_index)
75
 
00068      int argc;
76
 
00069      <span class="keywordtype">char</span> *const *argv;
77
 
00070      const <span class="keywordtype">char</span> *options;
78
 
00071      const struct option *long_options;
79
 
00072      <span class="keywordtype">int</span> *opt_index;
80
 
00073 {
81
 
00074   <span class="keywordflow">return</span> _getopt_internal (argc, argv, options, long_options, opt_index, 0);
82
 
00075 }
83
 
00076 
84
 
00077 <span class="comment">/* Like getopt_long, but '-' as well as '--' can indicate a long option.</span>
85
 
00078 <span class="comment">   If an option that starts with '-' (not '--') doesn't match a long option,</span>
86
 
00079 <span class="comment">   but does match a short option, it is parsed as a short option</span>
87
 
00080 <span class="comment">   instead.  */</span>
88
 
00081 
89
 
00082 <span class="keywordtype">int</span>
90
 
00083 getopt_long_only (argc, argv, options, long_options, opt_index)
91
 
00084      int argc;
92
 
00085      <span class="keywordtype">char</span> *const *argv;
93
 
00086      const <span class="keywordtype">char</span> *options;
94
 
00087      const struct option *long_options;
95
 
00088      <span class="keywordtype">int</span> *opt_index;
96
 
00089 {
97
 
00090   <span class="keywordflow">return</span> _getopt_internal (argc, argv, options, long_options, opt_index, 1);
98
 
00091 }
99
 
00092 
100
 
00093 
101
 
00094 <span class="preprocessor">#endif  </span><span class="comment">/* Not ELIDE_CODE.  */</span>
102
 
00095 
103
 
00096 <span class="preprocessor">#ifdef TEST</span>
104
 
00097 <span class="preprocessor"></span>
105
 
00098 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
106
 
00099 
107
 
00100 <span class="keywordtype">int</span>
108
 
00101 <a class="code" href="ofxdump_8cpp.html#a5">main</a> (argc, argv)
109
 
00102      int argc;
110
 
00103      <span class="keywordtype">char</span> **argv;
111
 
00104 {
112
 
00105   <span class="keywordtype">int</span> c;
113
 
00106   <span class="keywordtype">int</span> digit_optind = 0;
114
 
00107 
115
 
00108   <span class="keywordflow">while</span> (1)
116
 
00109     {
117
 
00110       <span class="keywordtype">int</span> this_option_optind = optind ? optind : 1;
118
 
00111       <span class="keywordtype">int</span> option_index = 0;
119
 
00112       <span class="keyword">static</span> <span class="keyword">struct </span>option long_options[] =
120
 
00113       {
121
 
00114         {<span class="stringliteral">"add"</span>, 1, 0, 0},
122
 
00115         {<span class="stringliteral">"append"</span>, 0, 0, 0},
123
 
00116         {<span class="stringliteral">"delete"</span>, 1, 0, 0},
124
 
00117         {<span class="stringliteral">"verbose"</span>, 0, 0, 0},
125
 
00118         {<span class="stringliteral">"create"</span>, 0, 0, 0},
126
 
00119         {<span class="stringliteral">"file"</span>, 1, 0, 0},
127
 
00120         {0, 0, 0, 0}
128
 
00121       };
129
 
00122 
130
 
00123       c = getopt_long (argc, argv, <span class="stringliteral">"abc:d:0123456789"</span>,
131
 
00124                        long_options, &amp;option_index);
132
 
00125       <span class="keywordflow">if</span> (c == -1)
133
 
00126         <span class="keywordflow">break</span>;
134
 
00127 
135
 
00128       <span class="keywordflow">switch</span> (c)
136
 
00129         {
137
 
00130         <span class="keywordflow">case</span> 0:
138
 
00131           printf (<span class="stringliteral">"option %s"</span>, long_options[option_index].name);
139
 
00132           <span class="keywordflow">if</span> (optarg)
140
 
00133             printf (<span class="stringliteral">" with arg %s"</span>, optarg);
141
 
00134           printf (<span class="stringliteral">"\n"</span>);
142
 
00135           <span class="keywordflow">break</span>;
143
 
00136 
144
 
00137         <span class="keywordflow">case</span> <span class="charliteral">'0'</span>:
145
 
00138         <span class="keywordflow">case</span> <span class="charliteral">'1'</span>:
146
 
00139         <span class="keywordflow">case</span> <span class="charliteral">'2'</span>:
147
 
00140         <span class="keywordflow">case</span> <span class="charliteral">'3'</span>:
148
 
00141         <span class="keywordflow">case</span> <span class="charliteral">'4'</span>:
149
 
00142         <span class="keywordflow">case</span> <span class="charliteral">'5'</span>:
150
 
00143         <span class="keywordflow">case</span> <span class="charliteral">'6'</span>:
151
 
00144         <span class="keywordflow">case</span> <span class="charliteral">'7'</span>:
152
 
00145         <span class="keywordflow">case</span> <span class="charliteral">'8'</span>:
153
 
00146         <span class="keywordflow">case</span> <span class="charliteral">'9'</span>:
154
 
00147           <span class="keywordflow">if</span> (digit_optind != 0 &amp;&amp; digit_optind != this_option_optind)
155
 
00148             printf (<span class="stringliteral">"digits occur in two different argv-elements.\n"</span>);
156
 
00149           digit_optind = this_option_optind;
157
 
00150           printf (<span class="stringliteral">"option %c\n"</span>, c);
158
 
00151           <span class="keywordflow">break</span>;
159
 
00152 
160
 
00153         <span class="keywordflow">case</span> <span class="charliteral">'a'</span>:
161
 
00154           printf (<span class="stringliteral">"option a\n"</span>);
162
 
00155           <span class="keywordflow">break</span>;
163
 
00156 
164
 
00157         <span class="keywordflow">case</span> <span class="charliteral">'b'</span>:
165
 
00158           printf (<span class="stringliteral">"option b\n"</span>);
166
 
00159           <span class="keywordflow">break</span>;
167
 
00160 
168
 
00161         <span class="keywordflow">case</span> <span class="charliteral">'c'</span>:
169
 
00162           printf (<span class="stringliteral">"option c with value `%s'\n"</span>, optarg);
170
 
00163           <span class="keywordflow">break</span>;
171
 
00164 
172
 
00165         <span class="keywordflow">case</span> <span class="charliteral">'d'</span>:
173
 
00166           printf (<span class="stringliteral">"option d with value `%s'\n"</span>, optarg);
174
 
00167           <span class="keywordflow">break</span>;
175
 
00168 
176
 
00169         <span class="keywordflow">case</span> <span class="charliteral">'?'</span>:
177
 
00170           <span class="keywordflow">break</span>;
178
 
00171 
179
 
00172         <span class="keywordflow">default</span>:
180
 
00173           printf (<span class="stringliteral">"?? getopt returned character code 0%o ??\n"</span>, c);
181
 
00174         }
182
 
00175     }
183
 
00176 
184
 
00177   <span class="keywordflow">if</span> (optind &lt; argc)
185
 
00178     {
186
 
00179       printf (<span class="stringliteral">"non-option ARGV-elements: "</span>);
187
 
00180       <span class="keywordflow">while</span> (optind &lt; argc)
188
 
00181         printf (<span class="stringliteral">"%s "</span>, argv[optind++]);
189
 
00182       printf (<span class="stringliteral">"\n"</span>);
190
 
00183     }
191
 
00184 
192
 
00185   exit (0);
193
 
00186 }
194
 
00187 
195
 
00188 <span class="preprocessor">#endif </span><span class="comment">/* TEST */</span>
196
 
</div></pre><hr size="1"><address style="align: right;"><small>Generated on Fri Oct 8 20:34:47 2004 for LibOFX by
197
 
<a href="http://www.doxygen.org/index.html">
198
 
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.7 </small></address>
199
 
</body>
200
 
</html>