示例#1
0
static void *
get_buffer(lua_State *L, int index, int *sz) {
	void *buffer;
	switch(lua_type(L, index)) {
		const char * str;
		size_t len;
	case LUA_TUSERDATA:
	case LUA_TLIGHTUSERDATA:
		buffer = lua_touserdata(L,index);
		*sz = luaL_checkinteger(L,index+1);
		break;
	case LUA_TTABLE:
		// concat the table as a string
		len = count_size(L, index);
		buffer = skynet_malloc(len);
		concat_table(L, index, buffer, len);
		*sz = (int)len;
		break;
	default:
		str =  luaL_checklstring(L, index, &len);
		buffer = skynet_malloc(len);
		memcpy(buffer, str, len);
		*sz = (int)len;
		break;
	}
	return buffer;
}
void			event_radar(t_sdl *sdl)
{
  int			xaff;
  int			yaff;
  int			w;
  int			h;
  static int		first = 1;

  get_size_aff(sdl, &xaff, &yaff);
  count_size(&w, xaff, &h, yaff);
  if (first)
    {
      sdl->radar.screen_radar = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h,
						     32, 0, 0, 0, 0);
      SDL_FillRect(sdl->radar.screen_radar, NULL,
		   SDL_MapRGB(sdl->screen->format, 255, 255, 255));
      SDL_SetAlpha(sdl->radar.screen_radar, SDL_SRCALPHA, 75);
      first = 0;
    }
  sdl->radar.rect_radar.x = (sdl->scrollX * w * 64) / xaff + 920;
  sdl->radar.rect_radar.y = (sdl->scrollY * h * 64) / yaff + 42;
  xSDL_BlitSurface(sdl->radar.screen_radar, NULL, sdl->screen,
		  &sdl->radar.rect_radar);
  put_monster_minimap(sdl);
}
示例#3
0
文件: echo.c 项目: bloodead/BIGSH
char*	id_echo(char** str)
{
	int	size;
	char*	str2;

	size = count_size(str);
	str2 = malloc(sizeof(char) * size);
	id_print_tab(str, str2);
}
示例#4
0
  void deserialize(Reader &is) {
    clear();

    is.read((char*)&num_buckets_, sizeof(num_buckets_));

    index_ = new KMerDataIndex[num_buckets_];
    for (size_t i = 0; i < num_buckets_; ++i)
      index_[i].deserialize(is);

    bucket_starts_.resize(num_buckets_ + 1);
    is.read((char*)&bucket_starts_[0], (num_buckets_ + 1) * sizeof(bucket_starts_[0]));
    count_size();
  }
示例#5
0
t_epur		init_epur(char *str)
{
  t_epur	e;
  int		count;
  char		*tmp2;

  e.com = xmalloc(sizeof(char) * 5);
  e.com[0] = '|';
  e.com[1] = '&';
  e.com[2] = ';';
  e.com[3] = '>';
  e.com[4] = '<';
  e.k = 0;
  e.i = 0;
  tmp2 = first_epur(str);
  count = count_size(tmp2, &e);
  e.tmp = xmalloc(sizeof(char) * (my_strlen(tmp2) + count) + 1);
  my_bzero(e.tmp, my_strlen(tmp2) + count);
  xfree(tmp2);
  return (e);
}
示例#6
0
int count_size(TreeNode* root){
    if (!root) return 0;
    return 1+count_size(root->left)+count_size(root->right);
}
示例#7
0
struct HEADERP *head_parse(FILE *f)
{
  int fd, count, ret;
  unsigned char byte;
  struct HEADERKEY *key;
  struct HEADERP *h;
  char temp[2048];

  fd = fileno(f);
  rewind(f);
  
  if((ret = read( fd, temp, 2048)) != 2048 ) {
    return(NULL);
  }

  temp[2047] = 0;

  if( !strstr( temp, "struct WAPP_HEADER" ) ) {
    return(NULL);
  }
    
  count = 2048;
  while( (ret = read( fd, &byte, 1)) == 1 ) {
    if( byte == 0 )
      break;
    count++;
  }
  wapp_incfile_length=count;

  if( ret < 0) {
    return(NULL);
  }

  h = ( struct HEADERP *)malloc( sizeof(struct HEADERP));
  bzero( h, sizeof(struct HEADERP));

  h->offset = count+1;
  h->fd = fd;
  h->buf = (char *)malloc( h->offset);
  lseek(fd, 0, SEEK_SET);
  read(fd, h->buf, h->offset );

  yacc_input = h;

  while(yyparse()); /* use yacc to parse the header */
  yyparse();

  if( !(h->headlen = count_size(h))) {
    close_parse(h);
    return(NULL);
  }
  h->header = (void *)malloc( h->headlen );
  if( read( fd, h->header, h->headlen ) != h->headlen ) {
    perror("read header");
    close_parse(h);
    return(NULL);
  }

  key = h->head;
  count = 0;
  while( key ) {
    key->len = key_sizes(key->type);
    key->offset = count;
    count  += key->len* key->alen;
    key = key->next;
  }

  return(h);
}