void lowlevel_devinfo_semicpy(struct lowlevel_device_info * const dst, const struct lowlevel_device_info * const src) { #define COPYSTR(key) BFGINIT(dst->key, maybe_strdup(src->key)) COPYSTR(manufacturer); COPYSTR(product); COPYSTR(serial); COPYSTR(path); COPYSTR(devid); BFGINIT(dst->vid, src->vid); BFGINIT(dst->pid, src->pid); }
/* * _gr_copy * Copy the contents of fromgrp to grp; memory for strings * and arrays will be allocated from buf (of size buflen). * Returns 1 if copied successfully, 0 on copy failure. * NOTE: fromgrp must not use buf for its own pointers. */ static int _gr_copy(struct group *fromgrp, struct group *grp, char *buf, size_t buflen) { char *ep; int memc; _DIAGASSERT(fromgrp != NULL); _DIAGASSERT(grp != NULL); _DIAGASSERT(buf != NULL); #define COPYSTR(to, from) \ do { \ size_t count = strlen((from)); \ (to) = _gr_memfrombuf(count+1, &buf, &buflen); \ if ((to) == NULL) \ return 0; \ memmove((to), (from), count); \ to[count] = '\0'; \ } while (0) /* LINTED */ COPYSTR(grp->gr_name, fromgrp->gr_name); COPYSTR(grp->gr_passwd, fromgrp->gr_passwd); grp->gr_gid = fromgrp->gr_gid; if (fromgrp->gr_mem == NULL) return 0; for (memc = 0; fromgrp->gr_mem[memc]; memc++) continue; memc++; /* for final NULL */ /* grab ALIGNed char **gr_mem from buf */ ep = _gr_memfrombuf(memc * sizeof(char *) + ALIGNBYTES, &buf, &buflen); grp->gr_mem = (char **)ALIGN(ep); if (grp->gr_mem == NULL) return 0; for (memc = 0; fromgrp->gr_mem[memc]; memc++) { COPYSTR(grp->gr_mem[memc], fromgrp->gr_mem[memc]); } #undef COPYSTR grp->gr_mem[memc] = NULL; return 1; }
int main(int argc, char** argv) { Uint noofvecs, i; Sint optindex, c; vector_t info; #ifdef MEMMAN_H Spacetable spacetab; #endif void *space = NULL; char *url = NULL; char *outpath = NULL; char *pveclistfile = NULL; char *alphabetfile = NULL; char *vecext="vec"; char *seqext="seq"; struct prob_vec *p_vec; IntSequence *sequence; FAlphabet *alphabet; stringset_t *tok; stringset_t **fn; #ifdef MEMMAN_H initmemoryblocks(&spacetab, 1000); space = &spacetab; #endif while(1) { c=getopt_long(argc, argv, "f:a:o:", long_options, &optindex); if (c==-1) break; switch(c) { case 'f': pveclistfile = optarg; break; case 'a': alphabetfile = optarg; break; case 'o': outpath = optarg; break; default: usage(argv[0]); exit (EXIT_FAILURE); } } if (pveclistfile==NULL || alphabetfile == NULL) { usage(argv[0]); exit (EXIT_FAILURE); } fn=readcsv(space, pveclistfile, ".", &noofvecs); alphabet = loadCSValphabet(space, alphabetfile); sortMapdomain(space, alphabet); for(i=0; i<noofvecs; i++) { INITVECTOR(&info); SETSTR(fn[i],0) = concatdelim(space, SETSTR(fn[i],0), vecext, SETSTRLEN(fn[i],0), 3, '.'); p_vec = prob_vec_read (SETSTR(fn[i],0)); if (p_vec->mship == NULL) prob_vec_expand(p_vec); sequence = encode_prob_vec(space, alphabet, p_vec, 0, 0, cantorchar, &info); sequence->info = (Uint*) info.elements; sequence->namelen= strlen(alphabetfile); COPYSTR(space, sequence->alphabetname, alphabetfile, strlen(alphabetfile)); /*this is a potential security risk*/ if (p_vec->compnd_len > 0) { sequence->descrlen = p_vec->compnd_len-1; COPYSTR(space, sequence->description, p_vec->compnd, p_vec->compnd_len-1); } else { sequence->descrlen = 14; COPYSTR(space, sequence->description, "descriptor n/a", 14); } sequence->urllen = SETSTRLEN(fn[i],0); COPYSTR(space, sequence->url, SETSTR(fn[i],0), SETSTRLEN(fn[i],0)); SETSTR(fn[i],0) = concatdelim(space, SETSTR(fn[i],0), seqext, SETSTRLEN(fn[i],0), 3, '.'); SETSTRLEN(fn[i],0) += 4; if (outpath) { tok = tokensToStringset(space, "/", SETSTR(fn[i],0), SETSTRLEN(fn[i],0)); COPYSTR(space, url, outpath, strlen(outpath)); url = concat(space, url, SETSTR(tok, tok->noofstrings-1), strlen(url), SETSTRLEN(tok, tok->noofstrings-1)); saveSequence(sequence, url); destructStringset(space, tok); FREEMEMORY(space, url); url = NULL; } else { saveSequence(sequence, SETSTR(fn[i],0)); } destructSequence (space, sequence); prob_vec_destroy (p_vec); destructStringset (space, fn[i]); progressBarVT("probability vectors converted", noofvecs-1, i, 25); } printf("\nexit.\n"); FREEMEMORY(space, fn); destructAlphabet(space, alphabet); return EXIT_SUCCESS; }
void findwedges(Wedge wedge[NO_COLOURS], choice rep, Hashindex *items, choice chartby, Strlist *expandlist, unsigned int level, Strlist *partname, unsigned long tot, double totb, double totb7) { /* Calculate which wedges we actually want, i.e. the ten with the biggest angles. But we also preserve the sort order of the "items" list. (Be careful between > and >= so as to use that order for breaking ties). Construction of name same as in printtree(). */ static double smallestangle; static int smallestwedge; char *name; double angle; Strlist *pn, s; size_t need = (size_t)level + 3; Hashindex *p; int i; if (level == 0) { /* not recursing: initialise wedges to 0 */ for (i = 0; i < NO_COLOURS; i++) { wedge[i].angle = 0.0; wedge[i].name = NULL; } smallestangle = 0.0; smallestwedge = NO_COLOURS - 1; } for (pn = partname; pn != NULL; TO_NEXT(pn)) need += strlen(pn->name); for (p = items; p != NULL; TO_NEXT(p)) { name = maketreename(partname, p, &pn, &s, need, rep, TRUE); if (incstrlist(name, expandlist) && p->other != NULL && ((Hashtable *)(p->other))->head[0] != NULL) /* then find wedges in lower level of tree instead. ->head[0] != NULL must come after p->other != NULL; o/wise it may not be a treerep */ findwedges(wedge, rep, ((Hashtable *)(p->other))->head[0], chartby, expandlist, level + 1, pn, tot, totb, totb7); else { if (chartby == BYTES) angle = p->own->bytes / totb; else if (chartby == BYTES7) angle = p->own->bytes7 / totb7; else angle = ((double)(p->own->data[chartby])) / ((double)tot); if (angle > smallestangle) {/* remove smallest, move along, put p last */ /* We probably don't do this very often so we don't bother with keeping hold of the memory and reusing it later. */ free(wedge[smallestwedge].name); for (i = smallestwedge; i < NO_COLOURS - 1; i++) { wedge[i].name = wedge[i + 1].name; wedge[i].angle = wedge[i + 1].angle; } COPYSTR(wedge[NO_COLOURS - 1].name, name); /* malloc's necessary space. Needed because next call to maketreename() will overwrite name. */ wedge[NO_COLOURS - 1].angle = angle; smallestangle = wedge[0].angle; /* Recalculate smallest */ smallestwedge = 0; for (i = 1; i < NO_COLOURS; i++) { if (wedge[i].angle <= smallestangle) { smallestangle = wedge[i].angle; smallestwedge = i; } } } } } }
static void mptable_dump(struct mp_floating_pointer *mpfp, struct mp_config_hdr *mpch) { static char str[16]; int i; char *cur; union mpe { struct mpe_proc *proc; struct mpe_bus *bus; struct mpe_ioapic *ioapic; struct mpe_ioint *ioint; struct mpe_lint *lnit; char *p; }; union mpe mpe; printf(" MP Floating Pointer :\n"); COPYSTR(str, mpfp->signature, 4); printf("\tsignature:\t%s\n", str); printf("\tmpch paddr:\t%x\n", mpfp->mptable_paddr); printf("\tlength:\t%x\n", mpfp->length); printf("\tspecrec:\t%x\n", mpfp->specrev); printf("\tchecksum:\t%x\n", mpfp->checksum); printf("\tfeature1:\t%x\n", mpfp->feature1); printf("\tfeature2:\t%x\n", mpfp->feature2); printf("\tfeature3:\t%x\n", mpfp->feature3); printf("\tfeature4:\t%x\n", mpfp->feature4); printf(" MP Configuration Header :\n"); COPYSTR(str, mpch->signature, 4); printf(" signature: %s\n", str); printf(" length: %x\n", mpch->length); printf(" specrec: %x\n", mpch->specrev); printf(" checksum: %x\n", mpch->checksum); COPYSTR(str, mpch->oemid, MPCH_OEMID_LEN); printf(" oemid: %s\n", str); COPYSTR(str, mpch->prodid, MPCH_PRODID_LEN); printf(" prodid: %s\n", str); printf(" oem_ptr: %x\n", mpch->oem_ptr); printf(" oem_sz: %x\n", mpch->oem_sz); printf(" nr_entries: %x\n", mpch->nr_entries); printf(" apic paddr: %x\n", mpch->lapic_paddr); printf(" ext_length: %x\n", mpch->ext_length); printf(" ext_checksum: %x\n", mpch->ext_checksum); cur = (char *)mpch + sizeof(*mpch); for (i = 0; i < mpch->nr_entries; i++) { mpe.p = cur; switch(*mpe.p) { case MP_ENTRY_PROC: printf(" MP Processor Entry :\n"); printf(" lapic_id: %x\n", mpe.proc->lapic_id); printf(" lapic_version: %x\n", mpe.proc->lapic_version); printf(" proc_flags: %x\n", mpe.proc->proc_flags); printf(" proc_signature: %x\n", mpe.proc->proc_signature); printf(" feature_flags: %x\n", mpe.proc->feature_flags); cur += sizeof(struct mpe_proc); break; case MP_ENTRY_BUS: printf(" MP Bus Entry :\n"); printf(" busid: %x\n", mpe.bus->busid); COPYSTR(str, mpe.bus->busname, MPE_BUSNAME_LEN); printf(" busname: %s\n", str); cur += sizeof(struct mpe_bus); break; case MP_ENTRY_IOAPIC: printf(" MP IOAPIC Entry :\n"); printf(" ioapi_id: %x\n", mpe.ioapic->ioapic_id); printf(" ioapi_version: %x\n", mpe.ioapic->ioapic_version); printf(" ioapi_flags: %x\n", mpe.ioapic->ioapic_flags); printf(" ioapi_paddr: %x\n", mpe.ioapic->ioapic_paddr); cur += sizeof(struct mpe_ioapic); break; case MP_ENTRY_IOINT: printf(" MP IO Interrupt Entry :\n"); printf(" intr_type: %x\n", mpe.ioint->intr_type); printf(" intr_flags: %x\n", mpe.ioint->intr_flags); printf(" src_bus_id: %x\n", mpe.ioint->src_bus_id); printf(" src_bus_irq: %x\n", mpe.ioint->src_bus_irq); printf(" dst_apic_id: %x\n", mpe.ioint->dst_apic_id); printf(" dst_apic_intin: %x\n", mpe.ioint->dst_apic_intin); cur += sizeof(struct mpe_ioint); break; case MP_ENTRY_LINT: printf(" MP Local Interrupt Entry :\n"); cur += sizeof(struct mpe_lint); break; } } }