int main(void) { struct items { char *up; char *load; char *fan; char *temp; char *mem; char *swap; char *diskio; char *fs_root; char *fs_home; char *fs_storage; char *net_speed; char *batt; char *vol; char *time; char *status; }; if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "dwmstatus: cannot open display.\n"); return 1; } struct items *i = malloc(sizeof(struct items)); while(1) { i->up = get_up(); i->load = get_load(); i->fan = get_fan(); i->temp = get_temp(); i->mem = get_mem(); i->swap = get_swap(); i->diskio = get_diskio("sda"); i->fs_root = get_space("/"); i->fs_home = get_space("/home"); i->net_speed = get_net_speed(); i->batt = get_batt(); i->vol = get_vol(); i->time = mktimes("%m/%d/%Y %a %H:%M", tzkiev); i->status = smprintf( "up:%s la:%s fan:%s temp:%s m:%s s:%s io:%s /:%s " "~/:%s net:%s bat:%s vol:%s %s", i->up, i->load, i->fan, i->temp, i->mem, i->swap, i->diskio, i->fs_root, i->fs_home, i->net_speed, i->batt, i->vol, i->time); setstatus(i->status); sleep(INTERVAL); } free(i); XCloseDisplay(dpy); return EXIT_SUCCESS; }
void Body2DSW::set_active(bool p_active) { if (active==p_active) return; active=p_active; if (!p_active) { if (get_space()) get_space()->body_remove_from_active_list(&active_list); } else { if (mode==Physics2DServer::BODY_MODE_STATIC) return; //static bodies can't become active if (get_space()) get_space()->body_add_to_active_list(&active_list); //still_time=0; } /* if (!space) return; for(int i=0;i<get_shape_count();i++) { Shape &s=shapes[i]; if (s.bpid>0) { get_space()->get_broadphase()->set_active(s.bpid,active); } } */ }
void AreaSW::_queue_monitor_update() { ERR_FAIL_COND(!get_space()); if (!monitor_query_list.in_list()) get_space()->area_add_to_monitor_query_list(&monitor_query_list); }
void Area2DSW::set_transform(const Matrix32& p_transform) { if (!moved_list.in_list() && get_space()) get_space()->area_add_to_moved_list(&moved_list); _set_transform(p_transform); _set_inv_transform(p_transform.affine_inverse()); }
int brw_prepare_indices( struct brw_context *brw, const struct _mesa_index_buffer *index_buffer, dri_bo **bo_return, GLuint *offset_return) { GLcontext *ctx = &brw->intel.ctx; struct intel_context *intel = &brw->intel; GLuint ib_size = get_size(index_buffer->type) * index_buffer->count; dri_bo *bo; struct gl_buffer_object *bufferobj = index_buffer->obj; GLuint offset = (GLuint)index_buffer->ptr; int ret; /* Turn into a proper VBO: */ if (!bufferobj->Name) { /* Get new bufferobj, offset: */ get_space(brw, ib_size, &bo, &offset); /* Straight upload */ dri_bo_subdata(bo, offset, ib_size, index_buffer->ptr); } else { /* If the index buffer isn't aligned to its element size, we have to * rebase it into a temporary. */ if ((get_size(index_buffer->type) - 1) & offset) { GLubyte *map = ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, GL_DYNAMIC_DRAW_ARB, bufferobj); map += offset; get_space(brw, ib_size, &bo, &offset); dri_bo_subdata(bo, offset, ib_size, map); ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, bufferobj); } else { bo = intel_bufferobj_buffer(intel, intel_buffer_object(bufferobj), INTEL_READ); dri_bo_reference(bo); } } *bo_return = bo; *offset_return = offset; ret = dri_bufmgr_check_aperture_space(bo); return ret; }
void AreaSW::set_space(SpaceSW *p_space) { if (get_space()) { if (monitor_query_list.in_list()) get_space()->area_remove_from_monitor_query_list(&monitor_query_list); if (moved_list.in_list()) get_space()->area_remove_from_moved_list(&moved_list); } monitored_bodies.clear(); _set_space(p_space); }
/***************************************************************************** * void add_A( double quantity ) * * Preconditions: quantity is non-negative * * quantity is no greater than remaining capacity * * Postconditions: quantity of liquid `A' has been added to tank * *****************************************************************************/ void mixing_tank::add_A( double quantity ) { assert (quantity >= 0.0); assert (quantity <= get_space()); quantity_a += quantity; }
int storage_get_available_space(int storage, unsigned long long *bytes) { storage_info_h storage_info; storage_dev_get_space get_space; if (bytes == NULL) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, STORAGE_ERROR_INVALID_PARAMETER); return STORAGE_ERROR_INVALID_PARAMETER; } if (storage_get_storage(storage, &storage_info) != 0) { LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage); return STORAGE_ERROR_NOT_SUPPORTED; } get_space = storage_info->device->get_space; if (get_space == NULL) { LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage); return STORAGE_ERROR_NOT_SUPPORTED; } if (get_space(NULL, bytes) != 0) { LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage); return STORAGE_ERROR_NOT_SUPPORTED; } return STORAGE_ERROR_NONE; }
void Body2DSW::integrate_velocities(real_t p_step) { if (mode==Physics2DServer::BODY_MODE_STATIC) return; if (fi_callback) get_space()->body_add_to_state_query_list(&direct_state_query_list); if (mode==Physics2DServer::BODY_MODE_KINEMATIC) { _set_transform(new_transform,false); _set_inv_transform(new_transform.affine_inverse()); if (contacts.size()==0 && linear_velocity==Vector2() && angular_velocity==0) set_active(false); //stopped moving, deactivate return; } real_t total_angular_velocity = angular_velocity+biased_angular_velocity; Vector2 total_linear_velocity=linear_velocity+biased_linear_velocity; real_t angle = get_transform().get_rotation() - total_angular_velocity * p_step; Vector2 pos = get_transform().get_origin() + total_linear_velocity * p_step; _set_transform(Matrix32(angle,pos),continuous_cd_mode==Physics2DServer::CCD_MODE_DISABLED); _set_inv_transform(get_transform().inverse()); if (continuous_cd_mode!=Physics2DServer::CCD_MODE_DISABLED) new_transform=get_transform(); //_update_inertia_tensor(); }
void test_new_board() { Board* board = new_board(3); for(int i = 0; i < 9; i++) { assert(get_space(board, i) == '-'); } destroy_board(board); }
int _mem_init(size_t pages, malloc_data * md) { md->size = pages * PAGE_SIZE; get_space(pages, md); return 0; }
static inline void save_char(int c) { if (c == 0) c = 0200; get_space(1); out_buff[out_used++] = c; }
NcValues* NcVar::values( void ) const { int ndims = num_dims(); size_t crnr[NC_MAX_DIMS]; size_t edgs[NC_MAX_DIMS]; for (int i = 0; i < ndims; i++) { crnr[i] = 0; edgs[i] = get_dim(i)->size(); } NcValues* valp = get_space(); int status; switch (type()) { case ncFloat: status = NcError::set_err( nc_get_vara_float(the_file->id(), the_id, crnr, edgs, (float *)valp->base()) ); break; case ncDouble: status = NcError::set_err( nc_get_vara_double(the_file->id(), the_id, crnr, edgs, (double *)valp->base()) ); break; case ncInt: status = NcError::set_err( nc_get_vara_int(the_file->id(), the_id, crnr, edgs, (int *)valp->base()) ); break; case ncShort: status = NcError::set_err( nc_get_vara_short(the_file->id(), the_id, crnr, edgs, (short *)valp->base()) ); break; case ncByte: status = NcError::set_err( nc_get_vara_schar(the_file->id(), the_id, crnr, edgs, (signed char *)valp->base()) ); break; case ncChar: status = NcError::set_err( nc_get_vara_text(the_file->id(), the_id, crnr, edgs, (char *)valp->base()) ); break; case ncNoType: default: return 0; } if (status != NC_NOERR) return 0; return valp; }
/* Translate indices to GLuints and store in VB->Elts. */ static void bind_indices( struct gl_context *ctx, const struct _mesa_index_buffer *ib, struct gl_buffer_object **bo, GLuint *nr_bo) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; GLuint i; const void *ptr; if (!ib) { VB->Elts = NULL; return; } if (_mesa_is_bufferobj(ib->obj) && !_mesa_bufferobj_mapped(ib->obj, MAP_INTERNAL)) { /* if the buffer object isn't mapped yet, map it now */ bo[*nr_bo] = ib->obj; (*nr_bo)++; ptr = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr, ib->count * vbo_sizeof_ib_type(ib->type), GL_MAP_READ_BIT, ib->obj, MAP_INTERNAL); assert(ib->obj->Mappings[MAP_INTERNAL].Pointer); } else { /* user-space elements, or buffer already mapped */ ptr = ADD_POINTERS(ib->obj->Mappings[MAP_INTERNAL].Pointer, ib->ptr); } if (ib->type == GL_UNSIGNED_INT && VB->Primitive[0].basevertex == 0) { VB->Elts = (GLuint *) ptr; } else { GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint)); VB->Elts = elts; if (ib->type == GL_UNSIGNED_INT) { const GLuint *in = (GLuint *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } else if (ib->type == GL_UNSIGNED_SHORT) { const GLushort *in = (GLushort *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } else { const GLubyte *in = (GLubyte *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } } }
static inline void save_number(const char *fmt, int number, int len) { if (len < 30) len = 30; /* actually log10(MAX_INT)+1 */ get_space((unsigned) len + 1); (void) grub_snprintf(out_buff + out_used, len + 1, fmt, number); out_used += grub_strlen(out_buff + out_used); }
void AreaSW::set_area_monitor_callback(ObjectID p_id, const StringName &p_method) { if (p_id == area_monitor_callback_id) { area_monitor_callback_method = p_method; return; } _unregister_shapes(); area_monitor_callback_id = p_id; area_monitor_callback_method = p_method; monitored_bodies.clear(); monitored_areas.clear(); _shape_changed(); if (!moved_list.in_list() && get_space()) get_space()->area_add_to_moved_list(&moved_list); }
void dumper_t::dump_to (strbuf &b) { push_curr (); for (size_t i = 0; i < _lines.size (); i++) { ptr<line_t> l = _lines[i]; str space = get_space (l->level ()); str content = l->to_str (); b << space << content << "\n"; } }
bool Body2DSW::sleep_test(real_t p_step) { if (mode == Physics2DServer::BODY_MODE_STATIC || mode == Physics2DServer::BODY_MODE_KINEMATIC) return true; // else if (mode == Physics2DServer::BODY_MODE_CHARACTER) return !active; // characters and kinematic bodies don't sleep unless asked to sleep else if (!can_sleep) return false; if (Math::abs(angular_velocity) < get_space()->get_body_angular_velocity_sleep_treshold() && Math::abs(linear_velocity.length_squared()) < get_space()->get_body_linear_velocity_sleep_treshold() * get_space()->get_body_linear_velocity_sleep_treshold()) { still_time += p_step; return still_time > get_space()->get_body_time_to_sleep(); } else { still_time = 0; //maybe this should be set to 0 on set_active? return false; } }
static inline void save_text(const char *fmt, const char *s, int len) { grub_size_t s_len = grub_strlen(s); if (len > (int) s_len) s_len = len; get_space(s_len + 1); (void) grub_snprintf(out_buff + out_used, s_len + 1, fmt, s); out_used += grub_strlen(out_buff + out_used); }
void Body2DSW::set_space(Space2DSW *p_space){ if (get_space()) { wakeup_neighbours(); if (inertia_update_list.in_list()) get_space()->body_remove_from_inertia_update_list(&inertia_update_list); if (active_list.in_list()) get_space()->body_remove_from_active_list(&active_list); if (direct_state_query_list.in_list()) get_space()->body_remove_from_state_query_list(&direct_state_query_list); } _set_space(p_space); if (get_space()) { _update_inertia(); if (active) get_space()->body_add_to_active_list(&active_list); // _update_queries(); //if (is_active()) { // active=false; // set_active(true); //} } }
void BodySW::set_space(SpaceSW *p_space){ if (get_space()) { if (inertia_update_list.in_list()) get_space()->body_remove_from_inertia_update_list(&inertia_update_list); if (active_list.in_list()) get_space()->body_remove_from_active_list(&active_list); if (direct_state_query_list.in_list()) get_space()->body_remove_from_state_query_list(&direct_state_query_list); } _set_space(p_space); if (get_space()) { _update_inertia(); if (active) get_space()->body_add_to_active_list(&active_list); // _update_queries(); //if (is_active()) { // active=false; // set_active(true); //} } first_integration=true; }
/* Translate indices to GLuints and store in VB->Elts. */ static void bind_indices( struct gl_context *ctx, const struct _mesa_index_buffer *ib, struct gl_buffer_object **bo, GLuint *nr_bo) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; GLuint i; void *ptr; if (!ib) { VB->Elts = NULL; return; } if (ib->obj->Name && !ib->obj->Pointer) { bo[*nr_bo] = ib->obj; (*nr_bo)++; ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY_ARB, ib->obj); assert(ib->obj->Pointer); } ptr = ADD_POINTERS(ib->obj->Pointer, ib->ptr); if (ib->type == GL_UNSIGNED_INT && VB->Primitive[0].basevertex == 0) { VB->Elts = (GLuint *) ptr; } else { GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint)); VB->Elts = elts; if (ib->type == GL_UNSIGNED_INT) { const GLuint *in = (GLuint *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } else if (ib->type == GL_UNSIGNED_SHORT) { const GLushort *in = (GLushort *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } else { const GLubyte *in = (GLubyte *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } } }
static struct gl_client_array * copy_array_to_vbo_array( struct brw_context *brw, GLuint i, const struct gl_client_array *array, GLuint element_size, GLuint count) { GLcontext *ctx = &brw->intel.ctx; struct gl_client_array *vbo_array = &brw->vb.vbo_array[i]; GLuint size = count * element_size; struct gl_buffer_object *vbo; GLuint offset; GLuint new_stride; get_space(brw, size, &vbo, &offset); if (array->StrideB == 0) { assert(count == 1); new_stride = 0; } else new_stride = element_size; vbo_array->Size = array->Size; vbo_array->Type = array->Type; vbo_array->Stride = new_stride; vbo_array->StrideB = new_stride; vbo_array->Ptr = (const void *)offset; vbo_array->Enabled = 1; vbo_array->Normalized = array->Normalized; vbo_array->_MaxElement = array->_MaxElement; /* ? */ vbo_array->BufferObj = vbo; { GLubyte *map = ctx->Driver.MapBuffer(ctx, GL_ARRAY_BUFFER_ARB, GL_DYNAMIC_DRAW_ARB, vbo); map += offset; copy_strided_array( map, array->Ptr, element_size, array->StrideB, count); ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, vbo_array->BufferObj); } return vbo_array; }
NcValues* NcAtt::values( void ) const { NcValues* valp = get_space(); int status; switch (type()) { case ncFloat: status = NcError::set_err( nc_get_att_float(the_file->id(), the_variable->id(), the_name, (float *)valp->base()) ); break; case ncDouble: status = NcError::set_err( nc_get_att_double(the_file->id(), the_variable->id(), the_name, (double *)valp->base()) ); break; case ncInt: status = NcError::set_err( nc_get_att_int(the_file->id(), the_variable->id(), the_name, (int *)valp->base()) ); break; case ncShort: status = NcError::set_err( nc_get_att_short(the_file->id(), the_variable->id(), the_name, (short *)valp->base()) ); break; case ncByte: status = NcError::set_err( nc_get_att_schar(the_file->id(), the_variable->id(), the_name, (signed char *)valp->base()) ); break; case ncChar: status = NcError::set_err( nc_get_att_text(the_file->id(), the_variable->id(), the_name, (char *)valp->base()) ); break; case ncNoType: default: return 0; } if (status != NC_NOERR) { delete valp; return 0; } return valp; }
void *malloc(size_t size) { metadata_t *block; // TODO: align size? if (unlikely(size <= 0)) { return 0; } if (unlikely(!base)) { // first pthread_mutex_init(&list_lock, NULL); pthread_mutex_lock(&list_lock); block = get_space(0, size); if (unlikely(!block)) { pthread_mutex_unlock(&list_lock); return 0; } base = block; // pthread_mutex_unlock(&list_lock); } else { pthread_mutex_lock(&list_lock); metadata_t *last = base; block = get_free_block(&last, size); if (!block) { block = get_space(last, size); if (unlikely(!block)) { pthread_mutex_unlock(&list_lock); return 0; } } else { // TODO: split block->free = 0; block->magic1 = MAGIC_USED; block->magic2 = MAGIC_USED; } } alloc_count++; pthread_mutex_unlock(&list_lock); return (block+1); }
/* * Find the given name in the dictionary * and return its value. If the name was * not previously there, enter it now and * return a null value. */ struct var *lookup(const char *n) { static struct var dummy; struct var *vp; const char *cp; char *xp; /* var 'n' in vlist ? */ for (vp = vlist; vp; vp = vp->next) { if (eqname(vp->name, n)) { return vp; } } /* A new var, Add it */ cp = findeq(n); vp = get_space(sizeof(*vp)); if (vp == 0 || (vp->name = get_space((int) (cp - n) + 2)) == NULL) { dummy.name = dummy.value = (char*)""; return &dummy; } xp = vp->name; while ((*xp = *n++) != '\0' && *xp != '=') xp++; *xp++ = '='; *xp = '\0';; setarea((char *) vp, 0); setarea((char *) vp->name, 0); vp->value = null; vp->next = vlist; vp->status = GETCELL; vlist = vp; return vp; }
void show_board(Board* board) { reset_screen(); int size = get_size(board); int factor = get_factor(board); for(int i = 0; i < size; i++) { display_space(get_space(board, i), i); if (is_row_transition(i, factor, size)) { display_row_transition(factor); } if (is_cell_transition(i, factor)) { write_out(cell_transition_message); } } write_out(end_board_message); }
const char * put_string(struct ring_buff *rb, const char *str) { if (!str) return NULL; while (0 < get_space(rb) && *str) { *rb->head = *str; rb->head += 1; if (0 == get_end_dist(rb, rb->head)) rb->head = rb->buf; ++str; } return *str ? str : NULL; }
static GLboolean *_tnl_import_edgeflag( struct gl_context *ctx, const GLvector4f *input, GLuint count) { const GLubyte *ptr = (const GLubyte *)input->data; const GLuint stride = input->stride; GLboolean *space = (GLboolean *)get_space(ctx, count + CLIPVERTS); GLboolean *bptr = space; GLuint i; for (i = 0; i < count; i++) { *bptr++ = ((GLfloat *)ptr)[0] == 1.0; ptr += stride; } return space; }
void* _malloc(size_t size, malloc_data * md) { if (size <= 0) return NULL; size += sizeof(allocated_node); // we need to store our info there, too if (size % 4 != 0) size += 4 - (size % 4); assert(size % 4 == 0); // the pointer must be 4-byte aligned size = MAX(size, sizeof(free_node)); free_node* node = find_fit(size,md); if (!node) { md->db("No available space found for size %d. Getting more memory from the kernel", size); get_space(md->size / PAGE_SIZE, md); // get as much new as we had before. // try again node = find_fit(size, md); // it failed again, give up if (!node) { md->db("No available space _again_. Giving up"); exit(); return NULL; } } void* p = allocate_free_space(node, size,md); // md->db("Alloc of %d at %p", size, p); // Mem_Dump(md); assert(p); return p; }