diff --git a/gdal/gcore/gdal.h b/gdal/gcore/gdal.h index 7833b49..7534ca5 100644 --- a/gdal/gcore/gdal.h +++ b/gdal/gcore/gdal.h @@ -550,6 +550,11 @@ void CPL_DLL CPL_STDCALL GDALARUnlockBuffer(GDALAsyncReaderH hARIO); /* -------------------------------------------------------------------- */ int CPL_DLL CPL_STDCALL GDALGeneralCmdLineProcessor( int nArgc, char ***ppapszArgv, int nOptions ); +#ifndef GDAL_SET_CMD_LINE +#define GDAL_SET_CMD_LINE +void CPL_DLL CPL_STDCALL GDALSetCmdLine( int argc, char ** argv, int bComplete=FALSE ); +char CPL_DLL * CPL_STDCALL GDALGetCmdLine( int bComplete=FALSE ); +#endif void CPL_DLL CPL_STDCALL GDALSwapWords( void *pData, int nWordSize, int nWordCount, int nWordSkip ); void CPL_DLL CPL_STDCALL diff --git a/gdal/gcore/gdal_misc.cpp b/gdal/gcore/gdal_misc.cpp index 473537a..75af223 100644 --- a/gdal/gcore/gdal_misc.cpp +++ b/gdal/gcore/gdal_misc.cpp @@ -38,6 +38,10 @@ CPL_CVSID("$Id$"); #include "ogr_spatialref.h" +//static int nGDALCommandArgs = 0; +static char szGDALCommandArgs[1024]; +static char szGDALCommandArgsComplete[1024]; + /************************************************************************/ /* __pure_virtual() */ /* */ @@ -2343,6 +2347,9 @@ GDALGeneralCmdLineProcessor( int nArgc, char ***ppapszArgv, int nOptions ) (void) nOptions; + /* save the complete argv to szGDALCommandArgsComplete */ + GDALSetCmdLine( nArgc, *ppapszArgv, TRUE ) ; + /* -------------------------------------------------------------------- */ /* Preserve the program name. */ /* -------------------------------------------------------------------- */ @@ -2671,9 +2678,58 @@ GDALGeneralCmdLineProcessor( int nArgc, char ***ppapszArgv, int nOptions ) *ppapszArgv = papszReturn; + /* save the resulting argv to szGDALCommandArgs */ + GDALSetCmdLine( CSLCount( *ppapszArgv ), *ppapszArgv ) ; + return CSLCount( *ppapszArgv ); } +void GDALSetCmdLine1( int argc, char ** argv, char *dargv ) +{ + /* code taken from cdo commandline.c */ + int iarg; + char *pargv; + size_t len, offset = 0; + + for ( iarg = 0; iarg < argc; iarg++ ) + { + if ( iarg == 0 ) + { + pargv = strrchr(argv[iarg], '/'); + if ( pargv == 0 ) pargv = argv[0]; + else pargv++; + } + else + pargv = argv[iarg]; + + len = strlen(pargv); + if ( offset+len+1 > 1024 ) break; + memcpy(dargv+offset, pargv, len); + offset += len; + dargv[offset] = ' '; + offset++; + } + + dargv[offset-1] = '\0'; + +}; + +void GDALSetCmdLine(int argc, char ** argv, int bComplete ) +{ + if ( bComplete) + GDALSetCmdLine1( argc, argv, szGDALCommandArgsComplete ); + else + GDALSetCmdLine1( argc, argv, szGDALCommandArgs ); +} + +char * GDALGetCmdLine( int bComplete ) +{ + if ( bComplete) + return szGDALCommandArgsComplete; + else + return szGDALCommandArgs; +} + /************************************************************************/ /* _FetchDblFromMD() */ @@ -3077,5 +3133,6 @@ int GDALCheckBandCount( int nBands, int bIsZeroAllowed ) return TRUE; } + CPL_C_END