1// -*- C++ -*-
2/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003, 2005
3   Free Software Foundation, Inc.
4     Written by James Clark (jjc@jclark.com)
5
6This file is part of groff.
7
8groff is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 2, or (at your option) any later
11version.
12
13groff is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License along
19with groff; see the file COPYING.  If not, write to the Free Software
20Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21
22#include "lib.h"
23
24#include <math.h>
25#include <stdlib.h>
26#include <errno.h>
27
28#ifdef NEED_DECLARATION_RAND
29#undef rand
30extern "C" {
31  int rand();
32}
33#endif /* NEED_DECLARATION_RAND */
34
35#ifdef NEED_DECLARATION_SRAND
36#undef srand
37extern "C" {
38#ifdef RET_TYPE_SRAND_IS_VOID
39  void srand(unsigned int);
40#else
41  int srand(unsigned int);
42#endif
43}
44#endif /* NEED_DECLARATION_SRAND */
45
46#ifndef HAVE_FMOD
47extern "C" {
48  double fmod(double, double);
49}
50#endif
51
52#include "assert.h"
53#include "cset.h"
54#include "stringclass.h"
55#include "errarg.h"
56#include "error.h"
57#include "position.h"
58#include "text.h"
59#include "output.h"
60
61#ifndef M_SQRT2
62#define M_SQRT2	1.41421356237309504880
63#endif
64
65#ifndef M_PI
66#define M_PI 3.14159265358979323846
67#endif
68
69class input {
70  input *next;
71public:
72  input();
73  virtual ~input();
74  virtual int get() = 0;
75  virtual int peek() = 0;
76  virtual int get_location(const char **, int *);
77  friend class input_stack;
78  friend class copy_rest_thru_input;
79};
80
81class file_input : public input {
82  FILE *fp;
83  const char *filename;
84  int lineno;
85  string line;
86  const char *ptr;
87  int read_line();
88public:
89  file_input(FILE *, const char *);
90  ~file_input();
91  int get();
92  int peek();
93  int get_location(const char **, int *);
94};
95
96void lex_init(input *);
97int get_location(char **, int *);
98
99void do_copy(const char *file);
100void parse_init();
101void parse_cleanup();
102
103void lex_error(const char *message,
104	       const errarg &arg1 = empty_errarg,
105	       const errarg &arg2 = empty_errarg,
106	       const errarg &arg3 = empty_errarg);
107
108void lex_warning(const char *message,
109		 const errarg &arg1 = empty_errarg,
110		 const errarg &arg2 = empty_errarg,
111		 const errarg &arg3 = empty_errarg);
112
113void lex_cleanup();
114
115extern int flyback_flag;
116extern int command_char;
117// zero_length_line_flag is non-zero if zero-length lines are drawn
118// as dots by the output device
119extern int zero_length_line_flag;
120extern int driver_extension_flag;
121extern int compatible_flag;
122extern int safer_flag;
123extern char *graphname;
124