#!/bin/sh -u # $0 pathname # Compile a program (the only argument) as C or C++ based on its contents. # Display the errors/warnings with line numbers. # -IAN! idallen@ncf.ca # This is standard for shell scripts in this course. # export PATH=/bin:/usr/bin umask 022 # 6 marks # Validate the number of arguments; issue a good error message. # if [ $# -ne 1 ]; then echo 1>&2 "$0: Expecting 1 argument; found $# ($*)" exit 1 fi # 2 marks # Transfer the argument to a named variable for better readability. # cprog="$1" # Verify that the argument is a non-empty, readable file. # # 5 marks if [ ! -f "$cprog" ]; then echo 1>&2 "$0: '$cprog' is not a file" exit 1 fi # 5 marks if [ ! -r "$cprog" ]; then echo 1>&2 "$0: '$cprog' is not readable" exit 1 fi # 5 marks if [ ! -s "$cprog" ]; then echo 1>&2 "$0: '$cprog' is empty" exit 1 fi # 2 marks # Create an error file. Start by putting the date into it. # date >myerrs.txt || exit $? # 8 marks # Select the C compiler if a string is found indicating a C program. # if grep '/dev/null ; then gcc -o mycout -Wall "$cprog" 2>>myerrs.txt fi # 8 marks # Select the C++ compiler if the following string is *not* found. # if ! grep 'printf(' "$cprog" >/dev/null ; then g++ -o mycppout -Wall "$cprog" 2>>myerrs.txt fi # 9 marks # Remove an error file containing no errors. # Rename and display with line numbers any errors. # if [ $(wc -l