summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-11-20 22:24:23 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-11-20 22:24:23 +0800
commit6b285d3fd87cdb14d12d4d835bacd86283aa0b9e (patch)
treeea91b09c7ad99e4d1555b5e93537658dac3bd3ee /docs
parentc28b22f9df8800338a59bc7c793255d4cccf4506 (diff)
downloadpttbbs-6b285d3fd87cdb14d12d4d835bacd86283aa0b9e.tar
pttbbs-6b285d3fd87cdb14d12d4d835bacd86283aa0b9e.tar.gz
pttbbs-6b285d3fd87cdb14d12d4d835bacd86283aa0b9e.tar.bz2
pttbbs-6b285d3fd87cdb14d12d4d835bacd86283aa0b9e.tar.lz
pttbbs-6b285d3fd87cdb14d12d4d835bacd86283aa0b9e.tar.xz
pttbbs-6b285d3fd87cdb14d12d4d835bacd86283aa0b9e.tar.zst
pttbbs-6b285d3fd87cdb14d12d4d835bacd86283aa0b9e.zip
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
Diffstat (limited to 'docs')
-rw-r--r--docs/proto/Makefile18
-rwxr-xr-xdocs/proto/cdoc75
2 files changed, 93 insertions, 0 deletions
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 "",<SRC>;
+ close SRC;
+ print "/* vim:ft=c */\n\n";
+ while ($_ = grep_desc()) {
+ print "$_\n";
+ }
+}