SUBMITTING 16 KB

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