#!/usr/local/bin/perl -w
sub
TIEARRAY
{
print
"TIEARRAY("
,
join
(
','
,
@_
),
")\n"
;
my
(
$class
,
$text
) =
@_
;
return
bless
[
$text
],
$class
;
}
sub
FETCH
{
my
(
$obj
,
$key
) =
@_
;
my
$text
= ${
$obj
}[0];
$key
++;
return
$text
->get(
$key
.
".0"
,
$key
.
".0+1 line"
);
}
sub
STORE
{
my
(
$obj
,
$key
,
$val
) =
@_
;
my
$text
= ${
$obj
}[0];
$key
++;
while
(
$text
->compare(
$key
.
".0"
,
'>'
,
'end'
))
{
$text
->insert(
'end'
,
"\n"
);
}
if
(
$text
->compare(
$key
.
".0+1 line"
,
'<'
,
'end'
))
{
$text
->
delete
(
$key
.
".0"
,
$key
.
".0+1 line"
);
}
chomp
(
$val
);
$text
->insert(
$key
.
".0"
,
$val
.
"\n"
);
print
"$key:$val\n"
;
$text
->update;
}
sub
LENGTH
{
my
(
$obj
) =
@_
;
my
$text
= ${
$obj
}[0];
print
$text
->
index
(
"end"
),
"\n"
;
my
(
$line
,
$col
) =
split
(/\./,
$text
->
index
(
"end"
));
$line
-= 3;
return
$line
;
}
}
$top
= MainWindow->new;
$text
=
$top
->Text;
$text
->
pack
;
tie
@lines
,Tk::Text::Contents,
$text
;
@lines
= <>;
my
$line
;
foreach
$line
(
@lines
)
{
s/^/Added:/;
}
MainLoop;