Esempio n. 1
0
/**
 * Using the given wrap width, calculate the width and height necessary to display this text
 */
Point FontEngine::calc_size(string text_with_newlines, int width) {
	char newline = 10;
	
	string text = text_with_newlines;

	// if this contains newlines, recurse
	int check_newline = text.find_first_of(newline);
	if (check_newline > -1) {
		Point p1 = calc_size(text.substr(0, check_newline), width);
		Point p2 = calc_size(text.substr(check_newline+1, text.length()), width);
		Point p3;
		
		if (p1.x > p2.x) p3.x = p1.x;
		else p3.x = p2.x;
		
		p3.y = p1.y + p2.y;
		return p3;
	}

	int height = 0;
	int max_width = 0;

	string segment;
	string fulltext;
	string builder = "";
	string builder_prev = "";
	char space = 32;
	
	fulltext = text + " ";
	segment = eatFirstString(fulltext, space);
	
	while(segment != "" || fulltext.length() > 0) { // don't exit early on double spaces
		builder = builder + segment;
		
		if (calc_length(builder) > width) {
			height = height + getLineHeight();
			if (calc_length(builder_prev) > max_width) max_width = calc_length(builder_prev);
			builder_prev = "";
			builder = segment + " ";
		}
		else {
			builder = builder + " ";
			builder_prev = builder;
		}
		
		segment = eatFirstString(fulltext, space);
	}
	
	height = height + getLineHeight();
	builder = trim(builder, ' '); //removes whitespace that shouldn't be included in the size
	if (calc_length(builder) > max_width) max_width = calc_length(builder);
		
	Point size;
	size.x = max_width;
	size.y = height;
	return size;
}
Esempio n. 2
0
/**
	@fn static pool_u calc_size(pool_u8* tree, pool_u pos, pool_u8 depth)
	@brief Calculates the number of used blocks in the pool

	@param[in] tree The tree
	@param[in] pos The position in the tree we are looking at
	@param[in] depth The depth of the tree

	@return The number of used blocks
*/
POOL_FUNC static pool_u calc_size(pool_u8* tree, pool_u pos, pool_u8 depth)
{
	pool_u8 pos_level = pool_log2(pos);
	if (pos_level > depth)
		return 0;
	if (!POOL_GET_BIT(tree, pos))
		return pool_pow2(depth - pos_level);
	else
		return calc_size(tree, 2 * pos, depth) + calc_size(tree, 2 * pos + 1, depth);
}
Esempio n. 3
0
	size_t calc_size(node* curr) {
		if (!curr) {
			return 0;
		}

		//A little wordy, but I'd like to avoid an extra function call per leaf node.
		size_t res = 1; //Count yourself
		if (curr->left) {
			res += calc_size(curr->left);
		}
		if (curr->right) {
			res += calc_size(curr->right);
		}
		return res;
	}
Esempio n. 4
0
File: obox.cpp Progetto: mecirt/7k2
//------- Begin of function Box::tell ----------//
//
// Popup a box and display a message. Call Box::close() to close the box.
//
// Syntax :: tell( <char*> )
//
// <char*> tellStr = pointer to the message, use '\n' to seperate lines
// [int]   x1, y1 = the left corner of the box, if not given
//                  center the box on the screen
//
void Box::tell(char* tellStr, int x1, int y1)
{
   calc_size(tellStr,BOX_TOP_MARGIN+BOX_BOTTOM_MARGIN,x1,y1);   // calculate x1, y1, x2, y2 depended on the tellStr

	font_bld.put_paragraph( box_x1+BOX_X_MARGIN, box_y1+BOX_TOP_MARGIN, box_x2-BOX_X_MARGIN,
			   box_y2-BOX_BOTTOM_MARGIN, tellStr, BOX_LINE_SPACE );
}
Esempio n. 5
0
/* returns true or false */
static int is_deblk_end(union au_vdir_deblk_p *p,
                        union au_vdir_deblk_p *deblk_end)
{
    if (calc_size(0) <= deblk_end->deblk - p->deblk)
        return !p->de->de_str.len;
    return 1;
}
Esempio n. 6
0
/** Add rr (from packet here) to rrset, skips rr */
static int
add_rr_to_rrset(struct rrset_parse* rrset, sldns_buffer* pkt, 
	struct msg_parse* msg, struct regional* region, 
	sldns_pkt_section section, uint16_t type)
{
	struct rr_parse* rr;
	/* check section of rrset. */
	if(rrset->section != section && type != LDNS_RR_TYPE_RRSIG &&
		rrset->type != LDNS_RR_TYPE_RRSIG) {
		/* silently drop it - we drop the last part, since
		 * trust in rr data depends on the section it is in. 
		 * the less trustworthy part is discarded. 
		 * also the last part is more likely to be incomplete.
		 * RFC 2181: must put RRset only once in response. */
		/*
		verbose(VERB_QUERY, "Packet contains rrset data in "
			"multiple sections, dropped last part.");
		log_buf(VERB_QUERY, "packet was", pkt);
		*/
		/* forwards */
		if(!skip_ttl_rdata(pkt))
			return LDNS_RCODE_FORMERR;
		return 0;
	} 

	if( (msg->qtype == LDNS_RR_TYPE_RRSIG ||
	     msg->qtype == LDNS_RR_TYPE_ANY) 
	    && sig_is_double(pkt, rrset, sldns_buffer_current(pkt))) {
		if(!skip_ttl_rdata(pkt))
			return LDNS_RCODE_FORMERR;
		return 0;
	}
	
	/* create rr */
	if(!(rr = (struct rr_parse*)regional_alloc(region, sizeof(*rr))))
		return LDNS_RCODE_SERVFAIL;
	rr->outside_packet = 0;
	rr->ttl_data = sldns_buffer_current(pkt);
	rr->next = 0;
	if(type == LDNS_RR_TYPE_RRSIG && rrset->type != LDNS_RR_TYPE_RRSIG) {
		if(rrset->rrsig_last) 
			rrset->rrsig_last->next = rr;
		else	rrset->rrsig_first = rr;
		rrset->rrsig_last = rr;
		rrset->rrsig_count++;
	} else {
		if(rrset->rr_last)
			rrset->rr_last->next = rr;
		else	rrset->rr_first = rr;
		rrset->rr_last = rr;
		rrset->rr_count++;
	}

	/* calc decompressed size */
	if(!calc_size(pkt, type, rr))
		return LDNS_RCODE_FORMERR;
	rrset->size += rr->size;

	return 0;
}
Esempio n. 7
0
void psub_menu::draw(jwindow *parent, int x, int y, window_manager *wmanager)
{
  if (win) wm->close_window(win);
  wm=wmanager;


  int w,h,i=0;
  calc_size(w,h,wm);
  short cx1,cy1,cx2,cy2;
  screen->get_clip(cx1,cy1,cx2,cy2);
  if (parent->x+w+x>cx2)
    x=cx2-w-parent->x;
  if (h+y+parent->y>cy2)
    if (parent->y+parent->h+wm->frame_font()->height()>cy2)
      y=-h;
     else y=y-h+wm->frame_font()->height()+5;
     

  win=wm->new_window(parent->x+x,parent->y+y,
		     w-WINDOW_FRAME_LEFT-WINDOW_FRAME_RIGHT,
		     h-WINDOW_FRAME_TOP-WINDOW_FRAME_BOTTOM,NULL);
  win->set_moveability(0);
  win->screen->wiget_bar(0,0,w-1,h-1,wm->bright_color(),wm->medium_color(),wm->dark_color());

  int has_flags=0;
  pmenu_item *p=first;
  for (;p;p=p->next) if (p->on_off) has_flags=1;
  x=has_flags ? 3+wm->frame_font()->width() : 3;
  y=3;
 
  for (p=first;p;p=p->next,i++,y+=wm->frame_font()->height()+1)
    p->draw(win,x,y,w-6,0,wm,i==active);

}
Esempio n. 8
0
/**
@fn static pool_u pool_buddy_size(pool_u8* tree, pool_u pos, pool_u8 depth)
@brief Calculates the number of allocated bytes in the pool

@param[in] tree The tree
@param[in] pos The position in the tree we are looking at
@param[in] depth The depth of the tree

@return The number of allocated bytes
*/
POOL_FUNC pool_u pool_buddy_size(pool_buddy* p, pool_err* err)
{
	pool_u8 depth = pool_log2(POOL_CEIL_DIV(POOL_BUDDY_MAX_SIZE, POOL_BUDDY_BLOCK_SIZE));
	POOL_SET_ERR(err, POOL_ERR_OK);
	POOL_SET_ERR_IF(p == NULL, err, POOL_ERR_INVALID_POOL, 0);
	return POOL_BUDDY_BLOCK_SIZE*calc_size(p->tree, 1, depth);
}
Esempio n. 9
0
void TControl::set_font(TFont *fnt)
{
    m_font = fnt;
    calc_size();
    if (m_font) 
     send_msg(WM_SETFONT,(WPARAM)m_font->handle(),(LPARAM)TRUE);
}
 void initialize(std::vector<attack_t> & attacks)
 {
     std::vector<int> points;
     points.reserve(2 * attacks.size());
     // put all the points into a vector
     for (auto const & attack : attacks)
     {
         points.push_back(std::get<1>(attack));
         points.push_back(std::get<2>(attack));
     }
     // sort points
     std::sort(points.begin(), points.end());
     // remove duplicates
     auto end = std::unique(points.begin(), points.end());
     // replace each point with a respective index
     for (auto & attack : attacks)
     {
         // use binary search (lower_bound) to find the iterator pointing to the element of interest
         auto it = std::lower_bound(points.begin(), end, std::get<1>(attack));
         std::get<1>(attack) = it - points.begin();
         it = std::lower_bound(points.begin(), end, std::get<2>(attack));
         std::get<2>(attack) = it - points.begin();
     }
     // prepare the wall
     size = end - points.begin();
     segment_tree.resize(calc_size(size), 0);
 }
Esempio n. 11
0
static void menu_firstfit(WMenu *menu, bool submenu, const WRectangle *refg)
{
    WRectangle geom;
    
    calc_size(menu, &(geom.w), &(geom.h));
    
    if(!(menu->last_fp.mode&REGION_FIT_BOUNDS)){
        geom.x=menu->last_fp.g.x;
        geom.y=menu->last_fp.g.y;
    }else if(menu->pmenu_mode){
        geom.x=refg->x;
        geom.y=refg->y;
        
        if(!submenu){
            const WRectangle *maxg = 
                &REGION_GEOM(REGION_PARENT((WRegion*)menu));
            
            geom.x-=geom.w/2;
            geom.y+=POINTER_OFFSET;

            if(geom.y+MINIMUM_Y_VISIBILITY>maxg->y+maxg->h){
                geom.y=maxg->y+maxg->h-MINIMUM_Y_VISIBILITY;
                geom.x=refg->x+POINTER_OFFSET;
                if(geom.x+geom.w>maxg->x+maxg->w)
                    geom.x=refg->x-geom.w-POINTER_OFFSET;
            }else{
                if(geom.x<0)
                    geom.x=0;
                else if(geom.x+geom.w>maxg->x+maxg->w)
                    geom.x=maxg->x+maxg->w-geom.w;
            }
        }
    }else{
        const WRectangle *maxg=&(menu->last_fp.g);
        if(submenu){
            int l, r, t, b, xoff, yoff;
            
            get_placement_offs(menu, &xoff, &yoff);
            l=refg->x+xoff;
            r=refg->x+refg->w+xoff;
            t=refg->y-yoff;
            b=refg->y+refg->h-yoff;
            
            geom.x=maxof(l, r-geom.w);
            if(geom.x+geom.w>maxg->x+maxg->w)
                geom.x=maxg->x;

            geom.y=minof(b-geom.h, t);
            if(geom.y<maxg->y)
                geom.y=maxg->y;
        }else{
            geom.x=maxg->x;
            geom.y=maxg->y+maxg->h-geom.h;
        }
    }
    
    window_do_fitrep(&menu->win, NULL, &geom);
}
Esempio n. 12
0
static int set_deblk_end(union aufs_deblk_p *p, union aufs_deblk_p *deblk_end)
{
	if (calc_size(0) <= deblk_end->p - p->p) {
		p->de->de_str.len = 0;
		//smp_mb();
		return 0;
	}
	return -1; // error
}
Esempio n. 13
0
void vsx_widget_split_panel::i_draw()
{
  calc_size();
  vsx_vector3<> p = calc_pos();
  if (render_type == render_2d)
  p.z = 0.0f;
  if (orientation == VSX_WIDGET_SPLIT_PANEL_VERT) {
    sy = size.y-splitter_size;
    float sx = size.x;

    if (fabsf(two->size_min.y) > 0.0f) {
      if (sy*(1-split_pos) < two->size_min.y) {
        split_pos = (sy-two->size_min.y)/sy;
      }
    }
    if (fabsf(two->size_max.y) > 0.0f) {
      if (sy*(1-split_pos) > two->size_max.y) {
        split_pos = (sy-two->size_max.y)/sy;
      }
    }

    if (fabsf(one->size_min.y) > 0.0f) {
      if (sy*(split_pos) < one->size_min.y) {
        split_pos = (one->size_min.y)/sy;
      }
    }
    if (fabsf(one->size_max.y) > 0.0f) {
      if (sy*(split_pos) > two->size_max.y) {
        split_pos = (one->size_max.y)/sy;
      }
    }
      
    two->target_size.x = sx;
    two->target_size.y = sy*(1-split_pos);
    two->size = two->target_size;


    one->target_size.x = sx;
    one->target_size.y = sy*split_pos;
    one->size = one->target_size;
      
    one->target_pos.x = 0;
    one->target_pos.y = -target_size.y*0.5f + 0.5f*split_pos*sy;
    one->target_pos.z = pos.z;
    one->pos = one->target_pos;

    two->target_pos.x = 0;
    two->target_pos.y = target_size.y*0.5f - 0.5f*(1.0f-split_pos)*sy;
    two->target_pos.z = pos.z;
    two->pos = two->target_pos;

    glColor4f(1,1,1,1);
    if (!FLOAT_EQUALS(splitter_size, 0) )
    draw_box(p+vsx_vector3<>(0,split_pos*sy),sx,splitter_size);
  }
}
Esempio n. 14
0
double indiv::evaluate(void){
    fitness = 0;
    float output;
    for(int j=0; j < NUM_ENTRIES; j++){
        output = the_indiv-> evaluate(inputs[j], inputs2[j]);
        fitness += pow((output-outputs[j]), 2);
    }
    fitness = sqrt(fitness) + (calc_size() * .01);
    return fitness;
}
Esempio n. 15
0
static int set_deblk_end(union au_vdir_deblk_p *p,
                         union au_vdir_deblk_p *deblk_end)
{
    if (calc_size(0) <= deblk_end->deblk - p->deblk) {
        p->de->de_str.len = 0;
        /* smp_mb(); */
        return 0;
    }
    return -1; /* error */
}
Esempio n. 16
0
/**
	@fn void pool_buddy_stat(pool_buddy* p, pool_buddy_stats* stats, pool_err* err);
	@brief Stats the buddy mem

	@param[in] p The buddy struct
	@param[out] stats The statistics structure
	@param[out] err The error that happened
*/
POOL_FUNC void pool_buddy_stat(pool_buddy* p, pool_buddy_stats* stats, pool_err* err)
{
	pool_u8 depth = pool_log2(POOL_CEIL_DIV(POOL_BUDDY_MAX_SIZE, POOL_BUDDY_BLOCK_SIZE));
	POOL_SET_ERR(err, POOL_ERR_OK);
	POOL_SET_ERR_IF(p == NULL, err, POOL_ERR_INVALID_POOL, );
	POOL_SET_ERR_IF(stats == NULL, err, POOL_ERR_INVALID_PTR, );
	stats->size = POOL_BUDDY_MAX_SIZE;
	stats->n_blocks = POOL_BUDDY_BLOCK_N;
	stats->n_blocks_used = calc_size(p->tree, 1, depth);
	stats->used = stats->n_blocks_used*POOL_BUDDY_BLOCK_SIZE;
}
Esempio n. 17
0
File: obox.cpp Progetto: mecirt/7k2
//------- Begin of function Box::ask ----------//
//
// Popup a message box and ask user 'Ok' or 'Cancel'
//
// Syntax :: ask( <char*> )
//
// <char*> msgStr     = pointer to the message, use '\n' to seperate lines
// [char*] buttonDes1 = the description of button 1 (default : "Ok")
// [char*] buttonDes2 = the description of button 2 (default : "Cancel")
// [int]   x1, y1     = the left corner of the box, if not given
//                      center the box on the screen
//
// Return : 1 - if user select "Ok" button
//          0 - if user select "Cancel" button
//
//
int Box::ask(char* msgStr, char* buttonDes1, char* buttonDes2, int x1, int y1)
{
   int rc;

   calc_size(msgStr,BOX_TOP_MARGIN+BOX_BOTTOM_MARGIN,x1,y1);   // calculate x1, y1, x2, y2 depended on the msgStr

   opened_flag = 1;
   rc = ask_button(msgStr, buttonDes1, buttonDes2);

   close();

   return rc;
}
Esempio n. 18
0
blargg_err_t Gzip_Reader::open( File_Reader* new_in )
{
	close();
	
	in = new_in;
	RETURN_ERR( in->seek( 0 ) );
	RETURN_ERR( inflater.begin( gzip_reader_read, new_in ) );
	RETURN_ERR( inflater.set_mode( inflater.mode_auto ) );
	RETURN_ERR( calc_size() );
	set_remain( size_ );
	
	return blargg_ok;
}
Esempio n. 19
0
void psub_menu::hide(jwindow *parent, int x, int y, window_manager* wm)
{
  int w,h;
  calc_size(w,h,wm);
  short cx1,cy1,cx2,cy2;
  screen->get_clip(cx1,cy1,cx2,cy2);
  if (w+x>cx2)
    x=cx2-w;


  if (win)
  {
    if (active!=-1)
    {
      int w,h;
      calc_size(w,h,wm);
      item_num(active)->draw(win,x+3,y+3+active*(wm->frame_font()->height()+1),w-6,0,wm,0);
    }
    wm->close_window(win);
    win=NULL;
  }
}
Esempio n. 20
0
File: obox.cpp Progetto: mecirt/7k2
//------- Begin of function Box::msg ----------//
//
// Popup a message box and ask user to press the 'Ok' button
//
// Syntax :: msg( <char*> )
//
// <char*> msgStr 		 = pointer to the message, use '\n' to
//									seperate lines.
// [int]   enableTimeOut = enable time out or not (default: 1)
// [int]   x1, y1 		 = the left corner of the box, if not given
//                  		   center the box on the screen.
//
void Box::msg(const char* msgStr, int enableTimeOut, int x1, int y1)
{
	calc_size(msgStr,BOX_TOP_MARGIN+BOX_BOTTOM_MARGIN,x1,y1);   // calculate x1, y1, x2, y2 depended on the msgStr
  down_centre = 1;
  opened_flag = 1;
  paint();

	font_bld.put_paragraph( box_x1+BOX_X_MARGIN, box_y1+BOX_TOP_MARGIN, box_x2-BOX_X_MARGIN,
				box_y2-BOX_BOTTOM_MARGIN, msgStr, BOX_LINE_SPACE );

	ok_button(enableTimeOut);
	close();
}
Esempio n. 21
0
void vsx_widget_base_editor::i_draw() {
  calc_pos();
  calc_size();
  //vsx_widget_panel::base_draw();
  float db15 = dragborder*2.5f;
  scrollbar_horiz->set_pos(vsx_vector(-size.x*0.5,-size.y*0.5));
  scrollbar_horiz->set_size(vsx_vector(target_size.x-db15, db15));
  scrollbar_horiz->scroll_window_size = editor->scroll_x_size;

  scrollbar_vert->set_pos(vsx_vector(size.x*0.5-db15,-size.y*0.5+db15));
  scrollbar_vert->set_size(vsx_vector(db15,target_size.y-scrollbar_horiz->size.y));
  scrollbar_vert->scroll_window_size = editor->scroll_y_size;
  editor->set_pos(vsx_vector(-scrollbar_vert->size.x*0.5f,scrollbar_horiz->size.y*0.5f));

  editor->target_size.x = target_size.x-scrollbar_vert->size.x;
  editor->target_size.y = target_size.y-scrollbar_horiz->size.y;
}
Esempio n. 22
0
SymbolTableEntry* enterSymbol(char* symbolName, SymbolAttribute* attribute)
{
    int hashIndex = HASH(symbolName);
    SymbolTableEntry* hashChain = symbolTable.hashTable[hashIndex];
    SymbolTableEntry* newEntry = newSymbolTableEntry(symbolTable.currentLevel);
    newEntry->attribute = attribute;
    newEntry->name = symbolName;

    if(attribute->attributeKind == VARIABLE_ATTRIBUTE)
    {
        newEntry->offset = ARoffset;
        ARoffset -= calc_size(attribute->attr.typeDescriptor);
    }
    

    while(hashChain)
    {
        if(strcmp(hashChain->name, symbolName) == 0)
        {
            if(hashChain->nestingLevel == symbolTable.currentLevel)
            {
                printf("void enterSymbol(...): ID \'%s\' is redeclared(at the same level#%d).\n", symbolName, symbolTable.currentLevel);
                free(newEntry);
                return NULL;
            }
            else
            {
                removeFromHashTrain(hashIndex, hashChain);
                newEntry->sameNameInOuterLevel = hashChain;
                break;
            }
        }
        else
        {
            hashChain = hashChain->nextInHashChain;
        }
    }
    enterIntoHashTrain(hashIndex, newEntry);
    newEntry->nextInSameLevel = symbolTable.scopeDisplay[symbolTable.currentLevel];
    symbolTable.scopeDisplay[symbolTable.currentLevel] = newEntry;
    
    return newEntry;
}
Esempio n. 23
0
or_ent *or_map::entity_add (or_ent_type *_ent_type, uint32_t tile_c,
        bool collide_, int32_t x, int32_t y) {
    if (! _ent_type)
        return nullptr;

    auto _ent = new or_ent (this);
    _ent->_ent_type = _ent_type;
    _ent->tile_c = tile_c;
    _ent->collide_ = collide_;
    _ent->x = x;
    _ent->y = y;
    _ent->x_f = (float)x;
    _ent->y_f = (float)y;

    _ent->calc_pos ();
    _ent->calc_size ();

    this->ents.push_back (_ent);
    return _ent;
}
Esempio n. 24
0
void vsx_widget_panel::base_draw() {
  calc_size();
  vsx_vector3<> p = calc_pos();
  //vsx_color b(0,0,0,0), w(0,0,0,1), gr(0,1,0,1), r(1,0,0,1);
  vsx_color<> b(0,0,0,0);
  vsx_color<> w(0,0,0,1);
  //draw_box_gradient(p, dragborder, target_size.y, skin_color[0], skin_color[1], skin_color[1], skin_color[0]);

  draw_box_gradient(p, (float)dragborder, target_size.y, vsx_widget_skin::get_instance()->get_color(0), vsx_widget_skin::get_instance()->get_color(1), vsx_widget_skin::get_instance()->get_color(1), vsx_widget_skin::get_instance()->get_color(0));

  //  draw_box_gradient(p, target_size.x, dragborder, r, b, b, r);
  draw_box_gradient(p, target_size.x, (float)dragborder, w, b, b, w);
  p.y += size.y - (float)dragborder;
  draw_box_gradient(p, target_size.x, (float)dragborder, vsx_widget_skin::get_instance()->get_color(0), vsx_widget_skin::get_instance()->get_color(0), vsx_widget_skin::get_instance()->get_color(1), vsx_widget_skin::get_instance()->get_color(1));

  //  draw_box_gradient(p, target_size.x, dragborder, skin_color[0], skin_color[0], skin_color[1], gr);
  p.x += size.x - (float)dragborder;

  //p.y +=
  //draw_box_gradient(p, dragborder, -(target_size.y-dragborder), gr, skin_color[0], skin_color[1], skin_color[1]);
}
Esempio n. 25
0
int psub_menu::handle_event(jwindow *parent, int x, int y, window_manager *wm, event &ev)
{
  int w,h;
  calc_size(w,h,wm);
  short cx1,cy1,cx2,cy2;
  screen->get_clip(cx1,cy1,cx2,cy2);

  x=win->x;
  y=win->y;

  int has_flags=0,dx=3;
  for (pmenu_item *p=first;p;p=p->next) if (p->on_off) has_flags=1;
  if (has_flags) dx+=wm->frame_font()->width();

  int th=wm->frame_font()->height();
  if (ev.mouse_move.x>=x && ev.mouse_move.y>=y && ev.mouse_move.x<x+w && ev.mouse_move.y<y+h)
  {
    int new_active=(ev.mouse_move.y-y-3)/(th+1);
    if (item_num(new_active)==NULL) new_active=-1;

    if (new_active!=active)
    {
      if (active!=-1)
        item_num(active)->draw(win,dx,3+active*(th+1),w-6,0,wm,0);
      active=new_active;
      if (active!=-1)
        item_num(active)->draw(win,dx,3+active*(th+1),w-6,0,wm,1);
    }
    if (ev.type==EV_MOUSE_BUTTON)
    {
      if (active!=-1)
        return item_num(active)->handle_event(win,dx,3+active*(th+1),w-6,0,wm,ev);
      else return 0;
    } else return 1;
  } else if (active!=-1)
    return item_num(active)->handle_event(win,win->x+dx,win->y+3+active*(th+1),w-6,0,wm,ev);
  else return 0;


}
Esempio n. 26
0
static void menu_do_refit(WMenu *menu, WWindow *par, const WFitParams *oldfp)
{
    WRectangle geom;
    
    calc_size(menu, &(geom.w), &(geom.h));
    
    if(!(menu->last_fp.mode&REGION_FIT_BOUNDS)){
        geom.x=menu->last_fp.g.x;
        geom.y=menu->last_fp.g.y;
    }else if(menu->pmenu_mode){
        geom.x=REGION_GEOM(menu).x;
        geom.y=REGION_GEOM(menu).y;
    }else{
        const WRectangle *maxg=&(menu->last_fp.g);
        int xdiff=REGION_GEOM(menu).x-oldfp->g.x;
        int ydiff=(REGION_GEOM(menu).y+REGION_GEOM(menu).h
                   -(oldfp->g.y+oldfp->g.h));
        geom.x=maxof(0, minof(maxg->x+xdiff, maxg->x+maxg->w-geom.w));
        geom.y=maxof(0, minof(maxg->y+maxg->h+ydiff, maxg->y+maxg->h)-geom.h);
    }
    
    window_do_fitrep(&menu->win, par, &geom);
}
Esempio n. 27
0
void *thr_func(void *arg)
{
    while (1) {
        size_t s = calc_size();
        void *p = malloc(s);
        if (p == NULL) {
            printf("Failed to malloc: %d\n", s);
            return NULL;
        }

        if (!is_access())
            memset(p, 0xaa, s);

        if (!leak())
            free(p);

        /* sleep */
        const static useconds_t slp_min = 10*1000;
        const static useconds_t slp_max = 100*1000;
        useconds_t slp = (slp_max - slp_min) * frand() + slp_min;
        usleep(slp);
    }
}
Esempio n. 28
0
void IndexManager::create_index_file(const string& indexname, int attr_type)
{
	FILE *pFile = fopen(indexname.c_str(), "wb");
	if (!pFile)
	{
		cout << "create index fail";
	}
	FileHeader file_header;
	file_header.block_count = 0;
	file_header.record_size = 2 + NODE_CAPACITY * (sizeof(NodePointer) + calc_size(attr_type));
	fwrite(&file_header, sizeof(FileHeader), 1, pFile);
	fclose(pFile);

	//create an empty node in the first block
	File *file = buffer_manager_->open_file(indexname);
	Block *block = find_block_not_full(file);
	block->dirty = true;
	char *node_address = block->address + sizeof(BlockHeader) + file->header.record_size * block->header.record_count;
	memset(node_address, -1, file->header.record_size);
	node_address[0] = 0;//deleted flag bit is set 0
	node_address[1] = 1;//leaf flag bit is set 1
	block->header.record_count++;
	block->header.remain_record--;
}
Esempio n. 29
0
	//AncestorID starts at zero and increases by one for every time we jump up to an ancestor.
	void findAndBalanceScapegoat(nall::linear_vector<node*>& parentStack, node* curr, size_t nodeSize, size_t ancestorID) {
		bool foundScapegoat = false;
		while (!foundScapegoat) {
			//Step 1: Pop the stack, compute the parent size, and replace curr with parent; update ancestorID
			node* parent = parentStack[parentStack.size()-1];
			parentStack.resize(parentStack.size()-1);
			size_t siblingSize = calc_size(parent->left==curr?parent->right:parent->left);
			nodeSize = nodeSize + siblingSize + 1;
			curr = parent;
			ancestorID++;

			//Step 2: Check if this node is the root; if not, apply the formula.
			//        (Note that the root node satisfies the formula, but we want to be extra-safe here).
			foundScapegoat = (curr==root);
			if (!foundScapegoat) {
				foundScapegoat = (ancestorID > logA.log(nodeSize));
			}

			//Step 3: Rebalance if this is the scapegoat
			if (foundScapegoat) {
				rebalance(parentStack[parentStack.size()-1], curr, nodeSize);
			}
		}
	}
Esempio n. 30
0
unsigned long flash_init (void)
{
	unsigned long size_b0, size_b1;
	int i;
	uint pbcr;
	unsigned long base_b0, base_b1;

	/* Init: no FLASHes known */
	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
	}

	/* Static FLASH Bank configuration here - FIXME XXX */

	base_b0 = FLASH_BASE0_PRELIM;
	size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);

	if (flash_info[0].flash_id == FLASH_UNKNOWN) {
		printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
				size_b0, size_b0 << 20);
	}

	base_b1 = FLASH_BASE1_PRELIM;
	size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);

	/* Re-do sizing to get full correct info */

	if (size_b1) {
		if (size_b1 < (1 << 20)) {
			/* minimum CS size on PPC405GP is 1MB !!! */
			size_b1 = 1 << 20;
		}
		base_b1 = -size_b1;
		mtdcr (EBC0_CFGADDR, PB0CR);
		pbcr = mfdcr (EBC0_CFGDATA);
		mtdcr (EBC0_CFGADDR, PB0CR);
		pbcr = (pbcr & 0x0001ffff) | base_b1 | (calc_size(size_b1) << 17);
		mtdcr (EBC0_CFGDATA, pbcr);
#if 0 /* test-only */
		printf("size_b1=%x base_b1=%x PB1CR = %x\n",
		       size_b1, base_b1, pbcr); /* test-only */
#endif
	}

	if (size_b0) {
		if (size_b0 < (1 << 20)) {
			/* minimum CS size on PPC405GP is 1MB !!! */
			size_b0 = 1 << 20;
		}
		base_b0 = base_b1 - size_b0;
		mtdcr (EBC0_CFGADDR, PB1CR);
		pbcr = mfdcr (EBC0_CFGDATA);
		mtdcr (EBC0_CFGADDR, PB1CR);
		pbcr = (pbcr & 0x0001ffff) | base_b0 | (calc_size(size_b0) << 17);
		mtdcr (EBC0_CFGDATA, pbcr);
#if 0 /* test-only */
		printf("size_b0=%x base_b0=%x PB0CR = %x\n",
		       size_b0, base_b0, pbcr); /* test-only */
#endif
	}

	size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);

	flash_get_offsets (base_b0, &flash_info[0]);

	/* monitor protection ON by default */
	flash_protect (FLAG_PROTECT_SET,
			base_b0 + size_b0 - monitor_flash_len,
			base_b0 + size_b0 - 1, &flash_info[0]);

	if (size_b1) {
		/* Re-do sizing to get full correct info */
		size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);

		flash_get_offsets (base_b1, &flash_info[1]);

		/* monitor protection ON by default */
		flash_protect (FLAG_PROTECT_SET,
				base_b1 + size_b1 - monitor_flash_len,
				base_b1 + size_b1 - 1, &flash_info[1]);
		/* monitor protection OFF by default (one is enough) */
		flash_protect (FLAG_PROTECT_CLEAR,
				base_b0 + size_b0 - monitor_flash_len,
				base_b0 + size_b0 - 1, &flash_info[0]);
	} else {
		flash_info[1].flash_id = FLASH_UNKNOWN;
		flash_info[1].sector_count = -1;
	}

	flash_info[0].size = size_b0;
	flash_info[1].size = size_b1;

	return (size_b0 + size_b1);
}