Skip to content

Commit

Permalink
1.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielLMcGuire committed Jul 31, 2024
1 parent 686589f commit 29ba48d
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 15 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
3 changes: 3 additions & 0 deletions release/.APPIMAGE/makeappimage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

appimagetool AppDir
2 changes: 1 addition & 1 deletion PKGBUILD → release/.ARCH/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Maintainer: Daniel McGuire <[email protected]>
pkgname=sourcesearch
pkgver=1.0.0
pkgver=1.2.5
pkgrel=1
pkgdesc="Searches Source Code for matching words."
arch=('any')
Expand Down
3 changes: 3 additions & 0 deletions release/.ARCH/makearch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

makepkg -o -f
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: sourcesearch
Version: 1.0.0
Version: 1.2.5
Section: base
Priority: optional
Architecture: any
Expand Down
File renamed without changes.
38 changes: 25 additions & 13 deletions src/sourcesearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> loadSearchWords(const std::string& filePath) {
std::set<std::string> searchWords;
Expand All @@ -86,13 +85,14 @@ std::vector<std::string> findWordsInFile(const std::string& filePath, const std:
std::set<int> 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();
}

Expand All @@ -105,8 +105,10 @@ std::vector<std::string> 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<int>(buffer.size()));
for (int i = startLine; i < lineNumber; ++i) {
int startLine = std::max(0, lineNumber - contextSize - 1);
int endLine = std::min(static_cast<int>(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);
Expand All @@ -119,6 +121,7 @@ std::vector<std::string> 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('.');
Expand Down Expand Up @@ -192,11 +195,19 @@ void searchDirectory(const std::string& directory, const std::set<std::string>&

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";
Expand All @@ -207,3 +218,4 @@ int main(int argc, char* argv[]) {

return 0;
}

0 comments on commit 29ba48d

Please sign in to comment.