From 6b285d3fd87cdb14d12d4d835bacd86283aa0b9e Mon Sep 17 00:00:00 2001 From: victor Date: Sat, 20 Nov 2004 14:24:23 +0000 Subject: add "cdoc" (just like javadoc) to grab prototype and comments of functions git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2344 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- docs/proto/Makefile | 18 +++++++++++++ docs/proto/cdoc | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 docs/proto/Makefile create mode 100755 docs/proto/cdoc (limited to 'docs') diff --git a/docs/proto/Makefile b/docs/proto/Makefile new file mode 100644 index 00000000..63086b38 --- /dev/null +++ b/docs/proto/Makefile @@ -0,0 +1,18 @@ + +#.SUFFIXES: .c .txt + +# XXX 這有沒有比較好的作法? +# 直接用 .c.txt 好像會先去看目前目錄有沒有 xxx.c @_@ + +NAME!= cd ../../mbbsd/ && ls *.c | sed -e "s/\.c//" +SRC!= cd ../../mbbsd/ && ls *.c | sed -e "s/\.c/.txt/" + +all: $(SRC) + +.for fn in $(NAME) +$(fn).txt: ../../mbbsd/$(fn).c + ./cdoc ../../mbbsd/$(fn).c > $(fn).txt +.endfor + +clean: + rm -f *.txt diff --git a/docs/proto/cdoc b/docs/proto/cdoc new file mode 100755 index 00000000..e9403589 --- /dev/null +++ b/docs/proto/cdoc @@ -0,0 +1,75 @@ +#!/usr/bin/perl + +# follow javadoc +# @see http://java.sun.com/j2se/javadoc/writingdoccomments/ + +use strict; + +=cut + +oӵ{iHq C {XACXҦ statis/non-static functionsC +C function eiH javadoc-style ѡCdҦpUG + +/** + * Function of the function func. + * @param x variable, if there are more than one @-style description, it + * will end with the next @-style description. + * @return void + */ +void func(int x) +{ + ... +} +=cut + +my $content; + +foreach my $f (@ARGV) { + makedoc($f); +} + + +sub grep_desc +{ + my $name = '\w+'; + my $type = '\w+\s*\*?'; + my $sentence = '.*'; + + my $one_desc = "$name\\s+$sentence"; + my $desc_head = "\\/\\*\\*\n"; + my $desc_tail = "\\s*\\*\\/\n"; + my $desc_line = "\\s*\\*.*\n"; + my $paramdesc = "\@param\\s+$one_desc(?:\n$desc_line)*"; + my $returndesc = "\@return\\s+$sentence(?:\n$desc_line)*"; + my $seedesc = "\@see\\s+$sentence(?:\n$desc_line)*"; + my $desc = "$desc_head(?:$desc_line)*$desc_tail"; + + my $modifier = '(?:static|inline)\\s+'; + my $one_param = "$type\\s*$name"; + my $more_param = ",\\s*$one_param"; + my $param = "(?:$one_param(?:$more_param)*)?"; + my $func_proto = "(?:$modifier)?$type\\s+$name\\($param\\)"; + + $content =~ s/($desc_head(?:$desc_line)*$desc_tail)?($func_proto)\s*{//mo + or return undef; + my $comment = $1; + my $function = $2; + $function =~ s/\n/ /g; + $function =~ s/\s+/ /g; + + # check comment style here + + return "$function;\n".($comment ? $comment : "/* no comment */\n"); +} + +sub makedoc +{ + $_ = shift @_; + open SRC, "<$_"; + $content = join "",; + close SRC; + print "/* vim:ft=c */\n\n"; + while ($_ = grep_desc()) { + print "$_\n"; + } +} -- cgit v1.2.3