Implements the following instructions:

1) open(i|ic,i|ic,s|sc) - Filehandle in $1, r/w mode in $2 (permissions
644), filename in $3
2) read(s,i|ic,i|ic) - String register in $1, filehandle in $2, number
of chars in $3
3) write(i,s) - Filehandle in $1, string register in $2
4) close(i) - Filehandle in $1

You'll need to determine constants for O_CREAT &c on a per-platform
basis. The modes will probably need to be manifest constants. For
instance, O_CREAT|O_WRONLY on Linux is 65.

On UNIX, the following program takes input from command line and echoes
it:

read S0,1,80 ; take 80 characters from STDIN (Also will need to be a
manifest constant
print S1 ; print the string from STDIN
end

Writing to a file looks like this:

open I0,65,"test" ; O_CREAT|O_WRONLY, write to file 'test'
write I0,"Hey, here's some test data" ; Write some sample data in
close I0
end

This may not even vaguely resemble the I/O model we eventually adopt,
but it's one idea. Albeit a simplistic model.

--
Jeff
<[EMAIL PROTECTED]>

7,9d6
< #include <sys/types.h>
< #include <sys/stat.h>
< #include <fcntl.h>
75,139d71
< 
< 
< ########################################
< 
< =item B<open>(i,i|ic,s|sc)
< 
< Open file with name (string, parameter 3) with mod (int, parameter 2), and
< save the filenum into the register in parameter 1.
< 
< =cut
< 
< AUTO_OP open(i,i|ic,s|sc) {
<   STRING *s = $3;
<   $1 = open(s->bufstart,$2,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
< }
< 
< 
< ########################################
< 
< =item read(s,i|ic,i|ic)
< 
< Read $3 characters from filehandle $1 into string $2
< 
< =cut
< 
< AUTO_OP read(s,i|ic,i|ic) {
<   char *tmp;
<   STRING *s;
<   INTVAL len = $3;
< 
<   string_destroy($1);
<   tmp = malloc(len+1);
<   read($2,tmp,len);
<   s = string_make(interpreter,tmp,len,0,0,0);
<   $1 = s;
<   free(tmp);
< }
< 
< 
< ########################################
< 
< =item write(i,s)
< 
< Write the text at parameter 2 into filehandle with parameter 1.
< 
< =cut
< 
< AUTO_OP write(i,s) {
<   STRING * s = $2;
<   INTVAL count = string_length(s);
<   write($1,s->bufstart,count);
< }
< 
< 
< ########################################
< 
< =item close(i)
< 
< Close file reserved on the filehandle in parameter 1.
< 
< =cut
< 
< AUTO_OP close(i) {
<   close($1);
< }

Reply via email to