void filein_access(t_filein *x, t_symbol *s, short ac, t_atom *av) { OSErr err; Byte data[8]; long count; unsigned long dummy; if (s==ps_int) count = 1; else if (s==ps_in1) count = 2; else count = 4; err = sysfile_setpos(x->f_fh,SYSFILE_FROMSTART,av->a_w.w_long); if (err) object_error((t_object *)x, "seek err %d",err); else { err = sysfile_read(x->f_fh,&count,data); if (err) object_error((t_object *)x, "read err %d",err); else { if (count==1) dummy = data[0]; else sysmem_copyptr(data,&dummy,count); outlet_int(x->f_out,dummy); } } }
int fseek(FILE *f, long nbytes, int mode) { if (mode != SEEK_CUR) { ouchstring("Unimplemented fseek mode!"); } else { return sysfile_setpos(f, SYSFILE_FROMMARK, nbytes); } }
void filein_in2(t_filein *x, long n) /* long access */ { t_atom info; unsigned long data[4]; long count; OSErr err; if (x->f_open) { if (isr()) { atom_setlong(&info,n); defer(x,(method)filein_access,ps_in2,1,&info); } else { err = sysfile_setpos(x->f_fh,SYSFILE_FROMSTART,n); if (err) object_error((t_object *)x, "seek err %d",err); else { count = 4; err = sysfile_read(x->f_fh,&count,data); if (err) object_error((t_object *)x, "read err %d",err); else { count = data[0]; outlet_int(x->f_out,count); } } } } else if (x->f_data) { if (n < 0) object_error((t_object *)x, "access out of range"); else if (n >= x->f_size) outlet_bang(x->f_eof); else { sysmem_copyptr(*(x->f_data)+n,data,4L); outlet_int(x->f_out,data[0]); } } }
void filein_int(t_filein *x, long n) /* byte access */ { t_atom info; Byte data[16]; long count; OSErr err; if (x->f_open) { if (isr()) { atom_setlong(&info,n); defer(x,(method)filein_access,ps_int,1,&info); } else { err = sysfile_setpos(x->f_fh,SYSFILE_FROMSTART,n); if (err) object_error((t_object *)x, "seek err %d",err); else { count = 1; err = sysfile_read(x->f_fh,&count,data); if (err) object_error((t_object *)x, "read err %d",err); else { count = data[0]; outlet_int(x->f_out,count); } } } } else if (x->f_data) { if (n < 0) object_error((t_object *)x, "access out of range"); else if (n >= x->f_size) outlet_bang(x->f_eof); else { count = *((*(x->f_data))+n); outlet_int(x->f_out,count); } } }