QString ServerTools::FileProcess(QString path) { QString rootPath; //This is the folder path that our files are there rootPath="/home/hadi/apps/hadi2f244/threadServer/htdocs"; path=rootPath+path; php(path); QFile file(path); file.open(QIODevice::ReadOnly); if(file.exists()) qDebug()<<"The file exists."; else qDebug()<<"The file not exists."; return file.readAll(); }
int main(int argc, const char * argv[]) { Products php("PHP", 23, 10); Products java("JAVA", 23, 1); Inventory inv; inv.insert(php); inv.insert(java); std::cout << std::endl; inv.show(); std::cout << std::endl; std::cout << "Total quantity of all products: " << inv.countQuantity(); std::cout << std::endl; return 0; }
// run appropriate function for opcode in memory void execute_cpu(machine* mch) { uint8_t *opcode = &mch->memory[mch->pc++]; uint8_t *memory = mch->memory; fprintf(stdout, "opcode: %x\n", opcode[0]); switch(*opcode) { case 0x02: exit(123); case 0x12: exit(123); case 0x22: exit(123); case 0x32: exit(123); case 0x42: exit(123); case 0x52: exit(123); case 0x62: exit(123); case 0x72: exit(123); case 0x92: exit(123); case 0xB2: exit(123); case 0xD2: exit(123); case 0xF2: exit(123); case 0xEA: return nop(mch, 1); case 0x1A: return nop(mch, 2); // illegal instruction (nop with 2 cycles) case 0x7A: return nop(mch, 2); // same as above case 0x69: return adc_imm(opcode[1], mch); case 0x65: return adc_zp(opcode[1], mch); case 0x75: return adc_zpx(opcode[1], mch); case 0x6D: return adc_abs(opcode[2], opcode[1], mch); case 0x7D: return adc_absx(opcode[2], opcode[1], mch); case 0x79: return adc_absy(opcode[2], opcode[1], mch); case 0x61: return adc_indx(opcode[2], opcode[1], mch); case 0x71: return adc_indy(opcode[2], opcode[1], mch); case 0x29: return and_imm(opcode[1], mch); case 0x25: return and_zp(opcode[1], mch); case 0x35: return and_zpx(opcode[1], mch); case 0x2D: return and_abs(opcode[2], opcode[1], mch); case 0x3D: return and_absx(opcode[2], opcode[1], mch); case 0x39: return and_absy(opcode[2], opcode[1], mch); case 0x21: return and_indx(opcode[2], opcode[1], mch); case 0x31: return and_indy(opcode[2], opcode[1], mch); case 0x0A: return asl_acc(mch); case 0x06: return asl_zp(opcode[1], mch); case 0x16: return asl_zpx(opcode[1], mch); case 0x0E: return asl_abs(opcode[2], opcode[1], mch); case 0x1E: return asl_absx(opcode[2], opcode[1], mch); case 0x90: return branch_clear(opcode[2], opcode[1], mch, 0b00000001); case 0xB0: return branch_set(opcode[2], opcode[1], mch, 0b00000001); case 0xF0: return branch_set(opcode[2], opcode[1], mch, 0b00000010); case 0x24: return bit_zp(opcode[1], mch); case 0x2C: return bit_abs(opcode[2], opcode[1], mch); case 0x30: return branch_set(opcode[2], opcode[1], mch, 0b10000000); case 0xD0: return branch_clear(opcode[2], opcode[1], mch, 0b00000010); case 0x10: return branch_clear(opcode[2], opcode[1], mch, 0b10000000); case 0x00: return brk(mch); case 0x50: return branch_clear(opcode[2], opcode[1], mch, 0b01000000); case 0x70: return branch_set(opcode[2], opcode[1], mch, 0b01000000); case 0x18: return clc(mch); case 0x58: return cli(mch); case 0xB8: return clv(mch); case 0xC9: return cmp_imm(opcode[1], mch); case 0xC5: return cmp_zp(opcode[1], mch); case 0xD5: return cmp_zpx(opcode[1], mch); case 0xCD: return cmp_abs(opcode[2], opcode[1], mch, 0, 0); case 0xDD: return cmp_abs(opcode[2], opcode[1], mch, 1, mch->X); case 0xD9: return cmp_abs(opcode[2], opcode[1], mch, 1, mch->Y); case 0xC1: return cmp_indy(opcode[2], opcode[1], mch); case 0xD1: return cmp_indx(opcode[2], opcode[1], mch); case 0xE0: return cpx_imm(opcode[1], mch); case 0xE4: return cpx_zp(opcode[1], mch); case 0xEC: return cpx_abs(opcode[2], opcode[1], mch); case 0xC0: return cpy_imm(opcode[1], mch); case 0xC4: return cpy_zp(opcode[1], mch); case 0xCC: return cpy_abs(opcode[2], opcode[1], mch); case 0xC6: return dec_zp(opcode[1], mch); case 0xD6: return dec_zpx(opcode[1], mch); case 0xCE: return dec_abs(opcode[2], opcode[1], mch); case 0xDE: return dec_absx(opcode[2], opcode[1], mch); case 0xCA: return dex(mch); case 0x88: return dey(mch); case 0x49: return eor_imm(opcode[1], mch); case 0x45: return eor_zp(opcode[1], mch); case 0x55: return eor_zpx(opcode[1], mch); case 0x4D: return eor_abs(opcode[2], opcode[1], mch); case 0x5D: return eor_absx(opcode[2], opcode[1], mch); case 0x59: return eor_absy(opcode[2], opcode[1], mch); case 0x41: return eor_indx(opcode[2], opcode[1], mch); case 0x51: return eor_indy(opcode[2], opcode[1], mch); case 0xE6: return inc_zp(opcode[1], mch, 0, 0); case 0xF6: return inc_zp(opcode[1], mch, 1, mch->X); case 0xEE: return inc_abs(opcode[2], opcode[1], mch, 0, 0); case 0xFE: return inc_abs(opcode[2], opcode[1], mch, 1, mch->X); case 0xE8: return inx(mch); case 0xC8: return iny(mch); case 0x4C: return jmp_abs(opcode[2], opcode[1], mch); case 0x6C: return jmp_ind(opcode[2], opcode[1], mch); case 0x20: return jsr(opcode[2], opcode[1], mch); case 0xA9: return lda_imm(opcode[1], mch); case 0xA5: return lda_zp(opcode[1], mch, 0, 0); case 0xB5: return lda_zp(opcode[1], mch, 1, mch->X); case 0xAD: return lda_abs(opcode[2], opcode[1], mch, 0, 0); case 0xBD: return lda_abs(opcode[2], opcode[1], mch, 1, mch->X); case 0xB9: return lda_abs(opcode[2], opcode[1], mch, 1, mch->Y); case 0xA1: return lda_indx(opcode[2], opcode[1], mch); case 0xB1: return lda_indy(opcode[2], opcode[1], mch); case 0xA2: return ldx_imm(opcode[1], mch); case 0xA6: return ldx_zp(opcode[1], mch, 0, 0); case 0xB6: return ldx_zp(opcode[1], mch, 1, mch->X); case 0xAE: return ldx_abs(opcode[2], opcode[1], mch, 0, 0); case 0xBE: return ldx_abs(opcode[2], opcode[1], mch, 1, mch->X); case 0xA0: return ldy_imm(opcode[1], mch); case 0xA4: return ldy_zp(opcode[1], mch, 0, 0); case 0xB4: return ldy_zp(opcode[1], mch, 1, mch->X); case 0xAC: return ldy_abs(opcode[2], opcode[1], mch, 0, 0); case 0xBC: return ldy_abs(opcode[2], opcode[1], mch, 1, mch->X); case 0x4A: return lsr_acc(mch); case 0x46: return lsr_zp(opcode[1], mch); case 0x56: return lsr_zpx(opcode[1], mch); case 0x4E: return lsr_abs(opcode[2], opcode[1], mch); case 0x5E: return lsr_absx(opcode[2], opcode[1], mch); case 0x09: return or_imm(opcode[1], mch); case 0x05: return or_zp(opcode[1], mch); case 0x15: return or_zpx(opcode[1], mch); case 0x0D: return or_abs(opcode[2], opcode[1], mch); case 0x1D: return or_absx(opcode[2], opcode[1], mch); case 0x19: return or_absy(opcode[2], opcode[1], mch); case 0x01: return or_indx(opcode[2], opcode[1], mch); case 0x11: return or_indy(opcode[2], opcode[1], mch); case 0x48: return pha(mch); case 0x08: return php(mch); case 0x68: return pla(mch); case 0x28: return plp(mch); case 0x40: return rti(mch); case 0x60: return rts(mch); case 0x78: return sei(mch); case 0x38: return sec(mch); case 0xAA: return tax(mch); case 0xA8: return tay(mch); case 0x8A: return txa(mch); case 0x98: return tya(mch); default: fprintf(stdout, "unimplemented opcode!\n"); fprintf(stdout, "opcode in question: %x\n", opcode[0]); exit(1); break; } }
void CodeFormatter::OnFormatString(clSourceFormatEvent& e) { wxString str = e.GetInputString(); if(str.IsEmpty()) { e.SetFormattedString(str); return; } // execute the formatter FormatOptions fmtroptions; m_mgr->GetConfigTool()->ReadObject(wxT("FormatterOptions"), &fmtroptions); wxString output; if(FileExtManager::IsPHPFile(e.GetFileName())) { if(fmtroptions.GetPhpEngine() == kPhpFormatEngineBuiltin) { // use the built-in PHP formatter // Construct the formatting options PHPFormatterOptions phpOptions; phpOptions.flags = fmtroptions.GetPHPFormatterOptions(); if(m_mgr->GetEditorSettings()->GetIndentUsesTabs()) { phpOptions.flags |= kPFF_UseTabs; } phpOptions.indentSize = m_mgr->GetEditorSettings()->GetTabWidth(); phpOptions.eol = m_mgr->GetEditorSettings()->GetEOLAsString(); // Create the formatter buffer PHPFormatterBuffer buffer(e.GetInputString(), phpOptions); // Format the source buffer.format(); // set the output output = buffer.GetBuffer(); } else { wxFileName php(fmtroptions.GetPhpExecutable()); if(!php.Exists()) { ::wxMessageBox(_("Can not format file using PHP-CS-Fixer: Missing PHP executable path"), "Code Formatter", wxICON_ERROR | wxOK | wxCENTER); return; } wxFileName phar(fmtroptions.GetPHPCSFixerPhar()); if(!phar.Exists()) { ::wxMessageBox(_("Can not format file using PHP-CS-Fixer: Missing PHAR file"), "Code Formatter", wxICON_ERROR | wxOK | wxCENTER); return; } // Run the command, PHP-CS-Fixer works directly on the file // output.Clear(); IProcess::Ptr_t phpFixer(::CreateSyncProcess(fmtroptions.GetPhpFixerCommand(), IProcessCreateDefault | IProcessCreateWithHiddenConsole)); CHECK_PTR_RET(phpFixer); phpFixer->WaitForTerminate(output); } } else if(fmtroptions.GetEngine() == kFormatEngineAStyle) { wxString options = fmtroptions.AstyleOptionsAsString(); // determine indentation method and amount bool useTabs = m_mgr->GetEditorSettings()->GetIndentUsesTabs(); int tabWidth = m_mgr->GetEditorSettings()->GetTabWidth(); int indentWidth = m_mgr->GetEditorSettings()->GetIndentWidth(); options << (useTabs && tabWidth == indentWidth ? wxT(" -t") : wxT(" -s")) << indentWidth; AstyleFormat(str, options, output); output << DoGetGlobalEOLString(); } else if(fmtroptions.GetEngine() == kFormatEngineClangFormat) { ClangPreviewFormat(str, output, fmtroptions); } else { // ?? } e.SetFormattedString(output); }
void CodeFormatter::DoFormatFile(IEditor* editor) { int curpos = editor->GetCurrentPosition(); // execute the formatter FormatOptions fmtroptions; m_mgr->GetConfigTool()->ReadObject(wxT("FormatterOptions"), &fmtroptions); if(FileExtManager::IsPHPFile(editor->GetFileName())) { if(fmtroptions.GetPhpEngine() == kPhpFormatEngineBuiltin) { // use the built-in PHP formatter // Construct the formatting options PHPFormatterOptions phpOptions; phpOptions.flags = fmtroptions.GetPHPFormatterOptions(); if(m_mgr->GetEditorSettings()->GetIndentUsesTabs()) { phpOptions.flags |= kPFF_UseTabs; } phpOptions.indentSize = m_mgr->GetEditorSettings()->GetTabWidth(); phpOptions.eol = m_mgr->GetEditorSettings()->GetEOLAsString(); // Create the formatter buffer PHPFormatterBuffer buffer(editor->GetCtrl()->GetText(), phpOptions); // Format the source buffer.format(); // Restore line if(!buffer.GetBuffer().IsEmpty()) { clSTCLineKeeper lk(editor); editor->GetCtrl()->BeginUndoAction(); // Replace the text with the new formatted buffer editor->SetEditorText(buffer.GetBuffer()); editor->GetCtrl()->EndUndoAction(); } } else { wxFileName php(fmtroptions.GetPhpExecutable()); if(!php.Exists()) { ::wxMessageBox(_("Can not format file using PHP-CS-Fixer: Missing PHP executable path"), "Code Formatter", wxICON_ERROR | wxOK | wxCENTER); return; } wxFileName phar(fmtroptions.GetPHPCSFixerPhar()); if(!phar.Exists()) { ::wxMessageBox(_("Can not format file using PHP-CS-Fixer: Missing PHAR file"), "Code Formatter", wxICON_ERROR | wxOK | wxCENTER); return; } // Run the command, PHP-CS-Fixer works directly on the file // so create a copy of the file and format it, then replace the buffers // we do this like this so we won't lose our ability to undo the action wxString output; wxString command, filename, tmpfile; filename = editor->GetFileName().GetFullPath(); tmpfile << filename << ".php-cs-fixer"; if(!FileUtils::WriteFileContent(tmpfile, editor->GetEditorText())) { ::wxMessageBox(_("Can not format file using PHP-CS-Fixer:\nFailed to write temporary file"), "Code Formatter", wxICON_ERROR | wxOK | wxCENTER); return; } // Ensure that the temporary file is deleted once we are done with it FileUtils::Deleter fd(tmpfile); ::WrapWithQuotes(tmpfile); command << fmtroptions.GetPhpFixerCommand() << " " << tmpfile; ::WrapInShell(command); IProcess::Ptr_t phpFixer( ::CreateSyncProcess(command, IProcessCreateDefault | IProcessCreateWithHiddenConsole)); CHECK_PTR_RET(phpFixer); phpFixer->WaitForTerminate(output); output.clear(); if(!FileUtils::ReadFileContent(tmpfile, output)) { ::wxMessageBox(_("Can not format file using PHP-CS-Fixer:\nfailed to read temporary file content"), "Code Formatter", wxICON_ERROR | wxOK | wxCENTER); return; } // Update the editor clEditorStateLocker lk(editor->GetCtrl()); editor->GetCtrl()->BeginUndoAction(); editor->SetEditorText(output); editor->GetCtrl()->EndUndoAction(); } } else { // We allow ClangFormat to work only when the source file is known to be // a C/C++ source file or JavaScript (these are the types of files that clang-format can handle properly) if(fmtroptions.GetEngine() == kFormatEngineClangFormat && (FileExtManager::IsCxxFile(editor->GetFileName()) || FileExtManager::IsJavascriptFile(editor->GetFileName()))) { int from = wxNOT_FOUND, length = wxNOT_FOUND; wxString formattedOutput; if(editor->GetSelectionStart() != wxNOT_FOUND) { // we got a selection, only format it from = editor->GetSelectionStart(); length = editor->GetSelectionEnd() - from; if(length <= 0) { from = wxNOT_FOUND; length = wxNOT_FOUND; } } // Make sure we format the editor string and _not_ the file (there might be some newly added lines // that could be missing ...) if(!ClangFormatBuffer( editor->GetCtrl()->GetText(), editor->GetFileName(), formattedOutput, curpos, from, length)) { ::wxMessageBox(_("Source code formatting error!"), "CodeLite", wxICON_ERROR | wxOK | wxCENTER); return; } clEditorStateLocker lk(editor->GetCtrl()); editor->GetCtrl()->BeginUndoAction(); editor->SetEditorText(formattedOutput); editor->SetCaretAt(curpos); editor->GetCtrl()->EndUndoAction(); } else { // AStyle wxString options = fmtroptions.AstyleOptionsAsString(); // determine indentation method and amount bool useTabs = m_mgr->GetEditorSettings()->GetIndentUsesTabs(); int tabWidth = m_mgr->GetEditorSettings()->GetTabWidth(); int indentWidth = m_mgr->GetEditorSettings()->GetIndentWidth(); options << (useTabs && tabWidth == indentWidth ? wxT(" -t") : wxT(" -s")) << indentWidth; wxString output; wxString inputString; bool formatSelectionOnly(editor->GetSelection().IsEmpty() == false); if(formatSelectionOnly) { // get the lines contained in the selection int selStart = editor->GetSelectionStart(); int selEnd = editor->GetSelectionEnd(); int lineNumber = editor->LineFromPos(selStart); selStart = editor->PosFromLine(lineNumber); selEnd = editor->LineEnd(editor->LineFromPos(selEnd)); editor->SelectText(selStart, selEnd - selStart); inputString = editor->GetSelection(); } else { inputString = editor->GetEditorText(); } AstyleFormat(inputString, options, output); if(!output.IsEmpty()) { // append new-line wxString eol; if(editor->GetEOL() == 0) { // CRLF eol = wxT("\r\n"); } else if(editor->GetEOL() == 1) { // CR eol = wxT("\r"); } else { eol = wxT("\n"); } if(!formatSelectionOnly) output << eol; if(formatSelectionOnly) { clEditorStateLocker lk(editor->GetCtrl()); // format the text (add the indentation) output = editor->FormatTextKeepIndent(output, editor->GetSelectionStart(), Format_Text_Indent_Prev_Line | Format_Text_Save_Empty_Lines); editor->ReplaceSelection(output); } else { clEditorStateLocker lk(editor->GetCtrl()); editor->SetEditorText(output); } } } } // Notify that a file was indented wxCommandEvent evt(wxEVT_CODEFORMATTER_INDENT_COMPLETED); evt.SetString(editor->GetFileName().GetFullPath()); EventNotifier::Get()->AddPendingEvent(evt); }
void ConfigAutotuneWidget::onForumInteractionSet(int value) { if (!value) { forumInteractionForm->deleteLater(); return; } ExtensionSystem::PluginManager *pm=ExtensionSystem::PluginManager::instance(); Core::Internal::GeneralSettings * settings=pm->getObject<Core::Internal::GeneralSettings>(); if (forumInteractionForm->getSaveCredentials()) { settings->setForumPassword(forumInteractionForm->getPassword()); settings->setForumUser(forumInteractionForm->getUserName()); } else { settings->setForumPassword(""); settings->setForumUser(""); } settings->setObservations(forumInteractionForm->getObservations()); settings->setAircraftDescription(forumInteractionForm->getAircraftDescription()); Utils::PHPBB php("http://forum.taulabs.org", this); if (!php.login(forumInteractionForm->getUserName(), forumInteractionForm->getPassword())) { QMessageBox::warning(this, tr("Forum login"), tr("Forum login failed, probably wrong username or password")); forumInteractionForm->deleteLater(); return; } QString message0 = tr( "[b]Aircraft description[/b]: %0\n\n\n" "[b]Observations[/b]: %1\n\n\n" "[b]Measured properties[/b]" "[table][tr][td][/td]" "[td][b]Gain[/b][/td]" "[td][b]Bias[/b][/td]" "[td][b]Tau(s)[/b][/td]" "[td][b]Noise[/b][/td][/tr]" "[tr][td][b]Roll[/b][/td]" "[td]%2[/td]" "[td]%3[/td]" "[td]%4[/td]" "[td]%5[/td][/tr]" "[tr][td][b]Pitch[/b][/td]" "[td]%6[/td]" "[td]%7[/td]" "[td]%8[/td]" "[td]%9[/td][/tr][/table]" "[b]\n\nTuning aggressiveness [/b]" "[table][tr][td][b]Damping[/b][/td]" "[td]%10[/td][/tr]" "[tr][td][b]Noise sensitivity[/b][/td]" "[td]%11[/td][/tr]" "[tr][td][b]Natural frequency[/b][/td]" "[td]%12[/td][/tr][/table]") .arg(forumInteractionForm->getAircraftDescription()).arg(forumInteractionForm->getObservations()) .arg(m_autotune->measuredRollGain->text()).arg(m_autotune->measuredRollBias->text()) .arg(m_autotune->rollTau->text()).arg(m_autotune->measuredRollNoise->text()) .arg(m_autotune->measuredPitchGain->text()).arg(m_autotune->measuredPitchBias->text()) .arg(m_autotune->pitchTau->text()).arg(m_autotune->measuredPitchNoise->text()) .arg(m_autotune->lblDamp->text()).arg(m_autotune->lblNoise->text()) .arg(m_autotune->wn->text()); QString message1 = tr( "[b]\n\nComputed Values[/b]" "[table][tr][td][/td]" "[td][b]RateKp[/b][/td]" "[td][b]RateKi[/b][/td]" "[td][b]RateKd[/b][/td][/tr]" "[tr][td][b]Roll[/b][/td]" "[td]%1[/td]" "[td]%2[/td]" "[td]%3[/td][/tr]" "[tr][td][b]Pitch[/b][/td]" "[td]%4[/td]" "[td]%5[/td]" "[td]%6[/td][/tr]" "[tr][td][b]Outer Kp[/b][/td]" "[td]%7[/td]" "[td]-[/td]" "[td]-[/td][/tr]" "[tr][td][b]Derivative cutoff[/b][/td]" "[td]%8[/td]" "[td]-[/td]" "[td]-[/td][/tr][/table]" "\n\n") .arg(m_autotune->rollRateKp->text()).arg(m_autotune->rollRateKi->text()).arg(m_autotune->rollRateKd->text()) .arg(m_autotune->pitchRateKp->text()).arg(m_autotune->pitchRateKi->text()).arg(m_autotune->pitchRateKd->text()) .arg(m_autotune->lblOuterKp->text()).arg(m_autotune->derivativeCutoff->text()); QString message = message0 + message1; if(php.postReply(FORUM_SHARING_FORUM, FORUM_SHARING_THREAD, "Autotune Results", message)) { QMessageBox::information(this, tr("Autotune results sharing"), tr("Thank you for sharing your results")); } else { QMessageBox::warning(this, tr("Autotune results sharing"), tr("Ooops, something went wrong, your results were not shared")); } forumInteractionForm->deleteLater(); }
void handlerequest(int fd, const char *addr) { char buffer[BUFFER_SIZE]; char can_uri[BUFFER_SIZE]; char filepath[BUFFER_SIZE]; char headers[BUFFER_SIZE]; char pf[BUFFER_SIZE]; int len = 0, ret, begin = 0, p, pbegin = 0, plen = 0; int state = 0, filelen; int fduri; char *uribuffer; int tot; time_t now; struct header rq; rq.code = 500; rq.contentlen = 0; memset(rq.contenttype, 0, sizeof(rq.contenttype)); memset(rq.host, 0, sizeof(rq.host)); memset(rq.cookie, 0, sizeof(rq.cookie)); do { ret = read(fd, buffer + len, BUFFER_SIZE - len); if (ret > 0) { len += ret; while ((state == 0 || state == 1) && begin < len && (p = crlf(buffer + begin, len - begin)) >= 0) { p += begin; if (state == 0) { if (statusline(fd, buffer + begin, p - begin, &rq)) state = 1; else { state = 3; break; } } else if (state == 1) { if (p - begin == 0) { if (rq.contentlen == 0) state = 3; else state = 2; } else if (!header(fd, buffer + begin, p - begin, &rq)) state = 3; } begin = p + 2; if (state == 2 || state == 3) break; } if (state == 2) { memcpy(rq.payload + pbegin, buffer + begin, len - begin); pbegin += len - begin; plen += len - begin; begin += len - begin; if (rq.contentlen != 0 && pbegin >= rq.contentlen) state = 3; } } else { state = 3; break; } } while (state <= 2); if (rq.contentlen == 0) rq.contentlen = plen; if (rq.code != 200) { respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else { if (rq.uri[0] == '/') strcpy(can_uri, rq.uri); else { strcpy(can_uri, "/"); strcat(can_uri, rq.uri); } if (!permissible(can_uri)) { rq.code = 403; respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else { state = locateresource(can_uri, filepath, BUFFER_SIZE, &filelen); if (state == 0) { rq.code = 404; respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else if (state == 2) { strcpy(buffer, "Location: "); strcat(buffer, filepath); strcat(buffer, "\r\n"); rq.code = 301; respond(fd, rq.code, rq.protocol, NULL, 0, buffer); } else if (state == 3) { rq.code = 403; respond(fd, rq.code ,rq.protocol, NULL, 0, NULL); } else if (state == 1) { if (postfix(filepath, pf) && strcmp(pf, "php") == 0) { php(fd, filepath, addr, &rq); } else { strcpy(headers, "Content-Type: "); strcat(headers, contenttype(filepath)); strcat(headers, "\r\n"); if (rq.method == METHOD_HEAD) respond(fd, rq.code, rq.protocol, NULL, filelen, headers); else { fduri = open(filepath, O_RDONLY); if (fduri < 0) { rq.code = 404; respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else { uribuffer = malloc(filelen); if (uribuffer == 0) { rq.code = 500; respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else { tot = 0; while (tot < filelen) tot += read(fduri, uribuffer + tot, filelen - tot); respond(fd, rq.code, rq.protocol, uribuffer, filelen, headers); free(uribuffer); } close(fduri); } } } } } } now = time(NULL); len = strftime(buffer, BUFFER_SIZE, "%d/%b/%Y %H:%M:%S", gmtime(&now)); fprintf(stdout, "%s - - [%s] \"%s\" %d\n", addr, buffer, rq.statusline, rq.code); }
/** * @brief emulate instruction * @return returns false if something goes wrong (e.g. illegal instruction) * * Current limitations: * * - Illegal instructions are not implemented * - Excess cycles due to page boundary crossing are not calculated * - Some known architectural bugs are not emulated */ bool Cpu::emulate() { /* fetch instruction */ uint8_t insn = fetch_op(); bool retval = true; /* emulate instruction */ switch(insn) { /* BRK */ case 0x0: brk(); break; /* ORA (nn,X) */ case 0x1: ora(load_byte(addr_indx()),6); break; /* ORA nn */ case 0x5: ora(load_byte(addr_zero()),3); break; /* ASL nn */ case 0x6: asl_mem(addr_zero(),5); break; /* PHP */ case 0x8: php(); break; /* ORA #nn */ case 0x9: ora(fetch_op(),2); break; /* ASL A */ case 0xA: asl_a(); break; /* ORA nnnn */ case 0xD: ora(load_byte(addr_abs()),4); break; /* ASL nnnn */ case 0xE: asl_mem(addr_abs(),6); break; /* BPL nn */ case 0x10: bpl(); break; /* ORA (nn,Y) */ case 0x11: ora(load_byte(addr_indy()),5); break; /* ORA nn,X */ case 0x15: ora(load_byte(addr_zerox()),4); break; /* ASL nn,X */ case 0x16: asl_mem(addr_zerox(),6); break; /* CLC */ case 0x18: clc(); break; /* ORA nnnn,Y */ case 0x19: ora(load_byte(addr_absy()),4); break; /* ORA nnnn,X */ case 0x1D: ora(load_byte(addr_absx()),4); break; /* ASL nnnn,X */ case 0x1E: asl_mem(addr_absx(),7); break; /* JSR */ case 0x20: jsr(); break; /* AND (nn,X) */ case 0x21: _and(load_byte(addr_indx()),6); break; /* BIT nn */ case 0x24: bit(addr_zero(),3); break; /* AND nn */ case 0x25: _and(load_byte(addr_zero()),3); break; /* ROL nn */ case 0x26: rol_mem(addr_zero(),5); break; /* PLP */ case 0x28: plp(); break; /* AND #nn */ case 0x29: _and(fetch_op(),2); break; /* ROL A */ case 0x2A: rol_a(); break; /* BIT nnnn */ case 0x2C: bit(addr_abs(),4); break; /* AND nnnn */ case 0x2D: _and(load_byte(addr_abs()),4); break; /* ROL nnnn */ case 0x2E: rol_mem(addr_abs(),6); break; /* BMI nn */ case 0x30: bmi(); break; /* AND (nn,Y) */ case 0x31: _and(load_byte(addr_indy()),5); break; /* AND nn,X */ case 0x35: _and(load_byte(addr_zerox()),4); break; /* ROL nn,X */ case 0x36: rol_mem(addr_zerox(),6); break; /* SEC */ case 0x38: sec(); break; /* AND nnnn,Y */ case 0x39: _and(load_byte(addr_absy()),4); break; /* AND nnnn,X */ case 0x3D: _and(load_byte(addr_absx()),4); break; /* ROL nnnn,X */ case 0x3E: rol_mem(addr_absx(),7); break; /* RTI */ case 0x40: rti(); break; /* EOR (nn,X) */ case 0x41: eor(load_byte(addr_indx()),6); break; /* EOR nn */ case 0x45: eor(load_byte(addr_zero()),3); break; /* LSR nn */ case 0x46: lsr_mem(addr_zero(),5); break; /* PHA */ case 0x48: pha(); break; /* EOR #nn */ case 0x49: eor(fetch_op(),2); break; /* BVC */ case 0x50: bvc(); break; /* JMP nnnn */ case 0x4C: jmp(); break; /* EOR nnnn */ case 0x4D: eor(load_byte(addr_abs()),4); break; /* LSR A */ case 0x4A: lsr_a(); break; /* LSR nnnn */ case 0x4E: lsr_mem(addr_abs(),6); break; /* EOR (nn,Y) */ case 0x51: eor(load_byte(addr_indy()),5); break; /* EOR nn,X */ case 0x55: eor(load_byte(addr_zerox()),4); break; /* LSR nn,X */ case 0x56: lsr_mem(addr_zerox(),6); break; /* CLI */ case 0x58: cli(); break; /* EOR nnnn,Y */ case 0x59: eor(load_byte(addr_absy()),4); break; /* EOR nnnn,X */ case 0x5D: eor(load_byte(addr_absx()),4); break; /* LSR nnnn,X */ case 0x5E: lsr_mem(addr_absx(),7); break; /* RTS */ case 0x60: rts(); break; /* ADC (nn,X) */ case 0x61: adc(load_byte(addr_indx()),6); break; /* ADC nn */ case 0x65: adc(load_byte(addr_zero()),3); break; /* ROR nn */ case 0x66: ror_mem(addr_zero(),5); break; /* PLA */ case 0x68: pla(); break; /* ADC #nn */ case 0x69: adc(fetch_op(),2); break; /* ROR A */ case 0x6A: ror_a(); break; /* JMP (nnnn) */ case 0x6C: jmp_ind(); break; /* ADC nnnn */ case 0x6D: adc(load_byte(addr_abs()),4); break; /* ROR nnnn */ case 0x6E: ror_mem(addr_abs(),6); break; /* BVS */ case 0x70: bvs(); break; /* ADC (nn,Y) */ case 0x71: adc(load_byte(addr_indy()),5); break; /* ADC nn,X */ case 0x75: adc(load_byte(addr_zerox()),4); break; /* ROR nn,X */ case 0x76: ror_mem(addr_zerox(),6); break; /* SEI */ case 0x78: sei(); break; /* ADC nnnn,Y */ case 0x79: adc(load_byte(addr_absy()),4); break; /* ADC nnnn,X */ case 0x7D: adc(load_byte(addr_absx()),4); break; /* ROR nnnn,X */ case 0x7E: ror_mem(addr_absx(),7); break; /* STA (nn,X) */ case 0x81: sta(addr_indx(),6); break; /* STY nn */ case 0x84: sty(addr_zero(),3); break; /* STA nn */ case 0x85: sta(addr_zero(),3); break; /* STX nn */ case 0x86: stx(addr_zero(),3); break; /* DEY */ case 0x88: dey(); break; /* TXA */ case 0x8A: txa(); break; /* STY nnnn */ case 0x8C: sty(addr_abs(),4); break; /* STA nnnn */ case 0x8D: sta(addr_abs(),4); break; /* STX nnnn */ case 0x8E: stx(addr_abs(),4); break; /* BCC nn */ case 0x90: bcc(); break; /* STA (nn,Y) */ case 0x91: sta(addr_indy(),6); break; /* STY nn,X */ case 0x94: sty(addr_zerox(),4); break; /* STA nn,X */ case 0x95: sta(addr_zerox(),4); break; /* STX nn,Y */ case 0x96: stx(addr_zeroy(),4); break; /* TYA */ case 0x98: tya(); break; /* STA nnnn,Y */ case 0x99: sta(addr_absy(),5); break; /* TXS */ case 0x9A: txs(); break; /* STA nnnn,X */ case 0x9D: sta(addr_absx(),5); break; /* LDY #nn */ case 0xA0: ldy(fetch_op(),2); break; /* LDA (nn,X) */ case 0xA1: lda(load_byte(addr_indx()),6); break; /* LDX #nn */ case 0xA2: ldx(fetch_op(),2); break; /* LDY nn */ case 0xA4: ldy(load_byte(addr_zero()),3); break; /* LDA nn */ case 0xA5: lda(load_byte(addr_zero()),3); break; /* LDX nn */ case 0xA6: ldx(load_byte(addr_zero()),3); break; /* TAY */ case 0xA8: tay(); break; /* LDA #nn */ case 0xA9: lda(fetch_op(),2); break; /* TAX */ case 0xAA: tax(); break; /* LDY nnnn */ case 0xAC: ldy(load_byte(addr_abs()),4); break; /* LDA nnnn */ case 0xAD: lda(load_byte(addr_abs()),4); break; /* LDX nnnn */ case 0xAE: ldx(load_byte(addr_abs()),4); break; /* BCS nn */ case 0xB0: bcs(); break; /* LDA (nn,Y) */ case 0xB1: lda(load_byte(addr_indy()),5); break; /* LDY nn,X */ case 0xB4: ldy(load_byte(addr_zerox()),3); break; /* LDA nn,X */ case 0xB5: lda(load_byte(addr_zerox()),3); break; /* LDX nn,Y */ case 0xB6: ldx(load_byte(addr_zeroy()),3); break; /* CLV */ case 0xB8: clv(); break; /* LDA nnnn,Y */ case 0xB9: lda(load_byte(addr_absy()),4); break; /* TSX */ case 0xBA: tsx(); break; /* LDY nnnn,X */ case 0xBC: ldy(load_byte(addr_absx()),4); break; /* LDA nnnn,X */ case 0xBD: lda(load_byte(addr_absx()),4); break; /* LDX nnnn,Y */ case 0xBE: ldx(load_byte(addr_absy()),4); break; /* CPY #nn */ case 0xC0: cpy(fetch_op(),2); break; /* CMP (nn,X) */ case 0xC1: cmp(load_byte(addr_indx()),6); break; /* CPY nn */ case 0xC4: cpy(load_byte(addr_zero()),3); break; /* CMP nn */ case 0xC5: cmp(load_byte(addr_zero()),3); break; /* DEC nn */ case 0xC6: dec(addr_zero(),5); break; /* INY */ case 0xC8: iny(); break; /* CMP #nn */ case 0xC9: cmp(fetch_op(),2); break; /* DEX */ case 0xCA: dex(); break; /* CPY nnnn */ case 0xCC: cpy(load_byte(addr_abs()),4); break; /* CMP nnnn */ case 0xCD: cmp(load_byte(addr_abs()),4); break; /* DEC nnnn */ case 0xCE: dec(addr_abs(),6); break; /* BNE nn */ case 0xD0: bne(); break; /* CMP (nn,Y) */ case 0xD1: cmp(load_byte(addr_indy()),5); break; /* CMP nn,X */ case 0xD5: cmp(load_byte(addr_zerox()),4); break; /* DEC nn,X */ case 0xD6: dec(addr_zerox(),6); break; /* CLD */ case 0xD8: cld(); break; /* CMP nnnn,Y */ case 0xD9: cmp(load_byte(addr_absy()),4); break; /* CMP nnnn,X */ case 0xDD: cmp(load_byte(addr_absx()),4); break; /* DEC nnnn,X */ case 0xDE: dec(addr_absx(),7); break; /* CPX #nn */ case 0xE0: cpx(fetch_op(),2); break; /* SBC (nn,X) */ case 0xE1: sbc(load_byte(addr_indx()),6); break; /* CPX nn */ case 0xE4: cpx(load_byte(addr_zero()),3); break; /* SBC nn */ case 0xE5: sbc(load_byte(addr_zero()),3); break; /* INC nn */ case 0xE6: inc(addr_zero(),5); break; /* INX */ case 0xE8: inx(); break; /* SBC #nn */ case 0xE9: sbc(fetch_op(),2); break; /* NOP */ case 0xEA: nop(); break; /* CPX nnnn */ case 0xEC: cpx(load_byte(addr_abs()),4); break; /* SBC nnnn */ case 0xED: sbc(load_byte(addr_abs()),4); break; /* INC nnnn */ case 0xEE: inc(addr_abs(),6); break; /* BEQ nn */ case 0xF0: beq(); break; /* SBC (nn,Y) */ case 0xF1: sbc(load_byte(addr_indy()),5); break; /* SBC nn,X */ case 0xF5: sbc(load_byte(addr_zerox()),4); break; /* INC nn,X */ case 0xF6: inc(addr_zerox(),6); break; /* SED */ case 0xF8: sed(); break; /* SBC nnnn,Y */ case 0xF9: sbc(load_byte(addr_absy()),4); break; /* SBC nnnn,X */ case 0xFD: sbc(load_byte(addr_absx()),4); break; /* INC nnnn,X */ case 0xFE: inc(addr_absx(),7); break; /* Unknown or illegal instruction */ default: D("Unknown instruction: %X at %04x\n", insn,pc()); retval = false; } return retval; }