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