/* pk-diff.pk - Home of the `sdiff' and `bdiff' commands.  */

/* Copyright (C) 2022, 2023, 2024 Jose E. Marchesi */

/* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

load diff;

var pk_diff_group_by = 1#B;
var pk_sdiff_print_values = 1;

pk_help_add_topic
:entry Poke_HelpEntry {
          category = "commands",
          topic = "sdiff",
          summary = "structured binary diff of two mapped values",
          description= format ("
Synopsis:

  sdiff :a VAL :b VAL [:values BOOL] [:group_by OFFSET]

Arguments:

  :a (any)
         First mapped value whose bytes are compared.

  :b (any)
         Second mapped value whose bytes are compared.

  :values (bool)
         Whether to include interpreted values in the output.
         Defaults to `pk_sdiff_print_values', initially %v.

  :group_by (int)
         How are bytes grouped together in the output.  Defaults to
         `pk_diff_group_by', initially %v.

Note that for the differences to make sense, both values A and B
should be of the same type.

If any of the specified values are not mapped then `sdiff' raises an
E_map exception.

If the size of the values to be compared do not amount for a whole
number of bytes then `sdiff' raises an E_inval exception.

See `.doc sdiff' for more information.",
           pk_sdiff_print_values,
           pk_diff_group_by),
          };

fun sdiff = (any a, any b,
             string prefix_a = "a",
             string prefix_b = "b",
             int<32> values = pk_sdiff_print_values,
             offset<uint<64>,B> group_by = pk_diff_group_by)
            void:
{
  diff_structured :a a :b b
                  :prefix_a prefix_a :prefix_b prefix_b
                  :values values :group_by group_by;
}
