/// \par Description: /// The \ref malloc function allocates space for an object whose size is specified by size and /// whose value is indeterminate. __public void* malloc(size_t size) { // Sanity check: are we allocating nothing ? if (size == 0) { // Yes; return nothing return NULL; } // Attempt to use an allocated chunk struct _BASORE_memory_chunk* last = NULL; void* result = alloc(&_BASORE_first_memory_chunk, &last, size); // Did we get memory ? if (result != NULL) { // Good; return it return result; } // See how much more memory we need // FIXME: Make 0x50000 a configuration option somewhere size_t needed = size + 0x50000; size_t real = 0; // Try and get more memory from system if (last->previous == NULL) { // First block. last->first_block = (struct _BASORE_memory_block*)(__platform_allocate(needed, &real)); // Did we get it ? if (last->first_block) { // Set it up last->size = real; last->first_block->parent = last; } } else { // Not first block last->next = (struct _BASORE_memory_chunk*)(__platform_allocate(needed, &real)); // Did we get it ? if (last->next) { // Set it up last->next->next = NULL; last->next->previous = last; last->next->size = real - sizeof(struct _BASORE_memory_chunk); last->next->first_block = (struct _BASORE_memory_block*)(last->next + 1); last->next->first_block->parent = last->next; last = last->next; } } // Did we get some ? if (last != NULL) { // Yes; finish setting it up last->first_block->previous = NULL; last->first_block->next = NULL; last->first_block->size = last->size - sizeof(struct _BASORE_memory_block); last->first_block->available = true; // Use it return alloc(last, NULL, size); } // Emergency situation; have we been here before ? if (_BASORE_emergency_memory_chunk.first_block->size == 0) { // No; initialize emergency block _BASORE_emergency_memory_chunk.first_block->parent = &_BASORE_emergency_memory_chunk; _BASORE_emergency_memory_chunk.first_block->available = true; _BASORE_emergency_memory_chunk.first_block->size = _BASORE_emergency_memory_chunk.size - sizeof (struct _BASORE_memory_block); } // Try to allocate off the emergency chunk return alloc(&_BASORE_emergency_memory_chunk, NULL, size); }
value pgconn_alloc(PGconn* conn) { value res = alloc(1, Abstract_tag); initialize(&Field(res, 0), (value)conn); return res; }
int main() { //Remove shared memory on construction and destruction struct shm_remove { shm_remove() { bip::shared_memory_object::remove("ipdf_testdomain_simpletest"); } ~shm_remove(){ bip::shared_memory_object::remove("ipdf_testdomain_simpletest"); } } remover; // create segment and corresponding allocator bip::managed_shared_memory segment(bip::open_or_create, "ipdf_testdomain_simpletest", 65536); ipdf::ShmPortCondition *port = segment.find_or_construct<ipdf::ShmPortCondition>("port_testing")(); shm::shmem_channel_allocator alloc(segment.get_segment_manager()); shm::channel_message_queue *queue1 = segment.find_or_construct<shm::channel_message_queue>("queue1")(); shm::channel_message_queue *queue2 = segment.find_or_construct<shm::channel_message_queue>("queue2")(); bool running = true; unsigned int total_message_count = 0; while (running) { bool process_queues = false; // wait for activity .. could also be polling ... { bip::scoped_lock<bip::interprocess_mutex> lock(port->port_mutex); if (!port->data_available) { boost::posix_time::ptime timeout = boost::get_system_time() + boost::posix_time::milliseconds(1); bool was_notified = port->port_condition.timed_wait(lock, timeout); if (was_notified) { process_queues = true; } port->data_available = false; } } std::vector<unsigned long long> messages(0); if (process_queues) { std::cout << "process_queues" << "\n"; bool continue_poll = true; shm::ChannelMessage v(alloc); // loop until no more values are available while (continue_poll) { continue_poll = false; if (queue1->pop(v)) { //std::cout << "Processed 1: '" << v.timestamp << "'\n"; messages.push_back(v.timestamp); continue_poll = true; } if (queue2->pop(v)) { // std::cout << "Processed 2: '" << v.timestamp << "'\n"; messages.push_back(v.timestamp); continue_poll = true; } } } if (messages.size() > 0) { total_message_count += messages.size(); std::cout << " received " << total_message_count << " messages in total \n"; } } }
static void *load_primitive( const char *prim, int nargs, value path, liblist **libs ) { char *pos = strchr(prim,'@'); int len; liblist *l; PRIM0 ptr; if( pos == NULL ) return NULL; l = *libs; *pos = 0; len = (int)strlen(prim) + 1; # ifndef NEKO_STANDALONE while( l != NULL ) { if( memcmp(l->name,prim,len) == 0 ) break; l = l->next; } # endif if( l == NULL ) { void *h; value pname = pname = neko_select_file(path,prim,".ndll"); #ifdef NEKO_STANDALONE # ifdef NEKO_WINDOWS h = (void*)GetModuleHandle(NULL); # else h = dlopen(NULL,RTLD_LAZY); # endif #else h = dlopen(val_string(pname),RTLD_LAZY); #endif if( h == NULL ) { buffer b = alloc_buffer("Failed to load library : "); val_buffer(b,pname); #ifndef NEKO_WINDOWS buffer_append(b," ("); buffer_append(b,dlerror()); buffer_append(b,")"); #endif *pos = '@'; bfailure(b); } l = (liblist*)alloc(sizeof(liblist)); l->handle = h; l->name = alloc_private(len); memcpy(l->name,prim,len); l->next = *libs; *libs = l; ptr = (PRIM0)dlsym(l->handle,"__neko_entry_point"); if( ptr != NULL ) ((PRIM0)ptr())(); } *pos++ = '@'; { char buf[100]; if( strlen(pos) > 90 ) return NULL; if( nargs == VAR_ARGS ) sprintf(buf,"%s__MULT",pos); else sprintf(buf,"%s__%d",pos,nargs); ptr = (PRIM0)dlsym(l->handle,buf); if( ptr == NULL ) return NULL; return ptr(); } }
bool test_insert_with_expand_bwd() { typedef typename VectorWithExpandBwdAllocator::value_type value_type; typedef typename boost::remove_volatile<value_type>::type non_volatile_value_type; typedef std::vector<non_volatile_value_type> Vect; const int MemorySize = 1000; //Distance old and new buffer const int Offset[] = { 350, 250, 150, 150, 150, 50, 50, 50 }; //Insert position const int Position[] = { 100, 100, 100, 100, 100, 100, 100, 100 }; //Initial vector size const int InitialSize[] = { 200, 200, 200, 200, 200, 200, 200, 200 }; //Size of the data to insert const int InsertSize[] = { 100, 100, 100, 200, 300, 25, 100, 200 }; //Number of tests const int Iterations = sizeof(InsertSize)/sizeof(int); for(int iteration = 0; iteration < Iterations; ++iteration) { value_type *memory = new value_type[MemorySize]; try { std::vector<non_volatile_value_type> initial_data; initial_data.resize(InitialSize[iteration]); for(int i = 0; i < InitialSize[iteration]; ++i){ initial_data[i] = i; } Vect data_to_insert; data_to_insert.resize(InsertSize[iteration]); for(int i = 0; i < InsertSize[iteration]; ++i){ data_to_insert[i] = -i; } expand_bwd_test_allocator<value_type> alloc (&memory[0], MemorySize, Offset[iteration]); VectorWithExpandBwdAllocator vector(alloc); vector.insert( vector.begin() , initial_data.begin(), initial_data.end()); vector.insert( vector.begin() + Position[iteration] , data_to_insert.begin(), data_to_insert.end()); initial_data.insert(initial_data.begin() + Position[iteration] , data_to_insert.begin(), data_to_insert.end()); //Now check that values are equal if(!CheckEqualVector(vector, initial_data)){ std::cout << "test_assign_with_expand_bwd::CheckEqualVector failed." << std::endl << " Class: " << typeid(VectorWithExpandBwdAllocator).name() << std::endl << " Iteration: " << iteration << std::endl; return false; } } catch(...){ delete [](const_cast<non_volatile_value_type*>(memory)); throw; } delete [](const_cast<non_volatile_value_type*>(memory)); } return true; }
int main(void) { void *stage2 = NULL; f_desc_t f; int (* func)(void); int ret; #ifdef DEBUG debug_init(); DPRINTF("Stage 1 hello.\n"); #endif f.addr = flash_mount_clone; f.toc = (void *)MKA(TOC); func = (void *)&f; ret = func(); if (ret != 0 && ret != 1) { DPRINTF("Flash mount failed!\n"); } else { CellFsStat stat; DPRINTF("Flash mounted\n"); if (cellFsStat(STAGE2_FILE, &stat) == 0) { int fd; if (cellFsOpen(STAGE2_FILE, CELL_FS_O_RDONLY, &fd, 0, NULL, 0) == 0) { uint32_t psize = stat.st_size; DPRINTF("Payload size = %d\n", psize); stage2 = alloc(psize, 0x27); if (stage2) { uint64_t rs; if (cellFsRead(fd, stage2, psize, &rs) != 0) { DPRINTF("Stage 2 read fail.\n"); dealloc(stage2, 0x27); stage2 = NULL; } } else { DPRINTF("Cannot allocate stage2\n"); } cellFsClose(fd); } } else { DPRINTF("There is no stage 2, booting system.\n"); } } if (stage2) { f.addr = stage2; func = (void *)&f; DPRINTF("Calling stage 2...\n"); func(); } return ret; }
static void test_table(mk_table_fn mk_table) { datalog::table_signature sig; sig.push_back(2); sig.push_back(4); sig.push_back(8); sig.push_back(4); smt_params params; ast_manager ast_m; datalog::register_engine re; datalog::context ctx(ast_m, re, params); datalog::relation_manager & m = ctx.get_rel_context()->get_rmanager(); m.register_plugin(alloc(datalog::bitvector_table_plugin, m)); datalog::table_base* _tbl = mk_table(m, sig); datalog::table_base& table = *_tbl; datalog::table_fact row, row1, row2, row3; row.push_back(1); row.push_back(3); row.push_back(7); row.push_back(2); row1 = row; row[3] = 3; row2 = row; row[0] = 0; row[3] = 1; row3 = row; table.add_fact(row1); table.add_fact(row2); table.display(std::cout); datalog::table_base::iterator it = table.begin(); datalog::table_base::iterator end = table.end(); for (; it != end; ++it) { it->get_fact(row); for (unsigned j = 0; j < row.size(); ++j) { std::cout << row[j] << " "; } std::cout << "\n"; } SASSERT(table.contains_fact(row1)); SASSERT(table.contains_fact(row2)); SASSERT(!table.contains_fact(row3)); #if 0 table.remove_facts(1, &row1); SASSERT(!table.contains_fact(row1)); #endif table.add_fact(row1); datalog::table_base* _tbl2 = mk_table(m, sig); datalog::table_base& table2 = *_tbl2; table2.add_fact(row2); table2.add_fact(row3); unsigned cols1[1] = { 1 }; unsigned cols2[1] = { 3 }; datalog::table_join_fn * j1 = m.mk_join_fn(table2, table, 1, cols1, cols2); datalog::table_base* _tbl3 = (*j1)(table2,table); _tbl3->display(std::cout); datalog::table_join_fn * j2 = m.mk_join_fn(table2, table, 1, cols1, cols1); datalog::table_base* _tbl4 = (*j2)(table2,table); _tbl4->display(std::cout); dealloc(j1); dealloc(j2); _tbl->deallocate(); (_tbl2->deallocate()); (_tbl3->deallocate()); (_tbl4->deallocate()); }
void PartConv_Ctor( PartConv* unit ) { unit->m_fftsize= (int) ZIN0(1); unit->m_nover2= unit->m_fftsize>>1; unit->m_inputbuf= (float*)RTAlloc(unit->mWorld, unit->m_fftsize * sizeof(float)); unit->m_spectrum= (float*)RTAlloc(unit->mWorld, unit->m_fftsize * sizeof(float)); SCWorld_Allocator alloc(ft, unit->mWorld); unit->m_scfft = scfft_create(unit->m_fftsize, unit->m_fftsize, kRectWindow, unit->m_inputbuf, unit->m_spectrum, kForward, alloc); //inverse unit->m_inputbuf2= (float*)RTAlloc(unit->mWorld, unit->m_fftsize * sizeof(float)); unit->m_spectrum2= (float*)RTAlloc(unit->mWorld, unit->m_fftsize * sizeof(float)); //in place this time unit->m_scifft = scfft_create(unit->m_fftsize, unit->m_fftsize, kRectWindow, unit->m_inputbuf2, unit->m_spectrum2, kBackward, alloc); //debug test: changing scale factors in case amplitude summation is a problem //unit->m_scfft->scalefac=1.0/45.254833995939; //unit->m_scifft->scalefac=1.0/45.254833995939; unit->m_output= (float*)RTAlloc(unit->mWorld, unit->m_fftsize * sizeof(float)); unit->m_outputpos=0; memset(unit->m_output, 0, unit->m_fftsize * sizeof(float)); memset(unit->m_inputbuf, 0, unit->m_fftsize * sizeof(float)); unit->m_pos=0; //get passed in buffer unit->m_fd_accumulate=NULL; uint32 bufnum = (uint32)ZIN0(2); SndBuf *buf; if (bufnum >= unit->mWorld->mNumSndBufs) { int localBufNum = bufnum - unit->mWorld->mNumSndBufs; Graph *parent = unit->mParent; if(localBufNum <= parent->localMaxBufNum) { buf = parent->mLocalSndBufs + localBufNum; } else { printf("PartConv Error: Invalid Spectral data bufnum %d \n", bufnum); SETCALC(*ClearUnitOutputs); unit->mDone = true; return; } } buf = unit->mWorld->mSndBufs + bufnum; unit->m_specbufnumcheck = bufnum; if (!buf->data) { //unit->mDone = true; printf("PartConv Error: Spectral data buffer not allocated \n"); SETCALC(*ClearUnitOutputs); unit->mDone = true; return; } unit->m_irspectra = buf->data; unit->m_fullsize = buf->samples; unit->m_partitions=buf->samples/(unit->m_fftsize); //should be exact //printf("another check partitions %d irspecsize %d fftsize %d \n", unit->m_partitions,unit->m_fullsize, unit->m_fftsize); if((buf->samples % unit->m_fftsize !=0) || (buf->samples==0)) { printf("PartConv Error: fftsize doesn't divide spectral data buffer size or spectral data buffer size is zero\n"); SETCALC(*ClearUnitOutputs); unit->mDone = true; return; } //CHECK SAMPLING RATE AND BUFFER SIZE unit->m_blocksize = unit->mWorld->mFullRate.mBufLength; //if(unit->m_blocksize!=64) printf("TPV complains: block size not 64, you have %d\n", unit->m_blocksize); unit->m_sr = unit->mWorld->mSampleRate; //if(unit->m_sr!=44100) printf("TPV complains: sample rate not 44100, you have %d\n", unit->m_sr); if(unit->m_nover2 % unit->m_blocksize !=0) { printf("PartConv Error: block size doesn't divide partition size\n"); SETCALC(*ClearUnitOutputs); unit->mDone = true; return; } else { //must be exact divisor int blocksperpartition = unit->m_nover2/unit->m_blocksize; unit->m_spareblocks = blocksperpartition-1; if(unit->m_spareblocks<1) { printf("PartConv Error: no spareblocks, amortisation not possible! \n"); SETCALC(*ClearUnitOutputs); unit->mDone = true; return; } //won't be exact unit->m_numamort = (unit->m_partitions-1)/unit->m_spareblocks; //will relate number of partitions to number of spare blocks unit->m_lastamort= (unit->m_partitions-1)- ((unit->m_spareblocks-1)*(unit->m_numamort)); //allow for error on last one unit->m_amortcount= -1; //starts as flag to avoid any amortisation before have first fft done unit->m_partitionsdone=1; //printf("Amortisation stats partitions %d nover2 %d blocksize %d spareblocks %d numamort %d lastamort %d \n", unit->m_partitions,unit->m_nover2, unit->m_blocksize, unit->m_spareblocks, unit->m_numamort, unit->m_lastamort); unit->m_fd_accumulate= (float*)RTAlloc(unit->mWorld, unit->m_fullsize * sizeof(float)); memset(unit->m_fd_accumulate, 0, unit->m_fullsize * sizeof(float)); unit->m_fd_accum_pos=0; SETCALC(PartConv_next); } }
void mddi_init(void) { unsigned n; int i = 0; // dprintf("mddi_init()\n"); rev_pkt_buf = alloc(256); writel((unsigned) rev_pkt_buf, MDDI_REV_PTR); writel(256, MDDI_REV_SIZE); writel(256, MDDI_REV_ENCAP_SZ); mddi_do_cmd(CMD_FORCE_NEW_REV_PTR); mddi_do_cmd(CMD_LINK_ACTIVE); do { if(i++ > 0x100) break; n = readl(MDDI_STAT); } while(!(n & MDDI_STAT_LINK_ACTIVE)); /* v > 8? v > 8 && < 0x19 ? */ writel(2, MDDI_TEST); // writel(CMD_PERIODIC_REV_ENC | 0, MDDI_CMD); /* disable */ fb_width = 480; fb_height = 854; dprintf("panel is %d x %d\n", fb_width, fb_height); // FB = alloc(2 * fb_width * fb_height); FB = 0x2b00000; mlist = alloc(sizeof(mddi_llentry) * (fb_height / 8)); // dprintf("FB @ %x mlist @ %x\n", (unsigned) FB, (unsigned) mlist); for(n = 0; n < (fb_height / 8); n++) { unsigned y = n * 8; unsigned pixels = fb_width * 8; mddi_video_stream *vs = &(mlist[n].u.v); vs->length = sizeof(mddi_video_stream) - 2 + (pixels * 2); vs->type = TYPE_VIDEO_STREAM; vs->client_id = 0; vs->format = 0x5565; // FORMAT_16BPP; vs->pixattr = PIXATTR_BOTH_EYES | PIXATTR_TO_ALL; vs->left = 0; vs->right = fb_width - 1; vs->top = y; vs->bottom = y + 7; vs->start_x = 0; vs->start_y = y; vs->pixels = pixels; vs->crc = 0; vs->reserved = 0; mlist[n].header_count = sizeof(mddi_video_stream) - 2; mlist[n].data_count = pixels * 2; mlist[n].reserved = 0; wr32(&mlist[n].data, ((unsigned) FB) + (y * fb_width * 2)); mlist[n].flags = 0; wr32(&mlist[n].next, (unsigned) (mlist + n + 1)); } mlist[n-1].flags = 1; wr32(&mlist[n-1].next, 0); writel(CMD_HIBERNATE, MDDI_CMD); writel(CMD_LINK_ACTIVE, MDDI_CMD); for(n = 0; n < (fb_width * fb_height); n++) FB[n] = 0;//0x88; mddi_start_update(); }
Z3_context Z3_API Z3_mk_context_rc(Z3_config c) { LOG_Z3_mk_context_rc(c); memory::initialize(0); Z3_context r = reinterpret_cast<Z3_context>(alloc(api::context, reinterpret_cast<api::config_params*>(c), true)); RETURN_Z3(r); }
Z3_context Z3_mk_context_from_params(front_end_params const& p) { api::config_params cp(p); return reinterpret_cast<Z3_context>(alloc(api::context, &cp)); }
smt::solver & context::get_solver() { if (!m_solver) { m_solver = alloc(smt::solver, m_manager, m_params); } return *m_solver; }
/** * @brief Initializes the user interface. */ void Cg_InitUi(void) { mainViewController = $(alloc(MainViewController), init); cgi.AddViewController((ViewController *) mainViewController); }
/* * Handle marks in the viminfo file: * fp_out != NULL: copy marks for buffers not in buffer list * fp_out == NULL && (flags & VIF_WANT_MARKS): read marks for curbuf only * fp_out == NULL && (flags & VIF_GET_OLDFILES | VIF_FORCEIT): fill v:oldfiles */ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags) { char_u *line = virp->vir_line; buf_T *buf; int num_marked_files; int load_marks; int copy_marks_out; char_u *str; int i; char_u *p; char_u *name_buf; pos_T pos; list_T *list = NULL; if ((name_buf = alloc(LSIZE)) == NULL) return; *name_buf = NUL; if (fp_out == NULL && (flags & (VIF_GET_OLDFILES | VIF_FORCEIT))) { list = list_alloc(); if (list != NULL) set_vim_var_list(VV_OLDFILES, list); } num_marked_files = get_viminfo_parameter('\''); while (!eof && (count < num_marked_files || fp_out == NULL)) { if (line[0] != '>') { if (line[0] != '\n' && line[0] != '\r' && line[0] != '#') { if (viminfo_error("E576: ", _("Missing '>'"), line)) break; /* too many errors, return now */ } eof = vim_fgets(line, LSIZE, virp->vir_fd); continue; /* Skip this dud line */ } /* * Handle long line and translate escaped characters. * Find file name, set str to start. * Ignore leading and trailing white space. */ str = skipwhite(line + 1); str = viminfo_readstring(virp, (int)(str - virp->vir_line), FALSE); if (str == NULL) continue; p = str + STRLEN(str); while (p != str && (*p == NUL || vim_isspace(*p))) p--; if (*p) p++; *p = NUL; if (list != NULL) list_append_string(list, str, -1); /* * If fp_out == NULL, load marks for current buffer. * If fp_out != NULL, copy marks for buffers not in buflist. */ load_marks = copy_marks_out = FALSE; if (fp_out == NULL) { if ((flags & VIF_WANT_MARKS) && curbuf->b_ffname != NULL) { if (*name_buf == NUL) /* only need to do this once */ home_replace(NULL, curbuf->b_ffname, name_buf, LSIZE, TRUE); if (fnamecmp(str, name_buf) == 0) load_marks = TRUE; } } else { /* fp_out != NULL */ /* This is slow if there are many buffers!! */ for (buf = firstbuf; buf != NULL; buf = buf->b_next) if (buf->b_ffname != NULL) { home_replace(NULL, buf->b_ffname, name_buf, LSIZE, TRUE); if (fnamecmp(str, name_buf) == 0) break; } /* * copy marks if the buffer has not been loaded */ if (buf == NULL || !buf->b_marks_read) { copy_marks_out = TRUE; fputs("\n> ", fp_out); viminfo_writestring(fp_out, str); count++; } } vim_free(str); pos.coladd = 0; while (!(eof = viminfo_readline(virp)) && line[0] == TAB) { if (load_marks) { if (line[1] != NUL) { unsigned u; sscanf((char *)line + 2, "%ld %u", &pos.lnum, &u); pos.col = u; switch (line[1]) { case '"': curbuf->b_last_cursor = pos; break; case '^': curbuf->b_last_insert = pos; break; case '.': curbuf->b_last_change = pos; break; case '+': /* changelist positions are stored oldest * first */ if (curbuf->b_changelistlen == JUMPLISTSIZE) /* list is full, remove oldest entry */ mch_memmove(curbuf->b_changelist, curbuf->b_changelist + 1, sizeof(pos_T) * (JUMPLISTSIZE - 1)); else ++curbuf->b_changelistlen; curbuf->b_changelist[ curbuf->b_changelistlen - 1] = pos; break; default: if ((i = line[1] - 'a') >= 0 && i < NMARKS) curbuf->b_namedm[i] = pos; } } } else if (copy_marks_out) fputs((char *)line, fp_out); } if (load_marks) { win_T *wp; FOR_ALL_WINDOWS(wp) { if (wp->w_buffer == curbuf) wp->w_changelistidx = curbuf->b_changelistlen; } break; } } vim_free(name_buf); }
void install_interpolant_cmds(cmd_context & ctx) { ctx.insert(alloc(get_interpolant_cmd)); ctx.insert(alloc(compute_interpolant_cmd)); // ctx.insert(alloc(get_and_check_interpolant_cmd)); }
void mddi_init(void) { unsigned n; // dprintf("mddi_init()\n"); rev_pkt_buf = alloc(256); mddi_do_cmd(CMD_RESET); /* disable periodic rev encap */ mddi_do_cmd(CMD_PERIODIC_REV_ENC | 0); writel(0x0001, MDDI_VERSION); writel(0x3C00, MDDI_BPS); writel(0x0003, MDDI_SPM); writel(0x0005, MDDI_TA1_LEN); writel(0x001a, MDDI_TA2_LEN); writel(0x0096, MDDI_DRIVE_HI); writel(0x0050, MDDI_DRIVE_LO); writel(0x003C, MDDI_DISP_WAKE); writel(0x0004, MDDI_REV_RATE_DIV); /* needs to settle for 5uS */ if (readl(MDDI_PAD_CTL) == 0) { writel(0x08000, MDDI_PAD_CTL); udelay(5); } writel(0xA850F, MDDI_PAD_CTL); writel(0x60006, MDDI_DRIVER_START_CNT); writel((unsigned) rev_pkt_buf, MDDI_REV_PTR); writel(256, MDDI_REV_SIZE); writel(256, MDDI_REV_ENCAP_SZ); mddi_do_cmd(CMD_FORCE_NEW_REV_PTR); /* disable hibernate */ mddi_do_cmd(CMD_HIBERNATE | 0); panel_backlight(0); panel_poweron(); mddi_do_cmd(CMD_LINK_ACTIVE); do { n = readl(MDDI_STAT); } while(!(n & MDDI_STAT_LINK_ACTIVE)); /* v > 8? v > 8 && < 0x19 ? */ writel(2, MDDI_TEST); // writel(CMD_PERIODIC_REV_ENC | 0, MDDI_CMD); /* disable */ mddi_get_caps(); #if 0 writel(0x5666, MDDI_MDP_VID_FMT_DES); writel(0x00C3, MDDI_MDP_VID_PIX_ATTR); writel(0x0000, MDDI_MDP_CLIENTID); #endif dprintf("panel is %d x %d\n", fb_width, fb_height); FB = alloc(2 * fb_width * fb_height); mlist = alloc(sizeof(mddi_llentry) * (fb_height / 8)); // dprintf("FB @ %x mlist @ %x\n", (unsigned) FB, (unsigned) mlist); for(n = 0; n < (fb_height / 8); n++) { unsigned y = n * 8; unsigned pixels = fb_width * 8; mddi_video_stream *vs = &(mlist[n].u.v); vs->length = sizeof(mddi_video_stream) - 2 + (pixels * 2); vs->type = TYPE_VIDEO_STREAM; vs->client_id = 0; vs->format = 0x5565; // FORMAT_16BPP; vs->pixattr = PIXATTR_BOTH_EYES | PIXATTR_TO_ALL; vs->left = 0; vs->right = fb_width - 1; vs->top = y; vs->bottom = y + 7; vs->start_x = 0; vs->start_y = y; vs->pixels = pixels; vs->crc = 0; vs->reserved = 0; mlist[n].header_count = sizeof(mddi_video_stream) - 2; mlist[n].data_count = pixels * 2; mlist[n].reserved = 0; wr32(&mlist[n].data, ((unsigned) FB) + (y * fb_width * 2)); mlist[n].flags = 0; wr32(&mlist[n].next, (unsigned) (mlist + n + 1)); } mlist[n-1].flags = 1; wr32(&mlist[n-1].next, 0); writel(CMD_HIBERNATE, MDDI_CMD); writel(CMD_LINK_ACTIVE, MDDI_CMD); for(n = 0; n < (fb_width * fb_height); n++) FB[n] = 0; mddi_start_update(); panel_backlight(1); }
void allocLogBuffer() { // Allocate a buffer if not yet allocated if (commonInfo->logBuffer == NULL) { commonInfo->logBuffer = alloc(commonInfo->maxLogBufferLength); } }
struct yearly_clim_object *construct_yearly_clim( FILE *base_station_file, char *file_prefix, struct date start_date, long duration, int clim_repeat_flag) { /*--------------------------------------------------------------*/ /* local function declarations. */ /*--------------------------------------------------------------*/ double *construct_clim_sequence( char *, struct date, long, int); void *alloc( size_t, char *, char *); /*--------------------------------------------------------------*/ /* local variable declarations */ /*--------------------------------------------------------------*/ int i; int num_non_critical_sequences; char record[MAXSTR]; char sequence_name[256]; char file_name[256]; struct yearly_clim_object *yearly_clim; /*--------------------------------------------------------------*/ /* Allocate the yearly clim object. */ /*--------------------------------------------------------------*/ yearly_clim = (struct yearly_clim_object *) alloc(1*sizeof(struct yearly_clim_object), "yearly_clim","construct_yearly_clim"); /*--------------------------------------------------------------*/ /* Attempt to open the yearly clim sequence file for each */ /* critical clim parameter and read them in. */ /* */ /* At the moment there are no critical clim parameters. */ /*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/ /* Initialize non-critical sequences */ /*--------------------------------------------------------------*/ yearly_clim[0].temp = NULL; /*--------------------------------------------------------------*/ /* Read the still open base station file for the number of */ /* non-critical parameters. */ /*--------------------------------------------------------------*/ fscanf(base_station_file,"%d", &num_non_critical_sequences); read_record(base_station_file, record); /*--------------------------------------------------------------*/ /* Loop through all of the non-critical sequences and attempt */ /* to construct them. */ /*--------------------------------------------------------------*/ for ( i=0 ; i<num_non_critical_sequences ; i++ ){ /*--------------------------------------------------------------*/ /* read in the non-critical_sequence name. */ /*--------------------------------------------------------------*/ fscanf(base_station_file,"%s",sequence_name); read_record(base_station_file, record); /*--------------------------------------------------------------*/ /* test the sequence name and create it if it is valid. */ /* otherwise report a warning. */ /*--------------------------------------------------------------*/ if ( strcmp(sequence_name,"temp" ) == 0){ strcpy(file_name, file_prefix); yearly_clim[0].temp = construct_clim_sequence( (char *)strcat(file_name,".temp"), start_date, duration, clim_repeat_flag); } else{ fprintf(stderr, "WARNING - clim sequence %s not found./n",sequence_name); } /*end if-else*/ } /*end for*/ return(yearly_clim); } /*end construct_yearly_clim*/
struct stratum_default *construct_stratum_defaults( int num_default_files, char **default_files, struct command_line_object *command_line) { /*--------------------------------------------------------------*/ /* Local function definition. */ /*--------------------------------------------------------------*/ void *alloc( size_t, char *, char *); int parse_veg_type( char *); int parse_phenology_type( char *); int parse_dyn_flag( char *); int parse_alloc_flag( char *); /*--------------------------------------------------------------*/ /* Local variable definition. */ /*--------------------------------------------------------------*/ int i, itmp; int strbufLen = 256; int filenameLen = 1024; int paramCnt = 0; char record[MAXSTR]; char *newrecord; char stmp[MAXSTR]; char strbuf[strbufLen]; char outFilename[filenameLen]; double fcel, ftmp, lig_cel_ratio; //FILE *default_file; param *paramPtr = NULL; struct stratum_default *default_object_list; struct epconst_struct *epc; /*--------------------------------------------------------------*/ /* Allocate an array of default objects. */ /*--------------------------------------------------------------*/ default_object_list = (struct stratum_default *) alloc(num_default_files * sizeof(struct stratum_default),"default_object_list", "construct_stratum_defaults" ); /*--------------------------------------------------------------*/ /* Loop through the default files list. */ /*--------------------------------------------------------------*/ for (i=0 ; i<num_default_files; i++) { epc = &(default_object_list[i].epc); /*--------------------------------------------------------------*/ /* Try to open the ith default file. */ /*--------------------------------------------------------------*/ printf("Reading %s\n", default_files[i]); paramCnt = 0; if (paramPtr != NULL) free(paramPtr); paramPtr = readParamFile(¶mCnt, default_files[i]); /*--------------------------------------------------------------*/ /* read the ith default file into the ith object. */ /*--------------------------------------------------------------*/ default_object_list[i].ID = getIntParam(¶mCnt, ¶mPtr, "stratum_default_ID", "%d", 7, 1); // new param name default_object_list[i].epc.veg_type = parse_veg_type(getStrParam(¶mCnt, ¶mPtr, "epc.veg.type", "%s", "TREE", 1)); // param name is "epc.veg.type" in param file default_object_list[i].K_absorptance = getDoubleParam(¶mCnt, ¶mPtr, "K_absorptance", "%lf", 0.8, 1); // parameter misspelled in file as "K_apsorbtance" default_object_list[i].K_reflectance = getDoubleParam(¶mCnt, ¶mPtr, "K_reflectance", "%lf", 0.1, 1); default_object_list[i].K_transmittance = getDoubleParam(¶mCnt, ¶mPtr, "K_transmittance", "%lf", 0.1, 1); default_object_list[i].PAR_absorptance = getDoubleParam(¶mCnt, ¶mPtr, "PAR_absorptance", "%lf", 1.0, 1); // param misspelled in file "PAR_absrptance" default_object_list[i].PAR_reflectance = getDoubleParam(¶mCnt, ¶mPtr, "PAR_reflectance", "%lf", 0.0, 1); default_object_list[i].PAR_transmittance = getDoubleParam(¶mCnt, ¶mPtr, "PAR_transmittance", "%lf", 0.0, 1); default_object_list[i].epc.ext_coef = getDoubleParam(¶mCnt, ¶mPtr, "epc.ext_coef", "%lf", 0.5, 1); default_object_list[i].specific_rain_capacity = getDoubleParam(¶mCnt, ¶mPtr, "specific_rain_capacity", "%lf", 0.00024, 1); default_object_list[i].specific_snow_capacity = getDoubleParam(¶mCnt, ¶mPtr, "specific_snow_capacity", "%lf", 0.00024, 1); default_object_list[i].wind_attenuation_coeff = getDoubleParam(¶mCnt, ¶mPtr, "wind_attenuation_coef", "%lf", 0.4, 1); // param name is "wind_attenuation_coef" in param file default_object_list[i].ustar_overu = getDoubleParam(¶mCnt, ¶mPtr, "ustar_overu", "%lf", -999.9, 1); default_object_list[i].mrc.q10 = getDoubleParam(¶mCnt, ¶mPtr, "mrc.q10", "%lf", 1.5, 1); default_object_list[i].mrc.per_N = getDoubleParam(¶mCnt, ¶mPtr, "mrc.per_N", "%lf", 0.21, 1); default_object_list[i].epc.gr_perc = getDoubleParam(¶mCnt, ¶mPtr, "epc.gr_perc", "%lf", 0.2, 1); default_object_list[i].lai_stomatal_fraction = getDoubleParam(¶mCnt, ¶mPtr, "lai_stomatal_fraction", "%lf", 1.0, 1); default_object_list[i].epc.flnr = getDoubleParam(¶mCnt, ¶mPtr, "epc.flnr", "%lf", 0.1, 1); default_object_list[i].epc.ppfd_coef = getDoubleParam(¶mCnt, ¶mPtr, "epc.ppfd_coef", "%lf", 0.03, 1); default_object_list[i].epc.topt = getDoubleParam(¶mCnt, ¶mPtr, "epc.topt", "%lf", 15.0, 1); default_object_list[i].epc.tmax = getDoubleParam(¶mCnt, ¶mPtr, "epc.tmax", "%lf", 40.0, 1); default_object_list[i].epc.tcoef = getDoubleParam(¶mCnt, ¶mPtr, "epc.tcoef", "%lf", 0.2, 1); default_object_list[i].epc.psi_open = getDoubleParam(¶mCnt, ¶mPtr, "epc.psi_open", "%lf", -0.65, 1); default_object_list[i].epc.psi_close = getDoubleParam(¶mCnt, ¶mPtr, "epc.psi_close", "%lf", -2.5, 1); default_object_list[i].epc.vpd_open = getDoubleParam(¶mCnt, ¶mPtr, "epc.vpd_open", "%lf", 0.0, 1); default_object_list[i].epc.vpd_close = getDoubleParam(¶mCnt, ¶mPtr, "epc.vpd_close", "%lf", 3500.0, 1); default_object_list[i].epc.gl_smax = getDoubleParam(¶mCnt, ¶mPtr, "epc.gl_smax", "%lf", 0.006, 1); default_object_list[i].epc.gl_c = getDoubleParam(¶mCnt, ¶mPtr, "epc.gl_c", "%lf", 0.00006, 1); default_object_list[i].gsurf_slope = getDoubleParam(¶mCnt, ¶mPtr, "gsurf_slope", "%lf", 0.0, 1); default_object_list[i].gsurf_intercept = getDoubleParam(¶mCnt, ¶mPtr, "gsurf_intercept", "%lf", 1000000.0, 1); default_object_list[i].epc.phenology_flag = parse_dyn_flag(getStrParam(¶mCnt, ¶mPtr, "epc.phenology_flag", "%s", "static", 1)); default_object_list[i].epc.phenology_type = parse_phenology_type(getStrParam(¶mCnt, ¶mPtr, "epc.phenology.type", "%s", "EVERGREEN", 1)); default_object_list[i].epc.max_lai = getDoubleParam(¶mCnt, ¶mPtr, "epc.max_lai", "%lf", 12.0, 1); default_object_list[i].epc.proj_sla = getDoubleParam(¶mCnt, ¶mPtr, "epc.proj_sla", "%lf", 9.0, 1); default_object_list[i].epc.lai_ratio = getDoubleParam(¶mCnt, ¶mPtr, "epc.lai_ratio", "%lf", 2.6, 1); default_object_list[i].epc.proj_swa = getDoubleParam(¶mCnt, ¶mPtr, "epc.proj_swa", "%lf", 1.4, 1); default_object_list[i].epc.leaf_turnover = getDoubleParam(¶mCnt, ¶mPtr, "epc.leaf_turnover", "%lf", 0.27, 1); default_object_list[i].epc.day_leafon = getIntParam(¶mCnt, ¶mPtr, "epc.day_leafon", "%d", 91, 1); default_object_list[i].epc.day_leafoff = getIntParam(¶mCnt, ¶mPtr, "epc.day_leafoff", "%d", 260, 1); default_object_list[i].epc.ndays_expand = getIntParam(¶mCnt, ¶mPtr, "epc.ndays_expand", "%d", 30, 1); default_object_list[i].epc.ndays_litfall = getIntParam(¶mCnt, ¶mPtr, "epc.ndays_litfall", "%d", 30, 1); default_object_list[i].epc.leaf_cn = getDoubleParam(¶mCnt, ¶mPtr, "epc.leaf_cn", "%lf", 45.0, 1); default_object_list[i].epc.leaflitr_cn = getDoubleParam(¶mCnt, ¶mPtr, "epc.leaflitr_cn", "%lf", 70.0, 1); default_object_list[i].min_heat_capacity = getDoubleParam(¶mCnt, ¶mPtr, "min_heat_capacity", "%lf", 0.0, 1); default_object_list[i].max_heat_capacity = getDoubleParam(¶mCnt, ¶mPtr, "max_heat_capacity", "%lf", 0.0, 1); default_object_list[i].epc.allocation_flag = parse_alloc_flag(getStrParam(¶mCnt, ¶mPtr, "epc.allocation_flag", "%s", "waring", 1)); /*--------------------------------------------------------------*/ /* NOTE: PLACE ANY GROW READING HERE. */ /*--------------------------------------------------------------*/ if ( (default_object_list[i].epc.leaflitr_cn < default_object_list[i].epc.leaf_cn) && (command_line[0].grow_flag > 0) ){ fprintf(stderr, "\nWARNING construct_stratum_defaults"); fprintf(stderr, "\n leaf litter C:N < leaf C:N"); } default_object_list[i].epc.storage_transfer_prop = getDoubleParam(¶mCnt, ¶mPtr, "epc.storage_transfer_prop", "%lf", 1.0, 1); default_object_list[i].epc.froot_turnover = getDoubleParam(¶mCnt, ¶mPtr, "epc.froot_turnover", "%lf", 0.27, 1); if ((default_object_list[i].epc.veg_type == GRASS) || (default_object_list[i].epc.veg_type == C4GRASS)) { default_object_list[i].epc.deadleaf_turnover = getDoubleParam(¶mCnt, ¶mPtr, "epc.deadleaf_turnover", "%lf", 1.0, 1); } else { default_object_list[i].epc.livewood_turnover = getDoubleParam(¶mCnt, ¶mPtr, "epc.livewood_turnover", "%lf", 0.7, 1); } default_object_list[i].epc.kfrag_base = getDoubleParam(¶mCnt, ¶mPtr, "epc.kfrag_base", "%lf", 0.01, 1); default_object_list[i].epc.max_daily_mortality = getDoubleParam(¶mCnt, ¶mPtr, "epc.max_daily_mortality", "%lf", 0.005, 1) / 365; default_object_list[i].epc.min_daily_mortality = getDoubleParam(¶mCnt, ¶mPtr, "epc.min_daily_mortality", "%lf", 0.005, 1) / 365; default_object_list[i].epc.daily_mortality_threshold = getDoubleParam(¶mCnt, ¶mPtr, "epc.daily_mortality_threshold", "%lf",0.0,1); default_object_list[i].epc.froot_cn = getDoubleParam(¶mCnt, ¶mPtr, "epc.froot_cn", "%lf", 139.7, 1); default_object_list[i].epc.livewood_cn = getDoubleParam(¶mCnt, ¶mPtr, "epc.livewood_cn", "%lf", 200.0, 1); default_object_list[i].epc.leaflitr_flab = getDoubleParam(¶mCnt, ¶mPtr, "epc.leaflitr_flab", "%lf", 0.31, 1); // Skipping epc.leaflitr_fcel (pcs 20130117 : comment or var name wrong in orig code: defs/veg_westhemlock.def has 'leaflitr_fcel') fcel = getDoubleParam(¶mCnt, ¶mPtr, "epc.leaflitr_fcel", "%lf", 0.45, 1); // param name in file is "leaflitr_fcel" default_object_list[i].epc.leaflitr_flig = getDoubleParam(¶mCnt, ¶mPtr, "epc.leaflitr_flig", "%lf", 0.24, 1); if ( (float)(epc->leaflitr_flig + epc->leaflitr_flab + fcel) != 1.0 ) { fprintf(stderr,"\nFATAL ERROR construct_stratum_defaults"); fprintf(stderr,"\n litter proportions of labile, cell. and lignin must sum to 1.0"); fprintf(stderr," \n for default ID %d \n", default_object_list[i].ID); exit(EXIT_FAILURE); } lig_cel_ratio = epc->leaflitr_flig/fcel; /* calculate shielded and unshielded cellulose fraction */ if (lig_cel_ratio < 0.45){ epc->leaflitr_fscel = 0.0; epc->leaflitr_fucel = fcel; } else{ if ((lig_cel_ratio > 0.45) && (lig_cel_ratio < 0.7)){ epc->leaflitr_fscel= (lig_cel_ratio - 0.45)*3.2*fcel; epc->leaflitr_fucel = (1.0 - 3.2*(lig_cel_ratio - 0.45))*fcel; } else { epc->leaflitr_fscel = 0.8*fcel; epc->leaflitr_fucel = 0.2*fcel; } } default_object_list[i].epc.frootlitr_flab = getDoubleParam(¶mCnt, ¶mPtr, "epc.frootlitr_flab", "%lf", 0.23, 1); // Skipping the mortality parameter fcel = getDoubleParam(¶mCnt, ¶mPtr, "epc.frootlitr_fcel", "%lf", 0.41, 1); default_object_list[i].epc.frootlitr_flig = getDoubleParam(¶mCnt, ¶mPtr, "epc.frootlitr_flig", "%lf", 0.36, 1); if ( (float)(epc->frootlitr_flab + epc->frootlitr_flig + fcel) != 1.0 ){ fprintf(stderr,"\nFATAL ERROR construct_stratum_defaults"); fprintf(stderr,"\n froot litter proportions of labile, cell. and lignin must sum to 1.0\n"); exit(EXIT_FAILURE); } lig_cel_ratio = epc->frootlitr_flig/fcel; /* calculate shielded and unshielded cellulose fraction */ if (lig_cel_ratio < 0.45) { epc->frootlitr_fscel = 0.0; epc->frootlitr_fucel = fcel; } else{ if ((lig_cel_ratio > 0.45) && (lig_cel_ratio < 0.7)){ epc->frootlitr_fscel= (lig_cel_ratio - 0.45)*3.2*fcel; epc->frootlitr_fucel = (1.0 - 3.2*(lig_cel_ratio - 0.45))*fcel; } else{ epc->frootlitr_fscel = 0.8*fcel; epc->frootlitr_fucel = 0.2*fcel; } } fcel = getDoubleParam(¶mCnt, ¶mPtr, "epc.deadwood_fcel", "%lf", 0.52, 1); default_object_list[i].epc.deadwood_flig = getDoubleParam(¶mCnt, ¶mPtr, "epc.deadwood_flig", "%lf", 0.48, 1); if (epc->veg_type == TREE) { if ( (float)(epc->deadwood_flig + fcel) != 1.0 ){ fprintf(stderr,"\nFATAL ERROR construct_stratum_defaults"); fprintf(stderr,"\n dead wood proportions of labile, cell. and lignin must sum to 1.0\n"); exit(EXIT_FAILURE); } lig_cel_ratio = epc->deadwood_flig/fcel; /* calculate shielded and unshielded cellulose fraction */ if (lig_cel_ratio < 0.45) { epc->deadwood_fscel = 0.0; epc->deadwood_fucel = fcel; } else{ if ((lig_cel_ratio > 0.45) && (lig_cel_ratio < 0.7)){ epc->deadwood_fscel= (lig_cel_ratio - 0.45)*3.2*fcel; epc->deadwood_fucel = (1.0 - 3.2*(lig_cel_ratio - 0.45))*fcel; } else{ epc->deadwood_fscel = 0.8*fcel; epc->deadwood_fucel = 0.2*fcel; } } /* epc->deadwood_cn = ((epc->deadwood_fucel + epc->deadwood_fscel + epc->deadwood_flig) * CEL_CN * LIG_CN ) / (LIG_CN * (epc->deadwood_fucel + epc->deadwood_fscel) + CEL_CN * epc->deadwood_flig); if (epc->deadwood_cn < epc->livewood_cn){ fprintf(stderr,"\nFATAL ERROR: construct_canopy_stratum"); fprintf(stderr,"\ndeadwood C:N must be > livewood C:N"); exit(EXIT_FAILURE); } */ epc->deadwood_cn = (epc->deadwood_fucel + epc->deadwood_fscel) * CEL_CN + (epc->deadwood_flig) * LIG_CN; } /* end if tree */ else { epc->deadwood_flig = 0.0; epc->deadwood_fucel = 0.0; epc->deadwood_fscel = 0.0; epc->deadwood_cn = 0.0; } default_object_list[i].epc.alloc_frootc_leafc = getDoubleParam(¶mCnt, ¶mPtr, "epc.alloc_frootc_leafc", "%lf", 1.325, 1); default_object_list[i].epc.alloc_crootc_stemc = getDoubleParam(¶mCnt, ¶mPtr, "epc.alloc_crootc_stemc", "%lf", 0.3, 1); default_object_list[i].epc.alloc_stemc_leafc = getDoubleParam(¶mCnt, ¶mPtr, "epc.alloc_stemc_leafc", "%lf", 1.62, 1); default_object_list[i].epc.alloc_livewoodc_woodc = getDoubleParam(¶mCnt, ¶mPtr, "epc.alloc_livewoodc_woodc", "%lf", 0.073, 1); if (epc->veg_type != TREE){ epc->alloc_crootc_stemc = 0.0; epc->phloemcsa_per_alllai = 0.0; } default_object_list[i].epc.alloc_maxlgf = getDoubleParam(¶mCnt, ¶mPtr, "epc.maxlgf", "%lf", 0.05, 1); // param named 'epc.maxlgf' in parameter file default_object_list[i].epc.alloc_prop_day_growth = getDoubleParam(¶mCnt, ¶mPtr, "epc.alloc_prop_day_growth", "%lf", 0.5, 1); default_object_list[i].epc.dynamic_alloc_prop_day_growth = getIntParam(¶mCnt, ¶mPtr, "epc.dyn_alloc_prop_day_growth", "%d", 0, 1); default_object_list[i].epc.daily_fire_turnover = getDoubleParam(¶mCnt, ¶mPtr, "epc.daily_fire_turnover", "%lf", 0.0, 1); default_object_list[i].epc.height_to_stem_exp = getDoubleParam(¶mCnt, ¶mPtr, "epc.height_to_stem_exp", "%lf", 0.57, 1); default_object_list[i].epc.height_to_stem_coef = getDoubleParam(¶mCnt, ¶mPtr, "epc.height_to_stem_coef", "%lf", 11.39, 1); /*--------------------------------------------------------------*/ /* optionally read in parameters on re-sprouting */ /* and other newly implemented vegetation routines */ /*--------------------------------------------------------------*/ default_object_list[i].epc.min_leaf_carbon = getDoubleParam(¶mCnt, ¶mPtr, "epc.min_leaf_carbon", "%lf", 0.0005, 1); default_object_list[i].epc.max_years_resprout = getIntParam(¶mCnt, ¶mPtr, "epc.max_years_resprout", "%d", 100, 1); default_object_list[i].epc.resprout_leaf_carbon = getDoubleParam(¶mCnt, ¶mPtr, "epc.resprout_leaf_carbon", "%lf", 0.001, 1); default_object_list[i].epc.litter_gsurf_slope = getDoubleParam(¶mCnt, ¶mPtr, "epc.litter_gsurf_slope", "%lf", 0.0, 1); default_object_list[i].epc.litter_gsurf_intercept = getDoubleParam(¶mCnt, ¶mPtr, "epc.litter_gsurf_intercept", "%lf", 100000000, 1); default_object_list[i].epc.coef_CO2 = getDoubleParam(¶mCnt, ¶mPtr, "epc.coef_CO2", "%lf", 1.0, 1); default_object_list[i].epc.root_growth_direction = getDoubleParam(¶mCnt, ¶mPtr, "epc.root_growth_direction", "%lf", 0.8, 1); default_object_list[i].epc.root_distrib_parm = getDoubleParam(¶mCnt, ¶mPtr, "epc.root_distrib_parm", "%lf", 8.0, 1); default_object_list[i].epc.crown_ratio = getDoubleParam(¶mCnt, ¶mPtr, "epc.crown_ratio", "%lf", 0.6, 1); if (epc->veg_type != TREE) default_object_list[i].epc.crown_ratio = 1.0; /*--------------------------------------------------------------*/ /* default values for phenology (leaf onset/offset) model parameters */ /* are set based on Jolly et al., 2005, Global Change Biology */ /* who defined a globally uniform parameter set */ /*--------------------------------------------------------------*/ default_object_list[i].epc.gs_tmin = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_tmin", "%lf", -2.0, 1); default_object_list[i].epc.gs_tmax = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_tmax", "%lf", 5.0, 1); default_object_list[i].epc.gs_vpd_min = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_vpd_min", "%lf", 900, 1); default_object_list[i].epc.gs_vpd_max = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_vpd_max", "%lf", 4100, 1); default_object_list[i].epc.gs_dayl_min = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_dayl_min", "%lf", 36000, 1); default_object_list[i].epc.gs_dayl_max = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_dayl_max", "%lf", 39600, 1); default_object_list[i].epc.gs_psi_min = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_psi_min", "%lf", -15.0, 1); default_object_list[i].epc.gs_psi_max = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_psi_max", "%lf", -14.0, 1); default_object_list[i].epc.gs_ravg_days = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_ravg_days", "%lf", 6, 1); default_object_list[i].epc.gsi_thresh = getDoubleParam(¶mCnt, ¶mPtr, "epc.gsi_thresh", "%lf", 0.5, 1); default_object_list[i].epc.gs_npp_on = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_npp_on", "%lf", 1, 1); default_object_list[i].epc.gs_npp_slp = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_npp_slp", "%lf", 187, 1); default_object_list[i].epc.gs_npp_intercpt = getDoubleParam(¶mCnt, ¶mPtr, "epc.gs_npp_intercpt", "%lf", 197, 1); default_object_list[i].epc.max_storage_percent = getDoubleParam(¶mCnt, ¶mPtr, "epc.max_storage_percent", "%lf", 0.2, 1); default_object_list[i].epc.min_percent_leafg = getDoubleParam(¶mCnt, ¶mPtr, "epc.min_percent_leafg", "%lf", default_object_list[i].epc.leaf_turnover, 1); default_object_list[i].epc.dickenson_pa = getDoubleParam(¶mCnt, ¶mPtr, "epc.dickenson_pa", "%lf", 0.25, 1); default_object_list[i].epc.waring_pa = getDoubleParam(¶mCnt, ¶mPtr, "epc.waring_pa", "%lf", 0.8, 1); default_object_list[i].epc.waring_pb = getDoubleParam(¶mCnt, ¶mPtr, "epc.waring_pb", "%lf", 2.5, 1); default_object_list[i].epc.branch_turnover = getDoubleParam(¶mCnt, ¶mPtr, "epc.branch_turnover", "%lf", 0.0, 1) / 365.0; default_object_list[i].epc.Tacclim = getIntParam(¶mCnt, ¶mPtr, "epc.Tacclim", "%d", 0, 1); default_object_list[i].epc.Tacclim_intercpt = getDoubleParam(¶mCnt, ¶mPtr, "epc.Tacclim_intercpt", "%lf",3.22, 1); default_object_list[i].epc.Tacclim_slp = getDoubleParam(¶mCnt, ¶mPtr, "epc.Tacclim_slp", "%lf",0.046, 1); default_object_list[i].epc.Tacclim_days = getIntParam(¶mCnt, ¶mPtr, "epc.Tacclim_days", "%d", 30, 1); /*--------------------------------------------------------------*/ /* litter is assumed to have a mositure capacity of */ /* given by litter_moist_coef default assumes */ /* 200% moisture content by weight following */ /* Helvey, 1964 (deciduous forest in Coweeta) and */ /* Ogee and Brunet (2002) J of Hydrology, for a pine */ /* forest - */ /* so capacity in m is 2*litter carbon * 2(carbon to biomass */ /* / density of water */ /* similarly for litter depth but we assume an organic */ /* matter density */ /*--------------------------------------------------------------*/ default_object_list[i].epc.litter_moist_coef = getDoubleParam(¶mCnt, ¶mPtr, "epc.litter_moist_coef", "%lf", 2.0/1000.0, 1); default_object_list[i].epc.litter_density = getDoubleParam(¶mCnt, ¶mPtr, "epc.litter_density", "%lf", 100.0/2.0, 1); default_object_list[i].epc.gs_psi_range = default_object_list[i].epc.gs_psi_max-default_object_list[i].epc.gs_psi_min; default_object_list[i].epc.gs_dayl_range = default_object_list[i].epc.gs_dayl_max-default_object_list[i].epc.gs_dayl_min; default_object_list[i].epc.gs_vpd_range = default_object_list[i].epc.gs_vpd_max-default_object_list[i].epc.gs_vpd_min; default_object_list[i].epc.gs_trange = default_object_list[i].epc.gs_tmax-default_object_list[i].epc.gs_tmin; /*--------------------------------------------------------------*/ /* plant type defaults - are you an nfixer - are you edible */ /*--------------------------------------------------------------*/ default_object_list[i].epc.nfix = getIntParam(¶mCnt, ¶mPtr, "epc.nfix", "%d", 0, 1); default_object_list[i].epc.edible = getIntParam(¶mCnt, ¶mPtr, "epc.edible", "%d", 1, 1); default_object_list[i].epc.psi_curve = getIntParam(¶mCnt, ¶mPtr, "epc.psi_curve", "%d", 0, 1); default_object_list[i].epc.psi_threshold = getDoubleParam(¶mCnt, ¶mPtr, "epc.psi_threshold", "%lf", -1, 1); default_object_list[i].epc.psi_slp = getDoubleParam(¶mCnt, ¶mPtr, "epc.psi_slp", "%lf", 0.2, 1); default_object_list[i].epc.psi_intercpt = getDoubleParam(¶mCnt, ¶mPtr, "epc.psi_intercpt", "%lf", 1.0, 1); /*--------------------------------------------------------------*/ /* set sunlit sla multiplier this should be an input */ /*--------------------------------------------------------------*/ default_object_list[i].epc.shade_sla_mult = 1.0; /*--------------------------------------------------------------*/ /* Apply sensitivity analysis if appropriate */ /*--------------------------------------------------------------*/ if (command_line[0].vgsen_flag == 1) { default_object_list[i].epc.proj_sla *= command_line[0].veg_sen1; default_object_list[i].epc.shade_sla_mult *= command_line[0].veg_sen2; } /*--------------------------------------------------------------*/ /* Close the ith default file. */ /*--------------------------------------------------------------*/ memset(strbuf, '\0', strbufLen); strcpy(strbuf, default_files[i]); char *s = strbuf; char *y = NULL; char *token = NULL; char filename[256]; // Store filename portion of path in 't' while ((token = strtok(s, "/")) != NULL) { // Save the latest component of the filename strcpy(filename, token); s = NULL; } // Remove the file extension, if one exists memset(strbuf, '\0', strbufLen); strcpy(strbuf, filename); free(s); s = strbuf; token = strtok(s, "."); if (token != NULL) { strcpy(filename, token); } memset(outFilename, '\0', filenameLen); // Concatenate the output prefix with the filename of the input .def file // and "_stratum.params" if (command_line[0].output_prefix != NULL) { strcat(outFilename, command_line[0].output_prefix); if (filename != NULL) { strcat(outFilename, "_"); strcat(outFilename, filename); } strcat(outFilename, "_stratum.params"); } else { if (filename != NULL) { strcat(outFilename, "_"); strcat(outFilename, filename); } strcat(outFilename, "stratum.params"); } printParams(paramCnt, paramPtr, outFilename); } /*end for*/ if (paramPtr != NULL) free(paramPtr); return(default_object_list); } /*end construct_stratum_defaults*/
void* Allocator::_allocZeroed(size_t size, size_t& allocatedSize) { void* p = alloc(size, allocatedSize); if (p != NULL) ::memset(p, 0, allocatedSize); return p; }
void test_table_min() { std::cout << "----- test_table_min -----\n"; datalog::table_signature sig; sig.push_back(2); sig.push_back(4); sig.push_back(8); smt_params params; ast_manager ast_m; datalog::register_engine re; datalog::context ctx(ast_m, re, params); datalog::relation_manager & m = ctx.get_rel_context()->get_rmanager(); m.register_plugin(alloc(datalog::bitvector_table_plugin, m)); datalog::table_base* tbl = mk_bv_table(m, sig); datalog::table_base& table = *tbl; datalog::table_fact row, row1, row2, row3; row.push_back(1); row.push_back(2); row.push_back(5); // Group (1,2,*) row1 = row; row[2] = 6; row2 = row; row[2] = 5; row3 = row; table.add_fact(row1); table.add_fact(row2); table.add_fact(row3); // Group (1,3,*) row[1] = 3; row1 = row; row[2] = 7; row2 = row; row[2] = 4; row3 = row; table.add_fact(row1); table.add_fact(row2); table.add_fact(row3); table.display(std::cout); unsigned_vector group_by(2); group_by[0] = 0; group_by[1] = 1; datalog::table_min_fn * min_fn = m.mk_min_fn(table, group_by, 2); datalog::table_base * min_tbl = (*min_fn)(table); min_tbl->display(std::cout); row[1] = 2; row[2] = 5; SASSERT(min_tbl->contains_fact(row)); row[1] = 3; row[2] = 4; SASSERT(min_tbl->contains_fact(row)); dealloc(min_fn); min_tbl->deallocate(); tbl->deallocate(); }
struct zone_object *construct_zone( struct command_line_object *command_line, FILE *world_file, int num_world_base_stations, struct base_station_object **world_base_stations, struct default_object *defaults) { /*--------------------------------------------------------------*/ /* Local function definition. */ /*--------------------------------------------------------------*/ struct base_station_object *assign_base_station( int , int , struct base_station_object **); struct patch_object *construct_patch( struct command_line_object *, FILE *, int num_world_base_stations, struct base_station_object **world_base_stations, struct default_object *defaults); void *alloc(size_t, char *, char *); double atm_pres( double ); /*--------------------------------------------------------------*/ /* Local variable definition. */ /*--------------------------------------------------------------*/ int base_stationID; int i; int default_object_ID; char record[MAXSTR]; struct zone_object *zone; /*--------------------------------------------------------------*/ /* Allocate a zone object. */ /*--------------------------------------------------------------*/ zone = (struct zone_object *) alloc( 1 * sizeof( struct zone_object ),"zone","construct_zone" ); /*--------------------------------------------------------------*/ /* Read in the next zone record for this hillslope. */ /*--------------------------------------------------------------*/ fscanf(world_file,"%d",&(zone[0].ID)); read_record(world_file, record); fscanf(world_file,"%lf",&(zone[0].x)); read_record(world_file, record); fscanf(world_file,"%lf",&(zone[0].y)); read_record(world_file, record); fscanf(world_file,"%lf",&(zone[0].z)); read_record(world_file, record); fscanf(world_file,"%d",&(default_object_ID)); read_record(world_file, record); fscanf(world_file,"%lf",&(zone[0].area)); read_record(world_file, record); fscanf(world_file,"%lf",&(zone[0].slope)); read_record(world_file, record); fscanf(world_file,"%lf",&(zone[0].aspect)); read_record(world_file, record); fscanf(world_file,"%lf",&(zone[0].precip_lapse_rate)); read_record(world_file, record); fscanf(world_file,"%lf",&(zone[0].e_horizon)); read_record(world_file, record); fscanf(world_file,"%lf",&(zone[0].w_horizon)); read_record(world_file, record); fscanf(world_file,"%d",&(zone[0].num_base_stations)); read_record(world_file, record); /*--------------------------------------------------------------*/ /* convert from degrees to radians for slope and aspects */ /*--------------------------------------------------------------*/ zone[0].aspect = zone[0].aspect * DtoR; zone[0].slope = zone[0].slope * DtoR; /*--------------------------------------------------------------*/ /* Define cos and sine of slopes and aspects. */ /*--------------------------------------------------------------*/ zone[0].cos_aspect = cos(zone[0].aspect); zone[0].cos_slope = cos(zone[0].slope); zone[0].sin_aspect = sin(zone[0].aspect); zone[0].sin_slope = sin(zone[0].slope); /*--------------------------------------------------------------*/ /* Initialize accumulator variables */ /*--------------------------------------------------------------*/ zone[0].acc_month.K_direct = 0.0; zone[0].acc_month.K_diffuse = 0.0; zone[0].acc_month.tmax = 0.0; zone[0].acc_month.tmin = 0.0; zone[0].acc_month.precip = 0.0; zone[0].acc_month.length = 0; /*--------------------------------------------------------------*/ /* Define hourly array zone */ /*--------------------------------------------------------------*/ zone[0].hourly = (struct zone_hourly_object *) alloc( sizeof( struct zone_hourly_object ), "hourly","zone_hourly"); /*--------------------------------------------------------------*/ /* Assign defaults for this zone */ /*--------------------------------------------------------------*/ zone[0].defaults = (struct zone_default **) alloc( sizeof(struct zone_default *),"defaults", "construct_zone" ); i = 0; while (defaults[0].zone[i].ID != default_object_ID) { i++; /*--------------------------------------------------------------*/ /* Report an error if no match was found. Otherwise assign */ /* the default to point to this zone. */ /*--------------------------------------------------------------*/ if ( i>= defaults[0].num_zone_default_files ){ fprintf(stderr, "\nFATAL ERROR: in construct_zone, zone default ID %d not found.\n", default_object_ID); exit(EXIT_FAILURE); } } /* end-while */ zone[0].defaults[0] = &defaults[0].zone[i]; /*--------------------------------------------------------------*/ /* Allocate a list of base stations for this zone. */ /*--------------------------------------------------------------*/ zone[0].base_stations = (struct base_station_object **) alloc(zone[0].num_base_stations * sizeof(struct base_station_object *), "base_stations","construct_zone" ); /*--------------------------------------------------------------*/ /* Read each base_station ID and then point to that base station */ /*--------------------------------------------------------------*/ for (i=0 ; i<zone[0].num_base_stations ; i++ ){ fscanf(world_file,"%d",&(base_stationID)); read_record(world_file, record); /*--------------------------------------------------------------*/ /* Point to the appropriate base station in the base */ /* station list for this world. */ /* */ /*--------------------------------------------------------------*/ zone[0].base_stations[i] = assign_base_station( base_stationID, num_world_base_stations, world_base_stations); } /*end for*/ /*--------------------------------------------------------------*/ /* Read in number of patches in this zone. */ /*--------------------------------------------------------------*/ fscanf(world_file,"%d",&(zone[0].num_patches)); read_record(world_file, record); /*--------------------------------------------------------------*/ /* Allocate list of pointers to patch objects . */ /*--------------------------------------------------------------*/ zone[0].patches = ( struct patch_object ** ) alloc( zone[0].num_patches * sizeof( struct patch_object *), "patches","construct_zone"); /*--------------------------------------------------------------*/ /* Initialize any variables that should be initialized at */ /* the start of a simulation run for the zone. */ /* for temperaturature we initialize to 999 so that they will be set on the first day based */ /* on air temperatures on that day - which we don't know at this point */ /*--------------------------------------------------------------*/ zone[0].metv.pa = atm_pres( zone[0].z ); zone[0].metv.tsoil_sum = 0.0; zone[0].metv.tsoil = 0.0; zone[0].metv.tmin_ravg = 3.0; zone[0].metv.vpd_ravg = 900; zone[0].metv.dayl_ravg = 38000; /*--------------------------------------------------------------*/ /* Construct the intervals in this zone. */ /*--------------------------------------------------------------*/ for ( i=0 ; i<zone[0].num_patches ; i++ ){ zone[0].patches[i] = construct_patch( command_line, world_file, num_world_base_stations, world_base_stations, defaults); zone[0].patches[i][0].zone = zone; } /*end for*/ return(zone); } /*end construct_zone.c*/
void doswit(Node *n) { Case *c; C1 *q, *iq, *iqh, *iql; long def, nc, i, j, isv, nh; Prog *hsb; Node *vr[2]; int dup; def = 0; nc = 0; isv = 0; for(c = cases; c->link != C; c = c->link) { if(c->def) { if(def) diag(n, "more than one default in switch"); def = c->label; continue; } isv |= c->isv; nc++; } if(typev[n->type->etype]) isv = 1; else if(isv){ warn(n, "32-bit switch expression with 64-bit case constant"); isv = 0; } iq = alloc(nc*sizeof(C1)); q = iq; for(c = cases; c->link != C; c = c->link) { if(c->def) continue; if(c->isv && !isv) continue; /* can never match */ q->label = c->label; if(isv) q->val = c->val; else q->val = (long)c->val; /* cast ensures correct value for 32-bit switch on 64-bit architecture */ q++; } qsort(iq, nc, sizeof(C1), swcmp); if(debug['K']) for(i=0; i<nc; i++) print("case %2ld: = %.8llux\n", i, (vlong)iq[i].val); dup = 0; for(i=0; i<nc-1; i++) if(iq[i].val == iq[i+1].val) { diag(n, "duplicate cases in switch %lld", (vlong)iq[i].val); dup = 1; } if(dup) return; if(def == 0) { def = breakpc; nbreak++; } if(!isv || ewidth[TIND] > ewidth[TLONG] || n->op == OREGISTER) { swit1(iq, nc, def, n); return; } /* * 64-bit case on 32-bit machine: * switch on high-order words, and * in each of those, switch on low-order words */ if(n->op != OREGPAIR) fatal(n, "internal: expected register pair"); if(thechar == '8'){ /* TO DO: need an enquiry function */ vr[0] = n->left; /* low */ vr[1] = n->right; /* high */ }else{ vr[0] = n->right; vr[1] = n->left; } vr[0]->type = types[TLONG]; vr[1]->type = types[TLONG]; gbranch(OGOTO); hsb = p; iqh = alloc(nc*sizeof(C1)); iql = alloc(nc*sizeof(C1)); nh = 0; for(i=0; i<nc;){ iqh[nh].val = iq[i].val >> 32; q = iql; /* iq is sorted, so equal top halves are adjacent */ for(j = i; j < nc; j++){ if((iq[j].val>>32) != iqh[nh].val) break; q->val = (long)iq[j].val; q->label = iq[j].label; q++; } qsort(iql, q-iql, sizeof(C1), swcmp); iqh[nh].label = pc; nh++; swit1(iql, q-iql, def, vr[0]); i = j; } patch(hsb, pc); swit1(iqh, nh, def, vr[1]); }
// Allocate a default-constructed T as a proton object. // T must be a subclass of context. template <class T> static T *create() { return new(alloc(sizeof(T))) T(); }
/* verify */ void RSASigner::verify( const void *data, size_t dataLen, const void *sig, size_t sigLen) { StLock<Mutex> _(gMutex()); const char *op = NULL; bool throwSigVerify = false; if(mRsaKey == NULL) { CssmError::throwMe(CSSMERR_CSP_INTERNAL_ERROR); } /* get encoded digest info */ CssmAutoData encodedInfo(alloc()); int irtn = generateDigestInfo(data, dataLen, digestAlg(), encodedInfo, RSA_size(mRsaKey)); if(irtn) { rsaSigDebug("***digestInfo error\n"); CssmError::throwMe(/* FIXME */CSSMERR_CSP_INTERNAL_ERROR); } /* malloc decrypted signature */ unsigned char *decryptSig = (unsigned char *)alloc().malloc(RSA_size(mRsaKey)); unsigned decryptSigLen; /* signature should be encrypted digest info; decrypt the signature */ irtn = RSA_public_decrypt(sigLen, (unsigned char *)sig, decryptSig, mRsaKey, mPadding); if(irtn < 0) { op = "RSA_public_decrypt"; throwSigVerify = true; goto abort; } decryptSigLen = (unsigned)irtn; if(decryptSigLen != encodedInfo.length()) { rsaSigDebug("***Decrypted signature length error (exp %ld, got %d)\n", encodedInfo.length(), decryptSigLen); throwSigVerify = true; op = "RSA Sig length check"; goto abort; } if(memcmp(decryptSig, encodedInfo.data(), decryptSigLen)) { rsaSigDebug("***Signature miscompare\n"); throwSigVerify = true; op = "RSA Sig miscompare"; goto abort; } else { irtn = 0; } abort: if(decryptSig != NULL) { alloc().free(decryptSig); } if(throwSigVerify) { clearOpensslErrors(); CssmError::throwMe(CSSMERR_CSP_VERIFY_FAILED); } }
//_________________________________________________________________________ graph_molloy_hash::graph_molloy_hash(degree_sequence °s) { if(VERBOSE()) fprintf(stderr,"Allocating memory for graph..."); int s = alloc(degs); if(VERBOSE()) fprintf(stderr,"%d bytes allocated successfully\n",s); }
void gui_mch_draw_string( int row, int col, char_u *text, int len, int flags) { #ifndef MSWIN16_FASTTEXT static int *padding = NULL; static int pad_size = 0; int i; #endif HPEN hpen, old_pen; int y; #ifndef MSWIN16_FASTTEXT /* * Italic and bold text seems to have an extra row of pixels at the bottom * (below where the bottom of the character should be). If we draw the * characters with a solid background, the top row of pixels in the * character below will be overwritten. We can fix this by filling in the * background ourselves, to the correct character proportions, and then * writing the character in transparent mode. Still have a problem when * the character is "_", which gets written on to the character below. * New fix: set gui.char_ascent to -1. This shifts all characters up one * pixel in their slots, which fixes the problem with the bottom row of * pixels. We still need this code because otherwise the top row of pixels * becomes a problem. - webb. */ HBRUSH hbr; RECT rc; if (!(flags & DRAW_TRANSP)) { /* * Clear background first. * Note: FillRect() excludes right and bottom of rectangle. */ rc.left = FILL_X(col); rc.top = FILL_Y(row); #ifdef FEAT_MBYTE if (has_mbyte) { /* Compute the length in display cells. */ rc.right = FILL_X(col + mb_string2cells(text, len)); } else #endif rc.right = FILL_X(col + len); rc.bottom = FILL_Y(row + 1); hbr = CreateSolidBrush(gui.currBgColor); FillRect(s_hdc, &rc, hbr); DeleteBrush(hbr); SetBkMode(s_hdc, TRANSPARENT); /* * When drawing block cursor, prevent inverted character spilling * over character cell (can happen with bold/italic) */ if (flags & DRAW_CURSOR) { pcliprect = &rc; foptions = ETO_CLIPPED; } } #else /* * Alternative: write the characters in opaque mode, since we have blocked * bold or italic fonts. */ /* The OPAQUE mode and backcolour have already been set */ #endif /* The forecolor and font have already been set */ #ifndef MSWIN16_FASTTEXT if (pad_size != Columns || padding == NULL || padding[0] != gui.char_width) { vim_free(padding); pad_size = Columns; padding = (int *)alloc(pad_size * sizeof(int)); if (padding != NULL) for (i = 0; i < pad_size; i++) padding[i] = gui.char_width; } #endif /* * We have to provide the padding argument because italic and bold versions * of fixed-width fonts are often one pixel or so wider than their normal * versions. * No check for DRAW_BOLD, Windows will have done it already. */ #ifndef MSWIN16_FASTTEXT ExtTextOut(s_hdc, TEXT_X(col), TEXT_Y(row), 0, NULL, (char *)text, len, padding); #else TextOut(s_hdc, TEXT_X(col), TEXT_Y(row), (char *)text, len); #endif if (flags & DRAW_UNDERL) { hpen = CreatePen(PS_SOLID, 1, gui.currFgColor); old_pen = SelectObject(s_hdc, hpen); /* When p_linespace is 0, overwrite the bottom row of pixels. * Otherwise put the line just below the character. */ y = FILL_Y(row + 1) - 1; #ifndef MSWIN16_FASTTEXT if (p_linespace > 1) y -= p_linespace - 1; #endif MoveToEx(s_hdc, FILL_X(col), y, NULL); /* Note: LineTo() excludes the last pixel in the line. */ LineTo(s_hdc, FILL_X(col + len), y); DeleteObject(SelectObject(s_hdc, old_pen)); } }
int pain(void *aio) { long int io = 0; caddr_t kp; int ksize; struct stat sb; extern u_int16_t timelimit; xdinit(aio); if (consinit(NULL)) /* Initialize fresh console */ return(1); #ifdef PPCBOOTER printf("NetBSD/AmigaPPC " NETBSD_VERS " Primary Bootstrap %s\n", bootprog_rev); #else printf("NetBSD/Amiga " NETBSD_VERS " Primary Bootstrap %s\n", bootprog_rev); #endif io = open("/boot.amiga", 0); /* Try /boot.amiga first */ if (io < 0) { io = open("/boot", 0); /* Fallback to /boot */ if (io < 0) { io = open("/boot.ami", 0); /* 8.3 name? */ if (io < 0) { goto err; } } } /* get size of file? */ if (fstat(io, &sb)) goto err; /* allocate memory for file */ ksize = sb.st_size; if (ksize == 0) { printf("Bad size, using 32K\n"); /* XXX debug? */ ksize = 32 * 1024; } kp = alloc(ksize); if (kp == 0) { errno = ENOMEM; goto err; } /* read file into memory */ if (read(io, kp, ksize) != ksize) { errno = ENOEXEC; goto freeall; } /* validate boot: DOS\0 and checksum? */ if (strcmp(kp, "DOS") != 0 && (*(u_int32_t *)kp) != 0x424f4f54) { errno = ENOEXEC; goto freeall; } /* call boot+12(aio, sysbase); */ close(io); startit(kp, aio, ConsoleBase); errno = -1; freeall: free(kp, ksize); err: printf("Error %ld\n", (long)errno); close(io); timelimit = 10; (void)getchar(); consclose(); return 1; }
/* * Initialise the GUI. Create all the windows, set up all the call-backs * etc. */ int gui_mch_init(void) { const char szVimWndClass[] = VIM_CLASS; const char szTextAreaClass[] = "VimTextArea"; WNDCLASS wndclass; #ifdef WIN16_3DLOOK Ctl3dRegister(s_hinst); Ctl3dAutoSubclass(s_hinst); #endif /* Display any pending error messages */ display_errors(); gui.scrollbar_width = GetSystemMetrics(SM_CXVSCROLL); gui.scrollbar_height = GetSystemMetrics(SM_CYHSCROLL); #ifdef FEAT_MENU gui.menu_height = 0; /* Windows takes care of this */ #endif gui.border_width = 0; gui.currBgColor = INVALCOLOR; s_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); if (GetClassInfo(s_hinst, szVimWndClass, &wndclass) == 0) { wndclass.style = 0; wndclass.lpfnWndProc = _WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = s_hinst; wndclass.hIcon = LoadIcon(wndclass.hInstance, MAKEINTRESOURCE(IDR_VIM)); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = s_brush; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szVimWndClass; if (( #ifdef GLOBAL_IME atom = #endif RegisterClass(&wndclass)) == 0) return FAIL; } s_hwnd = CreateWindow( szVimWndClass, "Vim MSWindows GUI", WS_OVERLAPPEDWINDOW, gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, 100, /* Any value will do */ 100, /* Any value will do */ NULL, NULL, s_hinst, NULL); if (s_hwnd == NULL) return FAIL; #ifdef GLOBAL_IME global_ime_init(atom, s_hwnd); #endif /* Create the text area window */ if (GetClassInfo(s_hinst, szTextAreaClass, &wndclass) == 0) { wndclass.style = CS_OWNDC; wndclass.lpfnWndProc = _TextAreaWndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = s_hinst; wndclass.hIcon = NULL; wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = NULL; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szTextAreaClass; if (RegisterClass(&wndclass) == 0) return FAIL; } s_textArea = CreateWindow( szTextAreaClass, "Vim text area", WS_CHILD | WS_VISIBLE, 0, 0, 100, /* Any value will do for now */ 100, /* Any value will do for now */ s_hwnd, NULL, s_hinst, NULL); if (s_textArea == NULL) return FAIL; #ifdef FEAT_MENU s_menuBar = CreateMenu(); #endif s_hdc = GetDC(s_textArea); #ifdef MSWIN16_FASTTEXT SetBkMode(s_hdc, OPAQUE); #endif DragAcceptFiles(s_hwnd, TRUE); /* Do we need to bother with this? */ /* m_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); */ /* Get background/foreground colors from the system */ gui_mch_def_colors(); /* Get the colors from the "Normal" group (set in syntax.c or in a vimrc * file) */ set_normal_colors(); /* * Check that none of the colors are the same as the background color. * Then store the current values as the defaults. */ gui_check_colors(); gui.def_norm_pixel = gui.norm_pixel; gui.def_back_pixel = gui.back_pixel; /* Get the colors for the highlight groups (gui_check_colors() might have * changed them) */ highlight_gui_started(); /* * Start out by adding the configured border width into the border offset */ gui.border_offset = gui.border_width; /* * compute a couple of metrics used for the dialogs */ get_dialog_font_metrics(); #ifdef FEAT_TOOLBAR /* * Create the toolbar */ initialise_toolbar(); #endif #ifdef MSWIN_FIND_REPLACE /* * Initialise the dialog box stuff */ s_findrep_msg = RegisterWindowMessage(FINDMSGSTRING); /* Initialise the struct */ s_findrep_struct.lStructSize = sizeof(s_findrep_struct); s_findrep_struct.lpstrFindWhat = alloc(MSWIN_FR_BUFSIZE); s_findrep_struct.lpstrFindWhat[0] = NUL; s_findrep_struct.lpstrReplaceWith = alloc(MSWIN_FR_BUFSIZE); s_findrep_struct.lpstrReplaceWith[0] = NUL; s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE; s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE; #endif return OK; }
datatype_decl * mk_datatype_decl(symbol const & n, unsigned num_constructors, constructor_decl * const * cs) { return alloc(datatype_decl, n, num_constructors, cs); }