ncu-indent 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/sh
  2. #****************************************************************************
  3. #* Copyright (c) 2001-2006,2008 Thomas E. Dickey *
  4. #* *
  5. #* Permission is hereby granted, free of charge, to any person obtaining a *
  6. #* copy of this software and associated documentation files (the *
  7. #* "Software"), to deal in the Software without restriction, including *
  8. #* without limitation the rights to use, copy, modify, merge, publish, *
  9. #* distribute, distribute with modifications, sublicense, and/or sell *
  10. #* copies of the Software, and to permit persons to whom the Software is *
  11. #* furnished to do so, subject to the following conditions: *
  12. #* *
  13. #* The above copyright notice and this permission notice shall be included *
  14. #* in all copies or substantial portions of the Software. *
  15. #* *
  16. #* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  17. #* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  18. #* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  19. #* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  20. #* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  21. #* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  22. #* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  23. #* *
  24. #* Except as contained in this notice, the name(s) of the above copyright *
  25. #* holders shall not be used in advertising or otherwise to promote the *
  26. #* sale, use or other dealings in this Software without prior written *
  27. #* authorization. *
  28. #****************************************************************************/
  29. # $Id: ncu-indent,v 1.17 2008/08/03 15:46:44 tom Exp $
  30. NOOP=no
  31. OPTS='
  32. --blank-lines-after-procedures
  33. --braces-on-if-line
  34. --continuation-indentation0
  35. --continue-at-parentheses
  36. --cuddle-else
  37. --indent-level4
  38. --leave-preprocessor-space
  39. --no-blank-lines-after-commas
  40. --no-blank-lines-after-declarations
  41. --no-space-after-function-call-names
  42. --procnames-start-lines
  43. --space-special-semicolon
  44. --swallow-optional-blank-lines
  45. --tab-size8
  46. -T NCURSES_EXPORT_VAR
  47. -T NCURSES_INLINE
  48. -T SCREEN
  49. -T TERMTYPE
  50. -T attr_t
  51. -T cchar_t
  52. -T chtype
  53. -T inline
  54. -T wchar_t
  55. -T wint_t
  56. -T BUFFER
  57. -T CHARTYPE
  58. -T FILE
  59. -T GCC_NORETURN
  60. -T LINE
  61. -T MARK
  62. -T RETSIGTYPE
  63. -T TBUFF
  64. -T WINDOW
  65. -T size_t
  66. -T va_list
  67. -T Cardinal
  68. -T Widget
  69. -T XtPointer
  70. '
  71. for name in $*
  72. do
  73. case $name in
  74. -v|-n)
  75. NOOP=yes
  76. OPTS="$OPTS -v"
  77. ;;
  78. -*)
  79. OPTS="$OPTS $name"
  80. ;;
  81. *.[ch]|*.cc|*.cpp)
  82. save="${name}".a$$
  83. test="${name}".b$$
  84. rm -f "$save" "$test"
  85. mv "$name" "$save"
  86. sed \
  87. -e '/EMPTY_MODULE(/s/)$/);/' \
  88. -e '/MODULE_ID(/s/)$/);/' \
  89. -e 's,\<GCC_NORETURN;,;//GCC_NORETURN;,' \
  90. -e 's,\<GCC_PRINTFLIKE(,;//GCC_PRINTFLIKE(,' \
  91. -e 's,\<GCC_SCANFLIKE(,;//GCC_SCANFLIKE(,' \
  92. -e 's,\(\<NCURSES_EXPORT_VAR\>\),//\1,' \
  93. "$save" >"$test"
  94. cp "$test" "$name"
  95. chmod u+w "$name"
  96. # ${INDENT_PROG-indent} --version
  97. ${INDENT_PROG-indent} -npro $OPTS "$name"
  98. sed \
  99. -e '/EMPTY_MODULE(/s/);$/)/' \
  100. -e '/MODULE_ID(/s/);$/)/' \
  101. -e 's,;[ ]*//GCC_NORETURN;, GCC_NORETURN;,' \
  102. -e 's,;[ ]*//GCC_PRINTFLIKE(, GCC_PRINTFLIKE(,' \
  103. -e 's,;[ ]*//GCC_SCANFLIKE(, GCC_SCANFLIKE(,' \
  104. -e 's,//\(\<NCURSES_EXPORT_VAR\>\),\1,' \
  105. "$name" >"$test"
  106. mv "$test" "$name"
  107. rm -f "${name}~"
  108. if test $NOOP = yes ; then
  109. if (cmp -s "$name" "$save" ) then
  110. echo "** no change: $name"
  111. else
  112. diff -u "$save" "$name"
  113. fi
  114. rm -f "$name"
  115. mv "$save" "$name"
  116. elif ( cmp -s "$name" "$save" ) ; then
  117. echo "** unchanged $name"
  118. rm -f "${name}"
  119. mv "$save" "$name"
  120. else
  121. echo "** updated $name"
  122. rm -f "$save"
  123. fi
  124. ;;
  125. *)
  126. echo "** ignored: $name"
  127. ;;
  128. esac
  129. done