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:
Mark Pizzolato 2020-05-26 09:47:10 -07:00
parent f519513f50
commit b9297e185f

View file

@ -777,7 +777,7 @@ switch (MT_GET_FMT (uptr)) {
}
block = (uint8 *)malloc (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);
if (data_read > 0)
error = memory_tape_add_block (tape, block, data_read);
@ -793,7 +793,7 @@ switch (MT_GET_FMT (uptr)) {
}
tape->block_size = uptr->recsize;
block = (uint8 *)calloc (1, uptr->recsize + 3);
while (!feof(f) && !error) {
while (!feof (f) && !error) {
if (fgets ((char *)block, uptr->recsize + 3, f)) {
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;
ASSURE((size == 0) == (block == NULL));
if (tape->array_size <= tape->record_count) {
TAPE_RECORD **new_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));
if (ansi->fixed_text)
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 (!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 */
rewind (f);
block = (uint8 *)calloc (tape->block_size, 1);
while (!feof(f) && !error) {
while (!feof (f) && !error) {
size_t data_read = tape->block_size;
if (lf_line_endings || crlf_line_endings) /* text file? */
@ -4739,11 +4741,12 @@ while (!feof(f) && !error) {
ansi->fixed_text);
else
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);
if (!error)
++block_count;
}
}
fclose (f);
free (block);
memory_tape_add_block (tape, NULL, 0); /* Tape Mark */