#include "FIGlib.h"

/****************************************************************************

  main

  The main program, of course.
  Reads characters 1 by 1 from stdin, and makes lines out of them using
  addchar. Handles line breaking, (which accounts for most of the
  complexity in this function).

****************************************************************************/

int main(argc,argv)
int argc;
char *argv[];
{
  inchr c,c2;
  int last_was_eol_flag;

  fig_init(argc, argv);
  getparams();
  readcontrolfiles();
  readfont();
  linealloc();

  last_was_eol_flag = 0;

#ifdef TLF_FONTS
  toiletfont = 0;
#endif

  while ((c = getinchr())!=EOF) {

    if (c=='\n'&&paragraphflag&&!last_was_eol_flag) {
      ungetinchr(c2 = getinchr());
      c = ((isascii(c2)&&isspace(c2))?'\n':' ');
      }
    last_was_eol_flag = (isascii(c)&&isspace(c)&&c!='\t'&&c!=' ');

    if (deutschflag) {
      if (c>='[' && c<=']') {
        c = deutsch[c-'['];
        }
      else if (c >='{' && c <= '~') {
        c = deutsch[c-'{'+3];
        }
      }

    c = handlemapping(c);

    if (isascii(c)&&isspace(c)) {
      c = (c=='\t'||c==' ') ? ' ' : '\n';
      }

    if ((c>'\0' && c<' ' && c!='\n') || c==127) continue;

	f(c);
  }

  if (outlinelen!=0) {
    printline();
    }

  return 0;
}