[patch] kernel-doc: fixes and enhancements

From: Tim Waugh (twaugh@redhat.com)
Date: Wed Apr 05 2000 - 08:54:39 EST


Here is take 3 of my patch for scripts/kernel-doc. This is the last
chance for someone to say something about this patch before I send it to
Linus..

- function pointers in parameter lists now works
- &struct struct_name now works
- quoted words are marked up <quoted></> in DocBook
- function names referred to in descriptive text doesn't have parenths
- use DocBook v3.1's <constant> tag for constants

Tim.
*/

Index: linux/scripts/kernel-doc
diff -u linux/scripts/kernel-doc:1.1.1.3 linux/scripts/kernel-doc:1.3
--- linux/scripts/kernel-doc:1.1.1.3 Wed Mar 29 09:56:00 2000
+++ linux/scripts/kernel-doc Wed Apr 5 14:49:00 2000
@@ -76,15 +76,15 @@
 #
 # 'funcname()' - function
 # '$ENVVAR' - environmental variable
-# '&struct_name' - name of a structure
+# '&struct_name' - name of a structure (up to two words including 'struct')
 # '@parameter' - name of a parameter
 # '%CONST' - name of a constant.
 
 # match expressions used to find embedded type information
-$type_constant = "\\\%(\\w+)";
-$type_func = "(\\w+\\(\\))";
+$type_constant = "\\\%([-\\w]+)";
+$type_func = "(\\w+)\\(\\)";
 $type_param = "\\\@(\\w+)";
-$type_struct = "\\\&(\\w+)";
+$type_struct = "\\\&((struct\\s*)?\\w+)";
 $type_env = "(\\\$\\w+)";
 
 
@@ -99,7 +99,8 @@
 $blankline_html = "<p>";
 
 # sgml, docbook format
-%highlights_sgml = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
+%highlights_sgml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
+ $type_constant, "<constant>\$1</constant>",
                      $type_func, "<function>\$1</function>",
                      $type_struct, "<structname>\$1</structname>",
                      $type_env, "<envar>\$1</envar>",
@@ -258,7 +259,13 @@
     print "(";
     $count = 0;
     foreach $parameter (@{$args{'parameterlist'}}) {
- print "<i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
+ $type = $args{'parametertypes'}{$parameter};
+ if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
+ # pointer-to-function
+ print "<i>$1</i> <b>$parameter</b>) <i>($2)</i>\n";
+ } else {
+ print "<i>".$type."</i> <b>".$parameter."</b>\n";
+ }
         if ($count != $#{$args{'parameterlist'}}) {
             $count++;
             print ", ";
@@ -339,8 +346,15 @@
     $count = 0;
     if ($#{$args{'parameterlist'}} >= 0) {
         foreach $parameter (@{$args{'parameterlist'}}) {
- print " <paramdef>".$args{'parametertypes'}{$parameter};
- print " <parameter>$parameter</parameter></paramdef>\n";
+ $type = $args{'parametertypes'}{$parameter};
+ if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
+ # pointer-to-function
+ print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
+ print " <funcparams>$2</funcparams></paramdef>\n";
+ } else {
+ print " <paramdef>".$type;
+ print " <parameter>$parameter</parameter></paramdef>\n";
+ }
         }
     } else {
         print " <void>\n";
@@ -438,8 +452,15 @@
     $count = 0;
     if ($#{$args{'parameterlist'}} >= 0) {
         foreach $parameter (@{$args{'parameterlist'}}) {
- print " <paramdef>".$args{'parametertypes'}{$parameter};
- print " <parameter>$parameter</parameter></paramdef>\n";
+ $type = $args{'parametertypes'}{$parameter};
+ if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
+ # pointer-to-function
+ print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
+ print " <funcparams>$2</funcparams></paramdef>\n";
+ } else {
+ print " <paramdef>".$type;
+ print " <parameter>$parameter</parameter></paramdef>\n";
+ }
         }
     } else {
         print " <void>\n";
@@ -524,7 +545,15 @@
     print "(\n";
     $count = 0;
     foreach $parameter (@{$args{'parameterlist'}}) {
- print ".I \"".$args{'parametertypes'}{$parameter}."\"\n.B \"".$parameter."\"\n";
+ $type = $args{'parametertypes'}{$parameter};
+ if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
+ # pointer-to-function
+ print ".I \"".$1."\"\n";
+ print ".B \"".$parameter."\"\n";
+ print ".I \"".$2."\"\n";
+ } else {
+ print ".I \"".$type."\"\n.B \"".$parameter."\"\n";
+ }
         if ($count != $#{$args{'parameterlist'}}) {
             $count++;
             print ",\n";
@@ -565,7 +594,13 @@
     print "Function = ".$args{'function'}."\n";
     print " return type: ".$args{'functiontype'}."\n\n";
     foreach $parameter (@{$args{'parameterlist'}}) {
- print " ".$args{'parametertypes'}{$parameter}." ".$parameter."\n";
+ $type = $args{'parametertypes'}{$parameter};
+ if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
+ # pointer-to-function
+ print " ".$1." ".$parameter.") ".$2."\n";
+ } else {
+ print " ".$type." ".$parameter."\n";
+ }
         print " -> ".$args{'parameters'}{$parameter}."\n";
     }
     foreach $section (@{$args{'sectionlist'}}) {
@@ -614,32 +649,46 @@
     $prototype =~ s/^inline+ //;
     $prototype =~ s/^__inline__+ //;
 
- if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
- $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
- $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
- $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
- $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/) {
+ if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
+ $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
+ $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
+ $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
+ $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
         $return_type = $1;
         $function_name = $2;
         $args = $3;
 
+ # allow for up to fours args to function pointers
+ $args =~ s/(\([^\),]+),/\1#/;
+ $args =~ s/(\([^\),]+),/\1#/;
+ $args =~ s/(\([^\),]+),/\1#/;
 # print STDERR "ARGS = '$args'\n";
 
         foreach $arg (split ',', $args) {
             # strip leading/trailing spaces
             $arg =~ s/^\s*//;
             $arg =~ s/\s*$//;
-# print STDERR "SCAN ARG: '$arg'\n";
- @args = split('\s', $arg);
 
-# print STDERR " -> @args\n";
- $param = pop @args;
-# print STDERR " -> @args\n";
- if ($param =~ m/^(\*+)(.*)/) {
- $param = $2;
- push @args, $1;
+ if ($arg =~ m/\(/) {
+ # pointer-to-function
+ $arg =~ tr/#/,/;
+ $arg =~ m/[^\(]+\(\*([^\)]+)\)/;
+ $param = $1;
+ $type = $arg;
+ $type =~ s/([^\(]+\(\*)$param/\1/;
+ } else {
+# print STDERR "SCAN ARG: '$arg'\n";
+ @args = split('\s', $arg);
+
+# print STDERR " -> @args\n";
+ $param = pop @args;
+# print STDERR " -> @args\n";
+ if ($param =~ m/^(\*+)(.*)/) {
+ $param = $2;
+ push @args, $1;
+ }
+ $type = join " ", @args;
             }
- $type = join " ", @args;
 
             if ($type eq "" && $param eq "...")
             {

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Apr 07 2000 - 21:00:14 EST