Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

textfile.h

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      textfile.h
00004  *
00005  *      Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifndef __TEXTFILE_H__
00022 #define __TEXTFILE_H__
00023 
00024 #include "htdata.h"
00025 #include "stream.h"
00026 #include "syntax.h"
00027 
00028 /*
00029  *      CLASS ht_textfile
00030  */
00031  
00032 class ht_textfile: public ht_layer_streamfile {
00033 public:
00034 /* new */
00035         virtual bool convert_ofs2line(FILEOFS o, UINT *line, UINT *pofs)=0;
00036         virtual bool convert_line2ofs(UINT line, UINT pofs, FILEOFS *o)=0;
00037         virtual void delete_lines(UINT line, UINT count)=0;
00038         virtual void delete_chars(UINT line, UINT ofs, UINT count)=0;
00039         virtual bool get_char(UINT line, char *ch, UINT pos)=0;
00040         virtual bool getline(UINT line, UINT pofs, void *buf, UINT buflen, UINT *retlen, lexer_state *state)=0;
00041         virtual UINT getlinelength(UINT line)=0;
00042         virtual void insert_lines(UINT before, UINT count, void **line_ends = NULL, int *lineendlens = NULL)=0;
00043         virtual void insert_chars(UINT line, UINT ofs, void *chars, UINT len)=0;
00044         virtual bool has_line(UINT line)=0;
00045         virtual UINT linecount()=0;
00046         virtual void set_layered_assume(ht_streamfile *streamfile, bool changes_applied)=0;
00047         virtual void set_lexer(ht_syntax_lexer *lexer)=0;
00048 };
00049 
00050 /*
00051  *      CLASS ht_layer_textfile
00052  */
00053  
00054 class ht_layer_textfile: public ht_textfile {
00055 public:
00056                         void init(ht_textfile *textfile, bool own_textfile);
00057 /* overwritten */
00058         virtual bool convert_ofs2line(FILEOFS o, UINT *line, UINT *pofs);
00059         virtual bool convert_line2ofs(UINT line, UINT pofs, FILEOFS *o);
00060         virtual void delete_lines(UINT line, UINT count);
00061         virtual void delete_chars(UINT line, UINT ofs, UINT count);
00062         virtual bool get_char(UINT line, char *ch, UINT pos);
00063         virtual bool getline(UINT line, UINT pofs, void *buf, UINT buflen, UINT *retlen, lexer_state *state);
00064         virtual UINT getlinelength(UINT line);
00065         virtual void insert_lines(UINT before, UINT count, void **line_ends, int *lineendlens);
00066         virtual void insert_chars(UINT line, UINT ofs, void *chars, UINT len);
00067         virtual bool has_line(UINT line);
00068         virtual UINT linecount();
00069         virtual void set_layered_assume(ht_streamfile *streamfile, bool changes_applied);
00070         virtual void set_lexer(ht_syntax_lexer *lexer);
00071 };
00072 
00073 /*
00074  *      CLASS ht_ltextfile_line
00075  */
00076 
00077 class ht_ltextfile_line: public Object {
00078 public:
00079         virtual ~ht_ltextfile_line();
00080 
00081         lexer_state instate;
00082         struct {
00083                 FILEOFS ofs;
00084                 UINT len;
00085         } on_disk;
00086         bool is_in_memory;
00087         struct {
00088                 char *data;
00089                 UINT len;
00090         } in_memory;
00091         FILEOFS nofs;
00092         byte lineendlen;
00093         byte lineend[2];
00094 };
00095 
00096 /*
00097  *      CLASS ht_ltextfile
00098  */
00099  
00100 class ht_ltextfile: public ht_textfile {
00101 protected:
00102         FILEOFS ofs;
00103         ht_clist *lines;
00104         ht_clist *orig_lines;
00105         ht_syntax_lexer *lexer;
00106         UINT first_parse_dirty_line;
00107         UINT first_nofs_dirty_line;
00108         bool dirty;
00109 
00110                         void cache_invd();
00111                         void cache_flush();
00112                         void dirty_nofs(UINT line);
00113                         void dirty_parse(UINT line);
00114                         UINT find_linelen_forwd(byte *buf, UINT maxbuflen, FILEOFS ofs, int *le_len);
00115         virtual ht_ltextfile_line *fetch_line(UINT line);
00116                         ht_ltextfile_line *fetch_line_nofs_ok(UINT line);
00117                         ht_ltextfile_line *fetch_line_into_memory(UINT line);
00118                         UINT getlinelength_i(ht_ltextfile_line *e);
00119                         bool is_dirty_nofs(UINT line);
00120                         bool is_dirty_parse(UINT line);
00121                         byte *match_lineend_forwd(byte *buf, UINT buflen, int *le_len);
00122                         lexer_state next_instate(UINT line);
00123                         FILEOFS next_nofs(ht_ltextfile_line *l);
00124                         void split_line(UINT a, UINT pos, void *line_end, int line_end_len);
00125                         void update_nofs(UINT line);
00126                         void update_parse(UINT line);
00127                         void reread();
00128 public:
00129                         void    init(ht_streamfile *streamfile, bool own_streamfile, ht_syntax_lexer *lexer);
00130         virtual void done();
00131 /* overwritten (streamfile) */
00132         virtual void    copy_to(ht_stream *stream);
00133         virtual int     extend(UINT newsize);
00134         virtual UINT    get_size();
00135         virtual void    pstat(pstat_t *s);
00136         virtual UINT    read(void *buf, UINT size);
00137         virtual void set_layered(ht_streamfile *streamfile);
00138         virtual int     seek(FILEOFS offset);
00139         virtual FILEOFS tell();
00140         virtual int     truncate(UINT newsize);
00141         virtual int     vcntl(UINT cmd, va_list vargs);
00142         virtual UINT    write(const void *buf, UINT size);
00143 /* overwritten (textfile) */
00144         virtual bool convert_ofs2line(FILEOFS o, UINT *line, UINT *pofs);
00145         virtual bool convert_line2ofs(UINT line, UINT pofs, FILEOFS *o);
00146         virtual void delete_lines(UINT line, UINT count);
00147         virtual void delete_chars(UINT line, UINT ofs, UINT count);
00148         virtual bool get_char(UINT line, char *ch, UINT pos);
00149         virtual bool getline(UINT line, UINT pofs, void *buf, UINT buflen, UINT *retlen, lexer_state *state);
00150         virtual UINT getlinelength(UINT line);
00151         virtual void insert_lines(UINT before, UINT count, void **line_ends, int *lineendlens);
00152         virtual void insert_chars(UINT line, UINT ofs, void *chars, UINT len);
00153         virtual bool has_line(UINT line);
00154         virtual UINT linecount();
00155         virtual void set_layered_assume(ht_streamfile *streamfile, bool changes_applied);
00156         virtual void set_lexer(ht_syntax_lexer *lexer);
00157 };
00158 
00159 #endif /* __TEXTFILE_H__ */
00160 

Generated on Fri May 7 21:15:45 2004 by doxygen 1.3.5