      SUBROUTINE PLH.POST.DECODE(SRC,OPT,MAT R.HDR,MAT R.DTA,R.ERR)
*PIC-LAN
*
*ALL
*PC
*Y
*
*
*
      DIM R.HDR(100)
      DIM R.DTA(100)
*
      CRLF = CR : LF
*
      A.OPT = INDEX(OCONV(OPT,'MCU'),'A',1) # 0
*
      MAT R.HDR = ''
      MAT R.DTA = ''
      R.ERR = ''
*
      T = INDEX(SRC,CRLF,1)
      IF T <= 1 THEN
         R.ERR = 'Invalid incoming data format.'
         RETURN
      END
*
      SEP.STR = SRC[1,T-1]
      SEP.LEN = LEN(SEP.STR)
*
      SEC.CNT = DCOUNT(SRC,SEP.STR)
      IF SEC.CNT >= 100 THEN
         R.ERR = 'Source has too many content sections.'
         RETURN
      END
*
      FOR SEC.N = 1 TO SEC.CNT
         T0 = INDEX(SRC,SEP.STR,SEC.N)
         T1 = INDEX(SRC,SEP.STR,SEC.N+1)
         IF T0 > 0 AND T1 > 0 THEN
            START.OFFSET = T0 + SEP.LEN
            SEGMENT.LEN = T1 - T0 - SEP.LEN
            IF SEGMENT.LEN > 0 THEN
               S = T[START.OFFSET,SEGMENT.LEN]
               IF S[1,2] = CRLF THEN S = S[3,99999999]
               T = INDEX(S,CRLF:CRLF,1)
               IF NOT(T) THEN
                  H = S
                  D = ''
               END ELSE
                  H = S[1,T-1]
                  D = S[T+5,99999999]
               END
               R.HDR(SEC.N) = PL_CRLFTOAM(H)
               IF NOT(A.OPT) THEN
                  R.DTA(SEC.N) = D
               END ELSE
                  R.DTA(SEC.N) = PL_CRLFTOAM(D)
               END
            END
         END
      NEXT SEC.N
*
      RETURN
   END
