/************************************************************************ * This program is Copyright (C) 1986 by Jonathan Payne. JOVE is * * provided to you without charge, and with no warranty. You may give * * away copies of JOVE, including sources, provided that this notice is * * included in all the files. * ************************************************************************/ #ifndef _IO_H_ #define _IO_H_ #ifndef TUNED # include "tune.h" #endif #ifdef Extern RCS_H(io, "$Id: io.h,v 14.32.0.7 1993/10/29 02:43:03 tom Exp tom $") #endif #ifndef Extern # define Extern extern #endif #if _STDARG_ # include #else # include #endif #if _I_SYS_STAT - -1 # include #else # if _I_STAT # include # endif #endif #if _I_FCNTL # include #endif /* Downward compatibility strikes again! */ #ifndef S_ISREG # ifndef S_IFMT #error "st_mode macros undefined--check !" # endif # define S_ISREG(m) (((m)&S_IFMT)==S_IFREG) # define S_ISDIR(m) (((m)&S_IFMT)==S_IFDIR) # define S_ISCHR(m) (((m)&S_IFMT)==S_IFCHR) # ifndef TINY /* Kludge...we don't use these if TINY anyway. */ # define S_ISBLK(m) (((m)&S_IFMT)==S_IFBLK) # ifdef S_IFIFO # define S_ISFIFO(m) (((m)&S_IFMT)==S_IFIFO) # endif # ifdef S_IFLNK # define S_ISLNK(m) (((m)&S_IFMT)==S_IFLNK) # endif # ifdef S_IFNAM # define S_ISNAM(m) (((m)&S_IFMT)==S_IFNAM) # endif # ifdef S_IFSOCK # define S_ISSOCK(m) (((m)&S_IFMT)==S_IFSOCK) # endif # endif /* TINY */ #endif #ifndef S_IREAD # define S_IREAD 0000400 #endif #ifndef S_IROTH # define S_IROTH (S_IREAD>>6) # define S_IRGRP (S_IREAD>>3) # define S_IRUSR (S_IREAD) #endif #ifndef S_IWRITE # define S_IWRITE 0000200 #endif #ifndef S_IWOTH # define S_IWOTH (S_IWRITE>>6) # define S_IWGRP (S_IWRITE>>3) # define S_IWUSR (S_IWRITE) #endif #ifndef S_IEXEC # define S_IEXEC 0000100 #endif #ifndef S_IXOTH # define S_IXOTH (S_IEXEC>>6) # define S_IXGRP (S_IEXEC>>3) # define S_IXUSR (S_IEXEC) #endif #ifndef S_IRWXU # define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) # define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP) # define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH) #endif #ifndef SEEK_SET # define SEEK_SET 0 # define SEEK_CUR 1 # define SEEK_END 2 #endif #ifndef R_OK # define R_OK 4 # define W_OK 2 # define X_OK 1 # define F_OK 0 #endif #ifndef O_RDONLY # define O_RDONLY 0 # define O_WRONLY 1 # define O_RDWR 2 #endif /* This amusing bullshit comes AFTER so that when they are wrong at least these won't screw up. i.e., for prototyping only. Assume POSIX compliant compilers do it right all along. */ #if !__POSIX__ # ifndef TINY /* Kludge...see above. */ # ifndef _UID_T # ifndef __UID_T # ifndef uid_t # define uid_t int # endif # endif # endif # ifndef _PID_T # ifndef __PID_T # ifndef pid_t # define pid_t int # endif # endif # endif # ifndef _MODE_T # ifndef __MODE_T # ifndef mode_t # define mode_t unsigned # endif # endif # endif # ifndef _OFF_T # ifndef __OFF_T # ifndef off_t # define off_t long # endif # endif # endif # endif /* TINY */ #endif /* __POSIX__ */ #ifndef TINY /* !Kludge!... */ #ifndef S_ISLNK /* has symbolic links? */ # define lstat stat #endif #endif #ifdef DOS # define FIX_FILENAME(f) strlwr(f) #endif #if vms # define FIX_FILENAME(f) strlwr(f) #endif #ifndef FIX_FILENAME # define FIX_FILENAME(f) /* dummy */ #endif #ifndef NOT_JOVE #ifdef DOS /* accept as line separator. */ # define CRLF #endif #ifndef NO_TRIV_PROTO extern void putch __(( int _(c) )); /* hidden by the macro below */ #endif #define putch(c) putc(c,stdout) #define putc(c, fp) (--(fp)->f_cnt>=0?(*(fp)->f_ptr++=(c)):_flush((c),fp)) #define getc(fp) (((--(fp)->f_cnt<0)?filbuf(fp):*(fp)->f_ptr++)) #define f_rewind(fp) f_seekblk(fp,0) #define f_eof(fp) ((fp)->f_flags&F_EOF) typedef struct { int f_cnt, /* number of characters left in buffer */ f_bufsize, /* size of what f_base points to */ f_fd, /* fildes */ f_flags; /* various flags */ char *f_ptr, /* current offset */ *f_base; /* pointer to base */ char *f_name; /* name of open file */ } File; #define F_READ 01 #define F_WRITE 02 #define F_APPEND 04 #define F_MODE(x) ((x)&07) #define F_EOF 010 #define F_STRING 020 #define F_ERR 040 #define F_LOCKED 0100 /* don't close this file upon error */ #define F_MYBUF 0200 /* f_alloc allocated the buffer, so f_close knows to free it up */ #if (!unix && !vms || 2*CRLF-1!=2*0-1) # define F_BINARY 0400 /* for non- systems */ #else # define F_BINARY 0 #endif #if (unix || vms) /* These don't distinguish binary and text. */ # define F_TEXT F_BINARY #else /* Others do. */ # define F_TEXT 0 #endif #ifdef CRLF # define F_PEND_CR 01000 /* pending (for systems) */ #endif /* the next ones are used only by {open,read,write,close}_file I/O level */ #define F_COMPLAIN 010000 /* complain on error */ #define F_QUIET 020000 /* be quiet */ #define F_SAVE 040000 /* handle some common file-saving chores. */ #define F_READONLY 0100000 /* status, set by open_file */ Extern long io_chars; /* number of chars in this open_file */ Extern int io_lines; /* number of lines in this open_file */ /* function prototypes */ /* fp.c */ extern File *stdout, *fd_open __(( const char *_(fname), int _(flags), int _(fd), char *_(buffer), int _(buf_size) )), *f_open __(( const char *_(fname), int _(flags), char *_(buffer), int _(buf_size) )); extern void flush __(( File *_(fp) )); #ifndef NO_TRIV_PROTO extern int _flush __(( int _(c), File *_(fp) )); extern void f_close __(( File *_(fp) )), gc_openfiles __(( void )), putstr __(( const char *_(s) )), fputnchar __(( const void_* _(buf), int _(n), File *_(fp) )), flusho __(( void )), f_seekblk __(( File *_(fp), int _(bno) )), f_bsearch __(( File *_(fp), const char *_(searchstr), int _(prefix_len), int _(max_len) )); extern int filbuf __(( File *_(fp) )), fgetnchar __(( void_* _(buf), int _(n), File *_(fp) )), f_gets __(( File *_(fp), char *_(buf), int _(size) )), re_fsearch __(( File *_(fp), const char *_(pattern) )); #endif /* NO_TRIV_PROTO */ /* fmt.c */ extern int fprintf __(( File *_(fp), const char *_(fmt), ... )); #ifndef NO_TRIV_PROTO extern int format __(( char *_(buf), int _(len), const char *_(fmt), va_list _(ap) )); #endif /* others of the `printf' and `_mess' family are declared in jove.h */ /* io.c */ extern File *open_file __(( const char *_(fname), char *_(buf), int _(how) )); #ifndef NO_TRIV_PROTO extern void close_file __(( File *_(file) )), putreg __(( File *_(fp), Line *_(line1), int _(char1), Line *_(line2), int _(char2), int _(makesure) )), chk_file __(( const char *_(filename), const char *_(how) )), read_file __(( const char *_(file), int _(is_insert) )), write_file __(( const char *_(fname), int _(app) )), visit_file __(( const char *_(file), int _(toline) )), SaveFile __(( void )), WriteFile __(( void )), d_cache_init __(( void )), tmpclose __(( void )), SyncTmp __(( void )), UndoReset __(( void )); extern int UndoLine __(( void )); #endif /* NO_TRIV_PROTO */ /* dirs.c */ #define rel_name /* i.e., rel_name(fname) => (fname) */ #ifdef CHDIR extern char *pwd __(( void )), *PathParse __(( const char *_(name), char *_(intobuf) )), *dfollow __(( const char *_(file), char *_(into) )), # ifndef TINY # if unix || vms # undef rel_name *rel_name __(( const char *_(fname) )), # endif # endif # ifdef GETWD *getwd __(( char *_(buf) )); # else # ifdef GETCWD *getcwd __(( char *_(buf), size_t _(size) )); # define getwd(buf) getcwd(buf, FILESIZE) # else # if !unix #error "get_proc_line() is not supported on this system!" #error "(use either GETWD or GETCWD instead)" # else *get_proc_line __((const char *_(process) )); # define GET_PROC_LINE # define getwd(buf) get_proc_line("/bin/pwd") # endif # endif # endif /* !GETWD */ # define samefile(file1, file2) (strcmp(file1, file2) == 0) /* since we use absolute pathnames if CHDIR */ # ifndef NO_TRIV_PROTO extern void setCWD __(( const char *_(cwd) )); # ifdef CHDIR_EXT extern void dirs_init __(( void )); # endif # else # define cmp_ino(file1, file2) NO # endif #else /* !CHDIR */ # define pwd() "." # define samefile cmp_ino #endif /* CHDIR */ #ifndef cmp_ino extern int cmp_ino __(( const char *_(file1), const char *_(file2) )); #endif /* some others are declared in jove.h */ #if unix # define read_one_char(cp) read(0, (cp), 1) #endif #ifdef DOS # define read_one_char(cp) (*(cp) = getchar()) #endif #ifdef MAC # define read_one_char(cp) (*(cp) = getchar()) #endif #ifndef read_one_char extern void read_one_char __(( char *_(cp) )); #endif /* util.c */ #ifndef NO_TRIV_PROTO extern int zstat __(( const char *_(file), struct stat *_(stbuf) )); #endif #endif /* NOT_JOVE */ /* unix/Posix io */ extern time_t time __(( time_t *_(time) )); extern ssize_t read __(( int _(fd), void *_(buf), size_t _(size) )), write __(( int _(fd), const void *_(buf), size_t _(size) )); extern off_t lseek __(( int _(fd), off_t _(offset), int _(mode) )); #ifndef NO_TRIV_PROTO extern int open __(( const char *_(filename), int _(mode), ... )), #if (__TURBOC__ && __TOS__) /* How braindead can you get!-) */ creat __(( const char *_(filename), ... )), #else creat __(( const char *_(filename), mode_t _(mode) )), #endif close __(( int _(fd) )), access __(( const char *_(filename), int _(mode) )), unlink __(( const char *_(filename) )), rename __(( const char *_(from), const char *_(to) )), # ifdef CHDIR chdir __(( const char *_(newdir) )), # endif isatty __(( int _(fd) )); # ifndef getuid extern uid_t getuid __(( void )); # endif extern pid_t getpid __(( void )); #endif /* NO_TRIV_PROTO */ #endif /* _IO_H_ */ #undef Extern /*====================================================================== * $Log: io.h,v $ * Revision 14.32.0.7 1993/10/29 02:43:03 tom * FIX_FILENAME(): move outside NOT_JOVE conditional. * * Revision 14.32.0.6 1993/10/28 00:54:50 tom * add (system-dependent) definitions of FIX_FILENAME(). * * Revision 14.32.0.1 1993/07/07 12:12:57 tom * (F_TEXT): new option for f_open et al. * * Revision 14.32 1993/06/09 01:02:20 tom * (F_IGN_0): remove definition. * * Revision 14.31.0.2 1993/03/25 21:30:48 tom * allow compile-time CRLF option on non-DOS systems. * * Revision 14.31 1993/02/16 16:24:18 tom * replace TINY with NO_TRIV_PROTO for clarity of intent; simplify handling * of get_proc_line(). * * Revision 14.30 1993/02/06 00:48:33 tom * cleanup whitespace; add F_SAVE flag for open_file; * update function prototypes. * * Revision 14.28 1992/10/24 01:24:19 tom * convert to "port{ansi,defs}.h" conventions. * * Revision 14.26 1992/08/26 23:56:45 tom * #include if not yet included; some more Posix-ation; * add RCS directives. * */