1
- /* $Id$
2
- *
3
- * Copyright (c) 2016-2018 by pwessel
1
+ /*
2
+ * Copyright (c) 2012-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
4
3
* See LICENSE.TXT file for copying and redistribution conditions.
5
4
*/
6
5
7
- /* gmt_custom_module.c populates the local array g_custom_module
8
- * with parameters such as name, group, purpose and keys strings.
6
+ /* gmt_custom_module.c populates the external array of GMT custom with
7
+ * module parameters such as name, group, purpose and keys strings.
9
8
* This file also contains the following convenience functions to
10
9
* display all module purposes or just list their names:
11
10
*
12
- * void gmt_custom_module_show_all (void *API);
11
+ * void gmt_custom_module_show_all (struct GMTAPI_CTRL *API);
13
12
* void gmt_custom_module_list_all (void *API);
14
13
*
15
14
* These functions may be called by gmt --help and gmt --show-modules
16
15
*
16
+ * Developers of external APIs for accessing GMT modules will use this
17
+ * function indirectly via GMT_Encode_Options to retrieve option keys
18
+ * needed for module arg processing:
19
+ *
20
+ * char * gmt_custom_module_keys (void *API, const char *module);
21
+ *
17
22
* DO NOT edit this file directly! Regenerate the file by running
18
- * gmt_make_custom_code .sh
23
+ * gmt_make_module_src .sh custom
19
24
*/
20
-
21
25
#include "gmt.h"
22
- #include "gmt_custom_module.h"
23
- #include <string.h>
24
-
25
- #ifndef gmt_M_unused
26
+ #include "gmt_notposix.h" /* Non-POSIX extensions */
26
27
#define gmt_M_unused (x ) (void)(x)
27
- #endif
28
+ #define GMT_LEN256 256
29
+ #include "gmt_supplements_module.h"
30
+ #include <string.h>
28
31
29
- /* Sorted array with information for all custom modules */
32
+ /* Sorted array with information for all GMT custom modules */
30
33
31
34
/* name, library, and purpose for each module */
32
35
struct Gmt_moduleinfo {
33
- const char * name ; /* Program name */
36
+ const char * mname ; /* Program (modern) name */
37
+ const char * cname ; /* Program (classic) name */
34
38
const char * component ; /* Component (core, supplement, custom) */
35
39
const char * purpose ; /* Program purpose */
36
40
const char * keys ; /* Program option info for external APIs */
37
41
};
38
42
43
+ static int sort_on_classic (const void * vA , const void * vB ) {
44
+ const struct Gmt_moduleinfo * A = vA , * B = vB ;
45
+ if (A == NULL ) return +1 ; /* Get the NULL entry to the end */
46
+ if (B == NULL ) return -1 ; /* Get the NULL entry to the end */
47
+ return strcmp (A -> cname , B -> cname );
48
+ }
49
+
39
50
static struct Gmt_moduleinfo g_custom_module [] = {
40
- {"gmtaverage" , "custom" , "Block average (x,y,z) data tables by mean, median, or mode estimation" , "<DI,>DO,RG- " },
41
- {"gmtmercmap" , "custom " , "Make a Mercator color map from ETOPO 1, 2, or 5 arc min global relief grids " , "CCi,>XO,RG-" },
42
- {"gmtparser" , "custom " , "Demonstrate parsing of input data, defaults, and options" , "" },
43
- {"grdfourier" , "custom " , "Create a grid, add a spike, filter it in frequency domain, and write output " , "<GI,GGO,RG-" },
44
- {NULL , NULL , NULL , NULL } /* last element == NULL detects end of array */
51
+ {"gmtaverage" , "gmtaverage" , " custom" , , "Block average (x,y,z) data tables by mean, median, or mode estimation" },
52
+ {"gmtmercmap" , "gmtmercmap " , "custom " , , },
53
+ {"gmtparser" , "gmtparser " , "custom" , , },
54
+ {"grdfourier" , "grdfourier " , "custom " , , },
55
+ {NULL , NULL , NULL , NULL , NULL } /* last element == NULL detects end of array */
45
56
};
46
57
47
58
/* Pretty print all GMT custom module names and their purposes for gmt --help */
48
59
void gmt_custom_module_show_all (void * V_API ) {
49
60
unsigned int module_id = 0 ;
50
- char message [256 ] = { "" } ;
51
- GMT_Message (V_API , GMT_TIME_NONE , "\n=== " " GMT custom: Tools for the custom project" " ===\n" );
52
- while (g_custom_module [module_id ].name != NULL ) {
61
+ char message [GMT_LEN256 ] ;
62
+ GMT_Message (V_API , GMT_TIME_NONE , "\n=== GMT custom: The custom modules of the Generic Mapping Tools ===\n" );
63
+ while (g_custom_module [module_id ].cname != NULL ) {
53
64
if (module_id == 0 || strcmp (g_custom_module [module_id - 1 ].component , g_custom_module [module_id ].component )) {
54
65
/* Start of new supplemental group */
55
- sprintf (message , "\nModule name: Purpose of %s module:\n" , g_custom_module [module_id ].component );
66
+ snprintf (message , GMT_LEN256 , "\nModule name: Purpose of %s module:\n" , g_custom_module [module_id ].component );
56
67
GMT_Message (V_API , GMT_TIME_NONE , message );
57
68
GMT_Message (V_API , GMT_TIME_NONE , "----------------------------------------------------------------\n" );
58
69
}
59
- sprintf (message , "%-16s %s\n" ,
60
- g_custom_module [module_id ].name , g_custom_module [module_id ].purpose );
61
- GMT_Message (V_API , GMT_TIME_NONE , message );
70
+ snprintf (message , GMT_LEN256 , "%-16s %s\n" ,
71
+ g_custom_module [module_id ].mname , g_custom_module [module_id ].purpose );
72
+ GMT_Message (V_API , GMT_TIME_NONE , message );
62
73
++ module_id ;
63
74
}
64
75
}
65
76
66
77
/* Produce single list on stdout of all GMT custom module names for gmt --show-modules */
67
- void gmt_custom_module_list_all (void * API ) {
78
+ void gmt_custom_module_list_all (void * V_API ) {
68
79
unsigned int module_id = 0 ;
69
- gmt_M_unused (API );
70
- while (g_custom_module [module_id ].name != NULL ) {
71
- printf ("%s\n" , g_custom_module [module_id ].name );
80
+ gmt_M_unused (V_API );
81
+ while (g_custom_module [module_id ].cname != NULL ) {
82
+ printf ("%s\n" , g_custom_module [module_id ].mname );
83
+ ++ module_id ;
84
+ }
85
+ }
86
+
87
+ /* Produce single list on stdout of all GMT custom module names for gmt --show-classic [i.e., classic mode names] */
88
+ void gmt_custom_module_classic_all (void * V_API ) {
89
+ unsigned int module_id = 0 ;
90
+ size_t n_modules = 0 ;
91
+ gmt_M_unused (V_API );
92
+
93
+ while (g_custom_module [n_modules ].cname != NULL ) /* Count the modules */
94
+ ++ n_modules ;
95
+
96
+ /* Sort array on classic names since original array is sorted on modern names */
97
+ qsort (g_custom_module , n_modules , sizeof (struct Gmt_moduleinfo ), sort_on_classic );
98
+
99
+ while (g_custom_module [module_id ].cname != NULL ) {
100
+ printf ("%s\n" , g_custom_module [module_id ].cname );
72
101
++ module_id ;
73
102
}
74
103
}
@@ -78,9 +107,9 @@ const char *gmt_custom_module_keys (void *API, char *candidate) {
78
107
int module_id = 0 ;
79
108
gmt_M_unused (API );
80
109
81
- /* Match actual_name against g_module[module_id].name */
82
- while (g_custom_module [module_id ].name != NULL &&
83
- strcmp (candidate , g_custom_module [module_id ].name ))
110
+ /* Match actual_name against g_module[module_id].cname */
111
+ while (g_custom_module [module_id ].cname != NULL &&
112
+ strcmp (candidate , g_custom_module [module_id ].cname ))
84
113
++ module_id ;
85
114
86
115
/* Return Module keys or NULL */
@@ -92,9 +121,9 @@ const char *gmt_custom_module_group (void *API, char *candidate) {
92
121
int module_id = 0 ;
93
122
gmt_M_unused (API );
94
123
95
- /* Match actual_name against g_module[module_id].name */
96
- while (g_custom_module [module_id ].name != NULL &&
97
- strcmp (candidate , g_custom_module [module_id ].name ))
124
+ /* Match actual_name against g_module[module_id].cname */
125
+ while (g_custom_module [module_id ].cname != NULL &&
126
+ strcmp (candidate , g_custom_module [module_id ].cname ))
98
127
++ module_id ;
99
128
100
129
/* Return Module keys or NULL */
0 commit comments