TAPE: Fix ANSI EOF1 to correctly indicate the block count
- when the file ends on a block boundary, the block count was off by one. - always use the max_record_size in ANSI labels independent of the ansi-type.
This commit is contained in:
parent
f519513f50
commit
b9297e185f
1 changed files with 10 additions and 7 deletions
17
sim_tape.c
17
sim_tape.c
|
@ -777,7 +777,7 @@ switch (MT_GET_FMT (uptr)) {
|
||||||
}
|
}
|
||||||
block = (uint8 *)malloc (uptr->recsize);
|
block = (uint8 *)malloc (uptr->recsize);
|
||||||
tape->block_size = uptr->recsize;
|
tape->block_size = uptr->recsize;
|
||||||
while (!feof(f) && !error) {
|
while (!feof (f) && !error) {
|
||||||
size_t data_read = fread (block, 1, tape->block_size, f);
|
size_t data_read = fread (block, 1, tape->block_size, f);
|
||||||
if (data_read > 0)
|
if (data_read > 0)
|
||||||
error = memory_tape_add_block (tape, block, data_read);
|
error = memory_tape_add_block (tape, block, data_read);
|
||||||
|
@ -793,7 +793,7 @@ switch (MT_GET_FMT (uptr)) {
|
||||||
}
|
}
|
||||||
tape->block_size = uptr->recsize;
|
tape->block_size = uptr->recsize;
|
||||||
block = (uint8 *)calloc (1, uptr->recsize + 3);
|
block = (uint8 *)calloc (1, uptr->recsize + 3);
|
||||||
while (!feof(f) && !error) {
|
while (!feof (f) && !error) {
|
||||||
if (fgets ((char *)block, uptr->recsize + 3, f)) {
|
if (fgets ((char *)block, uptr->recsize + 3, f)) {
|
||||||
size_t len = strlen ((char *)block);
|
size_t len = strlen ((char *)block);
|
||||||
|
|
||||||
|
@ -4374,6 +4374,8 @@ static t_bool memory_tape_add_block (MEMORY_TAPE *tape, uint8 *block, uint32 siz
|
||||||
{
|
{
|
||||||
TAPE_RECORD *rec;
|
TAPE_RECORD *rec;
|
||||||
|
|
||||||
|
ASSURE((size == 0) == (block == NULL));
|
||||||
|
|
||||||
if (tape->array_size <= tape->record_count) {
|
if (tape->array_size <= tape->record_count) {
|
||||||
TAPE_RECORD **new_records;
|
TAPE_RECORD **new_records;
|
||||||
new_records = (TAPE_RECORD **)realloc (tape->records, (tape->array_size + 1000) * sizeof (*tape->records));
|
new_records = (TAPE_RECORD **)realloc (tape->records, (tape->array_size + 1000) * sizeof (*tape->records));
|
||||||
|
@ -4708,7 +4710,7 @@ sprintf (file_sequence, "%04d", 1 + tape->file_count);
|
||||||
memcpy (hdr1.file_sequence, file_sequence, sizeof (hdr1.file_sequence));
|
memcpy (hdr1.file_sequence, file_sequence, sizeof (hdr1.file_sequence));
|
||||||
if (ansi->fixed_text)
|
if (ansi->fixed_text)
|
||||||
max_record_size = 512;
|
max_record_size = 512;
|
||||||
ansi_make_HDR2 (&hdr2, !lf_line_endings && !crlf_line_endings, tape->block_size, (tape->ansi_type > MTUF_F_ANSI) ? 512 : max_record_size, tape->ansi_type);
|
ansi_make_HDR2 (&hdr2, !lf_line_endings && !crlf_line_endings, tape->block_size, max_record_size, tape->ansi_type);
|
||||||
|
|
||||||
if (!ansi->nohdr3) { /* Need HDR3? */
|
if (!ansi->nohdr3) { /* Need HDR3? */
|
||||||
if (!lf_line_endings && !crlf_line_endings) /* Binary File? */
|
if (!lf_line_endings && !crlf_line_endings) /* Binary File? */
|
||||||
|
@ -4730,7 +4732,7 @@ if ((0 != memcmp (hdr4.extra_name_used, "00", 2)) && !ansi->nohdr3 && !ansi->noh
|
||||||
memory_tape_add_block (tape, NULL, 0); /* Tape Mark */
|
memory_tape_add_block (tape, NULL, 0); /* Tape Mark */
|
||||||
rewind (f);
|
rewind (f);
|
||||||
block = (uint8 *)calloc (tape->block_size, 1);
|
block = (uint8 *)calloc (tape->block_size, 1);
|
||||||
while (!feof(f) && !error) {
|
while (!feof (f) && !error) {
|
||||||
size_t data_read = tape->block_size;
|
size_t data_read = tape->block_size;
|
||||||
|
|
||||||
if (lf_line_endings || crlf_line_endings) /* text file? */
|
if (lf_line_endings || crlf_line_endings) /* text file? */
|
||||||
|
@ -4739,10 +4741,11 @@ while (!feof(f) && !error) {
|
||||||
ansi->fixed_text);
|
ansi->fixed_text);
|
||||||
else
|
else
|
||||||
data_read = fread (block, 1, tape->block_size, f);
|
data_read = fread (block, 1, tape->block_size, f);
|
||||||
if (data_read > 0)
|
if (data_read > 0) {
|
||||||
error = memory_tape_add_block (tape, block, data_read);
|
error = memory_tape_add_block (tape, block, data_read);
|
||||||
if (!error)
|
if (!error)
|
||||||
++block_count;
|
++block_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fclose (f);
|
fclose (f);
|
||||||
free (block);
|
free (block);
|
||||||
|
|
Loading…
Add table
Reference in a new issue