MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / GMT_Create_Cmd

Function GMT_Create_Cmd

src/gmt_parse.c:867–936  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

865
866/*! . */
867char *GMT_Create_Cmd (void *V_API, struct GMT_OPTION *head) {
868 /* This function creates a single character string with the command line options that
869 * correspond to the linked options provided.
870 */
871
872 char *txt = NULL, *c = NULL, buffer[GMT_BUFSIZ] = {""};
873 bool first = true, skip_infiles = false;
874 int k_data;
875 size_t length = 0, inc, n_alloc = GMT_BUFSIZ;
876 struct GMT_OPTION *opt = NULL;
877 struct GMT_CTRL *G = NULL;
878 struct GMTAPI_CTRL *API = NULL;
879
880 if (V_API == NULL) return_null (V_API, GMT_NOT_A_SESSION); /* GMT_Create_Session has not been called */
881 if (head == NULL) return_null (V_API, GMT_OPTION_LIST_NULL); /* No list of options was given */
882 API = gmtparse_get_api_ptr (V_API); /* Cast void pointer to a GMTAPI_CTRL pointer */
883
884 G = API->GMT; /* GMT control structure */
885 if ((txt = gmt_M_memory (G, NULL, n_alloc, char)) == NULL) return NULL;
886
887 for (opt = head; opt; opt = opt->next) { /* Loop over all options in the linked list */
888 if (!opt->option) continue; /* Skip all empty options */
889 if (opt->option == GMT_OPT_SYNOPSIS) /* Produce special - option for synopsis */
890 sprintf (buffer, "-");
891 else if (opt->option == '=' && opt->arg[0]) { /* Special list file, add it but not the files that follow */
892 snprintf (buffer, GMT_BUFSIZ, "=%s", opt->arg);
893 skip_infiles = true;
894 }
895 else if (opt->option == GMT_OPT_INFILE) { /* Option for input filename [or numbers] */
896 if (skip_infiles) continue;
897 if (gmt_file_is_tiled_list (API, opt->arg, &k_data, NULL, NULL)) { /* Want to replace the tiled list with the original @remotefile name instead */
898 snprintf (buffer, GMT_BUFSIZ, "@%s", API->remote_info[k_data].file);
899 }
900 else if ((k_data = gmt_remote_dataset_id (API, opt->arg)) != GMT_NOTSET && API->remote_info[k_data].ext[0] && (c = strstr (opt->arg, API->remote_info[k_data].ext))) {
901 c[0] = '\0'; /* Remove extension on remote file */
902 snprintf (buffer, GMT_BUFSIZ, "%s", opt->arg);
903 c[0] = '.';
904 }
905 else
906 snprintf (buffer, GMT_BUFSIZ, "%s", opt->arg);
907 }
908 else if (opt->arg && opt->arg[0]) { /* Regular -?arg commandline option with argument for some ? */
909 if (strchr (opt->arg, ' ')) /* Has a space in the argument, e.g., a title or similar */
910 snprintf (buffer, GMT_BUFSIZ, "-%c\"%s\"", opt->option, opt->arg);
911 else
912 snprintf (buffer, GMT_BUFSIZ, "-%c%s", opt->option, opt->arg);
913 }
914 else /* Regular -? commandline argument without argument */
915 snprintf (buffer, GMT_BUFSIZ, "-%c", opt->option);
916
917 inc = strlen (buffer);
918 if (!first) inc++; /* Count the space between args */
919 if ((length + inc) >= n_alloc) { /* Will need more memory */
920 n_alloc <<= 1;
921 if ((txt = gmt_M_memory (G, txt, n_alloc, char)) == NULL) return NULL;
922 }
923 if (!first) strcat (txt, " "); /* Add space between args */
924 strcat (txt, buffer);

Callers 15

GMT_insetFunction · 0.85
GMT_figureFunction · 0.85
gmt_change_grid_historyFunction · 0.85
gmtapi_update_grd_itemFunction · 0.85
gmtapi_update_txt_itemFunction · 0.85
GMT_Call_ModuleFunction · 0.85
GMT_Encode_OptionsFunction · 0.85
gmt_init.cFile · 0.85
gmt_init_moduleFunction · 0.85
GMT_subplotFunction · 0.85

Calls 3

gmtparse_get_api_ptrFunction · 0.85
gmt_file_is_tiled_listFunction · 0.85
gmt_remote_dataset_idFunction · 0.85

Tested by

no test coverage detected