**Listed On  07/11/94   17:08  **
**List of Fold**       "pra04"
**List of File**       "pra04.tsr"
**File Last Modified    07/11/94   15:34
**List all lines  with Fold Headers 
**Excluding : COMMENT folds  NO LIST folds 
--...  COMMENT Documentacion
--:::A COMMENT FOLD
--{{{  protocol
VAL number.of.cells IS 100:
VAL MAXN IS 100:
VAL MAX.MSG IS 255:
PROTOCOL PIPE.PROTOCOL
  CASE
    debug; INT; INT::[]BYTE
    vector; INT::[]INT
    value; INT
    finish
:
--}}}  

--{{{  uses host input/output libraries
--#USE strmhdr
#USE sphdr
#USE solib
#USE splib
#USE sklib
--#USE extrio
--#USE strings
--}}}  
--{{{  output
--{{{  util
PROC so.msg(CHAN OF PIPE.PROTOCOL out, VAL INT name, VAL []BYTE msg)
  out ! debug; name; (SIZE msg)::msg
:
--}}}  
PROC output(CHAN OF PIPE.PROTOCOL in, out)
  INT item, num.values, num.cell, length:
  BOOL running:
  [MAXN]INT n:
  [MAX.MSG]BYTE msg:
  SEQ
    running := TRUE
    num.values := 0
    WHILE running
      in ? CASE
        value; item
          IF
            item <> MOSTPOS INT
              SEQ
                n[num.values] := item
                num.values := num.values + 1
            TRUE
              SKIP
        debug; num.cell; length::msg
          so.msg(out, num.cell, [msg FROM 0 FOR length])
        finish
          SEQ
            out ! vector; num.values::n
            running := FALSE
    out ! finish
:
--}}}  
--{{{  cell
--{{{  util
PROC so.msg(CHAN OF PIPE.PROTOCOL out, VAL INT name, VAL []BYTE msg)
  out ! debug; name; (SIZE msg)::msg
:
--}}}  
PROC cell(VAL INT name, CHAN OF PIPE.PROTOCOL in, out)
  INT item, register, num.cell, length:
  BOOL running:
  [MAX.MSG]BYTE msg:
  SEQ
    register := MOSTPOS INT
    running := TRUE
    VAL msg1 IS "Empiezo a Trabajar":
    so.msg(out, name, [msg1 FROM 0 FOR SIZE msg1])
    WHILE running
      in ? CASE
        value; item
          IF
            register > item
              SEQ
                out ! value; register
                register := item
            TRUE
              out ! value; item
        debug; num.cell; length::msg
          so.msg(out, num.cell, [msg FROM 0 FOR length])
        finish
          SEQ
            running := FALSE
            out ! value; register
    VAL msg2 IS "Termino de Trabajar":
    so.msg(out, name, [msg2 FROM 0 FOR SIZE msg2])
    out ! finish
:
--}}}  
--{{{  utils
PROC so.prompt.int(VAL []BYTE msg, VAL INT n)
  SEQ
    so.write.string(from.isv, to.isv, msg)
    so.write.int(from.isv, to.isv, n, 0)
:


PROC so.pause()
  SEQ
    BYTE key, result:
    so.getkey(from.isv, to.isv, key, result)
:

--}}}  
--{{{  input
PROC input(CHAN OF PIPE.PROTOCOL in, out)
  [MAXN]INT n:
  INT longitud:

  SEQ
    in ? CASE
      vector; longitud::n
        SEQ i = 0 FOR longitud
          out ! value; n[i]
    in ? CASE finish
    out ! finish

:
--}}}  
--{{{  monitor
PROC monitor(CHAN OF PIPE.PROTOCOL in, out)
  INT num.cell, length, item, num.values:
  [MAX.MSG]BYTE msg:
  [MAXN]INT n:
  BOOL error, running, reading:
  SEQ
    reading := TRUE
    num.values := 0
    WHILE reading
      SEQ
        --{{{  reading.values
        VAL msg IS "*nIntroduce el numero":
        so.write.string(from.isv, to.isv, msg)
        so.read.echo.int(from.isv, to.isv, n[num.values], error)
        IF
          ((n[num.values] = (-1)) OR (num.values = (MAXN -1)))
            reading := FALSE
          TRUE
            num.values := num.values + 1
        --}}}  
    PAR
      SEQ
        out ! vector; num.values::n
        out ! finish
      SEQ
        running := TRUE
        WHILE running
          in ? CASE
            vector; num.values::n
              SEQ i = 0 FOR num.values
                so.write.int(from.isv, to.isv, n[i], 10)
            debug; num.cell; length::msg
              SEQ
                so.write.nl(from.isv, to.isv)
                so.write.int(from.isv, to.isv, num.cell, 10)
                so.write.int(from.isv, to.isv, length, 10)
                so.write.string(from.isv, to.isv, [msg FROM 0 FOR length])
                so.pause()
            finish
              running := FALSE
:
--}}}  

SEQ
  [number.of.cells + 1]CHAN OF PIPE.PROTOCOL pipe:
  CHAN OF PIPE.PROTOCOL from.monitor.to.in, from.out.to.monitor:
  PAR
    monitor(from.out.to.monitor, from.monitor.to.in)
    input(from.monitor.to.in, pipe[0])
    PAR i = 0 FOR number.of.cells
      cell(i, pipe[i], pipe[i+1])
    output(pipe[number.of.cells], from.out.to.monitor)
  so.pause()
