Kevin Day [Mon, 31 Jan 2022 04:40:58 +0000 (22:40 -0600)]
Progress: Continue mass converting to f_string_static_t.
The console program has been changed to populate an argv as a f_string_static_t.
This avoids having to run strlen() and strnlen() everywhere for console parameter processing.
The program that processes the parameters already does this, so save the values in an f_string_static_t.
Kevin Day [Fri, 28 Jan 2022 02:05:50 +0000 (20:05 -0600)]
Progress: Begin mass converting to f_string_static_t.
While working on the control and controller programs I realized that I should move from f_string_t to f_string_static_t.
This is a major change but it must be done before the API freeze for the stable release.
A long time ago, early in the design process of FLL, I considered using f_string_static_t (which was only f_string_dynamic_t at that time).
I had decided for simplicity and stuck with f_string_t.
In practice I have found that I was doing a lot of working creating f_string_static_t only to do more work to move it back to f_string_t.
This is an overall simplification of the project at the cost of some resources and some flexibility.
I've only just begun but I am already seeing what I believe to be is simpler code.
The biggest gotcha will be this will likely introduce bugs due to the sheer size of the changes.
The primary bug that will not be easily detected are the formatted print where '%s' needs to now become '%q' and '%S' needs to now become '%Q'.
There are also numerous potential optimizations that I am ignoring for now due to the size of this commit.
This work is by far not done and I expect all programs to fail.
I only tested compiling fake and I got it as far as running the help program.
Kevin Day [Wed, 26 Jan 2022 03:26:26 +0000 (21:26 -0600)]
Update: Add f_conversion unit tests.
There are far more permutations than what are handled within this commit.
Focus on only the most basic set of checks to write the unit tests for.
There are problems with mocking fwrite_unlocked() via the wrap strategy used by the linker.
I do not know why this is not working so I commented out the code and moved on.
Several problems are exposed and are solved.
- This exposed the fwrite_unlocked() return results problems.
- Add support for big endian (untested).
- Zero values are not correctly built (see below).
Make sure to count the zero number as a single digit.
Get rid of the "used" count and rely only on the digits.
Do not include the 0 digit when determining the padding.
Change the prefix append function to accommodate 0 and consistently call the prefix append function.
Kevin Day [Mon, 24 Jan 2022 01:33:55 +0000 (19:33 -0600)]
Update: Fix incorrect documentation and remove pointless code.
The documentation for some functions do not accurately reflect what the documentation does.
This is likely a copy and paste over sight.
The f_string_dynamic_resize() is adding one to destination->used.
It then updates the used to be that new number minus one.
This is pointless.
Don't bother with the "total" variable at all.
Also use the F_memory_default_allocation_small_d by rather than 1 when resizing.
Kevin Day [Wed, 19 Jan 2022 00:37:32 +0000 (18:37 -0600)]
Update: Use libc functions more in f_color.
The f_string_dynamic_increase_by() guarantees the size is allocated.
The f_string_dynamic_append() doesn't need to be called when the simple memcpy() can be directly called.
Doing this saves the status check and the additional function calls.
This likely increases performance but this performance increase potential has neither been tested nor confirmed.
Kevin Day [Mon, 17 Jan 2022 17:44:14 +0000 (11:44 -0600)]
Bugfix: The f_console project after writing unit tests.
Rename has_values to values_total to better communicate the intent of the property.
Expand out the macros across lines.
In f_console_identify() the strnlen() function is not properly handling when the character pointer is NULL, resulting in a segfault.
While this might be considered a bug in strnlen(), just make sure that a NULL pointer is not sent to strnlen().
Kevin Day [Mon, 17 Jan 2022 05:28:08 +0000 (23:28 -0600)]
Cleanup: Add back the two spaces before the "-" in the comments.
When in the comments with the " * " at the start, the behavior of not having the extra space seems fine.
When looking at the documentation and specification FSS files, I find that it is easier to read with the extra spaces.
I have decided to switch back and follow what I am doing in the documentation and specification FSS files.
This makes the style more consistent.
Kevin Day [Mon, 17 Jan 2022 03:01:44 +0000 (21:01 -0600)]
Update: Rewrite f_color functions and use f_string_static_t instead of f_string_t for global constant strings.
Switch to using the f_string_static_t so that the size does not have to be constantly tested via an strnlen() or similar call.
The f_string_static_t by default uses 64-bit types for size and used so there may be a performance hit due to this over the normal 32-bit numbers in strnlen().
Originally macros were used to reduce code repition.
This was done long before I decided to make f_string an exception that can be depended on by all level 0 projects.
The dynamic string functions can now be used, significantly simplifying the code.
The macros can be replaced with functions 1 through 5 to allow for only passing the required arguments.
This should reduce the cost of the function call by having fewer arguments when not necessary to have them.
The documentation comments are now present when they were not before.
Change the order of the function parameters to be more consistent with the latest practices.
Kevin Day [Sun, 16 Jan 2022 22:52:25 +0000 (16:52 -0600)]
Cleanup: Add additional initializer for f_string_static_t to allow initializing all parts.
Another acceptable practice is to set the used to some value greater than zero and size to zero to better designate that this is a static string and is not dynamically allocated.
Kevin Day [Sun, 16 Jan 2022 21:15:09 +0000 (15:15 -0600)]
Cleanup: Rename f_account functions in attempt to be easier to read.
I originally tried to group the logic by "name" and "id".
This becomes confusing when there is "group name" and "user name" or "group id" and "user id".
The function name with the structure "f_account_id_group_by_name" is intended to be understood as get id of group by name for account.
However, because account is in front (part of f_account) it could be easily misread as get account id by name with some spurious "group" injected.
This is clearly a bad interpretation but that interpretation is easy to think of.
Drop "user" because "account" and "user" should be synonymous.
Move "group" to the left in all cases to designate that this is about "group" associated with account.
Now f_account_group_id_by_name sounds more like get id of group by name for account.
Change the logic to not require format strings to be defined thereby avoiding potential segfaults.
Avoid using strnlen() and instead use memcpy().
More memory is used when specifying the sizes, but strnlen() calls probably does this to some extent.
Doing this reduces the number of calls to copying ranges of strings.
Kevin Day [Sat, 15 Jan 2022 23:01:53 +0000 (17:01 -0600)]
Update: Lay out the foundation for proper endianness support.
The endianness support is not currently a direct goal of the 0.4 versions.
The 0.6 versions will deal with networking and will most certainly need proper endianness support.
Ultimate the FLL needs to properly handle endianness.
Provide the initial functionality needed to make this possible.
The BIG_ENDIAN and LITTLE_ENDIAN cannot be directly relied on.
Provide custom _is_F_endian_big and _is_F_endian_little macros where when BIG_ENDIAN is not defined default to little endian.
By using the custom _is_F_endian_big and _is_F_endian_little, allow for the endianness to be explicit set at compile time.
This should make it easy to configure in cases where BIG_ENDIAN and LITTLE_ENDIAN are not defined.
Kevin Day [Fri, 14 Jan 2022 01:45:39 +0000 (19:45 -0600)]
Bugfix: IKI variables are not substituting consistently.
There appears to be a logic flaw where when more than one IKI variables are present, they start overwriting.
I changed the logic to focus more on the content loop.
The arguments array is only incremented for the content row.
When the resulting row is empty and is not quoted, then do not increment the arguments array.
Remove unnecessary NULL insertions.
The only time the NULL needs to be inserted is at the end when done adding all of the characters to the argument buffer.
Kevin Day [Thu, 13 Jan 2022 00:14:57 +0000 (18:14 -0600)]
Update: Provide more details in the documentation on if/else logic.
With the logic being different from normal conditional logic, I figured that it would be a good idea to add more documentation to further clarify the design.
Traditional logic is:
A and B or C and D
Where order of operations would be:
1) If A and B are TRUE...
2) If C and D are TRUE...
3) If (1) or (2) are TRUE...
The logic used by this program would be:
A and B or C and D
Where order of operations would be:
1) If A and B are TRUE...
2) If (1) or C are TRUE...
3) If (2) and D are TRUE...
Kevin Day [Wed, 12 Jan 2022 23:57:19 +0000 (17:57 -0600)]
Bugfix: More cases where if/else is not working as intended.
In the previous commit I accidentally removed the "or" condition.
I also found that I needed to be more thorough with the logic.
The condition result needs to be returned and handled when immediately returning.
This then allows for subsequent conditions to use the condition result.
The condition result gets reset on each pass of the loop.
The block result needs to then retrieve the condition result to ensure the result is preserved across loop passes.
Kevin Day [Wed, 12 Jan 2022 03:48:43 +0000 (21:48 -0600)]
Regression: The "failure" operation if condition type is not working as intended.
The documentation and specification is out of date and refers to this as "fail".
This is instead the word "failure".
This is also different from the setting "fail" that designates what to do on failure.
With one of the recent re-designs of the process logic, the failure status is no longer being passed.
When the "fail" setting is set to "warn" or "ignore", the status code of F_none is returned.
Change the return status to "F_failure" without the error bit to designate that this is a failure but it is not being treated as an error due to the state of the "fail" setting.
Then process the "F_failure" without the error bit to remember the state that a failure occurred.
This then allows for the "failure" if condition type to get triggered.
The recent if/else logic changes introduced behavior where a failure in the processing of the if/else commands should also trigger the "failure" if condition type.
This failure is not associated with the if condition results.
When an if condition results in either true or false, then this is considered a "success" rather than a "failure".
Generally, syntax failures are what trigger the "failure" state.
Programs that are executed, such as when using the "run" operation, will result in "failure" if a non-zero value is returned by the program.
Kevin Day [Wed, 12 Jan 2022 02:30:28 +0000 (20:30 -0600)]
Bugfix: If/else condition logic is incorrect or incomplete.
The if/else logic is not properly traversing.
I believe the original design is to just have if and else be a single set rather than a chain.
At some point I changed this to be chainable (or maybe I am incorrectly thinking that I did).
It made sense to use this if/then chain logic for my unit test files.
The Fake make unit test files are not working as I want them to because if/else chaining is not working.
As a big disclaimer, this does not support nesting.
I continue to refuse to design nesting of the if/else condition logic as I want to keep this as simple as possible.
Which, by the way, this is not simple.
I attempt to cut corners when I did my recent rewrite of the if/else logic.
Redesign this (again) but this time attempt to do this more properly.
The block process state now exclusively uses a special block process state enumeration rather than relying on a synthetic rule type.
The synthetic rule type is now removed.
The goal with this design is to:
1) On syntax error, bail out of the entire if/else chain.
2) On comparison error, continue an if/else chain passes or the end of chain is reached.
3) When any if/else chain passes, all subsequent conditions in the chain are not run.
Replace the "done" condition result with an "error" condition result to more accurately communicate its use.
Isolate the block and block result from the operate processing as much as possible so that all modifications of the variable are done outside of the operate processing.
When the "fail" is set to "exit" the if/else should fail appropriately on syntax error.
When the "fail" is set to "warn" or "ignore", then continue on after skipping the entire chain.
The operate process still needs to check the if/else chain states to determine if it should skip or not.
When an if/else condition terminates unexpectedly due to an end of file (or section) an error is more consistently reported regardless of place in the if/else chain.
This still needs real testing to confirm that all of the possible permutations work as expected.
Unit tests for this will need to be written but this is a long way away from being done.
Kevin Day [Mon, 10 Jan 2022 03:35:03 +0000 (21:35 -0600)]
Update: Implement f_capability unit tests and improve existing unit tests.
Add tests for f_capability functions.
This includes my first go at mocking functions using function wrapping.
It seems that the linker is limited on how it handles function wrapping.
I cannot simply wrap functions pulled in via a library.
To work around this I implemented another Fake build settings file for handling this.
This is not an ideal situation and adds a bit of extra work.
The environment variable settings for LD_LIBRARY_PATH needs to also support the work parameter.
These changes expose a logic flaw in the if/else logic of the Fake program.
That bug is not fixed in this commit, it is simply noted in this commit log.
Kevin Day [Mon, 10 Jan 2022 03:30:55 +0000 (21:30 -0600)]
Bugfix: Fix problems exposed by unit testing and perform cleanups.
f_capability_ambient_set() should not be testing for (!value_flag).
Te flags pointer test should be "flags" and not "*flags".
Explicitly cast capability to void * for cap_free().
Use "value" rather than "code" for "f_capability_value_t".
Expand out CAP_IS_SUPPORTED() and CAP_AMBIENT_SUPPORTED() to explicitly set F_true and F_false.
This is better than relying on the direct result of those macros.
Make sure f_type support "weak" compiler attributes.
Rename the compiler attributes to be more than just for visibility.
Kevin Day [Sun, 9 Jan 2022 03:48:52 +0000 (21:48 -0600)]
Cleanup: Simplify structure using more basic file names and using separate print files.
These are private files and are not intended to be exposed.
This allows for the names to be more generic.
Break out the print functions into their own separate files.
This will also make the code more multi-lingual friendly in the respect that much of the code that might need to be swapped out exists in a single file.
This is still very far from multi-lingual friendly with many print code still not in the isolated print functions file.
Kevin Day [Thu, 6 Jan 2022 05:08:59 +0000 (23:08 -0600)]
Update: Have fss-000e Payload be more specific about payload handling.
Because payload may be anything, especially a binary blob, having it always be last as a requirement makes the most sense.
This then allows me to guarantee comments and other lists may not be after or inside.
This allows for the payload to not have to have comments or delimited code to deal with.
The payload will be a complete virgin binary blob until EOF or a designated length is reached.
Kevin Day [Thu, 6 Jan 2022 04:40:45 +0000 (22:40 -0600)]
Bugfix: Valid comment lines are keeping leading white space.
Any line that ends up being a valid comment line may have white space on the left.
For lists, such as FSS Basic List, the leading white space is being printed.
This is not correct at all.
This is easily solved by getting the last new line and add one.
Update the specification to make the expected behavior clear.
Cleanup comment lines and other related code while its convenient.
Kevin Day [Tue, 4 Jan 2022 04:23:29 +0000 (22:23 -0600)]
Progress: Continue working on the controller program's control functionality.
The f_socket_listen() seems to need its own process or thread.
Give it one.
Make this one as isolated as possible so that it can be forcible exited.
(Because listen() doesn't respect signal handlers.)
Kevin Day [Tue, 4 Jan 2022 04:14:31 +0000 (22:14 -0600)]
Update: Fix bug in socket disconnect, add additional signal functions, and some clean up.
The socket close enumerations are being directly passed to shutdown().
This is not correct because they do not directly map.
Use the size_read and size_write already provided in the socket file.
This allows for the length to be exclusively a write (better practice).
Provide f_signal_wait() and f_signal_wait_until() functions that handle sigwaitinfo() and sigtimedwait() respectively.
Use uint8_t rather than unsigned short.
The fact that there is still a short in use here makes it clear that I have not even glanced at this file in a long long time.
Kevin Day [Sun, 2 Jan 2022 18:43:36 +0000 (12:43 -0600)]
Bugfix: Incorrect mode is being set.
The world/other character is being mixed with the user.
Swap the "on" value for world/other and user.
Always reset the "what" value before starting the condition loop.
Turns out that the previous code does not support the form "u+rw-x".
The following is an alternative way to write this that previously worked "u+rw,u-x".
Make sure both methods are supported by adding an additional check for the "+", "-", and "=".
When adding and removing, the previous opposing bits needs to be reset.
For example "u+rwx-r" should set the "add read" bit and then remove the "add read" bit while setting the "subtract read" bit.
Also absurd forms like the following need to work: "u+rrrrrwx+rwwwxwrwrwrwww" or "u+rwx,g-rwx+wrrr,o+rwx-wwr".
A copy and paste mistake in f_file_mode_to_mode() results in the wrong bits being set for the world bits.
Don't operate on the parameters directly.
Update them only on success.
This ensures a safer design at a cost of slightly more resources being used.
Swap the world and the owner bits for replace to make it more logically consistent in the order of the bits.
Hopefully this will make things slightly less confusing.
Kevin Day [Sun, 2 Jan 2022 04:07:52 +0000 (22:07 -0600)]
Progress: Begin implementing Control support in Controller program.
Numerous structural changes and cleanups.
Things are getting bigger so apply some more organization changes to the project structure.
Start using the pointer constant behavior.
Drafted out Control functionality.
Drafted out Task functionality, which is being considered and will be tested to see if I really want to do (keep) this.
Kevin Day [Sun, 2 Jan 2022 04:03:24 +0000 (22:03 -0600)]
Update: f_file project.
Now that I am moving towards using pointer constants (sch as "int * const"), I can move many of the parameters to the left side.
I believe this sufficiently follows the pattern of having constants on the left and editables on the right even though the data pointed to can be edited.
I feel this allows me to relax the compromise I originally made when following this design paradigm.
Kevin Day [Sun, 2 Jan 2022 04:00:49 +0000 (22:00 -0600)]
Update: Add socket functions and improve existing ones.
It is very clear to me that I had stopped working on the socket code.
Much of the code appears incomplete, including some comments that weren't updated after they were copy and pasted.
This is only preliminary work for only the functionality needed or preceived needed by the Controller program or other existing programs.
There will likely be major work in the future during the 0.7.x development release series.
Kevin Day [Sun, 2 Jan 2022 04:00:02 +0000 (22:00 -0600)]
Update: Add several new status codes and update existing ones.
A new group "_di_F_status_network_" is provided.
This is done in anticipation of a large amount of dedicated network related status codes.
The next minor development release series (0.7.x) is planned to focus heavily on networking.
The networking is highly specialized and will likely have network specific variations of many existing status codes.
Kevin Day [Sat, 1 Jan 2022 02:56:10 +0000 (20:56 -0600)]
Cleanup: Use present tense.
Using past tense is a habit because everything being referred to is generally in the past.
The documentation and comments really should present tense despite this.
There is a lot of code that really needs this done but is not done in this comment.
I just happened to see these and decided to immediately fix them.
Kevin Day [Sat, 1 Jan 2022 02:48:05 +0000 (20:48 -0600)]
Update: Improvements to file processing code.
Code cleanups.
Add initializer to F_file_mode_t.
Have file closures set id to -1 even on error due to documented design of the close() function.
Provide path type for process path related file system operation failures.
Some operations do not distinguish file or directory but instead only operate on the path itself.
In these cases, the path type is now available for use.
Add F_file_found_not to standard error printer.
This allows for the standard error printer to still report the problem rather than a code.
Using the file-specific standard error printer is still the recommended approach.
Kevin Day [Sat, 1 Jan 2022 02:46:13 +0000 (20:46 -0600)]
Update: f_path related improvements.
Return F_data_not rather than F_false to provide a more detailed reason as to the return status of f_path_is().
Explicitly check fo F_true when calling f_path_is() because it now returns F_data_not without the error bit.
Add f_path_is_relative().
Pretty much every path that does not begin with a "/" is a relative path.
This function performs a dirt simple check to achieve this.
This function does not perform any checks to see if the path would be a valid path.
Such decisions are filesystem and are otherwise too situation dependent to be reliable detect in a general manner.
Use f_path_separator_s rather than an explicit "/".
Simplify counter using a pre-increment within the if condition check.
Kevin Day [Sat, 25 Dec 2021 22:38:31 +0000 (16:38 -0600)]
Feature: Add support for "context" IKI in Fakefiles.
This updates the IKI-0002 specification to support "context".
This allows for color context and ideally any future context to make software more accessible.
Update the existing testfiles to utilize this context.
Kevin Day [Fri, 24 Dec 2021 05:49:32 +0000 (23:49 -0600)]
Cleanup: Append "_e" to all enums, update status types, and update status strings.
A new practice is to have "_e" at the end of all enums.
Update all of the existing enums to follow this practice.
I noticed some fixme comments about moving the status codes to a lower level.
Do this.
Update all code accordingly.
The status code strings are only for special cases, so make this its own project directory (for both Status and FSS Status).
These are f_status_string and fll_fss_status_string.
Kevin Day [Thu, 23 Dec 2021 17:43:57 +0000 (11:43 -0600)]
Update: Use 'shell' rather than 'run' in testfile.
I apparently missed this line.
The 'run' operation will attempt to execute based on PATH environment.
The 'shell' operation expects local files, which is what these tests are.
Kevin Day [Thu, 23 Dec 2021 17:38:21 +0000 (11:38 -0600)]
Update: Add tests for f_type_array.
Given the size of the task and my relative inexperience with cmocka, I opted to keep the tests as simple as possible.
This means that my tests are likely not thorough.
These are intended to be good enough for a first pass tests.
After all, I have the entire rest of the FLL projects to write tests for (as well as for the programs).
Kevin Day [Thu, 23 Dec 2021 04:58:47 +0000 (22:58 -0600)]
Update: Move main data into the data make structure.
The goal here is to reduce the number arguments passed to functions in a consistent manner.
This has a downside of having another pointer and the costs of dereferencing it for each access.
Rename the "main" property to "id_main" to be clearer as well as to not conflict with the new "main" property that points to the main data.
Remove a stale header that has no associated function implemented.
Kevin Day [Thu, 23 Dec 2021 03:59:47 +0000 (21:59 -0600)]
Update: Add "and" and "or" operations, operation if-then-else logic, and some cleanups.
Add the "and" and "or" operations to make the "if" and "else" operations more complete.
The current design still does not support directly nested multiple operations underneath an "if" or an "else".
Using an "operate" operation is still the only way to do this.
The reason for this is to keep the logic and design simple.
This has a cost of causing complicated design to be even more complicated than they otherwise could be if I allowed "if" and "else" to contain blocks of commands or even be nested.
While I am at it, this cleans up the if-then-else logic.
This needed to be done for some time.
My original design was patched at some point to add unexpected functionality that I had not originally planned but later realized I needed.
The patch was just a good enough for now.
This resulted in the logic being a bit ugly and confusing.
The new logic is a lot better, but there are still some things that might be confusing.
To that end, I decided to only perform simple tests.
I instead intend to write unit tests that will perform all of the possible combinations that I can reasonably come up with.
This should help me find logic flaws in my current design.
This now uses a structure to pass the process state data.
This further simplifies the design to allow for fewer parameters in the relevant functions.
Several of the duplicated print calls are consolidated into a single print function.
Kevin Day [Thu, 23 Dec 2021 03:40:54 +0000 (21:40 -0600)]
Security: Invalid memory access in interrupt handlers.
When I converted the data_main into a pointer from a value, I failed to remove the references on these variables.
The compiler does not catch these because they are cast to a void *.