Subversion Repositories DevTools

Rev

Rev 4636 | Rev 4641 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4636 Rev 4640
Line 1159... Line 1159...
1159
    print DT  $text || Error ("Cannot print to $file");
1159
    print DT  $text || Error ("Cannot print to $file");
1160
    close DT;
1160
    close DT;
1161
}
1161
}
1162
 
1162
 
1163
#-------------------------------------------------------------------------------
1163
#-------------------------------------------------------------------------------
-
 
1164
# Function        : ConvertFiles
-
 
1165
#
-
 
1166
# Description     : This sub-routine is used to remove all carrage return\line
-
 
1167
#                   feeds from a line and replace them with the platform
-
 
1168
#                   specific equivalent chars.
-
 
1169
#
-
 
1170
#                   We let PERL determine what characters are written to the
-
 
1171
#                   file base on the  platform you are running on.
-
 
1172
#
-
 
1173
#                   i.e. LF    for unix
-
 
1174
#                        CR\LF for win32
-
 
1175
#
-
 
1176
# Inputs          : outPath                 - Output directory
-
 
1177
#                   flist                   - List of files in that directory
-
 
1178
#                   or
-
 
1179
#                   SearchOptions           - Search options to find files
-
 
1180
#                                           --Recurse
-
 
1181
#                                           --NoRecurse
-
 
1182
#                                           --FilterIn=xxx
-
 
1183
#                                           --FilterInRe=xxx
-
 
1184
#                                           --FilterOut=xxx
-
 
1185
#                                           --FilterOutRe=xxx
-
 
1186
#                   Common options
-
 
1187
#                                           --Dos
-
 
1188
#                                           --Unix
-
 
1189
#
-
 
1190
#
-
 
1191
# Returns         : 1
-
 
1192
#
-
 
1193
sub ConvertFiles
-
 
1194
{
-
 
1195
    my @uargs;
-
 
1196
    my $lineEnding = "\n";
-
 
1197
    my ($dosSet, $unixSet);
-
 
1198
    my $search =  JatsLocateFiles->new( '--NoRecurse' );
-
 
1199
 
-
 
1200
    #
-
 
1201
    #   Process user arguments extracting options
-
 
1202
    #
-
 
1203
    foreach  ( @_ )
-
 
1204
    {
-
 
1205
        if ( m~^--Recurse~ ) {
-
 
1206
            $search->recurse(1);
-
 
1207
 
-
 
1208
        } elsif ( m~^--NoRecurse~) {
-
 
1209
            $search->recurse(0);
-
 
1210
 
-
 
1211
        } elsif ( /^--FilterOut=(.*)/ ) {
-
 
1212
            $search->filter_out($1);
-
 
1213
 
-
 
1214
        } elsif ( /^--FilterOutRe=(.*)/ ) {
-
 
1215
            $search->filter_out_re($1);
-
 
1216
 
-
 
1217
        } elsif ( /^--FilterIn=(.*)/ ) {
-
 
1218
            $search->filter_in($1);
-
 
1219
 
-
 
1220
        } elsif ( /^--FilterInRe=(.*)/ ) {
-
 
1221
            $search->filter_in_re($1);
-
 
1222
 
-
 
1223
        } elsif ( m~^--Dos~) {
-
 
1224
            $lineEnding = "\r\n";
-
 
1225
            $dosSet = 1;
-
 
1226
 
-
 
1227
        } elsif ( m~^--Unix~) {
-
 
1228
            $lineEnding = "\n";
-
 
1229
            $unixSet = 1;
-
 
1230
 
-
 
1231
        } elsif ( m~^--~) {
-
 
1232
            Error ("ConvertFile: Unknown option: $_");
-
 
1233
 
-
 
1234
        } else {
-
 
1235
            push @uargs, $_;
-
 
1236
        }
-
 
1237
    }
-
 
1238
 
-
 
1239
    #
-
 
1240
    #   Process non-option arguments
-
 
1241
    #       - Base dir
-
 
1242
    #       - List of files
-
 
1243
    #
-
 
1244
    my ($outPath, @flist) = @uargs;
-
 
1245
    Error ("ConvertFiles: Target Dir must be specified" ) unless ( $outPath );
-
 
1246
 
-
 
1247
    #
-
 
1248
    #   Sanity Tests
-
 
1249
    #
-
 
1250
    Error ("ConvertFiles: --Dos and --Unix are mutually exclusive" ) if ( $dosSet && $unixSet );
-
 
1251
 
-
 
1252
 
-
 
1253
    #
-
 
1254
    # Convert output path to physical path
-
 
1255
    #
-
 
1256
    my $topDir = catdir($DebianWorkDir, $outPath);
-
 
1257
    Verbose("ConvertFiles: topDir: $topDir");
-
 
1258
    Error ("ConvertFiles: Path does not exist", $topDir) unless ( -e $topDir );
-
 
1259
    Error ("ConvertFiles: Path is not a directory", $topDir) unless ( -d $topDir );
-
 
1260
 
-
 
1261
    #
-
 
1262
    #   Need to determine if we are searching or simply using a file list
-
 
1263
    #   There are two forms of the functions. If any of the search options have
-
 
1264
    #   been used then we assume that we are searchine
-
 
1265
    #
-
 
1266
    if ( $search->has_filter() )
-
 
1267
    {
-
 
1268
        Error ("ConvertFiles: Cannot mix search options with named files") if ( @flist );
-
 
1269
        @flist = $search->search($topDir);
-
 
1270
    }
-
 
1271
    Error ("ConvertFiles: No files specified") unless ( @flist );
-
 
1272
 
-
 
1273
    #
-
 
1274
    #   Process all named files
-
 
1275
    #
-
 
1276
    foreach my $file ( @flist )
-
 
1277
    {
-
 
1278
 
-
 
1279
        # this is our file that we want to clean.
-
 
1280
        my ($ifileLoc) = "$topDir/$file";
-
 
1281
        my ($tfileLoc) = "$topDir/$file\.tmp";
-
 
1282
        Verbose("ConvertFile: $file");
-
 
1283
 
-
 
1284
        # we will check to see if the file exists.
-
 
1285
        #
-
 
1286
        my $ifile;
-
 
1287
        my $tfile;
-
 
1288
        if ( -f "$ifileLoc" )
-
 
1289
        {
-
 
1290
            open ($ifile, "< $ifileLoc" ) or
-
 
1291
                Error("Failed to open file [$ifileLoc] : $!");
-
 
1292
 
-
 
1293
            open ($tfile, "> $tfileLoc" ) or
-
 
1294
                Error("Failed to open file [$tfileLoc] : $!");
-
 
1295
            binmode $tfile;
-
 
1296
 
-
 
1297
            while ( <$ifile> ) 
-
 
1298
            {
-
 
1299
                s~[\n\r]+$~~;               # Chomp
-
 
1300
                print $tfile "$_" . $lineEnding;
-
 
1301
            }
-
 
1302
        }
-
 
1303
        else
-
 
1304
        {
-
 
1305
            Error("ConvertFiles [$ifileLoc] does not exist.");
-
 
1306
        }
-
 
1307
 
-
 
1308
        close $ifile;
-
 
1309
        close $tfile;
-
 
1310
 
-
 
1311
 
-
 
1312
        # lets replace our original file with the new one
-
 
1313
        #
-
 
1314
        if(File::Copy::move("$tfileLoc", "$ifileLoc"))
-
 
1315
        {
-
 
1316
            Verbose2("ConvertFiles: Renamed [$tfileLoc] to [$ifileLoc] ...");
-
 
1317
        }
-
 
1318
        else
-
 
1319
        {
-
 
1320
            Error("ConvertFiles: Failed to rename file [$tfileLoc] to [$ifileLoc]: $!");
-
 
1321
        }
-
 
1322
    }
-
 
1323
 
-
 
1324
    return 1;
-
 
1325
}
-
 
1326
 
-
 
1327
#-------------------------------------------------------------------------------
1164
# Function        : SetFilePerms
1328
# Function        : SetFilePerms
1165
#
1329
#
1166
# Description     : Set file permissions on one or more files or directories
1330
# Description     : Set file permissions on one or more files or directories
1167
#
1331
#
1168
# Inputs          : $perm           - Perm Mask
1332
# Inputs          : $perm           - Perm Mask