inline void BigInt::allocate(unsigned digits) { size = adjust_size(digits); length = 0; digit = new onedig_t[size]; }
void Track::sequence ( Audio_Sequence * t ) { if ( sequence() == t ) { DMESSAGE( "Attempt to set sequence twice" ); return; } t->track( this ); if ( sequence() ) add( sequence() ); _sequence = t; /* insert following the annotation pack */ pack->insert( *t, 1 ); /* hide the take header */ t->child(0)->hide(); t->color( FL_GRAY ); t->labeltype( FL_NO_LABEL ); adjust_size(); }
void Gui::get_pos(int *x, int *y, char const map, int const i) const { if (map != ' ') adjust_size(x, y, i); else *x = -42; }
void* malloc(size_t size) { block_t* block; if(size <= 0) return NULL; unsigned char index; size = adjust_size(size, &index); if(index > K_VALUE) return NULL; if(!global_memory){ /*first time*/ global_memory = sbrk(1<<K_VALUE); if(global_memory == (void*)-1) return NULL; block = global_memory; block->reserved = 0; block->kval = K_VALUE; block->succ = NULL; block->pred = NULL; free_list[K_VALUE] = block; } block = reserve_first(index); if(block) return (block + 1); unsigned char new_index = index; while(!free_list[new_index] ){ ++new_index; if(new_index > K_VALUE) return NULL; } while(new_index > index){ block = remove_first(new_index); block->reserved = 0; block->succ = NULL; block->pred = NULL; block_t* new_block = split_block(block); --new_index; block->succ = new_block; new_block->pred = block; free_list[new_index] = block; } block = reserve_first(index); return (block+1); }
static int simple_truncate(const char *path, off_t offset) { struct directory_entry *p; if ( (p = search_file(path)) == 0 ) { return -ENOENT; } if ( offset < 0 ) { return -ENOENT; } if ( adjust_size(p->file, offset) < 0 ) { return -ENOENT; } return 0; }
void Track::size ( int v ) { if ( v < 0 || v > 3 ) return; _size = v; adjust_size(); }
void Track::remove ( Control_Sequence *t ) { if ( ! control ) return; control->remove( t ); adjust_size(); }
void Track::remove ( Annotation_Sequence *t ) { if ( ! annotation ) return; annotation->remove( t ); adjust_size(); }
inline void BigInt::reallocate(unsigned digits) { if (digits > size) { if (size) delete[] digit; size = adjust_size(digits); digit = new onedig_t[size]; } }
void Track::add ( Annotation_Sequence *t ) { DMESSAGE( "adding annotation sequence" ); t->track( this ); annotation->add( t ); adjust_size(); }
int main(int argc, char *argv[]) { if (argc < 3) { usage(argv); exit(1); } struct mmap_info binary; strncpy(binary.name, argv[1], BUFSIZ); if (mmap_file_read(&binary) < 0) { fprintf(stderr, "Unable to open binary file: %s\n", binary.name); exit(1); } struct mmap_info hide; strncpy(hide.name, argv[2], BUFSIZ); if (mmap_file_read(&hide) < 0) { fprintf(stderr, "Unable to open hide file: %s\n", hide.name); exit(1); } struct mmap_info binary_out; snprintf(binary_out.name, BUFSIZ, "%s.new", binary.name); binary_out.data_size = binary.data_size + adjust_size(hide.data_size, vm_page_size); binary_out.data = malloc(sizeof(u_char) * binary_out.data_size); bzero(binary_out.data, binary_out.data_size); if (stuff(&binary, &hide, &binary_out) < 0) { fprintf(stderr, "Unable to stuff binary\n"); exit(1); } munmap_file(&binary); munmap_file(&hide); if ((binary_out.fd = open(binary_out.name, O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE)) < 0) { perror("open"); fprintf(stderr, "Unable to open %s\n", binary_out.name); return 1; } if (write(binary_out.fd, binary_out.data, binary_out.data_size) < 0) { perror("write"); fprintf(stderr, "Unable to write %s\n", binary_out.name); return 1; } close(binary_out.fd); free(binary_out.data); printf("PASS\n"); return 0; }
void Track::add ( Control_Sequence *t ) { DMESSAGE( "adding control sequence" ); t->track( this ); t->color( random_color() ); // control->insert( *t, 0 ); control->add( t ); adjust_size(); }
/* * Re-writes the VM addresses of all segments and sections */ void adjust_vm_alignment(struct mach_header *mh) { u_char *ptr = (u_char*)mh + sizeof(struct mach_header); uint32_t vmaddr = 0; int i; for (i = 0; i < mh->ncmds; i++) { struct load_command *lc = (struct load_command *)ptr; if (lc->cmd == LC_SEGMENT) { struct segment_command *sc = (struct segment_command *)ptr; // skip text segment ; probably should be more robust and skip only the // expected areas. if (strncmp(sc->segname, SEG_TEXT, 16) != 0) { printf("segname=%s @ 0x%x\n", sc->segname, vmaddr); sc->vmaddr = vmaddr; uint32_t orig_size = sc->vmsize; sc->vmsize = 0; struct section *s = (struct section *)(sc + 1); struct section *end_section = s; end_section += sc->nsects; for (; s < end_section; ++s) { printf(".section=%s\n", s->sectname); s->addr = vmaddr; s->size = adjust_size(s->size, 1 << s->align); sc->vmsize += s->size; vmaddr += s->size; } printf("vmsize=%d => ", sc->vmsize); sc->vmsize = adjust_size(sc->vmsize, vm_page_size); printf("vmsize=%d\n", sc->vmsize); if (sc->vmsize < orig_size) { sc->vmsize = orig_size; } } vmaddr = sc->vmaddr + sc->vmsize; } ptr += lc->cmdsize; } }
void run_pdf(void) { int fd, i; pid_t pid; int64_t repeat; ssize_t written; int64_t remains; size_t block; char file_name[256]; char buf[WRITE_BUFFER_SIZE]; if (tests_fs_is_currfs()) return; adjust_size(); pid = getpid(); tests_cat_pid(file_name, "run_pdf_test_file_", pid); fd = open(file_name, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); CHECK(fd != -1); pid = getpid(); srand(pid); repeat = tests_repeat_parameter; for (;;) { for (i = 0; i < WRITE_BUFFER_SIZE;++i) buf[i] = rand(); remains = tests_size_parameter; while (remains > 0) { if (remains > WRITE_BUFFER_SIZE) block = WRITE_BUFFER_SIZE; else block = remains; written = write(fd, buf, block); if (written <= 0) { CHECK(errno == ENOSPC); /* File system full */ errno = 0; break; } remains -= written; } /* Break if repeat count exceeded */ if (tests_repeat_parameter > 0 && --repeat <= 0) break; CHECK(lseek(fd, 0, SEEK_SET) == 0); } CHECK(close(fd) != -1); CHECK(unlink(file_name) != -1); }
inline void BigInt::resize(unsigned digits) { if (digits > size) { onedig_t *old_digit = digit; unsigned old_size = size; size = adjust_size(digits); digit = new onedig_t[size]; if (old_digit) { memcpy(digit, old_digit, length * sizeof(onedig_t)); if (old_size) delete[] old_digit; } } }
void chat_app::start() { INVARIANT(root()); INVARIANT(layout()); INVARIANT(_conversation); //message list _messages = new QTextEdit; _messages->setReadOnly(true); _messages->setWordWrapMode(QTextOption::WordWrap); _messages->setUndoRedoEnabled(false); _main_layout->addWidget(_messages, 0, 0, 1, 2); //text edit _message = new QLineEdit; _main_layout->addWidget(_message, 1, 0); //send button _send = new QPushButton; make_reply(*_send); _send->setToolTip(tr("Send")); _main_layout->addWidget(_send, 1, 1); connect(_message, SIGNAL(returnPressed()), this, SLOT(send_message())); connect(_send, SIGNAL(clicked()), this, SLOT(send_message())); //setup mail service _mail_service = new mail_service{_mail, this}; _mail_service->start(); //join the chat join(); adjust_size(); //Let user know this widget is a chat. add_text(make_message_str("red", "notice", "Chat Started")); INVARIANT(_conversation); INVARIANT(_mail); INVARIANT(_sender); }
void Track::remove ( Audio_Sequence *t ) { if ( ! takes ) return; if ( sequence() == t ) { pack->remove( t ); if ( takes->children() ) sequence( (Audio_Sequence*)takes->child( 0 ) ); else /* FIXME: should this ever happen? */ _sequence = NULL; } else takes->remove( t ); /* delete t; */ adjust_size(); }
void script_app::got_adjust_size() { adjust_size(); }
void eoRealVectorBounds::readFrom(std::string _value) { // keep track of old size - to adjust in the end unsigned oldSize = size(); // clean-up before filling in if (ownedBounds.size()>0) for (unsigned i = 0; i < ownedBounds.size(); ++i) { delete ownedBounds[i]; } ownedBounds.resize(0); factor.resize(0); resize(0); // now read std::string delim(",; "); while (_value.size()>0) { if (!remove_leading(_value, delim)) // only delimiters were left break; // look for opening char size_t posDeb = _value.find_first_of("[("); if (posDeb >= _value.size()) // nothing left to read (though probably a syntax error there) { break; } // ending char std::string closeChar = (_value[posDeb] == '(' ? std::string(")") : std::string("]") ); size_t posFin = _value.find_first_of(std::string(closeChar)); if (posFin >= _value.size()) throw std::runtime_error("Syntax error when reading bounds"); // y a-t-il un nbre devant unsigned count = 1; if (posDeb > 0) // something before opening { std::string sCount = _value.substr(0, posDeb); count = read_int(sCount); if (count <= 0) throw std::runtime_error("Syntax error when reading bounds"); } // the bounds std::string sBounds = _value.substr(posDeb+1, posFin-posDeb-1); // and remove from original string _value = _value.substr(posFin+1); remove_leading(sBounds, delim); size_t posDelim = sBounds.find_first_of(delim); if (posDelim >= sBounds.size()) throw std::runtime_error("Syntax error when reading bounds"); bool minBounded=false, maxBounded=false; double minBound=0, maxBound=0; // min bound std::string sMinBounds = sBounds.substr(0,posDelim); if (sMinBounds != std::string("-inf")) { minBounded = true; minBound = read_double(sMinBounds); } // max bound size_t posEndDelim = sBounds.find_first_not_of(delim,posDelim); std::string sMaxBounds = sBounds.substr(posEndDelim); if (sMaxBounds != std::string("+inf")) { maxBounded = true; maxBound = read_double(sMaxBounds); } // now create the eoRealBounds objects eoRealBounds *ptBounds; if (minBounded && maxBounded) ptBounds = new eoRealInterval(minBound, maxBound); else if (!minBounded && !maxBounded) // no bound at all ptBounds = new eoRealNoBounds; else if (!minBounded && maxBounded) ptBounds = new eoRealAboveBound(maxBound); else if (minBounded && !maxBounded) ptBounds = new eoRealBelowBound(minBound); // store it for memory management ownedBounds.push_back(ptBounds); // push the count factor.push_back(count); // and add count of it to the actual bounds for (unsigned i=0; i<count; i++) push_back(ptBounds); } // now adjust the size to the initial value adjust_size(oldSize); }
/* * Stuff bin with data in hide */ int stuff(struct mmap_info *bin, struct mmap_info *hide, struct mmap_info *bin_out) { u_char *start = (u_char *)bin->data; u_char *ptr = start; u_char *ptr_out = (u_char *)bin_out->data; struct mach_header *mh = (struct mach_header *)start; if (bin->data_size < sizeof(struct mach_header)) { fprintf(stderr, "Binary too small (1)\n"); return -1; } if (mh->magic != MH_MAGIC) { fprintf(stderr, "Binary contains an invalid magic number\n"); return -1; } ptr += sizeof(struct mach_header); // TODO(aporter): Use zero'd empty space instead of new space int i; uint32_t shift = 0; uint32_t insert_offset = 0; for (i = 0; i < mh->ncmds; i++) { struct load_command *lc = (struct load_command *)ptr; if (lc->cmd == LC_SEGMENT) { struct segment_command *sc = (struct segment_command *)ptr; if (sc->filesize > 0) { printf("Copying %s (%d bytes @ 0x%08x [orig offset: 0x%08x]) " "shift=%d\n", sc->segname, sc->filesize, ptr_out - (u_char*)bin_out->data, sc->fileoff, shift); memcpy(ptr_out, start + sc->fileoff, sc->filesize); if (shift > 0) { sc->fileoff = ptr_out - (u_char*)bin_out->data; //+= shift; } assert(sc->fileoff == (ptr_out - (u_char*)bin_out->data)); ptr_out += sc->filesize; assert((ptr_out - (u_char*)bin_out->data) <= bin_out->data_size); } if (strncmp(sc->segname, SEG_DATA, 16) == 0) { insert_offset = sc->fileoff + sc->filesize; printf("Inserting %lu bytes @ 0x%08x\n", hide->data_size, (ptr_out - (u_char*)bin_out->data)); uint32_t fill_size = adjust_size(hide->data_size, vm_page_size); sc->filesize += fill_size; sc->vmsize += fill_size; memcpy(ptr_out, hide->data, hide->data_size); ptr_out += hide->data_size; printf("Inserting %lu bytes of zeros @ 0x%08x\n", fill_size - hide->data_size, (ptr_out - (u_char*)bin_out->data)); bzero(ptr_out, fill_size - hide->data_size); ptr_out += fill_size - hide->data_size; shift = fill_size; printf("Offset @ 0x%08x\n", (ptr_out - (u_char*)bin_out->data)); } } else if (lc->cmd == LC_SYMTAB) { printf("LC_SYMTAB\n"); struct symtab_command *sc = (struct symtab_command*)ptr; SHIFT(LC_SYMTAB, sc, symoff, insert_offset, shift); SHIFT(LC_SYMTAB, sc, stroff, insert_offset, shift); } else if (lc->cmd == LC_DYSYMTAB) { printf("LC_DYSYMTAB\n"); struct dysymtab_command *dc = (struct dysymtab_command*)ptr; SHIFT(LC_DYSYMTAB, dc, tocoff, insert_offset, shift); SHIFT(LC_DYSYMTAB, dc, modtaboff, insert_offset, shift); SHIFT(LC_DYSYMTAB, dc, indirectsymoff, insert_offset, shift); SHIFT(LC_DYSYMTAB, dc, extrefsymoff, insert_offset, shift); SHIFT(LC_DYSYMTAB, dc, extreloff, insert_offset, shift); SHIFT(LC_DYSYMTAB, dc, locreloff, insert_offset, shift); } else if (lc->cmd == LC_TWOLEVEL_HINTS) { printf("LC_TWOLEVEL_HINTS\n"); struct twolevel_hints_command *tc = (struct twolevel_hints_command*)ptr; SHIFT(LC_TWOLEVEL_HINTS, tc, offset, insert_offset, shift); } ptr += lc->cmdsize; } printf("\n"); uint32_t written = ptr_out - (u_char*)bin_out->data; assert(written == bin_out->data_size); // re-write header adjust_vm_alignment(mh); memcpy(bin_out->data, bin->data, sizeof(struct mach_header) + mh->sizeofcmds); return 0; }
static void splitfloat_do_resize(WSplitFloat *split, const WRectangle *ng, int hprimn, int vprimn, bool transpose) { WRectangle tlg=GEOM(split->ssplit.tl); WRectangle brg=GEOM(split->ssplit.br); WRectangle ntlg=*ng, nbrg=*ng; int dir=split->ssplit.dir; bool adjust=TRUE; splitfloat_tl_cnt_to_pwin(split, &tlg); splitfloat_br_cnt_to_pwin(split, &brg); if(transpose){ if(dir==SPLIT_VERTICAL){ dir=SPLIT_HORIZONTAL; split->tlpwin->bline=GR_BORDERLINE_RIGHT; split->brpwin->bline=GR_BORDERLINE_LEFT; }else{ dir=SPLIT_VERTICAL; split->tlpwin->bline=GR_BORDERLINE_BOTTOM; split->brpwin->bline=GR_BORDERLINE_TOP; } split->ssplit.dir=dir; } if(dir==SPLIT_VERTICAL){ if(ng->h<=tlg.h+brg.h){ if(transpose){ ntlg.h=MINOF(tlg.w, ng->h*2/3); nbrg.h=MINOF(brg.w, ng->h*2/3); adjust_size(&ntlg.h, dir, split, split->ssplit.tl); adjust_size(&nbrg.h, dir, split, split->ssplit.br); adjust=(ng->h>ntlg.h+nbrg.h); }else{ ntlg.h=MINOF(ng->h, tlg.h); nbrg.h=MINOF(ng->h, brg.h); adjust=FALSE; } }else{ ntlg.h=tlg.h; nbrg.h=brg.h; } if(adjust){ adjust_sizes(&ntlg.h, &nbrg.h, ng->h, splitfloat_get_min(split, dir, split->ssplit.tl), splitfloat_get_min(split, dir, split->ssplit.br), splitfloat_get_max(split, dir, split->ssplit.tl), splitfloat_get_max(split, dir, split->ssplit.br), vprimn); } nbrg.y=ng->y+ng->h-nbrg.h; }else{ if(ng->w<=tlg.w+brg.w){ if(transpose){ ntlg.w=MINOF(tlg.h, ng->w*2/3); nbrg.w=MINOF(brg.h, ng->w*2/3); adjust_size(&ntlg.w, dir, split, split->ssplit.tl); adjust_size(&nbrg.w, dir, split, split->ssplit.br); adjust=(ng->w>ntlg.w+nbrg.w); }else{ ntlg.w=MINOF(ng->w, tlg.w); nbrg.w=MINOF(ng->w, brg.w); adjust=FALSE; } }else{ ntlg.w=tlg.w; nbrg.w=brg.w; } if(adjust){ adjust_sizes(&ntlg.w, &nbrg.w, ng->w, splitfloat_get_min(split, dir, split->ssplit.tl), splitfloat_get_min(split, dir, split->ssplit.br), splitfloat_get_max(split, dir, split->ssplit.tl), splitfloat_get_max(split, dir, split->ssplit.br), hprimn); } nbrg.x=ng->x+ng->w-nbrg.w; } GEOM(split)=*ng; splitfloat_update_handles(split, &ntlg, &nbrg); splitfloat_tl_pwin_to_cnt(split, &ntlg); split_do_resize(split->ssplit.tl, &ntlg, hprimn, vprimn, transpose); splitfloat_br_pwin_to_cnt(split, &nbrg); split_do_resize(split->ssplit.br, &nbrg, hprimn, vprimn, transpose); }
// contructor, which adjusts m_dxdt stepper_euler( const container_type &x ) { adjust_size( x ); }
void Track::set ( Log_Entry &e ) { for ( int i = 0; i < e.size(); ++i ) { const char *s, *v; e.get( i, &s, &v ); if ( ! strcmp( s, ":height" ) ) { size( atoi( v ) ); adjust_size(); } else if ( ! strcmp( s, ":selected" ) ) _selected = atoi( v ); // else if ( ! strcmp( s, ":armed" else if ( ! strcmp( s, ":name" ) ) name( v ); else if ( ! strcmp( s, ":inputs" ) ) configure_inputs( atoi( v ) ); else if ( ! strcmp( s, ":outputs" ) ) configure_outputs( atoi( v ) ); else if ( ! strcmp( s, ":color" ) ) { color( (Fl_Color)atoll( v ) ); redraw(); } else if ( ! strcmp( s, ":show-all-takes" ) ) show_all_takes( atoi( v ) ); else if ( ! strcmp( s, ":overlay-controls" ) ) overlay_controls( atoi( v ) ); else if ( ! strcmp( s, ":solo" ) ) solo( atoi( v ) ); else if ( ! strcmp( s, ":mute" ) ) mute( atoi( v ) ); else if ( ! strcmp( s, ":arm" ) ) armed( atoi( v ) ); else if ( ! strcmp( s, ":sequence" ) ) { int i; sscanf( v, "%X", &i ); if ( i ) { Audio_Sequence *t = (Audio_Sequence*)Loggable::find( i ); /* FIXME: our track might not have been * defined yet... what should we do about this * chicken/egg problem? */ if ( t ) { // assert( t ); sequence( t ); } } } else if ( ! strcmp( s, ":row" ) ) row( atoi( v ) ); } }