1*a7c91847Schristos /* 2*a7c91847Schristos * Copyright (C) 1986-2005 The Free Software Foundation, Inc. 3*a7c91847Schristos * 4*a7c91847Schristos * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>, 5*a7c91847Schristos * and others. 6*a7c91847Schristos * 7*a7c91847Schristos * Portions Copyright (C) 1992, Brian Berliner and Jeff Polk 8*a7c91847Schristos * Portions Copyright (C) 1989-1992, Brian Berliner 9*a7c91847Schristos * 10*a7c91847Schristos * You may distribute under the terms of the GNU General Public License as 11*a7c91847Schristos * specified in the README file that comes with the CVS source distribution. 12*a7c91847Schristos * 13*a7c91847Schristos * RCS source control definitions needed by rcs.c and friends 14*a7c91847Schristos */ 15*a7c91847Schristos 16*a7c91847Schristos /* Strings which indicate a conflict if they occur at the start of a line. */ 17*a7c91847Schristos #define RCS_MERGE_PAT_1 "<<<<<<< " 18*a7c91847Schristos #define RCS_MERGE_PAT_2 "=======\n" 19*a7c91847Schristos #define RCS_MERGE_PAT_3 ">>>>>>> " 20*a7c91847Schristos 21*a7c91847Schristos #define RCSEXT ",v" 22*a7c91847Schristos #define RCSPAT "*,v" 23*a7c91847Schristos #define RCSHEAD "head" 24*a7c91847Schristos #define RCSBRANCH "branch" 25*a7c91847Schristos #define RCSSYMBOLS "symbols" 26*a7c91847Schristos #define RCSDATE "date" 27*a7c91847Schristos #define RCSDESC "desc" 28*a7c91847Schristos #define RCSEXPAND "expand" 29*a7c91847Schristos 30*a7c91847Schristos /* Used by the version of death support which resulted from old 31*a7c91847Schristos versions of CVS (e.g. 1.5 if you define DEATH_SUPPORT and not 32*a7c91847Schristos DEATH_STATE). Only a hacked up RCS (used by those old versions of 33*a7c91847Schristos CVS) will put this into RCS files. Considered obsolete. */ 34*a7c91847Schristos #define RCSDEAD "dead" 35*a7c91847Schristos 36*a7c91847Schristos #define DATEFORM "%02d.%02d.%02d.%02d.%02d.%02d" 37*a7c91847Schristos #define SDATEFORM "%d.%d.%d.%d.%d.%d" 38*a7c91847Schristos 39*a7c91847Schristos /* 40*a7c91847Schristos * Opaque structure definitions used by RCS specific lookup routines 41*a7c91847Schristos */ 42*a7c91847Schristos #define VALID 0x1 /* flags field contains valid data */ 43*a7c91847Schristos #define INATTIC 0x2 /* RCS file is located in the Attic */ 44*a7c91847Schristos #define PARTIAL 0x4 /* RCS file not completly parsed */ 45*a7c91847Schristos 46*a7c91847Schristos /* All the "char *" fields in RCSNode, Deltatext, and RCSVers are 47*a7c91847Schristos '\0'-terminated (except "text" in Deltatext). This means that we 48*a7c91847Schristos can't deal with fields containing '\0', which is a limitation that 49*a7c91847Schristos RCS does not have. Would be nice to fix this some day. */ 50*a7c91847Schristos 51*a7c91847Schristos struct rcsnode 52*a7c91847Schristos { 53*a7c91847Schristos /* Reference count for this structure. Used to deal with the 54*a7c91847Schristos fact that there might be a pointer from the Vers_TS or might 55*a7c91847Schristos not. Callers who increment this field are responsible for 56*a7c91847Schristos calling freercsnode when they are done with their reference. */ 57*a7c91847Schristos int refcount; 58*a7c91847Schristos 59*a7c91847Schristos /* Flags (INATTIC, PARTIAL, &c), see above. */ 60*a7c91847Schristos int flags; 61*a7c91847Schristos 62*a7c91847Schristos /* File name of the RCS file. This is not necessarily the name 63*a7c91847Schristos as specified by the user, but it is a name which can be passed to 64*a7c91847Schristos system calls and a name which is OK to print in error messages 65*a7c91847Schristos (the various names might differ in case). */ 66*a7c91847Schristos char *path; 67*a7c91847Schristos 68*a7c91847Schristos /* Use when printing paths. */ 69*a7c91847Schristos char *print_path; 70*a7c91847Schristos 71*a7c91847Schristos /* Value for head keyword from RCS header, or NULL if empty. HEAD may only 72*a7c91847Schristos * be empty in a valid RCS file when the file has no revisions, a state 73*a7c91847Schristos * that should not be able to occur with CVS. 74*a7c91847Schristos */ 75*a7c91847Schristos char *head; 76*a7c91847Schristos 77*a7c91847Schristos /* Value for branch keyword from RCS header, or NULL if omitted. */ 78*a7c91847Schristos char *branch; 79*a7c91847Schristos 80*a7c91847Schristos /* Raw data on symbolic revisions. The first time that RCS_symbols is 81*a7c91847Schristos called, we parse these into ->symbols, and free ->symbols_data. */ 82*a7c91847Schristos char *symbols_data; 83*a7c91847Schristos 84*a7c91847Schristos /* Value for expand keyword from RCS header, or NULL if omitted. */ 85*a7c91847Schristos char *expand; 86*a7c91847Schristos 87*a7c91847Schristos /* List of nodes, the key of which is the symbolic name and the data 88*a7c91847Schristos of which is the numeric revision that it corresponds to (malloc'd). */ 89*a7c91847Schristos List *symbols; 90*a7c91847Schristos 91*a7c91847Schristos /* List of nodes (type RCSVERS), the key of which the numeric revision 92*a7c91847Schristos number, and the data of which is an RCSVers * for the revision. */ 93*a7c91847Schristos List *versions; 94*a7c91847Schristos 95*a7c91847Schristos /* Value for access keyword from RCS header, or NULL if empty. 96*a7c91847Schristos FIXME: RCS_delaccess would also seem to use "" for empty. We 97*a7c91847Schristos should pick one or the other. */ 98*a7c91847Schristos char *access; 99*a7c91847Schristos 100*a7c91847Schristos /* Raw data on locked revisions. The first time that RCS_getlocks is 101*a7c91847Schristos called, we parse these into ->locks, and free ->locks_data. */ 102*a7c91847Schristos char *locks_data; 103*a7c91847Schristos 104*a7c91847Schristos /* List of nodes, the key of which is the numeric revision and the 105*a7c91847Schristos data of which is the user that it corresponds to (malloc'd). */ 106*a7c91847Schristos List *locks; 107*a7c91847Schristos 108*a7c91847Schristos /* Set for the strict keyword from the RCS header. */ 109*a7c91847Schristos int strict_locks; 110*a7c91847Schristos 111*a7c91847Schristos /* Value for the comment keyword from RCS header (comment leader), or 112*a7c91847Schristos NULL if omitted. */ 113*a7c91847Schristos char *comment; 114*a7c91847Schristos 115*a7c91847Schristos /* Value for the desc field in the RCS file, or NULL if empty. */ 116*a7c91847Schristos char *desc; 117*a7c91847Schristos 118*a7c91847Schristos /* File offset of the first deltatext node, so we can seek there. */ 119*a7c91847Schristos off_t delta_pos; 120*a7c91847Schristos 121*a7c91847Schristos /* Newphrases from the RCS header. List of nodes, the key of which 122*a7c91847Schristos is the "id" which introduces the newphrase, and the value of which 123*a7c91847Schristos is the value from the newphrase. */ 124*a7c91847Schristos List *other; 125*a7c91847Schristos }; 126*a7c91847Schristos 127*a7c91847Schristos typedef struct rcsnode RCSNode; 128*a7c91847Schristos 129*a7c91847Schristos struct deltatext { 130*a7c91847Schristos char *version; 131*a7c91847Schristos 132*a7c91847Schristos /* Log message, or NULL if we do not intend to change the log message 133*a7c91847Schristos (that is, RCS_copydeltas should just use the log message from the 134*a7c91847Schristos file). */ 135*a7c91847Schristos char *log; 136*a7c91847Schristos 137*a7c91847Schristos /* Change text, or NULL if we do not intend to change the change text 138*a7c91847Schristos (that is, RCS_copydeltas should just use the change text from the 139*a7c91847Schristos file). Note that it is perfectly valid to have log be NULL and 140*a7c91847Schristos text non-NULL, or vice-versa. */ 141*a7c91847Schristos char *text; 142*a7c91847Schristos size_t len; 143*a7c91847Schristos 144*a7c91847Schristos /* Newphrase fields from deltatext nodes. FIXME: duplicates the 145*a7c91847Schristos other field in the rcsversnode, I think. */ 146*a7c91847Schristos List *other; 147*a7c91847Schristos }; 148*a7c91847Schristos typedef struct deltatext Deltatext; 149*a7c91847Schristos 150*a7c91847Schristos struct rcsversnode 151*a7c91847Schristos { 152*a7c91847Schristos /* Duplicate of the key by which this structure is indexed. */ 153*a7c91847Schristos char *version; 154*a7c91847Schristos 155*a7c91847Schristos char *date; 156*a7c91847Schristos char *author; 157*a7c91847Schristos char *state; 158*a7c91847Schristos char *next; 159*a7c91847Schristos int dead; 160*a7c91847Schristos int outdated; 161*a7c91847Schristos Deltatext *text; 162*a7c91847Schristos List *branches; 163*a7c91847Schristos /* Newphrase fields from deltatext nodes. Also contains ";add" and 164*a7c91847Schristos ";delete" magic fields (see rcs.c, log.c). I think this is 165*a7c91847Schristos only used by log.c (where it looks up "log"). Duplicates the 166*a7c91847Schristos other field in struct deltatext, I think. */ 167*a7c91847Schristos List *other; 168*a7c91847Schristos /* Newphrase fields from delta nodes. */ 169*a7c91847Schristos List *other_delta; 170*a7c91847Schristos #ifdef PRESERVE_PERMISSIONS_SUPPORT 171*a7c91847Schristos /* Hard link information for each revision. */ 172*a7c91847Schristos List *hardlinks; 173*a7c91847Schristos #endif 174*a7c91847Schristos }; 175*a7c91847Schristos typedef struct rcsversnode RCSVers; 176*a7c91847Schristos 177*a7c91847Schristos /* 178*a7c91847Schristos * CVS reserves all even-numbered branches for its own use. "magic" branches 179*a7c91847Schristos * (see rcs.c) are contained as virtual revision numbers (within symbolic 180*a7c91847Schristos * tags only) off the RCS_MAGIC_BRANCH, which is 0. CVS also reserves the 181*a7c91847Schristos * ".1" branch for vendor revisions. So, if you do your own branching, you 182*a7c91847Schristos * should limit your use to odd branch numbers starting at 3. 183*a7c91847Schristos */ 184*a7c91847Schristos #define RCS_MAGIC_BRANCH 0 185*a7c91847Schristos 186*a7c91847Schristos /* The type of a function passed to RCS_checkout. */ 187*a7c91847Schristos typedef void (*RCSCHECKOUTPROC) (void *, const char *, size_t); 188*a7c91847Schristos 189*a7c91847Schristos struct rcsbuffer; 190*a7c91847Schristos 191*a7c91847Schristos /* What RCS_deltas is supposed to do. */ 192*a7c91847Schristos enum rcs_delta_op {RCS_ANNOTATE, RCS_FETCH}; 193*a7c91847Schristos 194*a7c91847Schristos /* 195*a7c91847Schristos * exported interfaces 196*a7c91847Schristos */ 197*a7c91847Schristos RCSNode *RCS_parse (const char *file, const char *repos); 198*a7c91847Schristos RCSNode *RCS_parsercsfile (const char *rcsfile); 199*a7c91847Schristos void RCS_fully_parse (RCSNode *); 200*a7c91847Schristos void RCS_reparsercsfile (RCSNode *, FILE **, struct rcsbuffer *); 201*a7c91847Schristos extern int RCS_setattic (RCSNode *, int); 202*a7c91847Schristos 203*a7c91847Schristos char *RCS_check_kflag (const char *arg); 204*a7c91847Schristos char *RCS_getdate (RCSNode * rcs, const char *date, int force_tag_match); 205*a7c91847Schristos char *RCS_gettag (RCSNode * rcs, const char *symtag, int force_tag_match, 206*a7c91847Schristos int *simple_tag); 207*a7c91847Schristos int RCS_exist_rev (RCSNode *rcs, char *rev); 208*a7c91847Schristos int RCS_exist_tag (RCSNode *rcs, char *tag); 209*a7c91847Schristos char *RCS_tag2rev (RCSNode *rcs, char *tag); 210*a7c91847Schristos char *RCS_getversion (RCSNode *rcs, const char *tag, const char *date, 211*a7c91847Schristos int force_tag_match, int *simple_tag); 212*a7c91847Schristos char *RCS_magicrev (RCSNode *rcs, char *rev); 213*a7c91847Schristos int RCS_isbranch (RCSNode *rcs, const char *rev); 214*a7c91847Schristos int RCS_nodeisbranch (RCSNode *rcs, const char *tag); 215*a7c91847Schristos char *RCS_whatbranch (RCSNode *rcs, const char *tag); 216*a7c91847Schristos char *RCS_head (RCSNode * rcs); 217*a7c91847Schristos int RCS_datecmp (const char *date1, const char *date2); 218*a7c91847Schristos time_t RCS_getrevtime (RCSNode * rcs, const char *rev, char *date, int fudge); 219*a7c91847Schristos List *RCS_symbols (RCSNode *rcs); 220*a7c91847Schristos void RCS_check_tag (const char *tag); 221*a7c91847Schristos int RCS_valid_rev (const char *rev); 222*a7c91847Schristos List *RCS_getlocks (RCSNode *rcs); 223*a7c91847Schristos void freercsnode (RCSNode ** rnodep); 224*a7c91847Schristos char *RCS_getbranch (RCSNode *rcs, const char *tag, int force_tag_match); 225*a7c91847Schristos char *RCS_branch_head (RCSNode *rcs, char *rev); 226*a7c91847Schristos 227*a7c91847Schristos int RCS_isdead (RCSNode *, const char *); 228*a7c91847Schristos char *RCS_getexpand (RCSNode *); 229*a7c91847Schristos void RCS_setexpand (RCSNode *, const char *); 230*a7c91847Schristos int RCS_checkout (RCSNode *, const char *, const char *, const char *, 231*a7c91847Schristos const char *, const char *, RCSCHECKOUTPROC, void *); 232*a7c91847Schristos int RCS_checkin (RCSNode *rcs, const char *update_dir, const char *workfile, 233*a7c91847Schristos const char *message, const char *rev, time_t citime, 234*a7c91847Schristos int flags); 235*a7c91847Schristos int RCS_cmp_file (RCSNode *, const char *, char **, const char *, const char *, 236*a7c91847Schristos const char * ); 237*a7c91847Schristos int RCS_settag (RCSNode *, const char *, const char *); 238*a7c91847Schristos int RCS_deltag (RCSNode *, const char *); 239*a7c91847Schristos int RCS_setbranch (RCSNode *, const char *); 240*a7c91847Schristos int RCS_lock (RCSNode *, const char *, int); 241*a7c91847Schristos int RCS_unlock (RCSNode *, char *, int); 242*a7c91847Schristos int RCS_delete_revs (RCSNode *, char *, char *, int); 243*a7c91847Schristos void RCS_addaccess (RCSNode *, char *); 244*a7c91847Schristos void RCS_delaccess (RCSNode *, char *); 245*a7c91847Schristos char *RCS_getaccess (RCSNode *); 246*a7c91847Schristos void RCS_rewrite (RCSNode *, Deltatext *, char *); 247*a7c91847Schristos void RCS_abandon (RCSNode *); 248*a7c91847Schristos int rcs_change_text (const char *, char *, size_t, const char *, 249*a7c91847Schristos size_t, char **, size_t *); 250*a7c91847Schristos void RCS_deltas (RCSNode *, FILE *, struct rcsbuffer *, const char *, 251*a7c91847Schristos enum rcs_delta_op, char **, size_t *, 252*a7c91847Schristos char **, size_t *); 253*a7c91847Schristos void RCS_setincexc (void **, const char *arg); 254*a7c91847Schristos void RCS_setlocalid (const char *, unsigned int, void **, const char *arg); 255*a7c91847Schristos char *make_file_label (const char *, const char *, RCSNode *); 256*a7c91847Schristos 257*a7c91847Schristos extern bool preserve_perms; 258*a7c91847Schristos 259*a7c91847Schristos /* From import.c. */ 260*a7c91847Schristos extern int add_rcs_file (const char *, const char *, const char *, 261*a7c91847Schristos const char *, const char *, const char *, 262*a7c91847Schristos const char *, int, char **, const char *, size_t, 263*a7c91847Schristos FILE *, bool); 264*a7c91847Schristos void free_keywords (void *keywords); 265