#!/bin/bash

# E.g. for filtering the output of reg_test/run --valgrind.
# This just strips out some false positives, e.g. system-level stuff not
# relevant to Miller itself. mgrepv is at
# https://github.com/johnkerl/scripts/blob/master/fundam/mgrepv

sed 's/^==.*== //' "$@" | swipe \
  | sed 's/--[0-9]*-- UNKNOWN.*//' \
  | mgrepv dyld \
  | mgrepv copySwiftV1MangledName \
  | mgrepv 'LEAK SUMMARY' \
  | mgrepv 'HEAP SUMMARY' \
  | grep -v 'ERROR SUMMARY' \
  | grep -v 'Memcheck,' \
  | grep -v 'Copyright' \
  | grep -v 'Using Valgrind' \
  | grep -v 'For counts of' \
  | mgrepv 'mlr_try_float_from_string' \
  | mgrepv '__snprintf_chk' \
  | mgrepv 'vsscanf_l' \
  | mgrepv 'handle_ld_preload' \
  | mgrepv 'NXMapRemove' \
  | mgrepv '_platform_memchr' \
  | mgrepv 'xpc_pipe_routine' \
  | grep -v 'MACH_SEND_TRAILER' \
  | mgrepv 'mlr_dsl_lexer_lex' \
  | mgrepv 'yyreduce' \
  | mgrepv 'unbackslash' \
  | mgrepv 'cli_sep_from_arg' \
  | mgrepv 'join_bucket_keeper_alloc' \
  | mgrepv 'join_bucket_keeper_emit' \
  | mgrepv 'handle_env_assignment' \
  | mgrepv 'file_ingestor_stdio_vopen' \
  | mgrepv 'lrec_reader_stdio_json_sof' \
  | cat

  #| mgrepv 'shared_parse_cli' \
  #| mgrepv 'parse_command_line'
