IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 129


Ignore:
Timestamp:
Mar 2, 2004, 10:45:16 AM (22 years ago)
Author:
rhl
Message:

Dealt with almost all XXX issues; greatly improved emacs section

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/misc/codeConventions.tex

    r128 r129  
    11\documentclass[panstarrs]{panstarrs}
    2 \newcommand\note[1]{{\bf #1}}
    3 \newcommand\tbd[1]{{\bf [#1]}}
    42
    53\title{\PS{} Code Conventions}
     
    1917
    2018\newcommand{\matchBracket}[1]{}         % help emacs match properly
    21 \newcommand{\XXX}{{\color{red} XXX}}
     19\newcommand{\XXX}[1]{{\color{red} XXX #1\hfil\break}}
    2220
    2321\pagenumbering{roman} \thispagestyle{empty} \maketitle
    2422
    2523\pagebreak \pagestyle{fancy}
    26 { \Large \bf Revision History}
     24\textbf{\Large Revision History}
    2725\begin{center}
    2826\begin{tabular}{|p{1in}|p{1in}|p{4.5in}|}
    2927\hline
    30 {\bf Revision Number} & {\bf Release Date} & {\bf Description} \\
     28\textbf{Revision Number} & \textbf{Release Date} & \textbf{Description} \\
    3129\hline
    32 %0.1 & 2003/12/08 & First draft \\
     300.1 & 2004/03/01 & First draft \\
    3331\hline
    3432\end{tabular}
    3533\end{center}
    3634
    37 { \Large \bf Referenced Documents}
     35\textbf{\Large Referenced Documents}
    3836\begin{center}
    3937\begin{tabular}{|p{1in}|p{2.75in}|p{2.75in}|}
    4038\hline
    41 {\bf \PS{} ID} & {\bf Title} & {\bf Author} \\
     39\textbf{\PS{} ID} & \textbf{Title} & \textbf{Author} \\
    4240\hline
    4341%%% References here.
     
    7674
    7775
    78 \label{L16729}
    7976\subsection{Acknowledgments}
    8077
     
    9693copyright notice (Copyright.doc.html).
    9794
    98 \subsection{\label{L16730}To whom should I Complain?}
     95\subsection{To whom should I Complain?}
    9996
    10097While we're working on this document complain to
    10198\code{rhl@astro.princeton.edu}.
    10299
    103 
    104100%------------------------------------------------------------------------------
    105101
    106 \label{L16732}
    107102\section{File Names}
    108103
    109 \emph{\XXX{} I don't discuss doxygen comments here.}
    110 
    111104This section lists commonly used file suffixes and names.
    112 \label{L647}
     105
    113106\subsection{File Suffixes}
    114107
     
    125118\end{center}
    126119
    127 \label{L253}
    128120\subsection{Common File Names}
    129121
     
    133125\textbf{File Name} & \textbf{Use} \\
    134126\file{Makefile} &
    135   The preferred name for makefiles.  We use \code{gnumake} to build our
    136 software.  \emph{Do we? \XXX{}} \\
     127  The preferred name for makefiles.\\
    137128
    138129\file{README} &
     
    140131particular directory. \\
    141132
    142 \code{TAGS} &
     133\file{TAGS} &
    143134The index file (built by etags) used by emacs to follow cross references. \\
    144135\end{tabular}
     
    148139%------------------------------------------------------------------------------
    149140
    150 \label{L3043}
    151141\section{File Organization}
    152142
     
    157147
    158148For an example of a properly formatted program, see
    159 Source File Example (section \ref{L182}).
    160 
    161 \label{L11684}
     149Source File Example (sec. \ref{SourceExample}).
     150
    162151\subsection{Source Files}
    163152
    164 \label{Lfile_h}
    165153\subsubsection{Include Files}
    166154
    167 \emph{\XXX{} I added this}\hfil\break
    168155Header files should have names starting \code{ps} or
    169156\code{p_ps} for private interface definitions. The latter
     
    189176\item
    190177Any typedefs.
    191 \XXX{} describe use of typedefs.
    192178
    193179\item
     
    205191
    206192typedef struct {
    207   int nthing;                           /* number of subthings */
    208   int sthing[PS_NMAX];                  /* the subthings */
     193    int nthing;                           /* number of subthings */
     194    int sthing[PS_NMAX];                  /* the subthings */
    209195} psThing;
    210196
     
    215201\end{verbatim}
    216202
    217 \label{Lfile_c}\subsubsection{C Source Files}
     203\subsubsection{C Source Files}
    218204
    219205C Source files have the following ordering:
     
    238224\end{itemize}
    239225
    240 \label{Lfile_i}\subsubsection{SWIG Interface Files}
    241 
    242 \XXX{} Write me
     226\subsubsection{SWIG Interface Files}
     227
     228\XXX{Write me}
    243229
    244230%------------------------------------------------------------------------------
    245231
    246 \label{L262}
    247232\section{Indentation}
    248233
    249 Two spaces should be used as the unit of indentation. The exact
     234Four spaces should be used as the unit of indentation. The exact
    250235construction of the indentation (spaces vs. tabs) is unspecified. Tabs
    251 must be set exactly every 8 spaces (not 2).
    252 
    253 \label{L313}
     236must be set exactly every 8 spaces (not 4).
     237
    254238\subsection{Line Length}
    255239
     
    258242Note: Examples for use in documentation should have a shorter line length-generally no more than 70 characters.
    259243
    260 \label{L248}
    261244\subsection{Wrapping Lines}
    262245
     
    265248
    266249\begin{itemize}
    267 \item Break after a comma.
    268 
    269 \item Break before an operator.
    270 
    271   \emph{ \XXX{} RHL prefers to break \textit{after} an operator}, e.g.
     250\item Break after a comma or operator.
     251
    272252\begin{verbatim}
    273253if(a < b ||
    274254   a > 2*b) {
    275   x = (a + b + c) +
     255    x = (a + b + c) +
    276256    sin(z);
    277257}
    278258\end{verbatim}
    279 not
    280 \begin{verbatim}
    281 if(a < b
    282    || a > 2*b) {
    283   x = (a + b + c)
    284     + sin(z);
    285 }
    286 \end{verbatim}
    287 as the former tells the reader more directly that it's a partial
    288 statement.  Do we want to modify these rules?
    289259
    290260\item Prefer higher-level breaks to lower-level breaks.
     
    296266be more formal about what this rule means).
    297267
    298 \item If the above rules lead to confusing code or to code that's squished up against the right margin, just indent 8 spaces instead.
    299 \hfil\break\emph{\XXX{} emacs actually just uses a regular 2 space indent;
    300 should we do the same? }
     268\item If the above rules lead to confusing code or to code that's
     269squished up against the right margin, just indent 8 spaces instead.
     270This should be \emph{very} rare! Consider whether you should be
     271e.g. factoring code into a function.
    301272\end{itemize}
    302273
     
    312283\end{verbatim}
    313284
    314 Following are two examples of breaking an arithmetic expression. The first is preferred, since the break occurs outside the parenthesized expression, which is at a higher level.
    315 
    316 \begin{verbatim}
    317 longName1 = longName2 * (longName3 + longName4 - longName5)
    318            + 4 * longname6; // PREFER
    319 
    320 longName1 = longName2 * (longName3 + longName4
    321                        - longName5) + 4 * longname6; // AVOID
    322 \end{verbatim}
    323 
    324 Following are two examples of indenting function declarations. The first is the conventional case. The second would shift the second and third lines to the far right if it used conventional indentation, so instead it indents only 8 spaces.
     285Following are two examples of breaking an arithmetic expression. The
     286first is preferred, since the break occurs outside the parenthesized
     287expression, which is at a higher level.
     288
     289\begin{verbatim}
     290    longName1 = longName2*(longName3 + longName4 - longName5) +
     291        4*longname6;                    // PREFER
     292   
     293    longName1 = longName2*(longName3 + longName4 -
     294                           longName5) + 4*longname6; // AVOID
     295\end{verbatim}
     296
     297Following are two examples of indenting function declarations. The
     298first is the conventional case. The second would shift the second and
     299third lines to the far right if it used conventional indentation, so
     300instead it indents only 4 spaces (note that putting the \code{anArg}
     301argument on a line of its own makes this the `natural' emacs indentation).
     302
    325303\begin{verbatim}
    326304//CONVENTIONAL INDENTATION
     
    331309}
    332310
    333 //INDENT 8 SPACES TO AVOID VERY DEEP INDENTS
    334 static type honkingLongFunctionName(int anArg,
    335         Object anotherArg, String yetAnotherArg,
    336         Object andStillAnother)
     311//INDENT 4 SPACES TO AVOID VERY DEEP INDENTS
     312static type honkingLongFunctionName(
     313    int anArg,
     314    Object anotherArg, String yetAnotherArg,
     315    Object andStillAnother)
    337316{
    338317    ...
     
    340319\end{verbatim}
    341320
    342 Line wrapping for \code{if} statements should generally use the
    343 8-space rule, since conventional (2 space) indentation makes seeing
    344 the body difficult. For example:
    345 \begin{verbatim}
    346 //DON'T USE THIS INDENTATION
    347 if ((condition1 &amp;&amp; condition2)
    348     || (condition3 &amp;&amp; condition4)
    349     ||!(condition5 &amp;&amp; condition6)) { //BAD WRAPS
    350     doSomethingAboutIt();            //MAKE THIS LINE EASY TO MISS
    351 }
    352 
    353 //USE THIS INDENTATION INSTEAD
    354 if ((condition1 &amp;&amp; condition2)
    355         || (condition3 &amp;&amp; condition4)
    356         ||!(condition5 &amp;&amp; condition6)) {
    357     doSomethingAboutIt();
    358 }
    359 
    360 //OR USE THIS
    361 if ((condition1 &amp;&amp; condition2) || (condition3 &amp;&amp; condition4)
    362         ||!(condition5 &amp;&amp; condition6)) {
    363     doSomethingAboutIt();
    364 }
    365 \end{verbatim}
    366321Here are three acceptable ways to format ternary expressions:
    367322\begin{verbatim}
     
    378333%------------------------------------------------------------------------------
    379334
    380 \label{L385}
    381335\section{Comments}
    382336
     
    387341\begin{verbatim}
    388342#if 0
    389   code that is not wanted just at present
     343    code that is not wanted just at present
    390344#endif
    391345\end{verbatim}
     
    397351#define IGNORE_RHL 1
    398352#if !IGNORE_RHL
    399   ...
     353    ...
    400354#endif
    401355...
    402356#if !IGNORE_RHL
    403   ...
     357    ...
    404358#endif
    405359\end{verbatim}
    406360This type of \code{#define} may appear within the main body of the file.
    407361\end{itemize}
    408 
    409 \emph{\XXX{} RHL added this.  He stands by it. }
    410362
    411363Comments should be used to give overviews of code and provide
     
    422374date as the code evolves.
    423375
    424 Note:The frequency of comments sometimes reflects poor quality of
     376Note: The frequency of comments sometimes reflects poor quality of
    425377code. When you feel compelled to add a comment, consider rewriting the
    426378code to make it clearer.
     
    432384backspace.
    433385 
    434 \label{L216}
    435386\subsection{Implementation Comment Formats}
    436387
    437 Programs can have four styles of implementation comments: block, single-line, trailing, and end-of-line.
    438 \label{L680}
     388Programs can have four styles of implementation comments: block,
     389single-line, trailing, and end-of-line.
     390
    439391\subsubsection{Block Comments }
     392\label{ImplBlockComments}
    440393
    441394Block comments are used to provide descriptions of files, functions,
     
    446399describe.
    447400
    448 \emph{\XXX{} I don't see any reason for this blank line}\hfil\break
    449 A block comment should be preceded by a blank line to set it apart from the rest of the code.
    450 \begin{verbatim}
    451 /*
    452  * Here is a block comment.
    453  */
    454 \end{verbatim}
    455 
    456 See also Documentation Comments (section \ref{L16838}).
    457 
    458 \label{L341}
     401See also Documentation Comments (sec. \ref{DocComments}).
     402
    459403\subsubsection{Single-Line Comments}
     404\label{SingleLineComment}
    460405
    461406Short comments can appear on a single line indented to the level of
    462407the code that follows. If a comment can't be written in a single line,
    463 it should follow the \ref{L680}block comment format. A
    464 single-line comment should be preceded by a blank line.
    465 \emph{\XXX{} I don't see any reason for this blank line}\hfil\break
    466 Here's an
    467 example of a single-line comment in C code (also see \ref{L16838}''Documentation Comments''):
    468 
    469 \begin{verbatim}
    470 if (condition) {
    471 
    472   /* Handle the condition. */
    473   ...
    474 }
    475 \end{verbatim}
    476 
    477 \label{L342}
     408it should follow the \ref{ImplBlockComments}block comment format.
     409
    478410\subsubsection{Trailing Comments}
    479411
     
    487419\begin{verbatim}
    488420if (a == 2) {
    489   return TRUE;                          /* special case */
     421    return TRUE;                          /* special case */
    490422} else {
    491   return isPrime(a);                    /* works only for odd a */
    492 }
    493 \end{verbatim}
    494 
    495 \label{L286}
     423    return isPrime(a);                    /* works only for odd a */
     424}
     425\end{verbatim}
     426
    496427\subsubsection{End-Of-Line Comments}
    497428
     
    502433
    503434\begin{verbatim}
    504 if (foo &gt; 1) {
    505 
    506   // Do a double-flip.
    507   ...
     435if (foo > 1) {
     436
     437    // Do a double-flip.
     438    ...
    508439} else {
    509   return false;          // Explain why here.
    510 }
    511 \end{verbatim}
    512 
    513 \label{L16838}
     440    return false;          // Explain why here.
     441}
     442\end{verbatim}
     443
    514444\subsection{Documentation Comments}
    515 
    516 \emph{\XXX{} Need references to Doxygen here.}
     445\label{DocComments}
     446
     447\XXX{Need references to Doxygen here.}
    517448
    518449If you need to give information about a type, interface, or variable
    519450that isn't appropriate for doxygenation, use an implementation block
    520 comment (sec. \ref{L680}) or single-line comment (sec. \ref{L341})
     451comment (sec. \ref{ImplBlockComments}) or single-line comment (sec. \ref{SingleLineComment})
    521452immediately \textit{before} the code. For example, details about the
    522453implementation of a type should go in in such an implementation block
     
    526457%------------------------------------------------------------------------------
    527458
    528 \label{L2991}
    529459\section{Declarations}
    530460
    531 \emph{\XXX{} I added this}\hfil\break
    532 \textit{All globally-visible symbols must be declared in
    533 a suitable header (.h) file.}.  Global private symbols (i.e.
    534 those named \code{p_ps}) should not appear in public header
    535 files, but rather in files whose names begin \code{p_ps}.
    536 
    537 \label{L2992}
     461All globally-visible symbols must be declared in a suitable header
     462(.h) file.  Global private symbols (i.e.  those named \code{p_ps})
     463should not appear in public header files, but rather in files whose
     464names begin \code{p_ps}.
     465
    538466\subsection{Number Per Line}
    539467
    540 One declaration per line is recommended since it encourages commenting. In other words,
     468One declaration per line is recommended since it encourages
     469commenting. In other words,
    541470\begin{verbatim}
    542471int level;                              // indentation level
     
    549478Do not put different types on the same line. Example:
    550479\begin{verbatim}
    551 int foo,  fooarray[];                   //WRONG!
     480int foo,  fooarray[];                   // WRONG!
    552481\end{verbatim}
    553482
     
    561490(Note that the comments are indented to column 40).
    562491
    563 \label{L18761}
    564492\subsection{Initialization}
    565493
    566 Try to initialize local variables where they're declared.
    567 \hfil\break\emph{\XXX{} the following is invalidated by the rewrite of section 6.3}
    568 The only
     494Try to initialize local variables where they're declared.  The only
    569495reason not to initialize a variable where it's declared is if the
    570496initial value depends on some computation occurring first.
    571497
    572 \hfil\break\emph{\XXX{} added by RHL}
    573498In some cases it may be necessary to initialize a variable to suppress
    574499a compiler warning; in this case a comment should explain the circumstances.
    575500
    576 \label{L16817}
    577501\subsection{Placement}
    578502
    579 \hfil\break\emph{\XXX{} I've changed this}
    580 
    581 Variables should ordinarily be declared as soon as they
    582 appear in the logical flow of control through a function. This
    583 allows them to be initialised as they are created, and naturally
     503Variables should ordinarily be declared at the top of the block in
     504which they appear, unless there is some reason to declare them later.
     505This allows them to be initialised as they are created, and naturally
    584506associates their declaration with their use.
    585507
    586 In particular, indexes of \code{for} loops should usually
     508For example, declarations are naturally mixed with assertions:
     509\begin{verbatim}
     510void function(REGION *reg)                      // image of the sky
     511{
     512    assert (reg != NULL);
     513    const int nrow = reg->nrow;
     514    assert (reg->type == psType_U16);
     515    const psTypeU16 *rows = reg->rows;
     516    ...
     517}
     518\end{verbatim}
     519
     520Indexes of \code{for} loops should usually
    587521be declared in the \code{for} statement (the declarations appear
    588522in the scope of the braces):
    589523\begin{verbatim}
    590 for (int i = 0; i &lt; maxLoops; i++) {
    591   ...
    592 }
    593 \end{verbatim}
    594 
    595 \hfil\break\emph{\XXX{} OLD VERSION}
    596 
    597 Put declarations at the beginning of blocks. (A block is any code
    598 surrounded by curly braces \CODE.{. and \CODE.}..) Don't wait to declare
    599 variables until their first use; it can confuse the unwary programmer
    600 and hamper code portability within the scope.
    601 
    602 \begin{verbatim}
    603 void myFunction(void)
    604 {
    605   int int1 = 0;                         // beginning of function block
    606 
    607   if (condition) {
    608     int int2 = 0;                       // beginning of "if" block
     524for (int i = 0; i < maxLoops; i++) {
    609525    ...
    610   }
    611 }
    612 \end{verbatim}
    613 
    614 One exception to the rule is indexes of \code{for} loops, which
    615 in C99 can be declared in the \code{for} statement (and which appear
    616 in the scope of the braces):
    617 \begin{verbatim}
    618 for (int i = 0; i &lt; maxLoops; i++) {
    619   ...
    620 }
    621 \end{verbatim}
    622 
    623 p>
    624 
    625 \emph{\XXX{} Added by RHL: }\hfil\break
    626 Another exception is that assertions may preceed or be mixed with declarations:
    627 \begin{verbatim}
    628 void function(REGION *reg)                      // image of the sky
    629 {
    630   assert (reg != NULL);
    631   const int nrow = reg->nrow;
    632   assert (reg->type == psType_U16);
    633   const psTypeU16 *rows = reg->rows;
    634   ...
    635 }
    636 \end{verbatim}
    637 Note that this allows us to declare variables that have been unpacked
    638 to e.g. allow dealiasing to be declared \code{const}.
    639 
    640 \hfil\break\emph{\XXX{} End old version }
     526}
     527\end{verbatim}
    641528
    642529Avoid local declarations that hide declarations at higher levels. For
     
    647534void myFunction(void)
    648535{
    649   if (condition) {
     536    if (condition) {
    650537    int count = 0;                      // AVOID!
    651538    ...
    652   }
    653   ...
    654 }
    655 \end{verbatim}
    656 
    657 \label{L381}
     539    }
     540    ...
     541}
     542\end{verbatim}
     543
    658544\subsection{Function Declarations}
    659545
     
    664550\item
    665551Function declarations should be preceeded by a short comment
    666 describing what the function does. \hfil\break\emph{\XXX{} Doxygen? }
     552describing what the function does.
     553
     554\XXX{Discuss Doxygen}
    667555
    668556\item The function's type should appear on the same line as the
    669557function declaration.
    670 \hfil\break\emph{\XXX{} I don't like this (I put the type
    671 on the previous line), but MHPCC seems to use it}
    672558
    673559\item All arguments should be declared with their types; i.e. no
     
    686572void function(void)
    687573{
    688   ...
     574    ...
    689575}
    690576\end{verbatim}
     
    699585               )
    700586{
    701   struct {
    702       int x, y;
    703   } work[10];
    704   int ivar;
    705 
    706   while(isspace(*descrip++)) {}         // skip white space
    707   descrip--;                            // one too far. Not great code...
    708 
    709   ...
     587    struct {
     588        int x, y;
     589    } work[10];
     590    int ivar;
     591
     592    while(isspace(*descrip++)) {}         // skip white space
     593    descrip--;                            // one too far. Not great code...
     594
     595    ...
    710596}
    711597\end{verbatim}
     
    714600%------------------------------------------------------------------------------
    715601
    716 \label{L430}
    717602\section{Statements}
    718 \label{L431}
    719603\subsection{Simple Statements}
    720604
    721 Each line should contain at most one statement. Example:
    722 \begin{verbatim}
    723 argv++;                                 // Correct
    724 argc--;                                 // Correct 
    725 argv++; argc--;                         // AVOID!
    726 \end{verbatim}
    727 
    728 \label{L15395}
     605Each line should usually contain only one statement. Example:
     606\begin{verbatim}
     607x = sqrt(x2);                           // Correct
     608i++;                                    // Correct 
     609x = sqrt(x2); i++;                      // Avoid!
     610\end{verbatim}
     611
     612An example of a reasonably two-statement line is:
     613\begin{verbatim}
     614argv++; argc--;
     615\end{verbatim}
     616where the two actions are intimately related.
     617
    729618\subsection{Compound Statements}
    730619
     
    746635\end{itemize}
    747636
    748 \label{L438}
    749637\subsection{return Statements}
    750638
     
    759647\end{verbatim}
    760648
    761 \label{L449}
    762649\subsection{if, if-else, if else-if else Statements}
    763650
     
    765652\begin{verbatim}
    766653if (condition) {
    767   statements;
     654    statements;
    768655}
    769656
    770657if (condition) {
    771   statements;
     658    statements;
    772659} else {
    773   statements;
     660    statements;
    774661}
    775662
    776663if (condition) {
    777   statements;
     664    statements;
    778665} else if (condition) {
    779   statements;
     666    statements;
    780667} else {
    781   statements;
    782 }
    783 
    784 \end{verbatim}
    785 
    786 Note: \code{if} statements always use braces {}. Avoid the following error-prone form:
    787 \begin{verbatim}
    788 if (condition) //AVOID! THIS OMITS THE BRACES {}!
     668    statements;
     669}
     670
     671\end{verbatim}
     672
     673Note: \code{if} statements always use braces {}. Avoid the following
     674error-prone form:
     675\begin{verbatim}
     676if (condition)                          // AVOID! THIS OMITS THE BRACES {}!
    789677    statement;
    790678\end{verbatim}
    791679
    792 \label{L454}
    793680\subsection{for Statements}
    794681
     
    796683\begin{verbatim}
    797684for (initialization; condition; update) {
    798   statements;
     685    statements;
    799686}
    800687\end{verbatim}
    801688
    802689An empty \code{for} statement (one in which all the work is done
    803 in the initialization, condition, and update clauses) should have the
    804 following form:
     690in the initialization, condition, and update clauses) should have one of
     691the following forms:
    805692\begin{verbatim}
    806693for (initialization; condition; update);
     694for (initialization; condition; update) {}
    807695\end{verbatim}
    808696
     
    813701the loop (for the update clause).
    814702
    815 \label{L460}
    816703\subsection{while Statements}
    817704
     
    819706\begin{verbatim}
    820707while (condition) {
    821   statements;
    822 }
    823 \end{verbatim}
    824 An empty \code{while} statement should have the following form:
     708    statements;
     709}
     710\end{verbatim}
     711An empty \code{while} statement should have one of the following forms:
    825712\begin{verbatim}
    826713while (condition);
    827 \end{verbatim}
    828 
    829 \label{L465}
     714while (condition) {}
     715\end{verbatim}
     716
    830717\subsection{do-while Statements}
    831718
     
    833720\begin{verbatim}
    834721do {
    835   statements;
     722    statements;
    836723} while (condition);
    837724\end{verbatim}
    838725
    839 
    840 \emph{\XXX{} RHL would prefer that we mandate one of the forms}:
    841 \begin{verbatim}
    842 for (initialization; condition; update) {}
    843 for (initialization; condition; update) continue;
    844 \end{verbatim}
    845 Ditto for \code{while} statements.  The closing ; is subtle,
    846 especially bearing in mind:
    847 \begin{verbatim}
    848 do {
    849     ....
    850 while (condition);
    851 \end{verbatim}
    852 where the while really does have a closing semicolon.
    853 
    854 \label{L468}
    855726\subsection{switch Statements}
    856727
    857 A \code{switch} statement should have the following form:
     728A \code{switch} statement should have the following form (note the
     729indentation; the \code{case/default} is indented 2 spaces, the
     730other statements are at the usual 4 space indent):
    858731\begin{verbatim}
    859732switch (condition) {
    860 case ABC:
    861   statements;
    862   /* falls through */
    863 
    864 case DEF:
    865 case GHI:
    866   statements;
    867   break;
    868 
    869 case XYZ:
    870   statements;
    871   break;
    872 
    873 default:
    874   statements;
    875   break;
    876 }
    877 \end{verbatim}
    878 
    879 \emph{\XXX{} I'd prefer to indent the ``case'' 1 more spaces RHL}:
    880 \begin{verbatim}
    881 switch (condition) {
    882  case ABC:
    883   statements;
    884   /* falls through */
    885 
    886  case DEF:
    887  case GHI:
    888   statements;
    889   break;
    890 
    891  case XYZ:
    892   statements;
    893   break;
    894 
    895  default:
    896   statements;
    897   break;
     733  case ABC:
     734    statements;
     735    /* falls through */
     736
     737  case DEF:
     738  case GHI:
     739    statements;
     740    break;
     741
     742  case XYZ:
     743    statements;
     744    break;
     745
     746  default:
     747    statements;
     748    break;
    898749}
    899750\end{verbatim}
     
    902753statement), add a comment where the \code{break} statement would
    903754normally be. This is shown in the preceding code example with the
    904  \code{/* falls through */} comment. A comment is not
    905 required (or expected) when the fall-through is between multiple case
    906 statements.
     755\code{/* falls through */} comment. A comment is not required (or
     756expected) when the fall-through is between multiple case statements.
    907757
    908758Every \code{switch} statement should include a default case,
     
    911761\code{case} is later (and illegally) added after the default clause.
    912762
    913 \emph{ \XXX{} Added by RHL}\hfil\break
    914763When switching on an enumerated type, if all the elements of the
    915764type are included in the switch a default clause should still be
     
    920769%------------------------------------------------------------------------------
    921770
    922 \label{L475}
    923771\section{White Space}
    924 \label{L487}
    925772\subsection{Blank Lines}
    926773
     
    939786\item Between the local variables in a function and its first statement
    940787
    941 \item Before a \ref{L680}block or \ref{L341}single-line comment
     788\item Before a block (sec. \ref{ImplBlockComments}) or
     789  single-line (sec. \ref{SingleLineComment}) comment
    942790
    943791\item Between logical sections inside a function to improve readability
    944792\end{itemize}
    945793
    946 \label{L682}
    947794\subsection{Blank Spaces}
    948795
     
    953800\begin{verbatim}
    954801while (true) {
    955   ...
     802    ...
    956803}
    957804\end{verbatim}
     
    963810\item A blank space should appear after commas in argument lists.
    964811
    965 \item All binary operators except \code{.} and \code{->}
    966 should be separated from their operands by spaces. Blank spaces should
    967 never separate unary operators such as unary minus, increment (\code{++}),
    968 and decrement (\code{--}) from their operands. Example:
    969 \begin{verbatim}
    970   a += c + d;
    971   a = (a + b) / (c * d);
     812\item
     813 Low priority binary operators (\code{+} and \code{-} and below)
     814should be separated from their operands by spaces; higher
     815precedence operators (e.g. \code{*}, \code{/}, \code{%},
     816  \code{.} and \code{->}) should not be separated by spaces.
     817Blank spaces should never separate
     818unary operators such as a type cast, unary minus, increment
     819(\code{++}), and decrement (\code{--}) from their operands. Examples:
     820\begin{verbatim}
     821    a += c + d;
     822    a = (a + b)/(c*d);
    972823   
    973   while (*d++ = *s++) {                 // Tricky way of copying to '\0'
    974       n++;
    975   }
    976   printf("size is %d\n", foo);
    977 \end{verbatim}
    978 \hfil\break\emph{ \XXX{} I had to fix the code to make it even make sense, but it's
    979 still lousy code (I admit that you'll see it in K\&R, but it's a very
    980 1970s style)}
    981 \hfil\break\emph{\XXX{} I don't like this either.  I'd prefer to see multiplicative
    982 operators (i.e. * / \%) without whitespace.  E.g.}
    983 \begin{verbatim}
    984 a%x + y;
    985 a*(x + y);
    986 (a + b)/(x + y);
     824    while (*d++ = *s++) {                 // Tricky way of copying until '\0'
     825        n++;
     826    }
     827    printf("size is %d\n", foo);
    987828\end{verbatim}
    988829
     
    993834    for (expr1; expr2; expr3)
    994835\end{verbatim}
    995 \item Casts should be followed by a blank space. Examples:
    996 \begin{verbatim}
    997     myFunc((byte) aNum, (Object) x);
    998     myFunc((int) (cp + 5), ((int) (i + 3))
    999                                   + 1);
    1000 \end{verbatim}
    1001 
    1002 \hfil\break\emph{\XXX{} I really don't like this one.  A cast is a unary operator,
    1003 and binds harder than e.g. ++. }
    1004836
    1005837\item
    1006 \emph{\XXX{} I added this }\hfil\break
    1007838The word \code{assert} should be treated as a keyword, and
    1008839separated by a space from its logical expression.
     
    1011842%------------------------------------------------------------------------------
    1012843
    1013 \label{L367}
    1014844\section{Naming Conventions}
    1015845
     
    1044874
    1045875The names of all externally visible functions (i.e. all those that are
    1046 not declared \code{static}) should be verbs, in mixed case. The
    1047 first two characters should be \code{ps}, with the first letter
    1048 of each internal word capitalized.
     876not declared \code{static}) should be verbal phrases, in mixed
     877case. The first two characters should be \code{ps}, with the first
     878letter of each internal word capitalized.
    1049879
    1050880Functions that are visible at global scope but are not considered part
     
    1067897
    1068898Except for variables, all instance, class, and class constants are in
    1069 mixed case with a lowercase first letter. Internal words start with
    1070 capital letters. Variable names should not start with underscore \code{_}
    1071 as these names are, under some circumstances, reserved by the
    1072 C standard.
     899mixed case with
     900
     901Variable names should not start with underscore \code{_} as these
     902names are, under some circumstances, reserved by the C
     903standard. Non-globally visible words should start with a lowercase
     904first letter; Internal words start with capital letters.
    1073905
    1074906Variables visible at global scope should begin with \code{ps},
    1075907or \code{p_ps} if not considered part of the public interface.
    1076908Variables that are local to a file should \textit{not} start
    1077 with \code{ps} (or \code{p_ps}).
     909with \code{ps} (or \code{p_ps}). These variables should be Capitalised
     910at the beginning of each word.
    1078911
    1079912Variable names should be short yet meaningful. The choice of a
     
    1097930&
    1098931
    1099 \emph{\XXX{} const is different in C from Java (and C++) so I've rewritten
    1100 this.}\hfil\break
    1101 
    1102 Constants used to e.g. dimension arrays should be set using
    1103 the \code{#define}; \code{const} variables should not be used, especially
     932Constants used to e.g. dimension arrays should be set using the
     933\code{#define}; \code{const} variables should not be used, especially
    1104934in header files.  Symbolic values should usually be declared using
    1105 enumerated types (although this requires more care with namespaces).
     935enumerated types.
    1106936
    1107937The names of all enumerated types and C-preprocessor symbols (but not
     
    1120950%------------------------------------------------------------------------------
    1121951
    1122 \label{L529}
    1123952\section{Programming Practices}
    1124953
    1125 \label{L177}
    1126954\subsection{When to Make Symbols Global}
    1127955
     
    1130958with its usage to make auto-variables within a function persistent).
    1131959
    1132 \label{L1255}
    1133960\subsection{Constants}
    1134961
     
    1137964in a \code{for} loop as counter values. 
    1138965
    1139 \emph{ \XXX{} RHL relaxed this a little}
    1140 
    1141 \label{L547}
    1142966\subsection{Variable Assignments}
    1143967
     
    1149973row0 = col0 = 0;                        // OK
    1150974\end{verbatim}
    1151 \emph{\XXX{} Relaxed by RHL}
    1152975
    1153976Do not use the assignment operator in a place where it can be easily confused with the equality operator. Example:
    1154977\begin{verbatim}
    1155978if (c++ = d++) {                        // AVOID!
    1156   ...
     979    ...
    1157980}
    1158981\end{verbatim}
     
    1160983\begin{verbatim}
    1161984if ((c++ = d++) != 0) {
    1162   ...
    1163 }
    1164 \end{verbatim}
    1165 If \code{c} and \code{d} are char variables, use \code{'\0'}
    1166 instead of \code{0}.
    1167 \hfil\break\emph{\XXX{} \code{'$\backslash$0'} added by RHL}
    1168 
    1169 Do not use embedded assignments in an attempt to improve run-time performance. This is the job of the compiler. Example:
     985    ...
     986}
     987\end{verbatim}
     988
     989Do not use embedded assignments in an attempt to improve run-time
     990performance. This is the job of the compiler. Example:
    1170991\begin{verbatim}
    1171992d = (a = b + c) + r;                    // AVOID!
     
    1178999\end{verbatim}
    11791000
    1180 \label{L554}
    11811001\subsection{Miscellaneous Practices}
    1182 \label{L331}
    11831002\subsubsection{Parentheses}
    11841003
     
    11931012if ((a == b) && (c == d))               // RIGHT
    11941013\end{verbatim}
    1195 \hfil\break\emph{\XXX{} I don't agree with this; you end up with
    1196 too many parens.  Next section is added by RHL}
    11971014
    11981015There are some famous problems with precedence in C.  In particular,
    11991016expressions involving the combinations of \code{||} and
    1200 \code{\&\&} should be parenthesised as should all
     1017\code{&&} should be fully parenthesised, as should all
    12011018expressions containing bitwise operators:
    12021019\begin{verbatim}
    1203 if ((a == b \&\& c == d) || e == f)
     1020if ((a == b && c == d) || e == f)
    12041021l << (j + k)
    12051022(l << j) + k
     
    12071024\end{verbatim}
    12081025
    1209 \label{L333}
    12101026\subsubsection{Returning Values}
    12111027
     
    12131029\begin{verbatim}
    12141030if (booleanExpression) {
    1215   return true;
     1031    return true;
    12161032} else {
    1217   return false;
     1033    return false;
    12181034}
    12191035\end{verbatim}
     
    12311047\begin{verbatim}
    12321048if (condition) {
    1233   return x;
     1049    return x;
    12341050}
    12351051return y;
     
    12401056\end{verbatim}
    12411057
    1242 \label{L353}
    12431058\subsubsection{Expressions before `?' in the Conditional Operator }
    12441059
    12451060If an expression containing a binary operator appears before the \code{?} in the ternary \code{?: }operator, it should be parenthesized. Example:
    12461061\begin{verbatim}
    1247 (x &gt;= 0) ? x : -x;
    1248 \end{verbatim}
    1249 
    1250 \label{L396}
     1062(x >= 0) ? x : -x;
     1063\end{verbatim}
     1064
    12511065\subsubsection{Functions that Take No Parameters}
    1252 
    1253 \emph{\XXX{} added by RHL}
    12541066
    12551067When a function takes no arguments, it should be explicitly declared
     
    12581070static type myFunction(void)
    12591071{
    1260   ...
    1261 }
    1262 \end{verbatim}
    1263 
    1264 
    1265 \label{L395}
     1072    ...
     1073}
     1074\end{verbatim}
     1075
     1076
    12661077\subsubsection{Special Comments}
    12671078\begin{itemize}
    12681079\item
    1269 Use \code{\XXX{}} in a comment to flag something that is bogus but works.
     1080Use \code{XXX} in a comment to flag something that is bogus but works.
    12701081
    12711082\item
    12721083Use \code{FIXME} to flag something that is bogus and broken.
    12731084
    1274 \emph{\XXX{} next items added by RHL}
    1275 
     1085\XXX{Check Doxygen versions of these special comments. I could not
     1086find any occurrence of \code{@notused@} in the Doxygen documentation}
    12761087\item
    12771088Use \code{NOTREACHED} to indicate a line of code that cannot be reached,
     
    12791090\begin{verbatim}
    12801091if (sqrt(x) < 0) {
    1281   psAbort();                            // never returns
    1282   exit(1);                              // NOTREACHED
     1092    psAbort();                            // never returns
     1093    exit(1);                              // NOTREACHED
    12831094}
    12841095\end{verbatim}
     
    12961107}
    12971108\end{verbatim}
    1298 
    1299 \emph{\XXX{} I see some @notused@ comments in the MHPCC code. Is this
    1300 usage documented? Should we adopt it?}
    13011109\end{itemize}
    13021110
    13031111\subsubsection{\label{LNewDel}10.4.6     Constructors/Destructors}
    1304 
    1305 \emph{\XXX{} Added by RHL }
    13061112
    13071113Type definitions should always be accompanied by prototypes for
     
    13351141\subsection{\label{LConvOps}Naming Conversion Operators}
    13361142
    1337 \emph{\XXX{} Added by RHL }
    1338 
    13391143When defining a function to convert from one type to another, the
    13401144name should be of the form \code{psOldToNew}, e.g.
    1341 \code{psEquatorialToEcliptic}.
     1145\code{psEquatorialToEcliptic} (\emph{not} \code{psEquatorial2Ecliptic}).
    13421146
    13431147\subsection{\label{LArgumentOrder}Order of I/O Arguments}
    1344 
    1345 \emph{\XXX{} Added by RHL }
    13461148
    13471149Functions that assign to a variable should list that argument
     
    13501152\subsection{\label{LConstRestrict}Type Qualifiers (const and restrict)}
    13511153
    1352 \emph{\XXX{} Added by RHL }
    1353 
    13541154All interfaces and type definitions should use \code{const} and
    13551155\code{restrict} wherever appropriate. For example,
    13561156\begin{verbatim}
    13571157typedef struct {
    1358   int n;
    1359   float *restrict vec;
     1158    int n;
     1159    float *restrict vec;
    13601160} psVec;
    13611161
     
    13661166so all code should be written to explicitly handle aliasing}.
    13671167
    1368 \emph{\XXX{} Sadly, it looks to me as if gcc 3.3 doesn't make
    1369 serious use of \code{restrict}.  I believe that we should
    1370 still encourage its use.}
    1371 
    13721168%------------------------------------------------------------------------------
    1373 
    1374 \label{L186}
     1169\appendix                               %Begin Appendices
     1170%------------------------------------------------------------------------------
     1171
    13751172\section{Code Examples}
    1376 \label{L182}
    13771173\subsection{Source File Example}
     1174\label{SourceExample}
     1175
     1176\XXX{Need to include more of the rules, and shorten the example}
     1177Here's \file{psBuffer.h}:
     1178\begin{verbatim}
     1179#if !defined(PS_BUFFER_H)               /* here's the insides of psBuffer.h */
     1180#define PS_BUFFER_H
     1181#define PS_BUFSIZE 128                  // Size for I/O buffers
     1182
     1183typedef struct {
     1184    char buf[PS_BUFSIZE];               // buffer
     1185    int n;                              // number of bytes in buffer
     1186} psBuffer;
     1187
     1188psBuffer *psBufferNew(void);
     1189void psBufferDel(psBuffer *buf,         // buffer to delete
     1190                 int deep);             // NOTUSED. Do a deep delete
     1191
     1192void psBufferAppend(psBuffer *restrict buf, // psBuffer to append to
     1193                    const char *restrict str); // string to add
     1194
     1195#endif
     1196\end{verbatim}
     1197
     1198And here's the C source; \file{psUtils.h} provides \code{psAlloc/psFree}.
    13781199
    13791200\begin{verbatim}
    13801201/*
    1381  * This file implements an example of formatting a C
     1202 * This file implements an example of formatting a file of C code
    13821203 *
    13831204 * It isn't a very good piece of code
     
    13891210#include <time.h>
    13901211#include "psUtils.h"
    1391 
    1392 #define BUFSIZE 128                     // Size for I/O buffers
    1393 
    1394 typedef struct {
    1395   char buf[BUFSIZE];                    // buffer
    1396   int n;                                // number of bytes in buffer
    1397 } Buffer;
    1398 
    1399 typedef enum { NL, CRNL, CR } NLType;
    1400 
    1401 static void addNewline(NLType type);    // add a newline to the buffer
    1402 
    1403 static Buffer *buf = NULL;              // I/O buffer
     1212#include "psBuffer.h"
     1213
     1214typedef enum { CRNL, NL } NLType;
     1215
     1216static char *getNewline(NLType type);   // return a suitable newline
     1217
     1218static psBuffer *buf = NULL;            // I/O buffer
    14041219
    14051220/*****************************************************************************/
    14061221/*
    1407  * Create/destroy Buffers
     1222 * Create/destroy psBuffers
    14081223 */
    1409 static Buffer *bufferNew(void)
     1224psBuffer *psBufferNew(void)
    14101225{
    1411   Buffer *buf = psAlloc(sizeof(Buffer));
    1412   buf->n = 0;
    1413 
    1414   return buf;
    1415 }
    1416 
    1417 void bufferDel(Buffer *buf,             // buffer to delete
    1418                int deep)                // NOTUSED. Do a deep delete
     1226    psBuffer *buf = psAlloc(sizeof(psBuffer));
     1227    buf->n = 0;
     1228
     1229    return buf;
     1230}
     1231
     1232void psBufferDel(psBuffer *buf,         // buffer to delete
     1233                 int deep)              // NOTUSED. Do a deep delete
    14191234{
    1420   if (buf == NULL) {
    1421     return;
    1422   }
     1235    if (buf == NULL) {
     1236        return;
     1237    }
    14231238   
    1424   if (buf->n > 0) {
    1425     (void) fputs(buf->buf, stdout);
    1426   }
     1239    if (buf->n > 0) {
     1240        (void)fputs(buf->buf, stdout);
     1241    }
    14271242   
    1428   psFree(buf);
     1243    psFree(buf);
    14291244}
    14301245
    14311246/*****************************************************************************/
    14321247/*
    1433  * Append to a string to a Buffer
     1248 * Append to a string to a psBuffer
    14341249 */
    1435 static void bufferAppend(Buffer *restrict buf, // Buffer to append to
    1436                          const char *restrict str) // string to add
     1250void psBufferAppend(psBuffer *restrict buf, // psBuffer to append to
     1251                    const char *restrict str) // string to add
    14371252{
    1438   assert(str != NULL);
    1439   const int len = strlen(str);
    1440 
    1441   if (buf->n + len >= BUFSIZE) {        // XXX Handle this better
    1442     fprintf(stderr,"Sorry; too many bytes. Bye bye\n");
    1443     abort();
    1444     exit(1);                    // NOTREACHED
    1445   }
    1446 
    1447   (void) strcat(&buf->buf[buf->n], str);
    1448   buf->n += len;
     1253    assert(str != NULL);
     1254    const int len = strlen(str);
     1255
     1256    if (buf->n + len >= PS_BUFSIZE) {   // XXX Handle this better
     1257        fprintf(stderr, "Sorry; too many bytes. Bye bye\n");
     1258        abort();
     1259        exit(1);                        // NOTREACHED
     1260    }
     1261
     1262    (void)strcat(&buf->buf[buf->n], str);
     1263    buf->n += len;
    14491264}   
    14501265
     
    14551270int main(void)
    14561271{
    1457   buf = bufferNew();
    1458   long t;                               // current time
    1459 
    1460   while(t = (long)time(NULL), t % 4 != 2) {}
     1272    buf = psBufferNew();
     1273    long t;                               // current time
     1274
     1275    while(t = (long)time(NULL), t%3 == 2) {}
    14611276   
    1462   if (t % 4 == 0) {
    1463     bufferAppend(buf, "Hello");
    1464   } else if (t % 4 == 1) {
    1465     bufferAppend(buf, "Bonjour");
    1466   } else {
    1467     bufferAppend(buf, "Aloha");
    1468   }
    1469   bufferAppend(buf, " World!");
    1470 
    1471   addNewline(NL);
    1472 
    1473   bufferDel(buf, 0);
    1474 
    1475   return 0;
     1277    if (t%3 == 0) {
     1278        psBufferAppend(buf, "Hello");
     1279    } else if (t%3 == 1) {
     1280        psBufferAppend(buf, "Aloha");
     1281    }
     1282    psBufferAppend(buf, " World!");
     1283
     1284    psBufferAppend(buf, getNewline(NL));
     1285
     1286    psBufferDel(buf, 0);
     1287
     1288    return 0;
    14761289}
    14771290
    14781291/*****************************************************************************/
    14791292/*
    1480  * Add a newline to the buffer
     1293 * Return a desired line terminator
    14811294 */
    1482 static void addNewline(NLType type)             // what sort of newline?
     1295static char *getNewline(NLType type)    // what sort of newline?
    14831296{
    1484   char *newline;                        // newline to add
    1485   switch (type) {
    1486    case NL:
    1487     newline = "\n";
    1488     break;
    1489 
    1490    case CRNL:
    1491     newline = "\r\n";
    1492     break;
    1493 
    1494    case CR:
    1495     newline = "\r";
    1496     break;
    1497 
    1498    default:
    1499     newline = "NL";                     // FIXME
    1500     break;
    1501   }
    1502 
    1503   bufferAppend(buf, newline);
    1504 }
    1505 \end{verbatim}
     1297    char *newline;                      // newline to add
     1298    switch (type) {
     1299      case CRNL:
     1300        newline = "\r\n";
     1301        break;
     1302
     1303      case NL:
     1304        newline = "\n";
     1305        break;
     1306
     1307      default:
     1308        newline = "NL";                     // FIXME
     1309        break;
     1310    }
     1311
     1312    return newline;
     1313}
     1314\end{verbatim}
     1315
     1316%------------------------------------------------------------------------------
     1317
     1318\section{Departures from Sun Java Coding Standards}
     1319
     1320Apart from changes required by our use of C99 rather than Java,
     1321this document differs from the original Sun-Java standard in
     1322two sorts of ways; additions and changes.
     1323
     1324\subsection{ Additions to the Sun-Java standards}
     1325
     1326\begin{itemize}
     1327\item
     1328    Naming convention for include files
     1329
     1330\item
     1331  Added naming conventions for constructors, destructors, and conversion
     1332  functions.
     1333
     1334\item
     1335  Specified that the `output' argument should come \emph{first}.
     1336
     1337\item
     1338  Added conventional comments for unused arguments and unreachable
     1339  statements (conforming to Doxygen's conventions).
     1340
     1341\item
     1342  Specified that functions taking no arguments should be explicitly
     1343  specified as \code{(void)} (avoiding complaints on some compilers,
     1344  e.g. on SGIs).
     1345 
     1346\end{itemize}
     1347
     1348\subsection{Departures from the Sun-Java standards}
     1349
     1350\begin{itemize}
     1351
     1352\item
     1353  We break lines \emph{after} (not before) an operator.
     1354
     1355\item
     1356  We don't specify any special indentation for continued logical
     1357  expressions within an \code{if} clause.
     1358
     1359\item
     1360  Specify that \code{case/break} statements should be indented
     1361  by half an indent (2 spaces)
     1362
     1363\item
     1364  Comments need not be preceeded by a blank line
     1365
     1366\item
     1367  The restriction on only declaring variables at the top of blocks (including
     1368  \code{for} loops has been somewhat relaxed.
     1369
     1370\item
     1371  Relaxed the `only one statement per line' rule a little.
     1372
     1373\item
     1374  High-precedence binary operators (\code{*}, \code{/}, \code{%} and above)
     1375    should \emph{not} be surrounded by whitespace.
     1376\end{itemize}
    15061377
    15071378%------------------------------------------------------------------------------
     
    15131384not part of the coding standards.}
    15141385
    1515 If you want to simply set these variables you can, see the code in
    1516 the section on hooks (section \ref{Lhooks}) below.
    1517 
    1518 \subsection{\label{Lusing customize}Using Customize to Control Formatting}
    1519 
    1520 Add this to your \file{.emacs} file:
    1521 \begin{verbatim}
    1522 (custom-set-variables
    1523   ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
    1524   ;; Your init file should contain only one such instance.
    1525  '(c-basic-offset 2)
    1526  '(c-default-style (quote ((other . "k\&r"))))
    1527  '(c-offsets-alist (quote ((statement-case-intro . 1) (statement-case-open . 1) (case-label . 1))))
    1528  '(comment-column 40)
    1529  )
    1530 \end{verbatim}
    1531 
    1532 If you already have a
    1533 \code{custom-set-variables} command be careful! Or set the same values
    1534 using the \code{Customize Emacs} entry in the \code{Options} menu,
    1535 then follow down:
    1536 \begin{verbatim}
    1537 Browse Customization Groups -->
    1538     Programming -->
    1539         Languages -->
    1540             C
    1541 \end{verbatim}
    1542 (an alternative way to get to the same place is
    1543 \begin{verbatim}
    1544 ESCx
    1545 customize-group
    1546 C
    1547 \end{verbatim}
    1548 )
    1549 Then set the values of
    1550 \begin{verbatim}
    1551  C Basic Offset    ==> 2
    1552  C Default Style   ==> k\&r
    1553  C Offsets Alist   ==> X  statement-case-intro 1
    1554                        X  statement-case-open  1
    1555                        X  case-label           1
    1556 \end{verbatim}
    1557 
    1558 Then in the same  \code{Customize Emacs} menu, choose
    1559 \begin{verbatim}
    1560 Settings Matching Regexp...
    1561 \end{verbatim}
    1562 then set the value of
    1563 \begin{verbatim}
    1564  Comment Column    ==> 40
    1565 \end{verbatim}
    1566 
    1567 If you want to use \code{//} style comments, see the top
    1568 of the next section.
    1569 
    1570 \subsection{Setting variables directly via lisp hooks}
    1571 \label{Lhooks}
    1572 
    1573 If you want to use \code{//} style comments, you may want to
    1574 make \code{ESC;} insert them rather than the traditional
    1575 \code{/* .. */} version.  If so, add something like this to
    1576 your \file{.emacs} file:
    1577 \begin{verbatim}
    1578 (add-hook 'c-mode-hook
     1386The easiest way to use these conventions while writing code using
     1387emacs is to add these lines to your \file{.emacs} file:
     1388
     1389\begin{verbatim}
     1390(define-derived-mode panstarrs-c-mode
     1391  c-mode "Pan-STARRS C"
     1392  "Major mode for editing Pan-STARRS C source.
     1393          \\{panstarrs-c-mode-map}"
     1394 
     1395  (setq c-default-style '((other . "k&r")))
     1396  (setq c-basic-offset 4)
     1397  (setq comment-column 40)
     1398  (add-to-list 'c-offsets-alist (cons 'statement-case-intro 2))
     1399  (add-to-list 'c-offsets-alist (cons 'statement-case-open 2))
     1400  (add-to-list 'c-offsets-alist (cons 'case-label 2))
     1401  )
     1402\end{verbatim}
     1403
     1404You then need to ensure that this mode is set when editing code;
     1405you could always type \code{ESCx panstarrs-c-mode} when you
     1406opened a file, but the simplest way is to add
     1407\begin{verbatim}
     1408(add-to-list 'auto-mode-alist (cons "\\.[ch]$" 'panstarrs-c-mode))
     1409\end{verbatim}                          % $ % match that $ for emacs
     1410to your \file{.emacs} file; this will use \code{panstarrs-c-mode}
     1411for all \file{.c} and \file{.h} files.
     1412
     1413If you want to use C99-style comments (i.e. \code{//} to end of line),
     1414add this to your \file{.emacs} file too:
     1415\begin{verbatim}
     1416(add-hook 'panstarrs-c-mode-hook
    15791417          '(lambda ()
    15801418             (setq comment-start "// ")
    15811419             (setq comment-end "")))
    15821420\end{verbatim}
    1583 
    1584 You can get fancier, of course. For example,
    1585 \begin{verbatim}
    1586 (setq ps-code t)                        ;this is Pan-STARRS code
    1587 (add-hook 'c-mode-hook
    1588           '(lambda ()
    1589              (if (and (boundp 'ps-code) ps-code)
    1590                  (progn
    1591                    (setq comment-start "// ")
    1592                    (setq comment-end "")))))
    1593 \end{verbatim}
    1594 will make emacs use \code{//} if and only if the lisp variable
    1595 \code{ps-code} is set and non-\code{nil}.
    1596 
    1597 To entirely bypass emacs' customize menus, also add this to your
    1598 \textit{.emacs} file (I left the \code{ps-code} test in):
    1599 \begin{verbatim}
    1600 (add-hook 'c-mode-hook
    1601           '(lambda ()
    1602              (if (and (boundp 'ps-code) ps-code)
    1603                  (progn
    1604                    (setq c-basic-offset 2)
    1605                    (setq c-default-style '((other . "k&r")))
    1606                    (setq comment-column 40)
    1607                    (let ( el (vals
    1608                               '((statement-case-intro . 1)
    1609                                 (statement-case-open . 1)
    1610                                 (case-label . 1))) )
    1611                      (while vals
    1612                        (setq el (car vals))
    1613                        (setq vals (cdr vals))
    1614                        (setq c-offsets-alist
    1615                              (cons el
    1616                                    (assoc-delete-all
    1617                                     (car el) c-offsets-alist))))
    1618                      )
    1619                    ))))
    1620 \end{verbatim}
    1621 (and yes, there must be an easier way to set that alist. But this works).
    1622 
     1421         
    16231422\bibliographystyle{plain}
    16241423\bibliography{panstarrs}
Note: See TracChangeset for help on using the changeset viewer.