nis-util  1.0.D108
lib/space.h
Go to the documentation of this file.
00001 //
00002 // nis-util - NIS Administration Utilities
00003 // Copyright (C) 2001, 2003, 2008, 2009, 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #ifndef LIB_SPACE_H
00020 #define LIB_SPACE_H
00021 
00022 #include <lib/ac/stdarg.h>
00023 #include <vector>
00024 
00025 #include <lib/source_location.h>
00026 #include <lib/gcc-attr.h>
00027 #include <lib/input.h>
00028 
00034 class space
00035 {
00036 public:
00040     virtual ~space();
00041 
00053     void error(const source_location &locn, const char *fmt, ...)
00054                                                          ATTRIBUTE_PRINTF(3, 4);
00055 
00062     const source_location &
00063     yak_location(void) const
00064     {
00065         return get_location();
00066     }
00067 
00068 protected:
00073     void discard_blank_lines(void);
00074 
00080     void discard_comments(void);
00081 
00088     void discard_backslash_newline(void);
00089 
00094     rcstring get_file_name(void) const { return filename; }
00095 
00108     void verror(const source_location &locn, const char *fmt, va_list)
00109                                                          ATTRIBUTE_PRINTF(3, 0);
00110 
00115     space(const rcstring &filename);
00116 
00121     void open(void);
00122 
00128     void close(void);
00129 
00133     typedef std::vector<rcstring> line_t;
00134 
00144     bool read_one_line(line_t &result);
00145 
00158     bool read_one_line(source_location &locn, line_t &result);
00159 
00171     void warning(const source_location &locn, const char *fmt, ...)
00172                                                          ATTRIBUTE_PRINTF(3, 4);
00173 
00187     void vwarning(const source_location &locn, const char *fmt, va_list ap)
00188                                                          ATTRIBUTE_PRINTF(3, 0);
00189 
00190 protected:
00195     void lex(void);
00196 
00197     enum token_ty
00198     {
00199         token_eof,
00200         token_eoln,
00201         token_string
00202     };
00203 
00208     token_ty get_token(void) const { return token; }
00209 
00218     rcstring get_value(void) const { return token_value; }
00219 
00229     const source_location &get_location(void) const { return locn; }
00230 
00236     void explain_sequence_errors(void);
00237 
00238 private:
00244     int getch(void);
00245 
00250     rcstring filename;
00251 
00257     input::pointer ip;
00258 
00264     bool non_printing_whine;
00265 
00271     token_ty token;
00272 
00277     rcstring token_value;
00278 
00285     int error_count;
00286 
00292     bool discard_comments_flag;
00293 
00300     bool discard_blank_lines_flag;
00301 
00308     bool discard_backslash_newline_flag;
00309 
00315     source_location locn;
00316 
00324     bool current_line_is_blank;
00325 
00326 private:
00332     bool explained_sequence_errors;
00333 
00337     space();
00338 
00342     space(const space &);
00343 
00347     space &operator=(const space &);
00348 };
00349 
00350 // vim: set ts=8 sw=4 et :
00351 #endif // LIB_SPACE_H