Exemplo n.º 1
0
int
nurand (int A, int x, int y, int C, char *estado1, char *estado2)
{
/* ------------------------------------------------------- *\
|* Función que genera un número aleatório con distribución *|
|* no uniforme, según el método definifido en la cláusula  *|
|* 2.1.6 del TPC-C.                                        *|
|* ------------------------------------------------------- *|
|* Parámetro A: entero que determina el intervalo [0, A]   *|
|* para determinar un núero aleatório necesário la         *|
|* generación del núemro buscado.                          *|
|* Parámetro x: inicio del itervalo de selección.          *|
|* Parámetro y: fin del itervalo de selección.             *|
|* Parámetro C: constante seleccionada para cada atributo. *|
|* Parámetro estado1: estado para la generación de un      *|
|* número aleatorio seleccionado entre x e y               *|
|* Parámetro estado2: estado para la generación de un      *|
|* número aleatorio seleccionado 0 y A                     *|
|* ------------------------------------------------------- *|
|* Retorna el número generado.                             *|
\* ------------------------------------------------------- */

  int lon1, lon2;


  setstate (estado1);
  lon1 = aleat_int (x, y);
  setstate (estado2);
  lon2 = aleat_int (0, A);

  /*Se obtienen el número según la cláusula 2.1.6 */
  return (((lon2 | lon1) + C) % (y - x + 1)) + x;
};
Exemplo n.º 2
0
/* play CD audio */
static int ioctl_command_play (int unitnum, int startlsn, int endlsn, int scan, play_status_callback statusfunc, play_subchannel_callback subfunc)
{
	struct dev_info_ioctl *ciw = unitisopen (unitnum);
	if (!ciw)
		return 0;

	ciw->cdda_play_finished = 0;
	ciw->cdda_subfunc = subfunc;
	ciw->cdda_statusfunc = statusfunc;
	ciw->cdda_scan = scan > 0 ? 10 : (scan < 0 ? 10 : 0);
	ciw->cdda_delay = setstate (ciw, -1);
	ciw->cdda_delay_frames = setstate (ciw, -2);
	setstate (ciw, AUDIO_STATUS_NOT_SUPPORTED);

	if (!open_createfile (ciw, 0)) {
		setstate (ciw, AUDIO_STATUS_PLAY_ERROR);
		return 0;
	}
	if (!isaudiotrack (&ciw->di.toc, startlsn)) {
		setstate (ciw, AUDIO_STATUS_PLAY_ERROR);
		return 0;
	}
	if (!ciw->cdda_play) {
		uae_start_thread (_T("ioctl_cdda_play"), cdda_play, ciw, NULL);
	}
	ciw->cdda_start = startlsn;
	ciw->cdda_end = endlsn;
	ciw->cd_last_pos = ciw->cdda_start;
	ciw->cdda_play++;

	return 1;
}
Exemplo n.º 3
0
istream& istream::getline(char *str, streamsize n, char delim) {
  FatPos_t pos;
  int c;
  m_gcount = 0;
  if (n > 0) str[0] = '\0';
  while (1) {
    c = getch(&pos);
    if (c < 0) {
      break;
    }
    if (c == delim) {
      m_gcount++;
      break;
    }
    if ((m_gcount + 1)  >=  n) {
      setpos(&pos);
      setstate(failbit);
      break;
    }
    str[m_gcount++] = c;
    str[m_gcount] = '\0';
  }
  if (m_gcount == 0) setstate(failbit);
  return *this;
}
Exemplo n.º 4
0
 /// \details
 /// Registers a function as an event callback with an integer parameter to
 /// be passed to the function when invoked.  Multiple copies of the
 /// function are allowed.  If there are multiple callbacks, they are
 /// invoked in the order they were registered.
 void
 ios_base::register_callback(event_callback fn __attribute__((unused)),
     int index __attribute__((unused)))
   {
     size_t req_size = __event_size_ + 1;
     if (req_size > __event_cap_)
       {
         size_t newcap;
         const size_t mx = numeric_limits < size_t > ::max();
         if (req_size < mx / 2)
         newcap = _VSTD::max(2 * __event_cap_, req_size);
         else
         newcap = mx;
         event_callback* fns = (event_callback*) realloc(__fn_,
             newcap * sizeof(event_callback));
         if (fns == 0)
         setstate(badbit);
         __fn_ = fns;
         int* indxs = (int*) realloc(__index_, newcap * sizeof(int));
         if (indxs == 0)
         setstate(badbit);
         __index_ = indxs;
       }
     __fn_[__event_size_] = fn;
     __index_[__event_size_] = index;
     ++__event_size_;
   }
Exemplo n.º 5
0
void ostream::outstr(const char *d, const char *p)
{
    if( opfx() )
        {
        int plen = p ? strlen(p) : 0;
        int dlen = d ? strlen(d) : 0;
        int pad = width(0) - plen - dlen;

        // pad on left (right-adjust) if needed -- the default case
        if( ! (x_flags & (ios::left | ios::internal)) )
            {
            while( --pad >= 0 )
                {
                if( bp->sputc(x_fill) == EOF )
                    {
                    setstate(ios::badbit);
                    break;
                    }
                }
            }

        // output the prefix
        if( ! fail()  &&  plen )
            if( bp->sputn(p, plen) != plen )
                setstate(ios::badbit);

        // internal padding if needed
        if( ! fail()  &&  (x_flags & ios::internal) )
            {
            while( --pad >= 0 )
                {
                if( bp->sputc(x_fill) == EOF )
                    {
                    setstate(ios::badbit);
                    break;
                    }
                }
            }

        // output the data
        if( ! fail()  &&  dlen )
            if( bp->sputn(d, dlen) != dlen )
                setstate(ios::badbit);

        // pad on right (left-adjust) if needed
        if( ! fail()  &&  (x_flags & ios::left) )
            {
            while( --pad >= 0 )
                {
                if( bp->sputc(x_fill) == EOF )
                    {
                    setstate(ios::badbit);
                    break;
                    }
                }
            }
        }
    osfx();
}
Exemplo n.º 6
0
static void WINAPI ctrlproc(DWORD ctrl) {
    if (ctrl == SERVICE_CONTROL_STOP) {
	    setstate(SERVICE_STOP_PENDING);
        service->stop();
    } else {
	    setstate(sta.dwCurrentState);
    }
}
Exemplo n.º 7
0
static int32_t
FcRandom(void)
{
    int32_t result;

#if HAVE_RANDOM_R
    static struct random_data fcrandbuf;
    static char statebuf[256];
    static FcBool initialized = FcFalse;

    if (initialized != FcTrue)
    {
	initstate_r(time(NULL), statebuf, 256, &fcrandbuf);
	initialized = FcTrue;
    }

    random_r(&fcrandbuf, &result);
#elif HAVE_RANDOM
    static char statebuf[256];
    char *state;
    static FcBool initialized = FcFalse;

    if (initialized != FcTrue)
    {
	state = initstate(time(NULL), statebuf, 256);
	initialized = FcTrue;
    }
    else
	state = setstate(statebuf);

    result = random();

    setstate(state);
#elif HAVE_LRAND48
    result = lrand48();
#elif HAVE_RAND_R
    static unsigned int seed = time(NULL);

    result = rand_r(&seed);
#elif HAVE_RAND
    static FcBool initialized = FcFalse;

    if (initialized != FcTrue)
    {
	srand(time(NULL));
	initialized = FcTrue;
    }
    result = rand();
#else
# error no random number generator function available.
#endif

    return result;
}
Exemplo n.º 8
0
static void WINAPI startproc(int argc, TCHAR **argv) {
    hsta = RegisterServiceCtrlHandler(service_name, ctrlproc);
    sta.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
    sta.dwServiceSpecificExitCode = 0;
    sta.dwControlsAccepted = SERVICE_ACCEPT_STOP;
    sta.dwWin32ExitCode = 0;
    sta.dwWaitHint = 3000;
    sta.dwCheckPoint = 0;
    setstate(SERVICE_RUNNING);
    service->start(argc, argv);
    setstate(SERVICE_STOPPED);
}
Exemplo n.º 9
0
int
cad_alfa_num (int ini, int fin, char *cadena, char *estado1, char *estado2)
{
/* ------------------------------------------------------ *\
|* Función que genera una cadena de caracteres            *|
|* alfanuméricos de tamaño comfrendido entre              *|
|* 'ini' y 'fin'                                          *|
|* ------------------------------------------------------ *|
|* Parámetro ini: inicio del entervalo de selección del   *|
|* tamaño                                                 *|
|* Parámetro fin: fin del entervalo de selección del tamaño*|
|* Parámetro cadena: cadena donde se almacenan los        *|
|* caractero aleatorios                                   *|
|* Parámetro estado1: estado para la generación del       *|
|* tamaño de la cadena aleatoria                          *|
|* Parámetro estado2: estado para la generación del       *|
|* de los caracteres aleatorios                           *|
|* ------------------------------------------------------ *|
|* Retorna el tamaño de la cadena generada                *|
\* ------------------------------------------------------ */
  int tam, i;
  char ch;

  /* utilizamos estado1 para el tamaño de la cadena */
  setstate (estado1);
  tam = (int) aleat_int (ini, fin);
  setstate (estado2);
  /* utilizamos estado2 para los caracteres aleatorios (e_global) */

  /*Se generan cada uno de los caracteres hasta completar el */
  /*el tamaño generado                                      */
  for (i = 0; i < tam; i++)
     {
       ch = (char) aleat_int (32, 125);	/*generamos aleatoriamente caracteres. */
       if ((ch >= 32) && (ch <= 125))
	  {			/*sólo se contemplas caracteres alfanuméricos   */
	    /*ATENCIÖN: si el caracter generado en el 39 (comilla simple ') se escoje el */
	    /*caracter 40. Esto se hace para evitar el error produce postgreSQL al       */
	    /*introducir una comilla simple en un atributo.                              */
	    if (ch == 39)
	      ch++;
	    cadena[i] = ch;
	  }
       else
	  {
	    printf ("ERROR EN LA FUNCION CAD_ALFA_NUM\n");
	    exit (0);
	  }
     }				/* de for */
  cadena[i] = '\0';		/*se termina la cadena con el fin de cadena */
  return tam;			/*se retorna el tamaño de la cadena generada */
}
Exemplo n.º 10
0
  void fstreambase::setbuf( char *buf, int len ) {

    filebuf *fb;

    __lock_it( __i_lock );
    fb = rdbuf();
    if( fb == NULL ) {
        setstate( ios::failbit );
    } else {
        __lock_it( fb->__b_lock );
        if( fb->setbuf( buf, len ) == NULL ) {
            setstate( ios::failbit );
        }
    }
  }
Exemplo n.º 11
0
void fstreambase::close() {

    filebuf *fb;

    __lock_it( __i_lock );
    fb = rdbuf();
    if( fb == NULL ) {
        setstate( ios::failbit );
    } else {
        __lock_it( fb->__b_lock );
        if( fb->close() == NULL ) {
            setstate( ios::failbit );
        }
    }
}
Exemplo n.º 12
0
locale
ios_base::imbue(const locale& loc)
{
    locale result = *loc_;
#ifndef _EWL_NO_EXCEPTIONS
    try
    {
#endif  // _EWL_NO_EXCEPTIONS
        locale* newloc = new locale(loc);
#ifdef _EWL_NO_EXCEPTIONS
        if (newloc == 0)
            __ewl_error("ios_base::imbue out of memory");
#endif  // _EWL_NO_EXCEPTIONS
        delete loc_;
        loc_ = newloc;
#ifndef _EWL_TINY_IO
        do_callbacks(imbue_event);
#endif
#ifndef _EWL_NO_EXCEPTIONS
    }
    catch (...)
    {
        setstate(badbit);
    }
#endif  // _EWL_NO_EXCEPTIONS
    return result;
}
Exemplo n.º 13
0
void FileIOS::close()
{
	if (!_buf.close())
	{
		setstate(ios_base::badbit);
	}
}
Exemplo n.º 14
0
Arquivo: proc.c Projeto: aaronb/CS637
// Set up first user process.
void
userinit(void)
{
  struct proc *p;
  extern uchar _binary_initcode_start[], _binary_initcode_size[];
  
  p = copyproc(0);
  p->sz = PAGE;
  p->mem = kalloc(p->sz);
  p->cwd = namei("/");
  memset(p->tf, 0, sizeof(*p->tf));
  p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
  p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
  p->tf->es = p->tf->ds;
  p->tf->ss = p->tf->ds;
  p->tf->eflags = FL_IF;
  p->tf->esp = p->sz;
  
  // Make return address readable; needed for some gcc.
  p->tf->esp -= 4;
  *(uint*)(p->mem + p->tf->esp) = 0xefefefef;

  // On entry to user space, start executing at beginning of initcode.S.
  p->tf->eip = 0;
  memmove(p->mem, _binary_initcode_start, (int)_binary_initcode_size);
  safestrcpy(p->name, "initcode", sizeof(p->name));
#ifdef LOTTERY
  p->tickets = INIT_TICKETS;
#endif
  p->state = UNUSED;
  setstate(p, RUNNABLE);

  initproc = p;
}
Exemplo n.º 15
0
Arquivo: proc.c Projeto: aaronb/CS637
// Atomically release lock and sleep on chan.
// Reacquires lock when reawakened.
void
sleep(void *chan, struct spinlock *lk)
{
  if(cp == 0)
    panic("sleep");

  if(lk == 0)
    panic("sleep without lk");

  // Must acquire proc_table_lock in order to
  // change p->state and then call sched.
  // Once we hold proc_table_lock, we can be
  // guaranteed that we won't miss any wakeup
  // (wakeup runs with proc_table_lock locked),
  // so it's okay to release lk.
  if(lk != &proc_table_lock){
    acquire(&proc_table_lock);
    release(lk);
  }

  // Go to sleep.
  cp->chan = chan;
//  cp->state = SLEEPING;
  setstate(cp, SLEEPING);
  sched();

  // Tidy up.
  cp->chan = 0;

  // Reacquire original lock.
  if(lk != &proc_table_lock){
    release(&proc_table_lock);
    acquire(lk);
  }
}
Exemplo n.º 16
0
// read the put pointer's position
streampos ostream::tellp()
{
    streampos p = EOF;
    if( bad()  ||  (p = bp->seekoff(0, ios::cur, ios::out)) == EOF )
        setstate(ios::failbit);
    return p;
}
Exemplo n.º 17
0
//------------------------------------------------------------------------------
void istream::getBool(bool *b) {
  if ((flags() & boolalpha) == 0) {
    getNumber(b);
    return;
  }
  PGM_P truePtr = PSTR("true");
  PGM_P falsePtr = PSTR("false");
  const uint8_t true_len = 4;
  const uint8_t false_len = 5;
  bool trueOk = true;
  bool falseOk = true;
  uint8_t i = 0;
  int c = readSkip();
  while (1) {
    falseOk = falseOk && c == pgm_read_byte(falsePtr + i);
    trueOk = trueOk && c == pgm_read_byte(truePtr + i);
    if (trueOk == false && falseOk == false) break;
    i++;
    if (trueOk && i == true_len) {
      *b = true;
      return;
    }
    if (falseOk && i == false_len) {
      *b = false;
      return;
    }
    c = getch();
  }
  setstate(failbit);
}
Exemplo n.º 18
0
  istream &istream::do_read( char *buf, streamsize len ) {

    __lock_it( __i_lock );
    streamsize offset = rdbuf()->sgetn( buf, len );
    if( offset < len ) {
#if 0
        setstate( ios::failbit );
#else
        setstate( ( rdbuf()->underflow() == EOF )
                ? ios::failbit | ios::eofbit
                : ios::failbit );
#endif
    }
    __last_read_length = offset;
    return( *this );
  }
Exemplo n.º 19
0
/*-------------------------------------------------------------ostream::seekp-+
|                                                                             |
+----------------------------------------------------------------------------*/
ostream & ostream::seekp(streampos pos)
{
   if (!fail() && (rdbuf()->pubseekpos(pos, ios::out) == EOF)) {
       setstate(failbit);
   }
   return *this;
}
Exemplo n.º 20
0
/*******************************************************************************
 raw_imemstream
*******************************************************************************/
raw_ios::pos_type raw_imemstream::seekoff(off_type offs, seekdir dir)
{
   setstate(eofbit, false) ;
   const pos_type from =
      dir == cur ? _pos : (dir == beg ? pos_type() : (pos_type)_size) ;
   return _pos = midval<pos_type>(0, _size, from + offs) ;
}
Exemplo n.º 21
0
void rpcstream::verify(int ok) {
    if (ok) {
	clear();
    } else {
	setstate(ios::failbit);
    }
}
Exemplo n.º 22
0
void
TPUARTwrap::stopped()
{
  setstate(T_new);

  LowLevelFilter::stopped();
}
Exemplo n.º 23
0
 ///
 /// \details
 /// The iword function provides access to an array of integers that can be
 /// used for any purpose.  The array grows as required to hold the
 /// supplied index.  All integers in the array are initialized to 0.
 ///
 /// The implementation reserves several indices.  You should use xalloc to
 /// obtain an index that is safe to use.  Also note that since the array
 /// can grow dynamically, it is not safe to hold onto the reference.
 long&
 ios_base::iword(int index)
   {
     size_t req_size = static_cast<size_t>(index) + 1;
     if (req_size > __iarray_cap_)
       {
         size_t newcap;
         const size_t mx = numeric_limits < size_t > ::max();
         if (req_size < mx / 2)
         newcap = _VSTD::max(2 * __iarray_cap_, req_size);
         else
         newcap = mx;
         long* iarray = (long*) realloc(__iarray_, newcap * sizeof(long));
         if (iarray == 0)
           {
             setstate(badbit);
             static long error;
             error = 0;
             return error;
           }
         __iarray_ = iarray;
         for (long* p = __iarray_ + __iarray_size_; __iarray_cap_ < newcap;
             ++__iarray_cap_, ++p)
         *p = 0;
       }
     __iarray_size_ = max < size_t > (__iarray_size_, req_size);
     return __iarray_[index];
   }
Exemplo n.º 24
0
States::States(int r,QString tag_,QTreeWidget *parent) :
    QTreeWidgetItem(parent)
{
    tag = tag_;
    number = r;
    setstate(r);
}
Exemplo n.º 25
0
//------------------------------------------------------------------------------
void istream::getStr(char *str) {
  FatPos_t pos;
  uint16_t i = 0;
  uint16_t m = width() ? width() - 1 : 0XFFFE;
  if (m != 0) {
    getpos(&pos);
    int c = readSkip();

    while (i < m) {
      if (c < 0) {
        break;
      }
      if (isspace(c)) {
        setpos(&pos);
        break;
      }
      str[i++] = c;
      c = getch(&pos);
    }
  }
  str[i] = '\0';
  if (i == 0) {
    setstate(failbit);
  }
  width(0);
}
Exemplo n.º 26
0
/*-------------------------------------------------------------ostream::seekp-+
|                                                                             |
+----------------------------------------------------------------------------*/
ostream & ostream::seekp(streamoff off, ios::seekdir dir)
{
   if (!fail() && (rdbuf()->pubseekoff(off, dir, ios::out) == EOF)) {
       setstate(failbit);
   }
   return *this;
}
Exemplo n.º 27
0
  fstreambase::fstreambase( filedesc fd ) {

    ios::init( &__flbuf );
    if( __flbuf.attach( fd ) == NULL ) {
        setstate( ios::failbit | ios::badbit );
    }
  }
Exemplo n.º 28
0
//------------------------------------------------------------------------------
void SdStreamBase::putch(char c) {
  if (c == '\n' && !(getmode() & ios::binary)) {
    write('\r');
  }
  write(c);
  if (writeError) setstate(badbit);
}
Exemplo n.º 29
0
/* ------------------------------------------------------------------------- */
static int
lpc_random_restore_old_state(void)
{
    int err = 0;
    char *old_state = NULL;

    if (lpc_random_old_state == NULL) {
        goto bail;
    }

    old_state = setstate(lpc_random_old_state);
    if (old_state == NULL) {
        err = 1;
        goto bail;
    }
    else if (old_state != lpc_random_state) {
        /*
         * Unexpected; what else would it have been, if we had put
         * something into lpc_random_old_state?
         */
        syslog(LOG_INFO, "Unexpected return from setstate(): %p", old_state);
    }

 bail:
    return(err);
}
Exemplo n.º 30
0
void iconvstream::open(std::ostream& sink_,
  const char* tocode, const char* fromcode,
  iconvstreambuf::mode_t mode)
{
  if (!fail() && streambuf.open(sink_, tocode, fromcode, mode) == 0)
    setstate(std::ios::failbit);
}