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
|
#ifndef REPREPRO_CHUNKEDIT_H
#define REPREPRO_CHUNKEDIT_H
#ifndef REPREPRO_ERROR_H
#include "error.h"
#warning "What's hapening here?"
#endif
#ifndef REPREPRO_STRLIST_H
#include "strlist.h"
#endif
/* modifications of a chunk: */
struct chunkeditfield {
/*@null@*/struct chunkeditfield *next;
/* The name of the field: */
const char *field; size_t len_field;
enum cefaction { CEF_DELETE, /* delete if there */
CEF_ADDMISSED, /* add if not there */
CEF_REPLACE, /* replace if there */
CEF_ADD, /* add if not there or replace if there */
CEF_KEEP /* keep it */
} action;
enum cefwhen { CEF_EARLY, CEF_LATE } when;
/* the following must be 0 or NULL for CEF_DELETE */
size_t len_all_data;
/*@null@*/const char *data; size_t len_data;
const struct strlist *words;
int linecount;
struct cef_line {
int wordcount;
const char **words;
size_t *wordlen;
} lines[];
};
/* those return NULL on out of memory and free next in that case */
/*@null@*/struct chunkeditfield *cef_newfield(const char *, enum cefaction, enum cefwhen, unsigned int /*linecount*/, /*@only@*//*@null@*/struct chunkeditfield *);
void cef_setdata(struct chunkeditfield *, const char *);
void cef_setdatalen(struct chunkeditfield *, const char *, size_t);
/* calculate the length, do not change the strlist after that before free */
void cef_setwordlist(struct chunkeditfield *, const struct strlist *);
retvalue cef_setline(struct chunkeditfield *, int /*line*/, int /*wordcount*/, ...);
retvalue cef_setline2(struct chunkeditfield *, int, const char *, size_t, const char *, size_t, int, ...);
retvalue chunk_edit(const char *, char **, size_t *, const struct chunkeditfield *);
void cef_free(/*@only@*//*@null@*/struct chunkeditfield *);
static inline struct chunkeditfield *cef_pop(/*@only@*/struct chunkeditfield *cef) {
struct chunkeditfield *next = cef->next;
cef->next = NULL;
cef_free(cef);
return next;
}
#endif
|