-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheng.c
68 lines (53 loc) · 1.23 KB
/
eng.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
// SPDX-License-Identifier: GPL-2.0
// Author: Antoni Przybylik
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/uio.h>
#include "eng.h"
#include "shell.h"
#include "apn/sort.h"
extern uint8_t VERBOSE;
#define VPRINT(...) do { if (VERBOSE) printf(__VA_ARGS__); } while (0)
static struct fun fun_template = {
.magic = 0x7017D1395252A18D,
.vars_cnt = 0,
.ones_cnt = 0,
.ones = 0,
};
struct fun *new_fun(char *name)
{
struct fun *new_fun;
struct timespec *ts;
new_fun = malloc(sizeof(struct fun));
*new_fun = fun_template;
ts = malloc(sizeof(struct timespec));
timespec_get(ts, 1); /* 1 = TIME_UTC */
new_fun->ts = ts;
new_fun->name = malloc(strlen(name) + 1);
strcpy(new_fun->name, name);
return new_fun;
}
static bool cmp(uint64_t a, uint64_t b)
{
return a < b;
}
void normalize_fun(struct fun *fun)
{
int i, j;
uint64_t prev;
if (fun->ones_cnt < 2) return;
sort(fun->ones, fun->ones_cnt, cmp);
j = 1;
prev = fun->ones[0];
for (i = 1; i < fun->ones_cnt; i++) {
if (fun->ones[i] == prev) continue;
fun->ones[j++] = fun->ones[i];
prev = fun->ones[i];
}
fun->ones = realloc(fun->ones, j * sizeof(fun->ones[0]));
fun->ones_cnt = j;
}