Ejemplo n.º 1
0
static int
s_wsue_com (cilist64 *a, unit **fu)
{
    unit		  *ftnunit;
    int             n;

    n = wsue(a, fu);
    ftnunit = *fu;
    if (n) {
        errret(a->cierr, n, "s_wsue");
    }
    if (ftnunit->uacc == KEYED) {
        ftnunit->f77idxlist.cimatch = a->cimatch;
        ftnunit->f77idxlist.cikeytype = a->cikeytype;
        ftnunit->f77idxlist.cikeyval.cicharval = a->cikeyval.cicharval;
        ftnunit->f77idxlist.cikeyid = a->cikeyid;
        ftnunit->f77idxlist.cinml = a->cinml;
        ftnunit->f77idxlist.cikeyvallen = a->cikeyvallen;
        ftnunit->f77do_unf = do_ui;
    }
    else {
        if (ftnunit->uacc == DIRECT) {
            ftnunit->f77recpos = 0;
            ftnunit->f77do_unf = do_ud;
            _fio_seq_pos( ftnunit->ufd, ftnunit );
        } else {
            if (ftnunit->uwrt != WR_READY && f77nowwriting (ftnunit))
                errret(a->cierr, 160, "startwrt");
            est_reclen = ftnunit->f77reclen = 0;
            ftnunit->overflowed = 0;
            ftnunit->f77recpos = 4;
            ftnunit->f77do_unf = do_us;
            if (ftnunit->uerror)
                unf_position (ftnunit->ufd, ftnunit);
        }
    }
    return 0;
}
Ejemplo n.º 2
0
static int
s_rsue_com (cilist64 *a, unit **fu)
{
    int             n;
    unit           *ftnunit;
    int		f77reclen_32bit;

    if (!f77init)
        f_init ();

    n = c_sue (a, fu);
    ftnunit = *fu;
    if (n) {
        if (n > 0) {
            errret(a->cierr, n, "s_rsue");
        } else {
            errret(a->ciend, n, "s_rsue");
        }
    }

    ftnunit->f77recpos = ftnunit->f77reclen = 0;

#ifdef I90
    if (ftnunit->uaction == WRITEONLY )
        errret(ftnunit->f77errlist.cierr,180,"startread");
#endif

    /*
     * The direct unformatted case, yup, in the sequential unformatted
     * file.
     */

    if ((ftnunit->uacc == DIRECT) && (ftnunit->ufmt == 0)) {
        if (ftnunit->url != 1) {
            ftnunit->f77do_unf = do_ud;
            ftnunit->f77reclen = ftnunit->url;
        } else {
            /* For 'SYSTEM' file set a very large MAX_INT value for record
            length so it cannot be exceeded
            */
#if (_MIPS_SIM == _MIPS_SIM_ABI64)
            ftnunit->f77reclen = LONGLONG_MAX;
#else
            ftnunit->f77reclen = LONG_MAX;
#endif
            ftnunit->f77do_unf = do_ud;
        }
        _fio_seq_pos( ftnunit->ufd, ftnunit );
        ftnunit->uwrt &= ~WR_OP;
        return (0);
    } else {
        if (ftnunit->uwrt & WR_OP)
            (void) f77nowreading (ftnunit);
    }

    /* The normal case. */

    if (ftnunit->uacc == KEYED) {
        ftnunit->f77do_unf = do_ui;
        ftnunit->f77idxlist.cimatch = a->cimatch;
        ftnunit->f77idxlist.cikeytype = a->cikeytype;
        ftnunit->f77idxlist.cikeyval.cicharval = a->cikeyval.cicharval;
        ftnunit->f77idxlist.cikeyid = a->cikeyid;
        ftnunit->f77idxlist.cinml = a->cinml;
        ftnunit->f77idxlist.cikeyvallen = a->cikeyvallen;
        if (n = idxread(ftnunit)) {
            if (n > 0) {
                errret(a->cierr, n, "s_rsue");
            } else {
                errret(a->ciend, n, "s_rsue");
            }
        }
    } else if (ftnunit->url != 1) {
        ftnunit->f77do_unf = do_us;
        if (ftnunit->uerror)
            unf_position (ftnunit->ufd, ftnunit);
        if (fread ((char *) &f77reclen_32bit, sizeof (int), 1, ftnunit->ufd) != 1) {
            if (feof (ftnunit->ufd)) {
                ftnunit->uend = 1;
                errret(a->ciend, EOF, "start");
            }
            clearerr(ftnunit->ufd);
            errret(a->cierr, errno, "start");
        }
        ftnunit->f77reclen = f77reclen_32bit;
    } else {
        ftnunit->f77reclen = INT_MAX;
        ftnunit->f77do_unf = do_ud;
    }
    return (0);
}
Ejemplo n.º 3
0
static ftnint
__f77_f_back_com (alist *a, int lock) 

{
   unit           *ftnunit;
   int             n, i;
   ftnll            x, y;
   char            buf[512];

   if ((ftnunit = find_luno (a->aunit)) == NULL)
      err(a->aerr, 114, "backspace");
   while (lock && test_and_set( &ftnunit->lock_unit, 1L ))
       ;
   if (ftnunit->uacc == APPEND || ftnunit->uacc == KEYED)
      errret(a->aerr, 165, "backspace");
   if (ftnunit->useek == 0 || ftnunit->url == 1)
      errret(a->aerr, 106, "backspace");
   if (ftnunit->uend == 1) {
      ftnunit->uend = 0;
      ftnunit->lock_unit = 0;
      return (0);
   }
   if (ftnunit->uwrt & WR_OP) {
#ifdef I90
      /* If in Fortran-90 nonadvancing mode, write endfile record (\n only). */
      if (ftnunit->f90sw == 1 && ftnunit->f90nadv == 1 ) {
	  putc ('\n', ftnunit->ufd);
	  ftnunit->f90nadv = 0;
      }
#endif
      /* Just completed a write operation, a backspace would force
      the truncation of the file at the current position.
      */
      (void) t_runc (ftnunit, a->aerr);
      /* make sure it gets switched back to reading mode so the
      file won't get truncated again if it gets backspace/rewind again
      */
      if (f77nowreading(ftnunit))
	 errret(a->aerr, 106, "backspace");
   }
   /* Backspace a direct unformatted file. */

   if ((ftnunit->uacc == DIRECT) && (ftnunit->ufmt == 0)) {
      if (ftnunit->uirec != 0)
	 ftnunit->uirec--;
      ftnunit->lock_unit = 0;
      return (0);
   }
   if (ftnunit->ufmt != 1) {
      if (ftnunit->uerror)
	 unf_position (ftnunit->ufd, ftnunit);
      if (fseek (ftnunit->ufd, -(long) sizeof (int), 1)) {
	  fseek(ftnunit->ufd, 0L, 0);
          ftnunit->lock_unit = 0;
	  return(0);
      }
      /* NEED TO CHANGE HERE DLAI */
      (void) fread ((char *) &n, sizeof (int), 1, ftnunit->ufd);
      (void) fseek (ftnunit->ufd, (long) (-n - 2 * sizeof (int)), 1);
      ftnunit->lock_unit = 0;
      return (0);
   }

   y = x = FTELL (ftnunit->ufd) - 1;	/* skip the last CR */

   /* If already at the beginning of file, ignore the backspace */

   if (x < 0) {
      ftnunit->lock_unit = 0;
      return (0);
   }

#ifdef I90
   /* Make sure these variables are zeroed out to allow record to be reread. */
   ftnunit->f77recpos = 0;
   ftnunit->f77recend = 0;
#endif

   for (;;) {
      if (x < sizeof (buf))
	 x = 0;
      else
	 x -= sizeof (buf);
      (void) FSEEK (ftnunit->ufd, x, 0);
      /* n should be ll for 64 bit records */
      n = (int) fread (buf, 1, (int) (y - x), ftnunit->ufd);
      for (i = n - 1; i >= 0; i--) {
	 if (buf[i] != '\n')
	    continue;
	 (void) fseek (ftnunit->ufd, (long) (i + 1 - n), 1);
         ftnunit->lock_unit = 0;
	 return (0);
      }
      if (x == 0) {
	 (void) fseek (ftnunit->ufd, 0L, 0);
         ftnunit->lock_unit = 0;
	 return (0);
      } else if (n <= 0)
	 errret (a->aerr, (EOF), "backspace")
	    (void) FSEEK (ftnunit->ufd, x, 0);
      y = x;
   }
}