readMyMsgAux :: Int -> ProcessHandle -> Handle -> String -> IO String
readMyMsgAux n cp h expect = if n < 1 then do
    appendFile vseErrFile $ "gave up waiting for: " ++ expect ++ "\n"
    return ""
  else do
  mc <- myGetChar cp h
  case mc of
    Wait -> do
      appendFile vseErrFile "waiting for first character ...\n"
      readMyMsgAux (n - 1) cp h expect
    Stop -> return ""
    JustChar c -> do
      r <- readUntilMatchParen cp h [c]
      let rr = reverse r
      if isPrefixOf (prx expect) $ dropWhile (/= '(') rr
        then return rr else do
        appendFile vseErrFile $ "waiting for '" ++ expect ++ "' got:\n" ++ rr
          ++ "\ntrying again\n"
        readMyMsgAux (n - 1) cp h expect -- try again
readMyMsgAux :: Int -> ProcessHandle -> Handle -> String -> IO String
readMyMsgAux n cp h expect = if n < 1 then do
    appendFile vseErrFile $ "gave up waiting for: " ++ expect ++ "\n"
    return ""
  else do
  mc <- myGetChar cp h
  case mc of
    Wait -> do
      appendFile vseErrFile "waiting for first character ...\n"
      readMyMsgAux (n - 1) cp h expect
    Stop -> return ""
    JustChar c -> do
      r <- readUntilMatchParen cp h [c]
      let rr = reverse r
      if isPrefixOf (prx expect) $ dropWhile (/= '(') rr
        then return rr else do
        appendFile vseErrFile $ "waiting for '" ++ expect ++ "' got:\n" ++ rr
          ++ "\ntrying again\n"
        readMyMsgAux (n - 1) cp h expect -- try again
readMyMsgAux n cp h expect = if n < 1 then do
    appendFile vseErrFile $ "gave up waiting for: " ++ expect ++ "\n"
    return ""
  else do
  mc <- myGetChar cp h
  case mc of
    Wait -> do
      appendFile vseErrFile "waiting for first character ...\n"
      readMyMsgAux (n - 1) cp h expect
    Stop -> return ""
    JustChar c -> do
      r <- readUntilMatchParen cp h [c]
      let rr = reverse r
      if isPrefixOf (prx expect) $ dropWhile (/= '(') rr
        then return rr else do
        appendFile vseErrFile $ "waiting for '" ++ expect ++ "' got:\n" ++ rr
          ++ "\ntrying again\n"
        readMyMsgAux (n - 1) cp h expect -- try again