From 8c06926e962a78f8dc2617c5a00f73d2552f8ea3 Mon Sep 17 00:00:00 2001
From: hdd29 <hdd29@drexel.edu>
Date: Sat, 11 May 2019 21:51:17 -0400
Subject: [PATCH] Functions well but prints weird things to stdout
---
assn1/al-top | 67 +++++++++++++++++++++++++++++++++++++++++++++
assn1/analyzeREADME | 38 +++++++++++++++++++++++++
2 files changed, 105 insertions(+)
create mode 100755 assn1/al-top
create mode 100755 assn1/analyzeREADME
diff --git a/assn1/al-top b/assn1/al-top
new file mode 100755
index 0000000..743a867
--- /dev/null
+++ b/assn1/al-top
@@ -0,0 +1,67 @@
+#!/bin/bash
+#
+#Written by Hanh Do Phung
+# 05/04/2019
+
+
+
+
+
+function createDirXML
+{
+ dirXML="./dir.xml"
+ echo '<?xml version="1.0" encoding="ISO-8859-1"?>' > "$dirXML"
+ echo '<direntry>' >> "$dirXML"
+ if [[ -f "./README" ]]; then
+ awk -f "$2/analyzeREADME" "./README" >> "$dirXML"
+ recordOthers "$dirXML" "$dirXML"
+ fi
+
+ echo '</direntry>' >> "$dirXML"
+ }
+
+function recordOthers
+{
+ echo -e "\t<other>" >> "$1"
+
+ find . -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | while read dir; do
+ echo -e "\t\t<dir>$dir</dir>" >> "$1"
+ done
+
+ find . -mindepth 1 -maxdepth 1 -type f ! -name "dir.xml" -printf "%f\n" | while read file ; do
+ if ! egrep "<file>$file" "$2"; then
+ echo -e "\t\t<file>$file</file>" >> "$1"
+ fi
+ done
+ echo -e "\t</other>" >> "$1"
+}
+
+
+pathAnalyzeREADME="$( cd "$(dirname "$0")" ; pwd -P)"
+
+
+
+if [[ "$#" == 1 ]]; then
+ if [[ ! -d $1 ]]; then
+ echo "Invalid directory!"
+ exit 2
+ fi
+ find "$1" -type d | while read dir; do
+ pushd "$dir"
+ createDirXML "$dir" "$pathAnalyzeREADME"
+ popd
+ done
+ exit 0
+
+elif [[ "$#" == 0 ]]; then
+ find . -type d | while read dir; do
+ pushd "$dir"
+ createDirXML "$dir" "$pathAnalyzeREADME"
+ popd
+ done
+ exit 0
+
+elif [[ "$#" > 1 ]]; then
+ echo -e "Have only 1 argument as directory to traverse \n or none to traverse this current directory"
+ exit 1
+fi
diff --git a/assn1/analyzeREADME b/assn1/analyzeREADME
new file mode 100755
index 0000000..9b47b68
--- /dev/null
+++ b/assn1/analyzeREADME
@@ -0,0 +1,38 @@
+#!/bin/awk -f
+#
+# Written by Hanh Do Phung
+# 05/04/2019
+#
+# This awk script is to analyze the README placed in each directory and
+#write the index and required part of the dir.xml file. Presumably the
+#in the README file, the required and index part does not contain any
+#directory
+
+
+
+BEGIN { FS=":" }
+
+
+$1=="index" {
+ print "\t<index>"
+
+ for ( i=2; i<=NF; ++i)
+ print "\t\t<file>" $i "</file>"
+ print "\t</index>"
+}
+
+
+$1=="required" {
+ print "\t<required>"
+
+ for (i=2; i<=NF; ++i)
+ print "\t\t<file>" $i "</file>"
+
+ print "\t</required>"
+}
+
+
+
+
+
+
--
GitLab