Sample C Code
The following code snippet, a routine extracted from a compiler, demonstrates most of the coding standards that we follow.
/******************************************************************************
* do_supprint - process `suppress_print[_unless]' statements *
* *
* This routine receives control from the CONF.C module when a suppress_print *
* or suppress_print_unless is encountered. Such statements are of the form *
* suppress_print[_unless] fld_def relop value *
******************************************************************************/
static int do_supprint()
{ /* start of sub-routine */
IFD *ifd = cvt->cvt_currifd; /* address of current IFD */
TRP *trp = cvt->cvt_trd->trd_trp; /* address of current TRP */
SPR *spr, *new; /* address of SPR */
int retcd = TRUE; /* assume that all is well */
char *emsg1 = "Misplaced statement: `%s' encountered before `table'";
char *emsg2 = "No more than one suppress_print[_unless] statement supported";
rt_start( ); /* trace program flow */
while (TRUE) /* outer control loop */
{ /* [to scoop up any exceptions] */
if ((! cvt->cvt_trd) || (! cvt->cvt_trd->trd_trp))
{ /* if `suppress_' stat't out of seq */
config_error(ERROR_LEVEL, emsg1, cvt->cvt_tokenptr[0]); /* mention err */
if (ifd) ifd->ifd_deferrors++; /* count specification errors */
retcd = FALSE; /* indicate that we are not happy */
break; /* and bypass further processing */
} /* end of handling misplaced statemnt*/
while (trp->trp_trp) trp = trp->trp_trp; /* advance to last [current] TRP*/
new = getmem(SPRlgth, "SPR"); /* acquire memory for area */
if (! new) break; /* exit if no memory available */
if (cvt->cvt_tokenlen[0] == 21) /* if this is an ..._unless stat't */
new->spr_flags |= FSPR_UNLESS; /* then flag to reverse the logic */
spr = (SPR *)&trp->trp_spr; /* treat TPR as SPR anchor */
if (trp->trp_spr) /* if the anchor is populated */
{ /* ... then ... */
config_error(ERROR_LEVEL, emsg2); /* explain the problem */
if (ifd) ifd->ifd_deferrors++; /* count specification errors */
retcd = FALSE; /* indicate that we are not happy */
break; /* and bypass further processing */
} /* end of handling multiple stat'ts */
while (spr->spr_spr) /* until the end of chain found */
spr = spr->spr_spr; /* walk the chain */
spr->spr_spr = new; /* append new SPR to end of chain */
ifd->ifd_selanchor = (SEL *)&new->spr_sel; /* establish SPR as SEL anchor*/
do_select(); /* process args as if 'select' stat't*/
break; /* break out of outer control loop */
} /* end of outer control loop */
rt_end( ); /* trace program flow */
return(retcd); /* return status to caller */
} /* end of sub-routine */