Skip to content

Commit 28fd79e

Browse files
Bob Supnikmarkpizz
Bob Supnik
authored andcommitted
All LP and CD devices: Removed use of ftell for pipe compatibility
Merge changes from v3.12-2
1 parent 8d49d8c commit 28fd79e

File tree

16 files changed

+141
-95
lines changed

16 files changed

+141
-95
lines changed

H316/h316_lp.c

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* h316_lp.c: Honeywell 316/516 line printer
22
3-
Copyright (c) 1999-2015, Robert M. Supnik
3+
Copyright (c) 1999-2021, Robert M. Supnik
44
55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the "Software"),
@@ -25,7 +25,8 @@
2525
2626
lpt line printer
2727
28-
03-Jul-13 RLA compatibility changes for extended interrupts
28+
09-Jun-21 RMS Added error detection, removed use of ftell
29+
03-Jul-13 RLA Compatibility changes for extended interrupts
2930
09-Jun-07 RMS Fixed lost last print line (Theo Engel)
3031
19-Jan-06 RMS Added UNIT_TEXT flag
3132
03-Apr-06 RMS Fixed bug in blanks backscanning (Theo Engel)
@@ -321,7 +322,12 @@ if (lpt_svcst & LPT_SVCSH) { /* shuttling? */
321322
}
322323
lpt_buf[i + 1] = 0;
323324
fputs (lpt_buf, uptr->fileref); /* output buf */
324-
uptr->pos = ftell (uptr->fileref); /* update pos */
325+
if (ferror (uptr->fileref)) { /* error? */
326+
perror ("LPT I/O error");
327+
clearerr (uptr->fileref);
328+
return SCPE_IOERR;
329+
}
330+
uptr->pos = uptr->pos + strlen (lpt_buf); /* update pos */
325331
for (i = 0; i < LPT_WIDTH; i++) /* clear buf */
326332
lpt_buf[i] = ' ';
327333
lpt_prdn = 1; /* print done */
@@ -330,7 +336,12 @@ if (lpt_svcst & LPT_SVCSH) { /* shuttling? */
330336
if (lpt_svcst & LPT_SVCPA) { /* paper advance */
331337
SET_INT (INT_LPT); /* interrupt */
332338
fputs (lpt_cc[lpt_svcch & 03], uptr->fileref); /* output eol */
333-
uptr->pos = ftell (uptr->fileref); /* update pos */
339+
if (ferror (uptr->fileref)) { /* error? */
340+
perror ("LPT I/O error");
341+
clearerr (uptr->fileref);
342+
return SCPE_IOERR;
343+
}
344+
uptr->pos = uptr->pos + strlen (lpt_cc[lpt_svcch & 03]); /* update pos */
334345
}
335346
lpt_svcst = 0;
336347
return SCPE_OK;

I1401/i1401_cd.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* i1401_cd.c: IBM 1402 card reader/punch
22
3-
Copyright (c) 1993-2017, Robert M. Supnik
3+
Copyright (c) 1993-2021, Robert M. Supnik
44
55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the "Software"),
@@ -35,6 +35,7 @@
3535
Cards are represented as ASCII text streams terminated by newlines.
3636
This allows cards to be created and edited as normal files.
3737
38+
09-Jun-21 RMS Removed use of ftell on output for pipe compatibility
3839
09-Mar-17 RMS Protect character conversions from gargage files (COVERITY)
3940
05-May-16 RMS Fixed calling sequence inconsistency (Mark Pizzolato)
4041
28-Feb-15 RMS Added read from console
@@ -295,13 +296,13 @@ else uptr = &stack_unit[0]; /* then default */
295296
if ((uptr->flags & UNIT_ATT) == 0) /* attached? */
296297
return SCPE_OK;
297298
fputs (cdr_buf, uptr->fileref); /* write card */
298-
uptr->pos = ftell (uptr->fileref); /* update position */
299299
if (ferror (uptr->fileref)) { /* error? */
300300
sim_perror ("Card stacker I/O error");
301301
clearerr (uptr->fileref);
302302
if (iochk)
303303
return SCPE_IOERR;
304304
}
305+
uptr->pos = uptr->pos + strlen (cdr_buf); /* update position */
305306
return SCPE_OK;
306307
}
307308

@@ -375,14 +376,14 @@ if ((uptr->flags & UNIT_ATT) == 0) /* attached? */
375376
return SCPE_UNATT;
376377
fputs (cdp_buf, uptr->fileref); /* output card */
377378
fputc ('\n', uptr->fileref); /* plus new line */
378-
uptr->pos = ftell (uptr->fileref); /* update position */
379379
if (ferror (uptr->fileref)) { /* error? */
380380
sim_perror ("Card punch I/O error");
381381
clearerr (uptr->fileref);
382382
if (iochk)
383383
return SCPE_IOERR;
384384
ind[IN_PNCH] = 1;
385385
}
386+
uptr->pos = uptr->pos + strlen (cdp_buf) + 1; /* update position */
386387
return SCPE_OK;
387388
}
388389

I1401/i1401_lp.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* i1401_lp.c: IBM 1403 line printer simulator
22
3-
Copyright (c) 1993-2015, Robert M. Supnik
3+
Copyright (c) 1993-2021, Robert M. Supnik
44
55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the "Software"),
@@ -25,6 +25,7 @@
2525
2626
lpt 1403 line printer
2727
28+
09-Jun-21 RMS Removed use of ftell for pipe compatibility
2829
08-Mar-15 RMS Added print to console option
2930
16-Apr-13 RMS Fixed printer chain selection
3031
19-Jan-07 RMS Added UNIT_TEXT flag
@@ -245,19 +246,19 @@ if ((lpt_unit.flags & UNIT_ATT) != 0) { /* attached? */
245246
ind[IN_LPT] = 1;
246247
sim_perror ("Line printer I/O error");
247248
clearerr (lpt_unit.fileref);
248-
if (iochk)
249+
if (iochk != 0)
249250
return SCPE_IOERR;
250251
}
251-
lpt_unit.pos = ftell (lpt_unit.fileref); /* update position */
252+
lpt_unit.pos = lpt_unit.pos + strlen (buf); /* update position */
252253
return SCPE_OK;
253254
}
254-
if ((lpt_unit.flags & UNIT_CONS) != 0) { /* default to cons? */
255-
if (buf[0] == '\n') { /* bare lf? */
256-
inq_puts ("\r"); /* cvt to crlf */
255+
if ((lpt_unit.flags & UNIT_CONS) != 0) { /* default to cons? */
256+
if (buf[0] == '\n') { /* bare lf? */
257+
inq_puts ("\r"); /* cvt to crlf */
257258
lpt_unit.pos = lpt_unit.pos + 1;
258259
}
259260
inq_puts (buf);
260-
lpt_unit.pos = lpt_unit.pos + strlen (buf);
261+
lpt_unit.pos = lpt_unit.pos + strlen (buf); /* update position */
261262
return SCPE_OK;
262263
}
263264
return SCPE_UNATT;

I1620/i1620_cd.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* i1620_cd.c: IBM 1622 card reader/punch
22
3-
Copyright (c) 2002-2017, Robert M. Supnik
3+
Copyright (c) 2002-2021, Robert M. Supnik
44
55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the "Software"),
@@ -26,6 +26,7 @@
2626
cdr 1622 card reader
2727
cdp 1622 card punch
2828
29+
09-Jun-21 RMS Removed use of ftell on output for pipe compatibility
2930
23-Jun-17 RMS Unattached error does not set RDCHK/WRCHK
3031
09-Mar-17 RMS Guardbanded translation table lookups (COVERITY)
3132
31-Jan-15 TFM Changes to translation tables (Tom McBride)
@@ -528,13 +529,13 @@ cdp_buf[len] = '\n'; /* newline, null */
528529
cdp_buf[len + 1] = 0;
529530

530531
fputs (cdp_buf, cdp_unit.fileref); /* write card */
531-
cdp_unit.pos = ftell (cdp_unit.fileref); /* count char */
532532
if (ferror (cdp_unit.fileref)) { /* error? */
533533
ind[IN_WRCHK] = 1;
534534
sim_perror ("CDP I/O error");
535535
clearerr (cdp_unit.fileref);
536536
return SCPE_IOERR;
537537
}
538+
cdp_unit.pos = cdp_unit.pos + strlen (cdp_buf); /* update position */
538539
return SCPE_OK;
539540
}
540541

I1620/i1620_lp.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* i1620_lp.c: IBM 1443 line printer simulator
22
3-
Copyright (c) 2002-2017, Robert M. Supnik
3+
Copyright (c) 2002-2021, Robert M. Supnik
44
55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the "Software"),
@@ -25,6 +25,7 @@
2525
2626
lpt 1443 line printer
2727
28+
10-Jun-21 RMS Removed use of ftell for pipe compatibility
2829
15-Jun-17 RMS Fixed K constants and print-no-spacing (Tom McBride)
2930
Added option to emulate form feed with newlines
3031
31-Jan-15 TFM Fixed various problems ... see comments in code
@@ -279,7 +280,7 @@ return sta;
279280

280281
t_stat lpt_print (uint32 flag)
281282
{
282-
int32 i;
283+
int32 i, cc;
283284

284285
if ((lpt_unit.flags & UNIT_ATT) == 0) { /* not attached? */
285286
ind[IN_PRCHK] = 1; /* pri check */
@@ -292,16 +293,19 @@ while ((lpt_bptr > 0) && (lpt_buf[lpt_bptr - 1] == ' '))
292293
lpt_buf[--lpt_bptr] = 0; /* trim buffer */
293294
if (lpt_bptr != 0) { /* any line? */
294295
fputs (lpt_buf, lpt_unit.fileref); /* print */
295-
if ((flag & 1) != 0) /* no space? */
296+
cc = strlen (lpt_buf);
297+
if ((flag & 1) != 0) { /* no space? */
296298
fputc ('\r', lpt_unit.fileref); /* bare return */
297-
lpt_unit.pos = ftell (lpt_unit.fileref); /* update pos */
299+
cc++;
300+
}
298301
lpt_buf_init (); /* reinit buf */
299302
if (ferror (lpt_unit.fileref)) { /* error? */
300303
ind[IN_PRCHK] = 1; /* pri check */
301304
sim_perror ("LPT I/O error");
302305
clearerr (lpt_unit.fileref);
303306
return SCPE_IOERR;
304307
}
308+
lpt_unit.pos = lpt_unit.pos + (t_addr)cc; /* update pos */
305309
}
306310
if ((flag & 1) == 0) /* spacing? */
307311
return lpt_spcop (lpt_savctrl); /* execute */
@@ -336,17 +340,19 @@ return STOP_CCT; /* runaway channel */
336340

337341
t_stat lpt_space (int32 count, int32 sflag)
338342
{
339-
int32 i;
343+
int32 i, cc;
340344

341345
cct_ptr = (cct_ptr + count) % cct_lnt; /* adv cct, mod lnt */
342346
if (sflag && CHP (0, cct[cct_ptr]) && /* skip, top of form, */
343-
((lpt_unit.flags & UNIT_FF) != 0)) /* and use form feeds? */
347+
((lpt_unit.flags & UNIT_FF) != 0)) { /* and use form feeds? */
344348
fputs ("\n\f", lpt_unit.fileref); /* nl, ff */
349+
cc = 2;
350+
}
345351
else {
346352
for (i = 0; i < count; i++) /* count lines */
347353
fputc ('\n', lpt_unit.fileref);
354+
cc = count;
348355
}
349-
lpt_unit.pos = ftell (lpt_unit.fileref); /* update position */
350356
ind[IN_PRCH9] = CHP (9, cct[cct_ptr]) != 0; /* set indicators */
351357
ind[IN_PRCH12] = CHP (12, cct[cct_ptr]) != 0;
352358
if (ferror (lpt_unit.fileref)) { /* error? */
@@ -355,6 +361,7 @@ if (ferror (lpt_unit.fileref)) { /* error? */
355361
clearerr (lpt_unit.fileref);
356362
return SCPE_IOERR;
357363
}
364+
lpt_unit.pos = lpt_unit.pos + (t_addr)cc; /* update position */
358365
ind[IN_PRBSY] = 1; /* print busy */
359366
sim_activate (&lpt_unit, lpt_unit.wait); /* start timer */
360367
return SCPE_OK;

I7094/i7094_cd.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* i7094_cd.c: IBM 711/721 card reader/punch
22
3-
Copyright (c) 2003-2017, Robert M. Supnik
3+
Copyright (c) 2003-2021, Robert M. Supnik
44
55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the "Software"),
@@ -26,6 +26,7 @@
2626
cdr 711 card reader
2727
cdp 721 card punch
2828
29+
09-Jun-21 RMS Removed use of ftell on output for pipe compatibility
2930
13-Mar-17 RMS Annotated fall through in switch
3031
19-Mar-12 RMS Fixed declaration of sim_switches (Mark Pizzolato)
3132
19-Jan-07 RMS Added UNIT_TEXT
@@ -448,12 +449,12 @@ for (i = ((2 * CD_CHRLNT) + 1); (i > 0) &&
448449
cdp_cbuf[i++] = '\n'; /* append nl */
449450
cdp_cbuf[i++] = 0; /* append nul */
450451
fputs (cdp_cbuf, uptr->fileref); /* write card */
451-
uptr->pos = ftell (uptr->fileref); /* update position */
452452
if (ferror (uptr->fileref)) { /* error? */
453453
sim_perror ("CDP I/O error");
454454
clearerr (uptr->fileref);
455455
return SCPE_IOERR;
456456
}
457+
uptr->pos = uptr->pos + strlen (cdp_cbuf); /* update position */
457458
cdp_sta = CDS_END; /* end state */
458459
sim_cancel (uptr); /* cancel current */
459460
sim_activate (uptr, cdp_tstop); /* long timer */

I7094/i7094_lp.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* i7094_lp.c: IBM 716 line printer simulator
22
3-
Copyright (c) 2003-2017, Robert M. Supnik
3+
Copyright (c) 2003-2021, Robert M. Supnik
44
55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the "Software"),
@@ -25,6 +25,7 @@
2525
2626
lpt 716 line printer
2727
28+
09-Jun-21 RMS Removed use of ftell for pipe compatibility
2829
13-Mar-17 RMS Fixed GET_PCHAIN macro (COVERITY)
2930
19-Jan-07 RMS Added UNIT_TEXT flag
3031
@@ -331,12 +332,12 @@ lpt_cbuf[i] = 0; /* append nul */
331332
if (uptr->flags & UNIT_ATT) { /* file? */
332333
fputs (lpt_cbuf, uptr->fileref); /* write line */
333334
fputc ('\n', uptr->fileref); /* append nl */
334-
uptr->pos = ftell (uptr->fileref); /* update position */
335335
if (ferror (uptr->fileref)) { /* error? */
336336
sim_perror ("LPT I/O error");
337337
clearerr (uptr->fileref);
338338
return SCPE_IOERR;
339339
}
340+
uptr->pos = uptr->pos + strlen (lpt_cbuf) + 1; /* update pos, add nl */
340341
}
341342
else if (uptr->flags & UNIT_CONS) { /* print to console? */
342343
for (i = 0; lpt_cbuf[i] != 0; i++)

0 commit comments

Comments
 (0)