Parent Directory
|
Revision Log
Removed unneeded scripts (as per discussion with gage, apizer). Added BEGIN-block method for library inclusion to command-line scripts.
1 #!/usr/local/bin/webwork-perl 2 3 BEGIN { 4 my $useLibDir = '.'; 5 if ($0 =~ m|^(/.*)/|) { $useLibDir = $1; } 6 elsif ($0 =~ m|^(\..*)/|) { $useLibDir = $1; } 7 elsif ($0 =~ m|^(.+)/|) { $useLibDir = "./$1"; } 8 unshift @INC, $useLibDir; 9 } 10 11 use webworkInit; # WeBWorKInitLine 12 use capa2PG; 13 use Benchmark; 14 15 16 17 # Called by 18 # convert_capa_2_PG.pl indirectory outdirectory 19 20 unless (defined($ARGV[0]) ) { 21 print qq! 22 Useage: 23 convert_capa_2_PG.pl in_directory_path out_directory_path 24 25 and will convert all *.txt files in the in directory from CAPA to PG files, 26 placing them in *.pg files in the out directory. 27 Files named prob1a.txt prob1b.txt will be concatenated 28 and placed into the file prob1.pg. 29 30 For example: 31 32 convert_capa_2.PG.pl type1 type1pg 33 34 If out_directory_path is omitted then the out_directory_path is obtained by adding pg to the 35 in_directory 36 \n\n 37 !; 38 exit; 39 } 40 41 42 $directory = $ARGV[0]; 43 $indirectory = $directory; # no final slash 44 $outdirectory = "${directory}pg"; 45 $outdirectory = $ARGV[1] if defined($ARGV[1]); 46 47 print "Converting all *.txt files in the directory 48 $directory 49 to the PG language and placing them in 50 *.pg files in the directory 51 $outdirectory. 52 Proceed?>"; 53 my $response = <STDIN>; 54 exit unless $response =~ /y/i ; 55 56 57 58 # $outdirectory = "${directory}pg"; # no final slash 59 opendir(DIRHANDLE, "$indirectory" ) || die "Can't open $indirectory $!"; 60 61 @allfiles = sort grep /\.txt/, readdir DIRHANDLE; 62 closedir DIRHANDLE; 63 64 $first_file = shift(@allfiles); 65 66 67 68 69 my @all_lines = slurp("$indirectory/$first_file"); 70 71 while (1) { 72 my $file = shift @allfiles; 73 74 if ( root($first_file) eq root($file) ) { 75 # $out_line .= "$directory/$file "; 76 push(@all_lines, slurp("$directory/$file") ); 77 } else { 78 # we're done time to ship the file 79 my $newName = root($first_file); 80 #$newName =~ s/prob/capa/; 81 82 print STDERR "Creating $outdirectory/$newName.pg\n"; 83 open(FILE_OUT, ">$outdirectory/$newName.pg") || print STDERR "Unable to output to $outdirectory/$newName.pg\n"; 84 85 ## begin Timing code 86 my $beginTime = new Benchmark; 87 ## end Timing code 88 print FILE_OUT parse_CAPA_file(\@all_lines); 89 ## begin Timing code 90 my $endTime = new Benchmark; 91 print FILE_OUT "\n#################################################\n## Processing time = ", timestr( timediff($endTime,$beginTime) ), 92 "\n#################################################\n"; 93 ## end Timing code 94 95 close(FILE_OUT); 96 # print $out_line; 97 # system( $out_line); 98 # and prepare the next 99 $first_file = $file; 100 #$out_line = "cat $directory/$first_file "; 101 @all_lines = slurp("$directory/$first_file"); 102 last unless defined($first_file); 103 } 104 } 105 106 sub slurp { 107 my $path = shift; 108 my @lines = (); 109 if (open(FILE, "<$path") ) { 110 print STDERR "Reading $path\n"; 111 @lines = <FILE>; 112 } else { 113 print STDERR "Can't open $path for reading. Skipping."; 114 } 115 @lines; 116 } 117 118 119 120 121 sub root { 122 my $in = shift; 123 $in =~ s/[abcdefg]*\.txt$//; 124 $in; 125 }
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |