Esempio n. 1
0
// externally called function, returns 0 on success, -1 on error
int feed_more( mpg123_handle_t *fr, const byte *in, long count )
{
	if( bc_add( &fr->rdat.buffer, in, count ) != 0 )
		return MPG123_ERR;

	return MPG123_OK;
}
Esempio n. 2
0
// add
BigNumber & BigNumber::operator+= (const BigNumber & n)
{ 
  bc_num result = NULL;
  bc_add (num_, n.num_, &result, scale_);
  bc_free_num (&num_);
  num_ = result;
  return *this; 
} // end of BigNumber::operator+= 
Esempio n. 3
0
/* externally called function, returns 0 on success, -1 on error */
int feed_more(mpg123_handle *fr, const unsigned char *in, long count)
{
	int ret = 0;
	if(VERBOSE3) debug("feed_more");
	if((ret = bc_add(&fr->rdat.buffer, in, count)) != 0)
	{
		ret = READER_ERROR;
		if(NOQUIET) error1("Failed to add buffer, return: %i", ret);
	}
	else /* Not talking about filelen... that stays at 0. */

	if(VERBOSE3) debug3("feed_more: %p %luB bufsize=%lu", fr->rdat.buffer.last->data,
		(unsigned long)fr->rdat.buffer.last->size, (unsigned long)fr->rdat.buffer.size);
	return ret;
}
Esempio n. 4
0
static ssize_t buffered_fullread(mpg123_handle *fr, unsigned char *out, ssize_t count)
{
    struct bufferchain *bc = &fr->rdat.buffer;
    ssize_t gotcount;
    if(bc->size - bc->pos < count)
    {   /* Add more stuff to buffer. If hitting end of file, adjust count. */
        unsigned char readbuf[BUFFBLOCK];
        ssize_t need = count - (bc->size-bc->pos);
        while(need>0)
        {
            int ret;
            ssize_t got = fr->rdat.fullread(fr, readbuf, BUFFBLOCK);
            if(got < 0)
            {
                if(NOQUIET) error("buffer reading");
                return READER_ERROR;
            }

            if(VERBOSE3) debug1("buffered_fullread: buffering %li bytes from stream (if > 0)", (long)got);
            if(got > 0 && (ret=bc_add(bc, readbuf, got)) != 0)
            {
                if(NOQUIET) error1("unable to add to chain, return: %i", ret);
                return READER_ERROR;
            }

            need -= got; /* May underflow here... */
            if(got < BUFFBLOCK) /* That naturally catches got == 0, too. */
            {
                if(VERBOSE3) fprintf(stderr, "Note: Input data end.\n");
                break; /* End. */
            }
        }
        if(bc->size - bc->pos < count)
            count = bc->size - bc->pos; /* We want only what we got. */
    }
    gotcount = bc_give(bc, out, count);

    if(VERBOSE3) debug2("wanted %li, got %li", (long)count, (long)gotcount);

    if(gotcount != count) {
        if(NOQUIET) error("gotcount != count");
        return READER_ERROR;
    }
    else return gotcount;
}
Esempio n. 5
0
String f_bcadd(CStrRef left, CStrRef right, int64 scale /* = -1 */) {
  if (scale < 0) scale = BCG(bc_precision);
  bc_num first, second, result;
  bc_init_num(&first);
  bc_init_num(&second);
  bc_init_num(&result);
  php_str2num(&first, (char*)left.data());
  php_str2num(&second, (char*)right.data());
  bc_add(first, second, &result, scale);
  if (result->n_scale > scale) {
    result->n_scale = scale;
  }
  String ret(bc_num2str(result), AttachString);
  bc_free_num(&first);
  bc_free_num(&second);
  bc_free_num(&result);
  return ret;
}
Esempio n. 6
0
static String HHVM_FUNCTION(bcadd, const String& left, const String& right,
                            int64_t scale /* = -1 */) {
  if (scale < 0) scale = BCG(bc_precision);
  bc_num first, second, result;
  bc_init_num(&first);
  bc_init_num(&second);
  bc_init_num(&result);
  php_str2num(&first, (char*)left.data());
  php_str2num(&second, (char*)right.data());
  bc_add(first, second, &result, scale);
  if (result->n_scale > scale) {
    result->n_scale = scale;
  }
  String ret(bc_num2str(result), AttachString);
  bc_free_num(&first);
  bc_free_num(&second);
  bc_free_num(&result);
  return ret;
}
Esempio n. 7
0
// the specific stuff for buffered stream reader.
static mpg_ssize_t buffered_fullread( mpg123_handle_t *fr, byte *out, mpg_ssize_t count )
{
	bufferchain_t	*bc = &fr->rdat.buffer;
	mpg_ssize_t		gotcount;

	if( bc->size - bc->pos < count )
	{
		// add more stuff to buffer. If hitting end of file, adjust count.
		byte	readbuf[4096];

		mpg_ssize_t need = count - (bc->size - bc->pos);

		while( need > 0 )
		{
			mpg_ssize_t	got = fr->rdat.fullread( fr, readbuf, sizeof( readbuf ));
			int	ret;

			if( got < 0 )
				return MPG123_ERR;

			if( got > 0 && ( ret = bc_add( bc, readbuf, got )) != 0 )
				return MPG123_ERR;

			need -= got; // may underflow here...

			if( got < sizeof( readbuf )) // that naturally catches got == 0, too.
				break; // end.
		}

		if( bc->size - bc->pos < count )
			count = bc->size - bc->pos; // we want only what we got.
	}

	gotcount = bc_give( bc, out, count );

	if( gotcount != count )
		return MPG123_ERR;
	return gotcount;
}
Esempio n. 8
0
int
main(void)
{
    char *memend;
    int i;

    WDEBUG_INIT();
    WDEBUG('X');

    /* Pick up arguments */
    kargs = (void *)__args;
    initial_howto = kargs->howto;
    initial_bootdev = kargs->bootdev;
    initial_bootinfo = kargs->bootinfo ? (struct bootinfo *)PTOV(kargs->bootinfo) : NULL;

#ifdef COMCONSOLE_DEBUG
    printf("args at %p initial_howto = %08x bootdev = %08x bootinfo = %p\n",
	kargs, initial_howto, initial_bootdev, initial_bootinfo);
#endif

    /* Initialize the v86 register set to a known-good state. */
    bzero(&v86, sizeof(v86));
    v86.efl = PSL_RESERVED_DEFAULT | PSL_I;

    /*
     * Initialize the heap as early as possible.  Once this is done,
     * malloc() is usable.
     *
     * Don't include our stack in the heap.  If the stack is in low
     * user memory use {end,bios_basemem}.  If the stack is in high
     * user memory but not extended memory then don't let the heap
     * overlap the stack.  If the stack is in extended memory limit
     * the heap to bios_basemem.
     *
     * Be sure to use the virtual bios_basemem address rather then
     * the physical bios_basemem address or we may overwrite BIOS
     * data.
     */
    bios_getmem();

    memend = (char *)&memend - 0x8000;	/* space for stack (16K) */
    memend = (char *)((uintptr_t)memend & ~(uintptr_t)(0x1000 - 1));

    /*
     * For day to day usage simple memend setup is more than engouh,
     * but bigger heap is a must for loading bzipp'ed kernel/modules
     * "bzf_read: BZ2_bzDecompress returned -3"
     */
#if defined(LOADER_BZIP2_SUPPORT)
    if (high_heap_size > 0) {
	heap_top = PTOV(high_heap_base + high_heap_size);
	heap_bottom = PTOV(high_heap_base);
	if (high_heap_base < memtop_copyin)
	    memtop_copyin = high_heap_base;
    } else
#endif
    if (memend < (char *)_end) {
	heap_top = PTOV(bios_basemem);
	heap_bottom = (void *)_end;
    } else {
	if (memend > (char *)PTOV(bios_basemem))
	    memend = (char *)PTOV(bios_basemem);
	heap_top = memend;
	heap_bottom = (void *)_end;
    }
    setheap(heap_bottom, heap_top);

    /*
     * XXX Chicken-and-egg problem; we want to have console output early,
     * but some console attributes may depend on reading from eg. the boot
     * device, which we can't do yet.
     *
     * We can use printf() etc. once this is done.   The previous boot stage
     * might have requested a video or serial preference, in which case we
     * set it.
     */
    bi_setboothowto(initial_howto);
    if (initial_howto & RB_MUTE) {
	setenv("console", "nullconsole", 1);
    } else if ((initial_howto & (RB_VIDEO|RB_SERIAL)) == (RB_VIDEO|RB_SERIAL)) {
	setenv("console", "vidconsole comconsole", 1);
    } else if (initial_howto & RB_VIDEO) {
	setenv("console", "vidconsole", 1);
    } else if (initial_howto & RB_SERIAL) {
	setenv("console", "comconsole", 1);
    } else {
	/* XXX leave to cons_probe() */
    }
    cons_probe();

    /*
     * Initialise the block cache
     */
    bcache_init(32, 512);	/* 16k cache XXX tune this */

    /*
     * Special handling for PXE and CD booting.
     */
    if (kargs->bootinfo == 0) {
	/*
	 * We only want the PXE disk to try to init itself in the below
	 * walk through devsw if we actually booted off of PXE.
	 */
	if (kargs->bootflags & KARGS_FLAGS_PXE)
	    pxe_enable(kargs->pxeinfo ? PTOV(kargs->pxeinfo) : NULL);
	else if (kargs->bootflags & KARGS_FLAGS_CD)
	    bc_add(initial_bootdev);
    }

    archsw.arch_autoload = i386_autoload;
    archsw.arch_getdev = i386_getdev;
    archsw.arch_copyin = i386_copyin;
    archsw.arch_copyout = i386_copyout;
    archsw.arch_readin = i386_readin;
    archsw.arch_isainb = isa_inb;
    archsw.arch_isaoutb = isa_outb;

    /*
     * March through the device switch probing for things.
     */
    for (i = 0; devsw[i] != NULL; i++) {
	WDEBUG('M' + i);
	if (devsw[i]->dv_init != NULL)
	    (devsw[i]->dv_init)();
	WDEBUG('M' + i);
    }
    printf("BIOS %dkB/%dkB available memory\n",
	    bios_basemem / 1024, bios_extmem / 1024);
    if (initial_bootinfo != NULL) {
	initial_bootinfo->bi_basemem = bios_basemem / 1024;
	initial_bootinfo->bi_extmem = bios_extmem / 1024;
    }

    /* detect ACPI for future reference */
    biosacpi_detect();

    /* detect SMBIOS for future reference */
    smbios_detect(NULL);

    /* detect PCI BIOS for future reference */
    biospci_detect();

    /* enable EHCI */
    setenv("ehci_load", "YES", 1);

    /* enable XHCI */
    setenv("xhci_load", "YES", 1);

    printf("\n");
    printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
    printf("(%s, %s)\n", bootprog_maker, bootprog_date);

    extract_currdev();				/* set $currdev and $loaddev */
    setenv("LINES", "24", 1);			/* optional */

    bios_getsmap();

    interact();			/* doesn't return */

    /* if we ever get here, it is an error */
    return (1);
}
Esempio n. 9
0
int
main(void)
{
    int			i;

    /* Set machine type to PC98_SYSTEM_PARAMETER. */
    set_machine_type();

    /* Pick up arguments */
    kargs = (void *)__args;
    initial_howto = kargs->howto;
    initial_bootdev = kargs->bootdev;
    initial_bootinfo = kargs->bootinfo ? (struct bootinfo *)PTOV(kargs->bootinfo) : NULL;

    /* Initialize the v86 register set to a known-good state. */
    bzero(&v86, sizeof(v86));
    v86.efl = PSL_RESERVED_DEFAULT | PSL_I;

    /* 
     * Initialise the heap as early as possible.  Once this is done, malloc() is usable.
     */
    bios_getmem();

#if defined(LOADER_BZIP2_SUPPORT)
    if (high_heap_size > 0) {
	heap_top = PTOV(high_heap_base + high_heap_size);
	heap_bottom = PTOV(high_heap_base);
	if (high_heap_base < memtop_copyin)
	    memtop_copyin = high_heap_base;
    } else
#endif
    {
	heap_top = (void *)PTOV(bios_basemem);
	heap_bottom = (void *)end;
    }
    setheap(heap_bottom, heap_top);

    /* 
     * XXX Chicken-and-egg problem; we want to have console output early, but some
     * console attributes may depend on reading from eg. the boot device, which we
     * can't do yet.
     *
     * We can use printf() etc. once this is done.
     * If the previous boot stage has requested a serial console, prefer that.
     */
    bi_setboothowto(initial_howto);
    if (initial_howto & RB_MULTIPLE) {
	if (initial_howto & RB_SERIAL)
	    setenv("console", "comconsole vidconsole", 1);
	else
	    setenv("console", "vidconsole comconsole", 1);
    } else if (initial_howto & RB_SERIAL)
	setenv("console", "comconsole", 1);
    else if (initial_howto & RB_MUTE)
	setenv("console", "nullconsole", 1);
    cons_probe();

    /*
     * Initialise the block cache
     */
    bcache_init(32, 512);	/* 16k cache XXX tune this */

    /*
     * Special handling for PXE and CD booting.
     */
    if (kargs->bootinfo == 0) {
	/*
	 * We only want the PXE disk to try to init itself in the below
	 * walk through devsw if we actually booted off of PXE.
	 */
	if (kargs->bootflags & KARGS_FLAGS_PXE)
	    pxe_enable(kargs->pxeinfo ? PTOV(kargs->pxeinfo) : NULL);
	else if (kargs->bootflags & KARGS_FLAGS_CD)
	    bc_add(initial_bootdev);
    }

    archsw.arch_autoload = i386_autoload;
    archsw.arch_getdev = i386_getdev;
    archsw.arch_copyin = i386_copyin;
    archsw.arch_copyout = i386_copyout;
    archsw.arch_readin = i386_readin;
    archsw.arch_isainb = isa_inb;
    archsw.arch_isaoutb = isa_outb;
    archsw.arch_loadaddr = pc98_loadaddr;

    /*
     * March through the device switch probing for things.
     */
    for (i = 0; devsw[i] != NULL; i++)
	if (devsw[i]->dv_init != NULL)
	    (devsw[i]->dv_init)();
    printf("BIOS %dkB/%dkB available memory\n", bios_basemem / 1024, bios_extmem / 1024);
    if (initial_bootinfo != NULL) {
	initial_bootinfo->bi_basemem = bios_basemem / 1024;
	initial_bootinfo->bi_extmem = bios_extmem / 1024;
    }

    printf("\n");
    printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
    printf("(%s, %s)\n", bootprog_maker, bootprog_date);

    extract_currdev();				/* set $currdev and $loaddev */
    setenv("LINES", "24", 1);			/* optional */

    interact();			/* doesn't return */

    /* if we ever get here, it is an error */
    return (1);
}