./splitter.pl [ script ]
NAME
splitter.pl
AUTHOR
Chr. Matyssek
USAGE
This script searches for .m files in a given directory and splits them according to any RoboDoc Headers that occurs. Each snippet is named according to the RoboDoc name that occurs in the header.
SOURCE
14 #!/usr/bin/perl -w 15 16 use File::Basename; 17 use File::Path; 18 19 ###################################### 20 # 21 # CONFIGURATION 22 23 # Where are the source files located? 24 #$searchpath="../../mathematica"; 25 $searchpath="./"; 26 27 # Where shall we put the documentation? 28 $docpath="../doc/doc_mod"; 29 30 ################################### 31 32 # First, check if the documentation path exists, if not create it. 33 unless(-e $docpath) { 34 print "Docpath ".$docpath." does not exist. Creating it.\n"; 35 mkdir($docpath); 36 } 37 38 # Get all .m files 39 my @files = glob($searchpath."/*.m"); 40 41 foreach (@files) { 42 my $filename=$_; 43 print "Processing $filename\n"; 44 # Go through file line by line and look for roobodoc header 45 open(INFILE, "<$filename"); 46 # This will tell us whether or not a file is open for output 47 $fileopen=-1; 48 while(<INFILE>) { 49 $line=$_; 50 # Start of header: open target file and name it according to 51 # the robodoc header 52 if( $line =~/\(\*\*\*\*([pm])\* (.+)\n/) { 53 print "Header found on line: $_"; 54 print "Type: $1\n"; 55 print "Name: $2\n"; 56 $targetfile=$2; 57 $dirname = dirname($targetfile); 58 if(-e $docpath.$dirname) { 59 print "Path $docpath.$dirname exists\n"; 60 } else { 61 # This will create the directories recursively 62 mkpath($docpath.$dirname); 63 } 64 # The path exists and we can open the target file for writing 65 open(OUTFILE, "+>".$docpath.$targetfile) || die "Cannot open outfile ".$docpath.$targetfile." because $! \n"; 66 $fileopen=0; 67 } 68 # End of header, close file 69 if($_ =~/\*\*\*\)/) { 70 print OUTFILE $line; 71 close(OUTFILE); 72 $fileopen=-1; 73 } 74 # If a file is openened, output the line to the file 75 if($fileopen == 0) { 76 print OUTFILE $line; 77 } 78 } 79 close(INFILE); 80 }