Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

General Suggestions for Coding in OAGear

General Suggestions for Coding in OAGear

Developer Notes

Coding Style Guidelines

OA Gear should generally follow the OpenAccess coding style guidelines (see doc/oa/html/styleguide/index.html in the OA documentation). The following changes/clarifications should be noted:

Tips for programming

Tools to format code --------------------

There are a number of tools that can help format code to comply with the coding standards.

indent ------

The utility "indent" should be available on most Linux systems. This indents C code well, and C++ code to a limited extent.

"indent" has many options to control its behavior. The file "Build/indent-sources" (from CVS) is a shell script wrapper which sets the options which most closely meet the OA style guidelines. Alternatively, you can instead create a file /home/zerocool/.indent.pro with the contents:

-nbad -bap -nbbb -sob -br -ce -cdw -cli2 -ss -npcs -cs -saf -saw -saf -sai -saw -di1 -nbc -bfda -psl -brs -i4 -ci4 -lp -ts8 -ip20 -nut -l80 -hnl

Note that you can run "indent" on a file, or use it as a filter (useful with the vim filter command '!').

There are several common places where "indent" fails to do the right thing, and some manual fixup will be required. The <> symbols for templates and variable declarations with initializers, e.g. MyClass x(42); are usually confused for other constructs.

vi/vim ------

Configured using the file /home/zerocool/.vimrc . Example .vimrc file:

set shiftwidth=4 autoindent ruler nocompatible autocmd BufEnter *.c,*.cc,*.cpp,*.h set cindent expandtab softtabstop=4 syntax on

shiftwidth=4 : Sets indentation levels to be 4 spaces, as required by the style standard. expandtab : Tab characters are converted to spaces. softtabstop=4 : Changes the behavior of the TAB key to move 4 spaces instead of the normal 8. The "tabstop" option should be left to 8, in order to expand existing tabs to 8 spaces. cindent : Turns on automatic C-style code indentation.

Note that some options are only turned on for *.{cpp,h} files. This is to prevent tabs from being expanded in Makefiles, a serious error.

The keystrokes >{motion} and <{motion} perform indentation (move the text [shiftwidth] spaces to the right) and unindentation (move the text [shiftwidth] spaces to the left) on the text defined by {motion} (the standard vi motion sequences, e.g. >> indents a line, >} indents a paragraph unit, etc.).

The keystroke ={motion} performs C-style re-indentation on the text defined by {motion} (e.g. =} re-indents a paragraph unit). shiftwidth should be defined to be the desired indentation level.

Modelines are comments that can be added to files so that appropriate vi settings are enabled when editing that file. As an OA Gear standard, .{cpp,h} files are permitted to have the following modeline as the last line in the file:

vim: ci et sw=4 sts=4

emacs -----

Example configuration using /home/zerocool/.emacs :

(set-foreground-color "white") (set-background-color "black") (global-font-lock-mode t)

(require 'cc-mode) (defun my-build-tab-stop-list (width) (let ((num-tab-stops (/ 80 width)) (counter 1) (ls nil)) (while (<= counter num-tab-stops) (setq ls (cons (* width counter) ls)) (setq counter (1+ counter))) (set (make-local-variable 'tab-stop-list) (nreverse ls)))) (defun my-c-mode-common-hook () (setq tab-width 5) ;; modify this (my-build-tab-stop-list tab-width) (setq c-basic-offset 4) ;; modify this (setq indent-tabs-mode nil)) ;; force only spaces for indentation (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)


Generated on Mon Jul 9 14:17:21 2007 for OA Gear Fpga by  doxygen 1.3.9.1