%

\documentclass{article}
\usepackage{noweb,pretzel-noweb,a4}
\begin{document}

This is a small file ment to test the {\tt noweb} prettyprinting
filter for C.

@

Fist some simple noweb stuff.

<<*>>=
<<a chunk>>
@

An empty 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 = 1e-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: ";
@

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 int_array[] = { 1, 2, 3, 4, 5, 6, 7, 0 };
@

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 ? b : c;
z = a ? 1 : 0;
x= (n>1)? 1 : z;
@

<<referncing and derefencing>>=
p = &i;
c = *a;
cc = a->b;
ccc = a.b;
@

\section{Control Flow}

<<some conditionals>>=
if (a==1) s=1; else s=2;
if (a);
@

<<happy if's>>=
if (a != 0) { b=1; c=2; }
if (n>0) if (a > b) z=a; else z=b;
@

<<some else-if's>>=
if (a==b)
  s1();
else if (a!=b)
  s2();
else
  s3();
@

<<switch and alike>>=
switch (a) {
  case 1: s1(); break;
  case 2: s2(); break;
  default: s3();
}
@

<<some loops>>=
for (i=0; isspace(s[i]); i++) ;
for (i=0; i<100; i++) { a=i; }
for (;;) {
  do_forever = 1;
}
while (c < 100) c++;
while (c<1000) {
  c++;
}
do {
  i++;
} while (i<100);

for (i=0; i<n; i++) {
  if (a[i] < 0) continue;
}
@

<<labels and goto>>=
for (i=1; i<10; i++) {
  if (disaster) goto error;
}
error: i=42;
@

page 70;

\section{Constructed Types}

Types defined by [[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;
@





\section{Hard Stuff}

<<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;

@


Some more hard stuff (taken from {\tt 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.


\end{document}

