#! /bin/bash
# Last edited on 2023-01-29 22:09:35 by stolfi

# Runs on an {svn}-managed directory. Writes to ".status" a cleaned
# report of the {svn} status of the directory,
# 
# Each line of this file has only two fields, the situation character
# and the file name. The situation charavter of tracked and unchanged
# files is "Z" instead of blank.
#
# The ".status" files excludes many untracked files that are not
# supposed to be tracked, like ".o" and ".ho" objects, "JUNK" and "SAVE"
# directories, binary executables (obtained from "~/binaries.dir"),
# dot-files, files called "*rename*.sed", etc. These excluded files are
# listed in ".status-bad".

dir="${PWD/${HOME}\//}"
echo "dir=${dir}" 1>&2

cat ${HOME}/binaries.dir \
  | egrep -e "^${dir}" \
  | sed -e "s:^${dir}/:? :g" \
  | sed -e 's:  *$::g' \
  | sort | uniq \
  > .bins-all

svn status -v \
  | sed -e 's:^[ \011]:Z:g' \
  | gawk '//{ st = $1; fn = $(NF); print st, fn; }' \
  | sort \
  > .status-all
  
cat .status-all \
  | egrep -v -e '^[?] .*([.](ho|o|a|)|/Deps.make|Makefile_cratera)$' \
  | egrep -v -e '^[?] .*/(JUNK|OLD|SAVE)' \
  | egrep -v -e '^[?] (|.*/)[.][a-zA-Z][-_.a-zA-Z0-9]*$' \
  | egrep -v -e '^[?] .*rename.*.sed$' \
  | egrep -v -e '^[?] .*/out/.*[.](ppm|pgm|pbm|png|jpg|gif|fni|eps|ps|pdf|plt|txt)' \
  | egrep -v -e '^[?] .*/out/.*[.](cdv|oct|eqs|plot|his|dat|stl|tom)' \
  | bool 1-2 - .bins-all \
  > .status
   
cat  .status-all \
  | bool 1.2 - .bins-all \
  | sort \
  > .status-bins
 
cat  .status-all \
  | bool 1-2 - .status \
  | bool 1-2 - .bins-all \
  | revbytes | sort | revbytes \
  > .status-bad
  
