-
Notifications
You must be signed in to change notification settings - Fork 3
/
add_run.c
76 lines (66 loc) · 1.54 KB
/
add_run.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* This file is part of the software similarity tester SIM.
Written by Dick Grune, Vrije Universiteit, Amsterdam.
$Id: add_run.c,v 2.12 2012-06-05 09:58:52 Gebruiker Exp $
*/
#include "sim.h"
#include "debug.par"
#include "text.h"
#include "runs.h"
#include "percentages.h"
#include "Malloc.h"
#include "options.h"
#include "error.h"
#include "add_run.h"
static void set_chunk(
struct chunk *,
struct text *,
size_t,
size_t
);
static void set_pos(
struct position *,
int,
struct text *,
size_t
);
void
add_run(struct text *txt0, size_t i0,
struct text *txt1, size_t i1,
size_t size
) {
/* Adds the run of given size to our collection.
*/
struct run *r = new(struct run);
set_chunk(&r->rn_chunk0, txt0, i0 - txt0->tx_start, size);
set_chunk(&r->rn_chunk1, txt1, i1 - txt1->tx_start, size);
r->rn_size = size;
#ifdef DB_RUN
db_run_info("Added", r, 0);
#endif /* DB_RUN */
if (is_set_option('p')) {
add_to_percentages(r);
}
else {
add_to_runs(r);
}
}
static void
set_chunk(struct chunk *cnk, struct text *txt,
size_t start, size_t size
) {
/* Fill the chunk *cnk with info about the piece of text
in txt starting at start extending over size tokens.
*/
cnk->ch_text = txt;
set_pos(&cnk->ch_first, 0, txt, start);
set_pos(&cnk->ch_last, 1, txt, start + size - 1);
}
static void
set_pos(struct position *pos, int type, struct text *txt, size_t start) {
/* Fill a single struct position */
pos->ps_next = txt->tx_pos;
txt->tx_pos = pos;
pos->ps_type = type;
pos->ps_tk_cnt = start;
pos->ps_nl_cnt = (size_t) -1; /* uninitialized */
}