From 4cdb05b97f24f66f026abc7846b3aff1fc53f71b Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 26 Feb 2024 10:06:47 +0200 Subject: [s1] Combined CSG scripts are now ordered, according to regexes in alphabetically-ordered scripts Scripts are alphabetically ordered, and combined files use the order in which new regexes (amongst the ordered scripts) are found. By regex I'm reffering to the filename regex as the top comment of every script. This allows some crude amount of control over the order in which scripts are concatenated. Since POSIX doesn't have @include or a similar construct, and the idea is to promote splitting your projects into smaller scripts, this is required. To summarize, all files with the same regex have their rules concatenated in filename alphabetic order, and the rules themselves are ordered, according to their first occurrence in the files in filename alphabetic order. So, rules of script B.awk will always run after script A.awk, no matter regexes. To make script C.awk run before script B.awk, you'll need A.awk and C.awk to share regex, but B.awk to not (A.awk could even be a dummy script, only having the regex on top). --- csg | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/csg b/csg index 61b010f..7e33c18 100755 --- a/csg +++ b/csg @@ -176,20 +176,28 @@ then # Remove first field $1=""; sub(FS, "") # Associate current file with regex - if (awks[$0] == "") awks[$0] = FILENAME - else awks[$0] = awks[$0] " " FILENAME + if (awks[$0] == "") { + awks[$0] = FILENAME + regexes[regexcount++] = $0 + } + else { + awks[$0] = awks[$0] " " FILENAME + } nextfile } END { - for (reg in awks) { - print reg + # Regexes are outputed in file alphabetic order + # Since certain scripts may require specific ordering + # between their rules, this is a crude way to allow that + for (regi = 0; regi < regexcount; regi++) { + print regexes[regi] outf = TMP_DIR "/csg-" (awkcount++) ".awk" print outf - system("cat " awks[reg] " > " outf) + system("cat " awks[regexes[regi]] " > " outf) } } - ' $(find $AWKSCRIPTS -type f -name "[A-Z]*.awk"))" + ' $(find $AWKSCRIPTS -type f -name "[A-Z]*.awk" | sort))" overwriteLine "[Stage 1] Finding awk libraries" -- cgit v1.3.1-23-gd82d