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
58
sim_tape.c
58
sim_tape.c
|
@ -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);
|
||||
|
@ -804,7 +804,7 @@ switch (MT_GET_FMT (uptr)) {
|
|||
if (sim_switches & SWMASK ('C')) {
|
||||
uint32 i;
|
||||
|
||||
for (i=0; i<uptr->recsize; i++)
|
||||
for (i = 0; i < uptr->recsize; i++)
|
||||
block[i] = ascii2ebcdic[block[i]];
|
||||
}
|
||||
error = memory_tape_add_block (tape, block, uptr->recsize);
|
||||
|
@ -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) {
|
||||
|
@ -1017,11 +1017,11 @@ return SCPE_OK;
|
|||
t_stat sim_tape_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr)
|
||||
{
|
||||
fprintf (st, "%s Tape Attach Help\n\n", dptr->name);
|
||||
if (0 == (uptr-dptr->units)) {
|
||||
if (0 == (uptr - dptr->units)) {
|
||||
if (dptr->numunits > 1) {
|
||||
uint32 i;
|
||||
|
||||
for (i=0; i < dptr->numunits; ++i)
|
||||
for (i = 0; i < dptr->numunits; ++i)
|
||||
if (dptr->units[i].flags & UNIT_ATTABLE)
|
||||
fprintf (st, " sim> ATTACH {switches} %s%d tapefile\n\n", dptr->name, i);
|
||||
}
|
||||
|
@ -1499,7 +1499,7 @@ switch (f) { /* otherwise the read method
|
|||
if (1) {
|
||||
MEMORY_TAPE *tape = (MEMORY_TAPE *)uptr->fileref;
|
||||
|
||||
if (uptr->pos >= tape->record_count)
|
||||
if (uptr->pos >= tape->record_count)
|
||||
status = MTSE_EOM;
|
||||
else {
|
||||
if (tape->records[uptr->pos]->size == 0)
|
||||
|
@ -4306,7 +4306,7 @@ static void ansi_make_HDR2 (HDR2 *hdr, t_bool fixed_record, size_t block_size, s
|
|||
hdr->record_format = ansi->record_format ? ansi->record_format : (fixed_record ? 'F' : 'D');
|
||||
sprintf (size, "%05d", (int)block_size);
|
||||
memcpy (hdr->block_length, size, sizeof (hdr->block_length));
|
||||
sprintf (size, "%05d", (ansi->zero_record_length)? 0 : (int)record_size);
|
||||
sprintf (size, "%05d", (ansi->zero_record_length) ? 0 : (int)record_size);
|
||||
memcpy (hdr->record_length, size, sizeof (hdr->record_length));
|
||||
hdr->carriage_control = ansi->carriage_control ? ansi->carriage_control : (fixed_record ? 'M' : ' ');
|
||||
memcpy (hdr->buffer_offset, "00", 2);
|
||||
|
@ -4399,7 +4399,7 @@ static void memory_free_tape (void *vtape)
|
|||
uint32 i;
|
||||
MEMORY_TAPE *tape = (MEMORY_TAPE *)vtape;
|
||||
|
||||
for (i=0; i<tape->record_count; i++) {
|
||||
for (i = 0; i < tape->record_count; i++) {
|
||||
free (tape->records[i]);
|
||||
tape->records[i] = NULL;
|
||||
}
|
||||
|
@ -4530,7 +4530,7 @@ while (year >= 2000)
|
|||
today = ((year - 70) * 1000) + tm->tm_yday + 1;
|
||||
|
||||
sprintf (FullPath, "%s%s", directory, filename);
|
||||
f = tape_open_and_check_file(FullPath);
|
||||
f = tape_open_and_check_file (FullPath);
|
||||
if (f == NULL)
|
||||
return;
|
||||
|
||||
|
@ -4588,7 +4588,7 @@ memory_tape_add_block (tape, NULL, 0);
|
|||
++tape->file_count;
|
||||
}
|
||||
|
||||
static FILE *tape_open_and_check_file(const char *filename)
|
||||
static FILE *tape_open_and_check_file (const char *filename)
|
||||
{
|
||||
FILE *file = fopen(filename, "rb");
|
||||
|
||||
|
@ -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') {
|
||||
|
@ -4700,7 +4702,7 @@ HDR2 hdr2;
|
|||
HDR3 hdr3;
|
||||
HDR4 hdr4;
|
||||
|
||||
f = tape_open_and_check_file(filename);
|
||||
f = tape_open_and_check_file (filename);
|
||||
if (f == NULL)
|
||||
return TRUE;
|
||||
|
||||
|
@ -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'))
|
||||
|
|
Loading…
Add table
Reference in a new issue