[patch] kernel-doc and pointers-to-functions in arg lists

From: Tim Waugh (twaugh@redhat.com)
Date: Mon Apr 03 2000 - 04:38:25 EST


Further to my mail at the weekend, here is a patch for kernel-doc that I
think fixes the issue with pointers-to-functions.

This patch properly extracts the parameter name and its type for a
pointer-to-function parameter, and also adds support for output in the
various formats defined (I don't understand what the difference between
output_gnome and output_sgml is).

I haven't worked out how '!E' and '!I' work yet though -- can anyone
enlighten me?

Tim.
*/

Index: linux/scripts/kernel-doc
diff -u linux/scripts/kernel-doc:1.1.1.3 linux/scripts/kernel-doc:1.2
--- linux/scripts/kernel-doc:1.1.1.3 Wed Mar 29 09:56:00 2000
+++ linux/scripts/kernel-doc Mon Apr 3 10:10:36 2000
@@ -82,7 +82,7 @@
 
 # match expressions used to find embedded type information
 $type_constant = "\\\%(\\w+)";
-$type_func = "(\\w+\\(\\))";
+$type_func = "(\\w+)\\(\\)";
 $type_param = "\\\@(\\w+)";
 $type_struct = "\\\&(\\w+)";
 $type_env = "(\\\$\\w+)";
@@ -103,7 +103,8 @@
                      $type_func, "<function>\$1</function>",
                      $type_struct, "<structname>\$1</structname>",
                      $type_env, "<envar>\$1</envar>",
- $type_param, "<parameter>\$1</parameter>" );
+ $type_param, "<parameter>\$1</parameter>",
+ "\\\"([^\\\"]+)\\\"", "<quote>\$1</quote>" );
 $blankline_sgml = "</para><para>\n";
 
 # gnome, docbook format
@@ -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:09 EST