#!/opt/bin/perl #//////////////////////////////////////// #// MODULE ansify (fm) // #//////////////////////////////////////// #// IMPORTS // #//////////////////////////////////////// # # Requires Perl version 4.036 or higher # #//////////////////////////////////////// #// INTERFACE // #//////////////////////////////////////// # # Usage: ansify [ ]* # # Note that you may use wildcard characters, # since they will be expanded by your shell. # #//////////////////////////////////////// #// RESOURCES // #//////////////////////////////////////// $version = 'version 1.2'; $self = $0; $self =~ s!^.*/!!; #//////////////////////////////////////// #// IMPLEMENTATION // #//////////////////////////////////////// print "\n'$self' $version\n\n"; print "Converter for non-standard C comments ('// ...')\n"; print "to ANSI C style comments ('/* ... */')\n\n"; FILE: while (@ARGV) { $filename = shift; next FILE unless (-f $filename); unless (open(INPUT, "<$filename")) { warn "unable to read '$filename': $!\n"; next FILE; } unless (rename($filename,"$filename.bak")) { warn "unable to rename '$filename' to '$filename.bak': $!\n"; next FILE; } unless (open(OUTPUT, ">$filename")) { warn "unable to write '$filename': $!\n"; next FILE; } while () { $loop = (index($_,'//') >= $[); while ($loop) { if (m!//(/+)//!) { $t1 = $`; $t2 = $1; $t3 = $'; $t2 =~ s!/!*!g; if ($t3 eq "") { $loop = 0; $_ = $t1 . "/*" . $t2 . "*/"; } else { $loop = (index($t3,'//') >= $[); if ($loop) { $_ = $t1 . "/*" . $t2 . "*/" . $t3; } else { $_ = $t1 . "/*" . $t2 . "*/ /*" . $t3 . " */"; } } } elsif (m!//(.*)//!) { $t1 = $`; $t2 = $1; $t3 = $'; if ($t3 eq "") { $loop = 0; $_ = $t1 . "/*" . $t2 . "*/"; } else { $loop = (index($t3,'//') >= $[); if ($loop) { $_ = $t1 . "/*" . $t2 . "*/" . $t3; } else { $_ = $t1 . "/*" . $t2 . "*/ /*" . $t3 . " */"; } } } else { $loop = 0; s!//!/*!; $_ .= " */"; } } print OUTPUT; } close(INPUT); close(OUTPUT); } #//////////////////////////////////////// #// PROGRAMMER Steffen Beyer // #//////////////////////////////////////// #// CREATED 22.04.95 // #//////////////////////////////////////// #// MODIFIED 09.12.95 // #//////////////////////////////////////// #// COPYRIGHT Steffen Beyer // #////////////////////////////////////////