GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-d6dec75dd4
|
GIS Library - Argument parsing functions. More...
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <grass/gis.h>
#include <grass/spawn.h>
#include <grass/glocale.h>
#include "parser_local_proto.h"
Go to the source code of this file.
Macros | |
#define | MAX_MATCHES 50 |
Enumerations | |
enum | opt_error { BAD_SYNTAX = 1 , OUT_OF_RANGE = 2 , MISSING_VALUE = 3 , INVALID_VALUE = 4 , AMBIGUOUS = 5 , REPLACED = 6 } |
Functions | |
void | G_disable_interactive (void) |
Disables the ability of the parser to operate interactively. More... | |
struct Flag * | G_define_flag (void) |
Initializes a Flag struct. More... | |
struct Option * | G_define_option (void) |
Initializes an Option struct. More... | |
struct GModule * | G_define_module (void) |
Initializes a new module. More... | |
int | G_parser (int argc, char **argv) |
Parse command line. More... | |
char * | recreate_command (int original_path) |
Creates command to run non-interactive. More... | |
char * | G_recreate_command (void) |
Creates command to run non-interactive. More... | |
char * | G_recreate_command_original_path (void) |
Creates command to run non-interactive. More... | |
void | G_add_keyword (const char *keyword) |
Add keyword to the list. More... | |
void | G_set_keywords (const char *keywords) |
Set keywords from the string. More... | |
int | G__uses_new_gisprompt (void) |
void | G__print_keywords (FILE *fd, void(*format)(FILE *, const char *), int newline) |
Print list of keywords (internal use only) More... | |
int | G_get_overwrite (void) |
Get overwrite value. More... | |
void | G__split_gisprompt (const char *gisprompt, char *age, char *element, char *desc) |
char * | G_option_to_separator (const struct Option *option) |
Get separator string from the option. More... | |
FILE * | G_open_option_file (const struct Option *option) |
Get an input/output file pointer from the option. If the file name is omitted or '-', it returns either stdin or stdout based on the gisprompt. More... | |
void | G_close_option_file (FILE *fp) |
Close an input/output file returned by G_open_option_file(). If the file pointer is stdin, stdout, or stderr, nothing happens. More... | |
Variables | |
struct state | state |
struct state * | st = &state |
GIS Library - Argument parsing functions.
Parses the command line provided through argc and argv. Example: Assume the previous calls:
G_parser() will respond to the following command lines as described:
command (No command line arguments)
Parser enters interactive mode.
command map=map.name
Parser will accept this line. Map will be set to "map.name", the 'a' and 'b' flags will remain off and the num option will be set to the default of 5.
command -ab map=map.name num=9 command -a -b map=map.name num=9 command -ab map.name num=9 command map.name num=9 -ab command num=9 -a map=map.name -b
These are all treated as acceptable and identical. Both flags are set to on, the map option is "map.name" and the num option is "9". Note that the "map=" may be omitted from the command line if it is part of the first option (flags do not count).
command num=12
This command line is in error in two ways. The user will be told that the "map" option is required and also that the number 12 is out of range. The acceptable range (or list) will be printed.
Overview table: Parser standard options
(C) 2001-2015 by the GRASS Development Team
This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
Definition in file parser.c.
enum opt_error |
void G__print_keywords | ( | FILE * | fd, |
void(*)(FILE *, const char *) | format, | ||
int | newline | ||
) |
void G__split_gisprompt | ( | const char * | gisprompt, |
char * | age, | ||
char * | element, | ||
char * | desc | ||
) |
Definition at line 1772 of file parser.c.
References Option::gisprompt.
Referenced by G__uses_new_gisprompt().
int G__uses_new_gisprompt | ( | void | ) |
Definition at line 890 of file parser.c.
References G__split_gisprompt(), Option::gisprompt, Option::next_opt, and st.
void G_add_keyword | ( | const char * | keyword | ) |
void G_close_option_file | ( | FILE * | fp | ) |
Close an input/output file returned by G_open_option_file(). If the file pointer is stdin, stdout, or stderr, nothing happens.
file | pointer |
struct Flag* G_define_flag | ( | void | ) |
Initializes a Flag struct.
Allocates memory for the Flag structure and returns a pointer to this memory.
Flags are always represented by single letters. A user "turns them on" at the command line using a minus sign followed by the character representing the flag.
Definition at line 157 of file parser.c.
References G_malloc, G_zero(), NULL, and st.
Referenced by G_define_standard_flag().
struct GModule* G_define_module | ( | void | ) |
struct Option* G_define_option | ( | void | ) |
Initializes an Option struct.
Allocates memory for the Option structure and returns a pointer to this memory.
Options are provided by user on command line using the standard format: key=value. Options identified as REQUIRED must be specified by user on command line. The option string can either specify a range of values (e.g. "10-100") or a list of acceptable values (e.g. "red,orange,yellow"). Unless the option string is NULL, user provided input will be evaluated against this string.
Definition at line 211 of file parser.c.
References G_malloc, G_zero(), Option::multiple, NO, Option::required, and st.
Referenced by G_define_standard_option(), M_define_option(), and N_define_standard_option().
void G_disable_interactive | ( | void | ) |
Disables the ability of the parser to operate interactively.
When a user calls a command with no arguments on the command line, the parser will enter its own standardized interactive session in which all flags and options are presented to the user for input. A call to G_disable_interactive() disables the parser's interactive prompting.
Definition at line 140 of file parser.c.
References st.
int G_get_overwrite | ( | void | ) |
Get overwrite value.
Definition at line 957 of file parser.c.
References st.
Referenced by V1_open_new_ogr().
FILE* G_open_option_file | ( | const struct Option * | option | ) |
Get an input/output file pointer from the option. If the file name is omitted or '-', it returns either stdin or stdout based on the gisprompt.
Calls G_fatal_error() on error. File pointer can be later closed by G_close_option_file().
option | pointer to a file option |
Definition at line 1919 of file parser.c.
References _, Option::answer, G_fatal_error(), Option::gisprompt, Option::key, Option::multiple, and NULL.
char* G_option_to_separator | ( | const struct Option * | option | ) |
Get separator string from the option.
Calls G_fatal_error() on error. Allocated string can be later freed by G_free().
option | pointer to separator option |
Definition at line 1857 of file parser.c.
References _, Option::answer, G_debug(), G_fatal_error(), G_store(), Option::gisprompt, Option::key, and NULL.
int G_parser | ( | int | argc, |
char ** | argv | ||
) |
Parse command line.
The command line parameters argv and the number of parameters argc from the main() routine are passed directly to G_parser(). G_parser() accepts the command line input entered by the user, and parses this input according to the input options and/or flags that were defined by the programmer.
Note: The only functions which can legitimately be called before G_parser() are:
The usual order a module calls functions is:
argc | number of arguments |
argv | argument list |
Definition at line 321 of file parser.c.
References _, err(), FALSE, G_basename(), G_is_dirsep(), G_store(), G_verbose_std(), G_warning(), Option::key, NULL, Option::required, and st.
char* G_recreate_command | ( | void | ) |
Creates command to run non-interactive.
Creates a command-line that runs the current command completely non-interactive.
Definition at line 838 of file parser.c.
References FALSE, and recreate_command().
Referenced by Rast_command_history(), and Vect_hist_command().
char* G_recreate_command_original_path | ( | void | ) |
Creates command to run non-interactive.
Creates a command-line that runs the current command completely non-interactive.
This gives the same as G_recreate_command() but the original path from the command line is used instead of the module name only.
Definition at line 856 of file parser.c.
References recreate_command(), and TRUE.
void G_set_keywords | ( | const char * | keywords | ) |
Set keywords from the string.
keywords | keywords separated by commas |
Definition at line 882 of file parser.c.
References G_number_of_tokens(), G_tokenize(), and st.
char* recreate_command | ( | int | original_path | ) |
Creates command to run non-interactive.
Creates a command-line that runs the current command completely non-interactive.
original_path | TRUE if original path should be used, FALSE for stripped and clean name of the module |
Definition at line 678 of file parser.c.
Referenced by G_recreate_command(), and G_recreate_command_original_path().
Definition at line 104 of file parser.c.
Referenced by AMI_STREAM< T >::AMI_STREAM(), D_setup2(), db_d_append_error(), db_d_init_error(), db_d_report_error(), G__read_env(), G__read_gisrc_path(), G__uses_new_gisprompt(), G__write_env(), G_add_keyword(), G_area_of_cell_at_row(), G_area_of_polygon(), G_create_alt_env(), G_create_alt_search_path(), G_darea0_on_ellipsoid(), G_darea0_on_sphere(), G_define_flag(), G_define_module(), G_define_option(), G_disable_interactive(), G_distance(), G_get_available_mapsets(), G_get_gisrc_mode(), G_get_mapset_name(), G_get_overwrite(), G_is_mapset_in_search_path(), G_ls2(), G_parser(), G_percent_reset(), G_plot_fx(), G_plot_point(), G_plot_where_en(), G_reset_mapsets(), G_rhumbline_lat_from_lon(), G_set_geodesic_distance_lat1(), G_set_geodesic_distance_lat2(), G_set_keywords(), G_set_ls_exclude_filter(), G_set_ls_filter(), G_set_verbose(), G_setup_fill(), G_setup_plot(), G_switch_search_path(), G_unset_window(), G_verbose(), gsd_put_legend(), AMI_STREAM< T >::new_substream(), open_stream(), Rast_close_gdal_write_link(), Rast_create_gdal_link(), sqpAllocCol(), sqpAllocVal(), sqpFreeStmt(), sqpInitParser(), sqpInitStmt(), and sqpPrintStmt().
struct state state |
Definition at line 1 of file parser.c.
Referenced by db__add_cursor_to_driver_state(), db__close_all_cursors(), db__drop_cursor_from_driver_state(), db__get_driver_state(), db__init_driver_state(), db__mark_database_closed(), db__mark_database_open(), db__test_database_open(), G_popen_clear(), G_popen_close(), LZ4_compress_fast_extState_fastReset(), and LZ4_compress_withState().