Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

getopt.cc

Go to the documentation of this file.
00001 // -*- Mode: C++; -*-
00002 //                            Package   : omniEvents
00003 // getopt.cc                  Created   : 1/4/98
00004 //                            Author    : Paul Nader (pwn)
00005 //
00006 //    Copyright (C) 1998 Paul Nader.
00007 //
00008 //    This file is part of the omniEvents application.
00009 //
00010 //    omniEvents is free software; you can redistribute it and/or
00011 //    modify it under the terms of the GNU Lesser General Public
00012 //    License as published by the Free Software Foundation; either
00013 //    version 2.1 of the License, or (at your option) any later version.
00014 //
00015 //    omniEvents is distributed in the hope that it will be useful,
00016 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 //    Lesser General Public License for more details.
00019 //
00020 //    You should have received a copy of the GNU Lesser General Public
00021 //    License along with this library; if not, write to the Free Software
00022 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // Description:
00025 //
00026 //    getopt implementation for WIN32 platforms.
00027 //
00028 
00029 /*
00030   $Log: getopt.cc,v $
00031   Revision 1.2  2003/11/03 22:46:54  alextingle
00032   This implementation of getopt() seems to be needed on AIX as well as
00033   windows. It therefore needs to be able to compile on Unix. Changed
00034   _tzset() to tzset() in order to achieve this.
00035 
00036   Revision 1.1.1.1  2002/09/25 19:00:35  shamus13
00037   Import of OmniEvents source tree from release 2.1.1
00038 
00039   Revision 1.3  1999/11/01 16:59:38  naderp
00040   *** empty log message ***
00041 
00042 Revision 1.2  99/04/23  12:11:18  12:11:18  naderp (Paul Nader)
00043 *** empty log message ***
00044 
00045 Revision 1.1  99/04/23  09:33:35  09:33:35  naderp (Paul Nader)
00046 Initial revision
00047 */
00048 
00049 #include <getopt.h>
00050 #include <errno.h>
00051 #include <stdio.h>
00052 #include <string.h>
00053 
00054 // Zeitfunktionen beachten die Umgebungsvariable TZ
00055 #include <time.h> /* tzset() */
00056  
00057 static  char   *letP = NULL;    // Speichert den Ort des Zeichens der
00058                                 // naechsten Option
00059 static  char    SW = 0;         // DOS-Schalter, entweder '-' oder '/'
00060 
00061 // -------------------------------------------------------------- exports ----
00062 
00063 int   optind  = 1;    // Index: welches Argument ist das naechste
00064 char* optarg;         // Zeiger auf das Argument der akt. Option
00065 int   opterr  = 1;    // erlaubt Fehlermeldungen
00066 
00067 // ===========================================================================
00068 int getopt(int argc, char *argv[], const char *optionS)
00069 // ---------------------------------------------------------------------------
00070 {
00071    unsigned char ch;
00072    char *optP;
00073     
00074    tzset(); /* Zeitfunktionen beachten die Umgebungsvariable TZ */
00075     
00076    if (SW == 0)
00077         SW = '-';
00078  
00079    if (argc > optind)
00080    {
00081       if (letP == NULL)
00082       {
00083          if ((letP = argv[optind]) == NULL || *(letP++) != SW)
00084             goto gopEOF;
00085          if (*letP == SW)
00086          {
00087             optind++;  goto gopEOF;
00088          }
00089       }
00090       if (0 == (ch = *(letP++)))
00091       {
00092          optind++;  goto gopEOF;
00093       }
00094       if (':' == ch  ||  (optP = (char*)strchr(optionS, ch)) == NULL)  
00095          goto gopError;
00096       if (':' == *(++optP))
00097       {
00098          optind++;
00099          if (0 == *letP)
00100          {
00101             if (argc <= optind)  goto  gopError;
00102                letP = argv[optind++];
00103          }
00104          optarg = letP;
00105          letP = NULL;
00106       } else
00107       {
00108          if (0 == *letP) {
00109             optind++;
00110             letP = NULL;
00111          }
00112          optarg = NULL;
00113       }
00114       return ch;
00115    }
00116 gopEOF:
00117    optarg = letP = NULL;  
00118    return EOF;
00119     
00120 gopError:
00121    optarg = NULL;
00122    errno  = EINVAL;
00123    if (opterr)
00124       perror ("error in command line");
00125    return ('?');
00126 }
00127 // ===========================================================================
00128 
00129 //                      Ende von getopt ()
00130 // ===========================================================================
00131 
00132 
00133 

Generated on Fri Dec 12 10:53:02 2003 for OmniEvents by doxygen1.2.15