setsize.sh 987 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. DEFAULT_R=30
  3. DEFAULT_C=60
  4. R=0
  5. C=0
  6. INPUT_FILE=definitions.hpp
  7. trap "rm $INPUT_FILE.tmp 2> /dev/null; exit -1" SIGINT SIGTERM
  8. if [[ $1 == "default" ]]; then
  9. sed s/"#define R [0-9]*"/"#define R $DEFAULT_R"/ <$INPUT_FILE >$INPUT_FILE.tmp
  10. sed s/"#define C [0-9]*"/"#define C $DEFAULT_C"/ <$INPUT_FILE.tmp >$INPUT_FILE
  11. rm $INPUT_FILE.tmp
  12. make clean
  13. make -j4
  14. exit 0
  15. elif [[ $# -gt 0 ]]; then echo Usage: $0 "[default]"; exit 1
  16. else
  17. echo Insert new Row number \(5-120\)
  18. until [[ $R -ge 5 && $R -le 120 ]]; do
  19. read R
  20. if [[ $R -lt 5 || $R -gt 120 ]]; then echo Invalid size.; fi
  21. echo New R will be $R
  22. done
  23. echo Insert new Column number \(5-120\)
  24. until [[ $C -ge 5 && $C -le 120 ]]; do
  25. read C
  26. if [[ $C -lt 5 || $C -gt 120 ]]; then echo Invalid size.; fi
  27. echo New C will be $C
  28. done
  29. sed s/"#define R [0-9]*"/"#define R $R"/ <$INPUT_FILE >$INPUT_FILE.tmp
  30. sed s/"#define C [0-9]*"/"#define C $C"/ <$INPUT_FILE.tmp >$INPUT_FILE
  31. rm $INPUT_FILE.tmp
  32. make clean
  33. make -j4
  34. fi