first commit
This commit is contained in:
parent
ce51c9d431
commit
5d13dd2df3
|
@ -9,3 +9,33 @@ When making TUI menus, try to use the first leter of the command and the key to
|
|||
When deleting, everything gets moved to the Trash folder.
|
||||
|
||||
MAKEFILE POLICY: There should be only ONE Makefile in the entire project. All build logic (library, tests, examples, websocket) must be consolidated into the root Makefile. Do not create separate Makefiles in subdirectories as this creates testing inconsistencies where you test with one Makefile but run with another.
|
||||
|
||||
### Sinple Text User Interfaces (TUI)
|
||||
When making TUI menus, try to use the first leter of the command and the key to press to execute that command. For example, if the command is "Open file" try to use a keypress of "o" upper or lower case to signal to open the file. Use this instead of number keyed menus when possible. In the command, the letter should be underlined that signifies the command.
|
||||
q and x should be reserved for the quit command.
|
||||
|
||||
|
||||
|
||||
## Buffer Size Guidelines to Prevent Compilation Warnings.
|
||||
|
||||
### Path Handling
|
||||
- Always use buffers of size 1024 or PATH_MAX (4096) for file paths
|
||||
- When concatenating paths with snprintf, ensure buffer is at least 2x the expected maximum input
|
||||
- Use safer path construction patterns that check lengths before concatenation
|
||||
|
||||
### String Formatting Safety
|
||||
- Before using snprintf with dynamic strings, validate that buffer size >= sum of all input string lengths + format characters + 1
|
||||
- Use strnlen() to check actual string lengths before formatting
|
||||
- Consider using asprintf() for dynamic allocation when exact size is unknown
|
||||
- Add length validation before snprintf calls
|
||||
|
||||
### Compiler Warning Prevention
|
||||
- Always size string buffers generously (minimum 1024 for paths, 512 for general strings)
|
||||
- Use buffer size calculations: `size >= strlen(str1) + strlen(str2) + format_overhead + 1`
|
||||
- Add runtime length checks before snprintf operations
|
||||
- Consider using safer alternatives like strlcpy/strlcat if available
|
||||
|
||||
### Code Patterns to Avoid
|
||||
- Fixed-size buffers (512 bytes) for path operations where inputs could be 255+ bytes each
|
||||
- Concatenating unchecked strings with snprintf
|
||||
- Assuming maximum path component sizes without validation
|
||||
|
|
69
build.sh
69
build.sh
|
@ -250,6 +250,75 @@ case "$TARGET" in
|
|||
|
||||
if [[ -f "Makefile" ]]; then
|
||||
make clean
|
||||
# Regenerate version files after clean (since clean removes them)
|
||||
if git rev-parse --git-dir > /dev/null 2>&1; then
|
||||
LATEST_TAG=$(git tag -l 'v*.*.*' | sort -V | tail -n 1 || echo "v0.1.0")
|
||||
VERSION=${LATEST_TAG#v}
|
||||
if [[ $VERSION =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||
MAJOR=${BASH_REMATCH[1]}
|
||||
MINOR=${BASH_REMATCH[2]}
|
||||
PATCH=${BASH_REMATCH[3]}
|
||||
|
||||
# Regenerate version files
|
||||
cat > "${SRC_DIR}/version.h" << EOF
|
||||
/*
|
||||
* ${PROJECT_NAME_UPPER} - Auto-Generated Version Header
|
||||
* DO NOT EDIT THIS FILE MANUALLY - Generated by build script
|
||||
*/
|
||||
|
||||
#ifndef ${PROJECT_NAME_UPPER}_VERSION_H
|
||||
#define ${PROJECT_NAME_UPPER}_VERSION_H
|
||||
|
||||
#define VERSION_MAJOR ${MAJOR}
|
||||
#define VERSION_MINOR ${MINOR}
|
||||
#define VERSION_PATCH ${PATCH}
|
||||
#define VERSION_STRING "${MAJOR}.${MINOR}.${PATCH}"
|
||||
#define VERSION_TAG "${LATEST_TAG}"
|
||||
|
||||
/* Build information */
|
||||
#define BUILD_DATE "$(date +%Y-%m-%d)"
|
||||
#define BUILD_TIME "$(date +%H:%M:%S)"
|
||||
#define BUILD_TIMESTAMP "$(date '+%Y-%m-%d %H:%M:%S')"
|
||||
|
||||
/* Git information */
|
||||
#define GIT_HASH "$(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')"
|
||||
#define GIT_BRANCH "$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'unknown')"
|
||||
|
||||
/* Display versions */
|
||||
#define VERSION_DISPLAY "${LATEST_TAG}"
|
||||
#define VERSION_FULL_DISPLAY "${LATEST_TAG} ($(date '+%Y-%m-%d %H:%M:%S'), $(git rev-parse --short HEAD 2>/dev/null || echo 'unknown'))"
|
||||
|
||||
/* Version API functions */
|
||||
const char* get_version(void);
|
||||
const char* get_version_full(void);
|
||||
const char* get_build_info(void);
|
||||
|
||||
#endif /* ${PROJECT_NAME_UPPER}_VERSION_H */
|
||||
EOF
|
||||
|
||||
cat > "${SRC_DIR}/version.c" << EOF
|
||||
/*
|
||||
* ${PROJECT_NAME_UPPER} - Auto-Generated Version Implementation
|
||||
* DO NOT EDIT THIS FILE MANUALLY - Generated by build script
|
||||
*/
|
||||
|
||||
#include "version.h"
|
||||
|
||||
const char* get_version(void) {
|
||||
return VERSION_TAG;
|
||||
}
|
||||
|
||||
const char* get_version_full(void) {
|
||||
return VERSION_FULL_DISPLAY;
|
||||
}
|
||||
|
||||
const char* get_build_info(void) {
|
||||
return "Built on " BUILD_DATE " at " BUILD_TIME " from commit " GIT_HASH " on branch " GIT_BRANCH;
|
||||
}
|
||||
EOF
|
||||
print_success "Regenerated version files after clean"
|
||||
fi
|
||||
fi
|
||||
make
|
||||
else
|
||||
print_error "No Makefile found. Please create a Makefile for your project."
|
||||
|
|
Loading…
Reference in New Issue