All -- [Thanks, Jeff]
Does anyone object to using this as a starting point? I'd like to have such ops, even if they are only there until we have a full I/O subsystem. Eventually, we'll want to move these and the printint ops to a separate devel.ops (or some such thing). That has to wait until we can deal with merging ops from multiple oplibs (which I started on, but have not been able to complete -- we are going to have to solve the dynamic loading problem satisfactorily before this can be taken very far). If there's no objection, I'll apply the patch here and play with it and probably commit it. Regards, -- Gregor On Tue, 2001-10-30 at 22:58, Jeff wrote: > 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); > < } -- _____________________________________________________________________ / perl -e 'srand(-2091643526); print chr rand 90 for (0..4)' \ Gregor N. Purdy [EMAIL PROTECTED] Focus Research, Inc. http://www.focusresearch.com/ 8080 Beckett Center Drive #203 513-860-3570 vox West Chester, OH 45069 513-860-3579 fax \_____________________________________________________________________/