1 /* grecs - Gray's Extensible Configuration System 2 Copyright (C) 2007-2016 Sergey Poznyakoff 3 4 Grecs is free software; you can redistribute it and/or modify it 5 under the terms of the GNU General Public License as published by the 6 Free Software Foundation; either version 3 of the License, or (at your 7 option) any later version. 8 9 Grecs is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with Grecs. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #ifdef HAVE_CONFIG_H 18 # include <config.h> 19 #endif 20 #include <stdlib.h> 21 #include <string.h> 22 #include <errno.h> 23 #include "grecs.h" 24 25 int grecs_error_count = 0; 26 int grecs_default_port = 0; 27 28 int grecs_trace_flags = 0; 29 int grecs_parser_options = 0; 30 31 #ifndef GRECS_DEFAULT_PARSER 32 # define GRECS_DEFAULT_PARSER grecs_grecs_parser 33 #endif 34 35 struct grecs_node *(*grecs_parser_fun)(const char *name, int trace) = 36 GRECS_DEFAULT_PARSER; 37 38 void grecs_gram_trace(int n)39grecs_gram_trace(int n) 40 { 41 if (n) 42 grecs_trace_flags |= GRECS_TRACE_GRAM; 43 else 44 grecs_trace_flags &= ~GRECS_TRACE_GRAM; 45 } 46 47 void grecs_lex_trace(int n)48grecs_lex_trace(int n) 49 { 50 if (n) 51 grecs_trace_flags |= GRECS_TRACE_LEX; 52 else 53 grecs_trace_flags &= ~GRECS_TRACE_LEX; 54 } 55 56 struct grecs_node * grecs_parse(const char * name)57grecs_parse(const char *name) 58 { 59 if (!grecs_trace_flags) { 60 char *p = getenv("GRECS_DEBUG"); 61 if (p) { 62 while (*p) { 63 switch (*p++) { 64 case 'g': 65 case 'G': 66 grecs_trace_flags |= GRECS_TRACE_GRAM; 67 break; 68 case 'l': 69 case 'L': 70 grecs_trace_flags |= GRECS_TRACE_LEX; 71 break; 72 } 73 } 74 } 75 } 76 grecs_error_count = 0; 77 grecs_current_locus_point.file = grecs_install_text(name); 78 grecs_current_locus_point.line = 1; 79 grecs_current_locus_point.col = 0; 80 return grecs_parser_fun(name, grecs_trace_flags); 81 } 82