[comp.text.tex] C WEB formatting conventions

neuhaus@gren.informatik.uni-kl.de (Stephan Neuhaus (HiWi Mattern)) (06/20/91)

I have used the C version of WEB now and then and found it quite
useable in general.  But in my opinion the C formatting leaves
a lot to be desired.  We all know that formatting C code can
become kind of a religious war but I think I know some cases
where it is undebatable that a different layout is superior.

For example, I often find myself writing something like
this in C WEB:

    if (some_condition)
      @<Do Action Number 1@>
    else
      @<Do Action Number 2@>
      
More often than not, @<Do Action Number 1@> and @<Do Action Number 2@>
are compund statements, not simple statements or procedure calls.
What happens is that I define a module like this:

@ Initial Comment
@<Do Action Number 1@>=
{
  Code for the module;
  More code;
}

This gets tangled OK, but it weaves to

<nn> Initial Comment
<Do Action Number 1 <nn>>=
{
  Code for the Module;
  More code;}
(this code is used...)
  
You see? The closing brace is immediately behind the last statement.
I'd find it more convenient to line it up with the corresponding
open brace.

Another thing which happens frequently:  I define a function

int foo (const struct bar *a, const struct bar *b)
{
  ...
}

(Note ANSI C usage with full prototypes.)  This gets weaved so
that there is no space between bar, *, and a, i.e.,

int foo (const struct bar*a , const struct bar *b)

Note that there definitely *are* spaces in the second argument.
Why is this behaviour and how can I circumvent it?  Note that 
inserting @;@/ sequences is not a solution to me, and I would
use

    if (some_condition) {
      @<Do Action Number 1@>
    } else {
      @<Do Action Number 2@>
    }

only with regrets because this spoils the notion of a module being
a self-contained piece of software that can be understood in terms
of itself and its immediate neighbours (IMHO).

One final word of warning:  I have tried to make an identifier
like "True" come out in boldface because I wanted to treat it as
a reserved word (as it should be).  I used:

@f True int

and it totally screwed up the formatting because a @f ormat does
not only give True the same formatting as int, but also gives True
the same *category* as int, which is not what I wanted.

Workarounds, anybody (perhaps a spiderweb file)?  I have tried
spiderweb but couldn't readily adapt the code (no offense, spider's
inventor surely did a great job).  Maybe someone who uses C WEB
regularly can give me hints on how to adapt a spider file to
conform to one's own formatting conventions?  

--Stephan

P.S. Please reply by email because I don't read this newsgroup regularly.
Reply to: neuhaus@informatik.uni-kl.de.

P.P.S While we're at it: 

How about   |  To weave to |  Instead of
------------+--------------+------------------
if (a)      | if (a)       | if (a)
  b();      |   b();       |   b();
else if (c) | else if (c)  | else
  d();      |   d();       |   if (c)
else        | else         |     d();
  e();      |   e();       |   else
            |              |     e();