Esempio n. 1
0
streambuf *filebuf::setbuf( char *buf, int len ) {
/************************************************/
// Set up the filebuf using the specified buffer.
// The buffer can be used if:
//   (1) the filebuf is not attached to a file (may or may not have a buffer
//       already),
//   (2) the file is attached to a file and does not have a buffer.
// If the buffer is too small (<= DEFAULT_PUTBACK_SIZE), then it cannot be
// used.

    __lock_it( __b_lock );
    if( (fd() != EOF) && (base() != NULL) ) {
        return( NULL );
    }
    if( (buf == NULL) || (len <= 0) ) {
        setb( NULL, NULL, FALSE );
    } else {
        if( len <= DEFAULT_PUTBACK_SIZE ) {
            setb( NULL, NULL, FALSE );
            return( NULL );
        }
        setb( buf, buf + len, FALSE );
    }
    return( this );
}
Esempio n. 2
0
static int usb_ep0tx_data(const void *data, const unsigned int len)
{
	unsigned int offset = 0, block, last_block = 0;
	uint32_t value;

	BUG_ON(len > AR9170_USB_EP_CTRL_MAX);
	BUILD_BUG_ON(len > AR9170_USB_EP_CTRL_MAX);

	block = min(len, (unsigned int) 4);
	offset = 0;
	while (offset < len) {

		if (last_block != block || block < 4)
			setb(AR9170_USB_REG_FIFO_SIZE, (1 << block) - 1);

		memcpy(&value, GET_ARRAY(data, offset), block);

		set(AR9170_USB_REG_EP0_DATA, value);

		offset += block;
		last_block = block = min(len - offset, (unsigned int) 4);
	}

	setb(AR9170_USB_REG_FIFO_SIZE, 0xf);

	/* this will push the data to the host */
	return 1;
}
Esempio n. 3
0
void
freejobs()
{
	struct job *jp;

	collectjobs(WNOHANG);

	if (jobnote) {
		int savefd = setb(2);
		for (jp = joblst; jp; jp = jp->j_nxtp) {
			if (jp->j_flag & J_NOTIFY) {
				if (jp->j_jid)
					printjob(jp, PR_DFL);
				else if (jp->j_flag & J_FOREGND)
					printjob(jp, PR_STAT);
				else
					printjob(jp, PR_STAT|PR_PGID);
			}
		}
		(void) setb(savefd);
	}

	if (jobdone) {
		for (jp = joblst; jp; jp = jp->j_nxtp) {
			if (jp->j_flag & J_DONE)
				freejob(jp);
		}
	}
}
Esempio n. 4
0
// Inicjalizacja przycisków
void switch_init() {
  // przycisk 1
  clr(SWITCH1_DDR, SWITCH1_PIN);
  setb(SWITCH1_PORT, SWITCH1_PIN);
  // przycisk 2
  clr(SWITCH2_DDR, SWITCH2_PIN);
  setb(SWITCH2_PORT, SWITCH2_PIN);
}
Esempio n. 5
0
streambuf* streambuf::setbuf(char* p, int len)
{
    if (sync() == EOF)
	return NULL;
    if (p == NULL || len == 0) {
	unbuffered(1);
	setb(_shortbuf, _shortbuf+1, 0);
    }
    else {
	unbuffered(0);
	setb(p, p+len, 0);
    }
    setp(0, 0);
    setg(0, 0, 0);
    return this;
}
Esempio n. 6
0
int general_parsebuf::underflow()
{
    register char *ptr = base();
    int has_newline = eback() < gptr() && gptr()[-1] == '\n';
    if (has_newline)
	*ptr++ = '\n';
    register streambuf *sb = sbuf;
    register int ch;
    for (;;) {
	ch = sb->sbumpc();
	if (ch == EOF)
	    break;
	if (ptr == ebuf()) {
	    int old_size = ebuf() - base();
	    char *new_buffer = new char[old_size * 2];
	    memcpy(new_buffer, base(), old_size);
	    setb(new_buffer, new_buffer + 2 * old_size, 1);
	    ptr = new_buffer + old_size;
	}
	*ptr++ = ch;
	if (ch == '\n')
	    break;
    }
    char *cur_pos = base() + has_newline;
    pos_at_line_start += _line_length + 1;
    _line_length = ptr - cur_pos;
    if (ch != EOF || _line_length > 0)
	__line_number++;
    setg(base(), cur_pos, ptr);
    return ptr == cur_pos ? EOF : cur_pos[0];
}
Esempio n. 7
0
filebuf* filebuf::close()
{
    if (!is_open())
	return NULL;

    // This flushes as well as switching mode.
    if (pptr() > pbase() || put_mode())
	if (switch_to_get_mode()) return NULL;

    unsave_markers();

    int status = sys_close();

    // Free buffer.
    setb(NULL, NULL, 0);
    setg(NULL, NULL, NULL);
    setp(NULL, NULL);

    _un_link();
    _flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
    _fb._fileno = EOF;
    _fb._offset = 0;

    return status < 0 ? NULL : this;
}
strstreambuf::strstreambuf(char * ptr, int size, char * pstart)
: streambuf()
{
    x_static = 1;
    x_dynamic = 0;
    char * pend;

    if (!size)
        pend = ptr + strlen(ptr);
    else if (size < 0)
        {
        pend = (char*)-1L;
        }
    else
        pend = ptr + size;

    setb(ptr, pend,0);
    if (pstart)
        {
        setg(ptr,ptr,pstart);
        setp(pstart, pend);
        }
    else
        {
        setg(ptr,ptr,pend);
        setp(0, 0);
        }
}
Esempio n. 9
0
int streambuf::doallocate()
{
    char *buf = ALLOC_BUF(_G_BUFSIZ);
    if (buf == NULL)
	return EOF;
    setb(buf, buf+_G_BUFSIZ, 1);
    return 1;
}
Esempio n. 10
0
  streambuf *streambuf::setbuf( char *buf, int len ) {

    __lock_it( __b_lock );
    if( base() != NULL ) {
        return( NULL );
    }
    if( (buf == NULL) || (len <= 0) ) {
        setb( NULL, NULL, FALSE );
    } else {
        if( len <= DEFAULT_PUTBACK_SIZE ) {
            setb( NULL, NULL, FALSE );
            return( NULL );
        }
        setb( buf, buf + len, FALSE );
    }
    return( this );
  }
Esempio n. 11
0
  streambuf *filebuf::setbuf( char *buf, int len ) {

    __lock_it( __b_lock );
    if( (fd() != EOF) && (base() != NULL) ) {
        return( NULL );
    }
    if( (buf == NULL) || (len <= 0) ) {
        setb( NULL, NULL, false );
    } else {
        if( len <= DEFAULT_PUTBACK_SIZE ) {
            setb( NULL, NULL, false );
            return( NULL );
        }
        setb( buf, buf + len, false );
    }
    return( this );
  }
Esempio n. 12
0
string_parsebuf::string_parsebuf(char *buf, int len,
				 int delete_at_close /* = 0*/)
: parsebuf()
{
    setb(buf, buf+len, delete_at_close);
    register char *ptr = buf;
    while (ptr < ebuf() && *ptr != '\n') ptr++;
    _line_length = ptr - buf;
    setg(buf, buf, ptr);
}
Esempio n. 13
0
func_parsebuf::func_parsebuf(CharReader func, void *argm) : parsebuf()
{
    read_func = func;
    arg = argm;
    buf_start = NULL;
    buf_end = NULL;
    setb((char*)NewLine, (char*)NewLine+1, 0);
    setg((char*)NewLine, (char*)NewLine+1, (char*)NewLine+1);
    backed_up_to_newline = 0;
}
Esempio n. 14
0
general_parsebuf::general_parsebuf(streambuf *buf, int delete_arg_buf)
 : parsebuf()
{
    delete_buf = delete_arg_buf;
    sbuf = buf;
    int buf_size = 128;
    char* buffer = ALLOC_BUF(buf_size);
    setb(buffer, buffer+buf_size, 1);
//    setg(buffer, buffer, buffer);
}
Esempio n. 15
0
void ocircleXZ(int x, int y, int z, int radius, block_t id)
{
	int maxrad = radius*radius;
	for (int dx = -radius; dx <= radius; dx++)
	for (int dz = -radius; dz <= radius; dz++)
	{
		if (dx*dx + dz*dz <= maxrad)
			setb(x+dx, y, z+dz, id);
	}
}
Esempio n. 16
0
void oellipsoidXY(int x, int y, int z, int radius, float radx, float rady, float stencil, block_t id)
{
	int dx, dy;
	float r1 = radius*radx; r1 *= r1;
	float r2 = radius*rady; r2 *= r2;
	float r;
	
	for (dx = -radius; dx <= radius; dx++)
	for (dy = -radius; dy <= radius; dy++) {
		r = dx*dx / r1 + dy*dy / r2;
		if (r <= 1) {
			if (r < 0.65)
				setb(x+dx, y+dy, z, id, 0, 0);
			else if (randf(x+dx, y+dy, z+613) < stencil)
			// always passes with stencil = 1.0, never passes with 0.0
				setb(x+dx, y+dy, z, id, 0, 0);
		}
	}
}
Esempio n. 17
0
void downSpider(int x, int y, int z, block_t id, int tries)
{
	block_t currentBlock = getblock(x, y, z);
	
	// air, crosses, water
	if (isAir(currentBlock) || currentBlock >= halfblock_start)
	{
		if (tries--) downSpider(x, y-1, z, id, tries);
		setb(x, y, z, id);
	}
}
Esempio n. 18
0
streambuf*	
PRfilebuf::setbuf(char *buffptr, int bufflen)
{
    if (is_open() && (ebuf()))
        return 0;
    if ((!buffptr) || (bufflen <= 0))
        unbuffered(1);
    else
        setb(buffptr, buffptr+bufflen, 0);
    return this;
}
Esempio n. 19
0
File: servo.cpp Progetto: teamon/egy
// Inicjalizacja serwomechanizmów 1-2
// UWAGA: zajmuje timer0
void servo_init(){
	
	// Włączenie przerwania od timera 0
	TIMSK = _BV(TOIE0);
	// konfiguracja preskalera
	TCNT0 = TIMER0_BEGIN_VALUE;
	// konfiguracja timera
	TCCR0 = T0_CONF;
	sei();
	
	// Konfiguracja portów
	setb(SERVO1_DDR, SERVO1_PIN);
	setb(SERVO2_DDR, SERVO2_PIN);
	clr(SERVO1_PORT, SERVO1_PIN);
	clr(SERVO2_PORT, SERVO2_PIN);
	
	// logiczne włączenie serw
	servo1 = 1;
	servo2 = 1;
}
Esempio n. 20
0
void obell(int x, int y, int z, block_t id, int lower, int height, int radius, int inner_rad, int midlevel, float midstrength, float understrength, float stencilchance)
{
	float radf, lradf, midd, dr;
	int dx, dy, dz, radxz;
	int r, l;
	
	for (dy = lower; dy <= height; dy++)
	{
		midd = 1.0 - fabs(dy - midlevel) / (height-midlevel);
		midd *= midstrength;
		if (dy < 0) midd = -dy * understrength;
		
		r = powf(radius - midd, 2.0);
		l = powf(inner_rad - midd, 2.0);
		
		dr = (float)dy / (float)height * (float)radius;
		radf = r - dr*dr;
		lradf = l - dr*dr;
		
		for (dx = -radius; dx <= radius; dx++)
		for (dz = -radius; dz <= radius; dz++)
		{
			radxz = dx*dx + dz*dz;
			if (radxz >= lradf && radxz <= radf)
			{
				if (stencilchance < 1.0 && radxz >= radf-8)
				{
					if (randf(x+dx, y+dy, z+dz) < stencilchance)
						setb(x+dx, y+dy, z+dz, id, 1, 0);
				}
				else
				{
					setb(x+dx, y+dy, z+dz, id, 1, 0);
				}
				
			} // rad
		}
		
	}	
	
}
Esempio n. 21
0
  int streambuf::doallocate() {

    char *buf;

    __lock_it( __b_lock );
    buf = (char *)_plib_malloc( DEFAULT_BUF_SIZE );
    if( buf == NULL ) {
        return( EOF );
    }
    setb( buf, buf + DEFAULT_BUF_SIZE, 1 );
    return( __NOT_EOF );          // something other than EOF!
  }
Esempio n. 22
0
void oellipsoidXZ(int x, int y, int z, int radius, float radx, float radz, block_t id)
{
	int dx, dz;
	float r1 = radius*radx; r1 *= r1;
	float r2 = radius*radz; r2 *= r2;
	
	for (dx = -radius; dx <= radius; dx++)
	for (dz = -radius; dz <= radius; dz++)
		if (dx*dx / r1 + dz*dz / r2 <= 1)
			setb(x+dx, y, z+dz, id, 1, 0);
	
}
Esempio n. 23
0
WORD16 StratError(RP FAR* _rp)
  {
  RPIOCtl FAR* rp = (RPIOCtl FAR*)_rp;
  // This command should shutdown any hardware devices that were setup
  // during the initialization stage.  Also, this command should free
  // any resources that the driver owns.
  // Print a message to the debug terminal saying when error
  cdbg << SKELETON;
  cdbg << MSG_ERROR << hex << setw(4);
  cdbg << setw() << setb() << endl;
  return RPDONE | RPERR_COMMAND;
  }
Esempio n. 24
0
void uos_init (void)
{
	/* Baud 19200. */
	UBRR = ((int) (KHZ * 1000L / 19200) + 8) / 16 - 1;

	/* Enable external RAM: port A - address/data, port C - address. */
	setb (SRE, MCUCR);
	mem_init (&pool, RAM_START, RAM_END);

	slip_init (&slip, 0, "slip0", 80, &pool, KHZ, 38400);
	task_create (hello, 0, "hello", 1, task, sizeof (task));
}
Esempio n. 25
0
strstreambuf::strstreambuf(int n)
{
    if( n < MinStrstreamAlloc )
        n = MinStrstreamAlloc;
    char *p = new char[n];
    setb(p, p+n, 0);
    *p = 0;
    allocf = 0;
    freef = 0;
    next_alloc = 0;
    ssbflags = dynamic;
}
Esempio n. 26
0
void ocircleXZroots(int x, int y, int z, int radius, block_t id)
{
	int dx, dz, r = radius*radius;
	for (dx = -radius; dx <= radius; dx++)
	for (dz = -radius; dz <= radius; dz++)
	{
		if (dx*dx + dz*dz <= r)
		{
			setb(x+dx, y, z+dz, id);
			downSpider(x+dx, y-1, z+dz, id, 6);
		}
	}
}
Esempio n. 27
0
vehiculo::vehiculo()
{
    float           px = 0;
    px = (float) rand() / RAND_MAX;
    seta_n((-1 / 1.7) * log(1 - px));
    px = (float) rand() / RAND_MAX;
    setb_n((-1 / 2.0) * log(1 - px));
    if (-3 <= ((getb_n() - 3) / 2)) {
	setb(-3);
    } else {
	setb((getb_n() - 3) / 2);
    }
    px = (float) rand() / RAND_MAX;
    sets_n((-1 / 6.5) * log(1 - px));
    setx_n(0);
    px = (float) rand() / RAND_MAX;
    setV_n((-1 / 1.7) * log(1 - px));
    settau(CTAU);
    v_n = 0.10;
    ptrsiguiente = 0;
    ptranterior = 0;
}
Esempio n. 28
0
PafColor& PafColor::makeDepthmapClassic( double field, double blue, double red )
{
   m_color = 0xff000000; // set alpha to 255, solid colour
   double green = blue + (red-blue) / 10.0;
   // NB previously included colour muting: the 1.0 was originally 0.9 to mute the colours slightly
   if (field >= 0.0 && field < blue) {
      setr(htmlByte(0.5 * (blue - field)/blue * 1.0));
      // Quick mod - TV
#if defined(_WIN32)
      setb(unsigned char(0xFF));
#else
      setb((unsigned char)(0xFF));
#endif
   }
Esempio n. 29
0
/***
*virtual streambuf* filebuf::setbuf(char* ptr, int len) - set reserve area.
*
*Purpose:
*	Synchronizes buffer with external file, by flushing any output and/or
*	discarding any unread input data.  Discards any get or put area(s).
*
*Entry:
*	ptr = requested reserve area.  If NULL, request is for unbuffered.
*	len = size of reserve area.  If <= 0, request is for unbuffered.
*
*Exit:
*	Returns this pointer if request is honored, else NULL.
*
*Exceptions:
*	Returns NULL if request is not honored.
*
*******************************************************************************/
streambuf * filebuf::setbuf(char * ptr, int len)
{
    if (is_open() && (ebuf()))
	return NULL;
    if ((!ptr) || (len <= 0))
	unbuffered(1);
    else
	{
	lock();
	setb(ptr, ptr+len, 0);
	unlock();
	}
    return this;
}
Esempio n. 30
0
filebuf::filebuf(int f)
{
    xfd = f;        // assumed to be valid
    opened = 1;     // unless we can find out otherwise
    mode = 0;       // unless we can find out otherwise
    last_seek = 0;
    char* p = new char[B_size];
    if( p )
        {
        setb(p, p+B_size, 1);   // ~streambuf() will delete buffer
        setp(p+4, p+4);
        setg(p, p+4, p+4);
        }
}