Skip to content

Commit

Permalink
gie: implement a strict_mode command
Browse files Browse the repository at this point in the history
In that mode:
* All non-comment/decoration lines must start with a valid tag
* Commands split on several lines should be terminated with " \"
  • Loading branch information
rouault committed Apr 19, 2020
1 parent b16b966 commit 7d446e1
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 117 deletions.
51 changes: 46 additions & 5 deletions src/apps/gie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Thomas Knudsen, thokn@sdfe.dk, 2017-10-01/2017-10-08
/* Package for flexible format I/O - ffio */
typedef struct ffio {
FILE *f;
const char **tags;
const char * const *tags;
const char *tag;
char *args;
char *next_args;
Expand All @@ -144,10 +144,10 @@ static int at_end_delimiter (ffio *G);
static const char *at_tag (ffio *G);
static int at_decorative_element (ffio *G);
static ffio *ffio_destroy (ffio *G);
static ffio *ffio_create (const char **tags, size_t n_tags, size_t max_record_size);
static ffio *ffio_create (const char * const *tags, size_t n_tags, size_t max_record_size);

static const char *gie_tags[] = {
"<gie>", "operation", "crs_src", "crs_dst", "use_proj4_init_rules",
static const char * const gie_tags[] = {
"<gie>", "strict_mode", "operation", "crs_src", "crs_dst", "use_proj4_init_rules",
"accept", "expect", "roundtrip", "banner", "verbose",
"direction", "tolerance", "ignore", "require_grid", "echo", "skip", "</gie>"
};
Expand Down Expand Up @@ -179,6 +179,7 @@ typedef struct {
PJ *P;
PJ_COORD a, b, c, e;
PJ_DIRECTION dir;
bool strict_mode;
int verbosity;
int skip;
int op_id;
Expand Down Expand Up @@ -1061,6 +1062,7 @@ Indicate that the remaining material should be skipped. Mostly for debugging.
static int dispatch (const char *cmnd, const char *args) {
if (T.skip)
return SKIP;
if (0==strcmp (cmnd, "strict_mode")) { T.strict_mode = true; return 0; }
if (0==strcmp (cmnd, "operation")) return operation ((char *) args);
if (0==strcmp (cmnd, "crs_src")) return crs_src (args);
if (0==strcmp (cmnd, "crs_dst")) return crs_dst (args);
Expand Down Expand Up @@ -1267,7 +1269,7 @@ See the PROJ ".gie" test suites for examples of supported formatting.


/***************************************************************************************/
static ffio *ffio_create (const char **tags, size_t n_tags, size_t max_record_size) {
static ffio *ffio_create (const char * const *tags, size_t n_tags, size_t max_record_size) {
/****************************************************************************************
Constructor for the ffio object.
****************************************************************************************/
Expand Down Expand Up @@ -1514,6 +1516,45 @@ whitespace etc. The block is stored in G->args. Returns 1 on success, 0 otherwis
****************************************************************************************/
G->args[0] = 0;

// Special parsing in strict_mode:
// - All non-comment/decoration lines must start with a valid tag
// - Commands split on several lines should be terminated with " \"
if( T.strict_mode )
{
while( nextline(G) )
{
G->lineno = G->next_lineno;
if( G->next_args[0] == 0 || at_decorative_element(G) ) {
continue;
}
G->tag = at_tag (G);
if (nullptr==G->tag)
{
fprintf (T.fout, "unsupported command line %d: %s\n", (int)G->lineno, G->next_args);
return 0;
}

append_args (G);
pj_shrink (G->args);
while( G->args[strlen(G->args)-1] == '\\' )
{
G->args[strlen(G->args)-1] = 0;
if( !nextline(G) )
{
return 0;
}
G->lineno = G->next_lineno;
append_args (G);
pj_shrink (G->args);
}
if ( 0==strcmp (G->tag, "</gie>")) {
G->level++;
}
return 1;
}
return 0;
}

if (0==skip_to_next_tag (G))
return 0;
G->tag = at_tag (G);
Expand Down
Loading

0 comments on commit 7d446e1

Please sign in to comment.