TAPE: Enhanced file type detection performance and cleaned up stylistic details
This commit is contained in:
parent
1d3d20e999
commit
c062c7589d
1 changed files with 30 additions and 28 deletions
40
sim_tape.c
40
sim_tape.c
|
@ -144,7 +144,7 @@ struct tape_context {
|
||||||
uint32 dbit; /* debugging bit for trace */
|
uint32 dbit; /* debugging bit for trace */
|
||||||
uint32 auto_format; /* Format determined dynamically */
|
uint32 auto_format; /* Format determined dynamically */
|
||||||
#if defined SIM_ASYNCH_IO
|
#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 */
|
int asynch_io_latency; /* instructions to delay pending interrupt */
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
pthread_t io_thread; /* I/O Thread Id */
|
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) \
|
if (ctx == NULL) \
|
||||||
return sim_messagef (SCPE_IERR, "Bad Attach\n"); \
|
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)\
|
#define AIO_CALL(op, _buf, _bc, _fc, _max, _vbc, _gaplen, _bpi, _obj, _callback)\
|
||||||
if (ctx->asynch_io) { \
|
if (ctx->asynch_io) { \
|
||||||
|
@ -589,7 +589,7 @@ if (!ctx) return SCPE_UNATT;
|
||||||
|
|
||||||
if (ctx->asynch_io) {
|
if (ctx->asynch_io) {
|
||||||
pthread_mutex_lock (&ctx->io_lock);
|
pthread_mutex_lock (&ctx->io_lock);
|
||||||
ctx->asynch_io = 0;
|
ctx->asynch_io = FALSE;
|
||||||
pthread_cond_signal (&ctx->io_cond);
|
pthread_cond_signal (&ctx->io_cond);
|
||||||
pthread_mutex_unlock (&ctx->io_lock);
|
pthread_mutex_unlock (&ctx->io_lock);
|
||||||
pthread_join (ctx->io_thread, NULL);
|
pthread_join (ctx->io_thread, NULL);
|
||||||
|
@ -636,7 +636,7 @@ DEVICE *dptr;
|
||||||
|
|
||||||
if ((dptr = find_dev_from_unit (uptr)) == NULL)
|
if ((dptr = find_dev_from_unit (uptr)) == NULL)
|
||||||
return SCPE_NOATT;
|
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)
|
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));
|
tape = ansi_create_tape (label, uptr->recsize, MT_GET_ANSI_TYP (uptr));
|
||||||
uptr->fileref = (FILE *)tape;
|
uptr->fileref = (FILE *)tape;
|
||||||
if (!uptr->fileref)
|
if (uptr->fileref == NULL)
|
||||||
return SCPE_MEM;
|
return SCPE_MEM;
|
||||||
while (*cptr != 0) { /* do all mods */
|
while (*cptr != 0) { /* do all mods */
|
||||||
uint32 initial_file_count = tape->file_count;
|
uint32 initial_file_count = tape->file_count;
|
||||||
|
@ -761,7 +761,7 @@ switch (MT_GET_FMT (uptr)) {
|
||||||
|
|
||||||
tape = memory_create_tape ();
|
tape = memory_create_tape ();
|
||||||
uptr->fileref = (FILE *)tape;
|
uptr->fileref = (FILE *)tape;
|
||||||
if (!uptr->fileref)
|
if (uptr->fileref == NULL)
|
||||||
return SCPE_MEM;
|
return SCPE_MEM;
|
||||||
f = fopen (cptr, "rb");
|
f = fopen (cptr, "rb");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
|
@ -769,7 +769,7 @@ switch (MT_GET_FMT (uptr)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tape_classify_file_contents (f, &max_record_size, &lf_line_endings, &crlf_line_endings);
|
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) {
|
if (uptr->recsize == 0) {
|
||||||
r = sim_messagef (SCPE_ARG, "Binary file %s must specify a record size with -B\n", cptr);
|
r = sim_messagef (SCPE_ARG, "Binary file %s must specify a record size with -B\n", cptr);
|
||||||
fclose (f);
|
fclose (f);
|
||||||
|
@ -835,7 +835,7 @@ switch (MT_GET_FMT (uptr)) {
|
||||||
tape = memory_create_tape();
|
tape = memory_create_tape();
|
||||||
tape->block_size = uptr->recsize;
|
tape->block_size = uptr->recsize;
|
||||||
uptr->fileref = (FILE *)tape;
|
uptr->fileref = (FILE *)tape;
|
||||||
if (!uptr->fileref)
|
if (uptr->fileref == NULL)
|
||||||
return SCPE_MEM;
|
return SCPE_MEM;
|
||||||
|
|
||||||
while (*cptr != 0) {
|
while (*cptr != 0) {
|
||||||
|
@ -4621,7 +4621,7 @@ long last_cr = -1;
|
||||||
long last_lf = -1;
|
long last_lf = -1;
|
||||||
long line_start = 0;
|
long line_start = 0;
|
||||||
int chr;
|
int chr;
|
||||||
long non_print_chars = 0;
|
t_bool non_print_chars = FALSE;
|
||||||
long lf_lines = 0;
|
long lf_lines = 0;
|
||||||
long crlf_lines = 0;
|
long crlf_lines = 0;
|
||||||
|
|
||||||
|
@ -4631,8 +4631,10 @@ long crlf_lines = 0;
|
||||||
rewind (f);
|
rewind (f);
|
||||||
while (EOF != (chr = fgetc (f))) {
|
while (EOF != (chr = fgetc (f))) {
|
||||||
++pos;
|
++pos;
|
||||||
if (!isprint (chr) && (chr != '\r') && (chr != '\n') && (chr != '\t') && (chr != '\f'))
|
if (!isprint (chr) && (chr != '\r') && (chr != '\n') && (chr != '\t') && (chr != '\f')) {
|
||||||
++non_print_chars;
|
non_print_chars = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (chr == '\r')
|
if (chr == '\r')
|
||||||
last_cr = pos;
|
last_cr = pos;
|
||||||
if (chr == '\n') {
|
if (chr == '\n') {
|
||||||
|
@ -4712,22 +4714,22 @@ 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, 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? */
|
||||||
memcpy (&hdr3, ansi->hdr3_fixed, sizeof (hdr3));
|
memcpy (&hdr3, ansi->hdr3_fixed, sizeof (hdr3));
|
||||||
else { /* Text file */
|
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));
|
memcpy (&hdr3, ansi->hdr3_lf_line_endings, sizeof (hdr3));
|
||||||
else
|
else
|
||||||
memcpy (&hdr3, ansi->hdr3_crlf_line_endings, sizeof (hdr3));
|
memcpy (&hdr3, ansi->hdr3_crlf_line_endings, sizeof (hdr3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memory_tape_add_block (tape, (uint8 *)&hdr1, sizeof (hdr1));
|
memory_tape_add_block (tape, (uint8 *)&hdr1, sizeof (hdr1));
|
||||||
if (!ansi->nohdr2)
|
if (!(ansi->nohdr2))
|
||||||
memory_tape_add_block (tape, (uint8 *)&hdr2, sizeof (hdr2));
|
memory_tape_add_block (tape, (uint8 *)&hdr2, sizeof (hdr2));
|
||||||
if (!ansi->nohdr3)
|
if (!(ansi->nohdr3))
|
||||||
memory_tape_add_block (tape, (uint8 *)&hdr3, sizeof (hdr3));
|
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, (uint8 *)&hdr4, sizeof (hdr4));
|
||||||
memory_tape_add_block (tape, NULL, 0); /* Tape Mark */
|
memory_tape_add_block (tape, NULL, 0); /* Tape Mark */
|
||||||
rewind (f);
|
rewind (f);
|
||||||
|
@ -4757,11 +4759,11 @@ memcpy (hdr4.type, "EOF", sizeof (hdr4.type));
|
||||||
sprintf (block_count_string, "%06d", block_count);
|
sprintf (block_count_string, "%06d", block_count);
|
||||||
memcpy (hdr1.block_count, block_count_string, sizeof (hdr1.block_count));
|
memcpy (hdr1.block_count, block_count_string, sizeof (hdr1.block_count));
|
||||||
memory_tape_add_block (tape, (uint8 *)&hdr1, sizeof (hdr1));
|
memory_tape_add_block (tape, (uint8 *)&hdr1, sizeof (hdr1));
|
||||||
if (!ansi->nohdr2)
|
if (!(ansi->nohdr2))
|
||||||
memory_tape_add_block (tape, (uint8 *)&hdr2, sizeof (hdr2));
|
memory_tape_add_block (tape, (uint8 *)&hdr2, sizeof (hdr2));
|
||||||
if (!ansi->nohdr3)
|
if (!(ansi->nohdr3))
|
||||||
memory_tape_add_block (tape, (uint8 *)&hdr3, sizeof (hdr3));
|
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, (uint8 *)&hdr4, sizeof (hdr4));
|
||||||
memory_tape_add_block (tape, NULL, 0); /* Tape Mark */
|
memory_tape_add_block (tape, NULL, 0); /* Tape Mark */
|
||||||
if (sim_switches & SWMASK ('V'))
|
if (sim_switches & SWMASK ('V'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue