diff --git a/sys/kern/makedevops.pl b/sys/kern/makedevops.pl index 295286206d60..46a2e05fc1e6 100644 --- a/sys/kern/makedevops.pl +++ b/sys/kern/makedevops.pl @@ -198,7 +198,6 @@ foreach $src ( @filenames ) { if ( $line =~ m/^$/ ) { # skip empty lines # nop - } elsif ( $line =~ m/^INTERFACE\s*([^\s;]*)(\s*;?)/i ) { $intname = $1; $semicolon = $2; @@ -222,7 +221,6 @@ foreach $src ( @filenames ) { if $hfile; print CFILE '#include "'.$intname.'_if.h"'."\n\n" if $cfile; - } elsif ( $line =~ m/^CODE\s*{$/i ) { $code = ""; $line = ; @@ -249,7 +247,7 @@ foreach $src ( @filenames ) { $lineno++ } if ( $hfile ) { - print HFILLE $header; + print HFILE $header; } } elsif ( $line =~ m/^(STATIC|)METHOD/i ) { # Get the return type function name and delete that from @@ -351,9 +349,9 @@ foreach $src ( @filenames ) { # the method description print HFILE "extern struct device_op_desc $mname\_desc;\n"; # the method typedef - print HFILE &format_line("typedef $ret $mname\_t($arguments);", - $line_width, ', ', - ',',' ' x length("typedef $ret $mname\_t(")) + my $prototype = "typedef $ret $mname\_t("; + print HFILE &format_line("$prototype$arguments);", + $line_width, ', ', ',',' ' x length($prototype)) . "\n"; # the method declaration print HFILE "$mname\_t $umname;\n\n"; @@ -370,9 +368,10 @@ foreach $src ( @filenames ) { print CFILE "$ret $umname($varnames)\n"; print CFILE "\t".join(";\n\t", @arguments).";\n"; } else { - print CFILE &format_line("$ret $umname($arguments)", - $line_width, ', ', - ',', ' ' x length("$ret $umname(")) . "\n"; + my $prototype = "$ret $umname("; + print CFILE &format_line("$prototype$arguments)", + $line_width, ', ', ',', ' ' x length($prototype)) + . "\n"; } print CFILE "{\n"; if ($static) { diff --git a/sys/kern/makeobjops.pl b/sys/kern/makeobjops.pl index 951c9df513b5..b99844521fff 100644 --- a/sys/kern/makeobjops.pl +++ b/sys/kern/makeobjops.pl @@ -52,34 +52,34 @@ $line_width = 80; # Process the command line # -while ( $arg = shift @ARGV ) { - if ( $arg eq '-c' ) { +while ($arg = shift @ARGV) { + if ($arg eq '-c') { warn "Producing .c output files" if $debug; $cfile = 1; - } elsif ( $arg eq '-h' ) { + } elsif ($arg eq '-h') { warn "Producing .h output files" if $debug; $hfile = 1; - } elsif ( $arg eq '-ch' || $arg eq '-hc' ) { + } elsif ($arg eq '-ch' || $arg eq '-hc') { warn "Producing .c and .h output files" if $debug; $cfile = 1; $hfile = 1; - } elsif ( $arg eq '-d' ) { + } elsif ($arg eq '-d') { $debug = 1; - } elsif ( $arg eq '-p' ) { + } elsif ($arg eq '-p') { warn "Will produce files in original not in current directory" if $debug; $keepcurrentdir = 0; - } elsif ( $arg eq '-l' ) { - if ( $line_width = shift @ARGV and $line_width > 0 ) { + } elsif ($arg eq '-l') { + if ($line_width = shift @ARGV and $line_width > 0) { warn "Line width set to $line_width" if $debug; } else { die "Please specify a valid line width after -l"; } - } elsif ( $arg =~ m/\.m$/ ) { + } elsif ($arg =~ m/\.m$/) { warn "Filename: $arg" if $debug; push @filenames, $arg; @@ -99,337 +99,335 @@ where -c produce only .c files -l set line width for output files [80] -d switch on debugging " - unless ($cfile or $hfile) + unless ($cfile or $hfile) and $#filenames != -1; # FIXME should be able to do this more easily # $tmpdir = $ENV{'TMPDIR'}; # environment variables $tmpdir = $ENV{'TMP'} - if !$tmpdir; + if !$tmpdir; $tmpdir = $ENV{'TEMP'} - if !$tmpdir; + if !$tmpdir; $tmpdir = '/tmp' # look for a physical directory - if !$tmpdir and -d '/tmp'; + if !$tmpdir and -d '/tmp'; $tmpdir = '/usr/tmp' - if !$tmpdir and -d '/usr/tmp'; + if !$tmpdir and -d '/usr/tmp'; $tmpdir = '/var/tmp' - if !$tmpdir and -d '/var/tmp'; + if !$tmpdir and -d '/var/tmp'; $tmpdir = '.' # give up and use current dir - if !$tmpdir; + if !$tmpdir; -foreach $src ( @filenames ) { - # Names of the created files - $ctmpname = "$tmpdir/ctmp.$$"; - $htmpname = "$tmpdir/htmp.$$"; +foreach $src (@filenames) { + # Names of the created files + $ctmpname = "$tmpdir/ctmp.$$"; + $htmpname = "$tmpdir/htmp.$$"; - ($name, $path, $suffix) = &fileparse($src, '.m'); - $path = '.' - if $keepcurrentdir; - $cfilename="$path/$name.c"; - $hfilename="$path/$name.h"; + ($name, $path, $suffix) = &fileparse($src, '.m'); + $path = '.' + if $keepcurrentdir; + $cfilename="$path/$name.c"; + $hfilename="$path/$name.h"; - warn "Processing from $src to $cfilename / $hfilename via $ctmpname / $htmpname" - if $debug; + warn "Processing from $src to $cfilename / $hfilename via $ctmpname / $htmpname" + if $debug; - die "Could not open $src, $!" - if !open SRC, "$src"; - die "Could not open $ctmpname, $!" - if $cfile and !open CFILE, ">$ctmpname"; - die "Could not open $htmpname, $!" - if $hfile and !open HFILE, ">$htmpname"; + die "Could not open $src, $!" + if !open SRC, "$src"; + die "Could not open $ctmpname, $!" + if $cfile and !open CFILE, ">$ctmpname"; + die "Could not open $htmpname, $!" + if $hfile and !open HFILE, ">$htmpname"; - if ($cfile) { - # Produce the header of the C file - # - print CFILE "/*\n"; - print CFILE " * This file is produced automatically.\n"; - print CFILE " * Do not modify anything in here by hand.\n"; - print CFILE " *\n"; - print CFILE " * Created from source file\n"; - print CFILE " * $src\n"; - print CFILE " * with\n"; - print CFILE " * $0\n"; - print CFILE " *\n"; - print CFILE " * See the source file for legal information\n"; - print CFILE " */\n"; - print CFILE "\n"; - print CFILE "#include \n"; - print CFILE "#include \n"; - print CFILE "#include \n"; - print CFILE "#include \n"; - } + if ($cfile) { + # Produce the header of the C file + # + print CFILE "/*\n"; + print CFILE " * This file is produced automatically.\n"; + print CFILE " * Do not modify anything in here by hand.\n"; + print CFILE " *\n"; + print CFILE " * Created from source file\n"; + print CFILE " * $src\n"; + print CFILE " * with\n"; + print CFILE " * $0\n"; + print CFILE " *\n"; + print CFILE " * See the source file for legal information\n"; + print CFILE " */\n"; + print CFILE "\n"; + print CFILE "#include \n"; + print CFILE "#include \n"; + print CFILE "#include \n"; + print CFILE "#include \n"; + } - if ($hfile) { - # Produce the header of the H file - # - print HFILE "/*\n"; - print HFILE " * This file is produced automatically.\n"; - print HFILE " * Do not modify anything in here by hand.\n"; - print HFILE " *\n"; - print HFILE " * Created from source file\n"; - print HFILE " * $src\n"; - print HFILE " * with\n"; - print HFILE " * $0\n"; - print HFILE " *\n"; - print HFILE " * See the source file for legal information\n"; - print HFILE " */\n"; - print HFILE "\n"; - } + if ($hfile) { + # Produce the header of the H file + # + print HFILE "/*\n"; + print HFILE " * This file is produced automatically.\n"; + print HFILE " * Do not modify anything in here by hand.\n"; + print HFILE " *\n"; + print HFILE " * Created from source file\n"; + print HFILE " * $src\n"; + print HFILE " * with\n"; + print HFILE " * $0\n"; + print HFILE " *\n"; + print HFILE " * See the source file for legal information\n"; + print HFILE " */\n"; + print HFILE "\n"; + } - %methods = (); # clear list of methods - @mnames = (); - @defaultmethods = (); - $lineno = 0; - $error = 0; # to signal clean up and gerror setting + %methods = (); # clear list of methods + @mnames = (); + @defaultmethods = (); + $lineno = 0; + $error = 0; # to signal clean up and gerror setting - LINE: - while ( $line = ) { - $lineno++; - - # take special notice of include directives. - # - if ( $line =~ m/^#\s*include\s+(["<])([^">]+)([">]).*/i ) { + LINE: while ($line = ) { + $lineno++; + + # take special notice of include directives. + # + if ($line =~ m/^#\s*include\s+(["<])([^">]+)([">]).*/i) { warn "Included file: $1$2" . ($1 eq '<'? '>':'"') - if $debug; + if $debug; print CFILE "#include $1$2" . ($1 eq '<'? '>':'"') . "\n" - if $cfile; - } - - $line =~ s/#.*//; # remove comments - $line =~ s/^\s+//; # remove leading ... - $line =~ s/\s+$//; # remove trailing whitespace - - if ( $line =~ m/^$/ ) { # skip empty lines - # nop - - } elsif ( $line =~ m/^INTERFACE\s*([^\s;]*)(\s*;?)/i ) { - $intname = $1; - $semicolon = $2; - unless ( $intname =~ m/^[a-z_][a-z0-9_]*$/ ) { - warn $line - if $debug; - warn "$src:$lineno: Invalid interface name '$intname', use [a-z_][a-z0-9_]*"; - $error = 1; - last LINE; - } - - warn "$src:$lineno: semicolon missing at end of line, no problem" - if $semicolon !~ s/;$//; - - warn "Interface $intname" - if $debug; - - print HFILE '#ifndef _'.$intname."_if_h_\n" - if $hfile; - print HFILE '#define _'.$intname."_if_h_\n\n" - if $hfile; - print CFILE '#include "'.$intname.'_if.h"'."\n\n" - if $cfile; - } elsif ( $line =~ m/^CODE\s*{$/i ) { - $code = ""; - $line = ; - $line =~ m/^(\s*)/; - $indent = $1; # find the indent used - while ( $line !~ m/^}/ ) { - $line =~ s/^$indent//g; # remove the indent - $code .= $line; - $line = ; - $lineno++ - } - if ($cfile) { - print CFILE "\n".$code."\n"; - } - } elsif ( $line =~ m/^HEADER\s*{$/i ) { - $header = ""; + if $cfile; + } + + $line =~ s/#.*//; # remove comments + $line =~ s/^\s+//; # remove leading ... + $line =~ s/\s+$//; # remove trailing whitespace + + if ($line =~ m/^$/) { # skip empty lines + # nop + } elsif ($line =~ m/^INTERFACE\s*([^\s;]*)(\s*;?)/i) { + $intname = $1; + $semicolon = $2; + unless ($intname =~ m/^[a-z_][a-z0-9_]*$/) { + warn $line + if $debug; + warn "$src:$lineno: Invalid interface name '$intname', use [a-z_][a-z0-9_]*"; + $error = 1; + last LINE; + } + + warn "$src:$lineno: semicolon missing at end of line, no problem" + if $semicolon !~ s/;$//; + + warn "Interface $intname" + if $debug; + + print HFILE '#ifndef _'.$intname."_if_h_\n" + if $hfile; + print HFILE '#define _'.$intname."_if_h_\n\n" + if $hfile; + print CFILE '#include "'.$intname.'_if.h"'."\n\n" + if $cfile; + } elsif ($line =~ m/^CODE\s*{$/i) { + $code = ""; + $line = ; + $line =~ m/^(\s*)/; + $indent = $1; # find the indent used + while ($line !~ m/^}/) { + $line =~ s/^$indent//g; # remove the indent + $code .= $line; $line = ; - $line =~ m/^(\s*)/; - $indent = $1; # find the indent used - while ( $line !~ m/^}/ ) { + $lineno++ + } + print CFILE "\n".$code."\n" + if $cfile; + } elsif ($line =~ m/^HEADER\s*{$/i) { + $header = ""; + $line = ; + $line =~ m/^(\s*)/; + $indent = $1; # find the indent used + while ($line !~ m/^}/) { $line =~ s/^$indent//g; # remove the indent $header .= $line; $line = ; $lineno++ } - if ($hfile) { - print HFILE $header; - } - } elsif ( $line =~ m/^(STATIC|)METHOD/i ) { - # Get the return type function name and delete that from - # the line. What is left is the possibly first function argument - # if it is on the same line. - # - if ( !$intname ) { - warn "$src:$lineno: No interface name defined"; - $error = 1; - last LINE; - } - $line =~ s/^(STATIC|)METHOD\s+([^\{]+?)\s*\{\s*//i; - $static = $1; - @ret = split m/\s+/, $2; - $name = pop @ret; # last element is name of method - $ret = join(" ", @ret); # return type - - warn "Method: name=$name return type=$ret" - if $debug; - - if ( !$name or !$ret ) { - warn $line - if $debug; - warn "$src:$lineno: Invalid method specification"; - $error = 1; - last LINE; - } - - unless ( $name =~ m/^[a-z_][a-z_0-9]*$/ ) { - warn $line - if $debug; - warn "$src:$lineno: Invalid method name '$name', use [a-z_][a-z0-9_]*"; - $error = 1; - last LINE; - } - - if ( defined($methods{$name}) ) { - warn "$src:$lineno: Duplicate method name"; - $error = 1; - last LINE; - } - - $methods{$name} = $name; - push @mnames, $name; - - while ( $line !~ m/}/ and $line .= ) { - $lineno++ - } - - $default = ""; - if ( $line !~ s/};?(.*)// ) { # remove first '}' and trailing garbage - # The '}' was not there (the rest is optional), so complain - warn "$src:$lineno: Premature end of file"; - $error = 1; - last LINE; - } - $extra = $1; - if ( $extra =~ /\s*DEFAULT\s*([a-zA-Z_][a-zA-Z_0-9]*)\s*;/ ) { - $default = $1; - } else { - warn "$src:$lineno: Ignored '$1'" # warn about garbage at end of line - if $debug and $1; - } - - # Create a list of variables without the types prepended - # - $line =~ s/^\s+//; # remove leading ... - $line =~ s/\s+$//; # ... and trailing whitespace - $line =~ s/\s+/ /g; # remove double spaces - - @arguments = split m/\s*;\s*/, $line; - @varnames = (); # list of varnames - foreach $argument (@arguments) { - next # skip argument if argument is empty - if !$argument; + print HFILE $header + if $hfile; + } elsif ($line =~ m/^(STATIC|)METHOD/i) { + # Get the return type function name and delete that from + # the line. What is left is the possibly first function argument + # if it is on the same line. + # + if (!$intname) { + warn "$src:$lineno: No interface name defined"; + $error = 1; + last LINE; + } + $line =~ s/^(STATIC|)METHOD\s+([^\{]+?)\s*\{\s*//i; + $static = $1; + @ret = split m/\s+/, $2; + $name = pop @ret; # last element is name of method + $ret = join(" ", @ret); # return type - @ar = split m/[*\s]+/, $argument; - if ( $#ar == 0 ) { # only 1 word in argument? - warn "$src:$lineno: no type for '$argument'"; - $error = 1; - last LINE; - } - - push @varnames, $ar[-1]; # last element is name of variable - }; - - warn 'Arguments: ' . join(', ', @arguments) . "\n" - . 'Varnames: ' . join(', ', @varnames) - if $debug; - - $mname = $intname.'_'.$name; # method name - $umname = uc($mname); # uppercase method name - - $arguments = join(", ", @arguments); - $firstvar = $varnames[0]; - $varnames = join(", ", @varnames); - - $default = "0" if $default eq ""; - push @defaultmethods, $default; - - if ($hfile) { - # the method description - print HFILE "extern struct kobjop_desc $mname\_desc;\n"; - # the method typedef - print HFILE &format_line("typedef $ret $mname\_t($arguments);", - $line_width, ', ', - ',',' ' x length("typedef $ret $mname\_t(")) - . "\n"; - } - - if ($cfile) { - # Print out the method desc - print CFILE "struct kobjop_desc $mname\_desc = {\n"; - print CFILE "\t0, (kobjop_t) $default\n"; - print CFILE "};\n\n"; - } - - if ($hfile) { - # Print out the method itself - if (0) { # haven't chosen the format yet - print HFILE "static __inline $ret $umname($varnames)\n"; - print HFILE "\t".join(";\n\t", @arguments).";\n"; - } else { - print HFILE &format_line("static __inline $ret $umname($arguments)", - $line_width, ', ', - ',', ' ' x length("$ret $umname(")) . "\n"; - } - print HFILE "{\n"; - print HFILE "\tkobjop_t _m;\n"; - if ( $static ) { - print HFILE "\tKOBJOPLOOKUP($firstvar->ops,$mname);\n"; - } else { - print HFILE "\tKOBJOPLOOKUP(((kobj_t)$firstvar)->ops,$mname);\n"; - } - print HFILE "\t"; - if ($ret ne 'void') { - print HFILE "return "; - } - print HFILE "(($mname\_t *) _m)($varnames);\n"; - print HFILE "}\n\n"; - } -} else { - warn $line - if $debug; - warn "$src:$lineno: Invalid line encountered"; - $error = 1; - last LINE; -} -} # end LINE + warn "Method: name=$name return type=$ret" + if $debug; -# print the final '#endif' in the header file -# -print HFILE "#endif /* _".$intname."_if_h_ */\n" - if $hfile; + if (!$name or !$ret) { + warn $line + if $debug; + warn "$src:$lineno: Invalid method specification"; + $error = 1; + last LINE; + } -close SRC; -close CFILE - if $cfile; -close HFILE - if $hfile; + unless ($name =~ m/^[a-z_][a-z_0-9]*$/) { + warn $line + if $debug; + warn "$src:$lineno: Invalid method name '$name', use [a-z_][a-z0-9_]*"; + $error = 1; + last LINE; + } -if ( !$error ) { - if ($cfile) { - ($rc = system("mv $ctmpname $cfilename")) - and warn "mv $ctmpname $cfilename failed, $rc"; + if (defined($methods{$name})) { + warn "$src:$lineno: Duplicate method name"; + $error = 1; + last LINE; + } + + $methods{$name} = $name; + push @mnames, $name; + + while ($line !~ m/}/ and $line .= ) { + $lineno++ + } + + $default = ""; + if ($line !~ s/};?(.*)//) { # remove first '}' and trailing garbage + # The '}' was not there (the rest is optional), so complain + warn "$src:$lineno: Premature end of file"; + $error = 1; + last LINE; + } + $extra = $1; + if ($extra =~ /\s*DEFAULT\s*([a-zA-Z_][a-zA-Z_0-9]*)\s*;/) { + $default = $1; + } else { + warn "$src:$lineno: Ignored '$1'" # warn about garbage at end of line + if $debug and $1; + } + + # Create a list of variables without the types prepended + # + $line =~ s/^\s+//; # remove leading ... + $line =~ s/\s+$//; # ... and trailing whitespace + $line =~ s/\s+/ /g; # remove double spaces + + @arguments = split m/\s*;\s*/, $line; + @varnames = (); # list of varnames + foreach $argument (@arguments) { + next # skip argument if argument is empty + if !$argument; + + @ar = split m/[*\s]+/, $argument; + if ($#ar == 0) { # only 1 word in argument? + warn "$src:$lineno: no type for '$argument'"; + $error = 1; + last LINE; + } + + push @varnames, $ar[-1]; # last element is name of variable + }; + + warn 'Arguments: ' . join(', ', @arguments) . "\n" + . 'Varnames: ' . join(', ', @varnames) + if $debug; + + $mname = $intname.'_'.$name; # method name + $umname = uc($mname); # uppercase method name + + $arguments = join(", ", @arguments); + $firstvar = $varnames[0]; + $varnames = join(", ", @varnames); + + $default = "0" if $default eq ""; + push @defaultmethods, $default; + + if ($hfile) { + # the method description + print HFILE "extern struct kobjop_desc $mname\_desc;\n"; + # the method typedef + my $prototype = "typedef $ret $mname\_t("; + print HFILE &format_line("$prototype$arguments);", + $line_width, ', ', + ',',' ' x length($prototype)) + . "\n"; + } + + if ($cfile) { + # Print out the method desc + print CFILE "struct kobjop_desc $mname\_desc = {\n"; + print CFILE "\t0, (kobjop_t) $default\n"; + print CFILE "};\n\n"; + } + + if ($hfile) { + # Print out the method itself + if (0) { # haven't chosen the format yet + print HFILE "static __inline $ret $umname($varnames)\n"; + print HFILE "\t".join(";\n\t", @arguments).";\n"; + } else { + my $prototype = "static __inline $ret $umname("; + print HFILE &format_line("$prototype$arguments)", + $line_width, ', ', + ',', ' ' x length($prototype)) . "\n"; + } + print HFILE "{\n"; + print HFILE "\tkobjop_t _m;\n"; + if ($static) { + print HFILE "\tKOBJOPLOOKUP($firstvar->ops,$mname);\n"; + } else { + print HFILE "\tKOBJOPLOOKUP(((kobj_t)$firstvar)->ops,$mname);\n"; + } + print HFILE "\t"; + if ($ret ne 'void') { + print HFILE "return "; + } + print HFILE "(($mname\_t *) _m)($varnames);\n"; + print HFILE "}\n\n"; + } + } else { + warn $line + if $debug; + warn "$src:$lineno: Invalid line encountered"; + $error = 1; + last LINE; + } + } # end LINE + + # print the final '#endif' in the header file + # + print HFILE "#endif /* _".$intname."_if_h_ */\n" + if $hfile; + + close SRC; + close CFILE + if $cfile; + close HFILE + if $hfile; + + if (!$error) { + if ($cfile) { + ($rc = system("mv $ctmpname $cfilename")) + and warn "mv $ctmpname $cfilename failed, $rc"; + } + + if ($hfile) { + ($rc = system("mv $htmpname $hfilename")) + and warn "mv $htmpname $hfilename failed, $rc"; + } + } else { + warn 'Output skipped'; + ($rc = system("rm -f $htmpname $ctmpname")) + and warn "rm -f $htmpname $ctmpname failed, $rc"; + $gerror = 1; } - - if ($hfile) { - ($rc = system("mv $htmpname $hfilename")) - and warn "mv $htmpname $hfilename failed, $rc"; - } -} else { - warn 'Output skipped'; - ($rc = system("rm -f $htmpname $ctmpname")) - and warn "rm -f $htmpname $ctmpname failed, $rc"; - $gerror = 1; -} } exit $gerror; @@ -438,13 +436,13 @@ exit $gerror; sub format_line { my ($line, $maxlength, $break, $new_end, $new_start) = @_; my $rline = ""; - - while ( length($line) > $maxlength - and ($i = rindex $line, $break, $maxlength-length($new_end)) != -1 ) { + + while (length($line) > $maxlength + and ($i = rindex $line, $break, $maxlength-length($new_end)) != -1) { $rline .= substr($line, 0, $i) . $new_end . "\n"; $line = $new_start . substr($line, $i+length($break)); } - + return $rline . $line; } @@ -455,7 +453,7 @@ sub format_line { sub fileparse { my ($filename, @suffix) = @_; my ($dir, $name, $type, $i); - + $type = ''; foreach $i (@suffix) { if ($filename =~ m|$i$|) { @@ -468,14 +466,9 @@ sub fileparse { $name = $1; $dir = $filename; $dir =~ s|$name$||; - } - else { + } else { $dir = ''; $name = $filename; } ($name, $dir, $type); } - -sub write_interface { - $mcount = $#mnames + 1; -}