-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlp3000.c
1711 lines (1569 loc) · 54.2 KB
/
lp3000.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*--------------------------------------------------------------------------
**
** Copyright (c) 2003-2010, Tom Hunter, Paul Koning
** (c) 2017 Steven Zoppi 22-Oct-2017
** Added Ascii and ANSI support
** Added subdirectory support
** (c) 2022 Kevin Jordan 02-Dec-2022
** Redesign to expose format effectors properly
**
** Name: lp3000.c
**
** Description:
** Perform emulation of CDC 3000 series printers/controllers.
**
** This combines the 501 and 512 printers, and the 3152 and 3555
** controllers, because they all look pretty similar.
**
** 501 vs. 512 is selected by which Init function is called from
** init.c via the device table; 3555 is the default but 3152/3256/3659
** emulation can be selected by supplying a name string of "3152".
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License version 3 as
** published by the Free Software Foundation.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License version 3 for more details.
**
** You should have received a copy of the GNU General Public License
** version 3 along with this program in file "license-gpl-3.0.txt".
** If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
**
**--------------------------------------------------------------------------
*/
#define DEBUG 0
/*
** -------------
** Include Files
** -------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include "const.h"
#include "types.h"
#include "proto.h"
#include "dcc6681.h"
/*
** -----------------
** Private Constants
** -----------------
*/
// General
// Flags stored in the context field:
#define Lp3000Type501 000001
#define Lp3000Type512 000002
#define Lp3000Type3152 000010
#define Lp3000Type3555 000020
#define Lp3555FillImageMem 000100
#define Lp3000IntReady 000200 // Same code as int status bit
#define Lp3000IntEnd 000400 // ditto
#define Lp3000IntReadyEna 002000
#define Lp3000IntEndEna 004000
#define Lp3000ExtArray 010000
/*
** Function codes
*/
// Codes common to 3152/3256/3659 and 3555
#define FcPrintRelease 00000
#define FcPrintSingle 00001
#define FcPrintDouble 00002
#define FcPrintLastLine 00003
#define FcPrintEject 00004
#define FcPrintAutoEject 00005
#define FcPrintNoSpace 00006
// Codes for 3152/3256/3659
#define Fc3152ClearFormat 00010
#define Fc3152PostVFU1 00011
#define Fc3152PostVFU2 00012
#define Fc3152PostVFU3 00013
#define Fc3152PostVFU4 00014
#define Fc3152PostVFU5 00015
#define Fc3152PostVFU6 00016
#define Fc3152SelectPrePrint 00020
#define Fc3152PreVFU1 00021
#define Fc3152PreVFU2 00022
#define Fc3152PreVFU3 00023
#define Fc3152PreVFU4 00024
#define Fc3152PreVFU5 00025
#define Fc3152PreVFU6 00026
#define Fc3152SelIntReady 00030
#define Fc3152RelIntReady 00031
#define Fc3152SelIntEnd 00032
#define Fc3152RelIntEnd 00033
#define Fc3152SelIntError 00034
#define Fc3152RelIntError 00035
#define Fc3152Release2 00040
// Codes for 3555
#define Fc3555CondClearFormat 00007
#define Fc3555Sel8Lpi 00010
#define Fc3555Sel6Lpi 00011
#define Fc3555FillMemory 00012
#define Fc3555SelExtArray 00013
#define Fc3555ClearExtArray 00014
#define Fc3555SelIntReady 00020
#define Fc3555RelIntReady 00021
#define Fc3555SelIntEnd 00022
#define Fc3555RelIntEnd 00023
#define Fc3555SelIntError 00024
#define Fc3555RelIntError 00025
#define Fc3555ReloadMemEnable 00026
#define Fc3555ClearFormat 00030
#define Fc3555PostVFU1 00031
#define Fc3555PostVFU2 00032
#define Fc3555PostVFU3 00033
#define Fc3555PostVFU4 00034
#define Fc3555PostVFU5 00035
#define Fc3555PostVFU6 00036
#define Fc3555PostVFU7 00037
#define Fc3555PostVFU8 00040
#define Fc3555PostVFU9 00041
#define Fc3555PostVFU10 00042
#define Fc3555PostVFU11 00043
#define Fc3555PostVFU12 00044
#define Fc3555SelectPrePrint 00050
#define Fc3555PreVFU1 00051
#define Fc3555PreVFU2 00052
#define Fc3555PreVFU3 00053
#define Fc3555PreVFU4 00054
#define Fc3555PreVFU5 00055
#define Fc3555PreVFU6 00056
#define Fc3555PreVFU7 00057
#define Fc3555PreVFU8 00060
#define Fc3555PreVFU9 00061
#define Fc3555PreVFU10 00062
#define Fc3555PreVFU11 00063
#define Fc3555PreVFU12 00064
#define Fc3555MaintStatus 00065
#define Fc3555ClearMaint 00066
/*
** Output rendering modes
*/
#define ModeCDC 0
#define ModeANSI 1
#define ModeASCII 2
/*
** Maximum number of characters per line
*/
#define MaxLineSize 140
/*
** Status reply
**
** 3152/3256/3659 vs. 3555 have different status codes for the
** most part, but the few we care about are common:
**
*/
#define StPrintReady 00001
#define StPrintIntReady 00200
#define StPrintIntEnd 00400
/*
** -----------------------
** Private Macro Functions
** -----------------------
*/
/*
** -----------------------------------------
** Private Typedef and Structure Definitions
** -----------------------------------------
*/
typedef struct lpContext
{
/*
** Info for show_tape operator command.
*/
struct lpContext *nextUnit;
u8 channelNo;
u8 eqNo;
u8 unitNo;
u16 flags;
bool isPrinted;
bool keepInt;
u8 renderingMode; // one of ModeCDC, modeANSI, or mode ASCII
u8 prePrintFunc; // last pre-print function (0 = no pre-print function specified)
u8 postPrintFunc; // last post-print function (0 = no post-print function specified)
bool doAutoEject; // auto-eject pages
bool doSuppress; // suppress next post-print spacing op
u8 lpi; // Lines Per Inch 6 or 8 (usually)
PpWord line[MaxLineSize]; // buffered line
u8 linePos; // current line position
bool doBurst; // bursting option for forced segmentation at EOJ
char path[MaxFSPath]; // preserve the device folder path
char curFileName[MaxFSPath+128];
} LpContext;
/*
** ---------------------------
** Private Function Prototypes
** ---------------------------
*/
static void lp3000Init(u16 lpType, u8 eqNo, u8 unitNo, u8 channelNo, char *deviceParams);
static char *lp3000FeForPostPrint(LpContext *lc, u8 func);
static char *lp3000FeForPrePrint(LpContext *lc, u8 func);
static FcStatus lp3000Func(PpWord funcCode);
static void lp3000Io(void);
static void lp3000Activate(void);
static void lp3000Disconnect(void);
static void lp3000PrintANSI(LpContext *lc, FILE *fcb);
static void lp3000PrintASCII(LpContext *lc, FILE *fcb);
static void lp3000PrintCDC(LpContext *lc, FILE *fcb);
#if DEBUG
static void lp3000DebugData(LpContext *lc);
static char *lp3000Func2String(LpContext *lc, PpWord funcCode);
#endif
/*
** ----------------
** Public Variables
** ----------------
*/
/*
** -----------------
** Private Variables
** -----------------
*/
static LpContext *firstUnit = NULL;
static LpContext *lastUnit = NULL;
static char *postPrintCdcEffectors[] = {
"H", // advance to channel 1
"G", // advance to channel 2
"F", // advance to channel 3
"E", // advance to channel 4
"D", // advance to channel 5
"C", // advance to channel 6
"I", // advance to channel 7
"J", // advance to channel 8
"K", // advance to channel 9
"L", // advance to channel 10
"M", // advance to channel 11
"N" // advance to channel 12
};
static char *prePrintAnsiEffectors[] = {
"1", // advance to channel 1
"2", // advance to channel 2
"3", // advance to channel 3
"4", // advance to channel 4
"5", // advance to channel 5
"6", // advance to channel 6
"7", // advance to channel 7
"8", // advance to channel 8
"9", // advance to channel 9
"A", // advance to channel 10
"B", // advance to channel 11
"C" // advance to channel 12
};
static char *prePrintCdcEffectors[] = {
"8", // advance to channel 1
"7", // advance to channel 2
"6", // advance to channel 3
"5", // advance to channel 4
"4", // advance to channel 5
"3", // advance to channel 6
"9", // advance to channel 7
"X", // advance to channel 8
"Y", // advance to channel 9
"Z", // advance to channel 10
"W", // advance to channel 11
"U" // advance to channel 12
};
static char *renderingModes[] = {
"CDC",
"ANSI",
"ASCII"
};
#if DEBUG
static FILE *lp3000Log = NULL;
#endif
/*
**--------------------------------------------------------------------------
**
** Public Functions
**
**--------------------------------------------------------------------------
*/
/*--------------------------------------------------------------------------
** Purpose: Initialise 501 line printer.
**
** Parameters: Name Description.
** eqNo equipment number
** unitNo unit number
** channelNo channel number the device is attached to
** deviceParams Comma Delimited Parameters
** <devicePath> Path to Output Files
** <deviceType> "3152" to get 3152 controller
** null or "3555" for 3555
** <deviceMode> "ansi" or "ascii" for output type
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void lp501Init(u8 eqNo, u8 unitNo, u8 channelNo, char *deviceParams)
{
lp3000Init(Lp3000Type501, eqNo, unitNo, channelNo, deviceParams);
}
/*--------------------------------------------------------------------------
** Purpose: Initialise 512 line printer.
**
** Parameters: Name Description.
** eqNo equipment number
** unitNo unit number
** channelNo channel number the device is attached to
** deviceParams Comma Delimited Parameters
** <devicePath> Path to Output Files
** <deviceType> "3152" to get 3152 controller
** null or "3555" for 3555
** <deviceMode> "ansi" or "ascii" for output type
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void lp512Init(u8 eqNo, u8 unitNo, u8 channelNo, char *deviceParams)
{
lp3000Init(Lp3000Type512, eqNo, unitNo, channelNo, deviceParams);
}
/*
**--------------------------------------------------------------------------
**
** Private Functions
**
**--------------------------------------------------------------------------
*/
/*--------------------------------------------------------------------------
** Purpose: Initialise 3000 class line printer.
**
** Parameters: Name Description.
** lpType printer type (Lp3000Type501 or Lp3000Type512)
** eqNo equipment number
** unitNo unit number
** channelNo channel number the device is attached to
** flags Printer type flags
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
static void lp3000Init(u16 lpType, u8 eqNo, u8 unitNo, u8 channelNo, char *deviceParams)
{
char *burstMode;
char *deviceMode;
char *devicePath;
char *deviceType;
u16 flags;
bool isBursting;
LpContext *lc;
char *lpTypeName;
u8 mode;
DevSlot *up;
#if DEBUG
if (lp3000Log == NULL)
{
lp3000Log = fopen("lp3000log.txt", "wt");
}
#endif
flags = lpType;
lpTypeName = (lpType == Lp3000Type501) ? "LP501" : "LP512",
/*
** When we are called, "deviceParams" is a space terminated string
** at the end of the INI entry.
**
** Tokenizing the remainder of the string as comma-delimited
** parameters gives us the configuration data that we need.
**
** The format of the remainder of the line is:
**
** <DeviceType> (NULL(="3555")|"3555"|"3152")
** <devicePath>
** <OutputMode> ("CDC"|"ANSI"|"ASCII")
** <BurstingMode> ("Burst"|"NoBurst")
**
*/
deviceType = strtok(deviceParams, ", "); // "3555" | "3152"
devicePath = strtok(NULL, ", "); // Get the Path (subdirectory)
deviceMode = strtok(NULL, ", "); // pick up "cdc", "ansi", or "ascii"
burstMode = strtok(NULL, ", "); // Indication for bursting
mode = ModeCDC;
if (deviceMode != NULL)
{
if (strcasecmp(deviceMode, "cdc") == 0)
{
mode = ModeCDC;
}
else if (strcasecmp(deviceMode, "ansi") == 0)
{
mode = ModeANSI;
}
else if (strcasecmp(deviceMode, "ascii") == 0)
{
mode = ModeASCII;
}
else
{
fprintf(stderr, "(lp3000 ) %s Unrecognized output rendering mode '%s'\n", lpTypeName, deviceMode);
exit(1);
}
}
fprintf(stdout, "(lp3000 ) %s Output rendering mode '%s'\n", lpTypeName, renderingModes[mode]);
/*
** This is an optional parameter, therefore the default prevails
** lack of presence will not constitute failure.
*/
isBursting = FALSE;
if (burstMode != NULL)
{
if (strcasecmp(burstMode, "burst") == 0)
{
if (strcasecmp(osType, "nos") == 0 || strcasecmp(osType, "kronos") == 0)
{
isBursting = TRUE;
}
else
{
fprintf(stderr, "(lp3000 ) %s WARNING: BURST mode ignored; applies only to NOS operating systems\n", lpTypeName);
}
}
else if (strcasecmp(burstMode, "noburst") == 0)
{
isBursting = FALSE;
}
else
{
fprintf(stderr, "(lp3000 ) %s Unrecognized BURST mode '%s'\n", lpTypeName, burstMode);
exit(1);
}
}
fprintf(stdout, "(lp3000 ) %s Burst mode '%s'\n", lpTypeName, isBursting ? "Bursting" : "Non-Bursting");
if (deviceType == NULL
|| strcmp(deviceType, "3555") == 0)
{
flags |= Lp3000Type3555;
}
else if (strcmp(deviceType, "3152") == 0)
{
flags |= Lp3000Type3152;
}
else
{
fprintf(stderr, "(lp3000 ) Unrecognized %s controller type %s\n", lpTypeName, deviceType);
exit(1);
}
up = dcc6681Attach(channelNo, eqNo, unitNo, DtLp5xx);
up->activate = lp3000Activate;
up->disconnect = lp3000Disconnect;
up->func = lp3000Func;
up->io = lp3000Io;
/*
** Only one printer unit is possible per equipment.
*/
if (up->context[0] != NULL)
{
fprintf(stderr, "(lp3000 ) Only one LP5xx unit is possible per equipment\n");
exit(1);
}
lc = (LpContext *)calloc(1, sizeof(LpContext));
if (lc == NULL)
{
fprintf(stderr, "(lp3000 ) Failed to allocate LP5xx context block\n");
exit(1);
}
up->context[0] = (void *)lc;
lc->flags = flags;
lc->lpi = 6; // Default print density
lc->linePos = 0;
lc->prePrintFunc = 0;
lc->postPrintFunc = 0;
lc->doAutoEject = FALSE; // Clear auto-eject
lc->doSuppress = FALSE; // Clear suppress space
lc->doBurst = isBursting; // Whether or not we force segmentation at EOJ
lc->renderingMode = mode; // Indicate how to handle Carriage Control
lc->channelNo = channelNo;
lc->unitNo = unitNo;
lc->eqNo = eqNo;
lc->path[0] = '\0';
/*
** Remember the device Path for future fopen calls
*/
if (devicePath == NULL)
{
lc->path[0] = '\0';
}
else
{
strcpy(lc->path, devicePath);
if (lc->path[0] != '\0')
{
strcat(lc->path, "/");
}
}
/*
** Open the device file.
*/
sprintf(lc->curFileName, "%sLP5xx_C%02o_E%o", lc->path, channelNo, eqNo);
up->fcb[0] = fopen(lc->curFileName, "w");
if (up->fcb[0] == NULL)
{
fprintf(stderr, "(lp3000 ) Failed to open %s\n", lc->curFileName);
exit(1);
}
/*
** Print a friendly message.
*/
printf("(lp3000 ) LP%d/%d initialised on channel %o equipment %o mode %s filename '%s'\n",
(flags & Lp3000Type3555) ? 3555 : 3152,
(flags & Lp3000Type501) ? 501 : 512,
channelNo, eqNo, renderingModes[mode], lc->curFileName);
/*
** Link into list of Line Printer units.
*/
if (lastUnit == NULL)
{
firstUnit = lc;
}
else
{
lastUnit->nextUnit = lc;
}
lastUnit = lc;
}
/*--------------------------------------------------------------------------
** Purpose: Show Line Printer Status (operator interface).
**
** Parameters: Name Description.
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void lp3000ShowStatus()
{
LpContext *lc;
char lpType[10];
char outBuf[MaxFSPath+128];
for (lc = firstUnit; lc != NULL; lc = lc->nextUnit)
{
sprintf(lpType, "%s/%s", (lc->flags & Lp3000Type3555) ? "3555" : "3152", (lc->flags & Lp3000Type501) ? "501" : "512");
sprintf(outBuf, " > %-8s C%02o E%02o U%02o", lpType, lc->channelNo, lc->eqNo, lc->unitNo);
opDisplay(outBuf);
sprintf(outBuf, " %-20s (mode ", lc->curFileName);
opDisplay(outBuf);
opDisplay(renderingModes[lc->renderingMode]);
sprintf(outBuf, ", %d lpi", lc->lpi);
opDisplay(outBuf);
if (lc->doBurst) opDisplay(", burst");
opDisplay(")\n");
}
}
/*--------------------------------------------------------------------------
** Purpose: Remove the paper (operator interface).
**
** Parameters: Name Description.
** params parameters
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void lp3000RemovePaper(char *params)
{
int channelNo;
time_t currentTime;
DevSlot *dp;
int equipmentNo;
char fNameNew[MaxFSPath+128];
int iSuffix;
LpContext *lc;
int numParam;
char outBuf[MaxFSPath*2+300];
bool renameOK;
struct tm t;
/*
** Operator wants to remove paper.
*/
numParam = sscanf(params, "%o,%o,%s", &channelNo, &equipmentNo, fNameNew);
/*
** Check parameters.
*/
if (numParam < 2)
{
opDisplay("(lp3000 ) Not enough or invalid parameters\n");
return;
}
if ((channelNo < 0) || (channelNo >= MaxChannels))
{
opDisplay("(lp3000 ) Invalid channel no\n");
return;
}
if ((equipmentNo < 0) || (equipmentNo >= MaxEquipment))
{
opDisplay("(lp3000 ) Invalid equipment no\n");
return;
}
/*
** Locate the device control block.
*/
dp = dcc6681FindDevice((u8)channelNo, (u8)equipmentNo, DtLp5xx);
if (dp == NULL)
{
sprintf(outBuf, "(lp3000 ) No printer on channel %o and equipment %o\n", channelNo, equipmentNo);
opDisplay(outBuf);
return;
}
lc = (LpContext *)dp->context[0];
renameOK = FALSE;
//
// This can happen if something goes wrong in the open and the file fails
// to be properly re-opened.
//
if (dp->fcb[0] == NULL)
{
fprintf(stderr, "(lp3000 ) lp3000RemovePaper: FCB is null on channel %o equipment %o\n",
dp->channel->id,
dp->eqNo);
// proceed to attempt to open a new FCB
}
else
{
fflush(dp->fcb[0]);
if (ftell(dp->fcb[0]) == 0)
{
sprintf(outBuf, "(lp3000 ) No output has been written on channel %o and equipment %o\n", channelNo, equipmentNo);
opDisplay(outBuf);
return;
}
/*
** Close the old device file.
*/
fclose(dp->fcb[0]);
dp->fcb[0] = NULL;
if (numParam > 2)
{
if (rename(lc->curFileName, fNameNew) == 0)
{
renameOK = TRUE;
}
else
{
sprintf(outBuf, "(lp3000 ) Rename Failure '%s' to '%s' - (%s).\n", lc->curFileName, fNameNew, strerror(errno));
opDisplay(outBuf);
}
}
else
{
/*
** Rename the device file to the format "LP5xx_yyyymmdd_hhmmss_nn.txt".
*/
for (iSuffix = 0; iSuffix < 100; iSuffix++)
{
time(¤tTime);
t = *localtime(¤tTime);
sprintf(fNameNew, "%sLP5xx_%04d%02d%02d_%02d%02d%02d_%02d.txt",
lc->path,
t.tm_year + 1900,
t.tm_mon + 1,
t.tm_mday,
t.tm_hour,
t.tm_min,
t.tm_sec,
iSuffix);
if (rename(lc->curFileName, fNameNew) == 0)
{
renameOK = TRUE;
break;
}
fprintf(stderr, "(lp3000 ) Rename Failure '%s' to '%s' - (%s). Retrying (%d)...\n",
lc->curFileName,
fNameNew,
strerror(errno),
iSuffix);
}
}
}
/*
** Open the device file.
*/
// Just append to the old file if the rename didn't happen correctly
dp->fcb[0] = fopen(lc->curFileName, renameOK ? "w" : "a");
/*
** Check if the open succeeded.
*/
if (dp->fcb[0] == NULL)
{
fprintf(stderr, "Failed to open %s\n", lc->curFileName);
return;
}
if (renameOK)
{
sprintf(outBuf, "(lp3000 ) Paper removed from 5xx printer and available on '%s'\n", fNameNew);
opDisplay(outBuf);
}
}
/*--------------------------------------------------------------------------
** Purpose: Execute function code on 3000 line printer.
**
** Parameters: Name Description.
** funcCode function code
**
** Returns: FcStatus
**
**------------------------------------------------------------------------*/
static FcStatus lp3000Func(PpWord funcCode)
{
FILE *fcb;
LpContext *lc;
char dispLpDevId[16]; // Used for automatically removing printouts at EOJ
unsigned int channelId;
unsigned int deviceId;
fcb = active3000Device->fcb[0];
lc = (LpContext *)active3000Device->context[0];
/*
** This can happen if something goes wrong in the open and the file fails
** to be properly re-opened.
*/
if (fcb == NULL)
{
fprintf(stderr, "(lp3000 ) lp3000Func: FCB is null on channel %o equipment %o\n",
active3000Device->channel->id,
active3000Device->eqNo);
return FcProcessed;
}
#if DEBUG
fprintf(lp3000Log, "\n%06d PP:%02o CH:%02o f:%04o T:%-25s > ",
traceSequenceNo,
activePpu->id,
activeDevice->channel->id,
funcCode,
lp3000Func2String(lc, funcCode));
#endif
// Start with the common codes
switch (funcCode)
{
case FcPrintNoSpace:
lc->doSuppress = TRUE;
return FcProcessed;
case FcPrintAutoEject:
if (lc->renderingMode != ModeASCII && lc->doAutoEject == FALSE) fputs("R\n", fcb);
lc->doAutoEject = TRUE;
return FcProcessed;
case Fc6681MasterClear:
lc->lpi = 6;
lc->linePos = 0;
lc->prePrintFunc = 0;
lc->postPrintFunc = 0;
lc->doAutoEject = FALSE;
lc->doSuppress = FALSE;
lc->flags &= ~Lp3000ExtArray;
return FcProcessed;
case FcPrintRelease:
// clear all interrupt conditions
lc->flags &= ~(StPrintIntReady | StPrintIntEnd);
fflush(fcb);
// Release is sent at end of job, so flush the print file
if (lc->isPrinted && lc->doBurst)
{
channelId = (int)active3000Device->channel->id;
deviceId = (int)active3000Device->eqNo;
sprintf(dispLpDevId, "%o,%o", channelId, deviceId);
lp3000RemovePaper(dispLpDevId);
}
lc->isPrinted = FALSE;
return FcProcessed;
case FcPrintSingle:
case FcPrintDouble:
case FcPrintLastLine:
case FcPrintEject:
if (lc->prePrintFunc != 0 && lc->prePrintFunc != FcPrintNoSpace)
{
fputs(lp3000FeForPrePrint(lc, lc->prePrintFunc), fcb);
fputc('\n', fcb);
}
lc->prePrintFunc = (u8)funcCode;
return FcProcessed;
case Fc6681Output:
if (lc->flags & Lp3555FillImageMem)
{
// Tweak the function code to tell I/O handler to toss this data
funcCode += 1;
// Now clear the flag
lc->flags &= ~Lp3555FillImageMem;
}
// Initially clear interrupt status flags
lc->flags &= ~(StPrintIntReady | StPrintIntEnd);
// Update interrupt status to reflect what status
// will be when this transfer is finished.
// Ok, so that's cheating a bit...
if (lc->flags & Lp3000IntReadyEna)
{
lc->flags |= Lp3000IntReady;
}
if (lc->flags & Lp3000IntEndEna)
{
lc->flags |= Lp3000IntEnd;
}
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
active3000Device->fcode = funcCode;
return FcAccepted;
case Fc6681DevStatusReq:
active3000Device->fcode = funcCode;
return FcAccepted;
}
if (lc->flags & Lp3000Type3555) // This is LP3555
{
switch (funcCode)
{
default:
fprintf(stderr, "(lp3000 ) Unknown LP3555 function %04o\n", funcCode);
return FcDeclined;
case Fc3555Sel8Lpi:
if (lc->renderingMode != ModeASCII && lc->lpi != 8) fputs("T\n", fcb);
lc->lpi = 8;
return FcProcessed;
case Fc3555Sel6Lpi:
if (lc->renderingMode != ModeASCII && lc->lpi != 6) fputs("S\n", fcb);
lc->lpi = 6;
return FcProcessed;
case Fc3555ClearFormat:
if (lc->renderingMode != ModeASCII
&& (lc->lpi != 6 || lc->doAutoEject)) fputs("Q\n", fcb);
case Fc3555CondClearFormat:
lc->postPrintFunc = 0;
lc->lpi = 6;
lc->doAutoEject = FALSE;
lc->doSuppress = FALSE;
return FcProcessed;
case Fc3555PostVFU1:
case Fc3555PostVFU2:
case Fc3555PostVFU3:
case Fc3555PostVFU4:
case Fc3555PostVFU5:
case Fc3555PostVFU6:
case Fc3555PostVFU7:
case Fc3555PostVFU8:
case Fc3555PostVFU9:
case Fc3555PostVFU10:
case Fc3555PostVFU11:
case Fc3555PostVFU12:
lc->postPrintFunc = (u8)funcCode;
return FcProcessed;
case Fc3555SelectPrePrint:
lc->postPrintFunc = 0;
return FcProcessed;
case Fc3555PreVFU1:
case Fc3555PreVFU2:
case Fc3555PreVFU3:
case Fc3555PreVFU4:
case Fc3555PreVFU5:
case Fc3555PreVFU6:
case Fc3555PreVFU7:
case Fc3555PreVFU8:
case Fc3555PreVFU9:
case Fc3555PreVFU10:
case Fc3555PreVFU11:
case Fc3555PreVFU12:
lc->prePrintFunc = (u8)funcCode;
return FcProcessed;
case Fc3555FillMemory:
// Remember that we saw this function, but this doesn't actually
// start any I/O yet.
lc->flags |= Lp3555FillImageMem;
return FcProcessed;
case Fc3555SelIntReady:
// Enable next int. If an I/O was done since the last
// time an int enable was issued, don't clear the
// current int. That's because things go very slowly
// otherwise; printer drivers typically issue the write,
// then enable the int shortly after. We've already set
// "ready" by then, unlike physical printers.
lc->flags |= Lp3000IntReady | Lp3000IntReadyEna;
if (lc->keepInt)
{
lc->keepInt = FALSE;
}
else
{
lc->flags &= ~Lp3000IntReady;
}
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return FcProcessed;
case Fc3555RelIntReady:
lc->flags &= ~(Lp3000IntReadyEna | Lp3000IntReady);
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return FcProcessed;
case Fc3555SelIntEnd:
lc->flags |= Lp3000IntEnd | Lp3000IntEndEna;
if (lc->keepInt)
{
lc->keepInt = FALSE;
}
else
{