OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [tools/] [bin/] [file2tap] - Blame information for rev 38

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 31 wfjm
#!/usr/bin/perl -w
2
# $Id: file2tap 686 2015-06-04 21:08:08Z mueller $
3
#
4
# Copyright 2008-2015 by Walter F.J. Mueller 
5
#
6
# This program is free software; you may redistribute and/or modify it under
7
# the terms of the GNU General Public License as published by the Free
8
# Software Foundation, either version 2, or at your option any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
12
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
# for complete details.
14
#
15
#  Revision History:
16
# Date         Rev Version  Comment
17
# 2015-06-03   686   1.1    fix -a option; support eom at end
18
# 2008-12-07   175   1.0.1  remove some upperfluous 'my'
19
# 2008-11-29   174   1.0    Initial version (import from tbird backup)
20
#
21
#
22
# Create a simh tape container file (.tap) from a set of files
23
#
24
# Usage:  file2tap -c name -b n file1 ... filen
25
#
26
#   if -c name is omitted, stdout is used
27
#
28
 
29
use strict;
30
use Fcntl qw(:seek O_RDWR);
31
 
32
my $arg;
33
my $cdone;
34
my $blocksize = 512;
35
my $nfile = 0;
36
 
37
while ($arg = shift) {
38
 
39
  if ($arg eq "-c") {
40
    if (@ARGV) {
41
      $arg = shift;
42
      open(OFILE, ">$arg") || die ("Can't open output file $arg: $!");
43
      $cdone = 1;
44
    }
45
 
46
  } elsif ($arg eq "-a") {
47
    if (@ARGV) {
48
      $arg = shift;
49
      sysopen OFILE, $arg, O_RDWR || die ("Can't open output file $arg: $!");
50
      my $buf;
51
      my $len;
52
 
53
      # check for EOM mark at end, if found, truncate it away
54
      sysseek OFILE, -4, SEEK_END;
55
      $len = sysread OFILE, $buf, 4;
56
      if ($buf eq "\xff\xff\xff\xff") {
57
        truncate OFILE, sysseek(OFILE, -4, SEEK_END);
58
      }
59
 
60
      # check for two EOF marks at end, if found, truncate 2nd away
61
      sysseek OFILE, -8, SEEK_END;
62
      $len = sysread OFILE, $buf, 8;
63
      if ($buf ne "\x00\x00\x00\x00\x00\x00\x00\x00") {
64
        die ("Didn't find double EOF at end of tap file");
65
      }
66
      truncate OFILE, sysseek(OFILE, -4, SEEK_END);
67
 
68
      close OFILE;
69
      open(OFILE, ">>$arg") || die ("Can't append to output file $arg: $!");
70
      $cdone = 1;
71
    }
72
 
73
  } elsif ($arg eq "-b") {
74
    if (@ARGV) {
75
      $arg = shift;
76
      $blocksize = 512 * int $arg;
77
    }
78
 
79
  } else {
80
    if (!$cdone) {
81
      open(OFILE, ">-") || die ("Can't open stdout: $!");
82
    }
83
 
84
    my @flist = split(",",$arg);
85
    my $file;
86
    foreach $file (@flist) {
87
      add_file($file, $blocksize);
88
    }
89
    $nfile += 1;
90
    end_file();
91
  }
92
}
93
end_file();
94
 
95
# ----------------------------------------------------------------------------
96
sub end_file {
97
  print OFILE "\x00\x00\x00\x00";
98
}
99
 
100
# ----------------------------------------------------------------------------
101
sub add_file {
102
  my($filename, $blocksize) = @_;
103
  my($block, $bytes_read, $length, $nb);
104
 
105
  open(FILE, $filename) || die("Can't open $filename: $!");
106
  while($bytes_read = read(FILE, $block, $blocksize)) {
107
    if($bytes_read < $blocksize) {
108
      $block .= "\x00" x ($blocksize - $bytes_read);
109
    }
110
    $length = pack("V", $blocksize);
111
    print OFILE $length, $block, $length;
112
    $nb += 1;
113
  }
114
  close(FILE);
115
  if ($cdone) {
116
    printf "file: %3d  records: %5d  length: %5d  file: $filename\n",
117
      $nfile, $nb, $blocksize;
118
  }
119
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.