aboutsummaryrefslogtreecommitdiff
path: root/src/optargpm.h
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2018-02-19 22:39:17 +0100
committerKristian Evers <kristianevers@gmail.com>2018-02-19 22:39:17 +0100
commit43d811d20598abde95a8d177123e9f26fe5229ab (patch)
treec66684d7975798109a072b52bce5e7c5f9bd5182 /src/optargpm.h
parenta9e08ad008b1ff16d6139aab5e813058c922eef8 (diff)
parentefa636e0d9e0cef5a5fff1b7ed76d0368d20121b (diff)
downloadPROJ-43d811d20598abde95a8d177123e9f26fe5229ab.tar.gz
PROJ-43d811d20598abde95a8d177123e9f26fe5229ab.zip
Merge remote-tracking branch 'osgeo/master' into docs-release-4.10.0
Diffstat (limited to 'src/optargpm.h')
-rw-r--r--src/optargpm.h38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/optargpm.h b/src/optargpm.h
index acb96583..8a9dd0c7 100644
--- a/src/optargpm.h
+++ b/src/optargpm.h
@@ -84,7 +84,7 @@ opt_eof_handler (o):
Usage is probably easiest understood by a brief textbook style example:
-Consider a simple program taking the conventinal "-v, -h, -o" options
+Consider a simple program taking the conventional "-v, -h, -o" options
indicating "verbose output", "help please", and "output file specification",
respectively.
@@ -183,15 +183,12 @@ Thomas Knudsen, thokn@sdfe.dk, 2016-05-25/2017-09-10
* DEALINGS IN THE SOFTWARE.
***********************************************************************/
-
-#define PJ_LIB__
-#include <proj.h>
+#include <ctype.h>
+#include <errno.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-#include <ctype.h>
#include <string.h>
-#include <math.h>
-#include <errno.h>
/**************************************************************************************************/
struct OPTARGS;
@@ -417,6 +414,7 @@ const char *opt_strip_path (const char *full_name) {
/* split command line options into options/flags ("-" style), projdefs ("+" style) and input file args */
OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys, const char **longflags, const char **longkeys) {
int i, j;
+ int free_format;
OPTARGS *o;
o = (OPTARGS *) calloc (1, sizeof(OPTARGS));
@@ -442,7 +440,8 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
o->longkeys = longkeys;
- /* check aliases, An end user should never experience this, but the developer should make sure that aliases are valid */
+ /* check aliases, An end user should never experience this, but */
+ /* the developer should make sure that aliases are valid */
for (i = 0; longflags && longflags[i]; i++) {
/* Go on if it does not look like an alias */
if (strlen (longflags[i]) < 3)
@@ -500,6 +499,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if ('-' != argv[i][0])
break;
+
if (0==o->margv)
o->margv = argv + i;
o->margc++;
@@ -516,7 +516,10 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
char *equals;
crepr = argv[i] + 2;
- /* need to maniplulate a bit to support gnu style --pap=pop syntax */
+ /* We need to manipulate a bit to support gnu style --foo=bar syntax. */
+ /* NOTE: This will segfault for read-only (const char * style) storage, */
+ /* but since the canonical use case, int main (int argc, char **argv), */
+ /* is non-const, we ignore this for now */
equals = strchr (crepr, '=');
if (equals)
*equals = 0;
@@ -579,6 +582,23 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
/* Process all '+'-style options, starting from where '-'-style processing ended */
o->pargv = argv + i;
+
+ /* Is free format in use, instead of plus-style? */
+ for (free_format = 0, j = 1; j < argc; j++) {
+ if (0==strcmp ("--", argv[j])) {
+ free_format = j;
+ break;
+ }
+ }
+
+ if (free_format) {
+ o->pargc = free_format - (o->margc + 1);
+ o->fargc = argc - (free_format + 1);
+ if (0 != o->fargc)
+ o->fargv = argv + free_format + 1;
+ return o;
+ }
+
for (/* empty */; i < argc; i++) {
if ('-' == argv[i][0]) {
free (o);