xref: /openbsd/usr.bin/cvs/rcs.h (revision ce7279d8)
1*ce7279d8Sjsg /*	$OpenBSD: rcs.h,v 1.104 2024/05/21 05:00:48 jsg Exp $	*/
26c121f58Sjfb /*
36c121f58Sjfb  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
46c121f58Sjfb  * All rights reserved.
56c121f58Sjfb  *
66c121f58Sjfb  * Redistribution and use in source and binary forms, with or without
76c121f58Sjfb  * modification, are permitted provided that the following conditions
86c121f58Sjfb  * are met:
96c121f58Sjfb  *
106c121f58Sjfb  * 1. Redistributions of source code must retain the above copyright
116c121f58Sjfb  *    notice, this list of conditions and the following disclaimer.
126c121f58Sjfb  * 2. The name of the author may not be used to endorse or promote products
136c121f58Sjfb  *    derived from this software without specific prior written permission.
146c121f58Sjfb  *
156c121f58Sjfb  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
166c121f58Sjfb  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
176c121f58Sjfb  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
186c121f58Sjfb  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
196c121f58Sjfb  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
206c121f58Sjfb  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
216c121f58Sjfb  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
226c121f58Sjfb  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
236c121f58Sjfb  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
246c121f58Sjfb  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
256c121f58Sjfb  */
266c121f58Sjfb 
276c121f58Sjfb #ifndef RCS_H
286c121f58Sjfb #define RCS_H
29394437e6Stobias 
30394437e6Stobias #include <stdio.h>
319a265d19Schl #include <time.h>
32394437e6Stobias 
336c121f58Sjfb #include "buf.h"
346c121f58Sjfb 
356c121f58Sjfb #define RCS_DIFF_DIV \
366c121f58Sjfb 	"==================================================================="
376c121f58Sjfb 
386c121f58Sjfb #define RCS_FILE_EXT		",v"
396c121f58Sjfb 
40a33e30caSjfb #define RCS_HEAD_BRANCH		"HEAD"
416c121f58Sjfb #define RCS_HEAD_INIT		"1.1"
42a33e30caSjfb #define RCS_HEAD_REV		((RCSNUM *)(-1))
436c121f58Sjfb 
44f9872b43Sjoris #define RCS_CONFLICT_MARKER1	"<<<<<<< "
45f9872b43Sjoris #define RCS_CONFLICT_MARKER2	">>>>>>> "
46f9872b43Sjoris #define RCS_CONFLICT_MARKER3	"=======\n"
47a021dec5Sjfb 
485be71afaSjfb #define RCS_SYM_INVALCHAR	"$,.:;@"
495be71afaSjfb 
50b64c20faSjoris #define RCS_MAGIC_BRANCH	".0."
51a33e30caSjfb #define RCS_STATE_EXP		"Exp"
52a33e30caSjfb #define RCS_STATE_DEAD		"dead"
53a33e30caSjfb 
54a021dec5Sjfb /* lock types */
5599466da1Sjfb #define RCS_LOCK_INVAL		(-1)
56a021dec5Sjfb #define RCS_LOCK_LOOSE		0
57a021dec5Sjfb #define RCS_LOCK_STRICT		1
58a021dec5Sjfb 
59a718728aSniallo /*
60a718728aSniallo  * Keyword expansion table
61a718728aSniallo  */
62a718728aSniallo #define RCS_KW_AUTHOR		0x1000
63a718728aSniallo #define RCS_KW_DATE		0x2000
64a718728aSniallo #define RCS_KW_LOG		0x4000
65a718728aSniallo #define RCS_KW_NAME		0x8000
66a718728aSniallo #define RCS_KW_RCSFILE		0x0100
67a718728aSniallo #define RCS_KW_REVISION		0x0200
68a718728aSniallo #define RCS_KW_SOURCE		0x0400
69a718728aSniallo #define RCS_KW_STATE		0x0800
70a718728aSniallo #define RCS_KW_FULLPATH		0x0010
71f4827e12Sniallo #define RCS_KW_MDOCDATE		0x0020
725c14cef8Stobias #define RCS_KW_LOCKER		0x0040
73a718728aSniallo 
74a718728aSniallo #define RCS_KW_ID \
75a718728aSniallo 	(RCS_KW_RCSFILE | RCS_KW_REVISION | RCS_KW_DATE \
76a718728aSniallo 	| RCS_KW_AUTHOR | RCS_KW_STATE)
77a718728aSniallo 
78a718728aSniallo #define RCS_KW_HEADER	(RCS_KW_ID | RCS_KW_FULLPATH)
79a718728aSniallo 
80b856966bSjfb /* RCS keyword expansion modes (kflags) */
8187d368dcStobias #define RCS_KWEXP_NONE	0x01	/* do not expand keywords */
8287d368dcStobias #define RCS_KWEXP_NAME	0x02	/* include keyword name */
8387d368dcStobias #define RCS_KWEXP_VAL	0x04	/* include keyword value */
8487d368dcStobias #define RCS_KWEXP_LKR	0x08	/* include name of locker */
8587d368dcStobias #define RCS_KWEXP_OLD	0x10	/* generate old keyword string */
8687d368dcStobias #define RCS_KWEXP_ERR	0x20	/* mode has an error */
87b856966bSjfb 
88b856966bSjfb #define RCS_KWEXP_DEFAULT	(RCS_KWEXP_NAME | RCS_KWEXP_VAL)
89b856966bSjfb #define RCS_KWEXP_KVL		(RCS_KWEXP_NAME | RCS_KWEXP_VAL | RCS_KWEXP_LKR)
90b856966bSjfb 
911b6534b8Sjfb #define RCS_KWEXP_INVAL(k) \
92a23c5e53Sjfb 	((k & RCS_KWEXP_ERR) || \
93fb4424afSray 	((k & RCS_KWEXP_OLD) && (k & ~RCS_KWEXP_OLD)))
941b6534b8Sjfb 
95a718728aSniallo struct rcs_kw {
96a718728aSniallo 	char	kw_str[16];
97a718728aSniallo 	int	kw_type;
98a718728aSniallo };
99a718728aSniallo 
100a718728aSniallo #define RCS_NKWORDS	(sizeof(rcs_expkw)/sizeof(rcs_expkw[0]))
101b856966bSjfb 
102b856966bSjfb #define RCSNUM_MAXNUM	USHRT_MAX
1038fe0da22Stedu #define RCSNUM_MAXLEN	16
1048fe0da22Stedu #define RCSNUM_MAXSTR	64
105b856966bSjfb 
1062043120eSjfb #define RCSNUM_ISBRANCH(n)	((n)->rn_len % 2)
107b1ce7b24Sjoris #define RCSNUM_ISBRANCHREV(n)	(!((n)->rn_len % 2) && ((n)->rn_len >= 4))
1086c121f58Sjfb 
1096c121f58Sjfb /* file flags */
110b71c7dfeSniallo #define RCS_READ	  (1<<0)
111cc89a134Snicm #define RCS_WRITE	  (1<<1)  /* flush changes on rcs_close() */
112b71c7dfeSniallo #define RCS_CREATE	  (1<<2)  /* create the file */
113b71c7dfeSniallo #define RCS_PARSE_FULLY   (1<<3)  /* fully parse it on open */
1141b6534b8Sjfb 
1151b6534b8Sjfb /* internal flags */
116b71c7dfeSniallo #define RCS_PARSED	  (1<<4)  /* file has been parsed */
117b71c7dfeSniallo #define RCS_SYNCED	  (1<<5)  /* in-mem copy is sync with disk copy */
118b71c7dfeSniallo #define RCS_SLOCK	  (1<<6)  /* strict lock */
119b71c7dfeSniallo 
120b71c7dfeSniallo /* parser flags */
121b71c7dfeSniallo #define PARSED_DELTAS     (1<<7)  /* all deltas are parsed */
122b71c7dfeSniallo #define PARSED_DESC       (1<<8)  /* the description is parsed */
123b71c7dfeSniallo #define PARSED_DELTATEXTS (1<<9)  /* all delta texts are parsed */
1246c121f58Sjfb 
1256c121f58Sjfb /* delta flags */
1266c121f58Sjfb #define RCS_RD_DEAD	0x01	/* dead */
1273c6748a1Sray #define RCS_RD_SELECT	0x02	/* select for operation */
1286c121f58Sjfb 
12952248372Sjcs /* commitids in cvs/cvsnt can be up to 64 bytes */
13052248372Sjcs #define RCS_COMMITID_MAXLEN 64
13152248372Sjcs 
1326c121f58Sjfb typedef struct rcs_num {
1336c121f58Sjfb 	u_int		 rn_len;
1348fe0da22Stedu 	u_int16_t	 rn_id[RCSNUM_MAXLEN];
1356c121f58Sjfb } RCSNUM;
1366c121f58Sjfb 
137d510a4e8Sjfb struct rcs_access {
138d510a4e8Sjfb 	char			*ra_name;
139d510a4e8Sjfb 	TAILQ_ENTRY(rcs_access)	 ra_list;
140d510a4e8Sjfb };
141d510a4e8Sjfb 
1426c121f58Sjfb struct rcs_sym {
1436c121f58Sjfb 	char			*rs_name;
1446c121f58Sjfb 	RCSNUM			*rs_num;
1456c121f58Sjfb 	TAILQ_ENTRY(rcs_sym)	 rs_list;
1466c121f58Sjfb };
1476c121f58Sjfb 
1486c121f58Sjfb struct rcs_lock {
149a33e30caSjfb 	char	*rl_name;
1506c121f58Sjfb 	RCSNUM	*rl_num;
1516c121f58Sjfb 
1526c121f58Sjfb 	TAILQ_ENTRY(rcs_lock)	 rl_list;
1536c121f58Sjfb };
1546c121f58Sjfb 
1556c121f58Sjfb struct rcs_branch {
1566c121f58Sjfb 	RCSNUM			*rb_num;
1576c121f58Sjfb 	TAILQ_ENTRY(rcs_branch)	 rb_list;
1586c121f58Sjfb };
1596c121f58Sjfb 
1604d7056deSray TAILQ_HEAD(rcs_dlist, rcs_delta);
1616c121f58Sjfb 
1626c121f58Sjfb struct rcs_delta {
1636c121f58Sjfb 	RCSNUM		*rd_num;
1646c121f58Sjfb 	RCSNUM		*rd_next;
16590fdc30cSotto 	int		 rd_flags;
1666c121f58Sjfb 	struct tm	 rd_date;
1676c121f58Sjfb 	char		*rd_author;
1686c121f58Sjfb 	char		*rd_state;
16952248372Sjcs 	char		*rd_commitid;
1706c121f58Sjfb 	char		*rd_log;
171bbfcb536Sjoris 	char		*rd_locker;
172b76fdb84Sjfb 	u_char		*rd_text;
173163f330fSjfb 	size_t		 rd_tlen;
1746c121f58Sjfb 
1756c121f58Sjfb 	TAILQ_HEAD(, rcs_branch)	rd_branches;
1766c121f58Sjfb 	TAILQ_ENTRY(rcs_delta)		rd_list;
1776c121f58Sjfb };
1786c121f58Sjfb 
1796c121f58Sjfb 
1806c121f58Sjfb typedef struct rcs_file {
181394437e6Stobias 	FILE	*rf_file;
1823258e4a0Sjoris 	int	 rf_dead;
1836c121f58Sjfb 	char	*rf_path;
1841b6534b8Sjfb 	mode_t	 rf_mode;
18590fdc30cSotto 	int	 rf_flags;
1866c121f58Sjfb 
1876c121f58Sjfb 	RCSNUM	*rf_head;
1886c121f58Sjfb 	RCSNUM	*rf_branch;
1896c121f58Sjfb 	char	*rf_comment;
1906c121f58Sjfb 	char	*rf_expand;
1916c121f58Sjfb 	char	*rf_desc;
1926c121f58Sjfb 
1931b6534b8Sjfb 	u_int					rf_ndelta;
1946c121f58Sjfb 	struct rcs_dlist			rf_delta;
195d510a4e8Sjfb 	TAILQ_HEAD(rcs_alist, rcs_access)	rf_access;
1966c121f58Sjfb 	TAILQ_HEAD(rcs_slist, rcs_sym)		rf_symbols;
1976c121f58Sjfb 	TAILQ_HEAD(rcs_llist, rcs_lock)		rf_locks;
1986c121f58Sjfb 
1996c121f58Sjfb 	void	*rf_pdata;
2006c121f58Sjfb } RCSFILE;
2016c121f58Sjfb 
2027bb3ddb0Sray struct rcs_line;
2037bb3ddb0Sray struct rcs_lines;
2044580e1eeSjfb 
2053ad3fb45Sjoris RCSFILE			*rcs_open(const char *, int, int, ...);
2066c121f58Sjfb void			 rcs_close(RCSFILE *);
20708458e59Sjoris RCSNUM			*rcs_head_get(RCSFILE *);
208b71c7dfeSniallo int			 rcs_head_set(RCSFILE *, RCSNUM *);
20945b98c07Stobias RCSNUM			*rcs_branch_new(RCSFILE *, RCSNUM *);
21095553451Sjfb const RCSNUM		*rcs_branch_get(RCSFILE *);
21195553451Sjfb int			 rcs_branch_set(RCSFILE *, const RCSNUM *);
212d510a4e8Sjfb int			 rcs_access_add(RCSFILE *, const char *);
213d510a4e8Sjfb int			 rcs_access_remove(RCSFILE *, const char *);
214b71c7dfeSniallo struct rcs_delta	*rcs_findrev(RCSFILE *, RCSNUM *);
2151b6534b8Sjfb int			 rcs_sym_add(RCSFILE *, const char *, RCSNUM *);
216a0d919f1Sxsa int			 rcs_sym_check(const char *);
217a0d919f1Sxsa struct rcs_sym		*rcs_sym_get(RCSFILE *, const char *);
2181b6534b8Sjfb int			 rcs_sym_remove(RCSFILE *, const char *);
219101fc366Sjfb RCSNUM			*rcs_sym_getrev(RCSFILE *, const char *);
22045d60d54Sjoris RCSNUM			*rcs_translate_tag(const char *, RCSFILE *);
221a021dec5Sjfb int			 rcs_lock_getmode(RCSFILE *);
222a021dec5Sjfb int			 rcs_lock_setmode(RCSFILE *, int);
223a33e30caSjfb int			 rcs_lock_add(RCSFILE *, const char *, RCSNUM *);
224bbfcb536Sjoris int			 rcs_lock_remove(RCSFILE *, const char *, RCSNUM *);
2254d33f394Sjoris int			 rcs_deltatext_set(RCSFILE *, RCSNUM *, BUF *);
226101fc366Sjfb const char		*rcs_desc_get(RCSFILE *);
227f92ad66fSxsa void			 rcs_desc_set(RCSFILE *, const char *);
228ff88b297Sjfb const char		*rcs_comment_lookup(const char *);
22970e8f52aSjfb const char		*rcs_comment_get(RCSFILE *);
2301d612bafSxsa void			 rcs_comment_set(RCSFILE *, const char *);
23186ca4362Sxsa void			 rcs_kwexp_set(RCSFILE *, int);
2321b6534b8Sjfb int			 rcs_kwexp_get(RCSFILE *);
23344b1b892Sniallo int			 rcs_rev_add(RCSFILE *, RCSNUM *, const char *, time_t,
23444b1b892Sniallo 			     const char *);
235c4521683Sniallo time_t			 rcs_rev_getdate(RCSFILE *, RCSNUM *);
236e2cf1205Sjoris int			 rcs_rev_setlog(RCSFILE *, RCSNUM *, const char *);
2373797569aSjfb int			 rcs_rev_remove(RCSFILE *, RCSNUM *);
2389aae8b12Sniallo int			 rcs_state_set(RCSFILE *, RCSNUM *, const char *);
239c4521683Sniallo const char		*rcs_state_get(RCSFILE *, RCSNUM *);
2409aae8b12Sniallo int			 rcs_state_check(const char *);
2413ad3fb45Sjoris void			 rcs_write(RCSFILE *);
2422e0d696aSjoris int			 rcs_rev_write_stmp(RCSFILE *,  RCSNUM *, char *, int);
243c86b3c7cSjoris void			 rcs_rev_write_fd(RCSFILE *, RCSNUM *, int, int);
2447bb3ddb0Sray struct rcs_lines	*rcs_rev_getlines(RCSFILE *, RCSNUM *,
2457bb3ddb0Sray 			     struct rcs_line ***);
24637cbc181Stobias void			 rcs_annotate_getlines(RCSFILE *, RCSNUM *,
2477bb3ddb0Sray 			     struct rcs_line ***);
248ff7b57e3Sjoris BUF			*rcs_rev_getbuf(RCSFILE *, RCSNUM *, int);
2499f5450fbSjoris void			 rcs_delta_stats(struct rcs_delta *, int *, int *);
2503797569aSjfb 
251b856966bSjfb int	rcs_kflag_get(const char *);
252b856966bSjfb 
2536c121f58Sjfb RCSNUM	*rcsnum_alloc(void);
25417d257bdSjfb RCSNUM	*rcsnum_parse(const char *);
2552043120eSjfb RCSNUM	*rcsnum_brtorev(const RCSNUM *);
2562043120eSjfb RCSNUM	*rcsnum_revtobr(const RCSNUM *);
2572043120eSjfb RCSNUM	*rcsnum_inc(RCSNUM *);
2582c56d68bSjoris RCSNUM	*rcsnum_dec(RCSNUM *);
25918cf7829Sjoris RCSNUM	*rcsnum_branch_root(RCSNUM *);
260e8f8196dStobias RCSNUM	*rcsnum_new_branch(RCSNUM *);
2610f301d36Stobias int	 rcsnum_addmagic(RCSNUM *);
2620fcddf58Sotto int	 rcsnum_aton(const char *, const char **, RCSNUM *);
2636c121f58Sjfb char	*rcsnum_tostr(const RCSNUM *, char *, size_t);
2640f9a9ee2Sray void	 rcsnum_cpy(const RCSNUM *, RCSNUM *, u_int);
26540e206ceSjoris int	 rcsnum_cmp(RCSNUM *, RCSNUM *, u_int);
26640e206ceSjoris int	 rcsnum_differ(RCSNUM *, RCSNUM *);
2676c121f58Sjfb 
2686c121f58Sjfb #endif	/* RCS_H */
269