file
shmem__diff__int_8h
define
SHDIFF_VERSION
PACKAGE_VERSION
enum
shdiff_operation_t
shmem__diff__int_8h_1a1165a72acd328d002a1440042ba9c3f5a9f3f9a6744491e4d4a84d01f54cad03cpublicSHDIFF_DIFF_DELETE -1shmem__diff__int_8h_1a1165a72acd328d002a1440042ba9c3f5acabbba30ebea6f57c02cfeab35463fe2publicSHDIFF_DIFF_EQUAL 0shmem__diff__int_8h_1a1165a72acd328d002a1440042ba9c3f5a3472fd4f165b37f3e6232b9b7866a63bpublicSHDIFF_DIFF_INSERT 1
Public: Each hunk of diff describes one of these operations.
typedef
typedef struct shdiff_diff shdiff_diff
Public: Main diff object.
This is an opaque structure. It is internally a linked list of diff records, each tracking one of the operations listed above, along with pointers into the original text data and run lenths for the diff records.
typedef
typedef struct shdiff_patch shdiff_patch
typedef
typedef int(* shdiff_diff_callback)(void *cb_ref, shdiff_operation_t op, const void *data, uint32_t len)
Public: Callback function for iterating over a diff.
When you call `shdiff_diff_foreach`, pass a function with this signature to iterate over the diff records. If the `op` is a DELETE, the `data` pointer will be into the `text1` original text. If the `op` is an INSERT, the pointer will be into the `text2` new text. If the `op` is an EQUAL, we generally attempt to keep the pointer into the `text1` original text, but that is not guaranteed. cb_ref - The reference pointer you passed to the foreach fn. op - A `shdiff_operation_t` value for the chunk of data. data - Pointer to the diff data as described above. This data will generally not be NUL-terminated, since it is a reference into the original data. You must use the `len` parameter correctly. len - Bytes of data after the pointer in this chunk. Returns 0 to keep iterator or non-zero to stop iteration. Any value you return will be passed back from the foreach function.
function
int shdiff_options_init
(shdiff_options *opts)
Public: Initialize options structure to default values.
This initializes a `shdiff_options` structure for passing into the various functions that take options. After initialization, you should set the parameters explicitly that you wish to change. opts - Structure to be initialized, generally created on the stack. Returns 0 on success, -1 on failure.
function
int shdiff_diff_new
(shdiff_diff **diff, const shdiff_options *options, const char *text1, uint32_t len1, const char *text2, uint32_t len2)
Public: Calculate the diff between two texts.
This will allocate and populate a new `shdiff_diff` object with records describing how to transform `text1` into `text2`. This returns a diff with byte-level differences between the two texts. You can use one of the diff transformation functions below to modify the diffs to word or line level diffs, or to align diffs to UTF-8 boundaries or the like. diff - Pointer to a `shdiff_diff` pointer that will be allocated. You must call `shdiff_diff_free()` on this pointer when done. options - `shdiff_options` structure to control diff, or NULL to use defaults. text1 - The FROM text for the left side of the diff. len1 - The number of bytes of data in `text1`. text2 - The TO text for the right side of the diff. len2 - The number of bytes of data in `text2`. Returns 0 if the diff was successfully generated, -1 on failure. The only current failure scenario would be a failed allocation. Otherwise, some sort of diff should be generated..
function
int shdiff_diff_from_strs
(shdiff_diff **diff, const shdiff_options *options, const char *text1, const char *text2)
Public: Generate diff from NUL-terminated strings.
This is a convenience function when you know that you are diffing NUL-terminated strings. It simply calls `strlen()` and passes the results along to `shdiff_diff_new` (plus it deals correctly with NULL strings, passing them in a zero-length texts). diff - Pointer to a `shdiff_diff` pointer that will be allocated. You must call `shdiff_diff_free()` on this pointer when done. options - `shdiff_options` structure to control diff, or NULL to use defaults. text1 - The FROM string for the left side of the diff. Must be a regular NUL-terminated C string. text2 - The TO string for the right side of the diff. Must be a regular NUL-terminated C string. Returns 0 if the diff was successfully generated, -1 on failure. The only current failure scenario would be a failed allocation. Otherwise, some sort of diff should be generated..
function
void shdiff_diff_free
(shdiff_diff *diff)
Public: Free the diff structure.
Call this when you are done with the diff data. diff - The `shdiff_diff` object to be freed.
function
int shdiff_diff_foreach
(const shdiff_diff *diff, shdiff_diff_callback cb, void *cb_ref)
Public: Iterate over changes in a diff list.
Invoke a callback on each hunk of a diff. diff - The `shdiff_diff` object to iterate over. cb - The callback function to invoke on each hunk. cb_ref - A reference pointer that will be passed to callback. Returns 0 if iteration completed successfully, or any non-zero value that was returned by the `cb` callback function to terminate iteration.
function
uint32_t shdiff_diff_hunks
(const shdiff_diff *diff)
Public: Count the number of diff hunks.
This computes the number of hunks in a diff object. This is the number of times that your iterator function would be invoked. diff - The `shdiff_diff` object. Returns a count of the number of hunks in the diff.
function
void shdiff_diff_print_raw
(FILE *fp, const shdiff_diff *diff)
function
int shdiff_patch_new
(shdiff_patch **patch, const char *text1, uint32_t len1, const shdiff_diff *diff)
function
void shdiff_patch_free
(shdiff_patch *patch)
function
uint32_t shdiff_common_prefix
(const char *t1, uint32_t l1, const char *t2, uint32_t l2)
function
uint32_t shdiff_common_suffix
(const char *t1, uint32_t l1, const char *t2, uint32_t l2)
function
int shdiff_has_prefix
(const char *text, uint32_t tlen, const char *pfx, uint32_t plen)
function
int shdiff_has_suffix
(const char *text, uint32_t tlen, const char *sfx, uint32_t slen)
function
int shdiff_strcmp
(const char *t1, uint32_t l1, const char *t2, uint32_t l2)
function
const char* shdiff_strstr
(const char *haystack, uint32_t lh, const char *needle, uint32_t ln)
function
void shdiff_build_texts_from_diff
(char **t1, uint32_t *l1, char **t2, uint32_t *l2, const shdiff_diff *diff)