From 6a350a8b49abbc2ef7c78a70c1cd4b63eb3ec6ff Mon Sep 17 00:00:00 2001 From: Frank Warmerdam Date: Fri, 23 Dec 2011 02:11:46 +0000 Subject: only split keywords on pluses following spaces (#132) git-svn-id: http://svn.osgeo.org/metacrs/proj/trunk@2131 4e78687f-474d-0410-85f9-8d5e500ac6b2 --- ChangeLog | 5 +++++ src/pj_init.c | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 334b64ab..343c136a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-12-22 Frank Warmerdam + + * src/pj_init.c; Only split arguments on pluses following spaces + in pj_init_plus() (#132) + 2011-12-14 Frank Warmerdam * src/pj_open_lib.c: make sure we check errno before logging messages (#131). diff --git a/src/pj_init.c b/src/pj_init.c index e483f44a..cec7c544 100644 --- a/src/pj_init.c +++ b/src/pj_init.c @@ -171,7 +171,7 @@ pj_init_plus_ctx( projCtx ctx, const char *definition ) #define MAX_ARG 200 char *argv[MAX_ARG]; char *defn_copy; - int argc = 0, i; + int argc = 0, i, blank_count = 0; PJ *result; /* make a copy that we can manipulate */ @@ -185,8 +185,15 @@ pj_init_plus_ctx( projCtx ctx, const char *definition ) switch( defn_copy[i] ) { case '+': - if( i == 0 || defn_copy[i-1] == '\0' ) + if( i == 0 || defn_copy[i-1] == '\0' || blank_count > 0 ) { + /* trim trailing spaces from the previous param */ + if( blank_count > 0 ) + { + defn_copy[i - blank_count] = '\0'; + blank_count = 0; + } + if( argc+1 == MAX_ARG ) { pj_ctx_set_errno( ctx, -44 ); @@ -200,13 +207,20 @@ pj_init_plus_ctx( projCtx ctx, const char *definition ) case ' ': case '\t': case '\n': - defn_copy[i] = '\0'; + /* trim leading spaces from the current param */ + if( i == 0 || defn_copy[i-1] == '\0' || argc == 0 || argv[argc-1] == defn_copy + i ) + defn_copy[i] = '\0'; + else + blank_count++; break; default: - /* do nothing */; + /* reset blank_count */ + blank_count = 0; } } + /* trim trailing spaces from the last param */ + defn_copy[i - blank_count] = '\0'; /* perform actual initialization */ result = pj_init_ctx( ctx, argc, argv ); -- cgit v1.2.3