KCMCgi::KCMCgi(QWidget *parent, const char *name) : KCModule(parent, name) { setButtons(Default|Apply); QVBoxLayout *topLayout = new QVBoxLayout(this, 0, KDialog::spacingHint()); QGroupBox *topBox = new QGroupBox( 1, Horizontal, i18n("Paths to Local CGI Programs"), this ); topLayout->addWidget( topBox ); mListBox = new QListBox( topBox ); QHBox *buttonBox = new QHBox( topBox ); buttonBox->setSpacing( KDialog::spacingHint() ); mAddButton = new QPushButton( i18n("Add..."), buttonBox ); connect( mAddButton, SIGNAL( clicked() ), SLOT( addPath() ) ); mRemoveButton = new QPushButton( i18n("Remove"), buttonBox ); connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removePath() ) ); connect( mListBox, SIGNAL( clicked ( QListBoxItem * )),this, SLOT( slotItemSelected( QListBoxItem *))); mConfig = new KConfig("kcmcgirc"); load(); updateButton(); KAboutData *about = new KAboutData( I18N_NOOP("kcmcgi"), I18N_NOOP("CGI KIO Slave Control Module"), 0, 0, KAboutData::License_GPL, I18N_NOOP("(c) 2002 Cornelius Schumacher") ); about->addAuthor( "Cornelius Schumacher", 0, "*****@*****.**" ); setAboutData(about); }
PathsManagementWidget::PathsManagementWidget(QWidget* Parent): QWidget(Parent),ui(new Ui::PathsManagementWidget), m_AllowEmpty(true) { ui->setupUi(this); ui->AddButton->setText(""); ui->AddButton->setIcon(QIcon(":/ui/common/icons/add.png")); ui->AddButton->setIconSize(QSize(20,20)); ui->RemoveButton->setText(""); ui->RemoveButton->setIcon(QIcon(":/ui/common/icons/remove.png")); ui->RemoveButton->setIconSize(QSize(20,20)); ui->UpButton->setText(""); ui->UpButton->setIcon(QIcon(":/ui/common/icons/go-up.png")); ui->UpButton->setIconSize(QSize(20,20)); ui->DownButton->setText(""); ui->DownButton->setIcon(QIcon(":/ui/common/icons/go-down.png")); ui->DownButton->setIconSize(QSize(20,20)); connect(ui->AddButton,SIGNAL(clicked()),this,SLOT(addPath())); connect(ui->RemoveButton,SIGNAL(clicked()),this,SLOT(removePath())); connect(ui->UpButton,SIGNAL(clicked()),this,SLOT(moveupPath())); connect(ui->DownButton,SIGNAL(clicked()),this,SLOT(movedownPath())); }
void showHelp(const char * argv[], struct TDCMopts opts) { const char *cstr = removePath(argv[0]); printf("usage: %s [options] <in_folder>\n", cstr); printf(" Options :\n"); printf(" -h : show help\n"); printf(" -f : filename (%%c=comments %%f=folder name %%p=protocol %%i ID of patient %%n=name of patient %%s=series, %%t=time; default '%s')\n",opts.filename); printf(" -o : output directory (omit to save to input folder)\n"); char gzCh = 'n'; if (opts.isGz) gzCh = 'n'; printf(" -z : gz compress images (y/n, default %c)\n", gzCh); #if defined(_WIN64) || defined(_WIN32) printf(" Defaults stored in Windows registry\n"); printf(" Examples :\n"); printf(" %s c:\\DICOM\\dir\n", cstr); printf(" %s -o c:\\out\\dir c:\\DICOM\\dir\n", cstr); printf(" %s -f mystudy%%s c:\\DICOM\\dir\n", cstr); printf(" %s -o \"c:\\dir with spaces\\dir\" c:\\dicomdir\n", cstr); #else printf(" Defaults file : %s\n", opts.optsname); printf(" Examples :\n"); printf(" %s /Users/chris/dir\n", cstr); printf(" %s -o /users/cr/outdir/ -z y ~/dicomdir\n", cstr); printf(" %s -f mystudy%%s ~/dicomdir\n", cstr); printf(" %s -o \"~/dir with spaces/dir\" ~/dicomdir\n", cstr); #endif } //showHelp()
bool ButtonDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { if (!index.parent().isValid() && event->type() == QEvent::MouseButtonRelease) emit removePath(index); return QItemDelegate::editorEvent(event, model, option, index); }
void Tree::remove(const std::string& id) { if (m_idToKeyMap.find(id) == m_idToKeyMap.end()) throw std::runtime_error("ID does not exist"); std::vector<std::string> path = Algorithm::split(m_idToKeyMap[id], " > "); removePath(path); m_keyToIdMap.erase(m_idToKeyMap[id]); m_idToKeyMap.erase(id); }
bool ScanFoldersModel::removePath(const QString &path, const bool removeFromFSWatcher) { const int row = findPathData(path); if (row == -1) return false; removePath(row, removeFromFSWatcher); return true; }
void TearDown() override { Dispatcher::stopServices(); Dispatcher::joinServices(); if (!isPlatform(PlatformType::TYPE_WINDOWS)) { removePath(socket_path); } }
int removePath(char *path, uint32_t *value, uint32_t max, void (* SetProgress)(uint32_t value, uint32_t max)) { SceUID dfd = sceIoDopen(path); if (dfd >= 0) { int res = 0; do { SceIoDirent dir; memset(&dir, 0, sizeof(SceIoDirent)); res = sceIoDread(dfd, &dir); if (res > 0) { if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0) continue; char *new_path = malloc(strlen(path) + strlen(dir.d_name) + 2); snprintf(new_path, MAX_PATH_LENGTH, "%s/%s", path, dir.d_name); if (SCE_S_ISDIR(dir.d_stat.st_mode)) { removePath(new_path, value, max, SetProgress); } else { sceIoRemove(new_path); if (value) (*value)++; if (SetProgress) SetProgress(value ? *value : 0, max); } free(new_path); } } while (res > 0); sceIoDclose(dfd); int ret = sceIoRmdir(path); if (ret < 0) return ret; if (value) (*value)++; if (SetProgress) SetProgress(value ? *value : 0, max); } else { int ret = sceIoRemove(path); if (ret < 0) return ret; if (value) (*value)++; if (SetProgress) SetProgress(value ? *value : 0, max); } return 0; }
void QReliableFileWatch::removeWatch(const QString& file, QObject *recipient) { QHash<QString, Watch>::iterator it = m_targets.find(file); if ( it == m_targets.end() ) { if ( !recipient ) return; // given recipient stop watching any file it = m_targets.begin(); while ( it != m_targets.end() ) { int n = it->recipients.removeAll(recipient); if ( n && it->recipients.isEmpty() ) { // no more recipients watching this file removePath(it.key()); it = m_targets.erase(it); } else { ++it; } } } else { if ( recipient ) { // given recipient stops watching given file it->recipients.removeAll(recipient); if ( it->recipients.isEmpty() ) { // no more recipients watching this file removePath(it.key()); m_targets.erase(it); } } else { // stop watching given file at all m_targets.erase(it); } } }
void GameTracker::RemoveDirectory(const QString& dir) { removePath(dir); QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); while (it.hasNext()) { QString path = QFileInfo(it.next()).canonicalFilePath(); if (m_tracked_files.contains(path)) { m_tracked_files[path]--; if (m_tracked_files[path] == 0) { removePath(path); m_tracked_files.remove(path); emit GameRemoved(path); } } } }
VOID Astar::removePath( PathNode* a_pPath ) { if( a_pPath == NULL ) { return; } removePath( a_pPath->next ); SAFE_DELETE( a_pPath ); }
void GameTracker::UpdateFile(const QString& file) { if (QFileInfo(file).exists()) { emit PathChanged(file); } else if (removePath(file)) { m_tracked_files.remove(file); emit GameRemoved(file); } }
void DatabasePluginTests::SetUp() { auto& rf = RegistryFactory::get(); existing_plugin_ = rf.getActive("database"); rf.plugin("database", existing_plugin_)->tearDown(); setName(name()); path_ = FLAGS_database_path; removePath(path_); auto plugin = rf.plugin("database", getName()); plugin_ = std::dynamic_pointer_cast<DatabasePlugin>(plugin); plugin_->reset(); rf.setActive("database", getName()); }
void SetUp() override { if (isPlatform(PlatformType::TYPE_WINDOWS)) { socket_path = OSQUERY_SOCKET; } else { socket_path = kTestWorkingDirectory; } socket_path += "testextmgr" + std::to_string(rand()); if (!isPlatform(PlatformType::TYPE_WINDOWS)) { removePath(socket_path); if (pathExists(socket_path).ok()) { throw std::domain_error("Cannot test sockets: " + socket_path); } } }
void handleCommandRm(char* args[], int numargs) { if (numargs == 0) { fprintf(stderr, "usage: rm path\n"); } else { int i; //Shell allows you to enter multiple file names separated by spaces for (i = 0; i < numargs; i++) { removePath(args[i]); } } }
int App::process() { cl.add("path", 'p', "directory path (e.g. C:\\Program Files (x86)\\MyProgram)", "path", false); cl.add("file", 'f', "path to an MSI package (e.g. C:\\Downloads\\MyProgram.msi)", "file", false); QString err = cl.parse(); if (!err.isEmpty()) { WPMUtils::outputTextConsole("Error: " + err + "\n"); return 1; } // cl.dump(); int r = 0; QStringList fr = cl.getFreeArguments(); if (fr.count() == 0) { help(); } else if (fr.count() > 1) { WPMUtils::outputTextConsole("Unexpected argument: " + fr.at(1) + "\n", false); r = 1; } else if (fr.at(0) == "help") { help(); } else if (fr.at(0) == "add-path") { r = addPath(); } else if (fr.at(0) == "remove-path") { r = removePath(); } else if (fr.at(0) == "list-msi") { r = listMSI(); } else if (fr.at(0) == "get-product-code") { r = getProductCode(); } else if (fr.at(0) == "uninstall-from-cp") { r = uninstallFromCP(); } else { WPMUtils::outputTextConsole("Wrong command: " + fr.at(0) + "\n", false); r = 1; } return r; }
void AutoUpdateManager::onFileChanged(const QString& local_path) { qDebug("[AutoUpdateManager] detected cache file %s changed", local_path.toUtf8().data()); if (!watch_infos_.contains(local_path)) { // filter unwanted events return; } WatchedFileInfo &info = watch_infos_[local_path]; QFileInfo finfo(local_path); // Download the doc file in the mac will automatically upload // If the timestamp has not changed, it will not be uploaded qint64 mtime = finfo.lastModified().toMSecsSinceEpoch(); if (mtime == info.mtime) { qDebug("[AutoUpdateManager] Received a file %s upload notification, but the timestamp has not changed, " "it will not upload", local_path.toUtf8().data()); return; } #ifdef Q_OS_MAC if (MacImageFilesWorkAround::instance()->isRecentOpenedImage(local_path)) { qDebug("[AutoUpdateManager] skip the image file updates on mac for %s", toCStr(local_path)); return; } #endif removePath(&watcher_, local_path); QString repo_id, path_in_repo; if (!finfo.exists()) { qDebug("[AutoUpdateManager] detected cache file %s renamed or removed", local_path.toUtf8().data()); WatchedFileInfo deferred_info = info; removeWatch(local_path); // Some application would deleted and recreate the file when saving. // We work around that by double checking whether the file gets // recreated after a short period QTimer::singleShot(5000, this, SLOT(checkFileRecreated())); deleted_files_infos_.enqueue(deferred_info); return; } uploadFile(local_path); }
void SourceHighlightQtDataWatcher::setFilePath( const QString& filePath ) { if ( mFilePath == filePath ) { return; } if ( !mFilePath.isEmpty() ) { removePath( mFilePath ); } mFilePath = filePath; srchilite::Settings::setGlobalDataDir( mFilePath.toStdString() ); if ( !mFilePath.isEmpty() ) { addPath( mFilePath ); } update(); }
TEST_F(RocksDBDatabasePluginTests, test_corruption) { ASSERT_TRUE(pathExists(path_)); ASSERT_FALSE(pathExists(path_ + ".backup")); // Mark the database as corrupted RocksDBDatabasePlugin::setCorrupted(); printf("set corrupt\n"); resetDatabase(); printf("did reset\n"); EXPECT_TRUE(pathExists(path_ + ".backup")); // Remove the backup and expect another reload to not create one. removePath(path_ + ".backup"); ASSERT_FALSE(pathExists(path_ + ".backup")); resetDatabase(); EXPECT_FALSE(pathExists(path_ + ".backup")); }
UpdateMailCount::UpdateMailCount() { QDir dir; QDirIterator it("/home/alexandre/Mail/",QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks, QDirIterator::Subdirectories); while (it.hasNext()) { QString dirName = it.next(); if (!dirName.contains("/new")) continue; addPath(dirName); for (int i = 0; i < mailChecker.ignoreList.size(); ++i) { if (dirName.contains(mailChecker.ignoreList.at(i))) { removePath(dirName); break; } } } connect(this, SIGNAL(directoryChanged(QString)), this, SLOT(slotCount())); slotCount(); }
QT_BEGIN_NAMESPACE PathPage::PathPage(QWidget *parent) : QWizardPage(parent) { setTitle(tr("Source File Paths")); setSubTitle(tr("Specify the paths where the sources files " "are located. By default, all files in those directories " "matched by the file filter will be included.")); m_ui.setupUi(this); connect(m_ui.addButton, SIGNAL(clicked()), this, SLOT(addPath())); connect(m_ui.removeButton, SIGNAL(clicked()), this, SLOT(removePath())); m_ui.filterLineEdit->setText(QLatin1String("*.html, *.htm, *.png, *.jpg, *.css")); registerField(QLatin1String("sourcePathList"), m_ui.pathListWidget); m_firstTime = true; }
Status socketExists(const fs::path& path, bool remove_socket) { // This implies that the socket is writable. if (pathExists(path).ok()) { if (!isWritable(path).ok()) { return Status(1, "Cannot write extension socket: " + path.string()); } else if (remove_socket && !removePath(path).ok()) { return Status(1, "Cannot remove extension socket: " + path.string()); } } else { // The path does not exist. if (!pathExists(path.parent_path()).ok()) { return Status(1, "Extension socket directory missing: " + path.string()); } else if (!isWritable(path.parent_path()).ok()) { return Status(1, "Cannot create extension socket: " + path.string()); } // If we are not requesting to remove the socket then this is a failure. if (!remove_socket) { return Status(1, "Socket does not exist"); } } return Status(0); }
void PipelineManager::removePathEvent(Jzon::Node* params, Jzon::Object &outputNode) { int id; if(!params) { outputNode.Add("error", "Error removing path. Invalid JSON format..."); return; } if (!params->Has("id")) { outputNode.Add("error", "Error removing path. Invalid JSON format..."); return; } id = params->Get("id").ToInt(); if (!removePath(id)) { outputNode.Add("error", "Error removing path. Internal error..."); return; } outputNode.Add("error", Jzon::null); }
void PrefsDialog::init() { setupUi(this); connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); connect(binPathList, SIGNAL(itemSelectionChanged()), this, SLOT(updatePathButtons())); connect(pathUp, SIGNAL(clicked()), this, SLOT(movePathUp())); connect(pathDown, SIGNAL(clicked()), this, SLOT(movePathDown())); connect(pathAdd, SIGNAL(clicked()), this, SLOT(addPath())); connect(pathRemove, SIGNAL(clicked()), this, SLOT(removePath())); connect(toolList, SIGNAL(itemSelectionChanged()), this, SLOT(updateToolButtons())); connect(toolList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(editTool(QListWidgetItem*))); connect(toolUp, SIGNAL(clicked()), this, SLOT(moveToolUp())); connect(toolDown, SIGNAL(clicked()), this, SLOT(moveToolDown())); connect(toolAdd, SIGNAL(clicked()), this, SLOT(addTool())); connect(toolRemove, SIGNAL(clicked()), this, SLOT(removeTool())); connect(toolEdit, SIGNAL(clicked()), this, SLOT(editTool())); connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(changedTabPanel(int))); pathsChanged = toolsChanged = false; }
bool findPath(int sx, int sy, int tx, int ty) { Point p (sx, sy); addPath(p); if (sx == tx && sy == ty) { return true; } bool success = false; if (sx <= tx && isOpen(sx+1, sy)) { success = findPath(sx+1, sy, tx, ty); } if (!success && sy <= ty && isOpen(sx, sy+1)) { success = findPath(sx, sy+1, tx, ty); } if (!success) { removePath(p); } return success; }
int delete_thread(SceSize args_size, DeleteArguments *args) { SceUID thid = -1; // Set progress to 0% sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 0); sceKernelDelayThread(DIALOG_WAIT); // Needed to see the percentage FileListEntry *file_entry = fileListGetNthEntry(args->file_list, args->index); int count = 0; FileListEntry *head = NULL; FileListEntry *mark_entry_one = NULL; if (fileListFindEntry(args->mark_list, file_entry->name)) { // On marked entry count = args->mark_list->length; head = args->mark_list->head; } else { count = 1; mark_entry_one = malloc(sizeof(FileListEntry)); strcpy(mark_entry_one->name, file_entry->name); head = mark_entry_one; } char path[MAX_PATH_LENGTH]; FileListEntry *mark_entry = NULL; // Get paths info uint32_t folders = 0, files = 0; mark_entry = head; int i; for (i = 0; i < count; i++) { disableAutoSuspend(); snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name); removeEndSlash(path); getPathInfo(path, NULL, &folders, &files); mark_entry = mark_entry->next; } // Update thread thid = createStartUpdateThread(folders + files); // Remove process uint32_t value = 0; mark_entry = head; for (i = 0; i < count; i++) { snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name); removeEndSlash(path); int res = removePath(path, &value, folders + files, SetProgress); if (res < 0) { closeWaitDialog(); errorDialog(res); goto EXIT; } mark_entry = mark_entry->next; } // Set progress to 100% sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 100); sceKernelDelayThread(COUNTUP_WAIT); // Close sceMsgDialogClose(); dialog_step = DIALOG_STEP_DELETED; EXIT: if (mark_entry_one) free(mark_entry_one); if (thid >= 0) sceKernelWaitThreadEnd(thid, NULL, NULL); return sceKernelExitDeleteThread(0); }
bool UrlParser::removePath( const UrlComponent::Matcher &matcher, const UrlComponent::Validator &validator ) { std::vector<std::pair<UrlComponent*, UrlComponent*> > matches = matchPath( matcher ); return removePath( matches, validator ); }
bool convert(const std::string &filename) { std::string file = removePath(filename); std::string outFile = getPrefix(filename, '.') + ".cfrt"; /* Retrieve file format */ FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(filename.c_str(), 0); if (fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilename(filename.c_str()); if (fif == FIF_UNKNOWN) { std::cout << "Unknown file format " << file << std::endl; return false; } /* Load image */ FIBITMAP *dib = nullptr; if (FreeImage_FIFSupportsReading(fif)) dib = FreeImage_Load(fif, filename.c_str()); if (!dib) { std::cout << "Failed to load " << file << std::endl; return false; } /* Convert to standard format if necessary */ if (FreeImage_GetImageType(dib) != FIT_BITMAP) { FIBITMAP *tmp = dib; dib = FreeImage_ConvertToStandardType(dib); FreeImage_Unload(tmp); if (!dib) { std::cout << "Failed to convert " << file << " to standard type." << std::endl; return false; } } /* Convert bpp if needed */ unsigned int bpp = FreeImage_GetBPP(dib); if (bpp <= 8) { FIBITMAP *tmp = dib; dib = FreeImage_ConvertToGreyscale(dib); FreeImage_Unload(tmp); bpp = 8; if (!dib || FreeImage_GetBPP(dib) != 8) bpp = 0; } else if (bpp > 32) { FIBITMAP *tmp = dib; dib = FreeImage_ConvertTo32Bits(dib); FreeImage_Unload(tmp); bpp = 32; if (!dib || FreeImage_GetBPP(dib) != 32) bpp = 0; } /* Get image information */ unsigned int width = FreeImage_GetWidth(dib); unsigned int height = FreeImage_GetHeight(dib); unsigned int bytes = 1; unsigned int channels = 0; switch (bpp) { case 8: channels = 1; break; case 24: channels = 3; break; case 32: channels = 4; break; default: bpp = 0; } /* Check if image is valid */ if (!dib || bpp == 0 || width == 0 || height == 0 || !FreeImage_HasPixels(dib)) { if (dib) FreeImage_Unload(dib); std::cout << "Invalid image " << file << std::endl; return false; } std::cout << file << " Loaded. Converting.\n"; /* Create CFR texture */ CFR::Texture texture( width, height, 1, channels, bytes ); /* Set texture pixels */ for (unsigned int y = 0; y < height; y++) { BYTE* bits = FreeImage_GetScanLine(dib, height - y - 1); for (unsigned int x = 0; x < width; x++) { CFR::Pixel8 pixel(0, 0, 0, 0); BYTE *p = bits + (channels * x); if (channels >= 1) pixel.r = p[FI_RGBA_RED]; if (channels >= 2) pixel.g = p[FI_RGBA_GREEN]; if (channels >= 3) pixel.b = p[FI_RGBA_BLUE]; if (channels >= 4) pixel.a = p[FI_RGBA_ALPHA]; texture.setPixel8(pixel, x, y, 0); } } /* Unload image */ FreeImage_Unload(dib); /* Save texture */ try { texture.saveToFile(outFile); } catch (CFR::Exception &fail) { std::cout << "Failed to save " << removePath(outFile) << ": " << fail.what() << std::endl; } return true; }
/* * Open a player. * * fileName (in) - file to open. * spriteAttr (in) - common attributes that feed into CSprite. * short (out) - minor version. */ short tagPlayer::open(const STRING fileName, SPRITE_ATTR &spriteAttr) { CFile file(fileName); if (!file.isOpen()) { // FileExists check. messageBox(_T("File not found: ") + fileName); return 0; } // Preserve subfolder to ensure loading from saved file. this->fileName = removePath(fileName, TEM_PATH); file.seek(13); char cVersion; file >> cVersion; file.seek(0); if (!cVersion) { STRING fileHeader; file >> fileHeader; if (fileHeader != _T("RPGTLKIT CHAR")) { messageBox(_T("Unrecognised File Format! ") + fileName); return 0; } short majorVer, minorVer; file >> majorVer; file >> minorVer; file >> charname; file >> experienceVar; replace(experienceVar, _T("!"), _T("")); file >> defenseVar; replace(defenseVar, _T("!"), _T("")); file >> fightVar; replace(fightVar, _T("!"), _T("")); file >> healthVar; replace(healthVar, _T("!"), _T("")); file >> maxHealthVar; replace(maxHealthVar, _T("!"), _T("")); file >> nameVar; replace(nameVar, _T("$"), _T("")); file >> smVar; replace(smVar, _T("!"), _T("")); file >> smMaxVar; replace(smMaxVar, _T("!"), _T("")); file >> leVar; replace(leVar, _T("!"), _T("")); file >> stats.experience; file >> stats.health; file >> stats.maxHealth; file >> stats.defense; file >> stats.fight; file >> stats.sm; file >> stats.smMax; file >> stats.level; file >> profilePic; unsigned int i; smlist.clear(); spcMinExp.clear(); spcMinLevel.clear(); spcVar.clear(); spcEquals.clear(); for (i = 0; i <= 200; i++) { STRING str; int num; file >> str; smlist.push_back(str); file >> num; spcMinExp.push_back(num); file >> num; spcMinLevel.push_back(num); file >> str; spcVar.push_back(str); file >> str; spcEquals.push_back(str); } file >> specialMoveName; file >> smYN; accessoryName.clear(); for (i = 0; i <= 10; i++) { STRING str; file >> str; accessoryName.push_back(str); } armorType.clear(); for (i = 0; i <= 6; i++) { char chr; file >> chr; armorType.push_back(chr); } if (minorVer == 3) { char lev; file >> lev; levelType = lev; }
/*parseinput: Shell Input Parser, gets instructions Returns: 0 if exiting the shell, 1 if returning to shell */ int parseinput(char *buf) { if (strcmp(buf, "\n") == 0) { return 1; } else if (strcmp(buf, "exit\n") == 0) { return 0; } else { push_hist(buf); char *cmd; char *arguments[22]; //Creates the argv array arguments[21] = NULL; //Initializes the 21st argument to be NULL for error checking char *pch; int i = 1; cmd = strtok (buf," \n"); arguments[0] = cmd; /*Build the arguments array*/ do { pch = strtok (NULL, " \n "); arguments[i] = pch; i++; } while ((pch != NULL) && (i < 22)); /*If there are over 20 arguments, then 21st argument is not NULL, throw error and return to shell*/ if (arguments[21] != NULL) { printf("error: Too many arguments.\n"); return 1; } /*Determine which instruction was called and call appropriate function*/ if (strcmp(cmd, "path") == 0) { // When there isn't any arguments then print the PATH if (arguments[1] == NULL) { printPath(); } else if (arguments[2] == NULL) // To handle case of null argument after path + { printf("error: No path input.\n"); } else if (strcmp(arguments[1], "+") == 0) { addPath(arguments[2]); } else if (strcmp(arguments[1], "-") == 0) { removePath(arguments[2]); } // When there's any arguments other than + and -, print the PATH else { printPath(); } } else if (strcmp(cmd, "cd") == 0) { cd(arguments); } else if (strcmp(cmd, "history") == 0) { print_hist(); } else if (strncmp(cmd, "!", 1) == 0) { if ((strlen(cmd) > 4)|(strlen(cmd) < 1)) { printf("Command not found.\n"); } else { int n = n_convert(cmd); if (n != 0) { call_hist(n); } else { printf("Command not found.\n"); } } } else { open (cmd, arguments); } } return 1; }