void RiscComm::onConsoleInput(QString input) { m_sp->readAll(); // flush any residual crap out (from FPGA reset for example) if (input.compare("s") == 0) { sendStep(); doScan(); } else if (input.compare("sc") == 0) doScan(); else if (input.compare("q") == 0) QCoreApplication::exit(); else if (input.compare("r") == 0) sendRun(); else if (input.compare("rs") == 0) sendReset(); else if (input.compare("st") == 0) { sendStop(); doScan(); } else if (input.startsWith("wp")) { QStringList args = input.split(" "); if (args.length() == 2) { // upload a file sendProgram(args.at(1)); } } else if (input.compare("clrmem") == 0) { QByteArray zeros; zeros.fill(0, 256); writeMem(zeros, 0, true); } else if (input.compare("dm") == 0) { dumpMem(); } else qDebug() << "Unknown command:" << input; }
void wallerScan() { if (!wallReached) { return; } int x = getX(), y = getY(); if (x == y && y == 0) { doScan(9); } else if (x == 0 && y == 7) { doScan(3); } else if (x == y && y == 7) { doScan(1); } else if (y == 0 && x == 7) { doScan(7); } else if (x > 0 && 7 > x && y == 0) { doScan(8); } else if (x > 0 && 7 > x && y == 7) { doScan(2); } else if (y > 0 && 7 > y && x == 0) { doScan(6); } else if (y > 0 && 7 > y && x == 7) { doScan(4); } }
UINT ScannerThread::run() { for(;;) { doScan(); *m_busy = false; suspend(); } }
// --------------------------------------------------------------------------- void draw_WifiScan() { Screen_DrawBorder(_lng(WIFI_SCAN_TITLE)); if(WifiScan_First == 1) { // first draw screen, on second draw scan for wifi networks WifiScan_First = 2; } else if(WifiScan_First == 2) { WifiScan_First = 0; doScan(); return; } if(WifiScan_First == 0) { // draw menu Menu_Draw(menu_wifi_scan, 1, 8); } else { // draw 'scanning...' GLCDD_Rect r; r.x = SCREEN_W / 2 - GLCDD_StringWidth(fnt_dejavu_9b, _lng(SCANNING)) / 2; r.y = SCREEN_H / 2 - GLCDD_FontHeight(fnt_dejavu_9b) / 2; r.w = SCREEN_W - 4; r.h = -1; GLCDD_Print(fnt_dejavu_9b, &r, _lng(SCANNING)); } }
void YarrGui::on_doScansButton_clicked(){ ui->scanProgressBar->setValue(0); unsigned int M = scanVec.size(); for(unsigned int i = 0; i < M; i++){ doScan(scanVec.at(i)); ui->scanProgressBar->setValue(100*(i+1)/M); } ui->scanProgressBar->setValue(100); }
int main(int argc, char* argv[]) { int res; unsigned char buf[RELAY_COMMAND_SIZE]; hid_device *handle; unsigned char command; if (argc != 2) { fprintf(stderr, "usage: %s [on|off]\n", argv[0]); exit(1); } if (strcmp(argv[1], "on") == 0) { command = RELAY_STATE_ON; } else if (strcmp(argv[1], "off") == 0) { command = RELAY_STAT_OFF; } else if (strcmp(argv[1], "scan") == 0) { return doScan(); } else { fprintf(stderr, "usage: %s [on|off]\n", argv[0]); exit(1); } if (hid_init()) { fprintf(stderr, "can't init hid lib\n"); exit(1); } // Set up the command buffer. memset(buf,0x00,sizeof(buf)); buf[1] = command; buf[2] = RELAY_NUMBER; // Open the device using the VID, PID, // and optionally the Serial number. ////handle = hid_open(0x4d8, 0x3f, L"12345"); handle = hid_open(RELAY_VENDOR_ID, RELAY_PRODUCT_ID, NULL); if (!handle) { printf("unable to open device\n"); return 1; } res = hid_write(handle, buf, sizeof(buf)); if (res < 0) { printf("Unable to send command\n"); } hid_close(handle); /* Free static HIDAPI objects. */ hid_exit(); exit(0); }
MStatus exportTerrain::doIt( const MArgList& args ) { MItDag::TraversalType traversalType = MItDag::kDepthFirst; MFn::Type filter = MFn::kMesh; MStatus status; if(!fout.good()) cout << "Error opening file: " << endl; status = doScan( args,traversalType, filter ); return status; fout.close(); };
void ScanThread::run() { abort = false; folders = movies = subtitles = 0; fileList.clear(); visited.clear(); searchFilters.clear(); searchFilters << "*.avi" << "*.asf" << "*.divx" << "*.mkv" << "*.mov" << "*.mp4" << "*.mpeg" << "*.mpg" << "*.ogm" << "*.rm" << "*.rmvb" << "*.wmv"; QDir::Filters filters = QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot | QDir::Readable | QDir::Hidden; if(!followSymLinks) filters |= QDir::NoSymLinks; emit scanFinished(doScan(searchPath, filters)); }
bool ScanThread::doScan(const QString & path, QDir::Filters filters) { QString myPath = QFileInfo(path).absoluteFilePath(); if(!QDir().exists(myPath)) return false; QString myCPath = QDir(path).canonicalPath(); if(visited.contains(myCPath)) return true; visited << myCPath; emit folderChange(myPath); ++folders; QFileInfoList list = QDir(myPath).entryInfoList(searchFilters, filters); for(QFileInfoList::iterator p=list.begin(); p != list.end(); p++) { if(abort) return false; if((*p).isDir() && ((*p).absoluteFilePath() != myPath)) { if(!doScan((*p).absoluteFilePath(), filters)) return false; } else { if(!QFile::exists((*p).absoluteFilePath())) continue; ++movies; if(QFile::exists((*p).absolutePath() + "/" + (*p).completeBaseName() + ".txt")) { ++subtitles; fileList << (*p).absoluteFilePath(); } } } return true; }
void GameScanner::doScanAll() { QList<GameHandler*> hlist; MSqlQuery query(MSqlQuery::InitCon()); query.prepare("SELECT DISTINCT playername FROM gameplayers " "WHERE playername <> '';"); if (!query.exec()) MythDB::DBError("doScanAll - selecting playername", query); while (query.next()) { QString name = query.value(0).toString(); GameHandler *hnd = GameHandler::GetHandlerByName(name); if (hnd) hlist.append(hnd); } doScan(hlist); }
void VideoScanner::doScanAll() { doScan(GetVideoDirs()); }
void GameUI::customEvent(QEvent *event) { if (event->type() == DialogCompletionEvent::kEventType) { DialogCompletionEvent *dce = (DialogCompletionEvent*)(event); QString resultid = dce->GetId(); QString resulttext = dce->GetResultText(); if (resultid == "showMenuPopup") { if (resulttext == tr("Edit Details")) { edit(); } if (resulttext == tr("Scan For Changes")) { doScan(); } else if (resulttext == tr("Show Information")) { showInfo(); } else if (resulttext == tr("Make Favorite") || resulttext == tr("Remove Favorite")) { toggleFavorite(); } else if (resulttext == tr("Retrieve Details")) { gameSearch(); } } else if (resultid == "chooseSystemPopup") { if (!resulttext.isEmpty() && resulttext != tr("Cancel")) { MythGenericTree *node = m_gameUITree->GetCurrentNode(); RomInfo *romInfo = qVariantValue<RomInfo *>(node->GetData()); GameHandler::Launchgame(romInfo, resulttext); } } else if (resultid == "editMetadata") { MythGenericTree *node = m_gameUITree->GetCurrentNode(); RomInfo *oldRomInfo = qVariantValue<RomInfo *>(node->GetData()); delete oldRomInfo; RomInfo *romInfo = qVariantValue<RomInfo *>(dce->GetData()); node->SetData(qVariantFromValue(romInfo)); node->SetText(romInfo->Gamename()); romInfo->SaveToDatabase(); updateChangedNode(node, romInfo); } else if (resultid == "detailsPopup") { // Play button pushed itemClicked(0); } } if (event->type() == MetadataLookupEvent::kEventType) { MetadataLookupEvent *lue = (MetadataLookupEvent *)event; MetadataLookupList lul = lue->lookupList; if (m_busyPopup) { m_busyPopup->Close(); m_busyPopup = NULL; } if (lul.isEmpty()) return; if (lul.count() == 1) { OnGameSearchDone(lul.takeFirst()); } else { MetadataResultsDialog *resultsdialog = new MetadataResultsDialog(m_popupStack, lul); connect(resultsdialog, SIGNAL(haveResult(MetadataLookup*)), SLOT(OnGameSearchListSelection(MetadataLookup*)), Qt::QueuedConnection); if (resultsdialog->Create()) m_popupStack->AddScreen(resultsdialog); } } else if (event->type() == MetadataLookupFailure::kEventType) { MetadataLookupFailure *luf = (MetadataLookupFailure *)event; MetadataLookupList lul = luf->lookupList; if (m_busyPopup) { m_busyPopup->Close(); m_busyPopup = NULL; } if (lul.size()) { MetadataLookup *lookup = lul.takeFirst(); MythGenericTree *node = qVariantValue<MythGenericTree *>(lookup->GetData()); if (node) { RomInfo *metadata = qVariantValue<RomInfo *>(node->GetData()); if (metadata) { } } LOG(VB_GENERAL, LOG_ERR, QString("No results found for %1").arg(lookup->GetTitle())); } } else if (event->type() == ImageDLEvent::kEventType) { ImageDLEvent *ide = (ImageDLEvent *)event; MetadataLookup *lookup = ide->item; if (!lookup) return; handleDownloadedImages(lookup); } }
void Context::scan() { myIsReady = false; emit readyChanged(); QTimer::singleShot(500, this, SLOT(doScan())); }
/* Process argument list */ int opt_Scan(int argc, char *argv[], int nOpts, opt_Option *opts, opt_Handler handler, void *client) { int i; int argi; char *p = argv[0] + strlen(argv[0]); opt_init(); /* Extract program name, scan for Unix, DOS, and Macintosh separators */ while (--p >= argv[0] && *p != '/' && *p != '\\' && *p != ':') ; opt_progname = p + 1; /* Initialize argument package */ opt_globals.nOpts = nOpts; opt_globals.opts = opts; if (handler != NULL) { opt_globals.handler = handler; opt_globals.client = client; } else { opt_globals.handler = defaultHandler; opt_globals.client = NULL; } /* Sort options into alphabetical order */ qsort(opts, nOpts, sizeof(opt_Option), cmpOptions); /* Set defaults */ for (i = 0; i < opt_globals.nOpts; i++) { opt_Option *opt = &opt_globals.opts[i]; opt->flags &= ~opt_PRESENT; if (opt->scan == NULL) opt_Error(opt_NoScanner, opt, NULL); else if (opt->scan != opt_Call) opt->scan(1, &opt->dflt, 0, opt); } argi = 1; while (argi < argc) { char *arg = argv[argi]; opt_Option *opt = lookup(arg, matchWhole); if (opt != NULL) /* Whole argument matched option */ argi = doScan(argc, argv, argi + 1, opt); else { opt = lookup(arg, matchPart); if (opt != NULL) { /* Initial part of argument matched option */ if (opt->flags & opt_COMBINED) { /* Argument is a combination of options */ int plen = opt->length; argi = doScan(argc, argv, argi + 1, opt); for (;;) { /* Trim last option name from argument and rematch */ strcpy(&arg[plen], &arg[strlen(opt->name)]); if (arg[plen] == '\0') break; /* No more options left */ opt = lookup(arg, matchPart); if (opt == NULL) { opt_Error(opt_Unknown, NULL, arg); break; } argi = doScan(argc, argv, argi, opt); } } else { /* Option and value combined together */ argv[argi] = arg + strlen(opt->name); argi = doScan(argc, argv, argi, opt); } } else break; } } /* Test that required options were actually present */ for (i = 0; i < opt_globals.nOpts; i++) { opt_Option *opt = &opt_globals.opts[i]; if (opt->flags & opt_REQUIRED && !(opt->flags & opt_PRESENT)) opt_Error(opt_Required, opt, NULL); } return (opt_globals.error != 0) ? 0 : argi; }
void YarrGui::on_runCustomScanButton_clicked(){ doScan("CS"); ui->runCustomScanButton->setEnabled(false); return; }
// send memory buffer to ICAP server for scanning int icapinstance::scanMemory(HTTPHeader * requestheader, HTTPHeader * docheader, const char *user, int filtergroup, const char *ip, const char *object, unsigned int objectsize, NaughtyFilter * checkme, const String *disposition, const String *mimetype) { lastvirusname = lastmessage = ""; Socket icapsock; if (not doHeaders(icapsock, requestheader, docheader, objectsize)) { icapsock.close(); return DGCS_SCANERROR; } #ifdef DGDEBUG std::cerr << "About to send memory data to icap" << std::endl; if (usepreviews && (objectsize > previewsize)) std::cerr << "Sending preview first" << std::endl; #endif unsigned int sent = 0; if (usepreviews && (objectsize > previewsize)) { try { if (!icapsock.writeToSocket(object, previewsize, 0, o.content_scanner_timeout)) { throw std::runtime_error("standard error"); } sent += previewsize; icapsock.writeString("\r\n0\r\n\r\n"); int rc = doScan(icapsock, docheader, object, objectsize, checkme); if (rc != ICAP_CONTINUE) return rc; // some servers send "continue" immediately followed by another response if (icapsock.checkForInput()) { int rc = doScan(icapsock, docheader, object, objectsize, checkme); if (rc != ICAP_NODATA) return rc; } char objectsizehex[32]; snprintf(objectsizehex, sizeof(objectsizehex), "%x\r\n", objectsize-previewsize); icapsock.writeString(objectsizehex); } catch (std::exception& e) { #ifdef DGDEBUG std::cerr << "Exception sending message preview to ICAP: " << e.what() << std::endl; #endif // this *might* just be an early response & closed connection if (icapsock.checkForInput()) { int rc = doScan(icapsock, docheader, object, objectsize, checkme); if (rc != ICAP_NODATA) return rc; } icapsock.close(); lastmessage = "Exception sending message preview to ICAP"; syslog(LOG_ERR, "Exception sending message preview to ICAP: %s", e.what()); return DGCS_SCANERROR; } } try { icapsock.writeToSockete(object + sent, objectsize - sent, 0, o.content_scanner_timeout); #ifdef DGDEBUG std::cout << "total sent to icap: " << objectsize << std::endl; #endif icapsock.writeString("\r\n0\r\n\r\n"); // end marker #ifdef DGDEBUG std::cout << "memory was sent to icap" << std::endl; #endif } catch(std::exception & e) { #ifdef DGDEBUG std::cerr << "Exception sending memory file to ICAP: " << e.what() << std::endl; #endif // this *might* just be an early response & closed connection if (icapsock.checkForInput()) { int rc = doScan(icapsock, docheader, object, objectsize, checkme); if (rc != ICAP_NODATA) return rc; } icapsock.close(); lastmessage = "Exception sending memory file to ICAP"; syslog(LOG_ERR, "Exception sending memory file to ICAP: %s", e.what()); return DGCS_SCANERROR; } return doScan(icapsock, docheader, object, objectsize, checkme); }
// send file contents for scanning int icapinstance::scanFile(HTTPHeader * requestheader, HTTPHeader * docheader, const char *user, int filtergroup, const char *ip, const char *filename, NaughtyFilter * checkme, const String *disposition, const String *mimetype) { lastmessage = lastvirusname = ""; int filefd = open(filename, O_RDONLY); if (filefd < 0) { #ifdef DGDEBUG std::cerr << "Error opening file (" << filename << "): " << strerror(errno) << std::endl; #endif lastmessage = "Error opening file to send to ICAP"; syslog(LOG_ERR, "Error opening file to send to ICAP: %s", strerror(errno)); return DGCS_SCANERROR; } lseek(filefd, 0, SEEK_SET); unsigned int filesize = lseek(filefd, 0, SEEK_END); Socket icapsock; if (not doHeaders(icapsock, requestheader, docheader, filesize)) { icapsock.close(); close(filefd); return DGCS_SCANERROR; } lseek(filefd, 0, SEEK_SET); unsigned int sent = 0; char *data = new char[previewsize]; char *object = new char[100]; int objectsize = 0; #ifdef DGDEBUG std::cerr << "About to send file data to icap" << std::endl; if (usepreviews && (filesize > previewsize)) std::cerr << "Sending preview first" << std::endl; #endif if (usepreviews && (filesize > previewsize)) { try { while (sent < previewsize) { int rc = readEINTR(filefd, data, previewsize); if (rc < 0) { throw std::runtime_error("could not read from file"); } if (rc == 0) { break; // should never happen } if (!icapsock.writeToSocket(data, rc, 0, o.content_scanner_timeout)) { throw std::runtime_error("could not write to socket"); } memcpy(object, data, (rc > 100) ? 100 : rc); objectsize += (rc > 100) ? 100 : rc; sent += rc; } icapsock.writeString("\r\n0\r\n\r\n"); int rc = doScan(icapsock, docheader, object, objectsize, checkme); if (rc != ICAP_CONTINUE) { delete[] data; close(filefd); return rc; } // some servers send "continue" immediately followed by another response if (icapsock.checkForInput()) { int rc = doScan(icapsock, docheader, object, objectsize, checkme); if (rc != ICAP_NODATA) { delete[] data; close(filefd); return rc; } } char objectsizehex[32]; snprintf(objectsizehex, sizeof(objectsizehex), "%x\r\n", filesize-previewsize); icapsock.writeString(objectsizehex); } catch (std::exception& e) { #ifdef DGDEBUG std::cerr << "Exception sending message preview to ICAP: " << e.what() << std::endl; #endif icapsock.close(); lastmessage = "Exception sending message preview to ICAP"; syslog(LOG_ERR, "Exception sending message preview to ICAP: %s", e.what()); delete[] data; close(filefd); // this *might* just be an early response & closed connection if (icapsock.checkForInput()) { int rc = doScan(icapsock, docheader, object, objectsize, checkme); if (rc != ICAP_NODATA) return rc; } return DGCS_SCANERROR; } } delete[] data; data = new char[256 * 1024]; // 256k try { while (sent < filesize) { int rc = readEINTR(filefd, data, 256 * 1024); #ifdef DGDEBUG std::cout << "reading icap file rc: " << rc << std::endl; #endif if (rc < 0) { #ifdef DGDEBUG std::cout << "error reading icap file so throwing exception" << std::endl; #endif throw std::runtime_error("could not read from file"); } if (rc == 0) { #ifdef DGDEBUG std::cout << "got zero bytes reading icap file" << std::endl; #endif break; // should never happen } memcpy(object + objectsize, data, (rc > (100-objectsize)) ? (100-objectsize) : rc); objectsize += (rc > (100-objectsize)) ? (100-objectsize) : rc; icapsock.writeToSockete(data, rc, 0, o.content_scanner_timeout); sent += rc; } #ifdef DGDEBUG std::cout << "total sent to icap: " << sent << std::endl; #endif icapsock.writeString("\r\n0\r\n\r\n"); // end marker #ifdef DGDEBUG std::cout << "file was sent to icap" << std::endl; #endif } catch(std::exception & e) { #ifdef DGDEBUG std::cerr << "Exception sending file to ICAP: " << e.what() << std::endl; #endif lastmessage = "Exception sending file to ICAP"; syslog(LOG_ERR, "Exception sending file to ICAP: %s", e.what()); delete[]data; close(filefd); // this *might* just be an early response & closed connection if (icapsock.checkForInput()) { int rc = doScan(icapsock, docheader, object, objectsize, checkme); if (rc != ICAP_NODATA) return rc; } return DGCS_SCANERROR; } close(filefd); delete[] data; return doScan(icapsock, docheader, object, objectsize, checkme); }
void execute(pruCPU *cpu) { aluInstruction inst; fmt2InstructionHeader fmt2Hdr; while(1) { int didBranch = 0; cgc_memcpy(&inst, (aluInstruction *)&cpu->code[cpu->pc], 4); switch(inst.opFmt) { case 0b000: switch(inst.aluOp) { case ADD: doAdd(cpu, inst); break; case ADC: doAdc(cpu, inst); break; case SUB: doSub(cpu, inst); break; case SUC: doSuc(cpu, inst); break; case LSL: doLsl(cpu, inst); break; case LSR: doLsr(cpu, inst); break; case RSB: doRsb(cpu, inst); break; case RSC: doRsc(cpu, inst); break; case AND: doAnd(cpu, inst); break; case OR: doOr(cpu, inst); break; case XOR: doXor(cpu, inst); break; case NOT: doNot(cpu, inst); break; case MIN: doMin(cpu, inst); break; case MAX: doMax(cpu, inst); break; case CLR: doClr(cpu, inst); break; case SET: doSet(cpu, inst); break; } break; case 0b001: cgc_memcpy(&fmt2Hdr, &inst, sizeof(fmt2Hdr)); switch(fmt2Hdr.subOp) { case JMP: case JAL: ; fmt2BranchInstruction fmt2Branch; cgc_memcpy(&fmt2Branch, &inst, 4); doBranch(cpu, fmt2Branch); didBranch = 1; break; case LDI: ; fmt2LdiInstruction fmt2Ldi; cgc_memcpy(&fmt2Ldi, &inst, 4); doLdi(cpu, fmt2Ldi); break; case LMBD: ; fmt2LmbdInstruction fmt2Lmbd; cgc_memcpy(&fmt2Lmbd, &inst, 4); doLmbd(cpu, fmt2Lmbd); break; case HALT: return; case SCAN: ; fmt2ScanInstruction fmt2Scan; cgc_memcpy(&fmt2Scan, &inst, 4); doScan(cpu, fmt2Scan); break; case SLP: case RESERVED_1: case RESERVED_2: case RESERVED_3: case RESERVED_4: case RESERVED_5: case RESERVED_6: case RESERVED_7: case RESERVED_8: case RESERVED_9: return; } break; case 0b11: ; fmtQatbInstruction qatbInstruction; cgc_memcpy(&qatbInstruction, &inst, 4); doQATB(cpu, qatbInstruction); default: return; } if(didBranch == 0) cpu->pc++; cpu->numExecuted++; if(cpu->numExecuted >= MAX_INSNS) return; } }