wingrep is a Python interface to a C library for searching files and directories in windows environmemnt, similar to the Unix grep tool. It provides efficient file searching capabilities by leveraging a shared library written in C.
- Search for patterns in files and directories.
- Supports various search options such as case-insensitive search, line numbers, word matching, and more.
- Handles binary files with customizable behavior.
- Displays context lines around matches.
- Python 3.x
- GCC (for compiling the shared library)
Before using wingrep, you need to compile the shared library from the C source file. Navigate to the directory containing your libgrep.c file and run:
gcc -shared -o wingrep/libgrep.so -fPIC libgrep.cTo install the wingrep package, navigate to the root directory of the project (where setup.py is located) and run:
python setup.py installAlternatively, you can use pip to install the package in editable mode:
pip install -e .After installation, you can use the wingrep command from the command line:
wingrep pattern path [options]pattern: The pattern to search for.path: The file or directory to search in.-i,--ignore-case: Perform case insensitive search.-n,--line-number: Show line numbers.-v,--invert-match: Invert the sense of matching.-c,--count: Count matching lines.-l,--files-with-matches: Print only names of files with matches.-w,--word-regexp: Match whole words only.-x,--line-regexp: Match whole lines only.-b,--byte-offset: Print the byte offset with output lines.-A,--after-context: Printnumlines of trailing context after matching lines.-bin,--binary-files: Determine how to handle binary files (binary,text,skip).
Search for the pattern "example" in the current directory and its subdirectories, displaying line numbers and matching whole words only:
wingrep example . -n -wwingrep/
│
├── wingrep/
│ ├── __init__.py
│ ├── wingrep.py
│ ├── libgrep.so
│ └── libgrep.h
│
├── setup.py
└── README.md
To add new features or modify existing ones, follow these steps:
-
Update the
libgrep.cfile with the required changes. -
Recompile the shared library:
gcc -shared -o wingrep/libgrep.so -fPIC libgrep.c
-
Update
wingrep.pyif necessary to reflect the changes in the shared library. -
Test the changes thoroughly before committing.
To test the wingrep functionality, you can use various test files and directories. Ensure that you cover different cases such as:
- Case-sensitive and case-insensitive searches.
- Word and line matching.
- Handling of binary files.
- Counting matches and displaying context lines.
This project is licensed under the MIT License. See the LICENSE file for more details.
Jawad Shafique
- Email: shafiquejr@gmail.com
- GitHub: killcod3
Contributions are welcome! Please fork the repository and submit a pull request with your changes. Ensure that your code follows the project's coding standards and includes appropriate tests.
Special thanks to the open-source community for their invaluable resources and support.