These are the coding standards I am using. If you make some changes to the
code, please attempt to follow these rules.

Gershon Elber

gershon@cs.technion.ac.il

------------------------------------------------------------------------------


GENERAL
-------

Code should not exceed column 80. If the code is going to "look"
better with more that 80 columns it is allowed but should be
restricted as possible.

NESTING
-------

Nesting of all expressions is by 4 spaces. Tabs used are 8 spaces.

SPACES
------

No spaces are allowed after '(' and before ')' in a function call or
math expression. However, spaces are allowed between arguments after
the comma or between operations:

	sin(x);
	Function1(x, y, z);
	x + 5 * sin(y);

FUNCTION HEADER'S COMMENT
-------------------------

Function comments will have the following form:

/*****************************************************************************
* DESCRIPTION:								     M
* Multi line description of the function. This is a text that will be copied M
* to the programmer's manual iff the end of the line is M instead of a *     M
* like this line.							     M
*   If a V is found at the end of the line, it is copied Verbatim. Example:  M
* A x + B y + C z + D w + E = 0 defines an hyper plane in four space.        V
*									     M
*   Proper indentation will be given to algorithms or sequences that begin   M
* with an alpha-numeric values followed by a point. For example:             M
*									     M
* 1. One letter	which sets the option letter (i.e. 'x' for option '-x').     M
*    1.1 Allow even sub sequences.					     M
* 2. '!' or '%'	to determines if this option is	really optional	('%') or     M
*    it	must be provided by the user ('!').				     M
* 3. '-' always.							     M
* 4. Sequences that start with either '!' or '%'.			     M
*       Each sequence will be followed by one or two characters	which        M
*    defines the kind of the input:			   		     M
*    4.1 d, x, o, u - integer is expected (decimal, hex, octal base or	     M
*		  unsigned).						     M
*    4.2 D, X, O, U - long integer is expected (same as above).		     M
*    4.3 f - float number is expected.					     M
*									     *
* PARAMETERS:								     M
*   I1: one per line, must have an M at the end to show up in prog manual.   M
*   C2: this parameter is the second one.				     M
*									     *
* RETURN VALUE:								     M
*   int: Number of manuals to create.					     M
*									     *
* KEYWORDS:	(only if a global non static function).			     M
*	ProgrammerManual, manual, documentation				     M
*****************************************************************************/
int ProgrammerManual(int I1, char C2)
{
}

Functions that are obviously auxiliary can have the postfix Aux, must be
static, and can have documentation as:

/*****************************************************************************
* DESCRIPTION:                                                               *
* Auxiliary function to function SymbPiecewiseRuledSrfApprox		     *
*****************************************************************************/
static CagdSrfStruct *CagdPiecewiseRuledSrfAux(CagdSrfStruct *Srf,
					       CagdBType ConsistentDir,
					       CagdRType Epsilon,
					       CagdSrfDirType Dir)

The function comment must be followed very precisely so they could be
grabbed out of the code directly into the programmer's manual. If you
are using the emacs editor (If you dont, you better switch to it), add
irit.el from the irit subdirectory to your .emacs. This emacs-lisp file
contains a definition for make-irit-c-function which expands a skeleton
from a given prototype. Once irit.el is installed, type
'M-x make-irit-c-function' followed by a function prototype 'int Test(char c)'.

Static functions will never have 'M' or 'V' as last character in line. Only
'*'.

INTERNAL COMMENTS
-----------------

Internal comments will be aligned to the right to column 80 if the
are commenting expression in the same line:

	i %= 2;						      /* Is i even? */

Comments that explains the following block, will be left aligned as
the block. The comment does not need to be right aligned to column 80
as well:

	/* This is a comment for the next line. */
	i %= 2;


FUNCTION AND VARIABLE NAMES
---------------------------

Both function and variable names will have NO UNDERSCORES. Words will be
capitalized to distinguish them from each other. Variables of single
character will be lower case. Examples of valid names:

    ThisIsAFunction, VariableOne, X1, i, j

VARIABLE'S DECLARATIONS
-----------------------
Variables will be declared at the deepest nesting possible. That is, if
a variable is used in one module, it will be static to the module. If the
variable is used in one function, it will be defined in one function. If
a variable is used in one block in one function, it will be defined in that
block. Variables will be declared static first, followed by automatic.
Variables will be declared from simple type to complex/composed ones.
Variables that are intialized are to be declared one per line, indented
once from the indentation level of the variable type. Example:

    static int
	LastCount = 0;
    static RealType
	LastValue = 0.0;
    static IPObjectStruct *TmpObj;
    char Str[LINE_LEN], *p,
	*Name = "MyName";
    int Dir = REAL_PTR_TO_INT(RDir),
	OldOrder = Dir == CAGD_CONST_U_DIR ? Srf -> VOrder : Srf -> UOrder,
	NewOrder = REAL_PTR_TO_INT(RNewOrder);
    IPObjectStruct *SrfObj;
    CagdSrfStruct *TSrf,
	*Srf = PObjSrf -> U.Srfs;


PARAMETERS OF FUNCTIONS
-----------------------

Parameters of function prototypes will either be all in one line:

    int Func1Test(int Len, RealType *Vect)

or all arguments must be aligned one below the other:

    static CagdSrfStruct *CagdPiecewiseRuledSrfAux(CagdSrfStruct *Srf,
					           CagdBType ConsistentDir,
					           CagdRType Epsilon,
					           CagdSrfDirType Dir)

Local (to a file) functions must be declared static and a prototype of the
function should also be placed in the beginning of the file. Otherwise,
for a non static function, a prototype must be place in the appropriate
header ('.h' file) file.


BLOCKS
------

Blocks starts with '{' and ends with '}'. If the block is beginning of
function then it will start with '{' at column 1 and end at column 1
with '}'. Otherwise, it will start with some expression as for/if/while
etc. in the nesting form: 

    expression {
	.
	.
	.
    }

FOR
---
	for (x = 0; x < 10; x++)

    or

	for (x = 0, i = 1;
	     x < 5;
	     x++, i--)

	The body of the for loop can never be in the same line where the ')'
    is. The ')' will be followed by '{' and the body will start in the next
    line nested 4 space deapper:

	for (....)
	    x = sin(j);
    or
	for (....) {
	    x = y / j;
	    y = j + 2;
	}

WHILE
-----
	while (x > 0)
	    x--;				       /* Better use x = 0! */

or

	while (x > 0 && y > 0) {
	    x -= 4;
	    y -= 4;
	}

or

	while (x > 0 &&
	       x < 5)
	    x /= 2;


IF
--

	if (x > 0)
	    x = -x;

or

	if (x > 0 && y > 0) {
	    x = -x;
	    y = -y;
	}

or

	if (x > 0)
	    x = -x;
	else
	    x /= 2;

or

	if (x > 0)
	    x = -x;
	else if (x < -100)
	    x /= 20;
	else
	    x /= 2;

If an if expression has an else clause both bodies will be aligned 4
space deep (The body of the if clause can not be in same line as the
if and must be aligned with the else body).


SWITCH
------

	switch (i) {
	    case 1:
		printf("1");
		break;
	    case 2:
		printf("2");
		break;
	    case 3:
		printf("3");
		break;
	    default:
		printf("Too big");
		break;
	}


FINAL REMARK
------------

If you are still not sure how the code should be formated in some specific
case, consult the code. Out of over 100k of lines of code, you are most
likely to find a similar case to yours.
