Compare commits
2 Commits
df57225b1c
...
72ee4655e3
Author | SHA1 | Date |
---|---|---|
Joe | 72ee4655e3 | |
Joe | bd11fdb37b |
75
linac
75
linac
|
@ -2,7 +2,7 @@
|
|||
# shellcheck disable=SC1090
|
||||
projectName='LINAC'
|
||||
projectDescription='LINAC is not a compiler'
|
||||
projectVersion=0.7.3
|
||||
projectVersion=0.8.0
|
||||
projectAuthor='Joe <joe@thisisjoes.site>'
|
||||
projectLicense='GPLv3'
|
||||
Configure() {
|
||||
|
@ -10,6 +10,10 @@ Configure() {
|
|||
config=(
|
||||
[config_path]="config"
|
||||
[config_file]="linac.conf"
|
||||
[verbosity]="error"
|
||||
[log_level]="info"
|
||||
[log_path]="/tmp"
|
||||
[log_file]="linac.log"
|
||||
[src_path]="src/"
|
||||
[build_path]="build/"
|
||||
[debug_enabled]="false"
|
||||
|
@ -66,10 +70,47 @@ Clean() {
|
|||
|
||||
echo "$clean_string"
|
||||
}
|
||||
DebugPrint() {
|
||||
if "${config[debug_enabled]}"; then
|
||||
echo "${FUNCNAME[1]} says: $*"
|
||||
fi
|
||||
Log() {
|
||||
LogTerm "$1" "$2"
|
||||
LogFile "$1" "$2"
|
||||
}
|
||||
LogTerm() {
|
||||
local term_log_type="${1^^}"
|
||||
local term_log_message="$2"
|
||||
|
||||
local verbosity="${config[verbosity]^^}"
|
||||
|
||||
DoLogTerm() {
|
||||
echo "$term_log_type - $term_log_message"
|
||||
}
|
||||
|
||||
case $term_log_type in
|
||||
DEBUG ) if [[ "$verbosity" = @(DEBUG) ]]; then DoLogTerm; fi;;
|
||||
INFO ) if [[ "$verbosity" = @(DEBUG|INFO) ]]; then DoLogTerm; fi;;
|
||||
WARN ) if [[ "$verbosity" = @(DEBUG|INFO|WARN) ]]; then DoLogTerm; fi;;
|
||||
ERROR ) if [[ "$verbosity" = @(DEBUG|INFO|WARN|ERROR) ]]; then DoLogTerm; fi;;
|
||||
CONFIG ) if [[ "$verbosity" = @(DEBUG|INFO) ]]; then DoLogTerm; fi;;
|
||||
* ) if [[ "$verbosity" = @(DEBUG) ]]; then DoLogTerm; Log debug "Invalid term log type '$term_log_type' in context '${FUNCNAME[2]}'"; fi;;
|
||||
esac
|
||||
}
|
||||
LogFile() {
|
||||
local file_log_type="${1^^}"
|
||||
local file_log_message="$2"
|
||||
|
||||
local log_level="${config[log_level]^^}"
|
||||
|
||||
DoLogFile() {
|
||||
echo "[$(date '+%d/%b/%Y:%H:%M:%S.%3N')] ${file_log_type} - ${FUNCNAME[3]}: $file_log_message" >> "${config[log_path]}/${config[log_file]}"
|
||||
}
|
||||
|
||||
case $file_log_type in
|
||||
DEBUG ) if [[ "$log_level" = @(DEBUG) ]]; then DoLogFile; fi;;
|
||||
INFO ) if [[ "$log_level" = @(DEBUG|INFO) ]]; then DoLogFile; fi;;
|
||||
WARN ) if [[ "$log_level" = @(DEBUG|INFO|WARN) ]]; then DoLogFile; fi;;
|
||||
ERROR ) if [[ "$log_level" = @(DEBUG|INFO|WARN|ERROR) ]]; then DoLogFile; fi;;
|
||||
CONFIG ) if [[ "$log_level" != @(NONE) ]]; then DoLogFile; fi;;
|
||||
* ) if [[ "$log_level" = @(DEBUG) ]]; then DoLogFile; Log debug "Invalid file log type '$file_log_type' in context '${FUNCNAME[2]}'"; fi;;
|
||||
esac
|
||||
}
|
||||
ProcessBuildFile() {
|
||||
local files
|
||||
|
@ -94,18 +135,18 @@ BuildProject() {
|
|||
arg="${arg#?}"
|
||||
case "$arg" in
|
||||
d )
|
||||
DebugPrint "Debug build enabled."
|
||||
DebugPrint "Args are $*"
|
||||
DebugPrint "Arg is $arg"
|
||||
Log debug "Debug build enabled."
|
||||
Log debug "Args are $*"
|
||||
Log debug "Arg is $arg"
|
||||
for ((i=0;i<"${#files[*]}";i++));do
|
||||
find "${files[$i]}" -type f -print0 | xargs -0 cat;
|
||||
done >> "${config[build_path]}""$name"
|
||||
;;
|
||||
|
||||
* )
|
||||
DebugPrint "Stripped build enabled."
|
||||
DebugPrint "Args are $*"
|
||||
DebugPrint "Arg is $arg"
|
||||
Log debug "Stripped build enabled."
|
||||
Log debug "Args are $*"
|
||||
Log debug "Arg is $arg"
|
||||
for ((i=0;i<"${#files[*]}";i++));do
|
||||
grep -Ehrv '^\s*\#' "${files[$i]}";
|
||||
done >> "${config[build_path]}""$name"
|
||||
|
@ -243,12 +284,10 @@ SubCommand() {
|
|||
fi
|
||||
;;
|
||||
* )
|
||||
Configure
|
||||
ReadConfiguration
|
||||
DebugPrint "Args are $*"
|
||||
Log debug "Args are $*"
|
||||
shift
|
||||
DebugPrint "Shifted args"
|
||||
DebugPrint "Args are $*"
|
||||
Log debug "Shifted args"
|
||||
Log debug "Args are $*"
|
||||
if ! command -v Sub"${subcommand^}" > /dev/null; then
|
||||
echo "Error: '$subcommand' is not a known command."
|
||||
echo " Run 'linac help' for a list of known commands."
|
||||
|
@ -260,8 +299,10 @@ SubCommand() {
|
|||
esac
|
||||
}
|
||||
Main() {
|
||||
PrintInfo
|
||||
Configure
|
||||
ReadConfiguration
|
||||
SubCommand "$@"
|
||||
}
|
||||
|
||||
PrintInfo
|
||||
Main "$@"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
projectName='LINAC'
|
||||
projectDescription='LINAC is not a compiler'
|
||||
projectVersion=0.7.3
|
||||
projectVersion=0.8.0
|
||||
projectAuthor='Joe <joe@thisisjoes.site>'
|
||||
projectLicense='GPLv3'
|
||||
|
|
Loading…
Reference in New Issue