Back to index

tetex-bin  3.0
Defines | Functions | Variables
squeeze.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "kpathsea/c-auto.h"
#include "kpathsea/c-memstr.h"

Go to the source code of this file.

Defines

#define EXIT_SUCCESS   0
#define EXIT_FAILURE   1
#define LINELENGTH   (72)
#define BUFLENGTH   (1000)
#define putchar(a)   (void)putc(a, out) ;

Functions

static void specialout (char c)
static void strout (char *s)
static void cmdout (char *s)
int main (int argc, char *argv[])

Variables

FILEin
FILEout
static int linepos = 0
static int lastspecial = 1
static int stringlen = 0
char buf [BUFLENGTH]

Define Documentation

#define BUFLENGTH   (1000)

Definition at line 51 of file squeeze.c.

#define EXIT_FAILURE   1

Definition at line 46 of file squeeze.c.

#define EXIT_SUCCESS   0

Definition at line 43 of file squeeze.c.

#define LINELENGTH   (72)

Definition at line 50 of file squeeze.c.

#define putchar (   a)    (void)putc(a, out) ;

Definition at line 53 of file squeeze.c.


Function Documentation

static void cmdout ( char *  s) [static]

Definition at line 91 of file squeeze.c.

{
    int l;

    l = strlen(s);
    if (linepos + l + 1 > LINELENGTH) {
       (void)fputs("\\n\\\n", out);
       stringlen += linepos + 1;
       linepos = 0;
       lastspecial = 1;
    }
    if (!lastspecial) {
       putchar(' ');
       linepos++;
    }
    while (*s != 0) {
       putchar(*s++);
    }
    linepos += l;
    lastspecial = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 117 of file squeeze.c.

{
    int c;
    char *b;
    char seeking;
    extern void exit();

    if (argc > 3 || (in = (argc < 2 ? stdin : fopen(argv[1], "r"))) == NULL ||
       (out = (argc < 3 ? stdout : fopen(argv[2], "w"))) == NULL) {
       (void)fprintf(stderr, "Usage:  squeeze [infile [outfile]]\n");
       exit(EXIT_FAILURE);
    }
    (void)fputs("/*\n"
              " *   DO NOT EDIT THIS FILE!\n"
              " *   It was created by squeeze.c from another file (see the Makefile).\n"
              " */\n\n"
              "const char psheader[] = \"\\\n", out);
    while (1) {
       c = getc(in);
       if (c == EOF)
           break;
       if (c == '%') {
           while ((c = getc(in)) != '\n');
       }
       if (c <= ' ')
           continue;
       switch (c) {
       case '{':
       case '}':
       case '[':
       case ']':
           specialout(c);
           break;
       case '<':
       case '(':
           if (c == '(')
              seeking = ')';
           else
              seeking = '>';
           b = buf;
           *b++ = c;
           do {
              c = getc(in);
              if (b > buf + BUFLENGTH - 2) {
                  (void)fprintf(stderr, "Overran buffer seeking %c", seeking);
                  exit(EXIT_FAILURE);
              }
              *b++ = c;
              if (c == '\\')
                  *b++ = getc(in);
           } while (c != seeking);
           *b++ = 0;
           strout(buf);
           break;
       default:
           b = buf;
           while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
                 (c >= '0' && c <= '9') || (c == '/') || (c == '@') ||
                 (c == '!') || (c == '"') || (c == '&') || (c == '*')
                 || (c == ':') || (c == ',') || (c == ';') || (c == '?')
                 || (c == '^') || (c == '~') || (c == '-') || (c == '.')
                 || (c == '#') || (c == '|') || (c == '_') || (c == '=')
                 || (c == '$') || (c == '+')) {
              *b++ = c;
              c = getc(in);
           }
           if (b == buf) {
              (void)fprintf(stderr, "Oops!  Missed a case: %c.\n", c);
              exit(EXIT_FAILURE);
           }
           *b++ = 0;
           (void)ungetc(c, in);
           cmdout(buf);
       }
    }
    (void)fprintf(out,
                "\\n\";\n\n int\tpsheaderlen\t= %d;\n",
                stringlen + linepos + 1);
    return 0;
}

Here is the call graph for this function:

static void specialout ( char  c) [static]

Definition at line 64 of file squeeze.c.

{
    if (linepos + 1 > LINELENGTH) {
       (void)fputs("\\n\\\n", out);
       stringlen += linepos + 1;
       linepos = 0;
    }
    putchar(c);
    linepos++;
    lastspecial = 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void strout ( char *  s) [static]

Definition at line 77 of file squeeze.c.

{
    if (linepos + strlen(s) > LINELENGTH) {
       (void)fputs("\\n\\\n", out);
       stringlen += linepos + 1;
       linepos = 0;
    }
    linepos += strlen(s);
    while (*s != 0)
       putchar(*s++);
    lastspecial = 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char buf[BUFLENGTH]

Definition at line 113 of file squeeze.c.

FILE* in

Definition at line 54 of file squeeze.c.

int lastspecial = 1 [static]

Definition at line 56 of file squeeze.c.

int linepos = 0 [static]

Definition at line 55 of file squeeze.c.

FILE * out

Definition at line 54 of file squeeze.c.

int stringlen = 0 [static]

Definition at line 57 of file squeeze.c.