SUBMITTING 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. NOTE: Please improve this list!
  2. Dear (new) GRASS developer,
  3. when submitting C code to GRASS SVN repository, please take care of
  4. following rules:
  5. [ see also SUBMITTING_PYTHON for Python code hints ]
  6. [ see alse SUBMITTING_DOCS for documentation ]
  7. 1. Get and read the GRASS Programmer's Manual here:
  8. http://grass.osgeo.org/programming7/
  9. or generate it from this source code (the programmer's manual is
  10. integrated in the source code in doxygen style):
  11. make htmldocs
  12. make pdfdocs
  13. 2. Use the directory structure to place your module appropriately into
  14. the source tree
  15. - libes go into lib/
  16. - raster modules go into raster/
  17. - vector modules go into vector/
  18. - ...
  19. Consider to take a look at "GNU Coding Standards"
  20. http://www.gnu.org/prep/standards.html
  21. 3. Add a header section to each file you submit and make sure you
  22. include the copyright. The purpose section is meant to contain a
  23. general overview of the code in the file to assist other
  24. programmers that will need to make changes to your code. If you
  25. are modifying an existing file you may under no circumstances
  26. remove prior copyright or licensing text that is not your own,
  27. even for a major rewrite. If any original code or code that is in
  28. part derived from another's original work remains, it must be
  29. properly cited.
  30. Example (ficticious header for a file called color.c) :
  31. /****************************************************************************
  32. *
  33. * MODULE: g.foo
  34. * AUTHOR(S): John Doe <jdoe at somewhere org>
  35. * PURPOSE: Provide short description of module here...
  36. * COPYRIGHT: (C) 2010 by John Doe, and the GRASS Development Team
  37. *
  38. * This program is free software under the GNU General Public
  39. * License (>=v2). Read the COPYING file that comes with GRASS
  40. * for details.
  41. *
  42. *****************************************************************************/
  43. The copyright protects your rights according to GNU General Public
  44. License (www.gnu.org).
  45. 4. We don't want the $ID$ in source code any more as it causes problems
  46. for the SVN branches.
  47. 5. To ensure that the software system continues to work, please include
  48. #include <grass/config.h>
  49. in your files and make use of the various system dependencies
  50. contained therein. As one example of this, see lib/gmath/fft.c.
  51. Please refrain from declaring system functions within the
  52. software; include the proper header files (conditionally dependent
  53. on config.h macros if necessary) instead.
  54. 6. Order of include headers
  55. In general, headers should be included in the order:
  56. 1. Core system headers (stdio.h, ctype.h, ...)
  57. 2. Headers for non-core system components (X11, libraries).
  58. 3. Headers for core systems of the package being compiled (grass/gis.h, grass/glocale.h, ...)
  59. 4. Headers for the specific library/program being compiled (geodesic.h, ...)
  60. Each class of header has an obligation to be compatible with those
  61. above it in the list, but not those below it.
  62. 7. Always specify the return type for ALL functions including those that
  63. return type "void", and insert return statements for any function
  64. which returns a value.
  65. Also, use ANSI C prototypes to declare your functions.
  66. For module return values, see "Exit status" below.
  67. Examples:
  68. void G_something(void);
  69. int G_something_else(int, int);
  70. void G_something(void)
  71. {
  72. /* Snipped out code */
  73. return;
  74. }
  75. int G_something_else(int x, int y)
  76. {
  77. /* Snipped out code */
  78. return 0;
  79. }
  80. 8. Module exit status is defined as EXIT_SUCCESS or EXIT_FAILURE
  81. (declared in stdlib.h), e.g.
  82. {
  83. ...
  84. if (G_parser (argc, argv))
  85. exit (EXIT_FAILURE);
  86. ...
  87. exit (EXIT_SUCCESS);
  88. }
  89. 9. Use fprintf() instead of printf()
  90. For errors and warnings please use the G_fatal_error() and
  91. G_warning() functions. General messages for the user should use
  92. G_message() while debug messages should use G_debug() whenever
  93. possible. There are two variants to G_message(): G_verbose_message()
  94. which will only display the message if in --verbose mode, and
  95. G_important_message() which will always show the message unless
  96. the module is running in --quiet mode. G_fatal_error() and
  97. G_warning() will always be displayed regardless of verbosity setting.
  98. Messages sent to any of these functions will be printed to stderr.
  99. G_message() output is not expected to be sent to pipe or file.
  100. Always use the gettext macros with _("") for user messages,
  101. example:
  102. G_fatal_error(_("Vector map <%s> not found"), name);
  103. Pipe/file data output:
  104. For data output redirected to pipe or file, please use fprintf() and
  105. specify the stdout stream as follows:
  106. fprintf(stdout, ...);
  107. fflush(stdout);
  108. fflush(stdout) always required when using fprintf(stdout, ...).
  109. 10. Use the GRASS library function G_asprintf() instead of the
  110. standard C functions asprintf(), vsnprintf() and snprintf(). These
  111. functions are not portable or have other issues. Example:
  112. char *msg;
  113. G_asprintf(&msg, "%s", parameters);
  114. do_something_with_msg();
  115. G_free(msg);
  116. Note that you should free memory when G_asprintf() is used.
  117. 11. Use the following GRASS library functions instead of the standard C
  118. functions. The reason for this is that the following functions ensure
  119. good programming practice (e.g. always checking if memory was allocated)
  120. and/or improves portability. PLEASE refer to the programmers manual
  121. for the proper use (e.g. determining if any casts are needed for arguments
  122. or return values) of these library functions. They may perform a task
  123. slightly different from their corresponding C library function, and thus,
  124. their use may not be the same.
  125. G_malloc() instead of malloc()
  126. G_calloc() instead of calloc()
  127. G_realloc() instead of realloc()
  128. G_free() instead of free()
  129. G_getenv() instead of getenv()
  130. G_setenv() instead of setenv()
  131. G_unsetenv() instead of unsetenv()
  132. G_sleep() instead of sleep()
  133. Could somebody please add others (please verify that they are
  134. useful and safe first)
  135. 12. Use function names which fulfill the official GNU naming convention.
  136. http://www.gnu.org/prep/standards/html_node/Names.html#Names
  137. Instead of naming a function like: MyNewFunction() use underscores
  138. for seperation and lower case letters: my_new_function().
  139. 13. Don't use the C++ comment style! This confuses several compilers.
  140. Use instead:
  141. /* C-comments */
  142. If you want to comment code portions, use
  143. #ifdef notdef
  144. portion_to_be_commented;
  145. #endif
  146. This is safe comparing to nested /* comments */
  147. Functions in the library must be documented in doxygen style to
  148. get them into the programmer's manual (generate with
  149. make pdfdocs or
  150. make htmldocs
  151. ). See lib/gis/*.c for examples.
  152. 14. PLEASE take the time to add comments throughout your code explaining what
  153. the code is doing. It will save a HUGE amount of time and frustration for
  154. other programmers that may have to change your code in the future.
  155. 15. To promote a consistent coding style, please use the "indent" program
  156. on all new C modules using the following switches:
  157. $ indent -bad -bap -bbb -br -bli0 -bls -cli0 -ncs -fc1 -hnl -i4 \
  158. -nbbo -nbc -nbfda -nbfde -ncdb -ncdw -nce -nfca -npcs -nprs \
  159. -npsl -nsc -nsob -saf -sai -saw -sbi0 -ss -ts8 -ut main.c
  160. Existing code should not be re-indented except in extreme cases, as this
  161. will make "diff" comparisons with older versions impossible. If indent is
  162. needed, do not check in any changes other than the indentation in the same
  163. commit! Do add the indent switches and any indent warning messages to the
  164. SVN log. Any change or fix mixed in with an indent is very hard to track
  165. making it hard for others to follow the change or fix any new bugs.
  166. For your convenience use the tools/grass_indent.sh script.
  167. 16. Platform dependent code:
  168. Do not remove #ifdef __CYGWIN__ and/or #ifndef __CYGWIN__ lines and
  169. their encapsulated lines from source code (one example was that someone
  170. removed drand48 definition.)
  171. 17. Suggested compiler flags:
  172. We suggest to use very strict compiler flags to capture errors
  173. at the very beginning. Here our list of flags, please use them
  174. to configure you development version of GRASS:
  175. GNU/Linux:
  176. MYCFLAGS="-g -Wall -Werror-implicit-function-declaration -fno-common"
  177. MYCXXFLAGS="-g -Wall"
  178. CFLAGS="$MYCFLAGS" CXXFLAGS="$MYCXXFLAGS" ./configure ...
  179. MacOSX: [to be suggested]
  180. MS-Windows: [to be suggested]
  181. 18. Make sure a new line is at the end of each file and UNIX style newlines
  182. are used (\n).
  183. 19. When writing Makefiles, use the current standard.
  184. If you have to use commands, please check for:
  185. avoid | use instead
  186. ------------------+---------------
  187. make target | $(MAKE) target
  188. mkdir target | $(MKDIR) target
  189. cp (executable) | $(INSTALL) -m 755 file target
  190. cp (normal file) | $(INSTALL) -m 644 file target
  191. ar | $(AR)
  192. rm: be VERY careful with recursive remove. Also beware of
  193. removing $(FOO)* if $(FOO) has any chance of being empty.
  194. Examples: see below examples or others
  195. raster/r.info/Makefile
  196. vector/v.edit/Makefile
  197. If you are unsure, please ask on the GRASS Developers list.
  198. 20. Have a look at ./INSTALL
  199. 21. Have a function included in your module which writes to the history
  200. file of the map (e.g. command line, parameters etc.). See e.g.
  201. raster/r.patch/main.c
  202. (the same applies to vector and g3d modules!)
  203. 22. Standard parser options: use G_define_standard_option() whenever possible
  204. to define standard module command line options. This will save you time,
  205. create fewer bugs, and make things easier on the translators.
  206. See lib/gis/parser.c for details of the function definition.
  207. 23. Add/update, if required the related GUI menus:
  208. gui/wxpython/xml/menudata.xml
  209. 24. For consistency, use README rather than README.txt for any README files.
  210. 25. GRASS/Environment variables:
  211. If you add a new variable, please follow the naming convention.
  212. All variables are described in
  213. lib/init/variables.html
  214. 26. Be sure to develop on top of the LATEST GRASS code (which is in our SVN
  215. repository). You can re-check before submission with 'svn diff':
  216. Be sure to create unified ("diff -u") format. "Plain" diffs (the default
  217. format) are risky, because they will apply without warning to code which
  218. has been substantially changed; they are also harder to read than unified.
  219. Such diffs should be made from the top-level directory, e.g.
  220. "svn diff display/d.vect/main.c"; that way, the diff will
  221. include the pathname rather than just an ambiguous "main.c".
  222. 27. Try to use module names which describe shortly the intended purpose of the module.
  223. The first letters for module name should be:
  224. d. - display commands
  225. db. - database commands
  226. g. - general GIS management commands
  227. i. - imagery commands
  228. m. - miscellaneous tool commands
  229. ps. - postscript commands
  230. r. - raster commands
  231. r3. - raster3D commands
  232. v. - vector commands
  233. Some additional naming conventions
  234. * export modules: (type).out.(format) eg: r.out.arc, v.out.ascii
  235. * import module: (type).in.(format) eg: r.in.arc, v.in.ascii
  236. * conversion modules: (type).to.(type) eg: r.to.vect, v.to.rast, r3.to.rast
  237. Avoid module names with more than two dots in the name.
  238. Example:
  239. instead of r.to.rast3.elev use r.to.rast3elev
  240. 28. Use the grass test suite to test your modules.
  241. http://www-pool.math.tu-berlin.de/~soeren/grass/GRASS_TestSuite
  242. You can easily write specific tests for your modules.
  243. If your module is part of GRASS and you created some standard test
  244. cases, please contact the developers to add your tests to the
  245. default test suite. This will automatize complex test scenarios
  246. and assure to find bugs much faster, if changes were made to your
  247. modules or to the grass library.
  248. Consider to subscribe to the GRASS Quality Assessment System to
  249. get immediate notification about the code quality:
  250. http://lists.osgeo.org/mailman/listinfo/grass-qa
  251. 29. When submitting new files to the repository set SVN properties,
  252. usually for directory
  253. svn:ignore : *.tmp.html
  254. *OBJ*
  255. or e.g. for C-file
  256. svn:mime-type : text/x-csrc
  257. svn:keywords : Author Date Id
  258. svn:eol-style : native
  259. See
  260. http://svnbook.red-bean.com/en/1.4/svn.advanced.props.html
  261. To set a property:
  262. svn propset svn:keywords 'Author Date Id' <file>
  263. svn propset svn:mime-type text/x-sh grass_shellscript.sh
  264. To edit the svn:ignore property using your default text editor:
  265. svn propedit svn:ignore <directory>
  266. To set the svn:ignore property non-interactively, first create a
  267. file containing the value:
  268. echo "*.tmp.html" > ignore.txt
  269. echo "*OBJ*" >> ignore.txt
  270. then use:
  271. svn propset -F ignore.txt svn:ignore <directory>
  272. List of mime-type:
  273. C++ files (.cpp): text/x-c++src
  274. C files (.c): text/x-csrc
  275. DTD files (.dtd): text/xml-dtd
  276. GIF files (.gif): image/gif
  277. Header files (.h): text/x-chdr
  278. HTML files (.html): text/html
  279. JPEG files (.jpg): image/jpeg
  280. Makefiles: text/x-makefile
  281. PNG files (.png): image/png
  282. Python files (.py): text/x-python
  283. Shell scripts (.sh): text/x-sh
  284. Text files (.txt): text/plain
  285. XML files (.xml): text/xml
  286. (please update the list...)
  287. For your convenience use the tools/module_svn_propset.sh script.
  288. 30. Use doxygen style for source code documentation. It is required
  289. for GRASS libraries, but also recommended for GRASS modules.
  290. Do not use structural command inside documentation block since it
  291. leads to some duplication of information (e.g. do not use \fn
  292. command in comment blocks). The exception is \file command for
  293. documenting a file, in this case structural command is required.
  294. For files
  295. /*!
  296. \file snap.c
  297. \brief Vector library - Clean vector map (snap lines)
  298. (C) 2001-2008 by the GRASS Development Team
  299. This program is free software under the GNU General Public
  300. License (>=v2). Read the file COPYING that comes with GRASS
  301. for details.
  302. \author Radim Blazek
  303. */
  304. For functions
  305. /*!
  306. \brief Snap lines in vector map to existing vertex in threshold
  307. For details see Vect_snap_lines_list()
  308. \param Map pointer to input vector map
  309. \param type filter features of given type to be snap
  310. \param thresh threshold value for snapping
  311. \param[out] Err pointer to vector map where lines representing snap are written or NULL
  312. \param[out] msgout file pointer where messages will be written or NULL
  313. \return 1
  314. */
  315. 31. If you need to add support for a different library in the 'configure' script,
  316. you should first seek consent in the grass-dev mailing list (see below), then
  317. you need to expand 'configure.in' and run subsequently autoconf-2.13 (later
  318. versions will not work) to re-generate 'configure'.
  319. 32. Tell the other developers about the new code using the following e-mail:
  320. grass-dev@lists.osgeo.org
  321. To subscribe to this mailing list, see
  322. http://lists.osgeo.org/mailman/listinfo/grass-dev
  323. 33. In case of questions feel free to contact the developers at the above
  324. mailing list.
  325. http://grass.osgeo.org/devel/index.php#submission
  326. ...
  327. [please add further hints if required]
  328. "Your attention to detail is appreciated."