From 29ba48d175dd179f3c8066486b0d105dd36fe97c Mon Sep 17 00:00:00 2001 From: Daniel McGuire Date: Wed, 31 Jul 2024 10:53:15 -0500 Subject: [PATCH] 1.2.5 --- {AppDir => release/.APPIMAGE/AppDir}/.DirIcon | 0 {AppDir => release/.APPIMAGE/AppDir}/AppRun | 0 .../.APPIMAGE/AppDir}/sourcesearch.desktop | 0 .../.APPIMAGE/AppDir}/sourcesearch.png | Bin release/.APPIMAGE/makeappimage.sh | 3 ++ PKGBUILD => release/.ARCH/PKGBUILD | 2 +- release/.ARCH/makearch.sh | 3 ++ .../.DEBIAN/.DEBIAN}/DEBIAN/control | 2 +- build-deb.sh => release/.DEBIAN/build-deb.sh | 0 src/sourcesearch.cpp | 38 ++++++++++++------ 10 files changed, 33 insertions(+), 15 deletions(-) rename {AppDir => release/.APPIMAGE/AppDir}/.DirIcon (100%) rename {AppDir => release/.APPIMAGE/AppDir}/AppRun (100%) rename {AppDir => release/.APPIMAGE/AppDir}/sourcesearch.desktop (100%) rename {AppDir => release/.APPIMAGE/AppDir}/sourcesearch.png (100%) create mode 100755 release/.APPIMAGE/makeappimage.sh rename PKGBUILD => release/.ARCH/PKGBUILD (97%) create mode 100755 release/.ARCH/makearch.sh rename {.DEBIAN => release/.DEBIAN/.DEBIAN}/DEBIAN/control (92%) rename build-deb.sh => release/.DEBIAN/build-deb.sh (100%) diff --git a/AppDir/.DirIcon b/release/.APPIMAGE/AppDir/.DirIcon similarity index 100% rename from AppDir/.DirIcon rename to release/.APPIMAGE/AppDir/.DirIcon diff --git a/AppDir/AppRun b/release/.APPIMAGE/AppDir/AppRun similarity index 100% rename from AppDir/AppRun rename to release/.APPIMAGE/AppDir/AppRun diff --git a/AppDir/sourcesearch.desktop b/release/.APPIMAGE/AppDir/sourcesearch.desktop similarity index 100% rename from AppDir/sourcesearch.desktop rename to release/.APPIMAGE/AppDir/sourcesearch.desktop diff --git a/AppDir/sourcesearch.png b/release/.APPIMAGE/AppDir/sourcesearch.png similarity index 100% rename from AppDir/sourcesearch.png rename to release/.APPIMAGE/AppDir/sourcesearch.png diff --git a/release/.APPIMAGE/makeappimage.sh b/release/.APPIMAGE/makeappimage.sh new file mode 100755 index 0000000..bd32925 --- /dev/null +++ b/release/.APPIMAGE/makeappimage.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +appimagetool AppDir diff --git a/PKGBUILD b/release/.ARCH/PKGBUILD similarity index 97% rename from PKGBUILD rename to release/.ARCH/PKGBUILD index 1e42bed..1fa1821 100644 --- a/PKGBUILD +++ b/release/.ARCH/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Daniel McGuire pkgname=sourcesearch -pkgver=1.0.0 +pkgver=1.2.5 pkgrel=1 pkgdesc="Searches Source Code for matching words." arch=('any') diff --git a/release/.ARCH/makearch.sh b/release/.ARCH/makearch.sh new file mode 100755 index 0000000..d8e0303 --- /dev/null +++ b/release/.ARCH/makearch.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +makepkg -o -f diff --git a/.DEBIAN/DEBIAN/control b/release/.DEBIAN/.DEBIAN/DEBIAN/control similarity index 92% rename from .DEBIAN/DEBIAN/control rename to release/.DEBIAN/.DEBIAN/DEBIAN/control index f0abeb6..e092182 100644 --- a/.DEBIAN/DEBIAN/control +++ b/release/.DEBIAN/.DEBIAN/DEBIAN/control @@ -1,5 +1,5 @@ Package: sourcesearch -Version: 1.0.0 +Version: 1.2.5 Section: base Priority: optional Architecture: any diff --git a/build-deb.sh b/release/.DEBIAN/build-deb.sh similarity index 100% rename from build-deb.sh rename to release/.DEBIAN/build-deb.sh diff --git a/src/sourcesearch.cpp b/src/sourcesearch.cpp index 7659893..5e15220 100644 --- a/src/sourcesearch.cpp +++ b/src/sourcesearch.cpp @@ -44,22 +44,21 @@ int parseArgs(int argc, char* argv[]) { if (argc > 1) { if (strcmp(argv[1], "--version") == 0) { std::cout << vernum << std::endl; - return 0; + return 1; // Special case handled } else if (strcmp(argv[1], "--help") == 0) { printHelp(argv[0]); - return 0; + return 1; // Special case handled } else { std::cout << "Unknown option: " << argv[1] << std::endl; printHelp(argv[0]); - return 1; + return 1; // Error code for unknown option } } else { // No arguments provided, show help printHelp(argv[0]); - return 0; + return 1; // Indicate that no valid arguments were provided } - - +} // Load words from a file std::set loadSearchWords(const std::string& filePath) { std::set searchWords; @@ -86,13 +85,14 @@ std::vector findWordsInFile(const std::string& filePath, const std: std::set processedLines; // Track processed line numbers std::string line; int lineNumber = 0; + const int contextSize = 2; // Number of lines before and after while (std::getline(file, line)) { buffer.push_back(line); lines.push_back(line); lineNumber++; - if (buffer.size() > 5) { // Buffer size for 2 lines before, 1 current, and 2 lines after + if (buffer.size() > contextSize * 2 + 1) { // Buffer size for context lines buffer.pop_front(); } @@ -105,8 +105,10 @@ std::vector findWordsInFile(const std::string& filePath, const std: std::cout << fs::path(filePath).filename().string() << ": Found the word '" << word << "' on line: " << lineNumber << std::endl; // Output context lines - int startLine = std::max(0, lineNumber - static_cast(buffer.size())); - for (int i = startLine; i < lineNumber; ++i) { + int startLine = std::max(0, lineNumber - contextSize - 1); + int endLine = std::min(static_cast(lines.size()) - 1, lineNumber + contextSize - 1); + + for (int i = startLine; i <= endLine; ++i) { resultLines.push_back(filePath + ": Line " + std::to_string(i + 1) + ": " + lines[i]); } processedLines.insert(lineNumber); @@ -119,6 +121,7 @@ std::vector findWordsInFile(const std::string& filePath, const std: return resultLines; } + // Function to generate a new output file name with an incremented suffix std::string getNewFileName(const std::string& baseFileName, int index) { std::string::size_type pos = baseFileName.find_last_of('.'); @@ -192,11 +195,19 @@ void searchDirectory(const std::string& directory, const std::set& int main(int argc, char* argv[]) { if (argc < 2) { - std::cout << "No arguments provided." << std::endl; - printHelp(argv[0]); - return 1; + std::cout << "No arguments provided." << std::endl; + printHelp(argv[0]); + return 1; } - parseArgs(argc, argv); + + // Parse arguments and handle special cases + int result = parseArgs(argc, argv); + if (result != 0) { + // If parseArgs returns a non-zero value, it indicates a special case + return result; + } + + // If not an error, proceed with normal execution printLogo(); std::string searchWordsFile = argv[1]; std::string outputFile = (argc > 2) ? argv[2] : "lines.txt"; @@ -207,3 +218,4 @@ int main(int argc, char* argv[]) { return 0; } +