#include <getopt.h>
#include <limits.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Mapping from indices in FILE1 to indices in FILE2.
A value -1 means that the entry from FILE1 is not found in FILE2.
A value -2 means that it has not yet been computed. */
- ssize_t *index_mapping;
+ ptrdiff_t *index_mapping;
/* Mapping from indices in FILE2 to indices in FILE1.
A value -1 means that the entry from FILE2 is not found in FILE1.
A value -2 means that it has not yet been computed. */
- ssize_t *index_mapping_reverse;
+ ptrdiff_t *index_mapping_reverse;
};
/* Look up (or lazily compute) the mapping of an entry in FILE1.
i is the index in FILE1.
Return the index in FILE2, or -1 when the entry is not found in FILE2. */
-static ssize_t
-entries_mapping_get (struct entries_mapping *mapping, ssize_t i)
+static ptrdiff_t
+entries_mapping_get (struct entries_mapping *mapping, ptrdiff_t i)
{
if (mapping->index_mapping[i] < -1)
{
size_t n1 = file1->num_entries;
size_t n2 = file2->num_entries;
struct entry *entry_i = file1->entries[i];
- ssize_t j;
+ ptrdiff_t j;
/* Search whether it approximately occurs in file2. */
- ssize_t best_j = -1;
+ ptrdiff_t best_j = -1;
double best_j_similarity = 0.0;
for (j = n2 - 1; j >= 0; j--)
if (mapping->index_mapping_reverse[j] < 0)
/* Found a similar entry in file2. */
struct entry *entry_j = file2->entries[best_j];
/* Search whether it approximately occurs in file1 at index i. */
- ssize_t best_i = -1;
+ ptrdiff_t best_i = -1;
double best_i_similarity = 0.0;
- ssize_t ii;
+ ptrdiff_t ii;
for (ii = n1 - 1; ii >= 0; ii--)
if (mapping->index_mapping[ii] < 0)
{
/* Look up (or lazily compute) the mapping of an entry in FILE2.
j is the index in FILE2.
Return the index in FILE1, or -1 when the entry is not found in FILE1. */
-static ssize_t
-entries_mapping_reverse_get (struct entries_mapping *mapping, ssize_t j)
+static ptrdiff_t
+entries_mapping_reverse_get (struct entries_mapping *mapping, ptrdiff_t j)
{
if (mapping->index_mapping_reverse[j] < -1)
{
size_t n1 = file1->num_entries;
size_t n2 = file2->num_entries;
struct entry *entry_j = file2->entries[j];
- ssize_t i;
+ ptrdiff_t i;
/* Search whether it approximately occurs in file1. */
- ssize_t best_i = -1;
+ ptrdiff_t best_i = -1;
double best_i_similarity = 0.0;
for (i = n1 - 1; i >= 0; i--)
if (mapping->index_mapping[i] < 0)
/* Found a similar entry in file1. */
struct entry *entry_i = file1->entries[best_i];
/* Search whether it approximately occurs in file2 at index j. */
- ssize_t best_j = -1;
+ ptrdiff_t best_j = -1;
double best_j_similarity = 0.0;
- ssize_t jj;
+ ptrdiff_t jj;
for (jj = n2 - 1; jj >= 0; jj--)
if (mapping->index_mapping_reverse[jj] < 0)
{
struct entries_mapping *result)
{
/* Mapping from indices in file1 to indices in file2. */
- ssize_t *index_mapping;
+ ptrdiff_t *index_mapping;
/* Mapping from indices in file2 to indices in file1. */
- ssize_t *index_mapping_reverse;
+ ptrdiff_t *index_mapping_reverse;
size_t n1 = file1->num_entries;
size_t n2 = file2->num_entries;
- ssize_t i, j;
+ ptrdiff_t i, j;
- index_mapping = XNMALLOC (n1, ssize_t);
+ index_mapping = XNMALLOC (n1, ptrdiff_t);
for (i = 0; i < n1; i++)
index_mapping[i] = -2;
- index_mapping_reverse = XNMALLOC (n2, ssize_t);
+ index_mapping_reverse = XNMALLOC (n2, ptrdiff_t);
for (j = 0; j < n2; j++)
index_mapping_reverse[j] = -2;
as long as they pair up. Unpaired occurrences of the same
entry are left without mapping. */
{
- ssize_t curr_i = i;
- ssize_t curr_j = j;
+ ptrdiff_t curr_i = i;
+ ptrdiff_t curr_j = j;
for (;;)
{
- ssize_t next_i;
- ssize_t next_j;
+ ptrdiff_t next_i;
+ ptrdiff_t next_j;
next_i =
gl_list_indexof_from (file1->entries_reversed,
{
enum edit_type type;
/* Range of indices into the entries of FILE1. */
- ssize_t i1, i2; /* first, last index; only used for CHANGE, REMOVAL */
+ ptrdiff_t i1, i2; /* first, last index; only used for CHANGE, REMOVAL */
/* Range of indices into the entries of FILE2. */
- ssize_t j1, j2; /* first, last index; only used for ADDITION, CHANGE */
+ ptrdiff_t j1, j2; /* first, last index; only used for ADDITION, CHANGE */
};
/* This structure represents the differences from one file, FILE1, to another
{
/* An array mapping FILE1 indices to FILE2 indices (or -1 when the entry
from FILE1 is not found in FILE2). */
- ssize_t *index_mapping;
+ ptrdiff_t *index_mapping;
/* An array mapping FILE2 indices to FILE1 indices (or -1 when the entry
from FILE2 is not found in FILE1). */
- ssize_t *index_mapping_reverse;
+ ptrdiff_t *index_mapping_reverse;
/* The edits that transform FILE1 into FILE2. */
size_t num_edits;
struct edit **edits;
/* Import the difference detection algorithm from GNU diff. */
#define ELEMENT struct entry *
#define EQUAL entry_equals
-#define OFFSET ssize_t
-#define OFFSET_MAX SSIZE_MAX
+#define OFFSET ptrdiff_t
+#define OFFSET_MAX PTRDIFF_MAX
#define EXTRA_CONTEXT_FIELDS \
- ssize_t *index_mapping; \
- ssize_t *index_mapping_reverse;
+ ptrdiff_t *index_mapping; \
+ ptrdiff_t *index_mapping_reverse;
#define NOTE_DELETE(ctxt, xoff) \
ctxt->index_mapping[xoff] = -1
#define NOTE_INSERT(ctxt, yoff) \
struct context ctxt;
size_t n1 = file1->num_entries;
size_t n2 = file2->num_entries;
- ssize_t i;
- ssize_t j;
+ ptrdiff_t i;
+ ptrdiff_t j;
gl_list_t /* <struct edit *> */ edits;
ctxt.xvec = file1->entries;
ctxt.yvec = file2->entries;
- ctxt.index_mapping = XNMALLOC (n1, ssize_t);
+ ctxt.index_mapping = XNMALLOC (n1, ptrdiff_t);
for (i = 0; i < n1; i++)
ctxt.index_mapping[i] = 0;
- ctxt.index_mapping_reverse = XNMALLOC (n2, ssize_t);
+ ctxt.index_mapping_reverse = XNMALLOC (n2, ptrdiff_t);
for (j = 0; j < n2; j++)
ctxt.index_mapping_reverse[j] = 0;
- ctxt.fdiag = XNMALLOC (2 * (n1 + n2 + 3), ssize_t) + n2 + 1;
+ ctxt.fdiag = XNMALLOC (2 * (n1 + n2 + 3), ptrdiff_t) + n2 + 1;
ctxt.bdiag = ctxt.fdiag + n1 + n2 + 3;
ctxt.too_expensive = n1 + n2;
{
/* An addition to the top of modified_file.
Apply it to the top of mainstream_file. */
- ssize_t j;
+ ptrdiff_t j;
for (j = edit->j2; j >= edit->j1; j--)
{
struct entry *added_entry = modified_file.entries[j];
}
else
{
- ssize_t i_before;
- ssize_t i_after;
- ssize_t k_before;
- ssize_t k_after;
+ ptrdiff_t i_before;
+ ptrdiff_t i_after;
+ ptrdiff_t k_before;
+ ptrdiff_t k_after;
i_before = diffs.index_mapping_reverse[edit->j1 - 1];
ASSERT (i_before >= 0);
i_after = (edit->j2 + 1 == modified_file.num_entries
for (i = edit->i1; i <= edit->i2; i++)
{
struct entry *removed_entry = ancestor_file.entries[i];
- ssize_t k = entries_mapping_get (&mapping, i);
+ ptrdiff_t k = entries_mapping_get (&mapping, i);
if (k >= 0
&& entry_equals (removed_entry,
mainstream_file.entries[k]))
separately. */
size_t num_changed = edit->i2 - edit->i1 + 1; /* > 0 */
size_t num_added = (edit->j2 - edit->j1 + 1) - num_changed;
- ssize_t j;
+ ptrdiff_t j;
/* First part of the split modified_file.entries[edit->j2 - edit->i2 + edit->i1]: */
gl_list_add_first (result_entries, split[0]);
/* The additions. */
? split[1]
: modified_file.entries[j]);
size_t i = j + edit->i2 - edit->j2;
- ssize_t k = entries_mapping_get (&mapping, i);
+ ptrdiff_t k = entries_mapping_get (&mapping, i);
if (k >= 0
&& entry_equals (ancestor_file.entries[i],
mainstream_file.entries[k]))
{
/* A simple change at the top of modified_file.
Apply it to the top of mainstream_file. */
- ssize_t j;
+ ptrdiff_t j;
for (j = edit->j1 + num_added - 1; j >= edit->j1; j--)
{
struct entry *added_entry = modified_file.entries[j];
{
struct entry *changed_entry = modified_file.entries[j];
size_t i = j + edit->i2 - edit->j2;
- ssize_t k = entries_mapping_get (&mapping, i);
+ ptrdiff_t k = entries_mapping_get (&mapping, i);
if (k >= 0
&& entry_equals (ancestor_file.entries[i],
mainstream_file.entries[k]))
}
else
{
- ssize_t i_before;
- ssize_t k_before;
+ ptrdiff_t i_before;
+ ptrdiff_t k_before;
bool linear;
i_before = diffs.index_mapping_reverse[edit->j1 - 1];
ASSERT (i_before >= 0);
{
gl_list_node_t node_for_insert =
result_entries_pointers[k_before + 1];
- ssize_t j;
+ ptrdiff_t j;
for (j = edit->j1 + num_added - 1; j >= edit->j1; j--)
{
struct entry *added_entry = modified_file.entries[j];
{
struct entry *changed_entry = modified_file.entries[j];
size_t i = j + edit->i2 - edit->j2;
- ssize_t k = entries_mapping_get (&mapping, i);
+ ptrdiff_t k = entries_mapping_get (&mapping, i);
ASSERT (k >= 0);
if (entry_equals (ancestor_file.entries[i],
mainstream_file.entries[k]))
See whether the num_changed entries still exist
unchanged in mainstream_file and are still
consecutive. */
- ssize_t i_first;
- ssize_t k_first;
+ ptrdiff_t i_first;
+ ptrdiff_t k_first;
bool linear_unchanged;
i_first = edit->i1;
k_first = entries_mapping_get (&mapping, i_first);
{
gl_list_node_t node_for_insert =
result_entries_pointers[k_first];
- ssize_t j;
+ ptrdiff_t j;
size_t i;
for (j = edit->j2; j >= edit->j1; j--)
{
}
for (i = edit->i1; i <= edit->i2; i++)
{
- ssize_t k = entries_mapping_get (&mapping, i);
+ ptrdiff_t k = entries_mapping_get (&mapping, i);
ASSERT (k >= 0);
ASSERT (entry_equals (ancestor_file.entries[i],
mainstream_file.entries[k]));