! . */
| 12799 | |
| 12800 | /*! . */ |
| 12801 | int GMT_Call_Module (void *V_API, const char *module, int mode, void *args) { |
| 12802 | /* Call the specified shared module and pass it the mode and args. |
| 12803 | * mode can be one of the following: |
| 12804 | * GMT_MODULE_CLASSIC [-7]: As GMT_MODULE_PURPOSE, but only lists the classic modules. |
| 12805 | * GMT_MODULE_LIST [-6]: As GMT_MODULE_PURPOSE, but only lists the modern modules. |
| 12806 | * GMT_MODULE_CLASSIC_CORE [-5]: As GMT_MODULE_PURPOSE, but only lists the classic modules (core only). |
| 12807 | * GMT_MODULE_LIST_CORE [-4]: As GMT_MODULE_PURPOSE, but only lists the modern modules (core only). |
| 12808 | * GMT_MODULE_EXIST [-3]: Return GMT_NOERROR (0) if module exists, GMT_NOT_A_VALID_MODULE otherwise. |
| 12809 | * GMT_MODULE_PURPOSE [-2]: As GMT_MODULE_EXIST, but also print the module purpose. |
| 12810 | * GMT_MODULE_OPT [-1]: Args is a linked list of option structures. |
| 12811 | * GMT_MODULE_CMD [0]: Args is a single textstring with multiple options |
| 12812 | * mode > 0: Args is an array of text strings (e.g., argv[]). |
| 12813 | */ |
| 12814 | int status = GMT_NOERROR; |
| 12815 | unsigned int lib; |
| 12816 | struct GMTAPI_CTRL *API = NULL; |
| 12817 | char gmt_module[GMT_LEN64] = "GMT_"; |
| 12818 | int (*p_func)(void*, int, void*) = NULL; /* function pointer */ |
| 12819 | |
| 12820 | if (V_API == NULL) return_error (V_API, GMT_NOT_A_SESSION); |
| 12821 | if (module == NULL && !(mode == GMT_MODULE_LIST || mode == GMT_MODULE_LIST_CORE || mode == GMT_MODULE_CLASSIC || mode == GMT_MODULE_CLASSIC_CORE || mode == GMT_MODULE_PURPOSE)) |
| 12822 | return_error (V_API, GMT_ARG_IS_NULL); |
| 12823 | API = gmtapi_get_api_ptr (V_API); |
| 12824 | API->error = GMT_NOERROR; |
| 12825 | |
| 12826 | if (module == NULL) { /* Did not specify any specific module, so list purpose of all modules in all shared libs */ |
| 12827 | char gmt_module[GMT_LEN256] = {""}; /* To form name of gmt_<lib>_module_show|list_all function */ |
| 12828 | char *listfunc = (mode == GMT_MODULE_LIST || mode == GMT_MODULE_LIST_CORE) ? "list" : ( (mode == GMT_MODULE_CLASSIC || mode == GMT_MODULE_CLASSIC_CORE) ? "classic" : "show"); |
| 12829 | void (*l_func)(void*); /* function pointer to gmt_<lib>_module_show|list_all which takes one arg (the API) */ |
| 12830 | unsigned int n_libs = (mode == GMT_MODULE_LIST_CORE || mode == GMT_MODULE_CLASSIC_CORE) ? 1 : API->n_shared_libs; |
| 12831 | /* Here we list purpose of all the available modules in each shared library */ |
| 12832 | for (lib = 0; lib < n_libs; lib++) { |
| 12833 | snprintf (gmt_module, GMT_LEN64, "%s_module_%s_all", API->lib[lib].name, listfunc); |
| 12834 | *(void **) (&l_func) = gmtapi_get_module_func (API, gmt_module, lib); |
| 12835 | if (l_func == NULL) continue; /* Not found in this shared library */ |
| 12836 | (*l_func) (V_API); /* Run this function */ |
| 12837 | } |
| 12838 | return (status); |
| 12839 | } |
| 12840 | |
| 12841 | /* Here we call a named module */ |
| 12842 | |
| 12843 | strncat (gmt_module, module, GMT_LEN64-5); /* Concatenate GMT_-prefix and module name to get function name */ |
| 12844 | for (lib = 0; lib < API->n_shared_libs; lib++) { /* Look for gmt_module in any of the shared libs */ |
| 12845 | *(void **) (&p_func) = gmtapi_get_module_func (API, gmt_module, lib); |
| 12846 | if (p_func) break; /* Found it in this shared library */ |
| 12847 | } |
| 12848 | if (p_func == NULL) { /* Not in any of the shared libraries */ |
| 12849 | status = GMT_NOT_A_VALID_MODULE; /* Most likely, but we will try again: */ |
| 12850 | if (strncasecmp (module, "gmt", 3)) { /* For any module not already starting with "gmt..." */ |
| 12851 | char gmt_module[GMT_LEN64] = "gmt"; |
| 12852 | strncat (gmt_module, module, GMT_LEN64-4); /* Prepend "gmt" to module and try again */ |
| 12853 | status = GMT_Call_Module (V_API, gmt_module, mode, args); /* Recursive call to try with the 'gmt' prefix this time */ |
| 12854 | } |
| 12855 | } |
| 12856 | else if (mode == GMT_MODULE_EXIST) /* Just wanted to know it is a valid module */ |
| 12857 | return (GMT_NOERROR); |
| 12858 | else { /* Call the function and pass back its return value */ |