.
authorThomas Walker Lynch <xtujpz@reasoningtechnology.com>
Mon, 12 Aug 2024 07:50:56 +0000 (07:50 +0000)
committerThomas Walker Lynch <xtujpz@reasoningtechnology.com>
Mon, 12 Aug 2024 07:50:56 +0000 (07:50 +0000)
developer/\necho $var_name = $file_list\n\nif [ -z "" ]; then\n exit 0\nfi\n\necho 'Cleaning files: '\nfor file in $file_list; do\n if [ -e "" ]; then\n echo rm -f ""\n rm -f ""\n fi\ndone\n [new file with mode: 0644]
developer/executor/PrintRuleNameList [deleted file]
developer/executor/Test__SyntaxTree_Arithmetic [deleted file]
developer/executor/clean
developer/executor/clean_file_list
developer/executor/clean_grammar
developer/executor/env_build
developer/makefile

diff --git a/developer/\necho $var_name = $file_list\n\nif [ -z "" ]; then\n exit 0\nfi\n\necho 'Cleaning files: '\nfor file in $file_list; do\n if [ -e "" ]; then\n echo rm -f ""\n rm -f ""\n fi\ndone\n b/developer/\necho $var_name = $file_list\n\nif [ -z "" ]; then\n exit 0\nfi\n\necho 'Cleaning files: '\nfor file in $file_list; do\n if [ -e "" ]; then\n echo rm -f ""\n rm -f ""\n fi\ndone\n
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/developer/executor/PrintRuleNameList b/developer/executor/PrintRuleNameList
deleted file mode 100755 (executable)
index 598e6a2..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env bash
-/var/user_data/Thomas-developer/GQL_to_Cypher/tool/jdk-22.0.1+8/bin/java -cp /var/user_data/Thomas-developer/GQL_to_Cypher/tool/executor/antlr-4.11.1-complete.jar:jvm:jvm/PrintRuleNameList.jar PrintRuleNameList $@
diff --git a/developer/executor/Test__SyntaxTree_Arithmetic b/developer/executor/Test__SyntaxTree_Arithmetic
deleted file mode 100755 (executable)
index 038b1ad..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env bash
-/var/user_data/Thomas-developer/GQL_to_Cypher/tool/jdk-22.0.1+8/bin/java -cp /var/user_data/Thomas-developer/GQL_to_Cypher/tool/executor/antlr-4.11.1-complete.jar:jvm:jvm/Test__SyntaxTree_Arithmetic.jar Test__SyntaxTree_Arithmetic $@
index b03a6b1..dd931d1 100755 (executable)
@@ -1,5 +1,4 @@
 #!/usr/bin/env bash
-#!/usr/bin/env bash
 
 # Clean targets:
 #
@@ -23,6 +22,35 @@ display_usage() {
   echo "Usage: clean <all [<program_name>] | program [<program_name>] | grammar [<name>] | class | temp[orary]>"
 }
 
+# Function to clean a directory
+clean_directory() {
+  local dir="$1"
+  find "$dir" -type f ! -name '.githolder' -exec rm -f {} +
+}
+
+# Function to check if a program is in PROGRAM_FPL
+is_program_in_fpl() {
+  local program="$1"
+  for prog in $PROGRAM_FPL; do
+    if [[ "$prog" == *"$program"* ]]; then
+      return 0
+    fi
+  done
+  return 1
+}
+
+# Function to delete a program
+delete_program() {
+  local program="$1"
+  if is_program_in_fpl "$program"; then
+    echo "Deleting program files for '$program'"
+    rm -f "executor/$program" "$JAVA_COMP_OUT_DIR/$program.jar" "$JAVA_COMP_OUT_DIR/$program.class"
+  else
+    echo "Error: Program '$program' is not recognized or is not listed in PROGRAM_FPL."
+    return 1
+  fi
+}
+
 # Command parser
 clean_command_parser() {
   local token_list=($@)
@@ -61,8 +89,9 @@ clean_command_parser() {
   elif [ "$token_count" -eq 2 ]; then
     case "$command" in
       "all")
-        clean_file_list "executor/$arg $JAVA_COMP_OUT_DIR/$arg.jar $JAVA_COMP_OUT_DIR/$arg.class"
-        # program specific cleaning
+        # Program name is $arg.
+        delete_program "$arg"
+        # Custom cleaning for each program.
         case "$arg" in
           "SyntaxTree_Test")
             clean_grammar "GQL_Test"
@@ -79,10 +108,11 @@ clean_command_parser() {
         esac
         ;;
       "program")
-        clean_file_list "executor/$arg"
-        clean_file_list "$JAVA_COMP_OUT_DIR/$arg.jar"
+        # Program name is $arg.
+        delete_program "$arg"
         ;;
       "grammar")
+        # Grammar name is $arg.
         clean_grammar "$arg"
         ;;
       *)
@@ -94,4 +124,5 @@ clean_command_parser() {
   fi
 }
 
+source env_build
 clean_command_parser $@
index df11624..7922717 100755 (executable)
@@ -1,21 +1,54 @@
 #!/usr/bin/env bash
 
 if [ -z "$1" ]; then
-  echo "Error: File list name is not provided."
+  exit 0
+fi
+
+# Determine the directory where the script is located
+script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Use `env -i` to clear the environment and then source `env_build` from the script's directory
+env -i bash -c "
+
+source '${script_dir}/env_build'
+
+var_name='$1'
+#echo 'var_name is: ' \$var_name
+if [ -z \"\$var_name\" ]; then
+  echo 'USAGE: clean_file_list <env_variable_name>'
   exit 1
 fi
 
-file_list=$(eval echo \$$1)
+# Check if the variable is defined in the current environment
+if [ -z \"\$(eval echo \\$\$var_name)\" ]; then
+  echo 'Error: Environment variable \"\$var_name\" is not defined in env_build.'
+  exit 1
+fi
 
-if [ -z "$file_list" ]; then
-  echo "Error: File list $1 is empty or not set."
+# Check if the variable name contains 'PRIMARY' (case insensitive)
+if [[ \"\$var_name\" =~ [Pp][Rr][Ii][Mm][Aa][Rr][Yy] ]]; then
+  echo 'Error: Environment variable \"\$var_name\" contains \"PRIMARY\" so listed files were not deleted.'
   exit 1
 fi
 
-echo "Cleaning files: $file_list"
-for file in $file_list; do
-  if [ -e "$file" ]; then
-    echo rm -f "$file"
-    rm -f "$file"
+# Check if the variable name ends with '_FPL'
+if [[ ! \"\$var_name\" =~ _FPL$ ]]; then
+  echo 'Error: Environment variable \"\$var_name\" must end with \"_FPL\".'
+  exit 1
+fi
+
+# Get the file list from the environment variable
+file_list=\$(eval echo \\$\$var_name)
+echo \$var_name \"=\" \$file_list
+
+if [ -z \"\$file_list\" ]; then
+  exit 0
+fi
+
+for file in \$file_list; do
+  if [ -e \"\$file\" ]; then
+    echo rm -f \"\$file\"
+    rm -f \"\$file\"
   fi
 done
+" "$1"
index 0ec60cf..e182a47 100755 (executable)
@@ -9,7 +9,7 @@ fi
 # Function to delete a specific grammar
 delete_grammar() {
   local grammar=$1
-  echo "Attempting to delete grammar: $grammar"
+  echo "Attempting to delete grammar: $grammar"
   if [ -z "$grammar" ]; then
     echo "Error: Grammar name is empty"
   elif echo "$ANTLR_GRAMMAR_LIST" | grep -qw "$grammar"; then
index 8e10c74..3973575 100755 (executable)
@@ -64,9 +64,9 @@ export TEMP_DIR="$DEVELOPER_HOME"/temporary
 # ANTLR files
 #
 
-export ANTLR_IN_FPL=$(ls ${ANTLR_IN_PRIMARY_DIR}/*.g4 2>/dev/null | tr '\n' ' ')
-export ANTLR_GRAMMAR_LIST=$(basename -s .g4 ${ANTLR_IN_FPL})
-if [ -z "${ANTLR_IN_FPL}" ]; then
+export ANTLR_IN_PRIMARY_FPL=$(ls ${ANTLR_IN_PRIMARY_DIR}/*.g4 2>/dev/null | tr '\n' ' ')
+export ANTLR_GRAMMAR_LIST=$(basename -s .g4 ${ANTLR_IN_PRIMARY_FPL})
+if [ -z "${ANTLR_IN_PRIMARY_FPL}" ]; then
   echo "No ANTLR input grammar files found"
 fi
 
index 2e31368..9aa6991 100644 (file)
@@ -74,7 +74,7 @@ nothing:
 $(ANTLR_OUT_DIR)/%Lexer.java \
 $(ANTLR_OUT_DIR)/%Parser.java \
 $(ANTLR_OUT_DIR)/%BaseVisitor.java \
-$(ANTLR_OUT_DIR)/%Visitor.java: $(ANTLR_IN_PRIMARY_DIR)/%.g4
+$(ANTLR_OUT_DIR)/%Visitor.java: $(ANTLR_IN_PRIMARY_FPL)
        @echo "making grammar from:" $<
        $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $<