diff --git a/Tools/portbuild/scripts/dopackagestats b/Tools/portbuild/scripts/dopackagestats
index 88ba1e26ef55..7aab8e26415a 100755
--- a/Tools/portbuild/scripts/dopackagestats
+++ b/Tools/portbuild/scripts/dopackagestats
@@ -18,6 +18,9 @@ THCOLOR="#E0E0FF"
TDCOLOR_DONE="lightgreen"
TDCOLOR_NOT_DONE="lightyellow"
+# subroutines
+
+write_header () {
echo "" > ${TMPFILE}
echo "
" >> ${TMPFILE}
echo "FreeBSD package building statistics" >> ${TMPFILE}
@@ -26,10 +29,9 @@ echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "FreeBSD package building statistics
" >> ${TMPFILE}
echo "as of `date`
" >> ${TMPFILE}
+}
-for arch in ${SUPPORTED_ARCHS}; do
-
- # begin table
+write_table_begin () {
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo " | " >> ${TMPFILE}
@@ -41,13 +43,13 @@ for arch in ${SUPPORTED_ARCHS}; do
echo "missing | " >> ${TMPFILE}
echo "done? | " >> ${TMPFILE}
echo "
" >> ${TMPFILE}
+}
- # begin row
- branches=`ls ${ROOT_DIRECTORY}/${arch} | grep '^[1-9]$' | sort`
- for branch in ${branches}; do
-
+write_row () {
# first, gather data
+ arch=$1
+ branch=$2
directory=${ROOT_DIRECTORY}/${arch}/${branch}
if [ "$branch" = "4" ]; then
indexfile=$directory/ports/INDEX
@@ -130,14 +132,14 @@ for arch in ${SUPPORTED_ARCHS}; do
echo "$n_missing | " >> ${TMPFILE}
echo "$done_flag | " >> ${TMPFILE}
echo "" >> ${TMPFILE}
+}
- done
-
+write_table_end () {
echo "
" >> ${TMPFILE}
echo "
" >> ${TMPFILE}
+}
-done
-
+write_footer () {
echo "explanation of columns:
" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "- as of is the date of the latest logfile.
" >> ${TMPFILE}
@@ -151,5 +153,23 @@ echo "
" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
+}
+
+# main
+
+write_header
+
+for arch in ${SUPPORTED_ARCHS}; do
+ write_table_begin
+
+ branches=`ls ${ROOT_DIRECTORY}/${arch} | grep '^[1-9]$' | sort`
+ for branch in ${branches}; do
+ write_row ${arch} ${branch}
+ done
+
+ write_table_end
+done
+
+write_footer
mv -f ${TMPFILE} ${OUTFILE}