gen-template.sh 1003 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. #set -v
  3. rm -f templates/*.bak templates/*.tmp
  4. mkdir -p doc
  5. list="$*"
  6. [[ $list = "" ]] && list="$(/bin/ls templates/)"
  7. awkprog='
  8. /@@MODULE\(.*\)@@/ {
  9. gsub(/@@MODULE\(/,"templates/module/");
  10. gsub(/\)@@/,"");
  11. system("cat " $0);
  12. next
  13. }
  14. /@@EXEC\(.*\)@@/ {
  15. gsub(/@@EXEC\(/,"");
  16. gsub(/\)@@\r?/,"");
  17. system($0);
  18. #print;
  19. next
  20. }
  21. { print $0 }
  22. '
  23. CRLF=0
  24. uname -s | grep -q CYGWIN && CRLF=1
  25. for fname in $list
  26. do
  27. src="setup/$fname"
  28. [[ -f $src ]] || src="templates/$fname"
  29. if [[ -f "$src" ]]
  30. then
  31. dest="doc/$fname"
  32. ext="${dest##*.}"
  33. #[[ $ext == edit-list ]] && continue
  34. [[ $ext = "sh" || $ext = "bat" || $ext = "h" ]] && dest="$fname"
  35. [[ $fname = "INSTALL.txt" ]] && dest="$fname"
  36. #echo "|$src|$dest|"
  37. if ((CRLF)) && [[ $ext = bat || $ext = txt ]]
  38. then
  39. awk "$awkprog" $src | sed -f templates.sed | sed 's/$/\r/' >$dest
  40. else
  41. awk "$awkprog" $src | sed -f templates.sed >$dest
  42. fi
  43. [[ $ext = "sh" ]] && chmod a+x "$fname"
  44. fi
  45. done
  46. exit 0