static uint32_t countPaths(btstring_t *data, int32_t x, int32_t y) { uint32_t rval = 0; if (x > 0) { if (isPath(data->buf[xy2index(x - 1, y)])) { rval++; } } if (y > 0) { if (isPath(data->buf[xy2index(x, y - 1)])) { rval++; } } if (y < 15) { if (isPath(data->buf[xy2index(x, y + 1)])) { rval++; } } if (x < 15) { if (isPath(data->buf[xy2index(x + 1, y)])) { rval++; } } return rval; }
static void move(btstring_t *data, int32_t *x, int32_t *y) { if (*x > 0) { if (isPath(data->buf[xy2index(*x - 1, *y)])) { *x = *x - 1; return; } } if (*y > 0) { if (isPath(data->buf[xy2index(*x, *y - 1)])) { *y = *y - 1; return; } } if (*x < 15) { if (isPath(data->buf[xy2index(*x + 1, *y)])) { *x = *x + 1; return; } } if (*y < 15) { if (isPath(data->buf[xy2index(*x, *y + 1)])) { *y = *y + 1; return; } } }
void FileManager::run() { qDebug() << "run the thread to copy file..."; if( isPath( srcfileName) ) { //qDebug() << srcfileName << destinationPath; copyFolder(srcfileName, destinationPath); } else { copyFile(srcfileName, destinationPath); } qDebug() << "copy done!"; // fileSize = src.size(); // int oldPercent = 0; // for(qint64 index = 0; index < fileSize; ++index) // { // dst.write(src.read(index)); // src.seek(index); // dst.seek(index); // int percent = ((index + 1) * 100) / fileSize; // if (oldPercent != percent) // { // emit verificationProgressSignal(percent); // oldPercent = percent; // } // } //emit verificationDone(); }
MyString dirname(MyString path) { assert(isPath(path)); int pos = path.size() - 1; for (; pos >= 0 && path[pos] != _T('\\'); --pos) { } return path.substr(0, pos); }
void adjustSizes(char** argv, int argc, size_t& commandsSize, size_t& filesSizes) { for (int word = 1; word < argc; ++word) { if (isPath(argv[word])) filesSizes++; else if (isCommand(argv[word])) commandsSize++; } }
MyString dirname(MyString path) { if (!isPath(path)) { return _T(""); } int pos = path.size() - 1; for (; pos >= 0 && path[pos] != _T('\\'); --pos) { } return path.substr(0, pos); }
MyString basename(MyString path) { assert(isPath(path)); int pos = path.size() - 1; for (; pos >= 0 && path[pos] != _T('\\'); --pos) { } if (pos < 0) { return _T(""); } return path.substr(pos + 1); }
// 不改变路径中的大小写情况 MyString VirtualDiskNode::pathNormalize(MyString path) const { MyString ret; if (!isPath(path)) { assert(0); return ret; } if (isVolumnRelative(path)) { ret = join(m_pwd.substr(0, 2), path); } else if (isRelative(path)) { if (path == _T(".")) { ret = m_pwd; } else if (path == _T("..")) { ret = dirname(m_pwd); } else if (path.startWith(_T("..\\"))) { ret = dirname(m_pwd) + path.substr(2); } else if (path.startWith(_T(".\\"))) { ret = m_pwd + path.substr(1); } // 直接输入名字的情况 else if (!match(path, _T("?:*"))) { ret = m_pwd + _T("\\") + path; } } // 绝对路径中处理:\dir\file的情况 //else if (path.startWith(_T("\\"))) //{ // ret = _T("c:") + path; //} if (path.endWith(_T("\\"))) { ret = ret.substr(0, ret.size() - 1); } return ret; }
bool loadPCD(char *name, pcType cloud_ptr) { if (isPath(name) != PT_FILE) { std::cout << "Filename " << name << " is not a valid file." << std::endl; return false; } bool result = (pcl::io::loadPCDFile(name, *cloud_ptr) == 0); if (result) std::cout << "Loaded file " << name << " with " << cloud_ptr->size() << " points."; std::cout << std::endl; return result; }
//////////////////////////////////////////////////////////////////////////////// // When a Lexer object is constructed with a string, this method walks through // the stream of low-level tokens. bool Lexer::token (std::string& token, Lexer::Type& type) { // Eat white space. while (isWhitespace (_text[_cursor])) utf8_next_char (_text, _cursor); // Terminate at EOS. if (isEOS ()) return false; // The sequence is specific, and must follow these rules: // - date < duration < uuid < identifier // - dom < uuid // - uuid < hex < number // - url < pair < identifier // - hex < number // - separator < tag < operator // - path < substitution < pattern // - set < number // - word last if (isString (token, type, "'\"") || isDate (token, type) || isDuration (token, type) || isURL (token, type) || isPair (token, type) || isUUID (token, type, true) || isSet (token, type) || isDOM (token, type) || isHexNumber (token, type) || isNumber (token, type) || isSeparator (token, type) || isTag (token, type) || isPath (token, type) || isSubstitution (token, type) || isPattern (token, type) || isOperator (token, type) || isIdentifier (token, type) || isWord (token, type)) return true; return false; }
int parse(const MyString& cmd, MyString* name, Vector<MyString>* pathes, Vector<MyString>* switches) { if (name == nullptr || pathes == nullptr || switches == nullptr) { return -1; } pathes->clear(); switches->clear(); int i = getCmd(cmd, 0, name); if (i == cmd.size()) { return 0; } if (*name == _T("mkdir")) { while (_istspace(cmd[i])) ++i; int j = cmd.size() - 1; while (_istspace(cmd[j])) --j; MyString path = cmd.substr(i, j - i + 1); pathes->append(path); return 0; } for (; i < cmd.size();) { if (_istspace(cmd[i])) { ++i; } else if (cmd[i] != _T('/')) { MyString path; i = getPath(cmd, i, &path); if (!isPath(path) && !hasWildcard(path)) { printf("文件名、目录名或卷标语法不正确\n"); *name = _T(""); pathes->clear(); switches->clear(); return -1; } pathes->append(path); } else if (cmd[i] == _T('/')) { MyString s; i = getSwitch(cmd, i, &s); switches->append(s); } else { assert(0); return -1; } } return 0; }
/* #define SERVER_DEBUG 1 */ int main(int argc, char *argv[]) { int status; rsComm_t rsComm; char *tmpStr; ProcessType = AGENT_PT; #ifdef RUN_SERVER_AS_ROOT #ifndef windows_platform if (initServiceUser() < 0) { exit (1); } #endif #endif #ifdef windows_platform iRODSNtAgentInit(argc, argv); #endif #ifndef windows_platform signal(SIGINT, signalExit); signal(SIGHUP, signalExit); signal(SIGTERM, signalExit); /* set to SIG_DFL as recommended by andy.salnikov so that system() * call returns real values instead of 1 */ signal(SIGCHLD, SIG_DFL); signal(SIGUSR1, signalExit); signal(SIGPIPE, rsPipSigalHandler); #endif #ifndef windows_platform #ifdef SERVER_DEBUG if (isPath ("/tmp/rodsdebug")) sleep (20); #endif #endif #ifdef SYS_TIMING rodsLogLevel(LOG_NOTICE); printSysTiming ("irodsAgent", "exec", 1); #endif memset (&rsComm, 0, sizeof (rsComm)); status = initRsCommWithStartupPack (&rsComm, NULL); if (status < 0) { sendVersion (rsComm.sock, status, 0, NULL, 0); cleanupAndExit (status); } /* Handle option to log sql commands */ tmpStr = getenv (SP_LOG_SQL); if (tmpStr != NULL) { #ifdef IRODS_SYSLOG int j = atoi(tmpStr); rodsLogSqlReq(j); #else rodsLogSqlReq(1); #endif } /* Set the logging level */ tmpStr = getenv (SP_LOG_LEVEL); if (tmpStr != NULL) { int i; i = atoi(tmpStr); rodsLogLevel(i); } else { rodsLogLevel(LOG_NOTICE); /* default */ } #ifdef IRODS_SYSLOG /* Open a connection to syslog */ #ifdef SYSLOG_FACILITY_CODE openlog("rodsAgent",LOG_ODELAY|LOG_PID,SYSLOG_FACILITY_CODE); #else openlog("rodsAgent",LOG_ODELAY|LOG_PID,LOG_DAEMON); #endif #endif status = getRodsEnv (&rsComm.myEnv); if (status < 0) { sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0); cleanupAndExit (status); } #if RODS_CAT if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) { chlDebug(rsComm.myEnv.rodsDebug); } #endif #ifdef RULE_ENGINE_N status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm); #else status = initAgent (&rsComm); #endif #ifdef SYS_TIMING printSysTiming ("irodsAgent", "initAgent", 0); #endif if (status < 0) { sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0); cleanupAndExit (status); } /* move configConnectControl behind initAgent for now. need zoneName if * the user does not specify one in the input */ initConnectControl (); if (rsComm.clientUser.userName[0] != '\0') { status = chkAllowedUser (rsComm.clientUser.userName, rsComm.clientUser.rodsZone); if (status < 0) { sendVersion (rsComm.sock, status, 0, NULL, 0); cleanupAndExit (status); } } /* send the server version and atatus as part of the protocol. Put * rsComm.reconnPort as the status */ status = sendVersion (rsComm.sock, status, rsComm.reconnPort, rsComm.reconnAddr, rsComm.cookie); if (status < 0) { sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0); cleanupAndExit (status); } #ifdef SYS_TIMING printSysTiming ("irodsAgent", "sendVersion", 0); #endif logAgentProc (&rsComm); status = agentMain (&rsComm); cleanupAndExit (status); return (status); }
//******************************************************************** // // Method: showHideButton // Parameter: none, // test all inputs // // Purpose: enable Hide-Button, eventually call ProblemDialog // //******************************************************************** void MainWindow::showHideButton() { if(ui->textFromDocRadio->isChecked() && isPath(ui->textPathTextField->text()) && isPath(ui->picPathTextField->text())) { ui->hideButton->setEnabled(true); if(ui->textPathTextField->text().endsWith(".png")) { ui->encryptCheckBox->setChecked(false); ui->encryptCheckBox->setEnabled(false); ui->asciiUnicodeLabel->setText("picture"); } else { ui->encryptCheckBox->setEnabled(true); QFile file(ui->textPathTextField->text()); file.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream in(&file); QString plain = in.readAll(); format = getFormat(plain); file.close(); if(format == UNICODE) ui->asciiUnicodeLabel->setText("Unicode format"); else ui->asciiUnicodeLabel->setText("Ascii format"); } } else if(ui->textFromFieldRadio->isChecked() && !(ui->textEdit->toPlainText().isEmpty())) { ui->encryptCheckBox->setEnabled(true); format = getFormat(ui->textEdit->toPlainText()); if(format == UNICODE) ui->asciiUnicodeLabel->setText("Unicode format"); else ui->asciiUnicodeLabel->setText("Ascii format"); if(isPath(ui->picPathTextField->text())) { ui->hideButton->setEnabled(true); } } else { ui->hideButton->setEnabled(false); ui->asciiUnicodeLabel->setText(""); } bool show = ui->hideButton->isEnabled(); if(ui->encryptCheckBox->isChecked()) { int keyLength = ui->keyTextField->text().size(); int oldFormat = format; if(getFormat(ui->keyTextField->text()) == ASCII) { switch (ui->techniqueComboBox->currentIndex()) { case 0: //Caesar if(keyLength == 1) { ui->hideButton->setEnabled(true); ui->keyTipLabel->setText("ok"); } else { ui->hideButton->setEnabled(false); ui->keyTipLabel->setText("only one letter key"); } break; case 1: //Vigenère if(keyLength > 0) { ui->keyTipLabel->setText("ok"); ui->hideButton->setEnabled(true); } else { ui->keyTipLabel->setText("one letter minimum"); ui->hideButton->setEnabled(false); } break; default: ui->hideButton->setEnabled(false); ui->keyTipLabel->setText(""); } } else { ui->keyTipLabel->setText("key is not Ascii format"); ui->hideButton->setEnabled(false); } format = oldFormat; if(show != ui->hideButton->isEnabled()) ui->hideButton->setEnabled(false); } }
int main(/*int argc, char** argv*/) { int argc = 4; char** argv = new char*[argc]; argv[1] = "--comments"; argv[2] = "Practice.cpp"; argv[3] = "--format"; size_t commandsSize = 0, filesSizes = 0; adjustSizes(argv, argc, commandsSize, filesSizes); Command** commands = new Command*[commandsSize]; File* files = new File [filesSizes]; size_t filePos = 0, commandPos = 0; for (int pos = 1; pos < argc; ++pos) { if (isPath(argv[pos])) { try { File currFile(argv[pos]); files[filePos++] = currFile; } catch (std::exception& e) { std::cerr << e.what() << std::endl; } } else if (isCommand(argv[pos])) { try { commands[commandPos++] = createCommand(argv[pos]); } catch (std::invalid_argument& i) { std::cerr << i.what() << std::endl; } } else std::cerr << "\n The " << pos << " command is invalid! \n"; } try { for (filePos = 0; filePos < filesSizes; ++filePos) executeCommands(files[filePos], commands, commandsSize); } catch (std::invalid_argument& i) { std::cerr << i.what() << std::endl; } catch (std::exception& e) { std::cerr << e.what() << std::endl; } clear(commands, commandsSize, files); delete[] argv; return 0; }
/* #define SERVER_DEBUG 1 */ int main( int, char ** ) { int status; rsComm_t rsComm; char *tmpStr; ProcessType = AGENT_PT; // capture server properties irods::server_properties& props = irods::server_properties::getInstance(); irods::error result = props.capture_if_needed(); if ( !result.ok() ) { irods::log( PASSMSG( "failed to read server configuration", result ) ); } #ifdef windows_platform iRODSNtAgentInit( argc, argv ); #endif #ifndef windows_platform signal( SIGINT, signalExit ); signal( SIGHUP, signalExit ); signal( SIGTERM, signalExit ); /* set to SIG_DFL as recommended by andy.salnikov so that system() * call returns real values instead of 1 */ signal( SIGCHLD, SIG_DFL ); signal( SIGUSR1, signalExit ); signal( SIGPIPE, SIG_IGN ); // register irods signal handlers register_handlers(); #endif #ifndef windows_platform #ifdef SERVER_DEBUG if ( isPath( "/tmp/rodsdebug" ) ) { sleep( 20 ); } #endif #endif memset( &rsComm, 0, sizeof( rsComm ) ); rsComm.thread_ctx = ( thread_context* )malloc( sizeof( thread_context ) ); status = initRsCommWithStartupPack( &rsComm, NULL ); // =-=-=-=-=-=-=- // manufacture a network object for comms irods::network_object_ptr net_obj; irods::error ret = irods::network_factory( &rsComm, net_obj ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); } if ( status < 0 ) { sendVersion( net_obj, status, 0, NULL, 0 ); cleanupAndExit( status ); } /* Handle option to log sql commands */ tmpStr = getenv( SP_LOG_SQL ); if ( tmpStr != NULL ) { #ifdef SYSLOG int j = atoi( tmpStr ); rodsLogSqlReq( j ); #else rodsLogSqlReq( 1 ); #endif } /* Set the logging level */ tmpStr = getenv( SP_LOG_LEVEL ); if ( tmpStr != NULL ) { int i; i = atoi( tmpStr ); rodsLogLevel( i ); } else { rodsLogLevel( LOG_NOTICE ); /* default */ } #ifdef SYSLOG /* Open a connection to syslog */ openlog( "rodsAgent", LOG_ODELAY | LOG_PID, LOG_DAEMON ); #endif status = getRodsEnv( &rsComm.myEnv ); if ( status < 0 ) { rodsLog( LOG_ERROR, "agentMain :: getRodsEnv failed" ); sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 ); cleanupAndExit( status ); } ret = setRECacheSaltFromEnv(); if ( !ret.ok() ) { rodsLog( LOG_ERROR, "rodsAgent::main: Failed to set RE cache mutex name\n%s", ret.result().c_str() ); exit( 1 ); } // =-=-=-=-=-=-=- // load server side pluggable api entries irods::api_entry_table& RsApiTable = irods::get_server_api_table(); irods::pack_entry_table& ApiPackTable = irods::get_pack_table(); ret = irods::init_api_table( RsApiTable, ApiPackTable, false ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return 1; } // =-=-=-=-=-=-=- // load client side pluggable api entries irods::api_entry_table& RcApiTable = irods::get_client_api_table(); ret = irods::init_api_table( RcApiTable, ApiPackTable, true ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return 1; } #if RODS_CAT if ( strstr( rsComm.myEnv.rodsDebug, "CAT" ) != NULL ) { chlDebug( rsComm.myEnv.rodsDebug ); } #endif status = initAgent( RULE_ENGINE_TRY_CACHE, &rsComm ); if ( status < 0 ) { rodsLog( LOG_ERROR, "agentMain :: initAgent failed: %d", status ); sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 ); cleanupAndExit( status ); } /* move configConnectControl behind initAgent for now. need zoneName if * the user does not specify one in the input */ initConnectControl(); if ( rsComm.clientUser.userName[0] != '\0' ) { status = chkAllowedUser( rsComm.clientUser.userName, rsComm.clientUser.rodsZone ); if ( status < 0 ) { sendVersion( net_obj, status, 0, NULL, 0 ); cleanupAndExit( status ); } } // =-=-=-=-=-=-=- // handle negotiations with the client regarding TLS if requested // this scope block makes valgrind happy { std::string neg_results; ret = irods::client_server_negotiation_for_server( net_obj, neg_results ); if ( !ret.ok() || neg_results == irods::CS_NEG_FAILURE ) { irods::log( PASS( ret ) ); // =-=-=-=-=-=-=- // send a 'we failed to negotiate' message here?? // or use the error stack rule engine thingie irods::log( PASS( ret ) ); sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 ); cleanupAndExit( ret.code() ); } else { // =-=-=-=-=-=-=- // copy negotiation results to comm for action by network objects snprintf( rsComm.negotiation_results, sizeof( rsComm.negotiation_results ), "%s", neg_results.c_str() ); //rsComm.ssl_do_accept = 1; } } /* send the server version and atatus as part of the protocol. Put * rsComm.reconnPort as the status */ ret = sendVersion( net_obj, status, rsComm.reconnPort, rsComm.reconnAddr, rsComm.cookie ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 ); cleanupAndExit( status ); } logAgentProc( &rsComm ); // call initialization for network plugin as negotiated irods::network_object_ptr new_net_obj; ret = irods::network_factory( &rsComm, new_net_obj ); if ( !ret.ok() ) { return ret.code(); } ret = sockAgentStart( new_net_obj ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } new_net_obj->to_server( &rsComm ); status = agentMain( &rsComm ); // call initialization for network plugin as negotiated ret = sockAgentStop( new_net_obj ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } new_net_obj->to_server( &rsComm ); cleanup(); free( rsComm.thread_ctx ); free( rsComm.auth_scheme ); rodsLog( LOG_NOTICE, "Agent exiting with status = %d", status ); return status; }