[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/win
From:       Christian Ehrlicher <Ch.Ehrlicher () gmx ! de>
Date:       2006-03-19 16:29:53
Message-ID: 1142785793.454640.27337.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 520343 by chehrlic:

add getopt(int argc, char **argv, const char *optstring)

 M  +2 -0      include/mingw/unistd.h  
 M  +2 -1      include/msvc/unistd.h  
 M  +93 -0     src/unistd.c  


--- trunk/KDE/kdelibs/win/include/mingw/unistd.h #520342:520343
@@ -134,6 +134,8 @@
 
 KDEWIN32_EXPORT long getpagesize (void);
 
+KDEWIN32_EXPORT int getopt(int argc, char **argv, const char *optstring);
+
 #ifdef __cplusplus
 }
 #endif
--- trunk/KDE/kdelibs/win/include/msvc/unistd.h #520342:520343
@@ -140,8 +140,9 @@
 
 KDEWIN32_EXPORT int revoke(const char *tty);
 
-KDEWIN32_EXPORT long getpagesize (void);
+KDEWIN32_EXPORT long getpagesize(void);
 
+KDEWIN32_EXPORT int getopt(int argc, char **argv, const char *optstring);
 
 #ifdef __cplusplus
 }
--- trunk/KDE/kdelibs/win/src/unistd.c #520342:520343
@@ -339,3 +339,96 @@
     }
     return g_pagesize;
 }
+
+// XGetopt.cpp  Version 1.2
+//
+// Author:  Hans Dietrich
+//          hdietrich2@hotmail.com
+//
+// Description:
+//     XGetopt.cpp implements getopt(), a function to parse command lines.
+//
+// History
+//     Version 1.2 - 2003 May 17
+//     - Added Unicode support
+//
+//     Version 1.1 - 2002 March 10
+//     - Added example to XGetopt.cpp module header 
+//
+// This software is released into the public domain.
+// You are free to use it in any way you like.
+//
+// This software is provided "as is" with no expressed
+// or implied warranty.  I accept no liability for any
+// damage or loss of business that this software may cause.
+//
+// CE: from http://www.codeproject.com/cpp/xgetopt.asp
+//     removed unicode support to compile with mingw
+char	*optarg;		// global argument pointer
+int		optind = 0; 	// global argv index
+
+int getopt(int argc, char **argv, const char *optstring)
+{
+	static char *next = NULL;
+	char c = '?';
+	char *cp = NULL;
+	if (optind == 0)
+		next = NULL;
+
+	optarg = NULL;
+
+	if (next == NULL || *next == '\0')
+	{
+		if (optind == 0)
+			optind++;
+
+		if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
+		{
+			optarg = NULL;
+			if (optind < argc)
+				optarg = argv[optind];
+			return -1;
+		}
+
+		if (strcmp(argv[optind], "--") == 0)
+		{
+			optind++;
+			optarg = NULL;
+			if (optind < argc)
+				optarg = argv[optind];
+			return -1;
+		}
+
+		next = argv[optind];
+		next++;		// skip past -
+		optind++;
+	}
+
+	c = *next++;
+	cp = strchr(optstring, c);
+
+	if (cp == NULL || c == ':')
+		return '?';
+
+	cp++;
+	if (*cp == ':')
+	{
+		if (*next != '\0')
+		{
+			optarg = next;
+			next = NULL;
+		}
+		else if (optind < argc)
+		{
+			optarg = argv[optind];
+			optind++;
+		}
+		else
+		{
+			return '?';
+		}
+	}
+
+	return c;
+}
+
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic