Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. # doxygenはソース中の改行を空白一文字に変換してしまう。
  2. # 日本語でドキュメントを書いている場合は
  3. # これによって文章中に余計な空白が追加されることになって嬉しくない。
  4. #
  5. # このinput_filterは、
  6. # //!という行形式のコメントが連続するドキュメントに対して、最後の行以外に<br>を付加する
  7. # /*! */または/** */という複数行形式のドキュメント対して、
  8. # (先頭行/最後の行/空白行)以外に<br>を付加する。
  9. # また、先頭行が/*!あるいは/**だけではなくテキストが存在している場合は先頭行にも<br>を付加する
  10. #
  11. # いまの実装だと、複数行形式のコメントを一行で書いてある場合や、
  12. # 行の先頭位置以外からコメントが開始しているようなソースで不具合が起こる。
  13.  
  14. debug_mode=0
  15.  
  16. if [[ $1 = "--debug" ]]; then
  17. debug_mode=1
  18. shift
  19. fi
  20.  
  21. echo() {
  22. if [[ $1 = -n ]]; then
  23. shift
  24. printf '%s' "$*"
  25. else
  26. printf '%s\n' "$*"
  27. fi
  28. }
  29.  
  30. echo_debug() {
  31. if [ $debug_mode -eq 1 ] ; then
  32. echo "$*"
  33. fi
  34. }
  35.  
  36. # ファイルの読み込み
  37. OriginalIFS=$IFS
  38. IFS=
  39.  
  40. lines=()
  41. eof=
  42.  
  43. while [ -z "$eof" ] ; do
  44. read line || eof=true
  45. lines+=("$line")
  46. done < $1
  47.  
  48. # while read -r line
  49. # do
  50. # echo_debug "read line $line"
  51. # lines+=("$line")
  52. # done < $1
  53.  
  54. edited_lines=()
  55. num_lines=${#lines[*]}
  56.  
  57. my_trim() {
  58. trimmed_string=`echo "$1" | awk '{gsub(/^[[:blank:]]*/,"");print}' | awk '{gsub(/[[:blank:]]*$/,"");print}'`
  59. # ここのechoにダブルクオーテーション忘れないようにする。
  60. echo "$trimmed_string"
  61. }
  62.  
  63. i=0
  64. while [ $i -lt $num_lines ] ; do
  65.  
  66. line=${lines[$i]}
  67.  
  68. # trimming leading and trailing spaces
  69. trimmed_line=`my_trim "${lines[$i]}"`
  70.  
  71. echo_debug "trimmed line at head : $trimmed_line"
  72.  
  73. if [ `echo "$trimmed_line" | grep "^//!"` ] ; then
  74. echo_debug "Step into inline comment"
  75.  
  76. in_inline_comment=0
  77.  
  78. while [ $i -lt $num_lines ] ; do
  79. echo_debug "index of i: $i"
  80.  
  81. line=${lines[$i]}
  82. trimmed_line=`my_trim "$line"`
  83.  
  84. echo_debug "current line : $line"
  85.  
  86. if [ ! `echo "$trimmed_line" | grep "^//!"` ] ; then
  87. # 行コメント終了
  88. # このインデックスでまた外側のループから処理開始
  89. echo_debug "Step out inline comment"
  90. break
  91. fi
  92.  
  93. if [ $in_inline_comment -eq 1 ] ; then
  94. num_edited_lines=${#edited_lines[*]}
  95.  
  96. if [ $num_edited_lines -ne 0 ] ; then
  97. last_index=`expr $i - 1`
  98. if [ ! `echo "${edited_lines[$last_index]}" | grep ".*<br>$"` ] ; then
  99. edited_lines[$last_index]="${edited_lines[$last_index]}<br>"
  100. fi
  101. fi
  102.  
  103. fi
  104.  
  105. in_inline_comment=1
  106.  
  107. echo_debug "Add line in inline comment $line"
  108. edited_lines+=("$line")
  109.  
  110. i=`expr $i + 1`
  111. done
  112.  
  113. elif [[ `echo "$trimmed_line" | grep -e "^/\*[\*\!]"` ]] ; then
  114.  
  115. echo_debug "Step into multiline comment"
  116.  
  117. in_multiline_comment=0
  118.  
  119. while [ $i -lt $num_lines ] ; do
  120.  
  121. line=${lines[$i]}
  122. trimmed_line=`my_trim "$line"`
  123.  
  124. echo_debug "current line : $line"
  125. echo_debug "trimmed line : $trimmed_line"
  126.  
  127. if [[ `echo "$trimmed_line" | grep '\*/'` ]] ; then
  128. # この行はそのまま追加して、次のインデックスで外側のループから処理開始
  129. # 複数行コメントがこの行で終わっているかもしれない
  130. # もしくは、この行の先頭が//!で始まっているかもしれない。
  131. edited_lines+=("$line")
  132. i=`expr $i + 1`
  133. echo_debug "Step out multiline comment"
  134. break
  135. fi
  136.  
  137. # "/*!"や"/**"の行でかつその行に空白以外の文字が後続している場合<br>を付加する
  138. # 中間の行でかつその行に空白と連続する*以外の文字が含まれている場合<br>を付加する
  139.  
  140. should_add_break=0
  141. if [ $in_multiline_comment -eq 0 ] ; then
  142. if [[ `echo "$trimmed_line" | awk '/^\/\*(\*|\!)[[:space:]]*[^\*]+/'` ]] ; then
  143. echo_debug "text in comment header"
  144. should_add_break=1
  145. fi
  146. in_multiline_comment=1
  147. else
  148. if [ ! `echo "$trimmed_line" | grep '/^\**$/'` ] ; then
  149. echo_debug "text in middle of comment"
  150. should_add_break=1
  151. fi
  152. fi
  153.  
  154. echo_debug "Add line in multiline comment $line"
  155. if [ $should_add_break -eq 1 ] ; then
  156. if [ ! `echo "$line" | grep ".*<br>$"` ] ; then
  157. edited_lines+=("$line<br>")
  158. fi
  159. else
  160. edited_lines+=("$line")
  161. fi
  162.  
  163. i=`expr $i + 1`
  164. done
  165. else
  166. echo_debug "current line : $line"
  167.  
  168. edited_lines+=("$line")
  169. i=`expr $i + 1`
  170. fi
  171. done
  172.  
  173. for line in "${edited_lines[@]}" ; do
  174. echo "$line"
  175. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement