21 #include "parser_local_proto.h"
26 static char *str_json_escape(
const char *str);
27 static char *str_replace_free_buffer(
char *buffer,
const char old_char,
198 char *file_name =
NULL;
200 int random_int = rand();
208 char desc[KEYLENGTH];
213 fp = fopen(file_name,
"w+");
215 fprintf(stderr,
"Unable to open temporary file <%s>\n", file_name);
222 for (flag = &
st->first_flag; flag; flag = flag->
next_flag) {
233 for (opt = &
st->first_option; opt; opt = opt->
next_opt) {
259 if (
st->n_flags && num_flags > 0) {
263 fprintf(fp,
" \"flags\":\"");
265 for (flag = &
st->first_flag; flag; flag = flag->
next_flag) {
267 fprintf(fp,
"%c", flag->
key);
274 if (
st->n_opts && num_inputs > 0) {
279 fprintf(fp,
" \"inputs\":[\n");
280 for (opt = &
st->first_option; opt; opt = opt->
next_opt) {
287 if (i < num_inputs) {
298 fprintf(fp,
" {\"param\": \"%s\", ", opt->
key);
299 char *escaped_value = str_json_escape(opt->
answer);
300 fprintf(fp,
"\"value\": \"%s\"}", escaped_value);
303 if (i < num_inputs) {
316 if (
st->n_opts && num_outputs > 0) {
321 fprintf(fp,
" \"outputs\":[\n");
322 for (opt = &
st->first_option; opt; opt = opt->
next_opt) {
329 if (i < num_outputs) {
346 fp = fopen(file_name,
"r");
348 fprintf(stderr,
"Unable to open temporary file <%s>\n", file_name);
354 fprintf(stdout,
"%c", c);
371 int i = 0, urlfound = 0;
375 G_debug(2,
"tokenize opt string: <%s> with '@'", opt->
answer);
383 _(
"Input string not understood: <%s>. Multiple '@' chars?"),
388 G_debug(2,
"tokens[1]: <%s>", tokens[1]);
389 if (strncmp(tokens[1],
"http://", 7) == 0 ||
390 strncmp(tokens[1],
"https://", 8) == 0 ||
391 strncmp(tokens[1],
"ftp://", 6) == 0) {
397 G_debug(2,
"name@mapset found");
403 if (i > 1 && urlfound == 1) {
406 "\"import_descr\": {\"source\":\"%s\", "
407 "\"type\":\"raster\"},\n ",
413 "\"import_descr\": {\"source\":\"%s\", "
414 "\"type\":\"file\"},\n ",
420 "\"import_descr\": {\"source\":\"%s\", "
421 "\"type\":\"vector\"},\n ",
427 fprintf(fp,
"\"param\": \"%s\", ", opt->
key);
430 char *escaped_value =
432 fprintf(fp,
"\"value\": \"%s\"", escaped_value);
436 char *escaped_value = str_json_escape(
438 fprintf(fp,
"\"value\": \"%s\"", escaped_value);
461 int has_file_export = 0;
476 "\"export\": {\"format\":\"%s\", \"type\":\"raster\"},\n ",
482 "\"export\": {\"format\":\"%s\", \"type\":\"file\"},\n ",
489 "\"export\": {\"format\":\"%s\", \"type\":\"vector\"},\n ",
494 fprintf(fp,
"\"param\": \"%s\", ", opt->
key);
495 if (has_file_export == 1) {
496 char *escaped_value =
498 fprintf(fp,
"\"value\": \"$file::%s\"", escaped_value);
502 char *escaped_value =
504 fprintf(fp,
"\"value\": \"%s\"", escaped_value);
535 if (always_remove == 1)
560 static char *str_replace_free_buffer(
char *buffer,
const char old_char,
565 if (strchr(buffer, old_char)) {
567 char old_str[2] = {old_char,
'\0'};
581 static char *str_json_escape(
const char *str)
589 out = str_replace_free_buffer(out,
'\\',
"\\\\");
590 out = str_replace_free_buffer(out,
'\r',
"\\r");
591 out = str_replace_free_buffer(out,
'\n',
"\\n");
592 out = str_replace_free_buffer(out,
'\t',
"\\t");
593 out = str_replace_free_buffer(out,
'\"',
"\\\"");
594 out = str_replace_free_buffer(out,
'\f',
"\\f");
595 out = str_replace_free_buffer(out,
'\b',
"\\b");
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
char * G_str_replace(const char *, const char *, const char *)
Replace all occurrences of old_str in buffer with new_str.
char * G_tempfile(void)
Returns a temporary file name.
const char * G_mapset(void)
Get current mapset name.
void G_free_tokens(char **)
Free memory allocated to tokens.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
int G_strncasecmp(const char *, const char *, int)
String compare ignoring case (upper or lower) - limited number of characters.
const char * G_program_name(void)
Return module name.
char * G_chop(char *)
Chop leading and trailing white spaces.
int G_debug(int, const char *,...) __attribute__((format(printf
char * G_store(const char *)
Copy string to allocated memory.
char ** G_tokenize(const char *, const char *)
Tokenize string.
void G__split_gisprompt(const char *gisprompt, char *age, char *element, char *desc)
void check_create_import_opts(struct Option *, char *, FILE *)
void check_create_export_opts(struct Option *, char *, FILE *)
char * G__json(void)
This function generates actinia JSON process chain building blocks from the command line arguments th...
char * check_mapset_in_layer_name(char *, int)
Structure that stores flag info.
Structure that stores option information.