static int __opendisk(const char *path, int flags, char *buf, size_t buflen, int iscooked, int (*ofn)(const char *, int, ...)) { #ifndef __minix int f, rawpart; #else int f; #endif if (buf == NULL) { errno = EFAULT; return (-1); } snprintf(buf, buflen, "%s", path); if ((flags & O_CREAT) != 0) { errno = EINVAL; return (-1); } #ifndef __minix rawpart = getrawpartition(); if (rawpart < 0) return (-1); /* sysctl(3) in getrawpartition sets errno */ #endif f = ofn(buf, flags, 0); if (f != -1 || errno != ENOENT) return (f); #ifndef __minix snprintf(buf, buflen, "%s%c", path, 'a' + rawpart); f = ofn(buf, flags, 0); if (f != -1 || errno != ENOENT) return (f); if (strchr(path, '/') != NULL) return (-1); snprintf(buf, buflen, "%s%s%s", _PATH_DEV, iscooked ? "" : "r", path); f = ofn(buf, flags, 0); if (f != -1 || errno != ENOENT) return (f); snprintf(buf, buflen, "%s%s%s%c", _PATH_DEV, iscooked ? "" : "r", path, 'a' + rawpart); f = ofn(buf, flags, 0); #endif return (f); }
bool FileDialog::ShowOpen(HWND owner) { if(_Handle) return 0;//防止同一实例打开两个对话框 Object<OPENFILENAME> ofn(true); ofn.Zero(); ofn->lStructSize = (DWORD)sizeof(OPENFILENAME); //文件类型组合框的内容.多文件类型用分号隔开.前一个是显示的文字,可以是任意字符.后一个是文件类型过滤字串,前两个字符必须是"*.". ofn->lpstrFilter = mFilter.Handle(); //这个参数是一个以NULL字符分开的多字符串,末尾必须有两个NULL字符(以此来确定结尾). ofn->lpstrFile = (LPWSTR)mFileNameBuffer.Handle(); WcsCopy(ofn->lpstrFile,DefaultFile.Handle(),DefaultFile.Length()); ofn->nMaxFile = 0x200000; ofn->lpstrTitle = Title; ofn->Flags = Flags; ofn->lpfnHook = mDlgProc.Procedure(); ofn->lpstrDefExt = DefaultExt.Handle(); ofn->FlagsEx = FlagsEx;//OFN_EX_NOPLACESBAR; ofn->lpstrInitialDir = InitDir; ofn->hwndOwner = owner; ofn->nFilterIndex = mFilterIndex; mSelectFiles.Clear(); bool r = ::GetOpenFileName(ofn.Handle())==1; if(r) { mSelectFiles.AddFromMemory(ofn->lpstrFile,-1); mFileNameBuffer.Desert(); } _Handle = 0; return r; }
//================================== void File2Code::gen() { std::ifstream in(m_infname.c_str()); if (!in.good()) { std::string err = std::string("Could not open '") + m_infname + "'"; throw std::runtime_error(err); } if (m_mode == JAVA) { std::string ofn(( m_dest_dir + "//" + m_fname + ".java" )); std::ofstream out( ofn.c_str( ) ); if ( !out.good() ) { throw std::runtime_error("Error opening file for writing " + ofn); } StrStrVecMap sm; generateMap(in, sm); genJavaFiles(sm); genMainJavaFile(out, sm); } else if (m_mode == CPP) { std::string ofn(( m_dest_dir + "//" + m_fname + ".h" )); std::ofstream out( ofn.c_str( ) ); if ( !out.good() ) { throw std::runtime_error("Error opening file for writing " + ofn); } m_linenum = std::numeric_limits<long>::max(); StrStrVecMap sm; generateMap(in, sm); genMainCppFile(out, sm); } }
bool FileDialog::ShowSave(HWND owner) { if(_Handle) return 0; Object<OPENFILENAME> ofn(true); ofn.Zero(); ofn->lStructSize = (DWORD)sizeof(OPENFILENAME); //文件类型组合框的内容.多文件类型用分号隔开.前一个是显示的文字,可以是任意字符.后一个是文件类型过滤字串,前两个字符必须是"*.". ofn->lpstrFilter = mFilter.Handle(); //这个参数是一个以NULL字符分开的多字符串,末尾必须有两个NULL字符(以此来确定结尾). ofn->lpstrFile = (LPWSTR)mFileNameBuffer.Handle(); WcsCopy(ofn->lpstrFile,DefaultFile.Handle(),DefaultFile.Length()); ofn->nMaxFile = 0x200000; ofn->lpstrTitle = Title; ofn->Flags = Flags; ofn->lpfnHook = mDlgProc.Procedure(); ofn->lpstrDefExt = DefaultExt.Handle(); ofn->FlagsEx = FlagsEx;//OFN_EX_NOPLACESBAR; ofn->lpstrInitialDir = InitDir; ofn->hwndOwner = owner; ofn->nFilterIndex = mFilterIndex; mSelectFiles.Clear(); bool r = ::GetSaveFileName(ofn.Handle())==1; if(r){ String fp = ofn->lpstrFile; String ext = ofn->lpstrFile; FPToExt(ext); if(ext.IsNull()){ uint ifilter = (uint)ofn->nFilterIndex*2 - 1; if(mFilter.Count()>ifilter){ ext = mFilter[ifilter]; uint i = ext.Length(); if(i>0) i--; for(;i>0;i--){ if(ext[i]=='.') break; } FPLinkExt(fp,ext+i); } } mSelectFiles.AddFromMemory(fp,-1); mFileNameBuffer.Desert(); } _Handle = 0; return r; }
void RTFEditor::OnSaveAs() { mol::bstr p; static wchar_t OutFilesFilter[] = _T("save as rtf *.rtf\0*.rtf\0save as file*.*\0*.*\0\0"); mol::FilenameDlg ofn(*this); ofn.setFilter( OutFilesFilter ); ofn.fileName(filename_); if ( ofn.dlgSave( OFN_OVERWRITEPROMPT| OFN_NOTESTFILECREATE| OFN_NOVALIDATE) ) { filename_ = ofn.fileName(); if ( ofn.index() == 1 ) { OnSave(); } else { std::string tmp; rtf_.streamOut(tmp); mol::filestream fs; if ( fs.open( mol::tostring(filename_)) ) { fs.write( tmp.c_str(), tmp.size() ); fs.flush(); fs.close(); } setText(filename_); statusBar()->status(_T("saved file")); } std::wostringstream oss; oss << "saved as " << filename_; statusBar()->status(oss.str()); } }
/* do one opcode (instruction or prefix) */ int z80ex_step(void) { Z80EX_BYTE opcode, d; z80ex_opcode_fn ofn = NULL; z80ex.doing_opcode = 1; z80ex.noint_once = 0; z80ex.reset_PV_on_int = 0; z80ex.tstate = 0; z80ex.op_tstate = 0; opcode = READ_OP_M1(); /* fetch opcode */ if (z80ex.int_vector_req) { TSTATES(2); /* interrupt eats two extra wait-states */ } R++; /* R increased by one on every first M1 cycle */ T_WAIT_UNTIL(4); /* M1 cycle eats min 4 t-states */ if (!z80ex.prefix) opcodes_base[opcode](); else { if ((z80ex.prefix | 0x20) == 0xFD && ((opcode | 0x20) == 0xFD || opcode == 0xED)) { z80ex.prefix = opcode; z80ex.noint_once = 1; /* interrupts are not accepted immediately after prefix */ } else { switch (z80ex.prefix) { case 0xDD: case 0xFD: if (opcode == 0xCB) { /* FD/DD prefixed CB opcodes */ d = READ_OP(); /* displacement */ temp_byte_s = (d & 0x80)? -(((~d) & 0x7f)+1): d; opcode = READ_OP(); #ifdef Z80EX_Z180_SUPPORT if (Z180_LIKELY(z80ex.z180)) { if (unlikely((opcode & 7) != 6 || opcode == 0x36)) ofn = trapping(z80ex.prefix, 0xCB, opcode, ITC_B3); else ofn = (z80ex.prefix == 0xDD) ? opcodes_ddcb[opcode] : opcodes_fdcb[opcode]; } else #endif ofn = (z80ex.prefix == 0xDD) ? opcodes_ddcb[opcode] : opcodes_fdcb[opcode]; } else { /* FD/DD prefixed base opcodes */ #ifdef Z80EX_Z180_SUPPORT if (unlikely(z80ex.z180 && opcodes_ddfd_bad_for_z180[opcode])) { ofn = trapping(z80ex.prefix, 0x00, opcode, ITC_B2); } else { #endif ofn = (z80ex.prefix == 0xDD) ? opcodes_dd[opcode] : opcodes_fd[opcode]; if (unlikely(ofn == NULL)) ofn = opcodes_base[opcode]; /* 'mirrored' instructions NOTE: this should NOT happen with Z180! */ #ifdef Z80EX_Z180_SUPPORT } #endif } break; case 0xED: /* ED opcodes */ #ifdef Z80EX_ED_TRAPPING_SUPPORT if (unlikely(opcode > 0xBB)) { /* check if ED-trap emu func accepted the opcode as its own "faked" */ if (z80ex_ed_cb(opcode)) { ofn = opcodes_base[0x00]; break; } } #endif #ifdef Z80EX_Z180_SUPPORT if (Z180_LIKELY(z80ex.z180)) ofn = opcodes_ed_z180[opcode]; else #endif ofn = opcodes_ed[opcode]; if (ofn == NULL) { #ifdef Z80EX_Z180_SUPPORT if (unlikely(z80ex.z180)) ofn = trapping(0x00, 0xED, opcode, ITC_B2); else #endif ofn = opcodes_base[0x00]; } break; case 0xCB: /* CB opcodes */ #ifdef Z80EX_Z180_SUPPORT if (unlikely(z80ex.z180 && (opcode & 0xF8) == 0x30)) ofn = trapping(0x00, 0xCB, opcode, ITC_B2); else #endif ofn = opcodes_cb[opcode]; break; default: /* this must'nt happen! */ assert(0); break; } ofn(); z80ex.prefix = 0; } } z80ex.doing_opcode = 0; return z80ex.tstate; }
bool LexicalReorderingTableTree::Create(std::istream& inFile, const std::string& outFileName) { std::string line; //TRACE_ERR("Entering Create...\n"); std::string ofn(outFileName+".binlexr.srctree"), oft(outFileName+".binlexr.tgtdata"), ofi(outFileName+".binlexr.idx"), ofsv(outFileName+".binlexr.voc0"), oftv(outFileName+".binlexr.voc1"); FILE *os = fOpen(ofn.c_str(),"wb"); FILE *ot = fOpen(oft.c_str(),"wb"); //TRACE_ERR("opend files....\n"); typedef PrefixTreeSA<LabelId,OFF_T> PSA; PSA *psa = new PSA; PSA::setDefault(InvalidOffT); WordVoc* voc[3]; LabelId currFirstWord = InvalidLabelId; IPhrase currKey; Candidates cands; std::vector<OFF_T> vo; size_t lnc = 0; size_t numTokens = 0; size_t numKeyTokens = 0; while(getline(inFile, line)) { ++lnc; if(0 == lnc % 10000) { TRACE_ERR("."); } IPhrase key; Scores score; std::vector<std::string> tokens = TokenizeMultiCharSeparator(line, "|||"); std::string w; if(1 == lnc) { //do some init stuff in the first line numTokens = tokens.size(); if(tokens.size() == 2) { //f ||| score numKeyTokens = 1; voc[0] = new WordVoc(); voc[1] = 0; } else if(3 == tokens.size() || 4 == tokens.size()) { //either f ||| e ||| score or f ||| e ||| c ||| score numKeyTokens = 2; voc[0] = new WordVoc(); //f voc voc[1] = new WordVoc(); //e voc voc[2] = voc[1]; //c & e share voc } } else { //sanity check ALL lines must have same number of tokens CHECK(numTokens == tokens.size()); } size_t phrase = 0; for(; phrase < numKeyTokens; ++phrase) { //conditioned on more than just f... need ||| if(phrase >=1) { key.push_back(PrefixTreeMap::MagicWord); } std::istringstream is(tokens[phrase]); while(is >> w) { key.push_back(voc[phrase]->add(w)); } } //collect all non key phrases, i.e. c std::vector<IPhrase> tgt_phrases; tgt_phrases.resize(numTokens - numKeyTokens - 1); for(size_t j = 0; j < tgt_phrases.size(); ++j, ++phrase) { std::istringstream is(tokens[numKeyTokens + j]); while(is >> w) { tgt_phrases[j].push_back(voc[phrase]->add(w)); } } //last token is score std::istringstream is(tokens[numTokens-1]); while(is >> w) { score.push_back(atof(w.c_str())); } //transform score now... std::transform(score.begin(),score.end(),score.begin(),TransformScore); std::transform(score.begin(),score.end(),score.begin(),FloorScore); std::vector<Scores> scores; scores.push_back(score); if(key.empty()) { TRACE_ERR("WARNING: empty source phrase in line '"<<line<<"'\n"); continue; } //first time inits if(currFirstWord == InvalidLabelId) { currFirstWord = key[0]; } if(currKey.empty()) { currKey = key; //insert key into tree CHECK(psa); PSA::Data& d = psa->insert(key); if(d == InvalidOffT) { d = fTell(ot); } else { TRACE_ERR("ERROR: source phrase already inserted (A)!\nline(" << lnc << "): '" << line << "\n"); return false; } } if(currKey != key) { //ok new key currKey = key; //a) write cands for old key cands.writeBin(ot); cands.clear(); //b) check if we need to move on to new tree root if(key[0] != currFirstWord) { // write key prefix tree to file and clear PTF pf; if(currFirstWord >= vo.size()) { vo.resize(currFirstWord+1,InvalidOffT); } vo[currFirstWord] = fTell(os); pf.create(*psa, os); // clear delete psa; psa = new PSA; currFirstWord = key[0]; } //c) insert key into tree CHECK(psa); PSA::Data& d = psa->insert(key); if(d == InvalidOffT) { d = fTell(ot); } else { TRACE_ERR("ERROR: source phrase already inserted (A)!\nline(" << lnc << "): '" << line << "\n"); return false; } } cands.push_back(GenericCandidate(tgt_phrases, scores)); } if (lnc == 0) { TRACE_ERR("ERROR: empty lexicalised reordering file\n" << std::endl); return false; } //flush remainders cands.writeBin(ot); cands.clear(); //process last currFirstWord PTF pf; if(currFirstWord >= vo.size()) { vo.resize(currFirstWord+1,InvalidOffT); } vo[currFirstWord] = fTell(os); pf.create(*psa,os); delete psa; psa=0; fClose(os); fClose(ot); /* std::vector<size_t> inv; for(size_t i = 0; i < vo.size(); ++i){ if(vo[i] == InvalidOffT){ inv.push_back(i); } } if(inv.size()) { TRACE_ERR("WARNING: there are src voc entries with no phrase " "translation: count "<<inv.size()<<"\n" "There exists phrase translations for "<<vo.size()-inv.size() <<" entries\n"); } */ FILE *oi = fOpen(ofi.c_str(),"wb"); fWriteVector(oi,vo); fClose(oi); if(voc[0]) { voc[0]->Write(ofsv); delete voc[0]; } if(voc[1]) { voc[1]->Write(oftv); delete voc[1]; } return true; }
int main(int argc, char **argv) { bool argerr = false; bool follow = false; bool use_stdin = false; long num = -1; char *matcher = "TRUE"; char *filename = NULL; output_function ofn = output_text; int c; while ((c = getopt(argc, argv, "tchfn:m:")) != -1) { switch (c) { case 't': ofn = output_text; break; case 'c': ofn = NULL; break; case 'h': ofn = output_heka; break; case 'f': follow = true; break; case 'n': num = strtol(optarg, NULL, 10); if (num < 0) argerr = true; break; case 'm': matcher = optarg; break; default: argerr = true; break; } } if (argc - optind == 1) { filename = argv[optind]; use_stdin = strcmp("-", filename) == 0; } else { argerr = true; } if (argerr) { log_cb(NULL, NULL, 0, "usage: %s [-t|-c|-h] [-m message_matcher] [-f] [-n #] <FILE>\n" "description:\n" " -t output the messages in text format (default)\n" " -c only output the message count\n" " -h output the messages as a Heka protobuf stream\n" " -f output appended data as the file grows\n" " -n output the last # of messages (simple header check so not " "100%% accurate)\n" " -m message_matcher expression (default \"TRUE\")\n" " FILE name of the file to cat or '-' for stdin\n" "notes:\n" " All output is written to stdout and all log/error messages are " "written to stderr.\n", argv[0]); return EXIT_FAILURE; } lsb_message_matcher *mm = lsb_create_message_matcher(matcher); if (!mm) { log_cb(NULL, NULL, 0, "invalid message matcher: %s", matcher); return EXIT_FAILURE; } FILE *fh = stdin; if (!use_stdin) { fh = fopen(filename, "r"); if (!fh) { log_cb(NULL, NULL, 0, "error opening: %s", filename); return EXIT_FAILURE; } if (num >= 0) { move_to_offset(fh, num); } } size_t discarded_bytes; size_t bytes_read = 0; size_t pcnt = 0; size_t mcnt = 0; lsb_input_buffer ib; lsb_init_input_buffer(&ib, 1024 * 1024 * 1024); lsb_heka_message msg; lsb_init_heka_message(&msg, 8); do { if (lsb_find_heka_message(&msg, &ib, true, &discarded_bytes, &logger)) { if (lsb_eval_message_matcher(mm, &msg)) { if (ofn) { ofn(&msg); } ++mcnt; } ++pcnt; } else { bytes_read = read_file(fh, &ib); } if (bytes_read == 0 && follow && !use_stdin) { sleep(1); } } while (bytes_read > 0 || follow); lsb_free_heka_message(&msg); lsb_free_input_buffer(&ib); lsb_destroy_message_matcher(mm); if (!use_stdin) { fclose(fh); } if (ofn) { log_cb(NULL, NULL, 0, "Processed: %zu, matched: %zu messages\n", pcnt, mcnt); } else { printf("Processed: %zu, matched: %zu messages\n", pcnt, mcnt); } }
/* do one opcode (instruction or prefix) */ LIB_EXPORT int z80ex_step(Z80EX_CONTEXT *cpu) { Z80EX_BYTE opcode, d; z80ex_opcode_fn ofn=NULL; cpu->doing_opcode=1; cpu->noint_once=0; cpu->reset_PV_on_int=0; cpu->tstate=0; cpu->op_tstate=0; opcode=READ_OP_M1(); /*fetch opcode*/ if(cpu->int_vector_req) { TSTATES(2); /*interrupt eats two extra wait-states*/ } R++; /*R increased by one on every first M1 cycle*/ T_WAIT_UNTIL(4); /*M1 cycle eats min 4 t-states*/ if(!cpu->prefix) opcodes_base[opcode](cpu); else { if((cpu->prefix | 0x20) == 0xFD && ((opcode | 0x20) == 0xFD || opcode == 0xED)) { cpu->prefix=opcode; cpu->noint_once=1; /*interrupts are not accepted immediately after prefix*/ } else { switch(cpu->prefix) { case 0xDD: case 0xFD: if(opcode == 0xCB) { d=READ_OP(); /*displacement*/ temp_byte_s=(d & 0x80)? -(((~d) & 0x7f)+1): d; opcode=READ_OP(); ofn = (cpu->prefix == 0xDD)? opcodes_ddcb[opcode]: opcodes_fdcb[opcode]; } else { ofn = (cpu->prefix == 0xDD)? opcodes_dd[opcode]: opcodes_fd[opcode]; if(ofn == NULL) ofn=opcodes_base[opcode]; /*'mirrored' instructions*/ } break; case 0xED: ofn = opcodes_ed[opcode]; if(ofn == NULL) ofn=opcodes_base[0x00]; break; case 0xCB: ofn = opcodes_cb[opcode]; break; default: /*this must'nt happen!*/ break; } ofn(cpu); cpu->prefix=0; } } cpu->doing_opcode=0; return(cpu->tstate); }