// call with *e locked static store_page *_allocate_page(store_engine *e, unsigned int bucket, unsigned int free_bucket) { assert(!e->page_buckets[bucket] || e->page_buckets[bucket]->allocated == e->page_size); store_page *tmp = NULL; // if a specific free bucket was requested, check there first if (free_bucket != 0 && e->free_page_buckets[free_bucket] != NULL) { assert(e->page_free > 0); tmp = e->free_page_buckets[free_bucket]; e->free_page_buckets[free_bucket] = tmp->next; } // failing that, try the global list. if (tmp == NULL && e->page_freelist != NULL) { tmp = e->page_freelist; e->page_freelist = tmp->next; } E_DEBUG("EXTSTORE: allocating new page\n"); // page_freelist can be empty if the only free pages are specialized and // we didn't just request one. if (e->page_free > 0 && tmp != NULL) { tmp->next = e->page_buckets[bucket]; e->page_buckets[bucket] = tmp; tmp->active = true; tmp->free = false; tmp->closed = false; tmp->version = _next_version(e); tmp->bucket = bucket; e->page_free--; STAT_INCR(e, page_allocs, 1); } else { extstore_run_maint(e); } if (tmp) E_DEBUG("EXTSTORE: got page %u\n", tmp->id); return tmp; }
int main(int argc, char *argv[]) { logmath_t *lmath; cmd_ln_t *config; acmod_t *acmod; ps_mgau_t *ps; ptm_mgau_t *s; int i, lastcb; lmath = logmath_init(1.0001, 0, 0); config = cmd_ln_init(NULL, ps_args(), TRUE, "-compallsen", "yes", "-input_endian", "little", NULL); cmd_ln_parse_file_r(config, ps_args(), MODELDIR "/en-us/en-us/feat.params", FALSE); cmd_ln_set_str_extra_r(config, "_mdef", MODELDIR "/en-us/en-us/mdef"); cmd_ln_set_str_extra_r(config, "_mean", MODELDIR "/en-us/en-us/means"); cmd_ln_set_str_extra_r(config, "_var", MODELDIR "/en-us/en-us/variances"); cmd_ln_set_str_extra_r(config, "_tmat", MODELDIR "/en-us/en-us/transition_matrices"); cmd_ln_set_str_extra_r(config, "_sendump", MODELDIR "/en-us/en-us/sendump"); cmd_ln_set_str_extra_r(config, "_mixw", NULL); cmd_ln_set_str_extra_r(config, "_lda", NULL); cmd_ln_set_str_extra_r(config, "_senmgau", NULL); err_set_debug_level(3); TEST_ASSERT(config); TEST_ASSERT((acmod = acmod_init(config, lmath, NULL, NULL))); TEST_ASSERT((ps = acmod->mgau)); TEST_EQUAL(0, strcmp(ps->vt->name, "ptm")); s = (ptm_mgau_t *)ps; E_DEBUG(2,("PTM model loaded: %d codebooks, %d senones, %d frames of history\n", s->g->n_mgau, s->n_sen, s->n_fast_hist)); E_DEBUG(2,("Senone to codebook mappings:\n")); lastcb = s->sen2cb[0]; E_DEBUG(2,("\t%d: 0", lastcb)); for (i = 0; i < s->n_sen; ++i) { if (s->sen2cb[i] != lastcb) { lastcb = s->sen2cb[i]; E_DEBUGCONT(2,("-%d\n", i-1)); E_DEBUGCONT(2,("\t%d: %d", lastcb, i)); } } E_INFOCONT("-%d\n", i-1); run_acmod_test(acmod); #if 0 /* Replace it with ms_mgau. */ ptm_mgau_free(ps); cmd_ln_set_str_r(config, "-mixw", MODELDIR "/en-us/en-us/mixture_weights"); TEST_ASSERT((acmod->mgau = ms_mgau_init(acmod, lmath, acmod->mdef))); run_acmod_test(acmod); cmd_ln_free_r(config); #endif return 0; }
int fsg_model_add_alt(fsg_model_t * fsg, char const *baseword, char const *altword) { int i, basewid, altwid; int ntrans; /* FIXME: This will get slow, eventually... */ for (basewid = 0; basewid < fsg->n_word; ++basewid) if (0 == strcmp(fsg->vocab[basewid], baseword)) break; if (basewid == fsg->n_word) { E_ERROR("Base word %s not present in FSG vocabulary!\n", baseword); return -1; } altwid = fsg_model_word_add(fsg, altword); if (fsg->altwords == NULL) fsg->altwords = bitvec_alloc(fsg->n_word_alloc); bitvec_set(fsg->altwords, altwid); E_DEBUG(2,("Adding alternate word transitions (%s,%s) to FSG\n", baseword, altword)); /* Look for all transitions involving baseword and duplicate them. */ /* FIXME: This will also get slow, eventually... */ ntrans = 0; for (i = 0; i < fsg->n_state; ++i) { hash_iter_t *itor; if (fsg->trans[i].trans == NULL) continue; for (itor = hash_table_iter(fsg->trans[i].trans); itor; itor = hash_table_iter_next(itor)) { glist_t trans; gnode_t *gn; trans = hash_entry_val(itor->ent); for (gn = trans; gn; gn = gnode_next(gn)) { fsg_link_t *fl = gnode_ptr(gn); if (fl->wid == basewid) { fsg_link_t *link; /* Create transition object */ link = listelem_malloc(fsg->link_alloc); link->from_state = fl->from_state; link->to_state = fl->to_state; link->logs2prob = fl->logs2prob; /* FIXME!!!??? */ link->wid = altwid; trans = glist_add_ptr(trans, (void *) link); ++ntrans; } } hash_entry_val(itor->ent) = trans; } } E_DEBUG(2,("Added %d alternate word transitions\n", ntrans)); return ntrans; }
int ee_do_command( u8 *Tx, int Tx_len, u8 *Rx, int Rx_len, int Send_skip ){ /* Execute this command string, including giving reset and setting to idle after command if Rx_len is set, we read out data from EEPROM */ int i; E_DEBUG("Command, Tx_len %d, Rx_len %d\n", Tx_len, Rx_len ); if(do_reset()){ /* Failed! */ return(-EIO); } if(Send_skip) /* Always send SKIP_ROM first to tell chip we are sending a command, except when we read out rom data for chip */ write_byte(SKIP_ROM); /* Always have Tx data */ for(i=0;i<Tx_len;i++){ write_byte(Tx[i]); } if(Rx_len){ for(i=0;i<Rx_len;i++){ Rx[i]=read_byte(); } } set_idle(); E_DEBUG("Command done\n"); return(0); }
void Algorithm::shouldStop(bool stop) { #if DEBUGGING_ENABLED std::ostringstream msg; msg << "Streaming: " << name() << "::shouldStop[" << nProcess << "] = " << (stop ? "true" : "false"); E_DEBUG(EAlgorithm, msg.str()); #else E_DEBUG(EAlgorithm, "Streaming: " << name() << "::shouldStop = " << (stop?"true":"false")); #endif _shouldStop = stop; }
static u8 read_byte(void){ /* Read a single byte from EEPROM Read LSb first */ int i; int Value; u8 Result=0; #ifndef CONFIG_SYS_IMMR u32 Flags; #endif E_DEBUG("Reading byte\n"); for(i=0;i<8;i++){ /* Small delay between pulses */ udelay(1); #ifndef CONFIG_SYS_IMMR /* Disable irq */ save_flags(Flags); cli(); #endif /* Pull down pin short time to start read See page 26 in data sheet */ WRITE_PORT(0); udelay(READ_LOW); WRITE_PORT(1); /* Wait for chip to drive pin */ udelay(READ_TIMEOUT); Value = READ_PORT; if(Value) Value=1; #ifndef CONFIG_SYS_IMMR /* Enable irq */ restore_flags(Flags); #endif /* Wait for chip to release pin */ udelay(TOTAL_READ_LOW-READ_TIMEOUT); /* LSb first */ Result|=Value<<i; } E_DEBUG("Read byte 0x%x\n",Result); return(Result); }
void SinkBase::detachProxy(SinkProxyBase* sproxy) { // TODO: verify me if (sproxy != _sproxy) { E_WARNING("Cannot detach " << fullName() << " from SinkProxy " << sproxy->fullName() << " as they are not attached"); return; } E_DEBUG(EConnectors, " SinkBase::detachProxy: " << fullName() << "::_sproxy = 0"); _sproxy = 0; E_DEBUG(EConnectors, " SinkBase::detachProxy: " << fullName() << "::_source = 0"); setSource(0); // also set source to 0 because the proxy set it for us when we attached, but now we're all alone }
/** * Initialize Essentia and fill the AlgorithmFactories with the Algorithms. */ void init() { setDebugLevel(EUser1 | EUser2); E_DEBUG(EFactory, "essentia::init()"); standard::AlgorithmFactory::init(); standard::registerAlgorithm(); streaming::AlgorithmFactory::init(); streaming::registerAlgorithm(); TypeMap::init(); _initialized = true; E_DEBUG(EFactory, "essentia::init() ok!"); }
static int state_align_search_finish(ps_search_t *search) { state_align_search_t *sas = (state_align_search_t *)search; hmm_t *final_phone = sas->hmms + sas->n_phones - 1; ps_alignment_iter_t *itor; ps_alignment_entry_t *ent; int last_frame, cur_frame; state_align_hist_t last, cur; /* Best state exiting the last cur_frame. */ last.id = cur.id = hmm_out_history(final_phone); last.score = hmm_out_score(final_phone); if (last.score == 0xffff) { E_ERROR("Failed to reach final state in alignment\n"); return -1; } itor = ps_alignment_states(sas->al); last_frame = sas->frame + 1; for (cur_frame = sas->frame - 1; cur_frame >= 0; --cur_frame) { cur = sas->tokens[cur_frame * sas->n_emit_state + cur.id]; /* State boundary, update alignment entry for next state. */ if (cur.id != last.id) { itor = ps_alignment_iter_goto(itor, last.id); assert(itor != NULL); ent = ps_alignment_iter_get(itor); ent->start = cur_frame + 1; ent->duration = last_frame - ent->start; ent->score = last.score - cur.score; E_DEBUG(1,("state %d start %d end %d\n", last.id, ent->start, last_frame)); last = cur; last_frame = cur_frame + 1; } } /* Update alignment entry for initial state. */ itor = ps_alignment_iter_goto(itor, 0); assert(itor != NULL); ent = ps_alignment_iter_get(itor); ent->start = 0; ent->duration = last_frame; E_DEBUG(1,("state %d start %d end %d\n", 0, ent->start, last_frame)); ps_alignment_iter_free(itor); ps_alignment_propagate(sas->al); return 0; }
int acmod_read_scores(acmod_t *acmod) { int inptr, rv; if (acmod->grow_feat) { /* Grow to avoid wraparound if grow_feat == TRUE. */ inptr = acmod->feat_outidx + acmod->n_feat_frame; /* Has to be +1, otherwise, next time acmod_advance() is * called, this will wrap around. */ while (inptr + 1 >= acmod->n_feat_alloc) acmod_grow_feat_buf(acmod, acmod->n_feat_alloc * 2); } else { inptr = (acmod->feat_outidx + acmod->n_feat_frame) % acmod->n_feat_alloc; } if ((rv = acmod_read_scores_internal(acmod)) != 1) return rv; /* Set acmod->senscr_frame appropriately so that these scores get reused below in acmod_score(). */ acmod->senscr_frame = acmod->output_frame + acmod->n_feat_frame; E_DEBUG(1,("Frame %d has %d active states\n", acmod->senscr_frame, acmod->n_senone_active)); /* Increment the "feature frame counter" and record the file * position for the relevant frame in the (possibly circular) * buffer. */ ++acmod->n_feat_frame; acmod->framepos[inptr] = ftell(acmod->insenfh); return 1; }
void SinkBase::attachProxy(SinkProxyBase* sproxy) { checkSameTypeAs(*sproxy); if (_source) throw EssentiaException("You cannot attach a SinkProxy to a Sink which is already connected: ", fullName(), " is already connected to ", _source->fullName()); if (_sproxy) throw EssentiaException("You cannot attach a SinkProxy to a Sink which is already attached to a SinkProxy: ", fullName(), " is attached to proxy ", _sproxy->fullName()); E_DEBUG(EConnectors, " SinkBase::attachProxy: " << fullName() << "::_sproxy = " << sproxy->fullName()); _sproxy = sproxy; E_DEBUG(EConnectors, " SinkBase::attachProxy: " << sproxy->fullName() << "::updateProxiedSink()"); _sproxy->updateProxiedSink(); }
void Algorithm::reset() { E_DEBUG(EAlgorithm, "Streaming: " << name() << "::reset()"); shouldStop(false); // reset the buffers of the sources of this algorithm for (OutputMap::iterator it = _outputs.begin(); it != _outputs.end(); ++it) { E_DEBUG(EAlgorithm, "resetting buffer for " << it->second->fullName()); it->second->reset(); } // Note: we don't need to reset the inputs because they share a Multi-rate // buffer with the outputs E_DEBUG(EAlgorithm, "Streaming: " << name() << "::reset() ok!"); }
void DesktopIcon::load_icon(int face) { const char* ic = NULL; if(face != ICON_FACE_TWO) { if(!settings->icon.empty()) ic = settings->icon.c_str(); } else { if(!settings->icon2.empty()) ic = settings->icon2.c_str(); } if(!ic) return; if(!IconLoader::set(this, ic, ICON_SIZE_HUGE)) { E_DEBUG(E_STRLOC ": Unable to load %s icon\n", ic); return; } /* fetch image object for sizes */ Fl_Image* img = image(); int img_w = img->w(); int img_h = img->h(); /* resize box if icon is larger */ if(img_w > ICON_SIZE_MIN_W || img_h > ICON_SIZE_MIN_H) size(img_w + OFFSET_W, img_h + OFFSET_H); /* darker icon version for selection */ delete darker_img; darker_img = img->copy(img->w(), img->h()); darker_img->color_average(FL_BLUE, 0.6); }
static void load_theme_cb(Fl_Widget*, void*) { E_RETURN_IF_FAIL(ThemeLoader::global()->load_with_path("theme-sample")); char buf[128]; if(ThemeLoader::global()->theme()->get_item("ede", "sample", buf, sizeof(buf))) E_DEBUG(E_STRLOC ": evaluated => %s\n", buf); }
static void populate_lrdiph(dict2pid_t *d2p, s3ssid_t ***rdiph_rc, s3cipid_t b) { bin_mdef_t *mdef = d2p->mdef; s3cipid_t l, r; for (l = 0; l < bin_mdef_n_ciphone(mdef); l++) { for (r = 0; r < bin_mdef_n_ciphone(mdef); r++) { s3pid_t p; p = bin_mdef_phone_id_nearest(mdef, (s3cipid_t) b, (s3cipid_t) l, (s3cipid_t) r, WORD_POSN_SINGLE); d2p->lrdiph_rc[b][l][r] = bin_mdef_pid2ssid(mdef, p); if (r == bin_mdef_silphone(mdef)) d2p->ldiph_lc[b][r][l] = bin_mdef_pid2ssid(mdef, p); if (rdiph_rc && l == bin_mdef_silphone(mdef)) rdiph_rc[b][l][r] = bin_mdef_pid2ssid(mdef, p); assert(IS_S3SSID(bin_mdef_pid2ssid(mdef, p))); E_DEBUG(2,("%s(%s,%s) => %d / %d\n", bin_mdef_ciphone_str(mdef, b), bin_mdef_ciphone_str(mdef, l), bin_mdef_ciphone_str(mdef, r), p, bin_mdef_pid2ssid(mdef, p))); } } }
Desktop::~Desktop() { E_DEBUG("Desktop::~Desktop()\n"); delete conf; delete icon_opts; delete selbox; }
DesktopIcon::~DesktopIcon() { E_DEBUG("DesktopIcon::~DesktopIcon()\n"); delete settings; delete micon; delete darker_img; delete imenu; }
int16 const * acmod_score(acmod_t *acmod, int *inout_frame_idx) { int frame_idx, feat_idx; /* Calculate the absolute frame index to be scored. */ frame_idx = calc_frame_idx(acmod, inout_frame_idx); /* If all senones are being computed, or we are using a senone file, then we can reuse existing scores. */ if ((acmod->compallsen || acmod->insenfh) && frame_idx == acmod->senscr_frame) { if (inout_frame_idx) *inout_frame_idx = frame_idx; return acmod->senone_scores; } /* Calculate position of requested frame in circular buffer. */ if ((feat_idx = calc_feat_idx(acmod, frame_idx)) < 0) return NULL; /* If there is an input senone file locate the appropriate frame and read it. */ if (acmod->insenfh) { fseek(acmod->insenfh, acmod->framepos[feat_idx], SEEK_SET); if (acmod_read_scores_internal(acmod) < 0) return NULL; } else { /* Build active senone list. */ acmod_flags2list(acmod); /* Generate scores for the next available frame */ ps_mgau_frame_eval(acmod->mgau, acmod->senone_scores, acmod->senone_active, acmod->n_senone_active, acmod->feat_buf[feat_idx], frame_idx, acmod->compallsen); } if (inout_frame_idx) *inout_frame_idx = frame_idx; acmod->senscr_frame = frame_idx; /* Dump scores to the senone dump file if one exists. */ if (acmod->senfh) { if (acmod_write_scores(acmod, acmod->n_senone_active, acmod->senone_active, acmod->senone_scores, acmod->senfh) < 0) return NULL; E_DEBUG(1,("Frame %d has %d active states\n", frame_idx, acmod->n_senone_active)); } return acmod->senone_scores; }
// NB: do not do anything if we're not actually connected to the given source void SinkBase::disconnect(SourceBase& source) { if (_source != &source) { E_WARNING("Cannot disconnect " << this->fullName() << " from " << source.fullName() << " as they are not connected"); return; } E_DEBUG(EConnectors, " SinkBase::disconnect: " << fullName() << "::_source = 0"); setSource(0); }
PtyProcess::~PtyProcess() { E_DEBUG(E_STRLOC " : killing pid %d\n",m_Pid); if(m_Pid) kill(m_Pid, SIGSTOP); // Terminate child process - Vedran if(m_TTY) free(m_TTY); if(m_Inbuf) free(m_Inbuf); delete m_pPTY; delete d; }
int DesktopIcon::handle(int event) { switch(event) { case FL_FOCUS: case FL_UNFOCUS: case FL_ENTER: case FL_LEAVE: return 1; /* We have to handle FL_MOVE too, if want to get only once FL_ENTER when entered or FL_LEAVE when leaved */ case FL_MOVE: return 1; case FL_PUSH: if(Fl::event_button() == 3) { /* MenuItem::popup() by default does not call callbacks */ const MenuItem* m = imenu->menu()->popup(Fl::event_x(), Fl::event_y()); if(m && m->callback()) m->do_callback(0, this); } return 1; case FL_RELEASE: if(Fl::event_clicks() > 0) run_async("ede-launch %s", settings->cmd.c_str()); return 1; case FL_DND_ENTER: case FL_DND_DRAG: case FL_DND_LEAVE: return 1; case FL_DND_RELEASE: E_DEBUG(E_STRLOC ": FL_DND_RELEASE on icon\n"); return 1; case FL_PASTE: E_DEBUG(E_STRLOC ": FL_PASTE on icon with %s\n", Fl::event_text()); return 1; default: break; } return 0; }
int32 acmod_flags2list(acmod_t *acmod) { int32 w, l, n, b, total_dists, total_words, extra_bits; bitvec_t *flagptr; total_dists = bin_mdef_n_sen(acmod->mdef); if (acmod->compallsen) { acmod->n_senone_active = total_dists; return total_dists; } total_words = total_dists / BITVEC_BITS; extra_bits = total_dists % BITVEC_BITS; w = n = l = 0; for (flagptr = acmod->senone_active_vec; w < total_words; ++w, ++flagptr) { if (*flagptr == 0) continue; for (b = 0; b < BITVEC_BITS; ++b) { if (*flagptr & (1UL << b)) { int32 sen = w * BITVEC_BITS + b; int32 delta = sen - l; /* Handle excessive deltas "lossily" by adding a few extra senones to bridge the gap. */ while (delta > 255) { acmod->senone_active[n++] = 255; delta -= 255; } acmod->senone_active[n++] = delta; l = sen; } } } for (b = 0; b < extra_bits; ++b) { if (*flagptr & (1UL << b)) { int32 sen = w * BITVEC_BITS + b; int32 delta = sen - l; /* Handle excessive deltas "lossily" by adding a few extra senones to bridge the gap. */ while (delta > 255) { acmod->senone_active[n++] = 255; delta -= 255; } acmod->senone_active[n++] = delta; l = sen; } } acmod->n_senone_active = n; E_DEBUG(1, ("acmod_flags2list: %d active in frame %d\n", acmod->n_senone_active, acmod->output_frame)); return n; }
/* * Fork and execute the command. This returns in the parent. */ int PtyProcess::exec(const char *command, const char **args) { E_DEBUG(E_STRLOC ": running '%s'\n", command); if(init() < 0) return -1; // Open the pty slave before forking. See SetupTTY() E_DEBUG(E_STRLOC ": pty: %s\n", m_TTY); int slave = open(m_TTY, O_RDWR); if(slave < 0) { E_WARNING(E_STRLOC ": could not open slave pty.\n"); return -1; } errno = 0; if((m_Pid = fork()) == -1) { E_WARNING(E_STRLOC ": fork failed with '%s'\n", strerror(errno)); return -1; } // Parent if(m_Pid) { close(slave); return 0; } // Child if(setup_tty(slave) < 0) _exit(1); if (d->env) { for(int i = 0; d->env[i]; i++) putenv(d->env[i]); } execv(command, (char**)args); _exit(1); return -1; /* never reached */ }
void Desktop::update_workarea(void) { int X, Y, W, H; if(!netwm_workarea_get_size(X, Y, W, H)) Fl::screen_xywh(X, Y, W, H); E_DEBUG(E_STRLOC ": resizing to %i %i %i %i\n", X, Y, W, H); resize(X, Y, W, H); /* also resize wallpaper if given */ if(wallpaper && wallpaper->visible()) wallpaper->resize(0, 0, w(), h()); }
static int do_reset(void){ /* Release reset and verify that chip responds with presence pulse */ int Retries = 0; while(Retries<5){ udelay(RESET_LOW_TIME); /* Send reset */ WRITE_PORT(0); udelay(RESET_LOW_TIME); /* Release reset */ WRITE_PORT(1); /* Wait for EEPROM to drive output */ udelay(PRESENCE_TIMEOUT); if(!READ_PORT){ /* Ok, EEPROM is driving a 0 */ E_DEBUG("Presence detected\n"); if(Retries){ E_DEBUG("Retries %d\n",Retries); } /* Make sure chip releases pin */ udelay(PRESENCE_LOW_TIME); return 0; } Retries++; } printk(KERN_ERR"EEPROM did not respond when releasing reset\n"); /* Make sure chip releases pin */ udelay(PRESENCE_LOW_TIME); /* Set to idle again */ set_idle(); return(-EIO); }
static bool icon_theme_load_once(const char* theme) { if(seen_theme && strcmp(seen_theme, theme) == 0) return false; seen_theme = strdup(theme); E_DEBUG(E_STRLOC ": loading '%s' theme\n", theme); if(IconLoader::inited()) IconLoader::reload(theme); else IconLoader::init(theme); return true; }
void SinkBase::connect(SourceBase& source) { checkSameTypeAs(source); if (_source) throw EssentiaException("You cannot connect more than one Source to a Sink: ", fullName(), " is already connected to ", _source->fullName()); if (_sproxy) throw EssentiaException("You cannot connect a Source to a Sink which is already attached to a SinkProxy: ", fullName(), " is connected to proxy ", _sproxy->fullName()); E_DEBUG(EConnectors, " SinkBase::connect: " << fullName() << "::_source = " << source.fullName()); _source = &source; }
DesktopIcon *Desktop::read_desktop_file(const char *path, const char *base, DesktopConfig *pos) { DesktopIcon *ret = NULL; if(file_test(path, FILE_TEST_IS_DIR)) { ret = new DesktopIcon(_("No Name")); ret->set_icon_type(DESKTOP_ICON_TYPE_FOLDER); /* hardcoded */ ret->set_image("folder"); /* copy label explicitly, as DesktopIcon() will only store a pointer */ ret->copy_label(base); } else { /* * try to load it as plain .desktop file by looking only at extension * TODO: MimeType can be used here too */ if(!str_ends(path, EDE_DESKTOP_DESKTOP_EXT)) return ret; DesktopFile df; char buf[PATH_MAX]; E_RETURN_VAL_IF_FAIL(df.load(path), ret); E_RETURN_VAL_IF_FAIL(df.type() != DESK_FILE_TYPE_UNKNOWN, ret); ret = new DesktopIcon(_("No Name")); ret->set_icon_type(DESKTOP_ICON_TYPE_NORMAL); if(df.name(buf, sizeof(buf))) ret->copy_label(buf); ret->set_image(df.icon(buf, sizeof(buf)) ? buf : NULL); if(df.comment(buf, sizeof(buf))) ret->set_tooltip(buf); } /* try to put random icon position in the middle of the desktop, so it is easier to notice */ int X = (rand() % (w() / 4)) + (w() / 4); int Y = (rand() % (h() / 4)) + (h() / 4); /* lookup icons locations if possible */ if(base && pos && *pos) { pos->get(base, "X", X, X); pos->get(base, "Y", Y, Y); } E_DEBUG("Setting icon '%s' (%i,%i)\n", base, X, Y); ret->position(X, Y); /* use loaded icon options */ ret->set_options(icon_opts); ret->set_path(path); return ret; }
void * gq_append(gq_t *q, void const *ent) { void *dest; if (q->count == gq_alloc_size(q)) gq_expand(q); ++q->count; E_DEBUG(2,("tail %d count %d size %d\n", gq_index(q, q->head + q->count - 1), q->count, gq_alloc_size(q))); dest = gq_tail_ptr(q); memcpy(dest, ent, garray_ent_size(&q->base)); return dest; }
const String& MimeType::comment(void) { // calling without mime loaded do nothing if(!(status & MIME_LOADED)) return mcmt; if(status & COMMENT_LOADED) return mcmt; String ttype = mtype; ttype += ".xml"; const char* p = xdg_mime_find_data(ttype.c_str()); if(!p) return mcmt; String path = p; TiXmlDocument doc(path.c_str()); if(!doc.LoadFile()) { E_DEBUG(E_STRLOC ": MimeType::comment() %s malformed\n", path.c_str()); return mcmt; } TiXmlNode* el = doc.FirstChild("mime-type"); /* * First element which does not have "xml:lang" attribute * is default one. So hunt that one :) * * Btw. TinyXML does not handle XML namespaces and will return * "<namespace>:<attribute>" value. This is not big deal as long * as correctly fetch attribute values. */ for(el = el->FirstChildElement(); el; el = el->NextSibling()) { if(strncmp(el->Value(), "comment", 7) == 0) { // TODO: add locale here if(!el->ToElement()->Attribute("xml:lang")) { TiXmlText* data = el->FirstChild()->ToText(); if(data) { mcmt = data->Value(); break; } } } } status |= COMMENT_LOADED; return mcmt; }