void set_char_form(char c, void* form, u_char place) { u_int addr = c; addr <<= 3; if (place & place_1) vwrite(form, addr, 8); if (place & place_2) vwrite(form, (256 * 8) + addr, 8); if (place & place_3) vwrite(form, (256 * 8 * 2) + addr, 8); }
void set_char_attr(char c, void *attr, u_char place) { u_int addr = c; addr <<= 3; addr += MODE2_ATTR; if (place & place_1) vwrite(attr, addr, 8); if (place & place_2) vwrite(attr, (256 * 8) + addr, 8); if (place & place_3) vwrite(attr, (256 * 8 * 2) + addr, 8); }
void set_mangled_mode() { set_mode(mode_1); set_mode(0x7E); vwrite((void*)0x1BBF, 0x0800, 0x800); vwrite((void*)0x1BBF, 0x1000, 0x800); fill(MODE2_ATTR, 0xF0, 0x17FF); fill(0xFF8, 0xFF, 8); fill(0x17F8, 0xFF, 8); _init_sprites(); }
void blit_ram_vram(u_char* source, u_int dest, u_char w, u_char h, int sjmp, int djmp) { while (h--) { vwrite(source, dest, w); source += sjmp; dest += djmp; } }
void clear_across(int8_t y, int8_t x, int16_t l) { char_addr(y, x); vtcount = l; vtchar = ' '; vwrite(); }
void clear_lines(int8_t y, int8_t ct) { char_addr(y, 0); vtcount = ct * (uint16_t)VT_WIDTH; vtchar = ' '; vwrite(); }
void plot_char(int8_t y, int8_t x, uint16_t c) { char_addr(y,x); vtcount = 1; vtchar = c; vwrite(); }
Cerror Logger::write(const char *fmt, ...) { va_list ap; va_start (ap, fmt); auto e = vwrite(fmt, ap); va_end(ap); return e; }
/** * Schreibt Daten nur ins Log und auf stdout. * * @author FloSoft */ void Log::write(const char* format, ...) { va_list list; va_start(list, format); vwrite(format, list); va_end(list); }
/// Formatted write with arguments int fwrite(const char* fmt, ...) { va_list ap; va_start(ap, fmt); int result = vwrite(fmt, ap); va_end(ap); return result; }
/** * Schreibt Daten ins Log und auf stdout. * * @author FloSoft */ void Log::lvprintf(const char* format, va_list list) { va_list list2; va_copy(list2, list); ::vprintf(format, list); vwrite(format, list2); va_end(list2); }
/* * This function writes to the *virtual* memory as seen by the kernel. */ static ssize_t write_kmem(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { unsigned long p = *ppos; ssize_t wrote = 0; ssize_t virtr = 0; ssize_t written; char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */ if (p < (unsigned long) high_memory) { wrote = count; if (count > (unsigned long) high_memory - p) wrote = (unsigned long) high_memory - p; written = do_write_mem((void*)p, p, buf, wrote, ppos); if (written != wrote) return written; wrote = written; p += wrote; buf += wrote; count -= wrote; } if (count > 0) { kbuf = (char *)__get_free_page(GFP_KERNEL); if (!kbuf) return wrote ? wrote : -ENOMEM; while (count > 0) { int len = count; if (len > PAGE_SIZE) len = PAGE_SIZE; if (len) { written = copy_from_user(kbuf, buf, len); if (written) { ssize_t ret; free_page((unsigned long)kbuf); ret = wrote + virtr + (len - written); return ret ? ret : -EFAULT; } } len = vwrite(kbuf, (char *)p, len); count -= len; buf += len; virtr += len; p += len; } free_page((unsigned long)kbuf); } *ppos = p; return virtr + wrote; }
void put_sprite_16(u_char id, int x, int y, u_char handle, u_char color) { sprite_t sp; if (x < 0) { x += 32; color |= 128; } sp.y = y - 1; sp.x = x; sp.handle = (handle << 2); sp.color = color; vwrite(&sp, 6912 + (id << 2), 4); }
Cerror Log::dumpLevel(const char *level, const char *fmt, va_list ap) { auto l = log_.get(); auto e = Cerror(nullptr); if(!l) goto out; l->write("level=%s : ", level); e = l->vwrite(fmt, ap); l->write("\n"); out: return e; }
static void vfatal(const char *msg, va_list ap) { char *fmt; if (asprintf(&fmt, "fatal: %s", msg) == -1) exit(1); vwrite(fmt, ap); free(fmt); exit(1); }
main(int argc, char *argv[]) { FILE* f; bool preview; u_char buf[MAX_BUF]; // bouring argv stuff if (!--argc) { printf("Usage: ex8 [-]file.alf\n"); printf("\t- : preview mode\n"); printf("file must be of type GRAPHOS ALPHABET (.ALF)\n"); return 1; } preview = false; ++argv; if (*argv[0] == '-') { (*argv)++; preview = true; printf("preview mode on\n"); } // read file f = fopen(*argv, "rb"); if (!f) { printf("couldn't open file %s\n", *argv); return 2; } fseek(f, FILE_OFFS, 0); fread(buf + 8, 1, MAX_BUF - 8, f); fclose(f); buf[0]=buf[1]=buf[2]=buf[3]=buf[4]=buf[5]=buf[6]=buf[7]=0; // here is the thing: when not previewing, the vwrite will set // your whole char table with the given alphabet. nice :) set_mode((preview) ? mode_2 : mode_1); if (preview) { do_preview(buf); set_mode(mode_0); } else vwrite(buf + 8, VRAM_OFFS, MAX_BUF); }
void update_display(const char *buf, int nchar) { vwrite(1, buf, nchar); for (int i = 0; i < nchar; i++) update_display_char(buf[i]); }
void Logger::panic(const char *fmt, va_list ap) { vwrite(fmt, ap); exit(0); }
void set_sprite_16(u_char handle, void* data) { vwrite(data, 14336 + (handle << 5), 32); }
void set_sprite_8(u_char handle, void* data) { vwrite(data, 14336 + (handle << 3), 8); }
//before we load the index , do memory usage check //if run out of memory limitation, release void do_weed(idx_map_t *idx, trans_info_t *trans_log, const string &f) { uint64_t fc = 0; uint64_t ec = 0; string fname = config::conf_inputdir + "/" + f; string tmpname = config::conf_tmpdir + "/" + f + ".chk"; char tbs[16]; full_time_str(tbs, time(0)); //for memory mangment if (!mm_factor) { size_t total_node = atol(config::conf_maxmem.c_str()); total_node *= max_mem_unit; total_node /= key_max *atol(config::conf_records_per_node.c_str() ) ; mm_factor =atol(config::conf_records_per_node.c_str() ) / total_node; mylog->write("runtime mm_factor:%llu\n", (int64_t)mm_factor); #ifdef DEBUG_PRINT_L3 #endif } if (mm_factor== 0) { mm_factor = 1; } FILE *fpin = fopen(fname.c_str(), "r"); if (!fpin) { string msg= "can not open:" + fname; msg += ":"; msg += strerror(errno); throw runtime_error(msg); } FILE *fptmp = fopen(tmpname.c_str(), "w"); if (!fptmp) { string msg= "can not open:" + tmpname; msg += ":"; msg += strerror(errno); throw runtime_error(msg); } uint64_t records_per_node = atoi(config::conf_records_per_node.c_str() ); uint64_t max_mem = atol(config::conf_maxmem.c_str()) ; max_mem *= max_mem_unit; char dup_key[key_max]; find_visitor<char> fv(dup_key, mem_layout); string prev_file_idx; fcache_map_t :: iterator prev_trans_itr; idx_map_t::iterator prev_idx_itr; uint64_t sync_count = 0; vector <string> verr ; string cur_file_idx; char line_buf[line_max+1]; while (fgets(line_buf, line_max + 1, fpin)) { string cur_file_idx; fcache_map_t :: iterator cur_trans_itr; idx_map_t::iterator cur_idx_itr; //make the file index mk_file_idx(&cur_file_idx, line_buf); //make the duplicate key for record mk_dup_key(dup_key, line_buf); //do previous cache check if (cur_file_idx == prev_file_idx) { cur_trans_itr = prev_trans_itr; cur_idx_itr = prev_idx_itr; } else {//no cache node found , we need a new node cur_idx_itr = idx->find(cur_file_idx); cur_trans_itr = trans_log->idx_map.find(cur_file_idx); if (cur_trans_itr == trans_log->idx_map.end()) { file_cache_t fc; cur_trans_itr = trans_log->idx_map.insert( fcache_map_t::value_type(cur_file_idx, fc) ).first; } if (cur_idx_itr == idx->end()) {//this file index does not resident in memory mem_adjust(idx, max_mem); //do the MM( memory management) if( (fc-ec-sync_count) * 100 * mem_layout[0].len > max_mem* cache_max_percent ){ cache_write(config::conf_tmpdir, & trans_log->idx_map); mylog->write("cache_write:on records: %llu, mem:%llu,maxmem,%llu\n", fc-ec-sync_count, (fc-ec-sync_count) *mem_layout[0].len, max_mem); sync_count += fc-ec-sync_count; } data_node_t dn; dn.count = records_per_node; dn.data = new htable<char>(records_per_node, vector <int>(1, 0)); dn.data->set_layout(mem_layout); cur_idx_itr = idx->insert(idx_map_t::value_type(cur_file_idx, dn)).first; //check if it exist in the disk file string idx_disk_file = config::conf_idxdir + "/" + cur_file_idx; if (access(idx_disk_file.c_str(), F_OK) == 0) { // the index resident in the disk load_idx(cur_idx_itr->second.data, idx_disk_file); } // note , if we get a new index node, there may be the node out of synchronize //load it to memory too if (cur_trans_itr->second.cache.size()) { vector<string>::const_iterator vitr = cur_trans_itr->second.cache.begin(); while (vitr != cur_trans_itr->second.cache.end()) { char vec_buf[key_max]; vitr->copy(vec_buf, key_max); cur_idx_itr->second.data->insert(hnode<char>(vec_buf)); ++vitr; } } if(cur_trans_itr->second.file.length()){ load_idx( cur_idx_itr->second.data, cur_trans_itr->second.file); } } //update the cache node prev_trans_itr = cur_trans_itr; prev_idx_itr = cur_idx_itr; prev_file_idx = cur_file_idx; } //do the duplicate check fv.reset(); size_t hpos = hashstr(dup_key)%cur_idx_itr->second.data->size(); cur_idx_itr->second.data->at(hpos).accept(fv); ++ cur_idx_itr->second.count; ++fc; if (!fv.done()) { cur_idx_itr->second.data->insert(hpos, hnode<char>(dup_key)); cur_trans_itr->second.cache.push_back(dup_key); fputs(line_buf, fptmp); } else { //duplicate record string es = EDUP; es += line_buf; verr.push_back(es); ++ec; } } fclose(fptmp); fclose(fpin); //record the transaction file : map<string, file_cache_t >:: const_iterator citr ; for (citr = trans_log->idx_map.begin(); citr != trans_log->idx_map.end(); ++citr) { string fname = config::conf_idxdir + "/" + citr -> first; unsigned long long flen = 0; if (access(fname.c_str(), F_OK) == 0) { //not exist in the disk flen = file_size(fname); } char buf[64]; sprintf(buf, "%llu", (uint64_t) flen); string trun_cmd = truncate_cmd + cmd_separator + fname + cmd_separator + buf; trans_log->trans_cmd.push_back(trun_cmd); if (citr->second.file.length()) {// there is some index data synchronize to disk, remove it string rmtmp = rm_cmd; rmtmp += cmd_separator; rmtmp += citr->second.file; trans_log->trans_cmd.push_back(rmtmp); } } string fcmd; if (config::conf_is_backup == "yes") { fcmd= mv_cmd + cmd_separator + fname + cmd_separator + config::conf_bakdir + "/" +f; trans_log->trans_cmd.push_back(fcmd); } if (verr.size()) { string errname = config::conf_tmpdir + "/" + f + ".dup"; vwrite(errname, verr); fcmd= mv_cmd + cmd_separator + errname + cmd_separator + config::conf_errdir + "/" + f; size_t fl = fcmd.length(); fcmd.replace(fl - 4, 4, ".dup"); trans_log->trans_cmd.push_back(fcmd); } if (file_size(tmpname)) { fcmd= mv_cmd + cmd_separator + tmpname + cmd_separator + config::conf_outdir + "/" + f; size_t fl = fcmd.length(); string::size_type dot = f.rfind('.'); if(dot == string::npos){ fcmd += ".chk"; }else if(dot == (fl -4) ){ fcmd.replace(fl - 4, 4, ".chk"); }else{ fcmd += ".chk"; } trans_log->trans_cmd.push_back(fcmd); } else { fcmd= rm_cmd + cmd_separator + tmpname; trans_log->trans_cmd.push_back(fcmd); } char tbe[16]; full_time_str(tbe, time(0)); mylog->write("%s,%s,%llu,%llu,%llu,%llu,%llu,%s,%s,%s\n" , "ProcInfo" , f.c_str() , (uint64_t)fc , (uint64_t)(fc - ec) , (uint64_t)ec , (uint64_t) 0 , (uint64_t) file_size(fname) , tbs , tbe , config::conf_inputdir.c_str() ); }