Example #1
0
size_t NullStore::CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end, const std::string &channel, bool blocking) const
{
	static const byte nullBytes[128] = {0};
	while (begin < end)
	{
		size_t len = (size_t)STDMIN(end-begin, lword(128));
		size_t blockedBytes = target.ChannelPut2(channel, nullBytes, len, 0, blocking);
		if (blockedBytes)
			return blockedBytes;
		begin += len;
	}
	return 0;
}
NODE *lfput(NODE *args) {
    NODE *lst, *arg;

    if (is_word(cadr(args)) && is_word(car(args)) &&
	    getstrlen(cnv_node_to_strnode(car(args))) == 1)
	return lword(args);

    arg = car(args);
    lst = list_arg(cdr(args));
    if (NOT_THROWING)
	return cons(arg,lst);
    else
	return UNBOUND;
}
TbBool load_map_data_file(LevelNumber lv_num)
{
    struct Map *mapblk;
    unsigned long x,y;
    unsigned char *buf;
    unsigned long i;
    unsigned long n;
    unsigned short *wptr;
    long fsize;
    clear_map();
    fsize = 2*(map_subtiles_y+1)*(map_subtiles_x+1);
    buf = load_single_map_file_to_buffer(lv_num,"dat",&fsize,LMFF_None);
    if (buf == NULL)
        return false;
    i = 0;
    for (y=0; y < (map_subtiles_y+1); y++)
    {
        for (x=0; x < (map_subtiles_x+1); x++)
        {
            mapblk = get_map_block_at(x,y);
            n = -lword(&buf[i]);
            mapblk->data ^= (mapblk->data ^ n) & 0x7FF;
            i += 2;
        }
    }
    LbMemoryFree(buf);
    // Clear some bits and do some other setup
    for (y=0; y < (map_subtiles_y+1); y++)
    {
        for (x=0; x < (map_subtiles_x+1); x++)
        {
            mapblk = get_map_block_at(x,y);
            wptr = &game.lish.subtile_lightness[get_subtile_number(x,y)];
            *wptr = 32;
            mapblk->data &= 0xFFC007FFu;
            mapblk->data &= ~0x0F000000;
            mapblk->data &= ~0xF0000000;
        }
    }
    return true;
}
TbBool load_thing_file(LevelNumber lv_num)
{
    struct InitThing itng;
    unsigned long i;
    long k;
    long total;
    unsigned char *buf;
    long fsize;
    SYNCDBG(5,"Starting");
    fsize = 2;
    buf = load_single_map_file_to_buffer(lv_num,"tng",&fsize,LMFF_None);
    if (buf == NULL)
      return false;
    i = 0;
    total = lword(&buf[i]);
    i += 2;
    // Validate total amount of things
    if ((total < 0) || (total > (fsize-2)/sizeof(struct InitThing)))
    {
        total = (fsize-2)/sizeof(struct InitThing);
        WARNMSG("Bad amount of things in TNG file; corrected to %d.",(int)total);
    }
    if (total > THINGS_COUNT-2)
    {
        WARNMSG("Only %d things supported, TNG file has %d.",(int)(THINGS_COUNT-2),(int)total);
        total = THINGS_COUNT-2;
    }
    // Create things
    for (k=0; k < total; k++)
    {
        LbMemoryCopy(&itng, &buf[i], sizeof(struct InitThing));
        thing_create_thing(&itng);
        i += sizeof(struct InitThing);
    }
    LbMemoryFree(buf);
    return true;
}
Example #5
0
  void ptransform ( std::string& s ) {
    std::string word(s);

    // Lower-case the word.
    std::string lword(word);
    std::transform(lword.begin(), lword.end(), lword.begin(), ::tolower );

    // Find where the first 'aeiou' occurs.
    std::size_t pivot = lword.find_first_of("aeiou");

    // Determine the suffix.
    std::string ay;
    if( pivot == 0 ) {
      ay = "way";
    }
    else {
      ay = "ay";
    }

    // Configure the piglatin string.
    std::string pword
      = lword.substr(pivot,lword.length()-pivot)
      + lword.substr(0,pivot)
      + ay;

    // Capitalize if necessary.
    if(
      word.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
      != std::string::npos
    ) {
      pword.at(0) = toupper(pword.at(0));
    }

    // Set our return value (via param)
    s = pword;
  }
Example #6
0
/*
 * Fixes up a bit stream after literals have been read out of the
 * data stream.
 */
static void bitread_fix (bit_stream *bs, unsigned char **p) {
    bs->bitcount -= 16;
    bs->bitbuf &= (1<<bs->bitcount)-1; /* remove the top 16 bits */
    bs->bitbuf |= (lword(*p)<<bs->bitcount);/* replace with what's at *p */
    bs->bitcount += 16;
}
Example #7
0
/*
 * Initialises a bit stream with the first two bytes of the packed
 * data.
 */
static void bitread_init (bit_stream *bs, unsigned char **p) {
    bs->bitbuf = lword (*p);
    bs->bitcount = 16;
}