1 /* $OpenBSD: rcs.h,v 1.92 2008/06/15 04:38:52 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 #include "buf.h" 30 31 #define RCS_DIFF_MAXARG 32 32 #define RCS_DIFF_DIV \ 33 "===================================================================" 34 35 #define RCSDIR "RCS" 36 #define RCS_FILE_EXT ",v" 37 38 #define RCS_HEAD_BRANCH "HEAD" 39 #define RCS_HEAD_INIT "1.1" 40 #define RCS_HEAD_REV ((RCSNUM *)(-1)) 41 42 #define RCS_CONFLICT_MARKER1 "<<<<<<< " 43 #define RCS_CONFLICT_MARKER2 ">>>>>>> " 44 #define RCS_CONFLICT_MARKER3 "=======\n" 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 #define RCS_KW_MDOCDATE 0x0020 72 #define RCS_KW_LOCKER 0x0040 73 74 #define RCS_KW_ID \ 75 (RCS_KW_RCSFILE | RCS_KW_REVISION | RCS_KW_DATE \ 76 | RCS_KW_AUTHOR | RCS_KW_STATE) 77 78 #define RCS_KW_HEADER (RCS_KW_ID | RCS_KW_FULLPATH) 79 80 /* RCS keyword expansion modes (kflags) */ 81 #define RCS_KWEXP_NONE 0x01 /* do not expand keywords */ 82 #define RCS_KWEXP_NAME 0x02 /* include keyword name */ 83 #define RCS_KWEXP_VAL 0x04 /* include keyword value */ 84 #define RCS_KWEXP_LKR 0x08 /* include name of locker */ 85 #define RCS_KWEXP_OLD 0x10 /* generate old keyword string */ 86 #define RCS_KWEXP_ERR 0x20 /* mode has an error */ 87 88 #define RCS_KWEXP_DEFAULT (RCS_KWEXP_NAME | RCS_KWEXP_VAL) 89 #define RCS_KWEXP_KVL (RCS_KWEXP_NAME | RCS_KWEXP_VAL | RCS_KWEXP_LKR) 90 91 #define RCS_KWEXP_INVAL(k) \ 92 ((k & RCS_KWEXP_ERR) || \ 93 ((k & RCS_KWEXP_OLD) && (k & ~RCS_KWEXP_OLD))) 94 95 96 struct rcs_kw { 97 char kw_str[16]; 98 int kw_type; 99 }; 100 101 #define RCS_NKWORDS (sizeof(rcs_expkw)/sizeof(rcs_expkw[0])) 102 103 #define RCSNUM_MAXNUM USHRT_MAX 104 #define RCSNUM_MAXLEN 64 105 106 #define RCSNUM_ISBRANCH(n) ((n)->rn_len % 2) 107 #define RCSNUM_ISBRANCHREV(n) (!((n)->rn_len % 2) && ((n)->rn_len >= 4)) 108 109 /* file flags */ 110 #define RCS_READ (1<<0) 111 #define RCS_WRITE (1<<1) 112 #define RCS_RDWR (RCS_READ|RCS_WRITE) 113 #define RCS_CREATE (1<<2) /* create the file */ 114 #define RCS_PARSE_FULLY (1<<3) /* fully parse it on open */ 115 116 /* internal flags */ 117 #define RCS_PARSED (1<<4) /* file has been parsed */ 118 #define RCS_SYNCED (1<<5) /* in-mem copy is sync with disk copy */ 119 #define RCS_SLOCK (1<<6) /* strict lock */ 120 121 /* parser flags */ 122 #define PARSED_DELTAS (1<<7) /* all deltas are parsed */ 123 #define PARSED_DESC (1<<8) /* the description is parsed */ 124 #define PARSED_DELTATEXTS (1<<9) /* all delta texts are parsed */ 125 126 /* delta flags */ 127 #define RCS_RD_DEAD 0x01 /* dead */ 128 #define RCS_RD_SELECT 0x02 /* select for operation */ 129 130 /* used for rcs_checkout_rev */ 131 #define CHECKOUT_REV_CREATED 1 132 #define CHECKOUT_REV_MERGED 2 133 #define CHECKOUT_REV_REMOVED 3 134 #define CHECKOUT_REV_UPDATED 4 135 136 typedef struct rcs_num { 137 u_int rn_len; 138 u_int16_t *rn_id; 139 } RCSNUM; 140 141 142 struct rcs_access { 143 char *ra_name; 144 uid_t ra_uid; 145 TAILQ_ENTRY(rcs_access) ra_list; 146 }; 147 148 struct rcs_sym { 149 char *rs_name; 150 RCSNUM *rs_num; 151 TAILQ_ENTRY(rcs_sym) rs_list; 152 }; 153 154 struct rcs_lock { 155 char *rl_name; 156 RCSNUM *rl_num; 157 158 TAILQ_ENTRY(rcs_lock) rl_list; 159 }; 160 161 162 struct rcs_branch { 163 RCSNUM *rb_num; 164 TAILQ_ENTRY(rcs_branch) rb_list; 165 }; 166 167 TAILQ_HEAD(rcs_dlist, rcs_delta); 168 169 struct rcs_delta { 170 RCSNUM *rd_num; 171 RCSNUM *rd_next; 172 int rd_flags; 173 struct tm rd_date; 174 char *rd_author; 175 char *rd_state; 176 char *rd_log; 177 char *rd_locker; 178 u_char *rd_text; 179 size_t rd_tlen; 180 181 TAILQ_HEAD(, rcs_branch) rd_branches; 182 TAILQ_ENTRY(rcs_delta) rd_list; 183 }; 184 185 186 typedef struct rcs_file { 187 int fd; 188 int rf_dead; 189 char *rf_path; 190 mode_t rf_mode; 191 int rf_flags; 192 193 RCSNUM *rf_head; 194 RCSNUM *rf_branch; 195 char *rf_comment; 196 char *rf_expand; 197 char *rf_desc; 198 199 u_int rf_ndelta; 200 struct rcs_dlist rf_delta; 201 TAILQ_HEAD(rcs_alist, rcs_access) rf_access; 202 TAILQ_HEAD(rcs_slist, rcs_sym) rf_symbols; 203 TAILQ_HEAD(rcs_llist, rcs_lock) rf_locks; 204 205 void *rf_pdata; 206 } RCSFILE; 207 208 struct cvs_line; 209 struct cvs_lines; 210 211 RCSFILE *rcs_open(const char *, int, int, ...); 212 void rcs_close(RCSFILE *); 213 RCSNUM *rcs_head_get(RCSFILE *); 214 int rcs_head_set(RCSFILE *, RCSNUM *); 215 RCSNUM *rcs_branch_new(RCSFILE *, RCSNUM *); 216 const RCSNUM *rcs_branch_get(RCSFILE *); 217 int rcs_branch_set(RCSFILE *, const RCSNUM *); 218 int rcs_access_add(RCSFILE *, const char *); 219 int rcs_access_remove(RCSFILE *, const char *); 220 int rcs_access_check(RCSFILE *, const char *); 221 struct rcs_delta *rcs_findrev(RCSFILE *, RCSNUM *); 222 int rcs_sym_add(RCSFILE *, const char *, RCSNUM *); 223 int rcs_sym_check(const char *); 224 struct rcs_sym *rcs_sym_get(RCSFILE *, const char *); 225 int rcs_sym_remove(RCSFILE *, const char *); 226 RCSNUM *rcs_sym_getrev(RCSFILE *, const char *); 227 RCSNUM *rcs_translate_tag(const char *, RCSFILE *); 228 int rcs_lock_getmode(RCSFILE *); 229 int rcs_lock_setmode(RCSFILE *, int); 230 int rcs_lock_add(RCSFILE *, const char *, RCSNUM *); 231 int rcs_lock_remove(RCSFILE *, const char *, RCSNUM *); 232 int rcs_deltatext_set(RCSFILE *, RCSNUM *, BUF *); 233 const char *rcs_desc_get(RCSFILE *); 234 void rcs_desc_set(RCSFILE *, const char *); 235 const char *rcs_comment_lookup(const char *); 236 const char *rcs_comment_get(RCSFILE *); 237 void rcs_comment_set(RCSFILE *, const char *); 238 BUF *rcs_kwexp_buf(BUF *, RCSFILE *, RCSNUM *); 239 void rcs_kwexp_set(RCSFILE *, int); 240 int rcs_kwexp_get(RCSFILE *); 241 int rcs_rev_add(RCSFILE *, RCSNUM *, const char *, time_t, 242 const char *); 243 time_t rcs_rev_getdate(RCSFILE *, RCSNUM *); 244 int rcs_rev_setlog(RCSFILE *, RCSNUM *, const char *); 245 int rcs_rev_remove(RCSFILE *, RCSNUM *); 246 int rcs_state_set(RCSFILE *, RCSNUM *, const char *); 247 const char *rcs_state_get(RCSFILE *, RCSNUM *); 248 int rcs_state_check(const char *); 249 RCSNUM *rcs_tag_resolve(RCSFILE *, const char *); 250 void rcs_write(RCSFILE *); 251 int rcs_rev_write_stmp(RCSFILE *, RCSNUM *, char *, int); 252 void rcs_rev_write_fd(RCSFILE *, RCSNUM *, int, int); 253 struct cvs_lines *rcs_rev_getlines(RCSFILE *, RCSNUM *, 254 struct cvs_line ***); 255 void rcs_annotate_getlines(RCSFILE *, RCSNUM *, 256 struct cvs_line ***); 257 BUF *rcs_rev_getbuf(RCSFILE *, RCSNUM *, int); 258 void rcs_delta_stats(struct rcs_delta *, int *, int *); 259 260 int rcs_kflag_get(const char *); 261 void rcs_kflag_usage(void); 262 int rcs_kw_expand(RCSFILE *, u_char *, size_t, size_t *); 263 264 RCSNUM *rcsnum_alloc(void); 265 RCSNUM *rcsnum_parse(const char *); 266 RCSNUM *rcsnum_brtorev(const RCSNUM *); 267 RCSNUM *rcsnum_revtobr(const RCSNUM *); 268 RCSNUM *rcsnum_inc(RCSNUM *); 269 RCSNUM *rcsnum_dec(RCSNUM *); 270 RCSNUM *rcsnum_branch_root(RCSNUM *); 271 RCSNUM *rcsnum_new_branch(RCSNUM *); 272 void rcsnum_free(RCSNUM *); 273 int rcsnum_addmagic(RCSNUM *); 274 int rcsnum_aton(const char *, char **, RCSNUM *); 275 char *rcsnum_tostr(const RCSNUM *, char *, size_t); 276 void rcsnum_cpy(const RCSNUM *, RCSNUM *, u_int); 277 int rcsnum_cmp(RCSNUM *, RCSNUM *, u_int); 278 int rcsnum_differ(RCSNUM *, RCSNUM *); 279 280 #endif /* RCS_H */ 281