kernel-doc (7c9aa0157ef4b4cc28c98b08a971dc8344e64aab) kernel-doc (8ad72163165265b686902c182c1b4a913e738a81)
1#!/usr/bin/env perl
2
3use warnings;
4use strict;
5
6## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
7## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
8## Copyright (C) 2001 Simon Huggins ##

--- 197 unchanged lines hidden (view full) ---

206my $errors = 0;
207my $warnings = 0;
208my $anon_struct_union = 0;
209
210# match expressions used to find embedded type information
211my $type_constant = '\b``([^\`]+)``\b';
212my $type_constant2 = '\%([-_\w]+)';
213my $type_func = '(\w+)\(\)';
1#!/usr/bin/env perl
2
3use warnings;
4use strict;
5
6## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
7## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
8## Copyright (C) 2001 Simon Huggins ##

--- 197 unchanged lines hidden (view full) ---

206my $errors = 0;
207my $warnings = 0;
208my $anon_struct_union = 0;
209
210# match expressions used to find embedded type information
211my $type_constant = '\b``([^\`]+)``\b';
212my $type_constant2 = '\%([-_\w]+)';
213my $type_func = '(\w+)\(\)';
214my $type_param = '\@(\w+(\.\.\.)?)';
214my $type_param = '\@(\w*(\.\w+)*(\.\.\.)?)';
215my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
216my $type_env = '(\$\w+)';
217my $type_enum = '\&(enum\s*([_\w]+))';
218my $type_struct = '\&(struct\s*([_\w]+))';
219my $type_typedef = '\&(typedef\s*([_\w]+))';
220my $type_union = '\&(union\s*([_\w]+))';
221my $type_member = '\&([_\w]+)(\.|->)([_\w]+)';
222my $type_fallback = '\&([_\w]+)';

--- 442 unchanged lines hidden (view full) ---

665 my %args = %{$_[0]};
666 my ($parameter, $section);
667
668 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
669
670 print ".SH NAME\n";
671 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
672
215my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
216my $type_env = '(\$\w+)';
217my $type_enum = '\&(enum\s*([_\w]+))';
218my $type_struct = '\&(struct\s*([_\w]+))';
219my $type_typedef = '\&(typedef\s*([_\w]+))';
220my $type_union = '\&(union\s*([_\w]+))';
221my $type_member = '\&([_\w]+)(\.|->)([_\w]+)';
222my $type_fallback = '\&([_\w]+)';

--- 442 unchanged lines hidden (view full) ---

665 my %args = %{$_[0]};
666 my ($parameter, $section);
667
668 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
669
670 print ".SH NAME\n";
671 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
672
673 my $declaration = $args{'definition'};
674 $declaration =~ s/\t/ /g;
675 $declaration =~ s/\n/"\n.br\n.BI \"/g;
673 print ".SH SYNOPSIS\n";
674 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
676 print ".SH SYNOPSIS\n";
677 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
678 print ".BI \"$declaration\n};\n.br\n\n";
675
679
676 foreach my $parameter (@{$args{'parameterlist'}}) {
677 if ($parameter =~ /^#/) {
678 print ".BI \"$parameter\"\n.br\n";
679 next;
680 }
681 my $parameter_name = $parameter;
682 $parameter_name =~ s/\[.*//;
683
684 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
685 $type = $args{'parametertypes'}{$parameter};
686 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
687 # pointer-to-function
688 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
689 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
690 # bitfield
691 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
692 } else {
693 $type =~ s/([^\*])$/$1 /;
694 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
695 }
696 print "\n.br\n";
697 }
698 print "};\n.br\n";
699
700 print ".SH Members\n";
701 foreach $parameter (@{$args{'parameterlist'}}) {
702 ($parameter =~ /^#/) && next;
703
704 my $parameter_name = $parameter;
705 $parameter_name =~ s/\[.*//;
706
707 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;

--- 220 unchanged lines hidden (view full) ---

928 print "\n\n.. c:type:: " . $name . "\n\n";
929 print_lineno($declaration_start_line);
930 $lineprefix = " ";
931 output_highlight_rst($args{'purpose'});
932 print "\n";
933
934 print "**Definition**\n\n";
935 print "::\n\n";
680 print ".SH Members\n";
681 foreach $parameter (@{$args{'parameterlist'}}) {
682 ($parameter =~ /^#/) && next;
683
684 my $parameter_name = $parameter;
685 $parameter_name =~ s/\[.*//;
686
687 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;

--- 220 unchanged lines hidden (view full) ---

908 print "\n\n.. c:type:: " . $name . "\n\n";
909 print_lineno($declaration_start_line);
910 $lineprefix = " ";
911 output_highlight_rst($args{'purpose'});
912 print "\n";
913
914 print "**Definition**\n\n";
915 print "::\n\n";
936 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
937 foreach $parameter (@{$args{'parameterlist'}}) {
938 if ($parameter =~ /^#/) {
939 print " " . "$parameter\n";
940 next;
941 }
916 my $declaration = $args{'definition'};
917 $declaration =~ s/\t/ /g;
918 print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n";
942
919
943 my $parameter_name = $parameter;
944 $parameter_name =~ s/\[.*//;
945
946 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
947 $type = $args{'parametertypes'}{$parameter};
948 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
949 # pointer-to-function
950 print " $1 $parameter) ($2);\n";
951 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
952 # bitfield
953 print " $1 $parameter$2;\n";
954 } else {
955 print " " . $type . " " . $parameter . ";\n";
956 }
957 }
958 print " };\n\n";
959
960 print "**Members**\n\n";
961 $lineprefix = " ";
962 foreach $parameter (@{$args{'parameterlist'}}) {
963 ($parameter =~ /^#/) && next;
964
965 my $parameter_name = $parameter;
966 $parameter_name =~ s/\[.*//;
967

--- 77 unchanged lines hidden (view full) ---

1045 my $file = shift;
1046 my $nested;
1047
1048 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1049 my $decl_type = $1;
1050 $declaration_name = $2;
1051 my $members = $3;
1052
920 print "**Members**\n\n";
921 $lineprefix = " ";
922 foreach $parameter (@{$args{'parameterlist'}}) {
923 ($parameter =~ /^#/) && next;
924
925 my $parameter_name = $parameter;
926 $parameter_name =~ s/\[.*//;
927

--- 77 unchanged lines hidden (view full) ---

1005 my $file = shift;
1006 my $nested;
1007
1008 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1009 my $decl_type = $1;
1010 $declaration_name = $2;
1011 my $members = $3;
1012
1053 # ignore embedded structs or unions
1054 $members =~ s/({.*})//g;
1055 $nested = $1;
1056
1057 # ignore members marked private:
1058 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
1059 $members =~ s/\/\*\s*private:.*//gosi;
1060 # strip comments:
1061 $members =~ s/\/\*.*?\*\///gos;
1013 # ignore members marked private:
1014 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
1015 $members =~ s/\/\*\s*private:.*//gosi;
1016 # strip comments:
1017 $members =~ s/\/\*.*?\*\///gos;
1062 $nested =~ s/\/\*.*?\*\///gos;
1063 # strip attributes
1064 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
1065 $members =~ s/__aligned\s*\([^;]*\)//gos;
1066 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
1067 # replace DECLARE_BITMAP
1068 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
1069 # replace DECLARE_HASHTABLE
1070 $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos;
1071 # replace DECLARE_KFIFO
1072 $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
1073 # replace DECLARE_KFIFO_PTR
1074 $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
1075
1018 # strip attributes
1019 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
1020 $members =~ s/__aligned\s*\([^;]*\)//gos;
1021 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
1022 # replace DECLARE_BITMAP
1023 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
1024 # replace DECLARE_HASHTABLE
1025 $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos;
1026 # replace DECLARE_KFIFO
1027 $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
1028 # replace DECLARE_KFIFO_PTR
1029 $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
1030
1031 my $declaration = $members;
1032
1033 # Split nested struct/union elements as newer ones
1034 my $cont = 1;
1035 while ($cont) {
1036 $cont = 0;
1037 while ($members =~ m/(struct|union)([^{};]+){([^{}]*)}([^{}\;]*)\;/) {
1038 my $newmember = "$1 $4;";
1039 my $id = $4;
1040 my $content = $3;
1041 $id =~ s/[:\[].*//;
1042 $id =~ s/^\*+//;
1043 foreach my $arg (split /;/, $content) {
1044 next if ($arg =~ m/^\s*$/);
1045 my $type = $arg;
1046 my $name = $arg;
1047 $type =~ s/\s\S+$//;
1048 $name =~ s/.*\s//;
1049 $name =~ s/[:\[].*//;
1050 $name =~ s/^\*+//;
1051 next if (($name =~ m/^\s*$/));
1052 if ($id =~ m/^\s*$/) {
1053 # anonymous struct/union
1054 $newmember .= "$type $name;";
1055 } else {
1056 $newmember .= "$type $id.$name;";
1057 }
1058 }
1059 $members =~ s/(struct|union)([^{};]+){([^{}]*)}([^{}\;]*)\;/$newmember/;
1060 $cont = 1;
1061 };
1062 };
1063
1064 # Ignore other nested elements, like enums
1065 $members =~ s/({[^\{\}]*})//g;
1066 $nested = $decl_type;
1067 $nested =~ s/\/\*.*?\*\///gos;
1068
1076 create_parameterlist($members, ';', $file);
1077 check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual, $nested);
1078
1069 create_parameterlist($members, ';', $file);
1070 check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual, $nested);
1071
1072 # Adjust declaration for better display
1073 $declaration =~ s/([{;])/$1\n/g;
1074 $declaration =~ s/}\s+;/};/g;
1075 # Better handle inlined enums
1076 do {} while ($declaration =~ s/(enum\s+{[^}]+),([^\n])/$1,\n$2/);
1077
1078 my @def_args = split /\n/, $declaration;
1079 my $level = 1;
1080 $declaration = "";
1081 foreach my $clause (@def_args) {
1082 $clause =~ s/^\s+//;
1083 $clause =~ s/\s+$//;
1084 $clause =~ s/\s+/ /;
1085 next if (!$clause);
1086 $level-- if ($clause =~ m/(})/ && $level > 1);
1087 if (!($clause =~ m/^\s*#/)) {
1088 $declaration .= "\t" x $level;
1089 }
1090 $declaration .= "\t" . $clause . "\n";
1091 $level++ if ($clause =~ m/({)/ && !($clause =~m/}/));
1092 }
1079 output_declaration($declaration_name,
1080 'struct',
1081 {'struct' => $declaration_name,
1082 'module' => $modulename,
1093 output_declaration($declaration_name,
1094 'struct',
1095 {'struct' => $declaration_name,
1096 'module' => $modulename,
1097 'definition' => $declaration,
1083 'parameterlist' => \@parameterlist,
1084 'parameterdescs' => \%parameterdescs,
1085 'parametertypes' => \%parametertypes,
1086 'sectionlist' => \@sectionlist,
1087 'sections' => \%sections,
1088 'purpose' => $declaration_purpose,
1089 'type' => $decl_type
1090 });

--- 994 unchanged lines hidden ---
1098 'parameterlist' => \@parameterlist,
1099 'parameterdescs' => \%parameterdescs,
1100 'parametertypes' => \%parametertypes,
1101 'sectionlist' => \@sectionlist,
1102 'sections' => \%sections,
1103 'purpose' => $declaration_purpose,
1104 'type' => $decl_type
1105 });

--- 994 unchanged lines hidden ---