rcs.h revision 1.7
1/*	$OpenBSD: rcs.h,v 1.7 2008/01/31 16:36:11 tobias Exp $	*/
2/*
3 * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products
13 *    derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef RCS_H
28#define RCS_H
29
30#include <sys/queue.h>
31
32#include "buf.h"
33
34#define RCS_DIFF_MAXARG		32
35#define RCS_DIFF_DIV \
36	"==================================================================="
37
38#define RCSDIR			"RCS"
39#define RCS_FILE_EXT		",v"
40
41#define RCS_HEAD_BRANCH		"HEAD"
42#define RCS_HEAD_INIT		"1.1"
43#define RCS_HEAD_REV		((RCSNUM *)(-1))
44
45
46#define RCS_SYM_INVALCHAR	"$,.:;@"
47
48
49#define RCS_MAGIC_BRANCH	".0."
50#define RCS_STATE_EXP		"Exp"
51#define RCS_STATE_DEAD		"dead"
52
53/* lock types */
54#define RCS_LOCK_INVAL		(-1)
55#define RCS_LOCK_LOOSE		0
56#define RCS_LOCK_STRICT		1
57
58
59/*
60 * Keyword expansion table
61 */
62#define RCS_KW_AUTHOR		0x1000
63#define RCS_KW_DATE		0x2000
64#define RCS_KW_LOG		0x4000
65#define RCS_KW_NAME		0x8000
66#define RCS_KW_RCSFILE		0x0100
67#define RCS_KW_REVISION		0x0200
68#define RCS_KW_SOURCE		0x0400
69#define RCS_KW_STATE		0x0800
70#define RCS_KW_FULLPATH		0x0010
71
72#define RCS_KW_ID \
73	(RCS_KW_RCSFILE | RCS_KW_REVISION | RCS_KW_DATE \
74	| RCS_KW_AUTHOR | RCS_KW_STATE)
75
76#define RCS_KW_HEADER	(RCS_KW_ID | RCS_KW_FULLPATH)
77
78/* RCS keyword expansion modes (kflags) */
79#define RCS_KWEXP_NONE	0x00
80#define RCS_KWEXP_NAME	0x01	/* include keyword name */
81#define RCS_KWEXP_VAL	0x02	/* include keyword value */
82#define RCS_KWEXP_LKR	0x04	/* include name of locker */
83#define RCS_KWEXP_OLD	0x08	/* generate old keyword string */
84#define RCS_KWEXP_ERR	0x10	/* mode has an error */
85
86#define RCS_KWEXP_DEFAULT	(RCS_KWEXP_NAME | RCS_KWEXP_VAL)
87#define RCS_KWEXP_KVL		(RCS_KWEXP_NAME | RCS_KWEXP_VAL | RCS_KWEXP_LKR)
88
89#define RCS_KWEXP_INVAL(k) \
90	((k & RCS_KWEXP_ERR) || \
91	((k & RCS_KWEXP_OLD) && (k & ~RCS_KWEXP_OLD)))
92
93
94struct rcs_kw {
95	char	kw_str[16];
96	int	kw_type;
97};
98
99#define RCS_NKWORDS	(sizeof(rcs_expkw)/sizeof(rcs_expkw[0]))
100
101#define RCSNUM_MAXNUM	USHRT_MAX
102#define RCSNUM_MAXLEN	64
103
104#define RCSNUM_ISBRANCH(n)	((n)->rn_len % 2)
105#define RCSNUM_ISBRANCHREV(n)	(!((n)->rn_len % 2) && ((n)->rn_len >= 4))
106#define RCSNUM_NO_MAGIC		(1<<0)
107
108/* file flags */
109#define RCS_READ	  (1<<0)
110#define RCS_WRITE	  (1<<1)
111#define RCS_RDWR	  (RCS_READ|RCS_WRITE)
112#define RCS_CREATE	  (1<<2)  /* create the file */
113#define RCS_PARSE_FULLY   (1<<3)  /* fully parse it on open */
114
115/* internal flags */
116#define RCS_PARSED	  (1<<4)  /* file has been parsed */
117#define RCS_SYNCED	  (1<<5)  /* in-mem copy is sync with disk copy */
118#define RCS_SLOCK	  (1<<6)  /* strict lock */
119
120/* parser flags */
121#define PARSED_DELTAS     (1<<7)  /* all deltas are parsed */
122#define PARSED_DESC       (1<<8)  /* the description is parsed */
123#define PARSED_DELTATEXTS (1<<9)  /* all delta texts are parsed */
124
125/* delta flags */
126#define RCS_RD_DEAD	0x01	/* dead */
127#define RCS_RD_SELECT	0x02	/* select for operation */
128
129/* RCS error codes */
130#define RCS_ERR_NOERR	0
131#define RCS_ERR_NOENT	1
132#define RCS_ERR_DUPENT	2
133#define RCS_ERR_BADNUM	3
134#define RCS_ERR_BADSYM	4
135#define RCS_ERR_PARSE	5
136#define RCS_ERR_ERRNO	255
137
138/* used for rcs_checkout_rev */
139#define CHECKOUT_REV_CREATED	1
140#define CHECKOUT_REV_MERGED	2
141#define CHECKOUT_REV_REMOVED	3
142#define CHECKOUT_REV_UPDATED	4
143
144typedef struct rcs_num {
145	u_int		 rn_len;
146	u_int16_t	*rn_id;
147} RCSNUM;
148
149
150struct rcs_access {
151	char			*ra_name;
152	uid_t			 ra_uid;
153	TAILQ_ENTRY(rcs_access)	 ra_list;
154};
155
156struct rcs_sym {
157	char			*rs_name;
158	RCSNUM			*rs_num;
159	TAILQ_ENTRY(rcs_sym)	 rs_list;
160};
161
162struct rcs_lock {
163	char	*rl_name;
164	RCSNUM	*rl_num;
165
166	TAILQ_ENTRY(rcs_lock)	 rl_list;
167};
168
169
170struct rcs_branch {
171	RCSNUM			*rb_num;
172	TAILQ_ENTRY(rcs_branch)	 rb_list;
173};
174
175TAILQ_HEAD(rcs_dlist, rcs_delta);
176
177struct rcs_delta {
178	RCSNUM		*rd_num;
179	RCSNUM		*rd_next;
180	u_int		 rd_flags;
181	struct tm	 rd_date;
182	char		*rd_author;
183	char		*rd_state;
184	char		*rd_log;
185	char		*rd_locker;
186	u_char		*rd_text;
187	size_t		 rd_tlen;
188
189	TAILQ_HEAD(, rcs_branch)	rd_branches;
190	TAILQ_ENTRY(rcs_delta)		rd_list;
191};
192
193
194typedef struct rcs_file {
195	int	 rf_fd;
196	char	*rf_path;
197	mode_t	 rf_mode;
198	u_int	 rf_flags;
199
200	RCSNUM	*rf_head;
201	RCSNUM	*rf_branch;
202	char	*rf_comment;
203	char	*rf_expand;
204	char	*rf_desc;
205
206	u_int					rf_ndelta;
207	struct rcs_dlist			rf_delta;
208	TAILQ_HEAD(rcs_alist, rcs_access)	rf_access;
209	TAILQ_HEAD(rcs_slist, rcs_sym)		rf_symbols;
210	TAILQ_HEAD(rcs_llist, rcs_lock)		rf_locks;
211
212	void	*rf_pdata;
213} RCSFILE;
214
215extern int rcs_errno;
216
217RCSFILE			*rcs_open(const char *, int, int, ...);
218void			 rcs_close(RCSFILE *);
219const RCSNUM		*rcs_head_get(RCSFILE *);
220int			 rcs_head_set(RCSFILE *, RCSNUM *);
221const RCSNUM		*rcs_branch_get(RCSFILE *);
222int			 rcs_branch_set(RCSFILE *, const RCSNUM *);
223int			 rcs_access_add(RCSFILE *, const char *);
224int			 rcs_access_remove(RCSFILE *, const char *);
225int			 rcs_access_check(RCSFILE *, const char *);
226struct rcs_delta	*rcs_findrev(RCSFILE *, RCSNUM *);
227int			 rcs_sym_add(RCSFILE *, const char *, RCSNUM *);
228int			 rcs_sym_remove(RCSFILE *, const char *);
229RCSNUM			*rcs_sym_getrev(RCSFILE *, const char *);
230int			 rcs_sym_check(const char *);
231int			 rcs_lock_getmode(RCSFILE *);
232int			 rcs_lock_setmode(RCSFILE *, int);
233int			 rcs_lock_add(RCSFILE *, const char *, RCSNUM *);
234int			 rcs_lock_remove(RCSFILE *, const char *, RCSNUM *);
235BUF			*rcs_getrev(RCSFILE *, RCSNUM *);
236int			 rcs_deltatext_set(RCSFILE *, RCSNUM *, BUF *);
237const char		*rcs_desc_get(RCSFILE *);
238void			 rcs_desc_set(RCSFILE *, const char *);
239const char		*rcs_comment_lookup(const char *);
240const char		*rcs_comment_get(RCSFILE *);
241void			 rcs_comment_set(RCSFILE *, const char *);
242BUF			*rcs_kwexp_buf(BUF *, RCSFILE *, RCSNUM *);
243void			 rcs_kwexp_set(RCSFILE *, int);
244int			 rcs_kwexp_get(RCSFILE *);
245int			 rcs_rev_add(RCSFILE *, RCSNUM *, const char *, time_t,
246			     const char *);
247time_t			 rcs_rev_getdate(RCSFILE *, RCSNUM *);
248int			 rcs_rev_setlog(RCSFILE *, RCSNUM *, const char *);
249int			 rcs_rev_remove(RCSFILE *, RCSNUM *);
250int			 rcs_state_set(RCSFILE *, RCSNUM *, const char *);
251const char		*rcs_state_get(RCSFILE *, RCSNUM *);
252int			 rcs_state_check(const char *);
253RCSNUM			*rcs_tag_resolve(RCSFILE *, const char *);
254const char		*rcs_errstr(int);
255void			 rcs_write(RCSFILE *);
256
257int	rcs_kflag_get(const char *);
258void	rcs_kflag_usage(void);
259int	rcs_kw_expand(RCSFILE *, u_char *, size_t, size_t *);
260
261RCSNUM	*rcsnum_alloc(void);
262RCSNUM	*rcsnum_parse(const char *);
263RCSNUM	*rcsnum_brtorev(const RCSNUM *);
264RCSNUM	*rcsnum_revtobr(const RCSNUM *);
265RCSNUM	*rcsnum_inc(RCSNUM *);
266RCSNUM	*rcsnum_dec(RCSNUM *);
267void	 rcsnum_free(RCSNUM *);
268int	 rcsnum_addmagic(RCSNUM *);
269int	 rcsnum_aton(const char *, char **, RCSNUM *);
270char	*rcsnum_tostr(const RCSNUM *, char *, size_t);
271void	 rcsnum_cpy(const RCSNUM *, RCSNUM *, u_int);
272int	 rcsnum_cmp(const RCSNUM *, const RCSNUM *, u_int);
273
274/* rcstime.c */
275void	 rcs_set_tz(char *, struct rcs_delta *, struct tm *);
276extern char *timezone_flag;
277extern int rcsnum_flags;
278
279#endif	/* RCS_H */
280