[BACK]Return to rcs.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / rcs

Annotation of src/usr.bin/rcs/rcs.h, Revision 1.4

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