175584Sru// -*- C++ -*-
2151497Sru/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003, 2005
3104862Sru   Free Software Foundation, Inc.
475584Sru     Written by James Clark (jjc@jclark.com)
575584Sru
675584SruThis file is part of groff.
775584Sru
875584Srugroff is free software; you can redistribute it and/or modify it under
975584Sruthe terms of the GNU General Public License as published by the Free
1075584SruSoftware Foundation; either version 2, or (at your option) any later
1175584Sruversion.
1275584Sru
1375584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY
1475584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or
1575584SruFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1675584Srufor more details.
1775584Sru
1875584SruYou should have received a copy of the GNU General Public License along
1975584Sruwith groff; see the file COPYING.  If not, write to the Free Software
20151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
2175584Sru
22104862Sru#include "lib.h"
23104862Sru
2475584Sru#include <math.h>
2575584Sru#include <stdlib.h>
2675584Sru#include <errno.h>
2775584Sru
28114402Sru#ifdef NEED_DECLARATION_RAND
29114402Sru#undef rand
30114402Sruextern "C" {
31114402Sru  int rand();
32114402Sru}
33114402Sru#endif /* NEED_DECLARATION_RAND */
34114402Sru
35114402Sru#ifdef NEED_DECLARATION_SRAND
36114402Sru#undef srand
37114402Sruextern "C" {
38114402Sru#ifdef RET_TYPE_SRAND_IS_VOID
39114402Sru  void srand(unsigned int);
40114402Sru#else
41114402Sru  int srand(unsigned int);
42114402Sru#endif
43114402Sru}
44114402Sru#endif /* NEED_DECLARATION_SRAND */
45114402Sru
46114402Sru#ifndef HAVE_FMOD
47114402Sruextern "C" {
48114402Sru  double fmod(double, double);
49114402Sru}
50114402Sru#endif
51114402Sru
5275584Sru#include "assert.h"
5375584Sru#include "cset.h"
5475584Sru#include "stringclass.h"
5575584Sru#include "errarg.h"
5675584Sru#include "error.h"
5775584Sru#include "position.h"
5875584Sru#include "text.h"
5975584Sru#include "output.h"
6075584Sru
6175584Sru#ifndef M_SQRT2
6275584Sru#define M_SQRT2	1.41421356237309504880
6375584Sru#endif
6475584Sru
6575584Sru#ifndef M_PI
6675584Sru#define M_PI 3.14159265358979323846
6775584Sru#endif
6875584Sru
6975584Sruclass input {
7075584Sru  input *next;
7175584Srupublic:
7275584Sru  input();
7375584Sru  virtual ~input();
7475584Sru  virtual int get() = 0;
7575584Sru  virtual int peek() = 0;
7675584Sru  virtual int get_location(const char **, int *);
7775584Sru  friend class input_stack;
7875584Sru  friend class copy_rest_thru_input;
7975584Sru};
8075584Sru
8175584Sruclass file_input : public input {
8275584Sru  FILE *fp;
8375584Sru  const char *filename;
8475584Sru  int lineno;
8575584Sru  string line;
8675584Sru  const char *ptr;
8775584Sru  int read_line();
8875584Srupublic:
8975584Sru  file_input(FILE *, const char *);
9075584Sru  ~file_input();
9175584Sru  int get();
9275584Sru  int peek();
9375584Sru  int get_location(const char **, int *);
9475584Sru};
9575584Sru
9675584Sruvoid lex_init(input *);
9775584Sruint get_location(char **, int *);
9875584Sru
9975584Sruvoid do_copy(const char *file);
10075584Sruvoid parse_init();
10175584Sruvoid parse_cleanup();
10275584Sru
10375584Sruvoid lex_error(const char *message,
10475584Sru	       const errarg &arg1 = empty_errarg,
10575584Sru	       const errarg &arg2 = empty_errarg,
10675584Sru	       const errarg &arg3 = empty_errarg);
10775584Sru
10875584Sruvoid lex_warning(const char *message,
10975584Sru		 const errarg &arg1 = empty_errarg,
11075584Sru		 const errarg &arg2 = empty_errarg,
11175584Sru		 const errarg &arg3 = empty_errarg);
11275584Sru
11375584Sruvoid lex_cleanup();
11475584Sru
11575584Sruextern int flyback_flag;
11675584Sruextern int command_char;
11775584Sru// zero_length_line_flag is non-zero if zero-length lines are drawn
11875584Sru// as dots by the output device
11975584Sruextern int zero_length_line_flag;
12075584Sruextern int driver_extension_flag;
12175584Sruextern int compatible_flag;
12275584Sruextern int safer_flag;
123114402Sruextern char *graphname;
124