/1.0.0/src/ai/api/squirrel_export.sh

https://github.com/bodhi/OpenTTD · Shell · 113 lines · 88 code · 13 blank · 12 comment · 14 complexity · a0bc5e6322f799b67655e251b32fb0cd MD5 · raw file

  1. #!/bin/bash
  2. # $Id: squirrel_export.sh 17697 2009-10-04 18:16:44Z rubidium $
  3. # This file is part of OpenTTD.
  4. # OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
  5. # OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  6. # See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
  7. # Set neutral locale so sort behaves the same everywhere
  8. LC_ALL=C
  9. export LC_ALL
  10. # We really need gawk for this!
  11. AWK=gawk
  12. ${AWK} --version > /dev/null 2> /dev/null
  13. if [ "$?" != "0" ]; then
  14. echo "This script needs gawk to run properly"
  15. exit 1
  16. fi
  17. # This must be called from within the src/ai/api directory.
  18. if [ -z "$1" ]; then
  19. for f in `ls *.hpp`; do
  20. case "${f}" in
  21. # these files should not be changed by this script
  22. "ai_controller.hpp" | "ai_object.hpp" | "ai_types.hpp" | "ai_changelog.hpp" | "ai_info_docs.hpp" ) continue;
  23. esac
  24. ${AWK} -f squirrel_export.awk ${f} > ${f}.tmp
  25. if ! [ -f "${f}.sq" ] || [ -n "`diff -I '$Id' ${f}.tmp ${f}.sq 2> /dev/null || echo boo`" ]; then
  26. mv ${f}.tmp ${f}.sq
  27. echo "Updated: ${f}.sq"
  28. svn add ${f}.sq > /dev/null 2>&1
  29. svn propset svn:eol-style native ${f}.sq > /dev/null 2>&1
  30. svn propset svn:keywords Id ${f}.sq > /dev/null 2>&1
  31. else
  32. rm -f ${f}.tmp
  33. fi
  34. done
  35. else
  36. ${AWK} -f squirrel_export.awk $1 > $1.tmp
  37. if ! [ -f "${f}.sq" ] || [ -n "`diff -I '$Id' $1.sq $1.tmp 2> /dev/null || echo boo`" ]; then
  38. mv $1.tmp $1.sq
  39. echo "Updated: $1.sq"
  40. svn add $1.sq > /dev/null 2>&1
  41. svn propset svn:eol-style native $1.sq > /dev/null 2>&1
  42. svn propset svn:keywords Id $1.sq > /dev/null 2>&1
  43. else
  44. rm -f $1.tmp
  45. fi
  46. fi
  47. # Remove .hpp.sq if .hpp doesn't exist anymore
  48. for f in `ls *.hpp.sq`; do
  49. f=`echo ${f} | sed "s/.hpp.sq$/.hpp/"`
  50. if [ ! -f ${f} ];then
  51. echo "Deleted: ${f}.sq"
  52. svn del --force ${f}.sq > /dev/null 2>&1
  53. fi
  54. done
  55. # Add stuff to ai_instance.cpp
  56. f='../ai_instance.cpp'
  57. functions=``
  58. echo "
  59. { }
  60. /.hpp.sq/ { next }
  61. /squirrel_register_std/ { next }
  62. /SQAIController_Register/ { print \$0; next }
  63. /SQAI.*_Register/ { next }
  64. /Note: this line a marker in squirrel_export.sh. Do not change!/ {
  65. print \$0
  66. gsub(\"^.*/\", \"\")
  67. split(\"`grep '^void SQAI.*_Register(Squirrel \*engine)$' *.hpp.sq | sed 's/:.*$//' | sort | uniq | tr -d '\r' | tr '\n' ' '`\", files, \" \")
  68. for (i = 1; files[i] != \"\"; i++) {
  69. print \"#include \\\"api/\" files[i] \"\\\"\" \$0
  70. }
  71. next;
  72. }
  73. /\/\* Register all classes \*\// {
  74. print \$0
  75. gsub(\"^.*/\", \"\")
  76. print \" squirrel_register_std(this->engine);\" \$0
  77. split(\"`grep '^void SQAI.*_Register(Squirrel \*engine)$' *.hpp.sq | sed 's/^.*void //;s/Squirrel \*/this->/;s/$/;/;s/_Register/0000Register/g;' | sort | sed 's/0000Register/_Register/g' | tr -d '\r' | tr '\n' ' '`\", regs, \" \")
  78. for (i = 1; regs[i] != \"\"; i++) {
  79. if (regs[i] == \"SQAIController_Register(this->engine);\") continue
  80. print \" \" regs[i] \$0
  81. }
  82. next
  83. }
  84. { print \$0; }
  85. " > ${f}.awk
  86. ${AWK} -f ${f}.awk ${f} > ${f}.tmp
  87. if ! [ -f "${f}" ] || [ -n "`diff -I '$Id' ${f} ${f}.tmp 2> /dev/null || echo boo`" ]; then
  88. mv ${f}.tmp ${f}
  89. echo "Updated: ${f}"
  90. else
  91. rm -f ${f}.tmp
  92. fi
  93. rm -f ${f}.awk