      SUBROUTINE RPCSVR.FILEIO(CMD,FNAME,ID.LST,ID.FLG,D.LENS,DD,S.RES)
*PIC-LAN
*
*ALL
*PC
*Y
*
*
*
*
* This is a general RPC subroutine
*
*
      INCLUDE SYS.TYPE.INCLUDE
*
      INCLUDE PL.COMMON
      INCLUDE PL.COMMON.DEFS
      INCLUDE PL.DEFS
      INCLUDE PLIP.COMMON
      INCLUDE PLW.COMMON
*
      CMD.LST = 'READ' : VM : 'SELECT' : VM : 'WRITE' : VM : 'DELETE'
*
      S.RES = ''
*
      OPEN FNAME TO FILE.FD ELSE
         S.RES  = 'Cannot open file'
         FNAME  = ''
         ID.LST = ''
         ID.FLG = ''
         D.LENS = ''
         DD     = ''
         RETURN
      END
*
      LOCATE(CMD,CMD.LST,1;LOC) THEN
         ON LOC GOSUB 100,200,300,400
      END ELSE
         S.RES = 'Invalid command'
      END
*
      RETURN
*
100   REM READ
*
      SELECT ID.LST
*
      ID.FLG = ''
      D.LENS = ''
      DD     = ''
      ID.FLG1 = ''
      D.LENS1 = ''
      DD1     = ''
      EOF = NO
*
      LOOP
         READNEXT ID ELSE EOF = YES
      UNTIL EOF DO
         READ D FROM FILE.FD , ID THEN
            ID.FLG1 = ID.FLG1 : '1'
            D.LENS1 = D.LENS1 : LEN(D) 'R%8'
            DD1 = DD1 : D
         END ELSE
PRINT 'Cannot read ' : ID
            ID.FLG1 = ID.FLG1 : '0'
            D.LENS1 = D.LENS1 : '00000000'
         END
         IF LEN(ID.FLG1) > 5000 THEN
            ID.FLG = ID.FLG : ID.FLG1
            ID.FLG1 = ''
         END
         IF LEN(D.LENS1) > 5000 THEN
            D.LENS = D.LENS : D.LENS1
            D.LENS1 = ''
         END
         IF LEN(DD1) > 200000 THEN
            DD = DD : DD1
            DD1 = ''
         END
      REPEAT
*
      ID.FLG = ID.FLG : ID.FLG1
      D.LENS = D.LENS : D.LENS1
      DD = DD : DD1
*
      RETURN
*
200   REM SELECT
*
      SELECT FILE.FD
*
      EOF = NO
      DD = ''
      DD1 = ''
      LOOP
         READNEXT ID ELSE EOF = YES
      UNTIL EOF DO
         DD1<-1> = ID
*$*      IF LEN(DD1) > 5000 THEN
*$*         DD<-1> = DD1
*$*         DD1 = ''
*$*      END
      REPEAT
      DD<-1> = DD1
T = INDEX(DD,'TLOG-MONITOR',1)
PRINT DD[T-10,50]
*
      RETURN
*
300   REM WRITE
*
      SELECT ID.LST
      EOF = NO
*
      D.OFS = 1
      L.OFS = 1
      LOOP
         READNEXT ID ELSE EOF = YES
      UNTIL EOF DO
         D.LEN = D.LENS[L.OFS,8]
         D = DD[D.OFS,D.LEN]
         WRITE D ON FILE.FD , ID
         D.OFS = D.OFS + D.LEN
         IF D.OFS > 200000 THEN
            DD = DD[D.OFS+D.LEN,999999999]
            D.OFS = 1
         END
         L.OFS = L.OFS + 8
         IF L.OFS > 5000 THEN
            D.LENS = D.LENS[L.OFS+8,999999999]
            L.OFS = 1
         END
      REPEAT
*
      FNAME  = ''
      ID.LST = ''
      ID.FLG = ''
      D.LENS = ''
      DD     = ''
*
      RETURN
*
400   REM DELETE
*
      SELECT ID.LST
*
      EOF = NO
      LOOP
         READNEXT ID ELSE EOF = YES
      UNTIL EOF DO
         DELETE FILE.FD , ID
      REPEAT
*
      RETURN
   END
