incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r1202270 - in /incubator/ooo/trunk/main/tools: Executable_rscdep.mk bootstrp/rscdep.cxx
Date Tue, 15 Nov 2011 16:12:05 GMT
Author: pfg
Date: Tue Nov 15 16:12:04 2011
New Revision: 1202270

URL: http://svn.apache.org/viewvc?rev=1202270&view=rev
Log:
i118595 - Removal of the use of getopt() from rscdep. Patch by Andre.

Modified:
    incubator/ooo/trunk/main/tools/Executable_rscdep.mk
    incubator/ooo/trunk/main/tools/bootstrp/rscdep.cxx

Modified: incubator/ooo/trunk/main/tools/Executable_rscdep.mk
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/tools/Executable_rscdep.mk?rev=1202270&r1=1202269&r2=1202270&view=diff
==============================================================================
--- incubator/ooo/trunk/main/tools/Executable_rscdep.mk (original)
+++ incubator/ooo/trunk/main/tools/Executable_rscdep.mk Tue Nov 15 16:12:04 2011
@@ -55,17 +55,4 @@ $(eval $(call gb_Executable_add_exceptio
 	tools/bootstrp/rscdep \
 ))
 
-ifeq ($(OS),WNT)
-ifeq ($(HAVE_GETOPT),YES)
-$(eval $(call gb_Executable_set_cxxflags,rscdep,\
-	$$(CXXFLAGS) \
-	-DHAVE_GETOPT \
-))
-else
-$(eval $(call gb_Executable_add_linked_libs,rscdep,\
-	gnu_getopt \
-))
-endif
-endif
-
 # vim: set noet sw=4 ts=4:

Modified: incubator/ooo/trunk/main/tools/bootstrp/rscdep.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/tools/bootstrp/rscdep.cxx?rev=1202270&r1=1202269&r2=1202270&view=diff
==============================================================================
--- incubator/ooo/trunk/main/tools/bootstrp/rscdep.cxx (original)
+++ incubator/ooo/trunk/main/tools/bootstrp/rscdep.cxx Tue Nov 15 16:12:04 2011
@@ -41,16 +41,6 @@
 
 #include "cppdep.hxx"
 
-#if defined WNT 
-#if !defined HAVE_GETOPT
-#define __STDC__ 1
-#define __GNU_LIBRARY__
-#include <external/glibc/getopt.h>
-#else
-#include <getopt.h>
-#endif
-#endif
-
 class RscHrcDep : public CppDep
 {
 public:
@@ -78,7 +68,6 @@ void RscHrcDep::Execute()
 
 int main( int argc, char** argv )
 {
-	int c;
 	char aBuf[255];
 	char pFileNamePrefix[255];
 	char pOutputFileName[255];
@@ -89,44 +78,96 @@ int main( int argc, char** argv )
 //  who needs anything but '/' ?
 //	String aDelim = String(DirEntry::GetAccessDelimiter());
 	String aDelim = '/';
-
 	RscHrcDep *pDep = new RscHrcDep;
-    
+
+    // When the options are processed, the non-option arguments are
+    // collected at the head of the argv array.
+    // nLastNonOption points to the last of them.
+    int nLastNonOption (-1);
+
     pOutputFileName[0] = 0;
     pSrsFileName[0] = 0;
 
 	for ( int i=1; i<argc; i++)
 	{
 		strcpy( aBuf, (const char *)argv[i] );
-		if ( aBuf[0] == '-' && aBuf[1] == 'p' && aBuf[2] == '=' )
-		{
-			strcpy(pFileNamePrefix, &aBuf[3]);
-			//break;
-		}
-		if ( aBuf[0] == '-' && aBuf[1] == 'f' && aBuf[2] == 'o' && aBuf[3]
== '=' )
-		{
-			strcpy(pOutputFileName, &aBuf[4]);
-			//break;
-		}
-		if ( aBuf[0] == '-' && aBuf[1] == 'f' && aBuf[2] == 'p' && aBuf[3]
== '=' )
-		{
-			strcpy(pSrsFileName, &aBuf[4]);
-			String aName( pSrsFileName, gsl_getSystemTextEncoding());
-			DirEntry aDest( aName );
-			aSrsBaseName = aDest.GetBase();
-			//break;
-		}
-		if (aBuf[0] == '-' &&  aBuf[1] == 'i' )
-		{
-			//printf("Include : %s\n", &aBuf[2] );
-			pDep->AddSearchPath( &aBuf[2] );
-		}
-		if (aBuf[0] == '-' &&  aBuf[1] == 'I' )
-		{
-			//printf("Include : %s\n", &aBuf[2] );
-			pDep->AddSearchPath( &aBuf[2] );
-		}
-		if (aBuf[0] == '@' )
+        const sal_Int32 nLength (strlen(aBuf));
+
+        printf("option %d is [%s] and has length %d\n", i, aBuf, nLength);
+
+        if (nLength == 0)
+        {
+            // Is this even possible?
+            continue;
+        }
+        if (aBuf[0] == '-' && nLength > 0)
+        {
+            bool bIsKnownOption (true);
+            // Make a switch on the first character after the - for a
+            // preselection of the option.
+            // This is faster then multiple ifs and improves readability.
+            switch (aBuf[1])
+            {
+                case 'p':
+                    if (nLength>1 && aBuf[2] == '=' )
+                        strcpy(pFileNamePrefix, &aBuf[3]);
+                    else
+                        bIsKnownOption = false;
+                    break;
+                        
+                case 'f':
+                    if (nLength>2 && aBuf[2] == 'o' && aBuf[3] == '='
)
+                    {
+                        strcpy(pOutputFileName, &aBuf[4]);
+                    }
+                    else if (nLength>2 && aBuf[2] == 'p' && aBuf[3] ==
'=' )
+                    {
+                        strcpy(pSrsFileName, &aBuf[4]);
+                        String aName( pSrsFileName, gsl_getSystemTextEncoding());
+                        DirEntry aDest( aName );
+                        aSrsBaseName = aDest.GetBase();
+                    }
+                    else
+                        bIsKnownOption = false;
+                    break;
+                        
+                case 'i':
+                case 'I':
+#ifdef DEBUG_VERBOSE
+                    printf("Include : %s\n", &aBuf[2] );
+#endif
+                    pDep->AddSearchPath( &aBuf[2] );
+                    break;
+                    
+                case 'h' :
+                case 'H' :
+                case '?' :
+                    printf("RscDep 1.0\n");
+                    break;
+
+                case 'a' :
+#ifdef DEBUG_VERBOSE
+                    printf("option a\n");
+#endif
+                    break;
+
+                case 'l' :
+#ifdef DEBUG_VERBOSE
+                    printf("option l with Value %s\n", &aBuf[2] );
+#endif
+                    pDep->AddSource(&aBuf[2]);
+                    break;
+
+                default:
+                    bIsKnownOption = false;
+                    break;       
+            }
+#ifdef DEBUG_VERBOSE
+            if ( ! bIsKnownOption)
+				printf("Unknown option error [%s]\n", aBuf);
+#endif
+        }
+		else if (aBuf[0] == '@' )
 		{
 			ByteString aToken;
 			String aRespName( &aBuf[1], gsl_getSystemTextEncoding());
@@ -172,47 +213,14 @@ int main( int argc, char** argv )
 				}
 			}
 		}
+        else
+        {
+            // Collect all non-options at the head of argv.
+            if (++nLastNonOption < i)
+                argv[nLastNonOption] = argv[i];
+        }
 	}
 
-	while( 1 )
-	{
-		c = getopt( argc, argv,
-		"_abcdefghi:jklmnopqrstuvwxyzABCDEFGHI:JKLMNOPQRSTUVWXYZ1234567890/-+=.\\()\"");
-		if ( c == -1 )
-			break;
-
-		switch( c )
-		{
-			case 0:
-				break;
-			case 'a' :
-#ifdef DEBUG_VERBOSE
-				printf("option a\n");
-#endif
-				break;
-
-			case 'l' :
-#ifdef DEBUG_VERBOSE
-				printf("option l with Value %s\n", optarg );
-#endif
-				pDep->AddSource( optarg );
-				break;
-
-			case 'h' :
-			case 'H' :
-			case '?' :
-				printf("RscDep 1.0\n");
-				break;
-
-			default:
-#ifdef DEBUG_VERBOSE
-				printf("Unknown getopt error\n");
-#endif
-				;
-		}
-	}
-
-
 	DirEntry aEntry(".");
 	aEntry.ToAbs();
 //	String aCwd = aEntry.GetName();
@@ -241,8 +249,10 @@ int main( int argc, char** argv )
 	//fprintf( stderr, "OutFileName : %s \n",aFileName.GetStr());
 	aOutStream.Open( aFileName, STREAM_WRITE );
 
+    // Process the yet unhandled non-options.  These are supposed to
+    // be names of files on which the target depends.
 	ByteString aString;
-	if ( optind < argc )
+    if (nLastNonOption >= 0)
 	{
 #ifdef DEBUG_VERBOSE
 		printf("further arguments : ");
@@ -251,17 +261,14 @@ int main( int argc, char** argv )
 		aString.SearchAndReplaceAll('\\', ByteString( aDelim,  RTL_TEXTENCODING_ASCII_US ));
 		aString += ByteString(" : " );
 
-		while ( optind < argc )
+        for (sal_Int32 nIndex=0; nIndex<=nLastNonOption; ++nIndex)
 		{
+            printf("option at %d is [%s]\n", nIndex, argv[nIndex]);
 			if (!bSource )
 			{
 				aString += ByteString("	" );
-				aString += ByteString( argv[optind]);
-				pDep->AddSource( argv[optind++]);
-			}
-			else
-			{
-				optind++;
+				aString += ByteString( argv[nIndex]);
+				pDep->AddSource( argv[nIndex]);
 			}
 		}
 	}



Mime
View raw message