about
12/01/2022
TextFinder Repo
TextFinder code

TextFinder  Repository

Useful grep-like tool

Quick Status Code functions correctly No known defects Demonstration code yes Documentation yes Test cases no Static library no Build requires C++17 option Planned design changes Add version with concurrent
text search

1.0 Concept

Textfinder accepts options from its command line and searches for files in a directory tree, that match one or more file patterns, looking for text that matches a specified regular expression.
Fig 1. TextFinder Packages
Fig 2. TextFinder Classes
Fig 3. TextFinder Output

2.0 Design

TextFinder uses facilities of DirExplorerT, TextSearch, Application, FileSystem, and CppUtilities packages. TextFinder, the program executive, uses command line arguments to configure its operation by configuring DirExplorerT with path, file pattern, and regular expression declarations.
DirExplorerT<Application> is a reusable directory navigator that supports application specific processing of files and directories through its Application template parameter.
Application holds an ITextFinder interface pointer that allows it to use searching facilities in TextFinder, e.g., method searchFile(filename), which uses a regular expression data member of TextFinder.
Eventually, TextFinder will serve as an example of the use of threads to build software pipelines and parallel processing blocks. The plan is to provide solutions for synchronous (this solution), pipeline, and parallel processing demos.
The structure used for this application makes it easy to set up a multi-threaded pipeline: just put a blocking queue in TextFinder to receive filenames from DirExplorerT<Application> and run each of them on a dedicated thread.
It will be interesting to measure the performance of each of these designs to understand how effective the use of concurrency will be for working sets of various sizes.

3.0 Implementation

Find C++ source code in TextFinder repository.
TextFinder code was built with Visual Studio Community Edition - 2019 and tested on Windows 10. It was compiled with the C++17 option set in Properties > C/C++ > language.

4.0 Operation

TextFinder processes its command line options using ProcessCmdLine then configures a few parameters based on those options. It provides a reference to itself, typed as an ITextFinder interface, to DirExplorerT's Application instance.
That allows the instance to use TextFinder's searchFile(filename) method. This structure was used to keep all of the searching operations in TextFinder, and all of the navigation operations in DirExplorerT<Application> and Application.
The callback from Application to TextFinder was simple to implement and helps us apply the "Single Responsibility Principle"
When TextFinder starts it configures its parts; then it starts DirExplorerT<Application> on a depth first walk through a specified directory tree, e.g., that path supplied on the command line. DirExplorerT<Application> and Application collaborate to do all of the remaining processing.
TextFinder output, shown in the diagram, illustrates how useful TextFinder can be. In the last part of the output TextFinder was asked to locate any files that contain the text "<flex-break>". To do that it had to search more than 6000 directories, which it did in about two seconds.

5.0 Status

Textfinder is installed and stable. The only expected changes are to provide a WPF GUI that allows the user to use dialog to find search directory, to supply a regular expression in a textblock, and to supply options in check boxes. The GUI application would then spawn a TextFinder process with the appropriate command line.
  Next Prev Pages Sections About Keys