apply.rb

#!/bin/ruby

command = ARGV.shift

#TODO: create temporary file name
tmp = "hogess"

ARGV.each do |x|
    com = sprintf("%s %s > %s", command, x, tmp) 
    puts com
    system(com)
    com = sprintf("mv -f %s %s", tmp, x)
    system(com)
end

#
#!/usr/bin/env python

#import sys
#import os
#
#tmp = os.tempnam()
#
#for each in sys.argv[2:]:
    #print each
    #os.system("%s %s > %s" % (sys.argv[1], each, tmp))
    #os.system("mv -f %s %s" % (tmp, each))


#!/bin/ruby
# $Id: doxall.rb,v 1.1 2005/04/15 07:51:41 aosyou Exp $

# 実行には doxall.cfg が必要

begin
require 'fileutils'

$KCODE = "SJIS"


#===============================================================================
# 定数定義
#===============================================================================

PLAINFUNCTION = 0
CONSTRUCTOR = 1
DESTRUCTOR = 2
OTHERMETHOD = 3


# 定数を定義したあとにロードする
configFileName = "c:\\doxall.cfg"
load configFileName



#===============================================================================
# main
#===============================================================================

if ARGV.length == 0
targets = Dir.glob($targetSuffixes)
elsif FileTest.directory?(ARGV[0])
Dir.chdir(ARGV[0])
targets = Dir.glob($targetSuffixes)
else
targets = ARGV
end

targets.each do |filename|
# 出力用のテキストを保持するリスト
after =

=begin
# 念のためバックアップをとる
$bakdir = "bak" + Time.now.strftime("%H%M")
if $bakdir
if not FileTest.exist?($bakdir)
Dir.mkdir($bakdir)
end
FileUtils.cp(filename, $bakdir + "\\" + filename)
end
=end

f = open(filename, "r")
lines = f.readlines()

# 改行コードの問題のため、いったん改行を削除する
lines.each { |line| line.chomp! }

# 先頭5行を見て @file がなければ、fileComment を挿入する
if not hasFileComment?(lines)
after += makeFileComment(filename)
end

lines.each_with_index do |line, i|
$db.each do |entry|
if line =~ entry[0] # 登録してあるパターンにマッチするなら
#p entry[1]
after += entry[1]
elsif line =~ /^\s*class\s/
lineSplit = line.split
i = lineSplit.index("class")
className = lineSplit[i+1]
after += makeClassComment(className)
elsif function?(lines[i-1], line, lines[i+1])
ret = methodType(line)
case ret[0]
when CONSTRUCTOR
after += makeConstructorComment(ret[1])
when DESTRUCTOR
after += makeDestructorComment(ret[1])
when OTHERMETHOD, PLAINFUNCTION
after += makeMethodComment(line)
end
end
end
after.push(line)
end

f.close

# 出力
f = open(filename, "wb")
after.each do |line|
f.puts line + "\r\n" # 改行コードを CRLF にして出力
end
f.close
end

rescue
f = open("errorlog.txt", "w")
f.puts $!
f.close
end

#!/usr/bin/ruby

# この doxall.cfg は必ず c:\ においてください

# doxall の使い方:
# エクスプローラでファイル(複数可)を doxall.exe にドロップ



#===============================================================================
# カスタマイズは以下の Ruby コードを直接変更してください。
#===============================================================================

# ソースファイルの拡張子。 "\0" で区切って複数指定可能
$targetSuffixes = "*.cpp\0*.cc\0*.h\0*.c"

# ファイルの先頭につけるコメントを返す
def makeFileComment(filename)
comment = [
"/*============================================================================*/",
"/*!",
" @file #{filename}",
" @brief ",
" @author 製作者",
" @date #{Time.now.strftime("%Y-%m-%d")}",
" @par [説明]",
" ここに細かな説明文を書く。更新日など。",
"*/",
"/*============================================================================*/",
""
]
return comment
end

# クラスのコメントを返す
def makeClassComment(className)
comment = [
"/*============================================================================*/",
"/*!",
" @class #{className}",
" @brief ",
" @par [説明]",
"   ここにクラスの説明を書く。",
"*/",
"/*============================================================================*/",
]
return comment
end

# コンストラクタにつけるコメントを返す
def makeConstructorComment(className)
comment = [
"/*============================================================================*/",
"/*!",
" @brief コンストラクタ",
" @par 説明",
"*/",
"/*============================================================================*/",
]
return comment
end

# デストラクタにつけるコメントを返す
def makeDestructorComment(className)
comment = [
"/*============================================================================*/",
"/*!",
" @brief デストラクタ",
" @par 説明",
"*/",
"/*============================================================================*/",
]
return comment
end

# メンバ関数につけるコメントを返す
def makeMethodComment(className)
comment = [
"/*============================================================================*/",
"/*!",
" @class #{className}",
" @brief ",
" @par 説明",
]

bracket = line.scan(/\(.*\)/)
innerBracket = bracket[0][1...-1] # ( ) の中身

fields = innerBracket.split(',')

params = fields.collect do |x|
#ポインタの * を型名にくっつける
x.gsub!(/\*\s*/, '* ')
x.gsub!(/\s*\*/, '*')

x.gsub!(/\[.*\]/, '') # を消去
x.split()[-1] # 空白で区切った最後が仮引数名
end

width = params.collect {|x| x.length}.max

params.each do |x|
if x != '...' # 可変長引数の '...' は除く
comment.push(' @param ' + x + ' '*(width-x.length+1))
end
end

rettype = line.split[0]
if rettype == 'void'
comment.push(' @return なし')
else
comment.push(' @return ')
end

comment += [
"*/",
"/*============================================================================*/",
]

return comment
end


#===============================================================================
# Advanced
# より詳細なカスタマイズをしたい人向け
#===============================================================================

# 関数名のある行を受け取り、その関数のタイプとクラス名を返す
def methodType(line)
if line.index("::")
className, methodName = line.gsub(/\(.*/, "").split(/::/)
if className == methodName
return [CONSTRUCTOR, className]
elsif '~' + className == methodName
return [DESTRUCTOR, className]
else
return [OTHERMETHOD, className]
end
else
return [PLAINFUNCTION, nil] # メンバ関数でない関数の場合はclassNameにnil
end
end


# ファイルの先頭に @file があるか判定
# lines : ソースファイル全体 (行の配列)
def hasFileComment?(lines)
for i in lines[0..5]
if i =~ /@file/
return true
end
end
return false
end

# 与えられた行が関数定義であるか判定する
def function?(prevline, line, nextline)
if line =~ /^[A-Za-z_].*\)\s*$/ and nextline =~ /^\{/ and prevline =~ /^\s*$/
return true
else
return false
end
end

# 特別なパターンとコメントの組を登録する
$db = []
$db.push([/^class CAboutDlg : public CDialog/, makeClassComment("「バージョン情報」のダイアログ")])