conv-theory-files.pl
author lcp
Mon, 21 Nov 1994 10:51:40 +0100
changeset 718 efca1e0710fb
parent 436 0cdc840297bb
permissions -rwxr-xr-x
page 157 erratum
lcp@436
     1
#!/usr/bin/perl -s-	 # -*-Perl-*-
lcp@436
     2
lcp@436
     3
#---------------------------------------------------------------------
lcp@436
     4
#The following script file is useful to convert old theory files into a
lcp@436
     5
#style consistent with new naming conventions. Now, the names of the
lcp@436
     6
#files must be the same as the names of the theories they define (with
lcp@436
     7
#a ".thy" suffix) and corresponding ML files must also be renamed.
lcp@436
     8
#
lcp@436
     9
#To make this renaming easier, the following perl script can be used.
lcp@436
    10
#It traverses the given directory recursively.  For each file of the
lcp@436
    11
#form abc.thy, this script does the following steps:
lcp@436
    12
#
lcp@436
    13
#1. Reads the file and grabs the first identifier, say Abc (skipping comments
lcp@436
    14
#   (*...*) and white space).
lcp@436
    15
#2. Outputs the commands needed to rename the file abc.thy to Abc.thy,
lcp@436
    16
#   including the appropriate CVS commands.
lcp@436
    17
#3. If abc.ML also exists, it outputs appropriate commands to rename it
lcp@436
    18
#   to Abc.ML.
lcp@436
    19
#
lcp@436
    20
#These commands can be put into a file, which can then be executed.
lcp@436
    21
#If you are not using cvs, use "grep" to extract just the "mv" commands.
lcp@436
    22
#
lcp@436
    23
#						- Sara Kalvala
lcp@436
    24
#						  (sk@cl.cam.ac.uk)
lcp@436
    25
#---------------------------------------------------------------------
lcp@436
    26
lcp@436
    27
open(MATCH_FILES, "find . -name \"*thy\" -print |");
lcp@436
    28
lcp@436
    29
foreach $each_match (<MATCH_FILES>) {
lcp@436
    30
 chop($each_match);
lcp@436
    31
 if($each_match =~ /(.*\/)(\w*)\.thy/) {$dirpart = $1;}
lcp@436
    32
 else {print "something wrong with finding path!\n";
lcp@436
    33
       $dirpart = "";}
lcp@436
    34
 open (CONTENTS, $each_match);
lcp@436
    35
 @readit = <CONTENTS>;
lcp@436
    36
 chop(@readit); $oneline = join(" ",@readit);
lcp@436
    37
 $oneline =~ s/\(\*([^\*]|(\*[^\)]))*\*\)//g ;
lcp@436
    38
# comments: have to remove strings of anything but stars or stars
lcp@436
    39
# followed by anything but right parenthesis 
lcp@436
    40
 if($oneline =~ /\s*([^ ]*)\s*=.*/)
lcp@436
    41
 {$th_name = $1;
lcp@436
    42
  $new_name = $dirpart . $th_name . ".thy";
lcp@436
    43
  print "mv -i $each_match $new_name \n";
lcp@436
    44
  print "cvs rm $each_match ; cvs add $new_name \n";
lcp@436
    45
# for ML files
lcp@436
    46
  $each_ML = $each_match;
lcp@436
    47
  $each_ML =~ s/.thy/.ML/;
lcp@436
    48
  if (-e $each_ML) { $new_ML = $dirpart . $th_name . ".ML";
lcp@436
    49
		     print "mv -i $each_ML $new_ML \n";
lcp@436
    50
		     print "cvs rm $each_ML ; cvs add $new_ML \n";}}
lcp@436
    51
 else {print "something wrong with format of theory file!\n";}
lcp@436
    52
}
lcp@436
    53