Rizin
unix-like reverse engineering framework and cli tools
lines_diff.c File Reference

Go to the source code of this file.

Macros

#define DIFF_IS_LINES_METHOD(x)   (x.elem_at == methods_lines.elem_at)
 

Functions

static RzListtokenize_lines (const char *string)
 
static const void * line_elem_at (const RzList *array, ut32 index)
 
static int line_compare (const char *a_elem, const char *b_elem)
 
static ut32 line_hash (const char *elem)
 
static void line_stringify (const char *a_elem, RzStrBuf *sb)
 
static void line_free (RzList *array)
 

Variables

static const MethodsInternal methods_lines
 

Macro Definition Documentation

◆ DIFF_IS_LINES_METHOD

#define DIFF_IS_LINES_METHOD (   x)    (x.elem_at == methods_lines.elem_at)

Definition at line 6 of file lines_diff.c.

Function Documentation

◆ line_compare()

static int line_compare ( const char *  a_elem,
const char *  b_elem 
)
static

Definition at line 53 of file lines_diff.c.

53  {
54  return strcmp(a_elem, b_elem);
55 }

◆ line_elem_at()

static const void* line_elem_at ( const RzList array,
ut32  index 
)
static

Definition at line 49 of file lines_diff.c.

49  {
50  return rz_list_get_n(array, index);
51 }
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574

References rz_list_get_n().

◆ line_free()

static void line_free ( RzList array)
static

Definition at line 66 of file lines_diff.c.

66  {
67  rz_list_free(array);
68 }
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137

References rz_list_free().

◆ line_hash()

static ut32 line_hash ( const char *  elem)
static

Definition at line 57 of file lines_diff.c.

57  {
58  ut32 size = strlen(elem);
59  return rz_diff_hash_data((const ut8 *)elem, size);
60 }
uint32_t ut32
RZ_API ut32 rz_diff_hash_data(RZ_NULLABLE const ut8 *buffer, ut32 size)
Calculates the hash of any given data.
Definition: diff.c:103
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11

References rz_diff_hash_data().

◆ line_stringify()

static void line_stringify ( const char *  a_elem,
RzStrBuf sb 
)
static

Definition at line 62 of file lines_diff.c.

62  {
63  rz_strbuf_set(sb, a_elem);
64 }
static SblHeader sb
Definition: bin_mbn.c:26
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153

References rz_strbuf_set(), and sb.

◆ tokenize_lines()

static RzList* tokenize_lines ( const char *  string)
static

Definition at line 8 of file lines_diff.c.

8  {
9  RzList *lines = NULL;
10  size_t last = 0;
11  size_t size = 0;
12  char *line = NULL;
13 
15  if (!lines) {
16  RZ_LOG_ERROR("rz_diff_line_new: cannot allocate list of lines\n");
17  goto tokenize_newlines_fail;
18  }
19 
20  size = strlen(string);
21  for (size_t i = 0; i < size; ++i) {
22  if (string[i] == '\n') {
23  line = rz_str_ndup(string + last, (i + 1) - last);
24  if (!line || !rz_list_append(lines, line)) {
25  RZ_LOG_ERROR("rz_diff_line_new: cannot allocate line or add it to the list\n");
26  free(line);
27  goto tokenize_newlines_fail;
28  }
29  last = i + 1;
30  }
31  }
32 
33  if (last < size) {
34  line = rz_str_ndup(string + last, size - last);
35  if (!line || !rz_list_append(lines, line)) {
36  RZ_LOG_ERROR("rz_diff_line_new: cannot allocate last line or add it to the list\n");
37  free(line);
38  goto tokenize_newlines_fail;
39  }
40  }
41 
42  return lines;
43 
44 tokenize_newlines_fail:
46  return NULL;
47 }
lzma_index ** i
Definition: index.h:629
static RzBinSourceLineInfo * lines(RzBinFile *bf)
Definition: bin_symbols.c:427
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
line
Definition: setup.py:34
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006

References free(), i, setup::line, lines(), NULL, rz_list_append(), rz_list_free(), rz_list_newf(), RZ_LOG_ERROR, and rz_str_ndup().

Referenced by rz_diff_lines_new().

Variable Documentation

◆ methods_lines

const MethodsInternal methods_lines
static
Initial value:
= {
.ignore = fake_ignore,
}
static bool fake_ignore(const void *value)
Definition: diff.c:118
void(* RzDiffMethodFree)(const void *array)
Definition: diff.c:78
static int line_compare(const char *a_elem, const char *b_elem)
Definition: lines_diff.c:53
static void line_free(RzList *array)
Definition: lines_diff.c:66
static void line_stringify(const char *a_elem, RzStrBuf *sb)
Definition: lines_diff.c:62
static ut32 line_hash(const char *elem)
Definition: lines_diff.c:57
static const void * line_elem_at(const RzList *array, ut32 index)
Definition: lines_diff.c:49
const void *(* RzDiffMethodElemAt)(RZ_BORROW const void *array, ut32 index)
Definition: rz_diff.h:36
ut32(* RzDiffMethodElemHash)(RZ_BORROW const void *elem)
Definition: rz_diff.h:37
void(* RzDiffMethodStringify)(RZ_BORROW const void *elem, RZ_BORROW RzStrBuf *sb)
Definition: rz_diff.h:40
int(* RzDiffMethodCompare)(RZ_BORROW const void *a_elem, RZ_BORROW const void *b_elem)
Definition: rz_diff.h:38

Definition at line 70 of file lines_diff.c.

Referenced by rz_diff_lines_new().