A portable command-line utility for generating a man-page
equivalent for your custom project.
Submission for tiancai-cup from @SamSamhuns
Tired of looking throughout the build directory of your project for the functions you wrote weeks before or don't remember their parameters. Want to find a quick way of querying functions and modules while displaying them like the on-line man pages
?
manp
is a command-line utility that lets you create a man pages
equivalent documentation of your project. This is similar to how man printf
works for C/C++ functions. But, now you can manp [YOUR_FUNCTIONS]
from your source code instead.
All files of extension TARGET_FILE_EXTN
are recursively searched inside the manp/target_data
folder and added to the data section of the manp
in the form of header includes.
If incorrect modules are entered, manp
also has a feature for auto-suggesting most similar named module.
Running make without setting any SOURCE_DIR or TARGET_FILE_EXTN creates a default manp
portable executable with documentation for the Python standard library modules and functions.
Requirements:
- Python 3.5+
- g++ compiler
- bash shell
For OSX and Linux Only
-
Clone the repository.
-
Set the
SOURCE_DIR
(Absolute path to your build directory) andTARGET_FILE_EXTN
(File extensions added tomanp
, separated by a single space inside double quotes) inside themakefile_configuration.mk
file. TheSOURCE_DIR
can be specified to any directory, the make commands recursively search through the source to find all files of the extensionTARGET_FILE_EXTN
. TheREPLACE_OLD_TARGET
variable, if set toTrue
will clean thetarget_data
folder before make. -
After the Use
makefile_configuration.mk
config file has been properly set,manp
can be compiled and the execute permissions be set. ( The original download from GitHub builds amanp
Python documentation )
$ make all
$ chmod a+x manp
Note: If the .mk
config file is not changed, the make
command can also be run like so:
$ make SOURCE_DIR=/usr/project/src TARGET_FILE_EXTN="txt py md"
-
Add the
manp
executable toPATH
var for faster execution so thatmanp
can be called using abash
shell from any directory and speeds documentation lookup.-
Recommended:
manp
can be indirectly added to the currentPATH
variable by creating a symlink to/usr/local/bin
using the absoute path of themanp
executable.$ ln -s /[ABSOLUTE_PATH]/manp /usr/local/bin
Note: If the original location of the
manp
executable is changed, the soft link must be updated again with the above command. -
Alternative:
copy
manp
to/usr/local/bin
with:$ cp manp /usr/local/bin
Note: Every time, there is a change to the source code, the
manp
binary will have to be recopied tousr/local/bin
.
-
Note: If there are any permission issues, use sudo
. The manp
executable can be directly added to the PATH
var if sudo
access is not present.
Only for Python projects as of now:
The python generate_txt_from_python_progs.py
function can be used to generate txt files containing information on individual functions and classes, the source folder is denoted by [SOURCE_FILE_DIR]
while the target folder is denoted by [TARGET_DIRECTORY]
.
$ python generate_funcs_from_modules [SOURCE_FILENAME] [TARGET_DIRECTORY]
$ python generate_txt_from_python_progs.py [SOURCE_FILE_DIR] [TARGET_DIRECTORY]
Support for more projects will be added in the future
To remove the manp
symlink from /usr/local/bin
:
$ rm /usr/local/bin/manp
or,
$ unlink /usr/local/bin/manp
Note: If there are permission errors, use sudo
. The symlink can be manually deleted as well
To get documentation for a artifact present in the SOURCE_DIR
:
$ manp [MODULE_OR_FUNCTION_NAME]
Example: (For the default Python std lib documentation)
$ manp zlib
To display help
:
$ manp -h
To display list of all available documented artifacts:
$ manp -l
A detailed explanation of how the program functions:
The program requires compilation and running of certain files and script before others which is handled by the Makefile
.
-
The
text_to_raw_string.cpp
andraw_string_to_text.cpp
modules are compiled before main. Thetext_to_raw_string.cpp
converts all the files inside theSOURCE_DIR
folder tomanp/target_data/
folder as raw string literal txt files padded with extraCPP_MAP_KEY_VALUE_DELIM
andCPP_MAP_MODULE_DELIM
(defined incommon.h
) delimiters for creating C++ maps. -
After this, the
generate_doc_artifacts_list.sh
will iterate through themanp/target_data/
folder and createcombined_txt_include.h
that includes all thetxt
raw string literal files in one header file anddoc_artifacts_list
header include file containing just the names of all the modules from thetarget_data
folder. -
The
main.cpp
function will finally be compiled along withSpellingCorrector.cpp
andmanp
will be available for execution. -
Once the
manp
is added to thePATH
var one way or another, it can be used asmanp abs
.
-
To add documentations manually, txt files with the name of the module in question should be added to the
SOURCE_DIR
folder and the project should be recompiled. -
To change documentation or source code files back to normal text format, run
./raw_string_to_text data
.
- All documentations imported from the Python Software Foundation Official Documentation https://www.python.org/psf/
- Peter Norvig's How to Write a Spelling Corrector
- Felipe Farinon's C++ implementation of Peter Norvig's Spell Correcter [email protected]
I am not the creator of the SpellingCorrector C++ modules. The SpellingCorrector module used in this project was first written by Peter Norvig in Python and then converted to C++ by Felipe Farinon.