app/mpg/2.2/src/GRAPHIK.Manager

Raw file
Back to index

  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
(**************************************************************************) 
(*                                                                        *) 
(*                        MPG - Graphik - System                          *) 
(*                                                                        *) 
(*                      Version 2.2 vom 23.09.1987                        *) 
(*                                                                        *) 
(*            (c) 1987 Beat Jegerlehner & Carsten Weinholz                *) 
(*                unter Verwendung der Standard-Graphik                   *) 
(*           "Graphik-Plotmanager" geschrieben von C.Weinholz             *) 
(*                                                                        *) 
(**************************************************************************) 
(*                                                                        *)
(*            Dieses Paket stellt den Multispool-Ausgabemanager           *)
(*                            zur Verfuegung.                             *)
(*                 Er wird in der Regel durch Aufruf von                  *)
(*        'generate plot manager' in GRAPHIK in einer neuerzeugten        *)
(*                      Sohntask 'PLOT' installiert.                      *)
(*                                                                        *)
(**************************************************************************)
(*   Urversion  : 10.09.87                                                *)
(*   Aenderungen: 23.09.87, Carsten Weinholz                              *)
(*                Kommando 'spool control ("TEXT")' im Plot-Monitor       *)
(*                Anzeige von 'order tasks' anderer Stationen             *)
(*                11.1.88, Thomas Clermont                                *)
(*                Fehler 'Zu viele DATASPACEs' und                        *)
(*                Spooling von zwei gleichnamigen JOBs behoben.           *)
(*   Fehler     : Keine bekannt.                                          *)
(**************************************************************************)
PACKET plot manager DEFINES plot manager ,
                            plot server  :

LET max spools  = 14,         (* Hinweis: max spools + dataspaces +      *)
    max entries = 14,         (*          max spools * max entries < 250 *)
 
    ack                 = 0,
    second phase ack    = 5,
    false code          = 6,
    fetch code          = 11,
    save  code          = 12,
    existscode          = 13,
    erase code          = 14,
    list  code          = 15,
    all   code          = 17,
    first code          = 25,
    start code          = 26,
    stop  code          = 27,
    halt code           = 28,
    wait for halt  code = 29,
    continue code       = 100,
    picfiletype = 1102,

    trenn       = "/",

    MSG         = STRUCT (TEXT ds name, dev name, passwd, INT dev no),

    JOB         = STRUCT (DATASPACE ds, TEXT ds name, TASK order task),
 
    ENTRY       = STRUCT (JOB job, INT link), 
 
    CHAIN       = STRUCT (ROW max entries ENTRY entry, INT first, last, empty), 
 
    SERVER      = STRUCT (TASK task, wait for halt, REAL time,
                          JOB current job, BOOL stopped, INT link);
 
ROW max spools STRUCT (SERVER server, CHAIN chain) VAR device; 

MSG VAR msg;

INT VAR entry to erase, last created server, reply, current plotter;
FILE VAR chain info;
THESAURUS VAR managed plotter;
BOUND THESAURUS VAR thesaurus msg;
DATASPACE VAR reply ds;
TASK VAR control task;

(********************************* SPOOL ***********************************)

PROC plot manager :
   INT VAR act dev;
   managed plotter := plotters LIKE (text (station (myself)) + any);
   FOR act dev FROM 1 UPTO max devices REP
      init device (act dev)
   PER;
   control task := niltask;
   end global manager (FALSE);
   global manager (PROC (DATASPACE VAR,INT CONST,INT CONST,TASK CONST)plot manager)
END PROC plot manager;

PROC plot manager (DATASPACE VAR ds, INT CONST order, phase, TASK CONST order task):
   enable stop;
   INT VAR act dev;
   SELECT order OF 
     CASE fetch code : y fetch 
     CASE save code  : y save 
     CASE exists code: y exists
     CASE erase code : y erase 
     CASE list code  : y list 
     CASE all code   : y all 
     OTHERWISE IF order >= continue code AND order task = supervisor
                  THEN forget (ds);
                       continue (order - continue code);
                       spool monitor
                  ELIF priv control op
                       THEN SELECT order OF
                              CASE first code : y first
                              CASE start code : y start
                              CASE stop code  : y stop
                              CASE halt code  : y halt
                              CASE wait for halt code : y halt
                              OTHERWISE order error
                            ENDSELECT
                       ELSE order error
               FI;
   END SELECT;
   BOOL VAR test;
   FOR act dev FROM 1 UPTO max devices REP
      test := server is active (act dev)
   PER;
   forget (ds).

   priv control op:
      (order task = father) OR (order task < supervisor) OR
      spool control task.

  spool control task:
     NOT (order task = niltask) CAND
     ((order task = control task) OR (order task < control task)).

  y fetch: 
     FOR act dev FROM 1 UPTO max devices REP 
     UNTIL act server.task = order task  PER;
     IF act dev > max devices
        THEN order error 
     ELIF chain is empty (act dev) OR act server.stopped
        THEN end server (act dev);
             IF exists (act server.wait for halt)
                THEN send (act server.wait for halt, ack);
                     act server.wait for halt := niltask
             FI
        ELSE transfer next job (act dev); 
             send current job (act dev) 
     FI.

  y save: 
     IF phase = 1 
        THEN y save pre 
        ELSE y save post 
     FI. 
 
     y save pre: 
        link dev;
        IF act dev = 0 
           THEN device error
        ELIF chain is full (act dev)
           THEN errorstop ("SPOOL ist voll")
           ELSE send (order task, second phase ack) 
        FI. 
 
     y save post: 
        act dev := msg.dev no;
        IF type (ds) <> picfile type 
           THEN errorstop ("Datenraum hat falschen Typ") 
           ELSE entry into chain (act dev, new job);
                forget (ds);
                IF NOT (server is active (act dev) OR act server.stopped)
                   THEN create server (act dev)
                FI;
                send ack
        FI.
 
        new job: 
           JOB : (ds, msg.ds name, order task).
 
  y exists:
     link dev;
     IF find entry (msg.ds name,act dev,order task, priv control op) = 0
        THEN send (order task, false code, ds)
        ELSE send ack
     FI.

  y erase:
     IF phase = 1
        THEN link dev;
             IF act dev > 0
                THEN y erase pre
                ELSE device error
             FI
        ELSE erase entry (act dev, entry to erase);
             send ack
     FI.

     y erase pre: 
        entry to erase := find entry (msg.ds name,act dev, order task, priv control op);
        IF order not from job order task AND NOT priv control op
           THEN errorstop ("Kein Zugriffsrecht auf Auftrag """ + msg.ds name + """")
        ELIF entry to erase = 0
           THEN manager message ("""" + msg.ds name + """ existiert nicht")
           ELSE manager question (erase msg)
        FI.

        erase msg:
           TASK VAR owner ::act chain.entry [entry to erase].job.order task;
           owner id (owner) + "/ """ + msg.ds name +
           """ in Spool """ + name (managed plotter, act dev) +
           """ loeschen".

        order not from job order task:
           NOT (act chain.entry [entry to erase].job.order task = order task).

  y list:
     link dev;
     create chain list (act dev);
     send (order task, ack, reply ds).

  y all:
     link dev;
     forget (reply ds);
     reply ds := nilspace;
     thesaurus msg := reply ds;
     thesaurus msg := chain thesaurus (act dev, owner or priv task, FALSE);
     send (order task, ack, reply ds).

     owner or priv task:
        IF priv control op
           THEN niltask
           ELSE order task
        FI.

  y start:
     link dev;
     IF act dev = 0
        THEN FOR act dev FROM 1 UPTO max devices REP
                 start (act dev)
             PER
        ELSE start (act dev)
     FI;
     send ack.
     
  y stop:
     IF phase = 1
        THEN y stop pre
        ELSE y stop post
     FI.

  y stop pre:
     link dev;
     IF act dev > 0
        THEN stop (act dev);
             IF NOT is no job (act server.current job)
                THEN manager question ("""" + act server.current job.ds name
                     + """ neu eintragen")
                ELSE send ack
             FI
        ELSE FOR act dev FROM 1 UPTO max devices REP
                  stop (act dev)
             PER;
             send ack
     FI.

  y stop post:
     act dev := msg.dev no;
     entry into chain (act dev, act server.current job);
     IF act chain.last > 1
        THEN make new first (act dev, act chain.last)
     FI;
     send ack.

  y halt:
     link dev;
     IF act dev = 0
        THEN IF order <> halt code
                THEN device error
                ELSE FOR act dev FROM 1 UPTO max devices REP
                         halt (act dev)
                     PER;
                     send ack
             FI
        ELSE halt (act dev);
             IF order = halt code
                THEN send ack;
                     act server.wait for halt := niltask
                ELSE act server.wait for halt := order task
             FI
     FI.

  y first:
     link dev;
     IF act dev = 0
        THEN device error
        ELSE INT VAR new first entry :: find entry (msg.ds name,act dev,order task,TRUE);
             IF new first entry = 0
                THEN manager message ("""" + msg.ds name + """ existiert nicht")
                ELSE make new first (act dev,new first entry);
                     send ack
             FI
     FI.

   act server:
      device [act dev].server.

   act chain:
      device [act dev].chain.

   send ack:
      send (order task, ack).

   link dev:
      msg := ds;
      act dev := msg.dev no.

  order error:
     errorstop ("Falscher Auftrag fuer Task """ + name (myself) + """").

  device error:
   disable stop;
   IF plotter (msg.dev name) = no plotter
     THEN clear error;   (* 'plotter(TEXT)' liefert evtl. bereits error *)
          errorstop ("Kein Endgeraet eingestellt")
     ELSE clear error;
          errorstop ("Unbekanntes Endgeraet: """ + msg.dev name + """")
   FI;
   enable stop.
END PROC plot manager;

(****************************** Spool Monitor ******************************)

INT VAR command index , params ;
TEXT VAR command line, param 1, param 2 ;
BOOL VAR is break;
 
LET spool command list =
"break:1.0start:2.0stop:3.0halt:4.0first:5.0killer:6.0listspool:7.0
 clearspool:8.0selectplotter:9.0spoolcontrol:10.1";
 
PROC spool monitor:
  disable stop ;
  current plotter := 0;
  is break := FALSE;
  select plotter ("");
  REP command dialogue (TRUE) ;
      get command (gib kommando, command line);
      analyze command (spool command list, command line, 3, command index,
                       params, param1, param2);
      execute command;
  UNTIL is break PER;
  command dialogue (FALSE);
  eumel must advertise;
  break (quiet);
  set autonom.

  gib kommando:
     IF actual plotter > 0
        THEN plotter info (name(plotters,actual plotter),50)
        ELSE "ALL-Plotter: "
     FI
END PROC spool monitor;

PROC execute command:
 enable stop;
 SELECT command index OF 
   CASE 1  :  is break := TRUE
   CASE 2  :  start cmd
   CASE 3  :  stop  cmd
   CASE 4  :  halt  cmd
   CASE 5  :  first cmd
   CASE 6  :  killer cmd
   CASE 7  :  show spool list
   CASE 8  :  clear spool
   CASE 9  :  select plotter cmd
   CASE 10 :  set spool control
   OTHERWISE  do (command line);
              set current plotter
 END SELECT.
 
 set current plotter:
   current plotter := link(managed plotter, name (plotters,actual plotter));
   IF actual plotter > 0 AND current plotter = 0
      THEN select plotter ("");
           current plotter := 0;
           errorstop ("Auf dieser Station unbekannt: """+name(plotter)+"""")
   FI.

   start cmd:
    FOR act dev FROM curr dev UPTO top dev REP
       start (act dev)
    PER.

 stop cmd:
    FOR act dev FROM curr dev UPTO top dev REP
       IF device [act dev].server.current job.ds name <> "" CAND
          yes ("""" + device [act dev].server.current job.ds name +
                """ neu eintragen")
          THEN entry into chain (act dev, device [act dev].server.current job);
               IF device [act dev].chain.last > 1
                  THEN make new first (act dev, device [act dev].chain.last)
               FI
       FI;
       stop (act dev)
    PER.

 halt cmd:
    FOR act dev FROM curr dev UPTO top dev REP
       halt (act dev)
    PER.

 first cmd:
    IF current plotter = 0
       THEN device error
    FI;
    TEXT VAR make to first :: one (chain thesaurus (current plotter,niltask,TRUE)
                                   -first chain entry)
   IF make to first <> ""
       THEN INT VAR new first entry :: find entry (make to first,
                                            current plotter, niltask, FALSE);
            IF new first entry > 1
               THEN make new first (current plotter, new first entry)
            FI
    FI.

    first chain entry:
       INT VAR first entry id :: device [current plotter].chain.first;
       IF first entry id > 0
          THEN device [current plotter].chain.entry[first entry id].job.ds name
          ELSE ""
       FI.

 killer cmd:
    IF current plotter = 0
       THEN device error
    FI;
    THESAURUS VAR to erase :: chain thesaurus (current plotter,niltask,FALSE);
    INT VAR index, act dev;
    TEXT VAR name to erase;
    FOR act dev FROM curr dev UPTO top dev REP
       index := 0;
       get (to erase, name to erase, index);
       WHILE index > 0 REP
          INT VAR entry to erase := find entry (name to erase, current plotter, niltask, TRUE);
          IF (entry to erase > 0) CAND
             yes ("""" + name to erase + """ loeschen")
             THEN erase entry (current plotter, entry to erase)
          FI;
          get (to erase, name to erase, index)
       PER
    PER.

 show spool list :
    create chain list (current plotter);
    show (chain info);
    forget (reply ds).

 clear spool:
    FOR act dev FROM curr dev UPTO top dev REP
        IF yes ("Spool """ + name (managed plotter, act dev) + """ initialisieren")
           THEN BOOL VAR stopped :: device [act dev].server.stopped;
                stop (act dev);
                init device (act dev);
                IF stopped
                   THEN device [act dev].server.stopped := TRUE
                   ELSE start (act dev)
                FI
        FI
    PER.

  set spool control:
     control task := task (param 1).

  select plotter cmd:
    THESAURUS VAR plotter list :: empty thesaurus;
    TEXT VAR plotter name;
    get (managed plotter, plotter name, index);
    WHILE index > 0 REP
       insert (plotter list, plotter info (plotter name, 60));
       get (managed plotter, plotter name, index)
    PER;
    select plotter (name (managed plotter,
                    link (plotter list,one (plotter list))));
    set current plotter.

 curr dev:
    IF current plotter = 0
       THEN 1
       ELSE current plotter
    FI.

 top dev:
    IF current plotter = 0
       THEN max devices
       ELSE current plotter
    FI.

  device error:
     errorstop ("Kein Endgeraet eingestellt")

ENDPROC execute command ;

(************************** SPOOL - Verwaltung *****************************)

PROC entry into chain (INT CONST dev no, JOB CONST new job): 
   INT VAR act entry := act chain.empty; 
   act chain.empty := act chain.entry [act entry].link;
   IF act chain.last > 0 
      THEN act chain.entry [act chain.last].link := act entry 
   FI; 
   act chain.last := act entry; 
   IF act chain.first = 0 
      THEN act chain.first := act entry 
   FI; 
   init job (act chain.entry [act  entry].job);
   act chain.entry [act entry] := ENTRY : (new job,0);
   forget (new job.ds).
 
   act chain : 
      device [dev no].chain 
END PROC entry into chain; 
 
PROC erase entry (INT CONST dev no, to erase): 
   INT VAR act entry;
   to forward entry; 
   IF act entry > 0 
      THEN act chain.entry [act entry].link := act chain.entry [to erase].link 
   FI; 
   IF act chain.last = to erase 
      THEN act chain.last := act entry 
   FI; 
   IF act chain.first = to erase 
      THEN act chain.first := act chain.entry [to erase].link 
   FI; 
   init job (act chain.entry [to erase].job);
   act chain.entry [to erase].link := act chain.empty; 
   act chain.empty := to erase. 
 
   to forward entry: 
      FOR act entry FROM 1 UPTO max entries REP 
      UNTIL act chain.entry [act entry].link = to erase PER; 
      IF act entry > max entries 
         THEN act entry := 0 
     FI. 
 
   act chain: 
      device [dev no].chain 
END PROC erase entry; 
 
INT PROC find entry (TEXT CONST ds name, INT CONST dev, TASK CONST order task,BOOL CONST priviledged):
   INT VAR act dev :: dev,act entry,last found :: 0;
   IF act dev = 0
      THEN FOR act dev FROM 1 UPTO max devices REP
               find entry of order task
           UNTIL act entry > 0 PER
      ELSE find entry of order task
    FI;
    IF act entry = 0
       THEN last found
       ELSE act entry
    FI.

   find entry of order task:
      BOOL VAR entry found;
      act entry := act chain.first;
      WHILE act entry > 0 REP
         entry found := (act chain.entry [act entry].job.ds name = ds name);
         IF entry found
            THEN last found := act entry;
                 entry found := (index (act chain.entry [act entry].job.order task) =
                                 index (order task)) OR priviledged
         FI;
         IF NOT entry found
            THEN act entry := act chain.entry [act entry].link
         FI
      UNTIL entry found PER.

   act chain:
      device [act dev].chain

END PROC find entry;

PROC make new first (INT CONST dev no, new first):
   JOB VAR new first job :: act chain.entry [new first].job;
   erase entry (dev no, new first);
   INT VAR act entry := act chain.empty;
   act chain.empty := act chain.entry [act entry].link;
   act chain.entry [act entry] := ENTRY : (new first job, act chain.first);
   init job (new first job);
   act chain.first := act entry;
   IF act chain.last = 0
      THEN act chain.last := act entry
   FI.

   act chain:
     device [dev no].chain

END PROC make new first;

THESAURUS PROC chain thesaurus (INT CONST dev no, TASK CONST order task,
                                BOOL CONST double):
   THESAURUS VAR list :: empty thesaurus;
   INT VAR act dev := dev no,act entry;
   IF act dev = 0 
      THEN FOR act dev FROM 1 UPTO max devices REP 
               list chain 
           PER 
      ELSE list chain 
   FI; 
   list.
       
   list chain: 
      act entry := act chain.first; 
      WHILE act entry > 0 REP 
         IF (order task = niltask) OR
            (act chain.entry [act entry].job.order task = order task)
            THEN insert job name
         FI;
         act entry := act chain.entry [act entry].link 
      PER.

   insert job name:
      TEXT VAR this job :: act chain.entry [act entry].job.ds name
      IF double OR (NOT (list CONTAINS this job))
         THEN insert (list, this job)
      FI.

   act chain: 
      device [act dev].chain 
 
END PROC chain thesaurus; 
 

PROC create chain list (INT CONST dev no):
   INT VAR act dev :: dev no, act entry; 
   init chain info; 
   IF act dev = 0
      THEN FOR act dev FROM 1 UPTO max devices REP 
             list chain 
           PER 
      ELSE list chain
   FI.
      
   init chain info: 
      forget (reply ds);
      reply ds := nilspace;
      chain info := sequential file (output, reply ds); 
      headline (chain info,"GRAPHIK - Ausgabe um "+ time of day (clock (1)) + " Uhr :").

 
   list chain: 
      server head;
      IF NOT server is active (act dev) OR is no job (act server.current job)
         THEN put (chain info, "- Kein Auftrag in Bearbeitung") ;
              IF act server.stopped
                 THEN put (chain info, "  ( SERVER deaktiviert )")
              FI;
              line (chain info)
         ELSE put (chain info, "- In Bearbeitung seit "+time of day (act server.time)+" Uhr :");
              IF act server.stopped
                 THEN put (chain info, " ( SERVER wird deaktiviert !)")
              FI;
              line (chain info, 2);
              putline (chain info, job note (act server.current job))
      FI; 
      line (chain info);  
      IF act chain.last = 0 
         THEN putline (chain info, "- Keine Auftraege im SPOOL")
         ELSE putline (chain info, "- Weitere Auftraege im SPOOL :"); 
              line    (chain info); 
              act entry := act chain.first; 
              WHILE act entry > 0 REP 
                    putline (chain info, job note (act chain.entry [act entry].job)); 
                    act entry := act chain.entry [act entry].link 
              PER 
      FI; 
      line (chain info, 2). 
 
   server head:
      TEXT VAR plotter name :: name (managed plotter,act dev);
      INT VAR station :: int (plottername),
              tp      :: pos (plottername,trenn)+1,
              channel :: int (subtext (plottername,tp));
      plotter name := subtext (plotter name, pos (plotter name, trenn, tp)+1);
      putline (chain info, 77 * "-");
      putline (chain info,
               center (plotter name + (30-length(plotter name))*"." +
                      "Kanal " + text (channel) +
                      "/Station " + text (station)));
      putline (chain info, 77 * "-");
      line (chain info).

   act chain: 
      device [act dev].chain. 
 
   act server: 
      device [act dev].server 
 
END PROC create chain list; 

BOOL PROC chain is empty (INT CONST dev no):
   device [dev no].chain.first = 0 OR device [dev no].chain.last = 0
END PROC chain is empty;

BOOL PROC chain is full (INT CONST dev no):
   device [dev no].chain.empty = 0
END PROC chain is full;

PROC transfer next job (INT CONST dev no): 
   INT VAR next chain entry := device [dev no].chain.first;
   next server job (dev no, device [dev no].chain.entry [next chain entry].job); 
   erase entry (dev no,next chain entry) 
END PROC transfer next job; 
 
(*************************** SERVER - Verwaltung ***************************)

PROC next server job (INT CONST dev no,JOB CONST next job): 
   act server.time := clock (1); 
   init job (act server.current job);
   act server.current job := next job. 
 
   act server: 
      device [dev no].server 
END PROC next server job; 
 
BOOL PROC server is active (INT CONST dev no):
   exists (act server.task) CAND server alive or restarted.

   server alive or restarted:
      SELECT status (act server.task) OF
        CASE 0 (* busy *) ,
             4 (* busy-blocked *),
             2 (* wait *),
             6 (* wait-blocked *) : TRUE
        CASE 1 (* i/o *),
             5 (* i/o -blocked *): IF channel (act server.task) = 0
                                     THEN restart
                                     ELSE TRUE
                                   FI
        OTHERWISE restart
      END SELECT.

   restart:
     end server (dev no);
     IF NOT act server.stopped AND NOT chain is empty (dev no)
        THEN create server (dev no)
     FI;
     NOT is niltask (act server.task).

   act server:
      device [dev no].server

END PROC server is active;

PROC create server (INT CONST dev no): 
   init job (act server.current job);
   act server.wait for halt := niltask;
   act server.time := 0.0;
   act server.stopped := FALSE;
   last created server := dev no;
   begin (PROC plot server, act server.task).

   act server:
      device [dev no].server
END PROC create server; 
 
PROC end server (INT CONST dev no): 
   end (act server.task);
   init job (act server.current job);
   act server.task := niltask.

   act server:
     device [dev no].server

END PROC end server; 
 
PROC start (INT CONST dev no):
   IF server is active (dev no)
      THEN end server (dev no)
   FI;
   IF NOT chain is empty (dev no)
      THEN create server (dev no)
   FI;
   device [dev no].server.stopped := FALSE
END PROC start;

PROC stop (INT CONST dev no):
   device [dev no].server.stopped := TRUE;
   IF exists (device [dev no].server.wait for halt)
      THEN send (device [dev no].server.wait for halt,ack)
   FI;
   device [dev no].server.wait for halt := niltask;
   IF server is active (dev no)
      THEN end server (dev no)
   FI
END PROC stop;

PROC halt (INT CONST dev no):
   device [dev no].server.stopped := TRUE
END PROC halt;

PROC send current job (INT CONST dev no):
   forget (reply ds);
   reply ds := device [dev no].server.current job.ds;
   send (device [dev no].server.task, ack,reply ds);
END PROC send current job;

(****************************** Hilfsprozeduren ****************************)

PROC init device (INT CONST dev no): 
   INT VAR act entry;
   act server.task        := niltask; 
   act server.time        := 0.0; 
   init job (act server.current job); 
   act server.stopped     := FALSE;
   act chain.first        := 0; 
   act chain.last         := 0; 
   act chain.empty        := 1;
   FOR act entry FROM 1 UPTO max entries-1 REP
      init job (act chain.entry [act entry].job);
      act chain.entry [act entry].link := act entry + 1
   PER;
   init job (act chain.entry [act entry].job);
   act chain.entry [act entry].link := 0.

   act server : 
      device [dev no].server. 
 
   act chain : 
      device [dev no].chain 
 
END PROC init device; 

INT PROC max devices:
   highest entry (managed plotter)
END PROC max devices;

OP := (MSG VAR dest, DATASPACE VAR source):
   TEXT VAR ds name :: "", dev name :: "";
   BOUND STRUCT (TEXT ds name, dev name, passwd) VAR msg in := source;
   divide names;
   dest := MSG : (ds name, dev name, msg in .passwd,
                  link (managed plotter,dev name));
   forget (source).

   divide names:
      INT VAR pps :: pos (msg in.ds name, ""0"");
      WHILE pos (msg in.ds name, ""0"", pps+1) > 0 REP
         pps := pos (msg in.ds name,""0"", pps+1)
      PER;
      IF pps > 0
         THEN ds name  := subtext (msg in.ds name, 1, pps-1);
      FI;
      dev name := subtext (msg in.ds name, pps+1).

END OP :=;

TEXT PROC job note (JOB CONST job): 
   "  - " + owner id (job.order task) + " : " + qrline (job.ds name, 30) +
   " (" + text (storage (job.ds)) + " K)".
END PROC job note; 

TEXT PROC owner id (TASK CONST owner):
    TEXT VAR test :: name (owner);
    IF test <> ""
       THEN text (station (owner)) + "/" + qrline (test,15)
       ELSE "?????"
    FI
END PROC owner id;

PROC init job (JOB VAR to initialize):
   forget (to initialize.ds);
   to initialize.ds name := "";
   to initialize.order task := niltask
END PROC init job;

TEXT PROC qrline (TEXT CONST t,INT CONST len): 
   IF length (t) > len-2 
      THEN """" + text (t, len-5) + "...""" 
      ELSE text ("""" + t + """", len) 
   FI 
END PROC qrline; 
 
TEXT PROC center (TEXT CONST chars,INT CONST len):
   len DIV 2 * " " + chars
END PROC center;

BOOL PROC is no job (JOB CONST job):
   job.ds name = ""
END PROC is no job;

PROC send (TASK CONST task, INT CONST code):
   DATASPACE VAR ds :: nilspace;
   send (task, code, ds);
   forget (ds)
END PROC send;

(**************************** Plot - Server ********************************)

PROC plot server:
   disable stop;
   select plotter (name (managed plotter,last created server));
   REP
      error handling;
      TEXT VAR dummy;
      catinput (dummy, dummy);  (* evtl. Zeichen im Tastaturpuffer *)
      PICFILE VAR pic :: next server job;
      prepare;
      plot (pic);
   PER.

   next server job:
     forget (reply ds);
     reply ds := nilspace;
     REP
       error handling;
       call (father, fetch code, reply ds, reply)
     UNTIL reply = ack PER;
     reply ds.

   error handling:
    IF is error
      THEN rename myself (error message);
           clear error;
           pause
    FI.

END PROC plot server;

END PACKET plot manager