summaryrefslogtreecommitdiffstats
path: root/src/util/argv.h
blob: b0098ce1303ab1f5ea0d55232c2f5bb48c6ec528 (plain)
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
77
78
#ifndef _ARGV_H_INCLUDED_
#define _ARGV_H_INCLUDED_

/*++
/* NAME
/*	argv 3h
/* SUMMARY
/*	string array utilities
/* SYNOPSIS
/*	#include "argv.h"
/* DESCRIPTION
/* .nf

 /*
  * External interface.
  */
typedef struct ARGV {
    ssize_t len;			/* number of array elements */
    ssize_t argc;			/* array elements in use */
    char  **argv;			/* string array */
} ARGV;

typedef int (*ARGV_COMPAR_FN)(const void *, const void *);

extern ARGV *argv_alloc(ssize_t);
extern ARGV *argv_sort(ARGV *);		/* backwards compatibility */
extern ARGV *argv_qsort(ARGV *, ARGV_COMPAR_FN);
extern ARGV *argv_uniq(ARGV *, ARGV_COMPAR_FN);
extern void argv_add(ARGV *,...);
extern void argv_addn(ARGV *,...);
extern void argv_terminate(ARGV *);
extern void argv_truncate(ARGV *, ssize_t);
extern void argv_insert_one(ARGV *, ssize_t, const char *);
extern void argv_replace_one(ARGV *, ssize_t, const char *);
extern void argv_delete(ARGV *, ssize_t, ssize_t);
extern ARGV *argv_free(ARGV *);

extern ARGV *argv_split(const char *, const char *);
extern ARGV *argv_split_count(const char *, const char *, ssize_t);
extern ARGV *argv_split_append(ARGV *, const char *, const char *);

extern ARGV *argv_splitq(const char *, const char *, const char *);
extern ARGV *argv_splitq_count(const char *, const char *, const char *, ssize_t);
extern ARGV *argv_splitq_append(ARGV *, const char *, const char *, const char *);

extern ARGV *argv_split_at(const char *, int);
extern ARGV *argv_split_at_count(const char *, int, ssize_t);
extern ARGV *argv_split_at_append(ARGV *, const char *, int);

#define ARGV_FAKE_BEGIN(fake_argv, arg) { \
	ARGV fake_argv; \
	char *__fake_argv_args__[2]; \
	__fake_argv_args__[0] = (char *) (arg); \
	__fake_argv_args__[1] = 0; \
	fake_argv.argv = __fake_argv_args__; \
	fake_argv.argc = fake_argv.len = 1;

#define ARGV_FAKE_END	}

#define ARGV_END	((char *) 0)

/* LICENSE
/* .ad
/* .fi
/*	The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/*	Wietse Venema
/*	IBM T.J. Watson Research
/*	P.O. Box 704
/*	Yorktown Heights, NY 10598, USA
/*
/*	Wietse Venema
/*	Google, Inc.
/*	111 8th Avenue
/*	New York, NY 10011, USA
/*--*/

#endif