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

Function GMT_docs

src/docs.c:71–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69#define Return(code) {gmt_end_module (GMT, GMT_cpy); bailout (code);}
70
71EXTERN_MSC int GMT_docs (void *V_API, int mode, void *args) {
72 bool other_file = false, print_url = false, got_file = false, called = false, remote = false, direct_URL = false;
73 int error = 0, id;
74 size_t vlen = 0;
75 char cmd[PATH_MAX] = {""}, view[PATH_MAX] = {""}, URL[PATH_MAX] = {""}, module[GMT_LEN64] = {""}, name[PATH_MAX] = {""}, *t = NULL, *ext = NULL;
76 const char *group = NULL, *docname = NULL;
77 char *ps_viewer = NULL;
78 static const char *known_group[2] = {"core", "other"};
79 static const char *known_doc[9] = {"gmtcolors", "reference", "api", "tutorial", "gallery", GMT_SETTINGS_FILE, "gmt", "datasets", "index"};
80 struct GMT_CTRL *GMT = NULL, *GMT_cpy = NULL;
81 struct GMT_OPTION *options = NULL, *opt = NULL;
82 struct GMTAPI_CTRL *API = gmt_get_api_ptr (V_API); /* Cast from void to GMTAPI_CTRL pointer */
83
84 /*----------------------- Standard module initialization and parsing ----------------------*/
85
86#ifdef WIN32
87 HKEY hkey; /* Handle to registry key */
88 static const char *file_viewer = "cmd /c start";
89 bool together = false; /* Must call file_viewer separately on each file */
90 long RegO = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.ps\\UserChoice", 0, KEY_READ, &hkey);
91 if (RegO == ERROR_SUCCESS) /* User has postscript viewer installed */
92 ps_viewer = (char *)file_viewer;
93 else
94 ps_viewer = "cmd /c start gswin64c"; /* No previewer. Resort to this. */
95#elif defined(__APPLE__)
96 static const char *file_viewer = "open";
97 bool together = true; /* Can call file_viewer once with all files */
98 ps_viewer = (char *)file_viewer;
99#else
100 static const char *file_viewer = "xdg-open";
101 bool together = false; /* Must call file_viewer separately on each file */
102 ps_viewer = (char *)file_viewer;
103#endif
104
105 if (API == NULL) return (GMT_NOT_A_SESSION);
106 if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */
107 options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */
108 /* Here we do not want to call GMT_Parse_Common since common options may be passed as sections in the docs */
109 if ((error = gmt_report_usage (API, options, 0, usage)) != GMT_NOERROR) bailout (error); /* Give usage if requested */
110
111 /* Parse the command-line arguments */
112
113 if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
114
115 /*---------------------------- This is the docs main code ----------------------------*/
116
117 opt = options; /* Start at first option to gmt docs */
118
119 while (opt) { /* For all possible arguments */
120 if (opt->option == 'Q') { print_url = true, opt = opt->next; continue; } /* Process optional -Q option which must be first (or maybe second if -S also) */
121 else if (opt->option == 'S') { remote = true, opt = opt->next; continue; } /* Process optional -S option which is either first or second (if -Q) */
122 else if (opt->option == 'V') { opt = opt->next; continue; } /* Skip the optional -V common option */
123
124 if (opt->option != GMT_OPT_INFILE) { /* This is not good */
125 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Unknown option (-%c)\n", opt->option);
126 Return (GMT_RUNTIME_ERROR);
127 }
128

Callers

nothing calls this directly

Calls 15

gmt_get_api_ptrFunction · 0.85
GMT_Create_OptionsFunction · 0.85
gmt_report_usageFunction · 0.85
gmt_init_moduleFunction · 0.85
GMT_ReportFunction · 0.85
gmt_get_extFunction · 0.85
gmt_get_graphics_idFunction · 0.85
gmt_filename_getFunction · 0.85
gmt_check_executableFunction · 0.85
gmt_current_nameFunction · 0.85
gmt_get_full_nameFunction · 0.85
strdupFunction · 0.85

Tested by

no test coverage detected