Back to index

radiance  4R0+20100331
Functions | Variables
neat.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

Go to the source code of this file.

Functions

int main (int argc, argv)

Variables

static const char RCSid [] = "$Id: neat.c,v 1.4 2003/11/14 17:31:24 schorsch Exp $"
char * format = "8.8"

Function Documentation

int main ( int  argc,
argv   
)

Definition at line 20 of file neat.c.

{
       int  left, anchor, right;
       char  buf[512];
       register char  *cp, *word;
       register int  i;

       if (argc == 2)
              format = argv[1];
       else if (argc > 2)
              goto userror;
       left = 0;
       for (cp = format; isdigit(*cp); cp++)
              left = left*10 + *cp - '0';
       right = 0;
       if ( (anchor = *cp) )
              for (cp++; isdigit(*cp); cp++)
                     right = right*10 + *cp - '0';
       if (*cp)
              goto userror;
       
       while ((cp = fgets(buf, sizeof(buf), stdin)) != NULL)
              for ( ; ; ) {
                     while (isspace(*cp))
                            cp++;
                     if (!*cp) {
                            putchar('\n');
                            break;
                     }
                     word = cp;
                     while (*cp && *cp != anchor && !isspace(*cp))
                            cp++;
                     i = left-(cp-word);
                     while (i-- > 0)
                            putchar(' ');
                     while (word < cp)
                            putchar(*word++);
                     i = right+1;
                     if (*cp == anchor)
                            do {
                                   putchar(*cp++);
                                   i--;
                            } while (*cp && !isspace(*cp));
                     while (i-- > 0)
                            putchar(' ');
              }
       exit(0);
userror:
       fputs("Usage: ", stderr);
       fputs(argv[0], stderr);
       fputs(" [format]\n", stderr);
       exit(1);
}

Here is the call graph for this function:


Variable Documentation

char* format = "8.8"

Definition at line 16 of file neat.c.

const char RCSid[] = "$Id: neat.c,v 1.4 2003/11/14 17:31:24 schorsch Exp $" [static]

Definition at line 2 of file neat.c.