home *** CD-ROM | disk | FTP | other *** search
- #include "blu.h"
- #include <stdio.h>
- #include <ctype.h>
- #include "util.h"
- #include "os_dep.h"
-
- #define IO_ERR 000400000
-
- #define READ 001
- #define WRITE 002
- #define BIN_READ 003
- #define BIN_WRITE 004
- #define CLOSE 014
- #define WRITEEOF 012
- #define WRITE_EOF 012
- #define OPEN 013
- #define SETCRA 023
- #define DUMP_BUFFER 024
- #define FLUSH 037
- /*
- *
- * os_dep_file_pos -- Return current position in file
- *
- * This routine returns the current position in the file. The value
- * returned is suitable for passing to os_dep_file_seek and is suitable
- * for no other purpose.
- *
- * Return value:
- * Current position in the file.
- *
- */
-
- rfa_type os_dep_file_pos (fp)
- FILE * fp;
- {
-
- return (fp -> cra);
- }
-
- /*
- *
- * os_dep_file_read -- Read a record from a file.
- *
- * This routine reads a record from a file.
- *
- * Return value:
- * SS_NORMAL Operation performed as requested.
- * SS_EOT End of disk area reached
- * SS_READ_ERR Error on read operation.
- * SS_SEEK_ERR Seek error occured
- *
- */
-
- STS_type os_dep_file_read (fp,
- buf_ptr,
- buf_len,
- ret_len_ptr)
- FILE * fp;
- char *buf_ptr;
- int buf_len;
-
- int *ret_len_ptr; /* output */
- /* Returns the number of bytes read. */
- /* A value of -1 indicates that an EOF record was read */
-
- {
-
- STS_type status;
-
- int i;
-
- fortran int LOWREAD ();
-
-
-
- if (!fp -> symbolic) {
- status = $IOW (LFN (fp), BIN_READ, (buf_len + 2) / 3, buf_ptr);
- fp -> cra = C_Ereg ();
- if (status & IO_ERR) {
- return (SS_READ_ERR);
- }
- } else {
-
- i = (buf_len + 2) / 3;
- status = LOWREAD (&(LFN (fp)), (int *) buf_ptr, &i);
-
- if (status <= -2) {
- if (status == -2) {
- return (SS_EOT);
- } else {
- return (SS_READ_ERR);
- }
- }
-
- *ret_len_ptr = status;
- ++(fp -> cra);
-
- }
-
- return (SS_NORMAL);
-
- }
-
- /*
- *
- * os_dep_file_seek -- Seek to record within file
- *
- * This routine seek to a particular record within a file.
- *
- * Return value:
- * SS_NORMAL Operation performed as requested.
- * SS_SEEK_ERR Error on seek operation.
- *
- */
-
- STS_type os_dep_file_seek (fp, rec_num)
- FILE * fp;
- rfa_type rec_num;
-
- {
-
- STS_type status;
-
-
-
- if (rec_num >= 0 && fp -> cra != rec_num) {
- status = $IOW (LFN (fp), SETCRA, rec_num, 0);
- fp -> cra = C_Ereg ();
- if (status & IO_ERR) {
- return (SS_SEEK_ERR);
- }
- }
- return (SS_NORMAL);
-
- }
-
- /*
- *
- * os_dep_file_write -- Write a record to a file.
- *
- * This routine writes a record to a file.
- *
- * Return value:
- * SS_NORMAL Operation performed as requested.
- * SS_WRITE_ERR Error on write operation.
- *
- */
-
- STS_type os_dep_file_write (fp,
- buf_ptr,
- buf_len)
- FILE * fp;
- char *buf_ptr;
- int buf_len; /* buffer length in bytes */
-
- {
-
- STS_type status;
-
-
-
- if (buf_len <= 0) {
- if (buf_len < 0) {
- return (os_dep_file_write_eof (fp));
- }
- buf_len = 1;
- }
-
- if (!fp -> symbolic) {
- status = $IOW (LFN (fp), BIN_WRITE, (buf_len + 2) / 3, buf_ptr);
- } else {
-
- buf_ptr[buf_len] = ' ';
- buf_ptr[buf_len + 1] = ' ';
- status = $IOW (LFN (fp), 02, (buf_len + 2) / 3, buf_ptr);
-
- }
-
- fp -> cra = C_Ereg ();
-
- if (status & IO_ERR) {
- return (SS_WRITE_ERR);
- }
-
- return (SS_NORMAL);
-
- }
-