diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/Assignment.pdf b/Summer-2024/CS-3424/Assignments/Assignment-1/Assignment.pdf new file mode 100644 index 0000000..27ecb88 Binary files /dev/null and b/Summer-2024/CS-3424/Assignments/Assignment-1/Assignment.pdf differ diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/assign1.bash b/Summer-2024/CS-3424/Assignments/Assignment-1/src/assign1.bash new file mode 100755 index 0000000..574f3e7 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/assign1.bash @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +set -eEuo pipefail + +SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" +DATA_DIR="${SCRIPT_DIR}/data" +LOG_FILE="${SCRIPT_DIR}/data/queries.log" + +log() { + local out + local title="${1?No title provided to log!}" + shift + local msg="${1?No message provided to log!}" + shift + out="[$(date)] ${title}: ${msg}" + for body_line in "${@}"; do + out="${out}\n${body_line}" + done + printf "%s\n" "$out" >"$LOG_FILE" +} + +show_options() { + cat <<-__EOS__ + Enter one of the following actions or press CTRL-D to exit. + C - create a new course record + R - read an existing course record + U - update an existing course record + D - delete an existing course record + E - update enrolled student count of existing course + T - show total course count + __EOS__ +} + +err() { + printf "ERROR: %s\n" "${*}" 1>&2 +} + +main() { + printf "%s\n" "OK" + . ./create.bash + . ./delete.bash + . ./enroll.bash + . ./read.bash + . ./total.bash + . ./update.bash + show_options + while read -r option; do + case "$option" in + C) + create_course "$DATA_DIR" || continue + ;; + R) + read_course "$DATA_DIR" || continue + ;; + U) ;; + D) + delete_course "$DATA_DIR" || continue + ;; + E) ;; + T) ;; + *) + printf "ERROR: invalid option\n" + ;; + esac + show_options + done + +} + +main "${@}" diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/create.bash b/Summer-2024/CS-3424/Assignments/Assignment-1/src/create.bash new file mode 100755 index 0000000..878da2c --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/create.bash @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +set -eEuo pipefail + +create_course() { + local data_dir="${1}" + local dept_code + local dept_name + local course_num + local course_name + local course_sched + local course_start + local course_end + local course_hours + local course_size + + read -r -p "Department code: " dept_code + read -r -p "Department name: " dept_name + read -r -p "Course number: " course_num + read -r -p "Course name: " course_name + read -r -p "Scheduled days: " course_sched + read -r -p "Course start: " course_start + read -r -p "Course end: " course_end + read -r -p "Credit hours: " course_hours + read -r -p "Enrolled students: " course_size + + if [[ -z "${dept_code}" ]] || [[ -z "${course_num}" ]]; then + err "must provide a department code and course number" + return + fi + + local course_file="${data_dir}/${dept_code}${course_num}.crs" + + if [[ -f "${course_file}" ]]; then + err "course already exists" + return + fi + + cat <<-__EOS__ >"${data_dir}/${dept_code}${course_num}.crs" + ${dept_code} ${dept_name} + ${course_name} + ${course_sched} ${course_start} ${course_end} ${course_hours} ${course_size} + __EOS__ + log "CREATED" "${dept_code} ${course_num} ${course_name}" +} diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/BIO2061.crs b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/BIO2061.crs new file mode 100644 index 0000000..bbe7285 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/BIO2061.crs @@ -0,0 +1,3 @@ +BIO Biology +Human Anatomy and Physiology Laboratory II +MWF 8/26/24 12/14/24 3 59 diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/BIO3343.crs b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/BIO3343.crs new file mode 100644 index 0000000..a396c81 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/BIO3343.crs @@ -0,0 +1,3 @@ +BIO Biology +Plant Cell Biology +TH 8/26/24 12/15/24 3 51 diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/CS3424.crs b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/CS3424.crs new file mode 100644 index 0000000..515ee49 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/CS3424.crs @@ -0,0 +1,3 @@ +CS Computer Science +Systems Programming +MWF 8/26/24 12/13/24 4 68 diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/GEO3151.crs b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/GEO3151.crs new file mode 100644 index 0000000..e92cc4d --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/GEO3151.crs @@ -0,0 +1,3 @@ +GEO Geological Sciences +Economic Geology Laboratory +TH 8/26/24 12/10/24 1 59 diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/MAT1311.crs b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/MAT1311.crs new file mode 100644 index 0000000..e2f05d6 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/MAT1311.crs @@ -0,0 +1,3 @@ +MAT Mathematics +Calculus I +TH 8/26/24 12/11/24 3 71 diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/MAT3103.crs b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/MAT3103.crs new file mode 100644 index 0000000..8ddaf13 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/MAT3103.crs @@ -0,0 +1,3 @@ +MAT Mathematics +Data Analysis and Interpretation +TH 8/26/24 12/12/24 3 60 diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/MAT4353.crs b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/MAT4353.crs new file mode 100644 index 0000000..6d132b0 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/MAT4353.crs @@ -0,0 +1,3 @@ +MAT Mathematics +Mathematical Foundations of Cryptography +MWF 8/26/24 12/13/24 3 53 diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/a1Input.txt b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/a1Input.txt new file mode 100644 index 0000000..ec4d682 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/a1Input.txt @@ -0,0 +1,36 @@ +c +CS +Computer Science +3423 +Systems Programming +TH +8/20/24 +12/13/24 +4 +60 +r +cs 3423 +r +cs 3424 +r +XXX 1234 +u +cs + +3421 +Systems Laboratory + + + + +25 +r +cs 3423 +d +cs 3424 +r +cs 3424 +e +cs 3423 +68 +t diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/a1_strings.txt b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/a1_strings.txt new file mode 100644 index 0000000..dafe21d --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/a1_strings.txt @@ -0,0 +1,68 @@ +This file was generated by using "grep" to filter for lines containing "echo" or "read -p" +invocations, such that you may you use the exact verbiage in your script. +For example, this was the command line used to make this file (notwithstanding a small +amount of manual cleanup/formatting at the end): + + for f in *.bash; do echo -e "\n$f:"; \grep -e echo -e "read -p" "$f"; done > a1_strings.txt + + +assign1.bash: + echo "Enter one of the following actions or press CTRL-D to exit." + echo "C - create a new course record" + echo "R - read an existing course record" + echo "U - update an existing course record" + echo "D - delete an existing course record" + echo "E - update enrolled student count of existing course" + echo "T - show total course count" + *) echo "ERROR: invalid option";; + +create.bash: + read -p "Department code: " dept_code + read -p "Department name: " dept_name + read -p "Course number: " course_num + read -p "Course name: " course_name + read -p "Scheduled days: " course_sched + read -p "Course start: " course_start + read -p "Course end: " course_end + read -p "Credit hours: " course_hours + read -p "Enrolled students: " course_size + echo "ERROR: must provide a department code and course number" 1>&2 + echo "ERROR: course already exists" + +delete.bash: + read -p "Enter a department code and course number: " dept_code course_num + echo "ERROR: course not found" + echo "$course_num was successfully deleted" + +enroll.bash: + read -p "Enter a department code and course number: " dept_code course_num + read -p "Enter an enrollment change amount: " change_amt + echo "ERROR: course not found" + +read.bash: + read -p "Enter a department code and course number: " dept_code course_num + echo "ERROR: course not found" + echo "Course department: ${dept_code^^} $dept_name" + echo "Course number: $course_num" + echo "Course name: $course_name" + echo "Scheduled days: $course_sched" + echo "Course start: $course_start" + echo "Course end: $course_end" + echo "Credit hours: $course_hours" + echo "Enrolled Students: $course_size" + +total.bash: + echo "Total course records: $count" + +update.bash: + read -p "Department code: " dept_code + read -p "Department name: " dept_name + read -p "Course number: " course_num + read -p "Course name: " course_name + read -p "Scheduled days: " course_sched + read -p "Course start: " course_start + read -p "Course end: " course_end + read -p "Credit hours: " course_hours + read -p "Enrolled students: " course_size + echo "ERROR: must provide a department code and course number" 1>&2 + echo "ERROR: course not found" diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/queries.log b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/queries.log new file mode 100644 index 0000000..379649d --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/data/queries.log @@ -0,0 +1 @@ +[Wed Jun 26 01:09:21 PM CDT 2024] DELETED: bio 2060 Human Anatomy and Physiology Laboratory II diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/delete.bash b/Summer-2024/CS-3424/Assignments/Assignment-1/src/delete.bash new file mode 100755 index 0000000..9896e94 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/delete.bash @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -eEuo pipefail + +delete_course() { + local data_dir="${1?No data directory provided to read courses from!}" + local dept_code + local course_num + local course_name + + read -r -p "Enter a department code and course number: " dept_code course_num + + local course_file="${data_dir}/${dept_code^^}${course_num}.crs" + if [[ ! -f "$course_file" ]]; then + err "course not found" + elif [[ ! -r "$course_file" ]]; then + err "lack permission to read ${course_file}" + fi + local linenr=0 + while read -r line; do + linenr="$((linenr + 1))" + if ((linenr == 2)); then + course_name="$line" + fi + done <"$course_file" + rm -f "$course_file" + + log "DELETED" "${dept_code} ${course_num} ${course_name}" + printf "%s %d was successfully deleted\n" "$dept_code" "$course_num" +} diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/enroll.bash b/Summer-2024/CS-3424/Assignments/Assignment-1/src/enroll.bash new file mode 100755 index 0000000..bb92ce4 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/enroll.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +set -eEuo pipefail diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/read.bash b/Summer-2024/CS-3424/Assignments/Assignment-1/src/read.bash new file mode 100755 index 0000000..e9dfacd --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/read.bash @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +set -eEuo pipefail + +export COURSE_DATA +declare -A COURSE_DATA + +_read_course() { + local data_dir="${1?No data directory provided to read courses from!}" + local dept_code="${2?No department code provided!}" + local course_num="${2?No course number provided!}" + local course="${dept_code^^}${course_num}" + + local dept_name + local course_name + local course_sched + local course_start + local course_end + local course_hours + local course_size + + local course_file="${data_dir}/${course}.crs" + + if [[ ! -f "$course_file" ]]; then + err "course not found" + return 1 + elif [[ ! -r "$course_file" ]]; then + err "course ${course} was found, but unable to read from its file" + return 1 + fi + + local linenr=0 + while read -r line; do + linenr="$((linenr + 1))" + if ((linenr == 1)); then + read -r dept_code dept_name <<<"$line" + elif ((linenr == 2)); then + read -r course_name <<<"$line" + elif ((linenr == 3)); then + read -r course_sched course_start course_end course_hours course_size <<<"$line" + else + err "unable to read ${course_file}, it has an invalid format!" + return 1 + fi + done <"$course_file" + + COURSE_DATA["dept_code"]="$dept_code" + COURSE_DATA["dept_code"]="$dept_code" + COURSE_DATA["dept_name"]="$dept_name" + COURSE_DATA["course_num"]="$course_num" + COURSE_DATA["course_name"]="$course_name" + COURSE_DATA["course_sched"]="$course_sched" + COURSE_DATA["course_start"]="$course_start" + COURSE_DATA["course_end"]="$course_end" + COURSE_DATA["course_hours"]="$course_hours" + COURSE_DATA["course_size"]="$course_size" +} + +read_course() { + local data_dir="${1?No data directory provided to read courses from!}" + local dept_code + local course_num + read -r -p "Enter a department code and course number: " dept_code course_num + + _read_course "$data_dir" "$dept_code" "$course_num" || return 0 + + printf "%s\n" "${COURSE_DATA[*]}" + + cat <<-__EOS__ + Course department: ${COURSE_DATA["dept_code"]} ${COURSE_DATA["dept_name"]} + Course number: ${COURSE_DATA["course_num"]} + Course name: ${COURSE_DATA["course_name"]} + Scheduled days: ${COURSE_DATA["course_sched"]} + Course start: ${COURSE_DATA["course_start"]} + Course end: ${COURSE_DATA["course_end"]} + Credit hours: ${COURSE_DATA["course_hours"]} + Enrolled Students: ${COURSE_DATA["course_size"]} + __EOS__ +} diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/total.bash b/Summer-2024/CS-3424/Assignments/Assignment-1/src/total.bash new file mode 100755 index 0000000..bb92ce4 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/total.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +set -eEuo pipefail diff --git a/Summer-2024/CS-3424/Assignments/Assignment-1/src/update.bash b/Summer-2024/CS-3424/Assignments/Assignment-1/src/update.bash new file mode 100755 index 0000000..a505527 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-1/src/update.bash @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -eEuo pipefail + +. ./read.bash + +_update_course() { + local data_dir="${1?No data directory provided to read courses from!}" + _read_course "$data_dir" "$dept_code" "$course_num" || return 0 + local dept_code="${2:-${COURSE_DATA["dept_code"]}}" + local dept_name="${3:-${COURSE_DATA["dept_name"]}}" + local course_num="${4:-${COURSE_DATA["course_num"]}}" + local course_name="${5:-${COURSE_DATA["course_name"]}}" + local course_sched="${6:-${COURSE_DATA["course_sched"]}}" + local course_start="${7:-${COURSE_DATA["course_start"]}}" + local course_end="${8:-${COURSE_DATA["course_end"]}}" + local course_hours="${9:-${COURSE_DATA["course_hours"]}}" + local course_size="${10:-${COURSE_DATA["course_size"]}}" + + cat <<-__EOS__ >"${data_dir}/${dept_code}${course_num}.crs" + ${dept_code} ${dept_name} + ${course_name} + ${course_sched} ${course_start} ${course_end} ${course_hours} ${course_size} + __EOS__ +} + +update_course() { + local data_dir="${1?No data directory provided to read courses from!}" + local dept_code + local dept_name + local course_num + local course_name + local course_sched + local course_start + local course_end + local course_hours + local course_size + + read -r -p "Department code: " dept_code + read -r -p "Department name: " dept_name + read -r -p "Course number: " course_num + read -r -p "Course name: " course_name + read -r -p "Scheduled days: " course_sched + read -r -p "Course start: " course_start + read -r -p "Course end: " course_end + read -r -p "Credit hours: " course_hours + read -r -p "Enrolled students: " course_size + +}