18 #include <grass/glocale.h>
19 #include <grass/gis.h>
21 #include "parser_local_proto.h"
192 char *file_name =
NULL;
194 int random_int = rand();
202 char desc[KEYLENGTH];
207 fp = fopen(file_name,
"w+");
209 fprintf(stderr,
"Unable to open temporary file <%s>\n", file_name);
216 for (flag = &
st->first_flag; flag; flag = flag->next_flag) {
226 for (opt = &
st->first_option; opt; opt = opt->next_opt) {
228 if (opt->gisprompt) {
251 if (
st->n_flags && num_flags > 0) {
255 fprintf(fp,
" \"flags\":\"");
257 for (flag = &
st->first_flag; flag; flag = flag->next_flag) {
259 fprintf(fp,
"%c", flag->key);
266 if (
st->n_opts && num_inputs > 0) {
271 fprintf(fp,
" \"inputs\":[\n");
272 for (opt = &
st->first_option; opt; opt = opt->next_opt) {
273 if (opt->gisprompt) {
279 if (i < num_inputs) {
288 else if (opt->answer) {
290 fprintf(fp,
" {\"param\": \"%s\", ", opt->key);
291 fprintf(fp,
"\"value\": \"%s\"}", opt->answer);
293 if (i < num_inputs) {
306 if (
st->n_opts && num_outputs > 0) {
311 fprintf(fp,
" \"outputs\":[\n");
312 for (opt = &
st->first_option; opt; opt = opt->next_opt) {
313 if (opt->gisprompt) {
319 if (i < num_outputs) {
336 fp = fopen(file_name,
"r");
338 fprintf(stderr,
"Unable to open temporary file <%s>\n", file_name);
344 fprintf(stdout,
"%c", c);
362 int i = 0, urlfound = 0;
366 G_debug(2,
"tokenize opt string: <%s> with '@'", opt->answer);
373 G_fatal_error(_(
"Input string not understood: <%s>. Multiple '@' chars?"),
378 G_debug(2,
"tokens[1]: <%s>", tokens[1]);
379 if (strncmp(tokens[1],
"http://", 7) == 0 ||
380 strncmp(tokens[1],
"https://", 8) == 0 ||
381 strncmp(tokens[1],
"ftp://", 6) == 0) {
387 G_debug(2,
"name@mapset found");
393 if (i > 1 && urlfound == 1) {
396 "\"import_descr\": {\"source\":\"%s\", \"type\":\"raster\"},\n ",
402 "\"import_descr\": {\"source\":\"%s\", \"type\":\"file\"},\n ",
408 "\"import_descr\": {\"source\":\"%s\", \"type\":\"vector\"},\n ",
414 fprintf(fp,
"\"param\": \"%s\", ", opt->key);
417 fprintf(fp,
"\"value\": \"%s\"",
421 fprintf(fp,
"\"value\": \"%s\"",
444 int has_file_export = 0;
458 "\"export\": {\"format\":\"%s\", \"type\":\"raster\"},\n ",
463 "\"export\": {\"format\":\"%s\", \"type\":\"file\"},\n ",
469 "\"export\": {\"format\":\"%s\", \"type\":\"vector\"},\n ",
474 fprintf(fp,
"\"param\": \"%s\", ", opt->key);
475 if (has_file_export == 1) {
476 fprintf(fp,
"\"value\": \"$file::%s\"",
480 fprintf(fp,
"\"value\": \"%s\"",
511 if (always_remove == 1)
int G_debug(int level, const char *msg,...)
Print debugging message.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
const char * G_mapset(void)
Get current mapset name.
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)
const char * G_program_name(void)
Return module name.
int G_strncasecmp(const char *x, const char *y, int n)
String compare ignoring case (upper or lower) - limited number of characters.
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
char * G_chop(char *line)
Chop leading and trailing white spaces.
char * G_tempfile(void)
Returns a temporary file name.
void G_free_tokens(char **tokens)
Free memory allocated to tokens.
char ** G_tokenize(const char *buf, const char *delim)
Tokenize string.