Progress: Redesign printing, redesign conversions, and some cleanup.
The print functions have been redesigned (work is incomplete as of this commit):
- Use unlocked printing where possible for all low level functions (like f_print()).
- Provide locked versions of all f_print* and fl_print* functions in newly added fll_print project.
- Redesign output variable to be at the end to be consistent with FLL practices (with an exception).
- Implement fprintf() alternative (very much incomplete, see below) and use a parameter structure to match fprintf() as an exception to the FLL practice mentioned above.
- Add *_raw() and *_safely() functions (see notes below).
The conversions are redesigned to better accommodate more flexibility as well as the newly added fprintf() alternatives (fl_print_string(), etc..).
- Provide a structure for more fine tuned control over convert process.
- Allow for literal designated of base 10 rather than making it solely the default base.
- Use bitwise operations and range comparisons more rather than switches and if then blocks for conversions.
There are some private headers being exposed to the installation (private headers should not be specified in the build_sources_headers build settings).
This commit all started with the observation that filenames could be created using control codes.
I tested using the backspace control code with the byte_dump program and found that it does perform backspace.
I consider this a security issue as I consider this undefined behavior.
To resolve this, I decided that I needed a "print safely" set of print functions.
After some consideration, I decided that providing my own fprintf() alternative is the way to go and has several advantages.
- Allow moving print locking to higher levels to avoid thread problems where multiple fprintf() like functions are called that should not be allowed for something else to print between them.
- The unlocked print functions also allow for better performance under the assumption or expectation allows for better control of the programmer to properly utilize this.
- Allow for having an unlocked fprintf() function.
- Still allow for locked versions of all unlocked print functions.
- Allow for passing FLL f_string_static_t, f_string_dynamic_t, and similar to the fprintf() alternative (which hopefully will make the code a lot cleaner and better maintainable).
- Allow for custom print options to "print safely".
- Allow for custom print options to "print rawly" (that is, allow printing NULL character and any control character as-is).
Working on this led to doing a rewrite of the conversion functions (which is needed anyway).
This also required major changes to the print functions and as per my completeness principle also requires a lot more functions to be implemented.
All of this resulted in a huge set of changes.
So big, that I am afraid of mistakes.
No, I expect there to be mistakes.
At this point, I spent enough time so I put the code in a state that compiles correctly and am saving as-is.
There are several @todos present and there are also a large number of incomplete areas of code.
Of particular note is the fprintf() compatibility.
I tried to stay as close to the fprintf() syntax as possible but I found that it is better to deviate in certain areas.
I do not plan on implementing the "type conversion" support.
I do plan on implementing the float/double support, but do to the additional complexity and my priorities, this functionality is being held off for a much later time.
I will get to documenting the fprintf() alternatives later on.
The fprintf() alternatives are being called fl_print_string() and fll_print_string() (including variations with different suffixes).
This is done to distinguish these between the normal f_print() and fll_print() type of functions.