version 1.56, 2005/07/07 14:27:57 |
version 1.57, 2005/07/25 12:05:43 |
|
|
#include "rcs.h" |
#include "rcs.h" |
#include "strtab.h" |
#include "strtab.h" |
|
|
#define RCS_BUFSIZE 16384 |
#define RCS_BUFSIZE 16384 |
#define RCS_BUFEXTSIZE 8192 |
#define RCS_BUFEXTSIZE 8192 |
|
|
|
|
/* RCS token types */ |
/* RCS token types */ |
#define RCS_TOK_ERR -1 |
#define RCS_TOK_ERR -1 |
#define RCS_TOK_EOF 0 |
#define RCS_TOK_EOF 0 |
#define RCS_TOK_NUM 1 |
#define RCS_TOK_NUM 1 |
#define RCS_TOK_ID 2 |
#define RCS_TOK_ID 2 |
#define RCS_TOK_STRING 3 |
#define RCS_TOK_STRING 3 |
#define RCS_TOK_SCOLON 4 |
#define RCS_TOK_SCOLON 4 |
#define RCS_TOK_COLON 5 |
#define RCS_TOK_COLON 5 |
|
|
|
|
#define RCS_TOK_HEAD 8 |
#define RCS_TOK_HEAD 8 |
#define RCS_TOK_BRANCH 9 |
#define RCS_TOK_BRANCH 9 |
#define RCS_TOK_ACCESS 10 |
#define RCS_TOK_ACCESS 10 |
#define RCS_TOK_SYMBOLS 11 |
#define RCS_TOK_SYMBOLS 11 |
#define RCS_TOK_LOCKS 12 |
#define RCS_TOK_LOCKS 12 |
#define RCS_TOK_COMMENT 13 |
#define RCS_TOK_COMMENT 13 |
#define RCS_TOK_EXPAND 14 |
#define RCS_TOK_EXPAND 14 |
#define RCS_TOK_DATE 15 |
#define RCS_TOK_DATE 15 |
#define RCS_TOK_AUTHOR 16 |
#define RCS_TOK_AUTHOR 16 |
#define RCS_TOK_STATE 17 |
#define RCS_TOK_STATE 17 |
#define RCS_TOK_NEXT 18 |
#define RCS_TOK_NEXT 18 |
#define RCS_TOK_BRANCHES 19 |
#define RCS_TOK_BRANCHES 19 |
#define RCS_TOK_DESC 20 |
#define RCS_TOK_DESC 20 |
#define RCS_TOK_LOG 21 |
#define RCS_TOK_LOG 21 |
#define RCS_TOK_TEXT 22 |
#define RCS_TOK_TEXT 22 |
#define RCS_TOK_STRICT 23 |
#define RCS_TOK_STRICT 23 |
|
|
#define RCS_ISKEY(t) (((t) >= RCS_TOK_HEAD) && ((t) <= RCS_TOK_BRANCHES)) |
#define RCS_ISKEY(t) (((t) >= RCS_TOK_HEAD) && ((t) <= RCS_TOK_BRANCHES)) |
|
|
|
|
#define RCS_NOSCOL 0x01 /* no terminating semi-colon */ |
#define RCS_NOSCOL 0x01 /* no terminating semi-colon */ |
#define RCS_VOPT 0x02 /* value is optional */ |
#define RCS_VOPT 0x02 /* value is optional */ |
|
|
|
|
/* opaque parse data */ |
/* opaque parse data */ |
struct rcs_pdata { |
struct rcs_pdata { |
u_int rp_lines; |
u_int rp_lines; |
|
|
char *rp_buf; |
char *rp_buf; |
size_t rp_blen; |
size_t rp_blen; |
char *rp_bufend; |
char *rp_bufend; |
size_t rp_tlen; |
size_t rp_tlen; |
|
|
/* pushback token buffer */ |
/* pushback token buffer */ |
char rp_ptok[128]; |
char rp_ptok[128]; |
int rp_pttype; /* token type, RCS_TOK_ERR if no token */ |
int rp_pttype; /* token type, RCS_TOK_ERR if no token */ |
|
|
FILE *rp_file; |
FILE *rp_file; |
}; |
}; |
|
|
|
|
struct rcs_line { |
struct rcs_line { |
char *rl_line; |
char *rl_line; |
int rl_lineno; |
int rl_lineno; |
TAILQ_ENTRY(rcs_line) rl_list; |
TAILQ_ENTRY(rcs_line) rl_list; |
}; |
}; |
TAILQ_HEAD(rcs_tqh, rcs_line); |
TAILQ_HEAD(rcs_tqh, rcs_line); |
|
|
struct rcs_foo { |
struct rcs_foo { |
int rl_nblines; |
int rl_nblines; |
char *rl_data; |
char *rl_data; |
struct rcs_tqh rl_lines; |
struct rcs_tqh rl_lines; |
}; |
}; |
|
|
#define RCS_TOKSTR(rfp) ((struct rcs_pdata *)rfp->rf_pdata)->rp_buf |
#define RCS_TOKSTR(rfp) ((struct rcs_pdata *)rfp->rf_pdata)->rp_buf |
#define RCS_TOKLEN(rfp) ((struct rcs_pdata *)rfp->rf_pdata)->rp_tlen |
#define RCS_TOKLEN(rfp) ((struct rcs_pdata *)rfp->rf_pdata)->rp_tlen |
|
|
|
|
|
|
|
|
|
|
/* comment leaders, depending on the file's suffix */ |
/* comment leaders, depending on the file's suffix */ |
static const struct rcs_comment { |
static const struct rcs_comment { |
const char *rc_suffix; |
const char *rc_suffix; |
const char *rc_cstr; |
const char *rc_cstr; |
} rcs_comments[] = { |
} rcs_comments[] = { |
{ "1", ".\\\" " }, |
{ "1", ".\\\" " }, |
{ "2", ".\\\" " }, |
{ "2", ".\\\" " }, |
|
|
{ "yr", " * " }, /* yacc-ratfor */ |
{ "yr", " * " }, /* yacc-ratfor */ |
}; |
}; |
|
|
#define NB_COMTYPES (sizeof(rcs_comments)/sizeof(rcs_comments[0])) |
#define NB_COMTYPES (sizeof(rcs_comments)/sizeof(rcs_comments[0])) |
|
|
#ifdef notyet |
#ifdef notyet |
static struct rcs_kfl { |
static struct rcs_kfl { |
char rk_char; |
char rk_char; |
int rk_val; |
int rk_val; |
} rcs_kflags[] = { |
} rcs_kflags[] = { |
{ 'k', RCS_KWEXP_NAME }, |
{ 'k', RCS_KWEXP_NAME }, |
{ 'v', RCS_KWEXP_VAL }, |
{ 'v', RCS_KWEXP_VAL }, |
|
|
#endif |
#endif |
|
|
static struct rcs_key { |
static struct rcs_key { |
char rk_str[16]; |
char rk_str[16]; |
int rk_id; |
int rk_id; |
int rk_val; |
int rk_val; |
int rk_flags; |
int rk_flags; |
} rcs_keys[] = { |
} rcs_keys[] = { |
{ "access", RCS_TOK_ACCESS, RCS_TOK_ID, RCS_VOPT }, |
{ "access", RCS_TOK_ACCESS, RCS_TOK_ID, RCS_VOPT }, |
{ "author", RCS_TOK_AUTHOR, RCS_TOK_ID, 0 }, |
{ "author", RCS_TOK_AUTHOR, RCS_TOK_ID, 0 }, |
|
|
{ "text", RCS_TOK_TEXT, RCS_TOK_STRING, RCS_NOSCOL }, |
{ "text", RCS_TOK_TEXT, RCS_TOK_STRING, RCS_NOSCOL }, |
}; |
}; |
|
|
#define RCS_NKEYS (sizeof(rcs_keys)/sizeof(rcs_keys[0])) |
#define RCS_NKEYS (sizeof(rcs_keys)/sizeof(rcs_keys[0])) |
|
|
#ifdef notyet |
#ifdef notyet |
/* |
/* |
* Keyword expansion table |
* Keyword expansion table |
*/ |
*/ |
static struct rcs_kw { |
static struct rcs_kw { |
char kw_str[16]; |
char kw_str[16]; |
} rcs_expkw[] = { |
} rcs_expkw[] = { |
{ "Author" }, |
{ "Author" }, |
{ "Date" }, |
{ "Date" }, |
|
|
int rcs_errno = RCS_ERR_NOERR; |
int rcs_errno = RCS_ERR_NOERR; |
|
|
|
|
static int rcs_write (RCSFILE *); |
static int rcs_write(RCSFILE *); |
static int rcs_parse (RCSFILE *); |
static int rcs_parse(RCSFILE *); |
static int rcs_parse_admin (RCSFILE *); |
static int rcs_parse_admin(RCSFILE *); |
static int rcs_parse_delta (RCSFILE *); |
static int rcs_parse_delta(RCSFILE *); |
static int rcs_parse_deltatext (RCSFILE *); |
static int rcs_parse_deltatext(RCSFILE *); |
|
|
static int rcs_parse_access (RCSFILE *); |
static int rcs_parse_access(RCSFILE *); |
static int rcs_parse_symbols (RCSFILE *); |
static int rcs_parse_symbols(RCSFILE *); |
static int rcs_parse_locks (RCSFILE *); |
static int rcs_parse_locks(RCSFILE *); |
static int rcs_parse_branches (RCSFILE *, struct rcs_delta *); |
static int rcs_parse_branches(RCSFILE *, struct rcs_delta *); |
static void rcs_freedelta (struct rcs_delta *); |
static void rcs_freedelta(struct rcs_delta *); |
static void rcs_freepdata (struct rcs_pdata *); |
static void rcs_freepdata(struct rcs_pdata *); |
static int rcs_gettok (RCSFILE *); |
static int rcs_gettok(RCSFILE *); |
static int rcs_pushtok (RCSFILE *, const char *, int); |
static int rcs_pushtok(RCSFILE *, const char *, int); |
static int rcs_growbuf (RCSFILE *); |
static int rcs_growbuf(RCSFILE *); |
static int rcs_patch_lines (struct rcs_foo *, struct rcs_foo *); |
static int rcs_patch_lines(struct rcs_foo *, struct rcs_foo *); |
static int rcs_strprint (const u_char *, size_t, FILE *); |
static int rcs_strprint(const u_char *, size_t, FILE *); |
|
|
static struct rcs_delta* rcs_findrev (RCSFILE *, const RCSNUM *); |
static struct rcs_delta *rcs_findrev(RCSFILE *, const RCSNUM *); |
static struct rcs_foo* rcs_splitlines (const char *); |
static struct rcs_foo *rcs_splitlines(const char *); |
static void rcs_freefoo (struct rcs_foo *); |
static void rcs_freefoo(struct rcs_foo *); |
|
|
|
|
/* |
/* |
|
|
* |
* |
* Retrieve the description for the RCS file <file>. |
* Retrieve the description for the RCS file <file>. |
*/ |
*/ |
const char* |
const char * |
rcs_desc_get(RCSFILE *file) |
rcs_desc_get(RCSFILE *file) |
{ |
{ |
return (file->rf_desc); |
return (file->rf_desc); |
|
|
* Lookup the assumed comment leader based on a file's suffix. |
* Lookup the assumed comment leader based on a file's suffix. |
* Returns a pointer to the string on success, or NULL on failure. |
* Returns a pointer to the string on success, or NULL on failure. |
*/ |
*/ |
const char* |
const char * |
rcs_comment_lookup(const char *filename) |
rcs_comment_lookup(const char *filename) |
{ |
{ |
int i; |
int i; |
|
|
* |
* |
* Retrieve the comment leader for the RCS file <file>. |
* Retrieve the comment leader for the RCS file <file>. |
*/ |
*/ |
const char* |
const char * |
rcs_comment_get(RCSFILE *file) |
rcs_comment_get(RCSFILE *file) |
{ |
{ |
return (file->rf_comment); |
return (file->rf_comment); |
|
|
* |
* |
* Get the error string matching the RCS error code <code>. |
* Get the error string matching the RCS error code <code>. |
*/ |
*/ |
const char* |
const char * |
rcs_errstr(int code) |
rcs_errstr(int code) |
{ |
{ |
const char *esp; |
const char *esp; |