106 | | 8. Module exit status is defined as `EXIT_SUCCESS` or `EXIT_FAILURE` |
107 | | (declared in `stdlib.h`), e.g. |
108 | | |
109 | | {{{ |
110 | | { |
111 | | ... |
112 | | if (G_parser (argc, argv)) |
113 | | exit (EXIT_FAILURE); |
114 | | |
115 | | ... |
116 | | exit (EXIT_SUCCESS); |
117 | | } |
118 | | }}} |
119 | | |
120 | | 9. Use `fprintf()` instead of `printf()`. For errors and warnings please use the `G_fatal_error()` and `G_warning()` functions. General messages for the user should use `G_message()` while debug messages should use `G_debug()` whenever possible. |
121 | | |
122 | | There are two variants to `G_message()`: `G_verbose_message()` which will only display the message if in `--verbose` mode, and `G_important_message()` which will always show the message unless the module is running in `--quiet` mode. `G_fatal_error()` and `G_warning()` will always be displayed regardless of verbosity setting. Messages sent to any of these functions will be printed to stderr. |
123 | | |
124 | | `G_message()` output is not expected to be sent to pipe or file. |
125 | | |
126 | | Always use the gettext macros with `_("")` for user messages, example: |
127 | | {{{ |
128 | | G_fatal_error(_("Vector map <%s> not found"), name); |
129 | | }}} |
130 | | It is suggested to add a comment line before translatable user message to give a hint to translators about meaning or use of cumbersome or obscure message. First word in the comment must be GTC - GRASS translation comment, |
131 | | |
132 | | Example: |
133 | | {{{ |
134 | | /* GTC A name of a projection */ |
135 | | G_message(_("State Plane")); |
136 | | }}} |
137 | | Any message with a noun in plural form has to pass _n() macro, even if for the English language it is not required! |
138 | | {{{ |
139 | | G_message(_n("One map", "%d maps", number), number); |
140 | | }}} |
141 | | See source:grass/trunk/locale/README for details. |
142 | | |
143 | | |
144 | | Pipe/file data output: For data output redirected to pipe or file, please use `fprintf()` and specify the stdout stream as follows: |
145 | | {{{ |
146 | | fprintf(stdout, ...); |
147 | | fflush(stdout); |
148 | | |
149 | | fflush(stdout) /* always required when using fprintf(stdout, ...). */ |
150 | | }}} |
151 | | |
152 | | 10. Use the GRASS library function `G_asprintf()` instead of the standard C functions `asprintf()`, `vsnprintf()` and `snprintf()`. These functions are not portable or have other issues. Example: |
| 110 | === G_asprintf() === |
| 111 | |
| 112 | Use the GRASS library function `G_asprintf()` instead of the standard C functions `asprintf()`, `vsnprintf()` and `snprintf()`. These functions are not portable or have other issues. Example: |
198 | | |
199 | | 15. To promote a consistent coding style, please use the "indent" program on all new C modules using the following switches: |
200 | | {{{ |
201 | | $ indent -bad -bap -bbb -br -bli0 -bls -cli0 -ncs -fc1 -hnl -i4 \ |
202 | | -nbbo -nbc -nbfda -nbfde -ncdb -ncdw -nce -nfca -npcs -nprs \ |
203 | | -npsl -nsc -nsob -saf -sai -saw -sbi0 -ss -ts8 -ut main.c |
204 | | }}} |
205 | | Existing code should not be re-indented except in extreme cases, as this will make "diff" comparisons with older versions impossible. If indent is needed, do not check in any changes other than the indentation in the same commit! Do add the indent switches and any indent warning messages to the SVN log. Any change or fix mixed in with an indent is very hard to track making it hard for others to follow the change or fix any new bugs. For your convenience use the source:grass/trunk/tools/grass_indent.sh script. |
206 | | |
207 | | |
208 | | 16. Platform dependent code: |
209 | | Do not remove `#ifdef __CYGWIN__` and/or `#ifndef __CYGWIN__` lines and their encapsulated lines from source code (one example was that someone removed `drand48` definition.) |
210 | | |
211 | | |
212 | | 17. Suggested compiler flags: |
213 | | We suggest to use very strict compiler flags to capture errors at the very beginning. Here our list of flags, please use them to configure you development version of GRASS: |
214 | | |
215 | | GNU/Linux: |
216 | | {{{ |
217 | | MYCFLAGS="-g -Wall -Werror-implicit-function-declaration -fno-common" |
218 | | MYCXXFLAGS="-g -Wall" |
219 | | |
220 | | CFLAGS="$MYCFLAGS" CXXFLAGS="$MYCXXFLAGS" ./configure ... |
221 | | }}} |
222 | | MacOSX: [to be suggested] |
223 | | |
224 | | MS-Windows: [to be suggested] |
225 | | |
226 | | |
227 | | 21. Have a function included in your module which writes to the history file of the map (e.g. command line, parameters etc.). See e.g. source:grass/trunk/raster/r.patch/main.c (the same applies to vector and raster3d modules!) |
228 | | |
229 | | |
230 | | 22. Standard parser options: use `G_define_standard_option()` whenever possible to define standard module command line options. This will save you time, create fewer bugs, and make things easier on the translators. |
231 | | See source:grass/trunk/lib/gis/parser_standard_options.c for details of the function definition. |
232 | | |
233 | | |
234 | | 23. Add/update, if required the related GUI menus: |
235 | | {{{ |
236 | | gui/wxpython/xml/menudata.xml |
237 | | }}} |
238 | | |
239 | | |
240 | | 30. Use doxygen style for source code documentation. It is required for GRASS libraries, but also recommended for GRASS modules. |
| 161 | === Documentation in Doxygen === |
| 162 | |
| 163 | Use doxygen style for source code documentation. It is required for GRASS libraries, but also recommended for GRASS modules. |
277 | | ... |
278 | | |
279 | | ''[please add further hints if required]''' |
280 | | |
281 | | ''Your attention to detail is appreciated.'' |
| 200 | == Modules == |
| 201 | |
| 202 | === Returning Value Of Main function === |
| 203 | |
| 204 | Module exit status is defined as `EXIT_SUCCESS` or `EXIT_FAILURE` |
| 205 | (declared in `stdlib.h`), e.g. |
| 206 | |
| 207 | {{{ |
| 208 | { |
| 209 | ... |
| 210 | if (G_parser (argc, argv)) |
| 211 | exit (EXIT_FAILURE); |
| 212 | |
| 213 | ... |
| 214 | exit (EXIT_SUCCESS); |
| 215 | } |
| 216 | }}} |
| 217 | |
| 218 | === Messages === |
| 219 | |
| 220 | Use `fprintf()` instead of `printf()`. For errors and warnings please use the `G_fatal_error()` and `G_warning()` functions. General messages for the user should use `G_message()` while debug messages should use `G_debug()` whenever possible. |
| 221 | |
| 222 | There are two variants to `G_message()`: `G_verbose_message()` which will only display the message if in `--verbose` mode, and `G_important_message()` which will always show the message unless the module is running in `--quiet` mode. `G_fatal_error()` and `G_warning()` will always be displayed regardless of verbosity setting. Messages sent to any of these functions will be printed to stderr. |
| 223 | |
| 224 | `G_message()` output is not expected to be sent to pipe or file. |
| 225 | |
| 226 | Always use the gettext macros with `_("")` for user messages, example: |
| 227 | {{{ |
| 228 | G_fatal_error(_("Vector map <%s> not found"), name); |
| 229 | }}} |
| 230 | It is suggested to add a comment line before translatable user message to give a hint to translators about meaning or use of cumbersome or obscure message. First word in the comment must be GTC - GRASS translation comment, |
| 231 | |
| 232 | Example: |
| 233 | {{{ |
| 234 | /* GTC A name of a projection */ |
| 235 | G_message(_("State Plane")); |
| 236 | }}} |
| 237 | Any message with a noun in plural form has to pass _n() macro, even if for the English language it is not required! |
| 238 | {{{ |
| 239 | G_message(_n("One map", "%d maps", number), number); |
| 240 | }}} |
| 241 | See source:grass/trunk/locale/README for details. |
| 242 | |
| 243 | |
| 244 | Pipe/file data output: For data output redirected to pipe or file, please use `fprintf()` and specify the stdout stream as follows: |
| 245 | {{{ |
| 246 | fprintf(stdout, ...); |
| 247 | fflush(stdout); |
| 248 | |
| 249 | fflush(stdout) /* always required when using fprintf(stdout, ...). */ |
| 250 | }}} |
| 251 | |
| 252 | === Map History === |
| 253 | |
| 254 | Have a function included in your module which writes to the history file of the map (e.g. command line, parameters etc.). See e.g. source:grass/trunk/raster/r.patch/main.c (the same applies to vector and raster3d modules!) |
| 255 | |
| 256 | === Standardized Options and Flags === |
| 257 | |
| 258 | Standard parser options: use `G_define_standard_option()` whenever possible to define standard module command line options. This will save you time, create fewer bugs, and make things easier on the translators. |
| 259 | See source:grass/trunk/lib/gis/parser_standard_options.c for details of the function definition. |
| 260 | |
| 261 | == Indentation == |
| 262 | |
| 263 | 15. To promote a consistent coding style, please use the "indent" program on all new C modules using the following switches: |
| 264 | {{{ |
| 265 | $ indent -bad -bap -bbb -br -bli0 -bls -cli0 -ncs -fc1 -hnl -i4 \ |
| 266 | -nbbo -nbc -nbfda -nbfde -ncdb -ncdw -nce -nfca -npcs -nprs \ |
| 267 | -npsl -nsc -nsob -saf -sai -saw -sbi0 -ss -ts8 -ut main.c |
| 268 | }}} |
| 269 | Existing code should not be re-indented except in extreme cases, as this will make "diff" comparisons with older versions impossible. If indent is needed, do not check in any changes other than the indentation in the same commit! Do add the indent switches and any indent warning messages to the SVN log. Any change or fix mixed in with an indent is very hard to track making it hard for others to follow the change or fix any new bugs. For your convenience use the source:grass/trunk/tools/grass_indent.sh script. |
| 270 | |
| 271 | == Compilation == |
| 272 | |
| 273 | Platform dependent code: |
| 274 | Do not remove `#ifdef __CYGWIN__` and/or `#ifndef __CYGWIN__` lines and their encapsulated lines from source code (one example was that someone removed `drand48` definition.) |
| 275 | |
| 276 | === Compiler Flags === |
| 277 | |
| 278 | Suggested compiler flags: |
| 279 | We suggest to use very strict compiler flags to capture errors at the very beginning. Here our list of flags, please use them to configure you development version of GRASS: |
| 280 | |
| 281 | GNU/Linux: |
| 282 | {{{ |
| 283 | MYCFLAGS="-g -Wall -Werror-implicit-function-declaration -fno-common" |
| 284 | MYCXXFLAGS="-g -Wall" |
| 285 | |
| 286 | CFLAGS="$MYCFLAGS" CXXFLAGS="$MYCXXFLAGS" ./configure ... |
| 287 | }}} |
| 288 | MacOSX: [to be suggested] |
| 289 | |
| 290 | MS-Windows: [to be suggested] |