/* actually -*-c++-*- */ #ifndef __TEXTFILE_H #define __TEXTFILE_H #ifndef __STDIO_H #include #endif #ifndef __STRINGS_H #include #endif #ifndef __WINDOW_H #include #endif #ifndef __RELATION_H //class TRelation; #include #endif enum direction {up, down, updown}; enum style {normal = XVT_FS_NONE, bold = XVT_FS_BOLD, italic = XVT_FS_ITALIC, underlined = XVT_FS_UNDERLINE, tabbed = XVT_FS_SCALE }; class TTextfile: public TObject { enum {DEFAULT_PAGESIZE = 128}; TArray _page; TBit_array _dirty_lines; long _page_start; long _page_end; long _page_size; long _lines; long _cur_line; TFilename _filename; TFilename _indname; FILE* _index; FILE* _instr; direction _direction; int _item; // Piece corrente TToken_string _line; // Testo riga corrente long _styles[256]; // Stile e colore carattere bool _tabbed_piece; TArray _hotspots; TArray _spots; bool _dirty; bool _isopen; bool _istemp; bool _accept; bool _interactive; // for merging with database fields TRelation* _rel; void _read_page(long line); bool _in_page(long l) { return l >= _page_start && l < _page_end; } void _save_changes(); // void _parse_style(long j); style _trans_style(char c); public: long lines() { return _lines; } bool changed() { return _dirty; } // line() ritorna la stringa di caratteri senza formattazione // ed eventualmente con i campi sostituiti se la relazione // non e' NULL const char* line(long row, long column = 0, int howmuch = -1); // line_formatted() la ritorna, come e' logico attendersi, con // la formattazione const char* line_formatted(long row); // appende una riga al text (con i formati del caso) bool append(const char* l); // chide tutti i files per poter copiare o eseguire operazioni // dopo close() non si puo' piu' fare nulla void close(); void print(); // chiude l'aggiunta di nuove linee void freeze() { _accept = FALSE; } bool frozen() { return !_accept; } // per leggere il testo formattato, si fa prima read_line, poi // si prende un pezzo per volta // style() ritorna lo stile (vedi enum) del piece() corrente // se chiamata con parametri ritorna lo stile del carattere alla // posizione data // get_background() e get_foreground() ritornano il suo colore di bg e fg // piece() ritorna il pezzo di linea successivo con stile e colore // invarianti, o NULL quando non ce n'e' piu' // bello, vero? void read_line(long j, long b = 0, bool pg = TRUE); const char* piece(); int get_style(int pos = -1); char get_background(int pos = -1); char get_foreground(int pos = -1); long get_attribute(int pos = -1); // ritorna la parola alla posizione indicata const char* word_at(long x, long y); // TBI ritorna il pezzo di testo da x a y // allochera' un altro TText che deve essere disfatto dall'utente TTextfile* section(TPoint& from, TPoint& to) { return this; } const char* name() { return (const char*)_filename; } void interactive(bool on = TRUE) { _interactive = on; } // scrive il testo (non formattato) su file, da punto a punto // (tutto per default) bool write(const char* path, TPoint* from = NULL, TPoint* to = NULL); // disfa tutto e svuota il file void destroy(); // search and replace (una riga per volta, rispetta i formati) // txt = text to search; pos = int to put the char position in; // from = where to start; down = FALSE == up long search (const char* txt, int& pos, long from = 0, bool down = TRUE, bool casesens = FALSE); // replace txt=txt in line=line at pos=pos for len=len int replace(long line, const char* txt, int pos = 0, int len = -1); // hypertext cazzuls // le si dice il colore che devono avere i punti selezionabili; // ritorna l'array in cui vengono messi gli hotspots relativi alla // pagina in memoria (come TToken_string con x|y|text) void set_hotspots(char fg, char bg = 'w'); TArray& hotspots() { return _spots; } // associa una relazione che viene usata (nello stato corrente) per // risolvere eventuali campi per merge (marcati nel testo come // <@file->fieldname@[format]@[len]@[just]> void set_relation(TRelation* r) { _rel = r; } TTextfile(const char* file = NULL, int pagesize = DEFAULT_PAGESIZE, direction preferred = updown, bool interactive = TRUE); virtual ~TTextfile(); }; #endif