void debug (void) { if (savepc - 1 == breakpt1 || savepc - 1 == breakpt2) { print("Breakpoint\n"); savepc--; // Restore contents of breakpoint 1 if (breakpt1) mem8080[breakpt1] = brkdata1; breakpt1 = 0; // Restore contents of breakpoint 2 if (breakpt2) mem8080[breakpt2] = brkdata2; breakpt2 = 0; } xcmd(); listptr = savepc; for (;;) { int nchars; print("-"); nchars = read(0,cmdline,sizeof(cmdline)-1); if (nchars < 0) return; cmdline[nchars] = 0; for (cptr = cmdline; *cptr != '\0'; cptr++) if (*cptr >= 'a') *cptr -= 'a' - 'A'; cptr = cmdline; switch(*cptr++) { case 'G': if (gcmd()) return; return; // resume execution of 8080 program case 'D': dcmd(); break; case 'X': xcmd(); break; case 'L': lcmd(); break; case 'S': single_step (); // force single stepping return; // resume execution of 8080 program default: printf ("valid commands:\n"); printf (" g go\n"); printf (" d[NNNN] display memory [at address]\n"); printf (" x examine registers registers\n"); printf (" l[NNNN] disassemble instructions [at address]\n"); printf (" s single step\n"); } } }
/* lineeditor(): * This function is fed a pointer to a command line. * It sets up a command line editor for that particular line. * The line is modified in place so, if successful, the function * returns the same pointer but with its contents modified based * on the editor commands executed. * If failure, the function returns (char *)0. */ static char * lineeditor(char *line_to_edit,int type) { lMode = CMD; startOfLine = line_to_edit; curPos = line_to_edit; while(*curPos != ESC) curPos++; *curPos = 0; /* Remove the escape character from the line */ lineLen = (ulong)curPos - (ulong)startOfLine; if (lineLen > 0) { curPos--; putstr(" \b\b"); } else putstr(" \b"); lastsize = 0; shwidx = stridx; srchidx = stridx; while(1) { curChar = getchar(); switch(curChar) { case ESC: if (lMode != CMD) { lMode = CMD; continue; } else { putchar('\n'); return((char *)0); } case '\r': case '\n': putchar('\n'); if (lineLen == 0) return((char *)0); *(char *)(startOfLine + lineLen) = '\0'; return(startOfLine); case CTLC: putchar('\n'); *startOfLine = 0; lineLen = 0; return((char *)0); } switch(lMode) { case CMD: lcmd(type); if (lMode == NEITHER) return((char *)0); break; case INSERT: linsert(); break; case EDIT1: ledit1(); break; case EDIT: ledit(); break; } if (lineLen >= (CMDLINESIZE - 2)) { printf("line overflow\n"); return((char *)0); } } }
int CDemoApp::Run(void) { const CArgs& args = GetArgs(); // Get command-line arguments ... string ServerName = args["S"].AsString(); string UserName = args["U"].AsString(); string Password = args["P"].AsString(); string Database = args["D"].AsString(); try { DBLB_INSTALL_DEFAULT(); CMySQLContext my_context; unique_ptr<CDB_Connection> con(my_context.Connect(ServerName, UserName, Password, 0)); // changing database con->SetDatabaseName(Database); cout << "Database changed" << endl; // creating table { unique_ptr<CDB_LangCmd> lcmd(con->LangCmd("create temporary table tmp_t1(" "a int," "b datetime," "c varchar(100)," "d text," "e double," "bl BLOB)" )); lcmd->Send(); cout << "Table created" << endl; } int nBlobSize = 0xffff; unique_ptr<char> buff( new char[nBlobSize]); // inserting data { char* p = buff.get(); for( int i = 0; i < nBlobSize; i++) *(p++) = i; unique_ptr<CDB_LangCmd> tmp_cmd(con->LangCmd("tmp")); string sql = "insert into tmp_t1 values"; sql += "(1, '2002-11-25 12:45:59', 'Hello, world', 'SOME TEXT', 3.1415, '"; sql += reinterpret_cast<CMySQL_LangCmd*>(tmp_cmd.get())->EscapeString( buff.get(), nBlobSize); sql += ")"; unique_ptr<CDB_LangCmd> lcmd(con->LangCmd(sql)); lcmd->Send(); cout << "Data inserted " << lcmd->RowCount() << " row(s) affected" << endl; } // selecting data { unique_ptr<CDB_LangCmd> lcmd(con->LangCmd("select * from tmp_t1")); lcmd->Send(); while (lcmd->HasMoreResults()) { unique_ptr<CDB_Result> r(lcmd->Result()); while (r->Fetch()) { CDB_Int a; CDB_DateTime b; CDB_VarChar c; CDB_VarChar d; CDB_Double e; CDB_Image blob; r->GetItem(&a); r->GetItem(&b); r->GetItem(&c); r->GetItem(&d); r->GetItem(&e); r->GetItem(&blob); unique_ptr<char> buff2( new char[blob.Size()]); blob.Read( buff2.get(), blob.Size()); int correct = memcmp( buff2.get(), buff.get(), nBlobSize); cout << "a=" << a.Value() << endl << "b=" << b.Value().AsString() << endl << "c=" << c.AsString() << endl << "d=" << d.AsString() << endl << "e=" << e.Value() << endl << "blob size is " << nBlobSize << " blob data is " << (!correct ? "correct" : "not correct") << endl; } } } // selecting data as strings { unique_ptr<CDB_LangCmd> lcmd(con->LangCmd("select * from tmp_t1")); lcmd->Send(); while (lcmd->HasMoreResults()) { unique_ptr<CDB_Result> r(lcmd->Result()); for(unsigned i = 0; i < r->NofItems(); ++i) cout << "[" << r->ItemName(i) << "]"; cout << endl; while (r->Fetch()) { for(unsigned i = 0; i < r->NofItems(); ++i) { CDB_VarChar field; r->GetItem(&field); if(! field.IsNULL()) cout << field.AsString() << endl; else cout << "NULL\n"; } } } } } catch (CDB_Exception& e) { CDB_UserHandler_Stream myExHandler(&cerr); myExHandler.HandleIt(&e); return 1; } catch (const CException&) { return 1; } return 0; }
void ItemHandle::installLaunchScripts() { UserCore::Item::ItemInfoI* item = getItemInfo(); if (!item) return; UserCore::Item::BranchInfoI* branch = item->getCurrentBranch(); if (!branch) return; std::vector<UserCore::Item::Misc::ExeInfoI*> exeList; item->getExeList(exeList); char* scriptBin = NULL; char* scriptXdg = NULL; try { UTIL::FS::readWholeFile(UTIL::STRING::toStr( UTIL::OS::getDataPath(L"scripts/launch_bin_template.sh")), &scriptBin); UTIL::FS::readWholeFile(UTIL::STRING::toStr( UTIL::OS::getDataPath(L"scripts/launch_xdg_template.sh")), &scriptXdg); } catch (gcException &e) { safe_delete(scriptBin); safe_delete(scriptXdg); Warning(gcString("Failed to read launch script template: {0}\n", e)); return; } gcString globalArgs = getUserCore()->getCVarValue("gc_linux_launch_globalargs"); gcString globalExe = getUserCore()->getCVarValue("gc_linux_launch_globalbin"); if (!UTIL::FS::isValidFile(globalExe.c_str())) globalExe = ""; for (size_t x=0; x<exeList.size(); x++) { UserCore::Item::Misc::ExeInfoI* exe = exeList[x]; if (!exe || !UTIL::FS::isValidFile(exe->getExe())) continue; gcString path("{0}/desura_launch_{1}.sh", item->getPath(), UTIL::LIN::sanitiseFileName(exe->getName())); char magicBytes[5] = {0}; try { UTIL::FS::FileHandle fh(exe->getExe(), UTIL::FS::FILE_READ); fh.read(magicBytes, 5); } catch (gcException& e) { continue; } UTIL::LIN::BinType type = UTIL::LIN::getFileType(magicBytes, 5); try { UTIL::FS::FileHandle fh(path.c_str(), UTIL::FS::FILE_WRITE); if (type == UTIL::LIN::BT_UNKNOWN) { gcString lcmd(scriptXdg, exe->getExe()); fh.write(lcmd.c_str(), lcmd.size()); } else { gcString libPath("\"{0}/{1}/{2}/lib\"", UTIL::OS::getAppDataPath(), branch->getItemId().getFolderPathExtension(), (uint32)branch->getBranchId()); gcString libPathB("{0}/lib{1}", item->getPath(), branch->is32Bit()?"32":"64"); if (UTIL::FS::isValidFolder(libPathB.c_str())) { libPath += ":"; libPath += "\"" + libPathB + "\""; } const char* exePath = exe->getExe(); gcString args; gcString ea(exe->getExeArgs()); if (globalExe.size() > 0) { args += gcString(exePath); exePath = globalExe.c_str(); } if (ea.size() > 0) { if (args.size() > 0) args += " "; args += ea; } if (globalArgs.size() > 0) { if (args.size() > 0) args += " "; args += globalArgs; } gcString lcmd(scriptBin, exePath, args, libPath); fh.write(lcmd.c_str(), lcmd.size()); } } catch (gcException &e) { } chmod(path.c_str(), S_IRWXU|S_IRGRP|S_IROTH); } safe_delete(scriptBin); safe_delete(scriptXdg); }