fieker-DuValspielwiese
Last change
on this file since 26da1d was
341696,
checked in by Hans Schönemann <hannes@…>, 15 years ago
|
Adding Id property to all files
git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
|
-
Property mode set to
100644
|
File size:
1.7 KB
|
Rev | Line | |
---|
[35aab3] | 1 | #!/usr/local/bin/perl |
---|
| 2 | ########################################################################### |
---|
[341696] | 3 | # $Id$ |
---|
[35aab3] | 4 | |
---|
| 5 | ########################################################################### |
---|
| 6 | ## |
---|
| 7 | ## FILE: check_aso.pl |
---|
| 8 | ## PURPOSE: checks source files for Alloc(sizeof(..)) statements and |
---|
| 9 | ## fixes them, if requested |
---|
| 10 | ## AUTHOR: obachman (10/99) |
---|
| 11 | ## |
---|
| 12 | |
---|
| 13 | $Usage = <<EOT; |
---|
| 14 | $0 [-fh] file(s) |
---|
| 15 | Checks source files for Alloc(sizeof(..)) statements and |
---|
| 16 | fixes them, if -f |
---|
| 17 | EOT |
---|
| 18 | |
---|
| 19 | # parse command-line options |
---|
| 20 | while (@ARGV && $ARGV[0] =~ /^-/) |
---|
| 21 | { |
---|
| 22 | $_ = shift(@ARGV); |
---|
| 23 | if (/^-h/) |
---|
| 24 | { |
---|
| 25 | print STDOUT $Usage; |
---|
| 26 | exit(0); |
---|
| 27 | } |
---|
| 28 | # $fix = 1 if /^-f/; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | # process file |
---|
| 33 | while (<>) |
---|
| 34 | { |
---|
| 35 | # Check for Alloc(sizeof(..)), Free(..,sizeof(..)) |
---|
| 36 | if (/(^|[^\w])(Alloc|Alloc0|AllocAligned|AllocAligned0)\s*\(\s*sizeof\s*\(\s*([^\)]*)\s*\)\s*\)/ |
---|
| 37 | || |
---|
| 38 | /(^|[^\w])(Free|FreeAligned)\s*\(.*,\s*sizeof\s*\(\s*([^\)]*)\s*\)\s*\)/) |
---|
| 39 | { |
---|
| 40 | $what = $3; |
---|
| 41 | $alloc = $2; |
---|
| 42 | $what =~ s/^\s*//; |
---|
| 43 | $what =~ s/\s*$//; |
---|
| 44 | if ($what !~ /^\w[\w\d]*$/) |
---|
| 45 | { |
---|
| 46 | print STDERR "Warning: Argument $what to $alloc does not match \w[\w\d]* at $ARGV:$.\n"; |
---|
| 47 | } |
---|
| 48 | else |
---|
| 49 | { |
---|
| 50 | # error if inside sizeof(..) is weird |
---|
| 51 | print STDERR "Warning: $alloc(sizeof($what)) found at $ARGV:$."; |
---|
| 52 | if ($fix) |
---|
| 53 | { |
---|
| 54 | s/sizeof\s*\(\s*$what\s*\)/$what/; |
---|
| 55 | $what = $alloc."SizeOf"; |
---|
| 56 | s/$alloc/$what/; |
---|
| 57 | $fixed = 1; |
---|
| 58 | print " (fixed)\n"; |
---|
| 59 | } |
---|
| 60 | else |
---|
| 61 | { |
---|
| 62 | print "\nRun '$0 -f $ARGV' to fix\n"; |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | $content .= $_ if $fix; |
---|
| 67 | } |
---|
| 68 | continue |
---|
| 69 | { |
---|
| 70 | if (eof) |
---|
| 71 | { |
---|
| 72 | close ARGV; |
---|
| 73 | if ($fix && $fixed) |
---|
| 74 | { |
---|
| 75 | print STDERR "Creating $ARGV.bak and fixing $ARGV\n"; |
---|
| 76 | system("cp $ARGV $ARGV.bak"); |
---|
| 77 | open(ARGV, ">$ARGV"); |
---|
| 78 | print ARGV $content; |
---|
| 79 | close(ARGV); |
---|
| 80 | $fixed = 0; |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
Note: See
TracBrowser
for help on using the repository browser.