Configure's detection of system manual
[p5sagit/p5-mst-13.2.git] / NetWare / t / NWModify.pl
CommitLineData
2986a63f 1
2
3print "\nModifying the '.t' files...\n\n";
4
5use File::Basename;
6use File::Copy;
7
225a5dca 8## Change the below line to the folder you want to process
2986a63f 9$DirName = "/perl/scripts/t";
10
11$FilesTotal = 0;
12$FilesRead = 0;
13$FilesModified = 0;
14
225a5dca 15opendir(DIR, $DirName);
2986a63f 16@Dirs = readdir(DIR);
17
18foreach $DirItem(@Dirs)
19{
20 $DirItem = $DirName."/".$DirItem;
225a5dca 21 push @DirNames, $DirItem; # All items under $DirName folder is copied into an array.
2986a63f 22}
23
24foreach $FileName(@DirNames)
25{
26 if(-d $FileName)
225a5dca 27 { # If an item is a folder, then open it further.
2986a63f 28
225a5dca 29 opendir(SUBDIR, $FileName);
2986a63f 30 @SubDirs = readdir(SUBDIR);
31 close(SUBDIR);
32
33 foreach $SubFileName(@SubDirs)
34 {
35 if(-f $SubFileName)
36 {
37 &Process_File($SubFileName); # If file, process it.
38 }
39 else
40 {
41 $SubFileName = $FileName."/".$SubFileName;
225a5dca 42 push @DirNames, $SubFileName; # If sub-folder, push it into the array.
2986a63f 43 }
44 }
45 }
46 else
47 {
48 if(-f $FileName)
49 {
50 &Process_File($FileName); # If file, process it.
51 }
52 }
53}
54
55close(DIR);
56
57print "\n\n\nTotal number of files present = $FilesTotal\n";
58print "Total number of '.t' files read = $FilesRead\n";
59print "Total number of '.t' files modified = $FilesModified\n\n";
60
61
62
63
64# Process the file.
65sub Process_File
66{
67 local($FileToProcess) = @_; # File name.
68 local($Modified) = 0;
69
2986a63f 70 if(!(-w $FileToProcess)) {
71 # If the file is a read-only file, then change its mode to read-write.
72 chmod(0777, $FileToProcess);
73 }
74
225a5dca 75 ## For example:
2986a63f 76 ## If the value of $FileToProcess is '/perl/scripts/t/pragma/warnings.t', then
77 ## $dir = '/perl/scripts/t/pragma/'
78 ## $base = 'warnings'
79 ## $ext = '.t'
225a5dca 80 $dir = dirname($FileToProcess); # Get the folder name
81 $base = basename($FileToProcess); # Get the base name
82 ($base, $dir, $ext) = fileparse($FileToProcess, '\..*'); # Get the extension of the file passed.
2986a63f 83
84
85 # Do the processing only if the file has '.t' extension.
86 if($ext eq '.t') {
87
88 open(FH, "+< $FileToProcess") or die "Unable to open the file, $FileToProcess for reading and writing.\n";
89 @ARRAY = <FH>; # Get the contents of the file into an array.
90
91 flock(FH, LOCK_EX); # Lock the file for safety purposes.
92 foreach $Line(@ARRAY) # Get each line of the file.
93 {
94 if($Line =~ m/\@INC = /)
95 { # If the line contains the string (@INC = ), then replace it
96
97 # Replace "@INC = " with "unshift @INC, "
98 $Line =~ s/\@INC = /unshift \@INC, /;
99
100 $Modified = 1;
101 }
102
103 if($Line =~ m/push \@INC, /)
104 { # If the line contains the string (push @INC, ), then replace it
105
106 # Replace "push @INC, " with "unshift @INC, "
107 $Line =~ s/push \@INC, /unshift \@INC, /;
108
109 $Modified = 1;
110 }
111 }
112
113 seek(FH, 0, 0); # Seek to the beginning.
114 print FH @ARRAY; # Write the changed array into the file.
115 flock(FH, LOCK_UN); # unlock the file.
116 close FH; # close the file.
117
118 $FilesRead++; # One more file read.
119
120 if($Modified) {
121 print "Modified the file, $FileToProcess\n";
122 $Modified = 0;
123
124 $FilesModified++; # One more file modified.
125 }
126 }
127
128 $FilesTotal++; # One more file present.
129}
130