IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2377


Ignore:
Timestamp:
Nov 16, 2004, 12:15:07 PM (22 years ago)
Author:
jhoblitt
Message:

add appendices for example source and perltidy

Location:
trunk/doc/misc
Files:
2 added
1 edited

Legend:

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

    r2376 r2377  
    1 %%% $Id: perlCodeConventions.tex,v 1.18 2004-11-16 21:20:22 jhoblitt Exp $
     1%%% $Id: perlCodeConventions.tex,v 1.19 2004-11-16 22:15:07 jhoblitt Exp $
    22\documentclass[panstarrs]{panstarrs}
     3
     4\usepackage{verbatim}
    35
    46% basic document variables
     
    1214\organization{Institute for Astronomy}
    1315\version{DR01}
    14 \docnumber{PSDC-430-010-DR}
     16\docnumber{PSDC-430-010}
    1517
    1618\begin{document}
     
    726728the compound statement; the closing brace should begin a line and be
    727729indented to the beginning of the compound statement.
     730\end{itemize}
    728731
    729732\subsection{return Statements}
     
    11701173\end{verbatim}
    11711174
    1172 \end{document}
    11731175%------------------------------------------------------------------------------
    11741176\appendix                               %Begin Appendices
     
    11791181\label{SourceExample}
    11801182
    1181 And here's the C source; \file{psUtils.h} provides \code{psAlloc/psFree}.
    1182 
    1183 \begin{verbatim}
    1184 /*
    1185  * This file implements an example of formatting a file of C code
    1186  *
    1187  * It isn't a very good piece of code
    1188  */
    1189 #include <stdlib.h>
    1190 #include <stdio.h>
    1191 #include <string.h>
    1192 #include <assert.h>
    1193 #include <time.h>
    1194 #include "psUtils.h"
    1195 #include "psBuffer.h"
    1196 
    1197 typedef enum { CRNL, NL } NLType;
    1198 
    1199 static char *getNewline(NLType type);   // return a suitable newline
    1200 
    1201 static psBuffer *buf = NULL;            // I/O buffer
    1202 
    1203 /*****************************************************************************/
    1204 /*
    1205  * Create/destroy psBuffers
    1206  */
    1207 psBuffer *psBufferAlloc(void)
    1208 {
    1209     psBuffer *buf = psAlloc(sizeof(psBuffer));
    1210     buf->n = 0;
    1211 
    1212     return buf;
    1213 }
    1214 
    1215 void psBufferFree(psBuffer *buf,         // buffer to delete
    1216                  int deep)              // NOTUSED. Do a deep delete
    1217 {
    1218     if (buf == NULL) {
    1219         return;
    1220     }
    1221    
    1222     if (buf->n > 0) {
    1223         (void)fputs(buf->buf, stdout);
    1224     }
    1225    
    1226     psFree(buf);
    1227 }
    1228 
    1229 /*****************************************************************************/
    1230 /*
    1231  * Append to a string to a psBuffer
    1232  */
    1233 void psBufferAppend(psBuffer *restrict buf, // psBuffer to append to
    1234                     const char *restrict str) // string to add
    1235 {
    1236     assert(str != NULL);
    1237     const int len = strlen(str);
    1238 
    1239     if (buf->n + len >= PS_BUFSIZE) {   // XXX Handle this better
    1240         fprintf(stderr, "Sorry; too many bytes. Bye bye\n");
    1241         abort();
    1242         exit(1);                        // NOTREACHED
    1243     }
    1244 
    1245     (void)strcat(&buf->buf[buf->n], str);
    1246     buf->n += len;
    1247 }   
    1248 
    1249 /*****************************************************************************/
    1250 /*
    1251  * Now do the work
    1252  */
    1253 int main(void)
    1254 {
    1255     buf = psBufferAlloc();
    1256     long t;                               // current time
    1257 
    1258     while(t = (long)time(NULL), t%3 == 2) {}
    1259    
    1260     if (t%3 == 0) {
    1261         psBufferAppend(buf, "Hello");
    1262     } else if (t%3 == 1) {
    1263         psBufferAppend(buf, "Aloha");
    1264     }
    1265     psBufferAppend(buf, " World!");
    1266 
    1267     psBufferAppend(buf, getNewline(NL));
    1268 
    1269     psBufferFree(buf, 0);
    1270 
    1271     return 0;
    1272 }
    1273 
    1274 /*****************************************************************************/
    1275 /*
    1276  * Return a desired line terminator
    1277  */
    1278 static char *getNewline(NLType type)    // what sort of newline?
    1279 {
    1280     char *newline;                      // newline to add
    1281     switch (type) {
    1282       case CRNL:
    1283         newline = "\r\n";
    1284         break;
    1285 
    1286       case NL:
    1287         newline = "\n";
    1288         break;
    1289 
    1290       default:
    1291         newline = "NL";                     // FIXME
    1292         break;
    1293     }
    1294 
    1295     return newline;
    1296 }
    1297 \end{verbatim}
     1183An example of \file{parseErrorCode.pl} that conforms with the Perl code
     1184convention.
     1185
     1186\verbatiminput{parseErrorCodes.pl}
    12981187
    12991188%------------------------------------------------------------------------------
     
    13021191\label{perltidy}
    13031192
    1304 The purpose of a coding standard is to improve coding efficiency, not
    1305 to hinder it.  Since people are inherently falible, 100\% adherence to
    1306 the standard is an impossible goal for human-generated code.
    1307 Furthermore, laziness and slopiness are human nature.  To minimize the
    1308 amount of effort spent in keeping software in line with a coding
    1309 standard is to use automatic re-formatting tools to enforce the
    1310 standard.  Various software tools exist to perform these tasks.  One
    1311 of these is \code{astyle}, an open-source tool which takes a variety
    1312 of options which allow the use to tailor the coding standard to suit
    1313 their preferences.  We have determined the following collection of
    1314 astyle options which achieve the many of the coding standard
    1315 guidelines specified above.  Note that any of the listed options
    1316 (always in the 'long' form) may be specified in the user's
    1317 \code{.astylerc} file by dropping the leading dash.
    1318 
    1319 \begin{itemize}
    1320 \item \code{--mode=c} - This option tells \code{astyle} to recognize
    1321   the source code as C code.
    1322 
    1323 \item \code{--indent-switches} - This option tells \code{astyle} to
    1324   indent the \code{case} statements in a \code{switch}.  Do not also
    1325   specify \code{--indent-cases}.
    1326 
    1327 \item \code{--indent-labels} - This option tells \code{astyle} to add
    1328   indentation to labels so they are indented one level less than the
    1329   current level.
    1330 
    1331 \item \code{--min-conditional-indent=0} - This option tells
    1332   \code{astyle} not to add indentation to successive lines of
    1333   multiple-line conditional statements.
    1334 
    1335 \item \code{--max-instatement-indent=20} - This option tells
    1336   \code{astyle} to limit the total amount of indentation to 20 spaces.
    1337 
    1338 \item \code{--pad=oper} - This option tells \code{astyle} to add
    1339   padding about binary operators.
    1340 
    1341 \item \code{--brackets=break} - This option tells \code{astyle} to
    1342   break brackets from their pre-block statements, dropping them to the
    1343   next line.
    1344 
    1345 \item \code{--convert-tabs} - This option tells \code{astyle} to
    1346   convert tabs into the equivalent number of space characters.
    1347 
    1348 \item \code{--indent=spaces=4} - This option tells \code{astyle} to
    1349   use 4 spaces per indent level.
    1350 \end{itemize}
     1193\code{pertidy} is a Perl specific code ``beautifier'' with functionality
     1194similar to \code{indent} or \code{astyle}.  It is freely avalible from
     1195\code{http://perltidy.sourceforge.net/}.
     1196
     1197\code{pertidy} can be configured with either command line switches or a
     1198\file{.perltidyrc} file in your home directory.
     1199
     1200Example \file{.perltidyrc} file to acheive the Perl code convention:
     1201
     1202\verbatiminput{.perltidyrc}
    13511203
    13521204\bibliographystyle{plain}
Note: See TracChangeset for help on using the changeset viewer.