2000-05-05 15:25:49 +00:00
|
|
|
#include <printer.h>
|
1996-10-21 10:42:45 +00:00
|
|
|
#include <relation.h>
|
1996-05-08 11:09:13 +00:00
|
|
|
#include <text.h>
|
1996-10-21 10:42:45 +00:00
|
|
|
#include <window.h>
|
1996-05-08 11:09:13 +00:00
|
|
|
#include <xvtility.h>
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
#define TEXT_TMP_SIZE 1024
|
|
|
|
static TString _TEXT_TMP(TEXT_TMP_SIZE);
|
2003-02-25 14:39:02 +00:00
|
|
|
static char* TEXT_TMP = (char*)(const char*)_TEXT_TMP;
|
1994-08-17 07:58:50 +00:00
|
|
|
|
1994-08-17 09:21:00 +00:00
|
|
|
class _HotSpot : public TObject
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1994-11-03 09:03:14 +00:00
|
|
|
public:
|
|
|
|
// TArray _spots; // tokenstrings
|
1994-08-17 07:58:50 +00:00
|
|
|
char _bg, _fg;
|
|
|
|
|
1994-11-03 09:03:14 +00:00
|
|
|
_HotSpot (char fg, char bg)
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
_fg = fg;
|
|
|
|
_bg = bg;
|
|
|
|
}
|
|
|
|
virtual ~ _HotSpot ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
1995-10-20 18:27:01 +00:00
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @mfunc Permette di settare gli hot_spot
|
1995-10-20 18:27:01 +00:00
|
|
|
void TTextfile::set_hotspots (
|
|
|
|
char fg, // @parm Colore di foreground da utilizzare per l'hotspot
|
|
|
|
char bg) // @parm Colore di background da utilizzare per l'hotspot
|
|
|
|
|
|
|
|
// @comm Aggiunge all'array gli hotspots relativi alla pagina in memoria
|
|
|
|
// (come <c TToken_string> con x<pipe>y<pipe>text)
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
_HotSpot *hp = new _HotSpot (fg, bg);
|
|
|
|
_hotspots.add (hp);
|
|
|
|
}
|
|
|
|
|
1994-08-17 09:21:00 +00:00
|
|
|
style TTextfile::_trans_style (char ch)
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
switch (ch)
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
|
|
|
case 'r':
|
|
|
|
return normal;
|
|
|
|
case 'i':
|
|
|
|
return italic;
|
|
|
|
case 'b':
|
|
|
|
return bold;
|
|
|
|
case 'u':
|
|
|
|
return underlined;
|
1995-05-12 09:24:47 +00:00
|
|
|
case 't':
|
|
|
|
return tabbed;
|
1994-11-03 09:03:14 +00:00
|
|
|
default:
|
|
|
|
return normal;
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1995-01-09 12:15:24 +00:00
|
|
|
|
|
|
|
void TTextfile::_save_changes()
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
TWait_cursor hourglass;
|
|
|
|
|
1995-01-09 12:15:24 +00:00
|
|
|
// fa i dovuti replace anche sul disco (solo replace di linee esistenti)
|
|
|
|
long line = 0l;
|
|
|
|
|
|
|
|
fclose(_index);
|
|
|
|
remove(_indname);
|
|
|
|
|
1999-01-19 09:15:17 +00:00
|
|
|
const TString oldfile(_filename);
|
1995-01-09 12:15:24 +00:00
|
|
|
_filename.temp("txtf");
|
|
|
|
|
|
|
|
FILE* newf = fopen(_filename, "a+");
|
|
|
|
|
|
|
|
if ((_index = fopen(_indname, "w+b")) == NULL || newf == NULL)
|
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
NFCHECK("Impossibile aprire files temporanei");
|
1995-01-09 12:15:24 +00:00
|
|
|
freeze();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-01-19 09:15:17 +00:00
|
|
|
// fseek(_instr, 0l, SEEK_SET);
|
|
|
|
rewind(_instr);
|
1995-01-09 12:15:24 +00:00
|
|
|
|
|
|
|
while (!feof(_instr))
|
|
|
|
{
|
|
|
|
const long l = ftell(newf);
|
|
|
|
fwrite (&l, sizeof(long), 1, _index);
|
|
|
|
|
|
|
|
if (ferror(_index) || ferror(newf))
|
|
|
|
{
|
|
|
|
error_box ("Errore di scrittura file temporaneo: scrittura interrotta");
|
|
|
|
freeze ();
|
|
|
|
}
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
if (fgets(TEXT_TMP, TEXT_TMP_SIZE, _instr) == NULL)
|
1995-01-09 12:15:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (line >= _page_start && line <= _page_end)
|
|
|
|
{
|
|
|
|
TString& lin = (TString&)(_page[(int)(line - _page_start)]);
|
|
|
|
if (_dirty_lines[line - _page_start])
|
|
|
|
{
|
1995-05-12 09:24:47 +00:00
|
|
|
strcpy(TEXT_TMP, lin);
|
|
|
|
strcat(TEXT_TMP, "\n");
|
1995-01-09 12:15:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-05-12 09:24:47 +00:00
|
|
|
fprintf(newf, "%s", TEXT_TMP);
|
1995-01-09 12:15:24 +00:00
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fflush(_index);
|
|
|
|
fclose(_instr);
|
|
|
|
fclose(newf);
|
|
|
|
remove(oldfile);
|
|
|
|
rename(_filename, oldfile);
|
|
|
|
_filename = oldfile;
|
|
|
|
_instr = fopen(_filename, "a+");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TTextfile::_read_page (long n)
|
|
|
|
{
|
|
|
|
if (_dirty_lines.ones() > 0l)
|
|
|
|
{
|
|
|
|
_save_changes();
|
|
|
|
_dirty_lines.reset();
|
|
|
|
}
|
|
|
|
|
1994-08-17 07:58:50 +00:00
|
|
|
switch (_direction)
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
|
|
|
case down:
|
|
|
|
_page_start = n;
|
|
|
|
break;
|
|
|
|
case up:
|
|
|
|
_page_start = n + _page_size;
|
|
|
|
break;
|
|
|
|
case updown:
|
|
|
|
_page_start = n - (_page_size / 2l);
|
|
|
|
break;
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
|
|
|
|
if (_page_start < 0l)
|
|
|
|
_page_start = 0l;
|
|
|
|
if ((_page_start + _page_size) > _lines)
|
|
|
|
_page_end = _lines - 1;
|
|
|
|
else
|
|
|
|
_page_end = _page_start + _page_size - 1;
|
|
|
|
|
|
|
|
// zap hotspots
|
|
|
|
_spots.destroy ();
|
|
|
|
|
|
|
|
long l = 0l;
|
|
|
|
if (_page_start != 0l)
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
|
|
|
fseek (_index, _page_start * (long) sizeof (long), SEEK_SET);
|
1994-08-17 07:58:50 +00:00
|
|
|
fread (&l, sizeof (long), 1, _index);
|
1999-10-22 10:00:18 +00:00
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
fseek (_instr, l, SEEK_SET);
|
1995-05-16 13:42:37 +00:00
|
|
|
|
1994-08-17 07:58:50 +00:00
|
|
|
for (long i = _page_start; i <= _page_end; i++)
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
|
|
|
if (feof (_instr))
|
|
|
|
break;
|
1999-07-16 14:59:11 +00:00
|
|
|
fgets (TEXT_TMP, TEXT_TMP_SIZE, _instr);
|
1995-05-12 09:24:47 +00:00
|
|
|
TEXT_TMP[strlen (TEXT_TMP) - 1] = '\0';
|
1994-11-03 09:03:14 +00:00
|
|
|
TString & ts = (TString &) _page[(int) (i - _page_start)];
|
1999-10-22 10:00:18 +00:00
|
|
|
CHECK(ts.size() > 0, "Corrupted string");
|
1995-05-12 09:24:47 +00:00
|
|
|
ts = TEXT_TMP;
|
1995-05-16 13:42:37 +00:00
|
|
|
if (_interactive)
|
|
|
|
{
|
|
|
|
TString hcol (6);
|
|
|
|
// find hotspots and compile list
|
1994-11-03 09:03:14 +00:00
|
|
|
|
1995-05-16 13:42:37 +00:00
|
|
|
int len = 0;
|
|
|
|
const char *cp;
|
|
|
|
read_line (i, 0, FALSE);
|
2004-03-12 15:41:25 +00:00
|
|
|
while ((cp = piece ()))
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
1995-05-16 13:42:37 +00:00
|
|
|
for (int z = 0; z < _hotspots.items (); z++)
|
1994-08-17 09:21:00 +00:00
|
|
|
{
|
1995-05-16 13:42:37 +00:00
|
|
|
_HotSpot & hs = (_HotSpot &) _hotspots[z];
|
|
|
|
if (hs._fg == get_foreground () && hs._bg == get_background ())
|
|
|
|
{
|
|
|
|
TToken_string *tts = new TToken_string (50);
|
|
|
|
tts->add (i); // line number
|
|
|
|
|
|
|
|
tts->add (len);
|
|
|
|
tts->add (len + (int) strlen (cp));
|
|
|
|
tts->add (cp);
|
|
|
|
tts->add (z);
|
|
|
|
_spots.add (tts);
|
|
|
|
break;
|
|
|
|
}
|
1994-08-17 09:21:00 +00:00
|
|
|
}
|
1995-05-16 13:42:37 +00:00
|
|
|
len += strlen (cp);
|
1994-11-03 09:03:14 +00:00
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
1995-10-20 18:27:01 +00:00
|
|
|
|
|
|
|
// @mfunc Legge il testo formattato
|
|
|
|
void TTextfile::read_line (
|
|
|
|
long n, // @parm Numero della linea da leggere
|
|
|
|
long pos, // @parm Numero della colonna da leggere (mai utilizzata)
|
|
|
|
bool pg) // @parm Fa si' che se la linea non e' nella pagina corrente non si faccia nulla,
|
|
|
|
// diversamente rilegge una nuova pagina dal file.
|
|
|
|
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
CHECK (_isopen, "Attempt operation on closed file");
|
1999-04-26 15:58:05 +00:00
|
|
|
// CHECKD (n >= 0 && n < _lines, "Line not present", n);
|
1994-08-17 07:58:50 +00:00
|
|
|
|
|
|
|
if (pg && !_in_page (n))
|
|
|
|
_read_page (n);
|
|
|
|
|
|
|
|
TString *tp = (TString *) _page.objptr (int (n - _page_start));
|
|
|
|
if (tp == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const char *sp = (const char *) (*tp);
|
|
|
|
_item = 0;
|
|
|
|
_line = "";
|
|
|
|
int ndx = 0, p = 0;
|
|
|
|
bool first = TRUE;
|
|
|
|
_cur_line = n;
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
int col = ((int) 'w' << 8) | (int) 'n';
|
|
|
|
long stl = (long) col << 16;
|
|
|
|
|
2004-03-12 15:41:25 +00:00
|
|
|
while ((ch = *sp++))
|
1995-06-22 09:30:05 +00:00
|
|
|
{
|
|
|
|
if (ch == '<' && *(sp) == '@')
|
|
|
|
{
|
|
|
|
// merge field if rel != NULL;
|
|
|
|
// else fill with whitespace
|
1997-10-16 13:56:15 +00:00
|
|
|
const char * save_sp = sp;
|
|
|
|
|
1995-06-22 09:30:05 +00:00
|
|
|
TToken_string id(80, '@');
|
|
|
|
sp++;
|
1996-09-13 08:08:54 +00:00
|
|
|
bool terminated = FALSE;
|
|
|
|
while ((ch = *sp++) != '>' && !terminated)
|
|
|
|
if (ch != '\0')
|
|
|
|
id << ch;
|
|
|
|
else terminated = TRUE;
|
1997-10-16 13:56:15 +00:00
|
|
|
if (!terminated) // Prosegue normalmente se non trova la matching >
|
1995-06-22 09:30:05 +00:00
|
|
|
{
|
1997-10-16 13:56:15 +00:00
|
|
|
// id contains tokenstring separated by @
|
|
|
|
// but with casinations for possible lack of spacing
|
|
|
|
// add spaces if needed
|
|
|
|
for (int i = 0; i < id.len(); i++)
|
|
|
|
{
|
|
|
|
if (id[i] == '@' && id [i+1] == '@')
|
|
|
|
{
|
|
|
|
id.insert(" ", i+1);
|
|
|
|
i+= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// parse string
|
|
|
|
int len;
|
|
|
|
TString80 file;
|
|
|
|
TString16 field;
|
|
|
|
TString80 format;
|
|
|
|
char just;
|
|
|
|
|
|
|
|
file = id.get();
|
|
|
|
format = id.get();
|
|
|
|
len = (int)id.get_long();
|
|
|
|
just = id.get_char();
|
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
if ((pos = file.find("->")) == -1)
|
|
|
|
error_box("field specification error");
|
1995-06-22 09:30:05 +00:00
|
|
|
else
|
|
|
|
{
|
1997-10-16 13:56:15 +00:00
|
|
|
file.cut(pos);
|
|
|
|
field = file.mid(pos+2);
|
1995-06-22 09:30:05 +00:00
|
|
|
}
|
1997-10-16 13:56:15 +00:00
|
|
|
|
|
|
|
if (len == 0) len = id.len();
|
|
|
|
|
|
|
|
TString txt(512);
|
|
|
|
TFieldtypes type;
|
|
|
|
|
|
|
|
if (_rel != NULL)
|
|
|
|
{
|
|
|
|
// retrieve file and field
|
|
|
|
if (atoi(file) == 0)
|
|
|
|
{
|
|
|
|
// tabella
|
|
|
|
TLocalisamfile& t = _rel->lfile(file);
|
|
|
|
txt = t.get(field);
|
|
|
|
type = t.curr().type(field);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TLocalisamfile& f = _rel->lfile(atoi(file));
|
|
|
|
txt = f.get(field);
|
|
|
|
type = f.curr().type(field);
|
|
|
|
}
|
|
|
|
// apply format to date and number
|
|
|
|
switch (type)
|
1995-06-22 09:30:05 +00:00
|
|
|
{
|
|
|
|
case _longfld:
|
1997-10-16 13:56:15 +00:00
|
|
|
case _realfld:
|
|
|
|
{
|
|
|
|
real r(txt);
|
|
|
|
txt = r.string(format);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case _datefld:
|
|
|
|
{
|
|
|
|
TDate dd(txt);
|
|
|
|
TFormatted_date d(dd, format);
|
|
|
|
txt = d.string();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// justify as requested
|
|
|
|
if (txt.len() < len)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case _longfld:
|
|
|
|
case _realfld:
|
|
|
|
txt.right_just(len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
txt.left_just(len);
|
|
|
|
break;
|
|
|
|
}
|
1995-06-22 09:30:05 +00:00
|
|
|
}
|
|
|
|
}
|
1997-10-16 13:56:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
txt.left_just(len);
|
|
|
|
}
|
|
|
|
// ficca il testo cola' dove si puote
|
2004-03-12 15:41:25 +00:00
|
|
|
const int txtlen = txt.len();
|
1999-10-22 10:00:18 +00:00
|
|
|
for (int k = 0; k < txtlen; k++)
|
1997-10-16 13:56:15 +00:00
|
|
|
TEXT_TMP[ndx++] = txt[k];
|
|
|
|
} // see (!terminated) above
|
|
|
|
else // Restore sp pointer
|
1995-06-22 09:30:05 +00:00
|
|
|
{
|
1997-10-16 13:56:15 +00:00
|
|
|
sp = save_sp;
|
|
|
|
ch = '<';
|
1995-06-22 09:30:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-11-03 09:03:14 +00:00
|
|
|
if (ch == '@' || (ch == '$' && *(sp) == '['))
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1994-11-03 09:03:14 +00:00
|
|
|
if (!first && p >= pos)
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
|
|
|
CHECKD(ndx < TEXT_TMP_SIZE, "Bad TEXT_TMP index ", ndx);
|
1994-11-03 09:03:14 +00:00
|
|
|
_styles[_item++] = stl;
|
1995-05-12 09:24:47 +00:00
|
|
|
TEXT_TMP[ndx] = '\0';
|
|
|
|
_line.add (TEXT_TMP);
|
1994-11-03 09:03:14 +00:00
|
|
|
ndx = 0;
|
|
|
|
}
|
|
|
|
while (ch && (ch == '@' || (ch == '$' && *sp == '[')))
|
|
|
|
{
|
|
|
|
if (ch == '@') // font style change ?
|
1995-05-12 09:24:47 +00:00
|
|
|
{
|
|
|
|
const char c = *sp++;
|
1999-10-22 10:00:18 +00:00
|
|
|
if (c == '@')
|
|
|
|
{
|
|
|
|
_styles[_item++] = stl;
|
|
|
|
_line.add("@");
|
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
else
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
|
|
|
style sss = _trans_style (c);
|
|
|
|
if (sss == normal)
|
|
|
|
stl = (long) col << 16;
|
|
|
|
else
|
|
|
|
stl |= (long) sss;
|
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
}
|
|
|
|
else if (ch == '$' && *sp == '[') // color change
|
|
|
|
{
|
|
|
|
++sp; // eat '['
|
|
|
|
|
|
|
|
col = *sp++;
|
|
|
|
++sp; // eat ','
|
|
|
|
|
|
|
|
col |= ((int) (*sp++) << 8);
|
|
|
|
++sp; // eat ']'
|
|
|
|
|
|
|
|
stl = (stl & 0x0000ffff) | ((long) col << 16);
|
|
|
|
}
|
|
|
|
ch = *sp++;
|
|
|
|
} // while
|
|
|
|
|
|
|
|
}
|
|
|
|
if (ch && p >= pos)
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
|
|
|
CHECKD(ndx < TEXT_TMP_SIZE, "Bad TEXT_TMP index ", ndx);
|
1994-11-03 09:03:14 +00:00
|
|
|
first = FALSE;
|
1995-05-12 09:24:47 +00:00
|
|
|
TEXT_TMP[ndx++] = ch;
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
p++;
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
_styles[_item++] = stl;
|
1995-05-12 09:24:47 +00:00
|
|
|
TEXT_TMP[ndx] = '\0';
|
|
|
|
_line.add(TEXT_TMP);
|
1994-08-17 07:58:50 +00:00
|
|
|
_item = 0;
|
|
|
|
}
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Ritorna la stringa di caratteri senza formattazione
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna la stringa di caratteri ed eventualmente con i campi sostituiti
|
|
|
|
// se la relazione non e' NULL
|
2009-07-15 15:10:28 +00:00
|
|
|
const char* TTextfile::line(
|
1995-10-20 18:27:01 +00:00
|
|
|
long j, // @parm Riga di cui ritornare la stringa
|
|
|
|
long pos, // @parm Colonna di cui ritornare la stringa
|
2009-07-15 15:10:28 +00:00
|
|
|
int howmuch) // @parm Numero di caratteri utili della stringa da ritornare (default -1)
|
1995-10-20 18:27:01 +00:00
|
|
|
|
|
|
|
// @comm Se <p howmuch> assume valore -1 ritorna tutta la pagina
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
if (_cur_line != j)
|
|
|
|
read_line (j);
|
2009-07-15 15:10:28 +00:00
|
|
|
|
1995-05-12 09:24:47 +00:00
|
|
|
*TEXT_TMP = '\0';
|
2003-02-25 14:39:02 +00:00
|
|
|
FOR_EACH_TOKEN(_line, l)
|
|
|
|
strcat (TEXT_TMP, l);
|
2009-07-15 15:10:28 +00:00
|
|
|
|
|
|
|
if (howmuch >= 0)
|
1994-12-23 11:57:45 +00:00
|
|
|
{
|
1995-05-12 09:24:47 +00:00
|
|
|
if (((unsigned int)pos+howmuch) < strlen(TEXT_TMP))
|
|
|
|
TEXT_TMP[pos+howmuch] = '\0';
|
1994-12-23 11:57:45 +00:00
|
|
|
}
|
1995-05-12 09:24:47 +00:00
|
|
|
return strlen(TEXT_TMP) > (word)pos ? &(TEXT_TMP[pos]) : "";
|
1994-12-23 11:57:45 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Cerca una stringa di testo all'interno di una riga
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna la posizione in cui e' stato rintracciato il testo. Ritorna -1 se non e' stato
|
|
|
|
// trovato il testo passato.
|
|
|
|
long TTextfile::search(
|
|
|
|
const char* txt, // @parm Testo da cercare
|
|
|
|
int& ret, // @parm Intero in cui posizionare la posizne del carattere
|
|
|
|
long from, // @parm Posizione all'interno della riga da cui iniziare la ricerca (default 0)
|
|
|
|
bool down, // @parm Indica se la ricerca va effettuata all'indietro:
|
|
|
|
//
|
|
|
|
// @flag TRUE | Ricerca dalla posizione indicata all'inizio della riga (default)
|
|
|
|
// @flag FALSE | Ricerca dalla posizione indicata alla fine della riga
|
1996-06-10 08:06:06 +00:00
|
|
|
bool casesens, // @parm Indica se ricerca il testo con criterio case sensitive (default FALSE)
|
|
|
|
bool regexp) // @parm indica se considerare la stringa un'espressione regolare (def. FALSE)
|
1995-10-20 18:27:01 +00:00
|
|
|
|
|
|
|
// @comm Cerca in una riga per volta rispettando i formati
|
1994-12-23 11:57:45 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
TString text(txt);
|
1995-01-03 16:44:27 +00:00
|
|
|
if (!casesens)
|
1999-10-22 10:00:18 +00:00
|
|
|
text.lower();
|
2005-10-11 15:15:04 +00:00
|
|
|
if (regexp && !text.ends_with("*"))
|
1999-10-22 10:00:18 +00:00
|
|
|
text << '*';
|
1995-01-03 16:44:27 +00:00
|
|
|
|
2005-10-11 15:15:04 +00:00
|
|
|
TString lin(512);
|
1994-12-23 11:57:45 +00:00
|
|
|
for (long i = from; down ? (i < lines()) : (i >= 0); down ? i++ : i--)
|
|
|
|
{
|
1995-01-03 16:44:27 +00:00
|
|
|
lin = line(i);
|
1999-10-22 10:00:18 +00:00
|
|
|
if (!casesens)
|
|
|
|
lin.lower();
|
1996-06-10 08:06:06 +00:00
|
|
|
if (regexp)
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
for (ret = 0; lin[ret]; ret++)
|
|
|
|
{
|
2005-10-11 15:15:04 +00:00
|
|
|
if (lin.mid(ret).match(text))
|
1999-10-22 10:00:18 +00:00
|
|
|
return i;
|
|
|
|
}
|
1996-06-10 08:06:06 +00:00
|
|
|
}
|
|
|
|
else
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
|
|
|
ret = lin.find(text);
|
|
|
|
if (ret >= 0)
|
1996-06-10 08:06:06 +00:00
|
|
|
return i;
|
|
|
|
}
|
1994-12-23 11:57:45 +00:00
|
|
|
}
|
|
|
|
return -1l;
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Sostituisce un testo all'interno di una riga
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna la posizione in cui e' stato sostituito il testo. Ritorna -1 se non e' stata
|
|
|
|
// fatto nessuna operazione di sostituzione.
|
|
|
|
int TTextfile::replace(
|
|
|
|
long l, // @parm Numero della riga nella quale sostituire il testo
|
|
|
|
const char* txt, // @parm Test da inserire nella riga
|
|
|
|
int pos, // @parm Posizione nella quale inserire il testo (default 0)
|
|
|
|
int len) // @parm Lunghezza del testo da sostituire (default 0)
|
1994-12-23 11:57:45 +00:00
|
|
|
{
|
|
|
|
if (_cur_line != l)
|
|
|
|
read_line(l);
|
|
|
|
|
|
|
|
TString& line = (TString&)_page[int(l-_page_start)];
|
|
|
|
|
|
|
|
char ch; int i = 0, cnt = 0, skip = 0;
|
|
|
|
bool sforating = FALSE;
|
|
|
|
|
|
|
|
// here's a nice casin
|
1996-05-08 11:09:13 +00:00
|
|
|
while(i < 256)
|
1994-12-23 11:57:45 +00:00
|
|
|
{
|
|
|
|
if (!sforating)
|
|
|
|
{
|
|
|
|
ch = line[i++];
|
|
|
|
if (ch == '\0')
|
|
|
|
sforating = TRUE;
|
1995-05-25 10:47:36 +00:00
|
|
|
else if (ch == '@' && strchr("ribuokt",line[i]) != NULL)
|
1994-12-23 11:57:45 +00:00
|
|
|
{
|
1995-05-25 10:47:36 +00:00
|
|
|
skip +=2; i++; cnt--;
|
1994-12-23 11:57:45 +00:00
|
|
|
}
|
|
|
|
else if (ch == '$' && line[i] == '[')
|
|
|
|
{
|
1995-05-25 10:47:36 +00:00
|
|
|
skip +=3; i++; cnt--;
|
1994-12-23 11:57:45 +00:00
|
|
|
while(line[i++] != ']')
|
|
|
|
if (line[i] == '\0')
|
|
|
|
return -1;
|
|
|
|
else skip++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt == pos)
|
1995-01-11 10:20:40 +00:00
|
|
|
{
|
1994-12-23 11:57:45 +00:00
|
|
|
line.overwrite(txt, cnt+skip);
|
1995-01-09 12:15:24 +00:00
|
|
|
_dirty_lines.set(l-_page_start);
|
1994-12-23 11:57:45 +00:00
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
else cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Ritorna la stringa di caratteri con la formattazione
|
|
|
|
//
|
|
|
|
// @rdesc La stringa ritornata ha la formattazione (ovvere tutti i @codes, in modo che anche
|
|
|
|
// la printer la possa utilizzare)
|
|
|
|
const char *TTextfile::line_formatted(
|
|
|
|
long j) //parm Numero della riga da ritornare
|
1994-11-11 11:23:30 +00:00
|
|
|
{
|
|
|
|
if (_cur_line != j)
|
|
|
|
read_line (j);
|
|
|
|
TString* tp = (TString*)_page.objptr(int(j-_page_start));
|
1995-05-12 09:24:47 +00:00
|
|
|
strcpy(TEXT_TMP, (const char*)(*tp));
|
|
|
|
return TEXT_TMP;
|
1994-11-11 11:23:30 +00:00
|
|
|
}
|
|
|
|
|
1994-08-17 09:21:00 +00:00
|
|
|
long TTextfile::get_attribute (int pos)
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
long stl = 0;
|
1999-01-19 09:15:17 +00:00
|
|
|
if (pos == -1)
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
|
|
|
CHECK (_item > 0, "must execute piece() before style()!");
|
|
|
|
stl = _styles[_item - 1];
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
else
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
|
|
|
int x = 0, nd = 0;
|
|
|
|
const char *c;
|
|
|
|
_line.restart ();
|
1995-05-12 09:24:47 +00:00
|
|
|
while ((c = _line.get ()) != NULL)
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1994-11-03 09:03:14 +00:00
|
|
|
x += strlen (c);
|
|
|
|
stl = _styles[nd++];
|
|
|
|
if ((x - 1) >= pos)
|
|
|
|
break;
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
return stl;
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Ritorna lo stile del piece
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna un numero (vedi <t style>) indicante lo stile
|
|
|
|
int TTextfile::get_style (
|
|
|
|
int pos) // @parm Posizione del carattere di cui ritornare lo stile (default -1)
|
|
|
|
|
|
|
|
// @comm Se viene passato a <p pos> valore -1 ritorna lo stile di tutta la piece, altrimente
|
|
|
|
// solamente quello del carattere selezionato.
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1995-05-12 09:24:47 +00:00
|
|
|
const long x = get_attribute(pos) & ~tabbed;
|
1994-08-17 07:58:50 +00:00
|
|
|
return (int) (x & 0x0000ffff);
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Ritorna il colore di background del piece
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna il codice del colore, NULL se il carattere non esiste
|
|
|
|
char TTextfile::get_background (
|
|
|
|
int pos) // @parm Posizione del carattere di cui conoscere il colore di background (default -1)
|
|
|
|
|
|
|
|
// @comm Se <p pos> e' minore di 0 ritorna il colore dell'intero piece, altrimenti solamente
|
|
|
|
// quello del carattere selezionato.
|
|
|
|
//
|
|
|
|
// @xref <mf TTextfile::get_foreground>
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
long x = get_attribute (pos);
|
|
|
|
return (char) (x >> 24);
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Ritorna il colore di foreground del piece
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna il codice del colore, NULL se il carattere non esiste
|
|
|
|
char TTextfile::get_foreground (
|
|
|
|
int pos) // @parm Posizione del carattere di cui conoscere il colore di background (default -1)
|
|
|
|
|
|
|
|
// @comm Se <p pos> e' minore di 0 ritorna il colore dell'intero piece, altrimenti solamente
|
|
|
|
// quello del carattere selezionato.
|
|
|
|
//
|
|
|
|
// @xref <mf TTextfile::get_bakcground>
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
long x = get_attribute (pos);
|
|
|
|
return (char) ((x >> 16) & 0x000000ff);
|
|
|
|
}
|
|
|
|
|
1995-05-12 09:24:47 +00:00
|
|
|
const char* TTextfile::piece()
|
|
|
|
{
|
|
|
|
const char* l = _line.get(_item);
|
|
|
|
if (l == NULL)
|
1994-08-17 07:58:50 +00:00
|
|
|
return NULL;
|
1995-05-12 09:24:47 +00:00
|
|
|
_item++;
|
|
|
|
return strcpy(TEXT_TMP, l);
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Ritorna la parola alla posizione indicata
|
|
|
|
//
|
|
|
|
// @rdesc Stringa indicante la parola cercate
|
|
|
|
const char *TTextfile::word_at (
|
|
|
|
long x, // @parm Numero della parola da ritornare
|
|
|
|
long y) // @parm Numero della linea su cui cercare la parole
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
CHECK (_isopen, "Attempt operation on closed file");
|
|
|
|
TString s (line (y));
|
|
|
|
int x2 = 0;
|
|
|
|
|
|
|
|
if (x < s.len ())
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
|
|
|
while (isspace (s[(int) x]))
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1994-11-03 09:03:14 +00:00
|
|
|
if (x == (s.len () - 1) && y < (_lines - 1l))
|
|
|
|
{
|
|
|
|
s = line (++y);
|
|
|
|
x = 0l;
|
|
|
|
}
|
|
|
|
else if (x < (s.len () - 1))
|
|
|
|
x++;
|
|
|
|
else
|
|
|
|
break;
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
while (isalnum (s[(int) x]))
|
1995-05-12 09:24:47 +00:00
|
|
|
TEXT_TMP[x2++] = s[(int) x++];
|
1994-11-03 09:03:14 +00:00
|
|
|
}
|
1995-05-12 09:24:47 +00:00
|
|
|
TEXT_TMP[x2] = '\0';
|
|
|
|
return TEXT_TMP;
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Aggiunge una riga al text (con i formati del caso)
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna il risultato dell'operazione:
|
|
|
|
//
|
|
|
|
// @flag TRUE | Se la riga e' stat aggiuntac correttamente
|
|
|
|
// @flag FALSE | Se non e' riuscot ad aggiungere la riga
|
|
|
|
bool TTextfile::append (
|
|
|
|
const char *l) // @parm Riga da aggiungere
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
CHECK (_isopen, "Attempt operation on closed file");
|
|
|
|
|
|
|
|
if (!_accept)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
fseek (_instr, 0l, SEEK_END);
|
|
|
|
fseek (_index, 0l, SEEK_END);
|
|
|
|
long cpos = ftell (_instr);
|
|
|
|
fprintf (_instr, "%s\n", l);
|
|
|
|
fwrite (&cpos, sizeof (long), 1, _index);
|
|
|
|
if (ferror (_index) || ferror (_instr))
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
|
|
|
error_box ("Errore di scrittura file temporaneo: scrittura interrotta");
|
|
|
|
freeze ();
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
fflush (_index);
|
|
|
|
fflush (_instr);
|
|
|
|
|
|
|
|
_lines++;
|
1995-05-16 13:42:37 +00:00
|
|
|
_dirty = TRUE;
|
|
|
|
|
1999-01-19 09:15:17 +00:00
|
|
|
if ((_lines) < (_page_start + _page_size))
|
1995-05-16 13:42:37 +00:00
|
|
|
{
|
|
|
|
if (_interactive)
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1995-05-18 14:18:01 +00:00
|
|
|
_page.add (new TString(l), int(_lines - _page_start - 1));
|
1995-05-16 13:42:37 +00:00
|
|
|
_page_end++;
|
|
|
|
|
|
|
|
int len = 0;
|
|
|
|
const char *cp;
|
|
|
|
read_line (_lines - 1);
|
2004-03-12 15:41:25 +00:00
|
|
|
while ((cp = piece ()))
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
1995-05-16 13:42:37 +00:00
|
|
|
for (int z = 0; z < _hotspots.items (); z++)
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
1995-05-16 13:42:37 +00:00
|
|
|
_HotSpot & hs = (_HotSpot &) _hotspots[z];
|
|
|
|
if (hs._fg == get_foreground () && hs._bg == get_background ())
|
|
|
|
{
|
|
|
|
TToken_string *tts = new TToken_string (50);
|
|
|
|
tts->add (_lines - 1l); // line number
|
|
|
|
//
|
|
|
|
|
|
|
|
tts->add (len);
|
|
|
|
tts->add (len + (int) strlen (cp));
|
|
|
|
tts->add (cp);
|
|
|
|
tts->add (z);
|
|
|
|
_spots.add (tts);
|
|
|
|
break;
|
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
}
|
1995-05-16 13:42:37 +00:00
|
|
|
len += strlen (cp);
|
1994-11-03 09:03:14 +00:00
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1994-08-17 09:21:00 +00:00
|
|
|
void TTextfile::close ()
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
if (_isopen)
|
|
|
|
{
|
|
|
|
fclose (_instr);
|
|
|
|
fclose (_index);
|
|
|
|
_instr = _index = NULL;
|
|
|
|
_isopen = FALSE;
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1994-08-17 09:21:00 +00:00
|
|
|
void TTextfile::print ()
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
printer().print_txt(*this);
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-10-20 18:27:01 +00:00
|
|
|
// @mfunc Scrive il testo (non formattato) su file
|
|
|
|
//
|
1996-02-05 19:00:53 +00:00
|
|
|
// @rdesc Ritorna il risultato dell'operazione di scrittura
|
1995-10-20 18:27:01 +00:00
|
|
|
//
|
|
|
|
// @flag TRUE | Se e' riuscito a scrivere il testo
|
|
|
|
// @flag FALSE | Se ha avuto qualche problema nella gestione del file in cui scrivere
|
|
|
|
bool TTextfile::write (
|
|
|
|
const char *path, // @parm Nome del file in cui scrivere il testo
|
|
|
|
TPoint * from, // @parm Punto da cui iniziare a scrivere il testo
|
|
|
|
TPoint * to) // @parm Punto a cui terminare di scrivere il testo
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
2009-07-15 15:10:28 +00:00
|
|
|
FILE* fp = fopen(path, "w");
|
|
|
|
if (fp != NULL)
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
1996-04-12 09:51:26 +00:00
|
|
|
TString s(512);
|
1994-11-03 09:03:14 +00:00
|
|
|
long starty = from == NULL ? 0l : from->y;
|
|
|
|
int startx = from == NULL ? 0 : (int) from->x;
|
|
|
|
long endy = to == NULL ? _lines - 1l : to->y;
|
|
|
|
int endx = to == NULL ? -1 : (int) to->x;
|
|
|
|
for (long j = starty; j <= endy; j++)
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
s = line(j);
|
1994-11-03 09:03:14 +00:00
|
|
|
if (j == endy && endx == -1)
|
1996-05-08 11:09:13 +00:00
|
|
|
endx = s.len();
|
1994-11-03 09:03:14 +00:00
|
|
|
|
|
|
|
if (j == starty && j == endy)
|
1996-05-08 11:09:13 +00:00
|
|
|
s = s.sub(startx, endx);
|
1994-11-03 09:03:14 +00:00
|
|
|
else if (j == starty)
|
1996-05-08 11:09:13 +00:00
|
|
|
s = s.mid(startx);
|
1994-11-03 09:03:14 +00:00
|
|
|
else if (j == endy)
|
1996-05-08 11:09:13 +00:00
|
|
|
s = s.left(endx);
|
1994-11-03 09:03:14 +00:00
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
fprintf(fp, "%s\n", (const char *) s);
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
fclose (fp);
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
else
|
|
|
|
warning_box ("Impossibile scrivere il file %s; scrittura fallita", path);
|
2009-07-15 15:10:28 +00:00
|
|
|
return fp != NULL;
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
|
|
|
// @mfunc Scrive il testo da punto a punto (non formattato) su string_array
|
|
|
|
void TTextfile::write(
|
|
|
|
TString_array& arr, // @parm Array in cui scrivere il testo
|
|
|
|
TPoint * from, // @parm Punto da cui iniziare a scrivere il testo
|
|
|
|
TPoint * to) // @parm Punto a cui terminare di scrivere il testo
|
|
|
|
{
|
|
|
|
arr.destroy();
|
|
|
|
TString s(512);
|
|
|
|
long starty = from == NULL ? 0l : from->y;
|
|
|
|
int startx = from == NULL ? 0 : (int) from->x;
|
|
|
|
long endy = to == NULL ? _lines - 1l : to->y;
|
|
|
|
int endx = to == NULL ? -1 : (int) to->x;
|
|
|
|
for (long j = starty; j <= endy; j++)
|
|
|
|
{
|
|
|
|
s = line(j);
|
|
|
|
if (j == endy && endx == -1)
|
|
|
|
endx = s.len();
|
|
|
|
|
|
|
|
if (j == starty && j == endy)
|
|
|
|
s = s.sub(startx, endx);
|
|
|
|
else if (j == starty)
|
|
|
|
s = s.mid(startx);
|
|
|
|
else if (j == endy)
|
|
|
|
s = s.left(endx);
|
|
|
|
|
|
|
|
arr.add(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-15 15:10:28 +00:00
|
|
|
// Determina il tipo di una stringa: 0=ignoto; 1=stringa; 2=numero
|
|
|
|
static int str_type(TString& str)
|
|
|
|
{
|
|
|
|
str.trim();
|
|
|
|
bool is_string = false;
|
|
|
|
bool is_number = str.full();
|
|
|
|
for (int i=0; str[i]; i++)
|
|
|
|
{
|
|
|
|
if (isalnum(str[i]))
|
|
|
|
is_string = true;
|
|
|
|
if (strchr("0123456789,.", str[i]) == NULL)
|
|
|
|
is_number = false;
|
|
|
|
}
|
|
|
|
if (is_number)
|
|
|
|
{
|
|
|
|
str.strip(".");
|
|
|
|
str.replace(',', '.');
|
|
|
|
const real r(str);
|
|
|
|
str = r.stringe();
|
|
|
|
}
|
|
|
|
return is_number ? 2 : (is_string ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TTextfile::write_xls(const TFilename& xls)
|
|
|
|
{
|
|
|
|
const int headerlen = printer().headersize();
|
|
|
|
const int footerlen = printer().footersize();
|
|
|
|
const int pagelen = printer().formlen();
|
|
|
|
TString str;
|
|
|
|
|
|
|
|
TTabulator tab;
|
|
|
|
for (long j = headerlen; j < _lines && j < pagelen; j++)
|
|
|
|
{
|
|
|
|
const int row = j % pagelen;
|
|
|
|
if (row >= headerlen && row < pagelen-footerlen)
|
|
|
|
{
|
|
|
|
read_line(j);
|
|
|
|
int x = 0;
|
|
|
|
for (const char* cp = piece(); cp; cp = piece())
|
|
|
|
{
|
|
|
|
str = cp;
|
|
|
|
const int len = str.len();
|
2010-05-06 13:28:28 +00:00
|
|
|
if (str.full() && str_type(str) > 0)
|
|
|
|
tab.add_field(x, len);
|
2009-07-15 15:10:28 +00:00
|
|
|
x += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tab.sort();
|
|
|
|
|
|
|
|
TToken_string riga(256, '\t');
|
|
|
|
|
|
|
|
ofstream out(xls);
|
|
|
|
for (long j = 0; j < _lines; j++)
|
|
|
|
{
|
|
|
|
const int row = j % pagelen;
|
|
|
|
// Esporto la testata solo nella prima pagina ed il footer solo nell'ultima
|
|
|
|
if ((row < headerlen && j >= pagelen) || (row >= pagelen-footerlen && row < _lines-pagelen))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
read_line(j);
|
|
|
|
riga.cut(0);
|
|
|
|
int x = 0;
|
|
|
|
for (const char* cp = piece(); cp; cp = piece())
|
|
|
|
{
|
|
|
|
str = cp;
|
|
|
|
const int len = str.len();
|
|
|
|
const int st = str_type(str);
|
|
|
|
if (st > 0)
|
|
|
|
{
|
|
|
|
const int pos = tab.find_column(x, len);
|
|
|
|
if (pos >= 0)
|
|
|
|
riga.add(str, pos);
|
|
|
|
}
|
|
|
|
x += len;
|
|
|
|
}
|
|
|
|
if (riga.full())
|
|
|
|
out << riga << endl;
|
|
|
|
}
|
|
|
|
return xls.exist();
|
|
|
|
}
|
|
|
|
|
1994-08-17 09:21:00 +00:00
|
|
|
void TTextfile::destroy ()
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
CHECK(_istemp, "destroy() chiamata su testo permanente!");
|
1994-08-17 07:58:50 +00:00
|
|
|
if (_page.items () > 0)
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
|
|
|
if (_index)
|
|
|
|
fclose (_index);
|
|
|
|
if (_instr)
|
|
|
|
fclose (_instr);
|
2009-07-15 15:10:28 +00:00
|
|
|
_filename.fremove();
|
|
|
|
_indname.fremove();
|
1994-11-03 09:03:14 +00:00
|
|
|
_page_start = _lines = 0l;
|
|
|
|
_page_end = _cur_line = -1l;
|
|
|
|
_accept = TRUE;
|
|
|
|
_instr = fopen (_filename, "a+");
|
|
|
|
_indname.temp ();
|
|
|
|
_index = fopen (_indname, "w+b");
|
|
|
|
if (_index == NULL || _instr == NULL)
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
2010-05-06 13:28:28 +00:00
|
|
|
cantwrite_box (_filename);
|
1994-11-03 09:03:14 +00:00
|
|
|
freeze ();
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
1994-11-03 09:03:14 +00:00
|
|
|
_isopen = TRUE;
|
1995-05-16 13:42:37 +00:00
|
|
|
// _page.destroy ();
|
1994-11-03 09:03:14 +00:00
|
|
|
_spots.destroy ();
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1995-05-16 13:42:37 +00:00
|
|
|
TTextfile ::TTextfile (const char *file, int pagesize, direction preferred,
|
|
|
|
bool interactive):
|
2004-03-12 15:41:25 +00:00
|
|
|
_page (pagesize), _dirty_lines(pagesize), _page_start (0l), _page_end (-1l), _page_size (pagesize),
|
|
|
|
_lines (0l), _cur_line (-1), _filename (file), _index (NULL),
|
|
|
|
_direction (preferred), _item (0), _line (256), _hotspots (4), _dirty (FALSE),
|
|
|
|
_istemp (FALSE), _accept (TRUE), _interactive(interactive), _rel(NULL)
|
1995-06-22 09:30:05 +00:00
|
|
|
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
// open file & build index
|
1994-11-22 15:03:51 +00:00
|
|
|
if (file == NULL || *file <= ' ')
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
1995-01-09 12:15:24 +00:00
|
|
|
_filename.temp("txtf");
|
1994-11-03 09:03:14 +00:00
|
|
|
_istemp = TRUE;
|
1995-05-16 13:42:37 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < pagesize; i++)
|
|
|
|
_page.add(new TString(132));
|
1994-12-01 14:49:44 +00:00
|
|
|
_isopen = TRUE;
|
1994-08-17 07:58:50 +00:00
|
|
|
|
|
|
|
_instr = fopen (_filename, "a+");
|
1995-01-09 12:15:24 +00:00
|
|
|
_indname.temp("txti");
|
1994-08-17 07:58:50 +00:00
|
|
|
_index = fopen (_indname, "w+b");
|
|
|
|
|
|
|
|
if (_index == NULL || _instr == NULL)
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
2010-05-06 13:28:28 +00:00
|
|
|
cantwrite_box(_filename);
|
1994-11-03 09:03:14 +00:00
|
|
|
freeze ();
|
|
|
|
}
|
1994-12-01 14:49:44 +00:00
|
|
|
if (!_istemp)
|
|
|
|
while (!feof(_instr))
|
1994-11-03 09:03:14 +00:00
|
|
|
{
|
|
|
|
const long l = ftell (_instr);
|
|
|
|
fwrite (&l, sizeof (long), 1, _index);
|
1994-12-01 14:49:44 +00:00
|
|
|
if (ferror(_index) || ferror(_instr))
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
2010-05-06 13:28:28 +00:00
|
|
|
cantwrite_box(_indname);
|
1995-01-09 12:15:24 +00:00
|
|
|
freeze();
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
if (fgets (TEXT_TMP, TEXT_TMP_SIZE, _instr) == NULL)
|
1994-12-01 14:49:44 +00:00
|
|
|
break;
|
1994-11-03 09:03:14 +00:00
|
|
|
_lines++;
|
|
|
|
}
|
1994-08-17 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
1994-08-17 09:21:00 +00:00
|
|
|
TTextfile::~TTextfile ()
|
1994-08-17 07:58:50 +00:00
|
|
|
{
|
|
|
|
if (_index)
|
|
|
|
fclose (_index);
|
|
|
|
if (_instr)
|
|
|
|
fclose (_instr);
|
1995-01-20 11:58:42 +00:00
|
|
|
if (_istemp) remove ((const char *) _filename);
|
1994-08-17 07:58:50 +00:00
|
|
|
remove ((const char *) _indname);
|
|
|
|
}
|