[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.16

1.16    ! jcs         1: /*     $OpenBSD: rcs.h,v 1.15 2011/07/06 15:36:52 nicm 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
1.6       xsa        29:
                     30: #include <sys/queue.h>
1.1       joris      31:
1.13      tobias     32: #include <stdio.h>
                     33:
1.1       joris      34: #include "buf.h"
                     35:
                     36: #define RCS_DIFF_MAXARG                32
                     37: #define RCS_DIFF_DIV \
                     38:        "==================================================================="
                     39:
                     40: #define RCSDIR                 "RCS"
                     41: #define RCS_FILE_EXT           ",v"
                     42:
                     43: #define RCS_HEAD_BRANCH                "HEAD"
                     44: #define RCS_HEAD_INIT          "1.1"
                     45: #define RCS_HEAD_REV           ((RCSNUM *)(-1))
                     46:
                     47:
1.11      tobias     48: #define RCS_STATE_INVALCHAR    "$,:;@"
1.1       joris      49: #define RCS_SYM_INVALCHAR      "$,.:;@"
                     50:
                     51: #define RCS_MAGIC_BRANCH       ".0."
                     52: #define RCS_STATE_EXP          "Exp"
                     53: #define RCS_STATE_DEAD         "dead"
                     54:
                     55: /* lock types */
                     56: #define RCS_LOCK_INVAL         (-1)
                     57: #define RCS_LOCK_LOOSE         0
                     58: #define RCS_LOCK_STRICT                1
                     59:
                     60: /*
                     61:  * Keyword expansion table
                     62:  */
                     63: #define RCS_KW_AUTHOR          0x1000
                     64: #define RCS_KW_DATE            0x2000
                     65: #define RCS_KW_LOG             0x4000
                     66: #define RCS_KW_NAME            0x8000
                     67: #define RCS_KW_RCSFILE         0x0100
                     68: #define RCS_KW_REVISION                0x0200
                     69: #define RCS_KW_SOURCE          0x0400
                     70: #define RCS_KW_STATE           0x0800
                     71: #define RCS_KW_FULLPATH                0x0010
1.15      nicm       72: #define RCS_KW_LOCKER          0x10000
1.1       joris      73:
                     74: #define RCS_KW_ID \
                     75:        (RCS_KW_RCSFILE | RCS_KW_REVISION | RCS_KW_DATE \
1.15      nicm       76:        | RCS_KW_AUTHOR | RCS_KW_STATE | RCS_KW_LOCKER)
1.1       joris      77:
                     78: #define RCS_KW_HEADER  (RCS_KW_ID | RCS_KW_FULLPATH)
                     79:
                     80: /* RCS keyword expansion modes (kflags) */
                     81: #define RCS_KWEXP_NONE 0x00
                     82: #define RCS_KWEXP_NAME 0x01    /* include keyword name */
                     83: #define RCS_KWEXP_VAL  0x02    /* include keyword value */
                     84: #define RCS_KWEXP_LKR  0x04    /* include name of locker */
                     85: #define RCS_KWEXP_OLD  0x08    /* generate old keyword string */
                     86: #define RCS_KWEXP_ERR  0x10    /* 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: struct rcs_kw {
                     96:        char    kw_str[16];
                     97:        int     kw_type;
                     98: };
                     99:
                    100: #define RCS_NKWORDS    (sizeof(rcs_expkw)/sizeof(rcs_expkw[0]))
                    101:
                    102: #define RCSNUM_MAXNUM  USHRT_MAX
                    103: #define RCSNUM_MAXLEN  64
                    104:
                    105: #define RCSNUM_ISBRANCH(n)     ((n)->rn_len % 2)
                    106: #define RCSNUM_ISBRANCHREV(n)  (!((n)->rn_len % 2) && ((n)->rn_len >= 4))
                    107: #define RCSNUM_NO_MAGIC                (1<<0)
                    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: /* RCS error codes */
                    131: #define RCS_ERR_NOERR  0
                    132: #define RCS_ERR_NOENT  1
                    133: #define RCS_ERR_DUPENT 2
                    134: #define RCS_ERR_BADNUM 3
                    135: #define RCS_ERR_BADSYM 4
                    136: #define RCS_ERR_PARSE  5
                    137: #define RCS_ERR_ERRNO  255
                    138:
                    139: /* used for rcs_checkout_rev */
                    140: #define CHECKOUT_REV_CREATED   1
                    141: #define CHECKOUT_REV_MERGED    2
                    142: #define CHECKOUT_REV_REMOVED   3
                    143: #define CHECKOUT_REV_UPDATED   4
                    144:
1.16    ! jcs       145: /* commitids in cvs/cvsnt can be up to 64 bytes */
        !           146: #define RCS_COMMITID_MAXLEN 64
        !           147:
1.1       joris     148: typedef struct rcs_num {
                    149:        u_int            rn_len;
                    150:        u_int16_t       *rn_id;
                    151: } RCSNUM;
                    152:
                    153: struct rcs_access {
                    154:        char                    *ra_name;
                    155:        TAILQ_ENTRY(rcs_access)  ra_list;
                    156: };
                    157:
                    158: struct rcs_sym {
                    159:        char                    *rs_name;
                    160:        RCSNUM                  *rs_num;
                    161:        TAILQ_ENTRY(rcs_sym)     rs_list;
                    162: };
                    163:
                    164: struct rcs_lock {
                    165:        char    *rl_name;
                    166:        RCSNUM  *rl_num;
                    167:
1.4       ray       168:        TAILQ_ENTRY(rcs_lock)    rl_list;
1.1       joris     169: };
                    170:
                    171: struct rcs_branch {
                    172:        RCSNUM                  *rb_num;
1.4       ray       173:        TAILQ_ENTRY(rcs_branch)  rb_list;
1.1       joris     174: };
                    175:
                    176: TAILQ_HEAD(rcs_dlist, rcs_delta);
                    177:
                    178: struct rcs_delta {
                    179:        RCSNUM          *rd_num;
                    180:        RCSNUM          *rd_next;
                    181:        u_int            rd_flags;
                    182:        struct tm        rd_date;
                    183:        char            *rd_author;
                    184:        char            *rd_state;
1.16    ! jcs       185:        char            *rd_commitid;
1.1       joris     186:        char            *rd_log;
                    187:        char            *rd_locker;
                    188:        u_char          *rd_text;
                    189:        size_t           rd_tlen;
                    190:
                    191:        TAILQ_HEAD(, rcs_branch)        rd_branches;
                    192:        TAILQ_ENTRY(rcs_delta)          rd_list;
                    193: };
                    194:
                    195:
                    196: typedef struct rcs_file {
1.13      tobias    197:        FILE    *rf_file;
1.1       joris     198:        char    *rf_path;
                    199:        mode_t   rf_mode;
                    200:        u_int    rf_flags;
                    201:
                    202:        RCSNUM  *rf_head;
                    203:        RCSNUM  *rf_branch;
                    204:        char    *rf_comment;
                    205:        char    *rf_expand;
                    206:        char    *rf_desc;
                    207:
                    208:        u_int                                   rf_ndelta;
                    209:        struct rcs_dlist                        rf_delta;
                    210:        TAILQ_HEAD(rcs_alist, rcs_access)       rf_access;
                    211:        TAILQ_HEAD(rcs_slist, rcs_sym)          rf_symbols;
                    212:        TAILQ_HEAD(rcs_llist, rcs_lock)         rf_locks;
                    213:
                    214:        void    *rf_pdata;
                    215: } RCSFILE;
                    216:
                    217: extern int rcs_errno;
                    218:
1.2       joris     219: RCSFILE                        *rcs_open(const char *, int, int, ...);
1.1       joris     220: void                    rcs_close(RCSFILE *);
                    221: int                     rcs_head_set(RCSFILE *, RCSNUM *);
                    222: const RCSNUM           *rcs_branch_get(RCSFILE *);
                    223: int                     rcs_access_add(RCSFILE *, const char *);
                    224: int                     rcs_access_remove(RCSFILE *, const char *);
                    225: int                     rcs_access_check(RCSFILE *, const char *);
                    226: struct rcs_delta       *rcs_findrev(RCSFILE *, RCSNUM *);
                    227: int                     rcs_sym_add(RCSFILE *, const char *, RCSNUM *);
                    228: int                     rcs_sym_remove(RCSFILE *, const char *);
                    229: RCSNUM                 *rcs_sym_getrev(RCSFILE *, const char *);
                    230: int                     rcs_sym_check(const char *);
                    231: int                     rcs_lock_getmode(RCSFILE *);
                    232: int                     rcs_lock_setmode(RCSFILE *, int);
                    233: int                     rcs_lock_add(RCSFILE *, const char *, RCSNUM *);
                    234: int                     rcs_lock_remove(RCSFILE *, const char *, RCSNUM *);
                    235: BUF                    *rcs_getrev(RCSFILE *, RCSNUM *);
1.5       niallo    236: int                     rcs_deltatext_set(RCSFILE *, RCSNUM *, BUF *);
1.1       joris     237: void                    rcs_desc_set(RCSFILE *, const char *);
                    238: void                    rcs_comment_set(RCSFILE *, const char *);
                    239: BUF                    *rcs_kwexp_buf(BUF *, RCSFILE *, RCSNUM *);
                    240: void                    rcs_kwexp_set(RCSFILE *, int);
                    241: int                     rcs_kwexp_get(RCSFILE *);
                    242: int                     rcs_rev_add(RCSFILE *, RCSNUM *, const char *, time_t,
                    243:                             const char *);
                    244: time_t                  rcs_rev_getdate(RCSFILE *, RCSNUM *);
                    245: int                     rcs_rev_setlog(RCSFILE *, RCSNUM *, const char *);
                    246: int                     rcs_rev_remove(RCSFILE *, RCSNUM *);
                    247: int                     rcs_state_set(RCSFILE *, RCSNUM *, const char *);
                    248: int                     rcs_state_check(const char *);
1.3       xsa       249: void                    rcs_write(RCSFILE *);
1.8       xsa       250: void                    rcs_delta_stats(struct rcs_delta *, int *, int *);
1.1       joris     251:
                    252: int    rcs_kflag_get(const char *);
                    253: void   rcs_kflag_usage(void);
                    254: int    rcs_kw_expand(RCSFILE *, u_char *, size_t, size_t *);
                    255:
                    256: RCSNUM *rcsnum_alloc(void);
                    257: RCSNUM *rcsnum_parse(const char *);
                    258: RCSNUM *rcsnum_brtorev(const RCSNUM *);
                    259: RCSNUM *rcsnum_revtobr(const RCSNUM *);
                    260: RCSNUM *rcsnum_inc(RCSNUM *);
                    261: void    rcsnum_free(RCSNUM *);
1.7       tobias    262: int     rcsnum_addmagic(RCSNUM *);
1.1       joris     263: int     rcsnum_aton(const char *, char **, RCSNUM *);
                    264: char   *rcsnum_tostr(const RCSNUM *, char *, size_t);
                    265: void    rcsnum_cpy(const RCSNUM *, RCSNUM *, u_int);
                    266: int     rcsnum_cmp(const RCSNUM *, const RCSNUM *, u_int);
                    267:
                    268: /* rcstime.c */
                    269: void    rcs_set_tz(char *, struct rcs_delta *, struct tm *);
                    270: extern char *timezone_flag;
                    271: extern int rcsnum_flags;
                    272:
                    273: #endif /* RCS_H */