Ejemplo n.º 1
0
 /**
  * @returns The size of the input sequence. The value is equal to that
  * calculated for @c s in the following code:
  * @code
  * size_t s = 0;
  * const_buffers_type bufs = data();
  * const_buffers_type::const_iterator i = bufs.begin();
  * while (i != bufs.end())
  * {
  *   const_buffer buf(*i++);
  *   s += buffer_size(buf);
  * }
  * @endcode
  */
 std::size_t size() const
 {
   return pptr() - gptr();
 }
Ejemplo n.º 2
0
 /**
  * @returns An object of type @c const_buffers_type that satisfies
  * ConstBufferSequence requirements, representing all character arrays in the
  * input sequence.
  *
  * @note The returned object is invalidated by any @c basic_streambuf member
  * function that modifies the input sequence or output sequence.
  */
 const_buffers_type data() const
 {
   return asio::buffer(asio::const_buffer(gptr(),
         (pptr() - gptr()) * sizeof(char_type)));
 }
Ejemplo n.º 3
0
inttoktype yylex()
{
	register	ptrall	bufptr;	
	register	inttoktype		val;	
	register	struct	exp	*locxp;
	/*
	 *	No local variables to be allocated; this saves
	 *	one piddling instruction..
	 */
	static	int	Lastjxxx;

	bufptr = tokptr;		/*copy in the global value*/
   top:
	if (bufptr < tokub){
		gtoken(val, bufptr);
		switch(yylval = val){
		case	PARSEEOF:
				yylval = val = PARSEEOF;
				break;
		case	BFINT:
		case	INT:
				if (xp >= &explist[NEXP])
				     yyerror("Too many expressions; try simplyfing");
				else
				    locxp = xp++;
				locxp->e_number = Znumber;
				locxp->e_number.num_tag = TYPL;
				glong(locxp->e_xvalue, bufptr);
			  makevalue:
				locxp->e_xtype = XABS;
				locxp->e_xloc = 0;
				locxp->e_xname = NULL;
				yylval = (int)locxp;
				break;
		case	BIGNUM:	
				if (xp >= &explist[NEXP])
				     yyerror("Too many expressions; try simplyfing");
				else
				    locxp = xp++;
				gnumber(locxp->e_number, bufptr);
				goto makevalue;
		case	NAME:
				gptr(yylval, bufptr);
				lastnam = (struct symtab *)yylval;
				break;
		case	SIZESPEC:
		case 	REG:
				gchar(yylval, bufptr);
				break;
		case	INSTn:
		case	INST0:
				gopcode(yyopcode, bufptr);
				break;
		case	IJXXX:
				gopcode(yyopcode, bufptr);
				/* We can't cast Lastjxxx into (int *) here.. */
				gptr(Lastjxxx, bufptr);
				lastjxxx = (struct symtab *)Lastjxxx;
				break;
		case	ILINESKIP:
				gint(yylval, bufptr);
				lineno += yylval;
				goto top;
		case	SKIP:	
				eatskiplg(bufptr);
				goto top;
		case	VOID:	
				goto top;
		case 	STRING:
		case 	ISTAB:
		case	ISTABSTR:
		case	ISTABNONE:
		case	ISTABDOT:
		case	IALIGN:
				gptr(yylval, bufptr);
				break;
		} 
#ifdef DEBUG
		if (toktrace){
		char	*tok_to_name();
		printf("P: %d T#: %4d, %s ",
			passno, bufptr -  firsttoken, tok_to_name(val));
		switch(val){
		case 	INT:	printf("val %d",
					((struct exp *)yylval)->e_xvalue);
				break;
		case	BFINT:	printf("val %d",
					((struct exp *)yylval)->e_xvalue);
				break;
		case 	BIGNUM: bignumprint(((struct exp*)yylval)->e_number);
				break;
		case	NAME:	printf("\"%.8s\"",
					FETCHNAME((struct symtab *)yylval));
				break;
		case	REG:	printf(" r%d",
					yylval);
				break;
		case	IJXXX:
		case	INST0:	
		case	INSTn:	if (ITABCHECK(yyopcode))
					printf("%.8s",
						FETCHNAME(ITABFETCH(yyopcode)));
				else
					printf("IJXXX or INST0 or INSTn can't get into the itab\n");
				break;
		case	STRING:
			printf("length %d, seekoffset %d, place 0%o ",
				((struct strdesc *)yylval)->sd_strlen,
				((struct strdesc *)yylval)->sd_stroff,
				((struct strdesc *)yylval)->sd_place
				);
			if (((struct strdesc *)yylval)->sd_place & STR_CORE)
				printf("value\"%*s\"",
					((struct strdesc *)yylval)->sd_strlen,
					((struct strdesc *)yylval)->sd_string);
			break;
		}  		/*end of the debug switch*/
		printf("\n");
		}
#endif DEBUG

	} else {	/* start a new buffer */
	    if (useVM){
		if (passno == 2){
			tok_temp = emptybuf->tok_next;
			emptybuf->tok_next = tok_free;
			tok_free = emptybuf;
			emptybuf = tok_temp;
		} else {
			emptybuf = emptybuf->tok_next;
		}
		bufno += 1;
		if (emptybuf == 0){
			struct	tokbufdesc *newdallop;
			int	i;
			if (passno == 2)
				goto badread;
			emptybuf = newdallop = (struct tokbufdesc *)
			  Calloc(TOKDALLOP, sizeof (struct tokbufdesc));
			for (i=0; i < TOKDALLOP; i++){
				buftail->tok_next = newdallop;
				buftail = newdallop;
				newdallop += 1;
			}
			buftail->tok_next = 0;
		}	/*end of need to get more buffers*/
		(bytetoktype *)bufptr = &(emptybuf->toks[0]);
		if (passno == 1)
			scan_dot_s(emptybuf);
	    } else {	/*don't use VM*/
		bufno ^= 1;
		emptybuf = &tokbuf[bufno];
		((bytetoktype *)bufptr) = &(emptybuf->toks[0]);
		if (passno == 1){
			/*
			 *	First check if there are things to write
			 *	out at all
			 */
			if (emptybuf->tok_count >= 0){
			    if (writeTEST((char *)emptybuf, sizeof *emptybuf, 1, tokfile)){
				yyerror("Unexpected end of file writing the interpass tmp file");
				exit(2);
			    }
			}
			scan_dot_s(emptybuf);
		} else {	/*pass 2*/
		    if (readTEST((char *)emptybuf, sizeof *emptybuf, 1, tokfile)){
			 badread:
			     yyerror("Unexpected end of file while reading the interpass tmp file");
			     exit(1);
		    }
		}
	    }	/*end of using a real live file*/
	    (char *)tokub = (char *)bufptr + emptybuf->tok_count;
#ifdef DEBUG
	    firsttoken = bufptr;
	    if (debug)
		printf("created buffernumber %d with %d tokens\n",
			bufno, emptybuf->tok_count);
#endif DEBUG
	    goto top;
	}	/*end of reading/creating a new buffer*/
	tokptr = bufptr;		/*copy back the global value*/
	return(val);
}	/*end of yylex*/
Ejemplo n.º 4
0
 ::std::size_t size() const
 {
     return (pptr() - gptr());
 }
Ejemplo n.º 5
0
streamsize CConn_Streambuf::showmanyc(void)
{
    static const STimeout kZeroTmo = {0, 0};

    _ASSERT(gptr() >= egptr());

    if (!m_Conn)
        return -1L;

    // flush output buffer, if tied up to it
    if (m_Tie)
        x_sync();

    const STimeout* tmo;
    const STimeout* timeout = CONN_GetTimeout(m_Conn, eIO_Read);
    if (timeout == kDefaultTimeout) {
        // HACK * HACK * HACK
        tmo = ((SMetaConnector*) m_Conn)->default_timeout;
    } else
        tmo = timeout;

    size_t x_read;
    bool backup = false;
    if (m_BufSize > 1) {
        if (eback() < gptr()) {
            x_Buf = gptr()[-1];
            backup = true;
        }
        if (!tmo)
            _VERIFY(CONN_SetTimeout(m_Conn, eIO_Read, &kZeroTmo)==eIO_Success);
        m_Status = CONN_Read(m_Conn, m_ReadBuf + 1, m_BufSize - 1,
                             &x_read, eIO_ReadPlain);
        if (!tmo)
            _VERIFY(CONN_SetTimeout(m_Conn, eIO_Read, timeout)  ==eIO_Success);
        _ASSERT(x_read > 0  ||  m_Status != eIO_Success);
    } else {
        m_Status = CONN_Wait(m_Conn, eIO_Read, tmo ? tmo : &kZeroTmo);
        x_read = 0;
    }

    if (!x_read) {
        switch (m_Status) {
        case eIO_Success:
            _ASSERT(m_BufSize <= 1);
            return  1L;  // can read at least 1 byte
        case eIO_Timeout:
            if (!tmo  ||  !(tmo->sec | tmo->usec))
                break;
            /*FALLTHRU*/
        case eIO_Closed:
            return -1L;  // EOF
        default:
            break;
        }
        return       0;  // no data available immediately
    }

    m_ReadBuf[0] = x_Buf;
    _ASSERT(m_BufSize > 1);
    setg(m_ReadBuf + !backup, m_ReadBuf + 1, m_ReadBuf + 1 + x_read);
    x_GPos += x_read;
    return x_read;
}
			// gptr as unsigned pointer
			uint8_t const * uptr() const
			{
				return reinterpret_cast<uint8_t const *>(gptr());
			}
Ejemplo n.º 7
0
 int streambuf::sync() {
   __lock_it( __b_lock );
   return( (gptr() < egptr()) || (pptr() > pbase()) ? EOF : __NOT_EOF );
 }
Ejemplo n.º 8
0
strstreambuf::pos_type
strstreambuf::seekoff(off_type off,
                      ios_base::seekdir dir, ios_base::openmode mode) {
  bool do_get = false;
  bool do_put = false;

  if ((mode & (ios_base::in | ios_base::out)) ==
          (ios_base::in | ios_base::out) &&
      (dir == ios_base::beg || dir == ios_base::end))
    do_get = do_put = true;
  else if (mode & ios_base::in)
    do_get = true;
  else if (mode & ios_base::out)
    do_put = true;

  // !gptr() is here because, according to D.7.1 paragraph 4, the seekable
  // area is undefined if there is no get area.
  if ((!do_get && !do_put) || (do_put && !pptr()) || !gptr())
    return pos_type(off_type(-1));

  char* seeklow  = eback();
  char* seekhigh = epptr() ? epptr() : egptr();

  off_type newoff;
  switch(dir) {
  case ios_base::beg:
    newoff = 0;
    break;
  case ios_base::end:
    newoff = seekhigh - seeklow;
    break;
  case ios_base::cur:
    newoff = do_put ? pptr() - seeklow : gptr() - seeklow;
    break;
  default:
    return pos_type(off_type(-1));
  }

  off += newoff;
  if (off < 0 || off > seekhigh - seeklow)
    return pos_type(off_type(-1));

  if (do_put) {
    if (seeklow + __STATIC_CAST(ptrdiff_t, off) < pbase()) {
      setp(seeklow, epptr());
      pbump((int)off);
    }
    else {
      setp(pbase(), epptr());
      pbump((int)(off - (pbase() - seeklow)));
    }
  }
  if (do_get) {
    if (off <= egptr() - seeklow)
      setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), egptr());
    else if (off <= pptr() - seeklow)
      setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), pptr());
    else
      setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), epptr());
  }

  return pos_type(newoff);
}
Ejemplo n.º 9
0
std::streamsize Socket::showmanyc() {
	#ifdef WIN32
	unsigned long result = -1;
	if(ioctlsocket(handle, FIONREAD, &result)) {
	#else
	int result = -1;
	if(ioctl(handle, FIONREAD, &result)) {
	#endif
        disconnect();
		throw Exception(Exception::ERROR_IOCTL);
    }else
        return result;
}

std::streamsize Socket::advanceInputBuffer() {
    if(inputIntermediateSize == 0) //No input buffer
        return 0;

    std::streamsize inAvail;
    if(type == UDP_PEER)
        inAvail = 0;
    else{
        inAvail = egptr()-gptr();
        memmove(eback(), gptr(), inAvail);
    }

    try {
        inAvail += receive(eback()+inAvail, inputIntermediateSize-inAvail);
    } catch(Exception err) {

    }

    setg(eback(), eback(), eback()+inAvail);
    return inAvail;
}

std::streamsize Socket::receive(char_type* buffer, std::streamsize size) {
    size = std::min(size, showmanyc());
    if(size == 0) return 0;
    
    switch(type) {
        case UDP_PEER: {
            struct sockaddr_storage remoteAddr;
			#ifdef WIN32
			int addrSize = sizeof(remoteAddr);
			#else
			unsigned int addrSize = sizeof(remoteAddr);
			#endif
            int result = recvfrom(handle, (char*)buffer, size, 0, reinterpret_cast<struct sockaddr*>(&remoteAddr), &addrSize);
            
            if(result == -1) {
                portRemote = 0;
                hostRemote = "";
                throw Exception(Exception::ERROR_READ);
            }else
                readSockaddr(&remoteAddr, hostRemote, portRemote);
            
            return result;
        }
        case TCP_CLIENT:
        case TCP_SERVERS_CLIENT: {
            int result = recv(handle, (char*)buffer, size, 0);
            
            if(result == -1)
                throw Exception(Exception::ERROR_READ);
            
            return result;
        }
		default:
        case NONE:
        case TCP_SERVER:
            throw Exception(Exception::BAD_TYPE);
    }
}
Ejemplo n.º 10
0
std::streambuf::int_type icryptostreambuf::underflow()
{

  if (!ctx)
    {
      // closed crypto stream
      return traits_type::eof();
    }

  // return character pointed to by gptr()
  // without advancing it if charactes are available
  // if there are no charactes return EOF
  if (gptr() < egptr())
    {
      return traits_type::to_int_type(*gptr());
    }

  if (eback() == NULL) // NULL indicates 1st time
    {
      // TODO: put back buffer handling
      // basically done by moving
      // last few bytes to front of the buffer
      // so buffer is always putback+buffer
    }

  // read from underlying buffer,  we should loop until stream is
  // at an end or encrypt/decrypt returns at least some bytes,
  // but there is no need to worry about filling out buffer completely
  int out_len = 0;
  while (out_len == 0 && input.sgetc() != traits_type::eof())
    {
      int in_len = input.sgetn(in.data(), in.size());
      int outl = 0;

      if (1 != EVP_CipherUpdate(ctx,
				(uint8_t*)out.data()+out_len, &outl,
				(uint8_t*)in.data(), in_len) )
	{
	  EVP_CIPHER_CTX_free(ctx);
	  ctx = NULL;
	  return traits_type::eof();
	}
      out_len += outl;
    }

  // finalise if underlying streambuf is at an end
  if (input.sgetc() == traits_type::eof())
    {
      int outl = 0;
      EVP_CipherFinal_ex(ctx, (uint8_t*)out.data()+out_len, &outl);
      EVP_CIPHER_CTX_free(ctx);
      ctx = NULL;
      out_len += outl;
    }

  // zero out here means we don't have any
  // bytes even after possible finalize, must be
  // at an end of stream..
  if (out_len == 0)
    {
      return traits_type::eof();
    }

  // set buffer pointers
  char *start = out.data(); // TODO: + putback_size
  // eback, gptr, egptr
  setg(out.data(), start, start + out_len);

  return traits_type::to_int_type(*gptr());
}
Ejemplo n.º 11
0
ClientSocket::StreamBuf::int_type ClientSocket::StreamBuf::underflow()
{
    const size_t got = conn->read(inBuffer, sizeof(inBuffer));
    setg(inBuffer, inBuffer, inBuffer + got);
    return traits_type::to_int_type(*gptr());
}
Ejemplo n.º 12
0
streammarker::~streammarker()
{
    if (saving()) {
	// Unlink from sb's chain.
	register streammarker **ptr = &((backupbuf*)_sbuf)->_markers;
	for (; ; ptr = &(*ptr)->_next)
	    if (*ptr == NULL)
		break;
	    else if (*ptr == this) {
		*ptr = _next;
		return;
	    }
    }
#if 0
    if _sbuf has a backup area that is no longer needed, should we delete
    it now, or wait until underflow()?
#endif
}

#define BAD_DELTA EOF

int streammarker::delta(streammarker& other_mark)
{
    if (_sbuf != other_mark._sbuf)
	return BAD_DELTA;
    if (saving() && other_mark.saving())
	return _pos - other_mark._pos;
    else if (!saving() && !other_mark.saving())
	return _spos - other_mark._spos;
    else
	return BAD_DELTA;
}

int streammarker::delta()
{
    if (_sbuf == NULL)
	return BAD_DELTA;
    if (saving()) {
	int cur_pos;
	if (_sbuf->in_backup())
	    cur_pos = _sbuf->_gptr - _sbuf->_egptr;
	else
	    cur_pos = _sbuf->_gptr - _sbuf->_eback;
	return _pos - cur_pos;
    }
    else {
	if (_spos == EOF)
	    return BAD_DELTA;
	int cur_pos = _sbuf->seekoff(0, ios::cur);
	if (cur_pos == EOF)
	    return BAD_DELTA;
	return _pos - cur_pos;
    }
}

int streambuf::seekmark(streammarker& mark, int delta /* = 0 */)
{
    if (mark._sbuf != this)
	return EOF;
    if (!mark.saving()) {
	return seekpos(mark._spos, ios::in);
    }
    else if (mark._pos >= 0) {
	if (in_backup())
	    switch_to_main_get_area();
	_gptr = _eback + mark._pos;
    }
    else {
	if (!in_backup())
	    switch_to_backup_area();
	_gptr = _egptr + mark._pos;
    }
    return 0;
}

void streambuf::unsave_markers()
{
    register streammarker *mark =_markers;
    if (_markers) {
	streampos offset = seekoff(0, ios::cur, ios::in);
	if (offset != EOF) {
	    offset += eGptr() - Gbase();
	    for ( ; mark != NULL; mark = mark->_next)
		mark->set_streampos(mark->_pos + offset);
	}
	else {
	    for ( ; mark != NULL; mark = mark->_next)
		mark->set_streampos(EOF);
	}
	_markers = 0;
    }

    free_backup_area();
}

int backupbuf::pbackfail(int c)
{
    if (_gptr <= _eback) {
	// Need to handle a filebuf in write mode (switch to read mode).  FIXME!
	if (have_backup() && !in_backup()) {
	    switch_to_backup_area();
	}
	if (!have_backup()) {
	    // No backup buffer: allocate one.
	    // Use short buffer, if unused? (probably not)  FIXME 
	    int backup_size = 128;
	    _other_gbase = new char [backup_size];
	    _other_egptr = _other_gbase + backup_size;
	    _aux_limit = _other_egptr;
	    switch_to_backup_area();
	}
	else if (gptr() <= eback()) {
	    // Increase size of existing backup buffer.
	    size_t new_size;
	    size_t old_size = egptr() - eback();
	    new_size = 2 * old_size;
	    char* new_buf = new char [new_size];
	    memcpy(new_buf+(new_size-old_size), eback(), old_size);
	    delete [] eback();
	    setg(new_buf, new_buf+(new_size-old_size), new_buf+new_size);
	    _aux_limit = _gptr;
        }
    }
    _gptr--;
    if (c != EOF && *_gptr != c)
	*_gptr = c;
    return (unsigned char)*_gptr;
}

unsigned __adjust_column(unsigned start, const char *line, int count)
{
    register const char *ptr = line + count;
    while (ptr > line)
	if (*--ptr == '\n')
	    return line + count - ptr - 1;
    return start + count;
}

int ios::readable() { return !(rdbuf()->_flags & _S_NO_READS); }
int ios::writable() { return !(rdbuf()->_flags & _S_NO_WRITES); }
int ios::is_open() { return rdbuf()
			 && (rdbuf()->_flags & _S_NO_READS+_S_NO_WRITES)
			     != _S_NO_READS+_S_NO_WRITES; }

#if defined(linux)
#define IO_CLEANUP ;
#endif

#ifdef IO_CLEANUP
  IO_CLEANUP
#else
struct __io_defs {
    __io_defs() { }
    ~__io_defs() { streambuf::flush_all(); }
};   
__io_defs io_defs__;
Ejemplo n.º 13
0
int streambuf::sync()
{
    if (gptr() == egptr() && pptr() == pbase())
	return 0;
    return EOF;
}
Ejemplo n.º 14
0
 /**
  * Removes @c n characters from the beginning of the input sequence.
  *
  * @throws std::length_error If <tt>n > size()</tt>.
  */
 void consume(std::size_t n)
 {
   if (gptr() + n > pptr())
     n = pptr() - gptr();
   gbump(static_cast<int>(n));
 }
Ejemplo n.º 15
0
int stdiobuf::underflow() {
/*************************/
// Handle allocating a buffer, if required.
// Handle filling the get area of the streambuf.
// Read more stuff from the input device.
// Return the first character read.

    char *ptr;
    int   len;

    __lock_it( __b_lock );

    // Flush any output waiting in the buffer:
    if( out_waiting() > 0 ) {
        if( sync() == EOF ) {
            return( EOF );
        }
    }
    // discard put area
    setp( NULL, NULL );

    // Try to allocate a buffer:
    if( base() == NULL ) {
        if( allocate() == EOF ) {
            return( EOF );
        }
        if( base() == NULL ) {
            // unbuffered special case
            ptr = __unbuffered_get_area + DEFAULT_PUTBACK_SIZE;
            setg( __unbuffered_get_area, ptr, ptr );
            int ch;
            ch = fgetc( __file_pointer );
            if( ch == EOF ) {
                return( EOF );
            } else {
                *egptr() = (char)ch;
            }
            setg( eback(), gptr(), egptr() + 1 );
            return( *gptr() );
        } else {
            ptr = base() + DEFAULT_PUTBACK_SIZE;
            setg( base(), ptr, ptr );
        }
    } else if( gptr() >= egptr() ) {
        ptr = base() + DEFAULT_PUTBACK_SIZE;
        setg( base(), ptr, ptr );
    }

    len = (__huge_ptr_int)(ebuf() - egptr());
    if( len > 0 ) {
        len = 1;
        int ch;
        ch = fgetc( __file_pointer );
        if( ch == EOF ) {
            return( EOF );
        } else {
            *egptr() = (char)ch;
        }
    } else {
        len = 0;
    }
    setg( eback(), gptr(), egptr() + len );
    return( gptr() < egptr() ? *gptr() : EOF );
}
Ejemplo n.º 16
0
  int strstreambuf::doallocate() {

    char   *oldbuf;
    int     oldbufsize;
    char   *newbuf;
    int     newbufsize;
    size_t  base_offset, ptr_offset, end_offset;

    __lock_it( __b_lock );
    if( !__dynamic || __frozen ) {
        return( EOF );
    }
    oldbuf     = base();
    oldbufsize = blen();
    if( __allocation_size <= oldbufsize ) {
        newbufsize = oldbufsize + DEFAULT_MAINBUF_SIZE;
    } else {
        newbufsize = __allocation_size;
    }
    if( __alloc_fn == NULL ) {
        newbuf = new char [newbufsize];
    } else {
        newbuf = (char *) __alloc_fn( newbufsize );
    }
    if( newbuf == NULL ) {
        return( EOF );
    }
    setb( newbuf, newbuf + newbufsize, false );

    // Copy the get area. This can be done directly by copying bytes and
    // setting new pointers. The size of the get area does not change.
    if( eback() != NULL ) {
        base_offset = (__huge_ptr_int)(eback() - oldbuf);
        ptr_offset  = (__huge_ptr_int)(gptr()  - oldbuf);
        end_offset  = (__huge_ptr_int)(egptr() - oldbuf);
        ::memcpy( newbuf+base_offset, eback(), end_offset-base_offset );
        setg( newbuf+base_offset, newbuf+ptr_offset, newbuf+end_offset );
    }

    // Copy the put area. This can be done directly by copying bytes and
    // setting new pointers. Add the extra bytes allocated above to the
    // end of the put area.
    if( pbase() == NULL ) {
        setp( newbuf, newbuf + newbufsize );
    } else {
        base_offset = (__huge_ptr_int)(pbase() - oldbuf);
        ptr_offset  = (__huge_ptr_int)(pptr()  - oldbuf);
        end_offset  = (__huge_ptr_int)(epptr() - oldbuf);
        ::memcpy( newbuf+base_offset, pbase(), end_offset-base_offset );
        end_offset += newbufsize - oldbufsize;    // grow the put area
        setp( newbuf+base_offset, newbuf+end_offset );
        pbump( ptr_offset - base_offset );
    }

    // Free the old buffer.
    if( oldbuf != NULL ) {
        if( __free_fn == NULL ) {
            delete [] oldbuf;
        } else {
            __free_fn( oldbuf );
        }
    }
    return( __NOT_EOF );
  }
Ejemplo n.º 17
0
	memrdbuf::pos_type memrdbuf::ff_to(pos_type target)
	{
		while (pos_ + egptr() - eback() < target) if (underflow() == traits_type::eof()) return pos_ + egptr() - gptr();
		setg(eback(), eback() + target - pos_, egptr());
		return target;
	}
Ejemplo n.º 18
0
streamsize CConn_Streambuf::xsgetn(CT_CHAR_TYPE* buf, streamsize m)
{
    if (!m_Conn)
        return 0;

    // flush output buffer, if tied up to it
    if (m_Tie  &&  x_sync() != 0)
        return 0;

    if (m < 0)
        return 0;

    _ASSERT((Uint8) m < numeric_limits<size_t>::max());
    size_t n = (size_t) m;
    size_t n_read;

    if (n) {
        // first, read from the memory buffer
        n_read = (size_t)(egptr() - gptr());
        if (n_read > n)
            n_read = n;
        memcpy(buf, gptr(), n_read);
        gbump(int(n_read));
        n   -= n_read;
        if (!n)
            return (streamsize) n_read;
        buf += n_read;
    } else
        n_read = 0;

    do {
        // next, read from the connection
        size_t     x_toread = n  &&  n < m_BufSize ? m_BufSize : n;
        CT_CHAR_TYPE* x_buf =        n < m_BufSize ? m_ReadBuf : buf;
        size_t       x_read;

        m_Status = CONN_Read(m_Conn, x_buf, x_toread,
                             &x_read, eIO_ReadPlain);
        _ASSERT(x_read <= x_toread);
        if (!x_read) {
            _ASSERT(!x_toread  ||  m_Status != eIO_Success);
            if (m_Status != eIO_Success  &&  m_Status != eIO_Closed)
                ERR_POST_X(10, x_Message("xsgetn():  CONN_Read() failed"));
            break;
        }
        x_GPos += (CT_OFF_TYPE) x_read;
        // satisfy "usual backup condition", see standard: 27.5.2.4.3.13
        if (x_buf == m_ReadBuf) {
            size_t xx_read = x_read;
            if (x_read > n)
                x_read = n;
            memcpy(buf, m_ReadBuf, x_read);
            setg(m_ReadBuf, m_ReadBuf + x_read, m_ReadBuf + xx_read);
        } else {
            _ASSERT(x_read <= n);
            size_t xx_read = x_read > m_BufSize ? m_BufSize : x_read;
            memcpy(m_ReadBuf, buf + x_read - xx_read, xx_read);
            setg(m_ReadBuf, m_ReadBuf + xx_read, m_ReadBuf + xx_read);
        }
        n_read += x_read;
        if (m_Status != eIO_Success)
            break;
        buf    += x_read;
        n      -= x_read;
    } while (n);

    return (streamsize) n_read;
}
Ejemplo n.º 19
0
			uint64_t tellg() const
			{
				return streamreadpos - (egptr()-gptr());
			}
Ejemplo n.º 20
0
int
DataIStreamBuf::underflow()
{
	return (gptr() < egptr()) ? static_cast<unsigned char>(*gptr()) : EOF;	// need a static_cast so a -1 doesn't turn into an EOF
}
Ejemplo n.º 21
0
			uint64_t tellg() const
			{
				// std::cerr << "here." << std::endl;
				return streamreadpos - (egptr()-gptr());
			}
Ejemplo n.º 22
0
streampos filebuf::seekoff(streamoff offset, _seek_dir dir, int mode)
{
    streampos result, new_offset, delta;
    _G_ssize_t count;

    if (mode == 0) // Don't move any pointers.
	dir = ios::cur, offset = 0;

    // Flush unwritten characters.
    // (This may do an unneeded write if we seek within the buffer.
    // But to be able to switch to reading, we would need to set
    // egptr to ptr.  That can't be done in the current design,
    // which assumes file_ptr() is eGptr.  Anyway, since we probably
    // end up flushing when we close(), it doesn't make much difference.)
    if (pptr() > pbase() || put_mode())
	if (switch_to_get_mode()) return EOF;

    if (base() == NULL) {
	doallocbuf();
	setp(base(), base());
	setg(base(), base(), base());
    }
    switch (dir) {
      case ios::cur:
	if (_fb._offset < 0) {
	    _fb._offset = sys_seek(0, ios::cur);
	    if (_fb._offset < 0)
		return EOF;
	}
	// Make offset absolute, assuming current pointer is file_ptr().
	offset += _fb._offset;

	offset -= _egptr - _gptr;
	if (in_backup())
	    offset -= _other_egptr - _other_gbase;
	dir = ios::beg;
	break;
      case ios::beg:
	break;
      case ios::end:
	struct stat st;
	if (sys_stat(&st) == 0 && S_ISREG(st.st_mode)) {
	    offset += st.st_size;
	    dir = ios::beg;
	}
	else
	    goto dumb;
    }
    // At this point, dir==ios::beg.

    // If destination is within current buffer, optimize:
    if (_fb._offset >= 0 && _eback != NULL) {
	// Offset relative to start of main get area.
	fpos_t rel_offset = offset - _fb._offset
	    + (eGptr()-Gbase());
	if (rel_offset >= 0) {
	    if (in_backup())
		switch_to_main_get_area();
	    if (rel_offset <= _egptr - _eback) {
		setg(base(), base() + rel_offset, egptr());
		setp(base(), base());
		return offset;
	    }
	    // If we have streammarkers, seek forward by reading ahead.
	    if (have_markers()) {
		int to_skip = rel_offset - (_gptr - _eback);
		if (ignore(to_skip) != to_skip)
		    goto dumb;
		return offset;
	    }
	}
	if (rel_offset < 0 && rel_offset >= Bbase() - Bptr()) {
	    if (!in_backup())
		switch_to_backup_area();
	    gbump(_egptr + rel_offset - gptr());
	    return offset;
	}
    }

    unsave_markers();

    // Try to seek to a block boundary, to improve kernel page management.
    new_offset = offset & ~(ebuf() - base() - 1);
    delta = offset - new_offset;
    if (delta > ebuf() - base()) {
	new_offset = offset;
	delta = 0;
    }
    result = sys_seek(new_offset, ios::beg);
    if (result < 0)
	return EOF;
    if (delta == 0)
	count = 0;
    else {
	count = sys_read(base(), ebuf()-base());
	if (count < delta) {
	    // We weren't allowed to read, but try to seek the remainder.
	    offset = count == EOF ? delta : delta-count;
	    dir = ios::cur;
	    goto dumb;
	}
    }
    setg(base(), base()+delta, base()+count);
    setp(base(), base());
    _fb._offset = result + count;
    xflags(xflags() & ~ _S_EOF_SEEN);
    return offset;
  dumb:
    unsave_markers();
    result = sys_seek(offset, dir);
    if (result != EOF) {
	xflags(xflags() & ~_S_EOF_SEEN);
    }
    _fb._offset = result;
    setg(base(), base(), base());
    setp(base(), base());
    return result;
}
Ejemplo n.º 23
0
streampos rpcbuf::seekoff(streamoff offset, ios::seek_dir dir, int mode) {
#else
streampos rpcbuf::seekoff(streamoff offset, seek_dir dir, int mode) {
#endif
    if (!_opened || !gptr()) {
	return EOF;
    }

    if (offset != 0 || dir != ios::cur || mode != ios::in) {
	return EOF;
    }

    return (streampos)gptr();
}

// Refuse any attempt to set the buffers for storing incoming and
// outgoing RPC requests because we need the ability to dynamically
// expand the buffers' sizes.

streambuf* rpcbuf::setbuf(char*, int) {
    return nil;
}

// Dynamically allocate two separate buffers for storing incoming and
// outgoing RPC requests.  Allocating separate buffers for the get and
// put areas makes it easier to expand either area later if necessary.

int rpcbuf::doallocate() {
    const int RPCBUFSIZE = 2032;

    char* get = new char[RPCBUFSIZE];
    if (!get) {
	error("rpcbuf::doallocate: out of memory");
	return EOF;
    }
    setb(get, get + RPCBUFSIZE, true);
    setg(get, get, get);

    char* put = new char[RPCBUFSIZE];
    if (!put) {
	error("rpcbuf::doallocate: out of memory");
	return EOF;
    }
    setp(put, put + RPCBUFSIZE);
    setr(nil);

    return 0;
}

// Expand the get area to make room for a large incoming request.

boolean rpcbuf::expand_g(int newsize) {
    char* get = new char[newsize];
    if (!get) {
	return false;
    }

    int navail = in_avail();
    Memory::copy(gptr(), get, navail);
    delete eback();
    setb(get, get + newsize, true);
    setg(get, get, get + navail);

    return true;
}
Ejemplo n.º 24
0
toktype yylex()
{
	register	ptrall	bufptr;	
	register	toktype		val;	
	register	struct	exp	*locxp;

	bufptr = tokptr;		/*copy in the global value*/
   top:
	if (bufptr < tokub){
		gtoken(val, bufptr);
		switch(yylval = val){
			case	PARSEEOF :
					yylval = val = PARSEEOF;
					break;
			case	INT:
					locxp = xp++;
					glong(locxp->xvalue, bufptr);
				  makevalue:
					locxp->xtype = XABS;
					locxp->xloc = 0;
					locxp->xname = NULL;
					yylval = (int)locxp;
					break;
			case	FLTNUM:	/*case patched on 3-Jan-80*/
					locxp = xp++;
					gdouble(locxp->doubval.dvalue, bufptr);
					/*
					 *	We make sure that locxp->xvalue
					 *	is not in the range suitable for
					 *	a short literal.  The field
					 *	xvalue is only used for
					 *	integers, not doubles, but when
					 *	we test for short literals
					 *	in ascode.c, we look
					 *	at the field xvalue when
					 *	it encounters an in line
					 *	floating number. Ergo,
					 *	give it a bad value.
					 */
					locxp->xvalue = -1;
					goto makevalue;
			case	NAME:
					gptr(yylval, bufptr);
					lastnam = (struct symtab *)yylval;
					break;
			case	SIZESPEC:
			case 	REG:
			case	INSTn:
			case	INST0:
					gchar(yylval, bufptr);
					break;
			case	IJXXX:
					gchar(yylval, bufptr);
					gptr(lastjxxx, bufptr);
					break;
			case	ILINESKIP:
					gint(yylval, bufptr);
					lineno += yylval;
					goto top;
			case	SKIP:	
					eatskiplg(bufptr);
					goto top;
			case	VOID:	
					goto top;
			case 	STRING:
					strptr = &strbuf[strno ^= 1];
					strptr->str_lg = *((lgtype *)bufptr);
					movestr(&strptr->str[0],
						(char *)bufptr + sizeof(lgtype),
						strptr->str_lg);
					eatstrlg(bufptr);
					yylval = (int)strptr;
					break;
			case 	ISTAB:
			case	ISTABSTR:
			case	ISTABNONE:
			case	ISTABDOT:
			case	IALIGN:
					gptr(yylval, bufptr);
					break;
		} /*end of the switch*/

#ifdef DEBUG

		if (toktrace)
		switch(val){
			case 	INT:	printf("Class integer val %d\n",
						((struct exp *)yylval)->xvalue);
					break;
			case 	FLTNUM: printf("Class floating point num value %4.3f\n",
					((struct exp *)yylval) -> doubval.dvalue);
					break;
			case	NAME:	printf("Class name, \"%.8s\"\n",
						((struct symtab *)yylval)->name);
					break;
			case	REG:	printf("Class register, number %d\n",
						yylval);
					break;
			case	INSTn:	printf("Class INSTn, %.8s\n",
						itab[0xFF &yylval]->name);
					break;
			case	IJXXX:	printf("Class IJXXX, %.8s\n",
						itab[0xFF &yylval]->name);
					break;
			case	INST0:	printf("Class INST0, %.8s\n",
						itab[0xFF &yylval]->name);
					break;
			case	STRING:	printf("Class string, length %d\n",
						((struct strdesc *)yylval)->str_lg);
					break;
			default:	printf("Pass: %d Tok: %d Other class: %d, 0%o, '%c'\n",
						passno,
						bufptr -  firsttoken,
						val,val, val);
					break;
		}		/*end of the debug switch*/
#endif

	}	/*end of this buffer*/
	else {
		if (useVM){
			bufno += 1;
			emptybuf = emptybuf->tok_next;
			if (emptybuf == 0){
				struct	tokbufdesc *newdallop;
				int	i;
				if (passno == 2)
					goto badread;
				emptybuf = newdallop = 
				  (struct tokbufdesc *)sbrk(
					TOKDALLOP*sizeof (struct tokbufdesc));
				if (emptybuf == (struct tokbufdesc *)-1)
					goto badwrite;
				for (i=0; i < TOKDALLOP; i++){
					buftail->tok_next = newdallop;
					buftail = newdallop;
					newdallop += 1;
				}
				buftail->tok_next = 0;
			}	/*end of need to get more buffers*/
			(toktype *)bufptr = &(emptybuf->toks[0]);
			if (passno == 1)
				scan_dot_s(emptybuf);
		} else {	/*don't use VM*/
			bufno ^= 1;
			emptybuf = &tokbuf[bufno];
			((toktype *)bufptr) = &(emptybuf->toks[0]);
			if (passno == 1){
				/*
				 *	First check if there are things to write
				 *	out at all
				 */
				if (emptybuf->tok_count >= 0){
					if (fwrite(emptybuf, sizeof *emptybuf, 1, tmpfil) != 1){
					  badwrite:
						yyerror("Unexpected end of file writing the interpass tmp file");
						exit(2);
					}
				}
				scan_dot_s(emptybuf);
			} else {	/*pass 2*/
				if (fread(emptybuf, sizeof *emptybuf, 1, tmpfil) != 1){
				  badread:
					yyerror("Unexpected end of file while reading the interpass tmp file");
					exit(1);
				}
			}	/*end of pass2*/
		}	/*end of using a real live file*/
		(char *)tokub = (char *)bufptr + emptybuf->tok_count;
#ifdef DEBUG
		firsttoken = bufptr;
		if (debug)
			printf("created buffernumber %d with %d tokens\n",
				bufno, emptybuf->tok_count);
#endif
			goto top;
	}	/*end of reading/creating a new buffer*/
	tokptr = bufptr;		/*copy back the global value*/
	return(val);
}	/*end of yylex*/
Ejemplo n.º 25
0
void
ParameterInfoPrivateHoard::
fill_hoard(GLuint program,
           GLenum count_enum, GLenum length_enum,
           F fptr, G gptr)
{
  GLint count, largest_length;
  std::vector<char> pname;

  glGetProgramiv(program, count_enum, &count);

  if(count > 0)
    {
      m_values.resize(count);
      glGetProgramiv(program, length_enum, &largest_length);

      ++largest_length;
      pname.resize(largest_length, '\0');

      for(int i = 0; i != count; ++i)
        {
          GLsizei name_length, psize;
          GLenum ptype;
          int array_index;

          std::memset(&pname[0], 0, largest_length);

          fptr(program, i, largest_length,
               &name_length, &psize,
               &ptype, &pname[0]);

          m_values[i].m_type = ptype;
          m_values[i].m_count = psize;
          m_values[i].m_name = filter_name(pname.begin(),
                                           pname.begin() + name_length,
                                           array_index);
          if(array_index != 0)
            {
              /*
                crazy GL... it lists an element
                from an array as a unique location,
                chicken out and add it with the
                array index:
              */
              m_values[i].m_name = std::string(pname.begin(),
                                               pname.begin() + name_length);
            }

          m_values[i].m_index = i;
          m_values[i].m_location = gptr(program, &pname[0]);

        }

      /* sort m_values by name and then make our map
       */
      std::sort(m_values.begin(), m_values.end());
      for(unsigned int i = 0, endi = m_values.size(); i < endi; ++i)
        {
          m_map[m_values[i].m_name] = i;
        }
    }
}