diff options
| author | Drahflow <drahflow@gmx.de> | 2013-12-22 17:05:46 +0100 |
|---|---|---|
| committer | Drahflow <drahflow@gmx.de> | 2013-12-22 17:05:46 +0100 |
| commit | 0bce2aecb9fddcacbd7353bcdc0c69703ed49e52 (patch) | |
| tree | f3e0e48ef874ebd0ef5d5fed90e41ca8f806214e /interpreter/ElymasSys.pm | |
| parent | 95129aebebc6f2552a600e443db4a207412f5f5b (diff) | |
read now universally returns (undecoded) string
Diffstat (limited to 'interpreter/ElymasSys.pm')
| -rw-r--r-- | interpreter/ElymasSys.pm | 53 |
1 files changed, 2 insertions, 51 deletions
diff --git a/interpreter/ElymasSys.pm b/interpreter/ElymasSys.pm index 9cb07d4..ad79b02 100644 --- a/interpreter/ElymasSys.pm +++ b/interpreter/ElymasSys.pm @@ -71,56 +71,8 @@ sub createFile { my $ret = POSIX::read($$scope->{' fd'}->[0], $buf, $count); die "read failed: $!" unless defined $ret; - $buf = [map { [ord, 'int'] } split //, $buf]; - - push @$data, [$buf, ['array', '[]', [['range', 0, $#{$buf}]], ['int']]]; - }, ['func', 'sys .file .read'], 'active'], - 'readall' => [sub { - my ($data) = @_; - - die "file not open" if $$scope->{' fd'}->[0] == -1; - - my $count = popInt($data); - - my $buf = []; - while($count) { - my $readbuf; - my $ret = POSIX::read($$scope->{' fd'}->[0], $readbuf, $count); - die "read failed: $!" unless defined $ret; - - $buf = [@$buf, map { [ord, 'int'] } split //, $readbuf]; - $count -= $ret; - } - - push @$data, [$buf, ['array', '[]', [['range', 0, $#{$buf}]], ['int']]]; - }, ['func', 'sys .file .read'], 'active'], - 'readstr' => [sub { - # FIXME: give the file an encoding and respect it here, buffering half-characters if needed - my ($data) = @_; - - die "file not open" if $$scope->{' fd'}->[0] == -1; - - my $count = popInt($data); - - my $buf; - my $ret = POSIX::read($$scope->{' fd'}->[0], $buf, $count); - die "read failed: $!" unless defined $ret; - push @$data, [$buf, 'string']; - }, ['func', 'sys .file .readstr'], 'active'], - 'write' => [sub { - my ($data) = @_; - - die "file not open" if $$scope->{' fd'}->[0] == -1; - - my $buf = popArray($data); - $buf = join '', map { chr($_->[0]) } @$buf; - - my $ret = POSIX::write($$scope->{' fd'}->[0], $buf, length $buf); - die "write failed: $!" unless defined $ret; - - push @$data, [$ret, 'int']; - }, ['func', 'sys .file .write'], 'active'], + }, ['func', 'sys .file .read'], 'active'], 'writeall' => [sub { my ($data) = @_; @@ -135,8 +87,7 @@ sub createFile { $buf = substr($buf, $ret); } }, ['func', 'sys .file .writeall'], 'active'], - 'writestr' => [sub { - # FIXME: give the file an encoding and respect it here + 'write' => [sub { my ($data) = @_; die "file not open" if $$scope->{' fd'}->[0] == -1; |
