1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>getopt.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="main.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center>
<hr><h1>getopt.cc</h1><a href="a00103.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// -*- Mode: C++; -*-</font>
00002 <font class="comment">// Package : omniEvents</font>
00003 <font class="comment">// getopt.cc Created : 1/4/98</font>
00004 <font class="comment">// Author : Paul Nader (pwn)</font>
00005 <font class="comment">//</font>
00006 <font class="comment">// Copyright (C) 1998 Paul Nader.</font>
00007 <font class="comment">//</font>
00008 <font class="comment">// This file is part of the omniEvents application.</font>
00009 <font class="comment">//</font>
00010 <font class="comment">// omniEvents is free software; you can redistribute it and/or</font>
00011 <font class="comment">// modify it under the terms of the GNU Lesser General Public</font>
00012 <font class="comment">// License as published by the Free Software Foundation; either</font>
00013 <font class="comment">// version 2.1 of the License, or (at your option) any later version.</font>
00014 <font class="comment">//</font>
00015 <font class="comment">// omniEvents is distributed in the hope that it will be useful,</font>
00016 <font class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment">// Lesser General Public License for more details.</font>
00019 <font class="comment">//</font>
00020 <font class="comment">// You should have received a copy of the GNU Lesser General Public</font>
00021 <font class="comment">// License along with this library; if not, write to the Free Software</font>
00022 <font class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font>
00023 <font class="comment">//</font>
00024 <font class="comment">// Description:</font>
00025 <font class="comment">//</font>
00026 <font class="comment">// getopt implementation for WIN32 platforms.</font>
00027 <font class="comment">//</font>
00028
00029 <font class="comment">/*</font>
00030 <font class="comment"> $Log: getopt.cc,v $</font>
00031 <font class="comment"> Revision 1.4 2004/08/04 08:13:44 alextingle</font>
00032 <font class="comment"> Unix daemon & Windows service now both working. Accessed through interface class Daemon (in daemon.h).</font>
00033 <font class="comment"></font>
00034 <font class="comment"> Revision 1.3 2004/07/15 14:34:31 alextingle</font>
00035 <font class="comment"> Global variables are now declared extern "C".</font>
00036 <font class="comment"></font>
00037 <font class="comment"> Revision 1.2 2004/02/22 00:37:35 alextingle</font>
00038 <font class="comment"> Now does nothing if it isn't needed. Fixes link errors</font>
00039 <font class="comment"></font>
00040 <font class="comment"> Revision 1.1 2003/12/21 16:19:49 alextingle</font>
00041 <font class="comment"> Moved into 'src' directory as part of the change to POA implementation.</font>
00042 <font class="comment"></font>
00043 <font class="comment"> Revision 1.2 2003/11/03 22:46:54 alextingle</font>
00044 <font class="comment"> This implementation of getopt() seems to be needed on AIX as well as</font>
00045 <font class="comment"> windows. It therefore needs to be able to compile on Unix. Changed</font>
00046 <font class="comment"> _tzset() to tzset() in order to achieve this.</font>
00047 <font class="comment"></font>
00048 <font class="comment"> Revision 1.1.1.1 2002/09/25 19:00:35 shamus13</font>
00049 <font class="comment"> Import of OmniEvents source tree from release 2.1.1</font>
00050 <font class="comment"></font>
00051 <font class="comment"> Revision 1.3 1999/11/01 16:59:38 naderp</font>
00052 <font class="comment"> *** empty log message ***</font>
00053 <font class="comment"></font>
00054 <font class="comment">Revision 1.2 99/04/23 12:11:18 12:11:18 naderp (Paul Nader)</font>
00055 <font class="comment">*** empty log message ***</font>
00056 <font class="comment"></font>
00057 <font class="comment">Revision 1.1 99/04/23 09:33:35 09:33:35 naderp (Paul Nader)</font>
00058 <font class="comment">Initial revision</font>
00059 <font class="comment">*/</font>
00060
00061 <font class="preprocessor">#ifdef HAVE_CONFIG_H</font>
00062 <font class="preprocessor"></font><font class="preprocessor"># include "<a class="code" href="a00082.html">config.h</a>"</font>
00063 <font class="preprocessor">#endif</font>
00064 <font class="preprocessor"></font>
00065 <font class="preprocessor">#ifdef HAVE_GETOPT</font>
00066 <font class="preprocessor"></font><font class="keywordtype">void</font> omniEventsDummyGetopt(){}
00067 <font class="preprocessor">#else</font>
00068 <font class="preprocessor"></font>
00069 <font class="preprocessor">#include "<a class="code" href="a00104.html">getopt.h</a>"</font>
00070 <font class="preprocessor">#include <errno.h></font>
00071 <font class="preprocessor">#include <stdio.h></font>
00072 <font class="preprocessor">#include <string.h></font>
00073
<a name="l00074"></a><a class="code" href="a00103.html#a0">00074</a> <font class="keyword">static</font> <font class="keywordtype">char</font>* <a class="code" href="a00103.html#a0">letP</a> =NULL; <font class="comment">// Speichert den Ort des Zeichens der</font>
00075 <font class="comment">// naechsten Option</font>
<a name="l00076"></a><a class="code" href="a00103.html#a1">00076</a> <font class="keyword">static</font> <font class="keywordtype">char</font> <a class="code" href="a00103.html#a1">SW</a> =<font class="charliteral">'-'</font>; <font class="comment">// DOS-Schalter, entweder '-' oder '/'</font>
00077
00078 <font class="comment">// -------------------------------------------------------------- exports ----</font>
00079
00080 <font class="keyword">extern</font> <font class="stringliteral">"C"</font>
00081 {
<a name="l00082"></a><a class="code" href="a00103.html#a2">00082</a> <font class="keywordtype">int</font> <a class="code" href="a00103.html#a2">optind</a> = 1; <font class="comment">// Index: welches Argument ist das naechste</font>
<a name="l00083"></a><a class="code" href="a00103.html#a3">00083</a> <font class="keywordtype">char</font>* <a class="code" href="a00103.html#a3">optarg</a>; <font class="comment">// Zeiger auf das Argument der akt. Option</font>
<a name="l00084"></a><a class="code" href="a00103.html#a4">00084</a> <font class="keywordtype">int</font> <a class="code" href="a00103.html#a4">opterr</a> = 1; <font class="comment">// erlaubt Fehlermeldungen</font>
00085 }
00086
00087 <font class="comment">// ===========================================================================</font>
<a name="l00088"></a><a class="code" href="a00103.html#a5">00088</a> <font class="keywordtype">int</font> <a class="code" href="a00103.html#a5">getopt</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> *argv[], <font class="keyword">const</font> <font class="keywordtype">char</font> *optionS)
00089 {
00090 <font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> ch;
00091 <font class="keywordtype">char</font> *optP;
00092
00093 <font class="keywordflow">if</font>(argc><a class="code" href="a00103.html#a2">optind</a>)
00094 {
00095 <font class="keywordflow">if</font>(<a class="code" href="a00103.html#a0">letP</a>==NULL)
00096 {
00097 <font class="comment">// Initialize letP</font>
00098 <font class="keywordflow">if</font>( (<a class="code" href="a00103.html#a0">letP</a>=argv[<a class="code" href="a00103.html#a2">optind</a>])==NULL || *(<a class="code" href="a00103.html#a0">letP</a>++)!=<a class="code" href="a00103.html#a1">SW</a> )
00099 <font class="keywordflow">goto</font> gopEOF;
00100 <font class="keywordflow">if</font>(*<a class="code" href="a00103.html#a0">letP</a> == <a class="code" href="a00103.html#a1">SW</a>)
00101 {
00102 <font class="comment">// "--" is end of options.</font>
00103 <a class="code" href="a00103.html#a2">optind</a>++;
00104 <font class="keywordflow">goto</font> gopEOF;
00105 }
00106 }
00107
00108 <font class="keywordflow">if</font>((ch=*(<a class="code" href="a00103.html#a0">letP</a>++))== <font class="charliteral">'\0'</font>)
00109 {
00110 <font class="comment">// "-" is end of options.</font>
00111 <a class="code" href="a00103.html#a2">optind</a>++;
00112 <font class="keywordflow">goto</font> gopEOF;
00113 }
00114 <font class="keywordflow">if</font>(<font class="charliteral">':'</font>==ch || (optP=(<font class="keywordtype">char</font>*)strchr(optionS,ch)) == NULL)
00115 {
00116 <font class="keywordflow">goto</font> gopError;
00117 }
00118 <font class="comment">// 'ch' is a valid option</font>
00119 <font class="comment">// 'optP' points to the optoin char in optionS</font>
00120 <font class="keywordflow">if</font>(<font class="charliteral">':'</font>==*(++optP))
00121 {
00122 <font class="comment">// Option needs a parameter.</font>
00123 <a class="code" href="a00103.html#a2">optind</a>++;
00124 <font class="keywordflow">if</font>(<font class="charliteral">'\0'</font>==*<a class="code" href="a00103.html#a0">letP</a>)
00125 {
00126 <font class="comment">// parameter is in next argument</font>
00127 <font class="keywordflow">if</font>(argc <= <a class="code" href="a00103.html#a2">optind</a>)
00128 <font class="keywordflow">goto</font> gopError;
00129 <a class="code" href="a00103.html#a0">letP</a> = argv[<a class="code" href="a00103.html#a2">optind</a>++];
00130 }
00131 <a class="code" href="a00103.html#a3">optarg</a> = <a class="code" href="a00103.html#a0">letP</a>;
00132 <a class="code" href="a00103.html#a0">letP</a> = NULL;
00133 }
00134 <font class="keywordflow">else</font>
00135 {
00136 <font class="comment">// Option needs no parameter.</font>
00137 <font class="keywordflow">if</font>(<font class="charliteral">'\0'</font>==*<a class="code" href="a00103.html#a0">letP</a>)
00138 {
00139 <font class="comment">// Move on to next argument.</font>
00140 <a class="code" href="a00103.html#a2">optind</a>++;
00141 <a class="code" href="a00103.html#a0">letP</a> = NULL;
00142 }
00143 <a class="code" href="a00103.html#a3">optarg</a> = NULL;
00144 }
00145 <font class="keywordflow">return</font> ch;
00146 }
00147 gopEOF:
00148 <a class="code" href="a00103.html#a3">optarg</a>=<a class="code" href="a00103.html#a0">letP</a>=NULL;
00149 <font class="keywordflow">return</font> EOF;
00150
00151 gopError:
00152 <a class="code" href="a00103.html#a3">optarg</a> = NULL;
00153 errno = EINVAL;
00154 <font class="keywordflow">if</font>(opterr)
00155 perror (<font class="stringliteral">"error in command line"</font>);
00156 <font class="keywordflow">return</font> (<font class="charliteral">'?'</font>);
00157 }
00158 <font class="comment">// ===========================================================================</font>
00159 <font class="comment">// Ende von getopt ()</font>
00160 <font class="comment">// ===========================================================================</font>
00161
00162 <font class="preprocessor">#endif // HAVE_GETOPT</font>
00163 <font class="preprocessor"></font>
</pre></div><hr><address align="right"><small>Generated on Fri Nov 19 17:42:20 2004 for OmniEvents by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>
|