This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly setup colorized printing functions
Previously, non-colorized and colorized printing made use of the same pw_*print family of functions. Since we do most of the setup after we parse the user supplied arguments, the user may supply the "--debug" option. This will cause a segmentation fault as the color struct has not been initialized but a NULL string in it is printed. The pw_safe_*print family of functions is introduced to solve this. Now, the pw_*print family of functions are just function pointers to the pw_safe_*print family of functions until we confirm whether the output is colorized. If so, then we call color_print_setup() to switch the pw_*print function pointers to pw_c*print family of functions to support colorized output. Otherwise, the pw_*print family of functions will still point to the original pw_safe_*print family of functions. When we destroy the color struct, color_print_restore() is invoked to switch the pw_*print pointers to the pw_safe_*print functions. Signed-off-by: Pang Yan Han <pangyanhan@gmail.com>
- Loading branch information
Showing
3 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters