strlist.h 2.35 KB
Newer Older
Bernhard Link's avatar
Bernhard Link committed
1 2
#ifndef REPREPRO_STRLIST_H
#define REPREPRO_STRLIST_H
Bernhard Link's avatar
Bernhard Link committed
3

Bernhard Link's avatar
Bernhard Link committed
4
#ifndef REPREPRO_ERROR_H
Bernhard Link's avatar
Bernhard Link committed
5 6 7
#include "error.h"
#warning "What's hapening here?"
#endif
Bernhard Link's avatar
Bernhard Link committed
8 9 10 11
#ifndef REPREPRO_GLOBALS_H
#include "globals.h"
#warning "What's hapening here?"
#endif
Bernhard Link's avatar
Bernhard Link committed
12 13 14 15 16 17

struct strlist {
	char **values;
	int count,size;
};

Bernhard Link's avatar
Bernhard Link committed
18
void strlist_init(/*@out@*/struct strlist *strlist);
19
retvalue strlist_init_n(int startsize,/*@out@*/struct strlist *strlist);
20
retvalue strlist_init_singleton(/*@only@*/char *value,/*@out@*/struct strlist *strlist);
21
void strlist_done(/*@special@*/struct strlist *strlist) /*@releases strlist->values @*/;
Bernhard Link's avatar
Bernhard Link committed
22 23

/* add a string, will get property of the strlist and free'd by it */
24
retvalue strlist_add(struct strlist *strlist,/*@only@*/char *element);
25
/* include a string at the beginning, otherwise like strlist_add */
26
retvalue strlist_include(struct strlist *strlist,/*@only@*/char *element);
27
/* add a string alphabetically, discarding if already there. */
28
retvalue strlist_adduniq(struct strlist *strlist,/*@only@*/char *element);
Bernhard Link's avatar
Bernhard Link committed
29 30
/* like strlist_add, but strdup it first */
retvalue strlist_add_dup(struct strlist *strlist, const char *todup);
Bernhard Link's avatar
Bernhard Link committed
31

Bernhard Link's avatar
Bernhard Link committed
32
/* print a space separated list of elements */
33 34 35 36
retvalue strlist_fprint(FILE *file,const struct strlist *strlist);

/* duplicate with content */
retvalue strlist_dup(struct strlist *dest,const struct strlist *orig);
Bernhard Link's avatar
Bernhard Link committed
37
/* replace the contents of dest with those from orig, which get emptied */
38
void strlist_move(/*@out@*/struct strlist *dest, /*@special@*/struct strlist *orig) /*@releases orig->values @*/;
39
/* empty orig and add everything to the end of dest, on error nothing is freed */
40
retvalue strlist_mvadd(struct strlist *dest, /*@special@*/struct strlist *orig) /*@releases orig->values @*/;
41

42
bool strlist_in(const struct strlist *strlist, const char *element);
Bernhard Link's avatar
Bernhard Link committed
43
int strlist_ofs(const struct strlist *strlist,const char *element);
44

45
bool strlist_intersects(const struct strlist *, const struct strlist *);
46
/* if missing != NULL And subset no subset of strlist, set *missing to the first missing one */
47
bool strlist_subset(const struct strlist *strlist, const struct strlist *subset, const char **missing);
Bernhard Link's avatar
Bernhard Link committed
48

49 50
/* concatenate <prefix> <values separated by infix> <suffix> */
char *strlist_concat(const struct strlist *, const char *prefix, const char *infix, const char *suffix);
Bernhard Link's avatar
Bernhard Link committed
51 52 53

/* remove all strings equal to the argument */
void strlist_remove(struct strlist *, const char *);
Bernhard Link's avatar
Bernhard Link committed
54
#endif