Fist some simple noweb stuff.
<*>= <a chunk>
An empty chunk.
<a chunk>= <a chunk>
<a chunk>+= <another chunk><and still another chunk>
Now let's start with some C stuff.
<some variable declarations>= int an_int, another_int, and_still_another_int; char c, d; float a, b; float pi; double a, b, c, e, f, g;
<some modified variable declarations>= short i1; short int i2; long i3; long int i4; long double doublette; unsigned int big_one; signed char odd_one;
<some initialized variables>= int i=1234; int a, b, i, g, l, o, n, g, r, o, w, o, f, in, t, e, g, e, r, s; long l=123456789L;
Let's try some octal and other esoteric stuff.
<some more initialized variables>= float f1=123.4, f2=1 e-2, f3=1; int octal_int=0777;
The first line is an unsigned long with value 15.
<some more initialized variables>+= int hex_int=0x1f; float pi=3.141, pi2; long hex_long=0XFUL; char initialized_char='c', another_one='x', difficult_ones=n, another_difficult_one=777, bell=007;
<some constants>= const float e=2.71828182845905; const char msg[]="warning: ";i>;
Now for some pointers and arrays.
<some pointers>= int *ip; int int_array[]; int int_array[1000]; char *a_string; char **an_array_of_strings; char *s="a string!"; int ****hey; int ****hey_hoh; int *zero=NULL;
<some big initializers>= int_array[]int_array[];
Now for some operators.
<some operators>= x+x; x-x; x*x; x<x; x%x; x<y; x<=y; x>=y; x>y; x==y; x!=y; x&y; x&&y; x|y; x||y; ~x; ++x; x++; --x; x--; x+=2; x-=2; x*=2; x<=2;
<conditional expressions>= a/i>-x;
<referncing and derefencing>= p=&i; c=*a; cc=a->b; ccc=a.b;
\section{Control Flow}
<some conditionals>= if (a==1)s=1; elses=2; if (a)
<happy if's>=
if (a!=0)
{
b=1;
c=2;
}
if (n>0)if (a>b)z=a;
elsez=b;
<some else-if's>=
if (a==b)s1();
elseif (a!=b)s2();
elses3();
<switch and alike>=
switch (a)
{
case 1:s1;
break;
case 2:s2;
break;
default:s3;
}
<some loops>=
for(i=0;isspace(s[i]);i++);;) {
do_forever = 1;
}
while (c < 100) c++;
while (c<1000
<labels and goto>=
for(i=1;i<10;i++)
{
if (disaster)goto error;
}
error:i=42;
typedef should be handled like normal types and
be typeset just like them.
<a few typedefs>= typedef int Length; typedef char *String; Length len; Length len, maxlen;
Let's see if if works in another chunk too.
<a few typedefs>+= String a_string; Length first=100;
<Chop resulting text into lines and send them to application>=
char *entire_pped_code=has_been_pped.str();
(pp->ppcb)(pp->user_data,
STRING,
" ");
(pp->ppcb)(pp->user_data,
LITERAL,
"\\begin{ppcode}");
char *line=strtok(entire_pped_code,
"\n");
do
{
if (strlen(line)==0)
{
(pp->ppcb)(pp->user_data,
NEWLINE,
NULL);
continue;
}
if (*line=='@')
{
(pp->ppcb)(pp->user_data,
WHATSIT,
line);
}
else
{
(pp->ppcb)(pp->user_data,
LITERAL,
line);
(pp->ppcb)(pp->user_data,
NEWLINE,
NULL);
}
}
while ((line=strtok(NULL,
"\n"))!=NULL);
(pp->ppcb)(pp->user_data,
LITERAL,
"\\end{ppcode}");
Finally, it's our responsibility to cleanup the output strstream,
because we've called the str() function on it.
<Chop resulting text into lines and send them to application>+= delete entire_pped_code;/i>.str(); (pp->ppcb)(pp->user_data, STRING, " "); (p
Some more hard stuff (taken from t1.w).
<main>=
mlp=NULL;
/* init match list pointer */
mp=mlp;
hp=rp->right;
/* point |hp| to beginning of round list */
while (hp!=NULL)
{
if (hp->type==matches)
{
if (mp==NULL)
{
/* take this node as hew head */
mp=new_node();
check_node(mp);
mp->type=matches;
mp->right=hp->right;
mp->left=NULL;
/* terminate list */
mlp=mp;
}
else
{
/* add this one to the back */
mp->left=new_node();
check_node(mp->left);
mp=mp->left;
mp->type=matches;
mp->right=hp->right;
mp->left=NULL;
/* terminate list */
}
}
hp=hp->left;
/* look at next item of the list */
}
That's it.