Exemple #1
0
void ax25_display_frame(Stream* out, FBUF *b)
{
    fbuf_reset(b);
    addr_t to, from;
    addr_t digis[7];
    uint8_t ctrl;
    uint8_t pid;
    uint8_t ndigis = ax25_decode_header(b, &from, &to, digis, &ctrl, &pid);
    ax25_display_addr(out, &from); 
    putstr_P(out, PSTR(">"));
    ax25_display_addr(out, &to);
    uint8_t i;
    for (i=0; i<ndigis; i++) {
       putstr_P(out, PSTR(","));
       ax25_display_addr(out, &digis[i]);
       if (digis[i].flags & FLAG_DIGI)
           putstr_P(out, PSTR("*"));
    }
    if (ctrl == FTYPE_UI)
    {
       putstr_P(out, PSTR(":"));    
       for (i=0; i < fbuf_length(b) - AX25_HDR_LEN(ndigis); i++) {
          register char c = fbuf_getChar(b); 
          if (c!='\n' && c!='\r' && c>=(char) 28)
              putch(out, c);
       }
    }

}
Exemple #2
0
int
PREFIX(fgetc) (const int * unit, char * c, gfc_charlen_type c_len)
{
  int ret;
  gfc_unit * u = find_unit (*unit);

  if (u == NULL)
    return -1;

  fbuf_reset (u);
  if (u->mode == WRITING)
    {
      sflush (u->s);
      u->mode = READING;
    }

  memset (c, ' ', c_len);
  ret = sread (u->s, c, 1);
  unlock_unit (u);

  if (ret < 0)
    return ret;

  if (ret != 1)
    return -1;
  else
    return 0;
}
void
st_rewind (st_parameter_filepos *fpp)
{
  gfc_unit *u;

  library_start (&fpp->common);

  u = find_unit (fpp->common.unit);
  if (u != NULL)
    {
      if (u->flags.access == ACCESS_DIRECT)
	generate_error (&fpp->common, LIBERROR_BAD_OPTION,
			"Cannot REWIND a file opened for DIRECT access");
      else
	{
	  /* If there are previously written bytes from a write with ADVANCE="no",
	     add a record marker before performing the ENDFILE.  */

	  if (u->previous_nonadvancing_write)
	    finish_last_advance_record (u);

	  u->previous_nonadvancing_write = 0;

	  fbuf_reset (u);

	  u->last_record = 0;

	  if (sseek (u->s, 0, SEEK_SET) < 0)
	    generate_error (&fpp->common, LIBERROR_OS, NULL);

	  /* Handle special files like /dev/null differently.  */
	  if (!is_special (u->s))
	    {
	      /* We are rewinding so we are not at the end.  */
	      u->endfile = NO_ENDFILE;
	    }
	  else
	    {
	      /* Set this for compatibilty with g77 for /dev/null.  */
	      if (file_length (u->s) == 0  && stell (u->s) == 0)
		u->endfile = AT_ENDFILE;
	      /* Future refinements on special files can go here.  */
	    }

	  u->current_record = 0;
	  u->strm_pos = 1;
	  u->read_bad = 0;
	}
      /* Update position for INQUIRE.  */
      u->flags.position = POSITION_REWIND;
      unlock_unit (u);
    }

  library_end ();
}
Exemple #4
0
void fbuf_rseek(FBUF* b, const uint8_t pos)
{
   register uint8_t i=pos;
   if (pos > b->length)
       return;
   fbuf_reset(b);
   while (i > _fbuf_length[b->rslot]) {
        i -= _fbuf_length[b->rslot];
        b->rslot = _fbuf_next[b->rslot];
   }
   b->rpos = i;
}
Exemple #5
0
static gfc_offset
gf_ftell (int unit)
{
  gfc_unit * u = find_unit (unit);
  if (u == NULL)
    return -1;
  int pos = fbuf_reset (u);
  if (pos != 0)
    sseek (u->s, pos, SEEK_CUR);
  gfc_offset ret = stell (u->s);
  unlock_unit (u);
  return ret;
}
Exemple #6
0
FBUF fbuf_newRef(FBUF* bb)
{
  FBUF newb;
  register uint8_t b = bb->head;
  while (b != NILPTR) 
  {
    _fbuf_refcnt[b]++; 
    b = _fbuf_next[b]; 
  } 
  newb.head = bb->head; 
  newb.length = bb->length; 
  fbuf_reset(&newb);
  newb.wslot = bb->wslot;
  return newb;
}
Exemple #7
0
int
PREFIX(fputc) (const int * unit, char * c,
	       gfc_charlen_type c_len __attribute__((unused)))
{
  ssize_t s;
  gfc_unit * u = find_unit (*unit);

  if (u == NULL)
    return -1;

  fbuf_reset (u);
  if (u->mode == READING)
    {
      sflush (u->s);
      u->mode = WRITING;
    }

  s = swrite (u->s, c, 1);
  unlock_unit (u);
  if (s < 0)
    return -1;
  return 0;
}
int
fbuf_flush (gfc_unit * u, int record_done)
{
  int status;
  size_t nbytes;

  if (!u->fbuf)
    return 0;
  if (u->fbuf->act - u->fbuf->flushed != 0)
    {
      if (record_done)
        nbytes = u->fbuf->act - u->fbuf->flushed;
      else	
        nbytes = u->fbuf->pos - u->fbuf->flushed;	
      status = swrite (u->s, u->fbuf->buf + u->fbuf->flushed, &nbytes);
      u->fbuf->flushed += nbytes;
    }
  else
    status = 0;
  if (record_done)
    fbuf_reset (u);
  return status;
}
void
st_backspace (st_parameter_filepos *fpp)
{
  gfc_unit *u;

  library_start (&fpp->common);

  u = find_unit (fpp->common.unit);
  if (u == NULL)
    {
      generate_error (&fpp->common, LIBERROR_BAD_UNIT, NULL);
      goto done;
    }

  /* Direct access is prohibited, and so is unformatted stream access.  */


  if (u->flags.access == ACCESS_DIRECT)
    {
      generate_error (&fpp->common, LIBERROR_OPTION_CONFLICT,
		      "Cannot BACKSPACE a file opened for DIRECT access");
      goto done;
    }

  if (u->flags.access == ACCESS_STREAM && u->flags.form == FORM_UNFORMATTED)
    {
      generate_error (&fpp->common, LIBERROR_OPTION_CONFLICT,
                      "Cannot BACKSPACE an unformatted stream file");
      goto done;
    }

  /* Make sure format buffer is flushed and reset.  */
  if (u->flags.form == FORM_FORMATTED)
    {
      int pos = fbuf_reset (u);
      if (pos != 0)
        sseek (u->s, pos, SEEK_CUR);
    }

  
  /* Check for special cases involving the ENDFILE record first.  */

  if (u->endfile == AFTER_ENDFILE)
    {
      u->endfile = AT_ENDFILE;
      u->flags.position = POSITION_APPEND;
      sflush (u->s);
    }
  else
    {
      if (stell (u->s) == 0)
	{
	  u->flags.position = POSITION_REWIND;
	  goto done;		/* Common special case */
	}

      if (u->mode == WRITING)
	{
	  /* If there are previously written bytes from a write with
	     ADVANCE="no", add a record marker before performing the
	     BACKSPACE.  */

	  if (u->previous_nonadvancing_write)
	    finish_last_advance_record (u);

	  u->previous_nonadvancing_write = 0;

	  unit_truncate (u, stell (u->s), &fpp->common);
	  u->mode = READING;
        }

      if (u->flags.form == FORM_FORMATTED)
	formatted_backspace (fpp, u);
      else
	unformatted_backspace (fpp, u);

      u->flags.position = POSITION_UNSPECIFIED;
      u->endfile = NO_ENDFILE;
      u->current_record = 0;
      u->bytes_left = 0;
    }

 done:
  if (u != NULL)
    unlock_unit (u);

  library_end ();
}