TAPE: Enhanced file type detection performance and cleaned up stylistic details

This commit is contained in:
Larry Baker 2020-06-14 14:10:55 -07:00 committed by Mark Pizzolato
parent 1d3d20e999
commit c062c7589d

View file

@ -144,7 +144,7 @@ struct tape_context {
uint32 dbit; /* debugging bit for trace */
uint32 auto_format; /* Format determined dynamically */
#if defined SIM_ASYNCH_IO
int asynch_io; /* Asynchronous Interrupt scheduling enabled */
t_bool asynch_io; /* Asynchronous Interrupt scheduling enabled */
int asynch_io_latency; /* instructions to delay pending interrupt */
pthread_mutex_t lock;
pthread_t io_thread; /* I/O Thread Id */
@ -173,7 +173,7 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx; \
\
if (ctx == NULL) \
return sim_messagef (SCPE_IERR, "Bad Attach\n"); \
if ((!callback) || !ctx->asynch_io)
if ((callback == NULL) || !(ctx->asynch_io))
#define AIO_CALL(op, _buf, _bc, _fc, _max, _vbc, _gaplen, _bpi, _obj, _callback)\
if (ctx->asynch_io) { \
@ -589,7 +589,7 @@ if (!ctx) return SCPE_UNATT;
if (ctx->asynch_io) {
pthread_mutex_lock (&ctx->io_lock);
ctx->asynch_io = 0;
ctx->asynch_io = FALSE;
pthread_cond_signal (&ctx->io_cond);
pthread_mutex_unlock (&ctx->io_lock);
pthread_join (ctx->io_thread, NULL);
@ -636,7 +636,7 @@ DEVICE *dptr;
if ((dptr = find_dev_from_unit (uptr)) == NULL)
return SCPE_NOATT;
return sim_tape_attach_ex (uptr, cptr, ((dptr->flags & DEV_DEBUG) || (dptr->debflags)) ? MTSE_DBG_API : 0, 0);
return sim_tape_attach_ex (uptr, cptr, ((dptr->flags & DEV_DEBUG) || (dptr->debflags != NULL)) ? MTSE_DBG_API : 0, 0);
}
t_stat sim_tape_attach_ex (UNIT *uptr, const char *cptr, uint32 dbit, int completion_delay)
@ -704,7 +704,7 @@ switch (MT_GET_FMT (uptr)) {
}
tape = ansi_create_tape (label, uptr->recsize, MT_GET_ANSI_TYP (uptr));
uptr->fileref = (FILE *)tape;
if (!uptr->fileref)
if (uptr->fileref == NULL)
return SCPE_MEM;
while (*cptr != 0) { /* do all mods */
uint32 initial_file_count = tape->file_count;
@ -761,7 +761,7 @@ switch (MT_GET_FMT (uptr)) {
tape = memory_create_tape ();
uptr->fileref = (FILE *)tape;
if (!uptr->fileref)
if (uptr->fileref == NULL)
return SCPE_MEM;
f = fopen (cptr, "rb");
if (f == NULL) {
@ -769,7 +769,7 @@ switch (MT_GET_FMT (uptr)) {
break;
}
tape_classify_file_contents (f, &max_record_size, &lf_line_endings, &crlf_line_endings);
if ((!lf_line_endings) && (!crlf_line_endings)) { /* binary file? */
if (!lf_line_endings && !crlf_line_endings) { /* binary file? */
if (uptr->recsize == 0) {
r = sim_messagef (SCPE_ARG, "Binary file %s must specify a record size with -B\n", cptr);
fclose (f);
@ -835,7 +835,7 @@ switch (MT_GET_FMT (uptr)) {
tape = memory_create_tape();
tape->block_size = uptr->recsize;
uptr->fileref = (FILE *)tape;
if (!uptr->fileref)
if (uptr->fileref == NULL)
return SCPE_MEM;
while (*cptr != 0) {
@ -4621,7 +4621,7 @@ long last_cr = -1;
long last_lf = -1;
long line_start = 0;
int chr;
long non_print_chars = 0;
t_bool non_print_chars = FALSE;
long lf_lines = 0;
long crlf_lines = 0;
@ -4631,8 +4631,10 @@ long crlf_lines = 0;
rewind (f);
while (EOF != (chr = fgetc (f))) {
++pos;
if (!isprint (chr) && (chr != '\r') && (chr != '\n') && (chr != '\t') && (chr != '\f'))
++non_print_chars;
if (!isprint (chr) && (chr != '\r') && (chr != '\n') && (chr != '\t') && (chr != '\f')) {
non_print_chars = TRUE;
break;
}
if (chr == '\r')
last_cr = pos;
if (chr == '\n') {
@ -4712,22 +4714,22 @@ if (ansi->fixed_text)
max_record_size = 512;
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? */
memcpy (&hdr3, ansi->hdr3_fixed, sizeof (hdr3));
else { /* Text file */
if ((lf_line_endings) && !(ansi->fixed_text))
if (lf_line_endings && !(ansi->fixed_text))
memcpy (&hdr3, ansi->hdr3_lf_line_endings, sizeof (hdr3));
else
memcpy (&hdr3, ansi->hdr3_crlf_line_endings, sizeof (hdr3));
}
}
memory_tape_add_block (tape, (uint8 *)&hdr1, sizeof (hdr1));
if (!ansi->nohdr2)
if (!(ansi->nohdr2))
memory_tape_add_block (tape, (uint8 *)&hdr2, sizeof (hdr2));
if (!ansi->nohdr3)
if (!(ansi->nohdr3))
memory_tape_add_block (tape, (uint8 *)&hdr3, sizeof (hdr3));
if ((0 != memcmp (hdr4.extra_name_used, "00", 2)) && !ansi->nohdr3 && !ansi->nohdr2)
if ((0 != memcmp (hdr4.extra_name_used, "00", 2)) && !(ansi->nohdr3) && !(ansi->nohdr2))
memory_tape_add_block (tape, (uint8 *)&hdr4, sizeof (hdr4));
memory_tape_add_block (tape, NULL, 0); /* Tape Mark */
rewind (f);
@ -4757,11 +4759,11 @@ memcpy (hdr4.type, "EOF", sizeof (hdr4.type));
sprintf (block_count_string, "%06d", block_count);
memcpy (hdr1.block_count, block_count_string, sizeof (hdr1.block_count));
memory_tape_add_block (tape, (uint8 *)&hdr1, sizeof (hdr1));
if (!ansi->nohdr2)
if (!(ansi->nohdr2))
memory_tape_add_block (tape, (uint8 *)&hdr2, sizeof (hdr2));
if (!ansi->nohdr3)
if (!(ansi->nohdr3))
memory_tape_add_block (tape, (uint8 *)&hdr3, sizeof (hdr3));
if ((0 != memcmp (hdr4.extra_name_used, "00", 2)) && !ansi->nohdr3 && !ansi->nohdr2)
if ((0 != memcmp (hdr4.extra_name_used, "00", 2)) && !(ansi->nohdr3) && !(ansi->nohdr2))
memory_tape_add_block (tape, (uint8 *)&hdr4, sizeof (hdr4));
memory_tape_add_block (tape, NULL, 0); /* Tape Mark */
if (sim_switches & SWMASK ('V'))