diff options
author | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2005-01-12 19:23:28 +0000 |
---|---|---|
committer | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2005-01-12 19:23:28 +0000 |
commit | 95861c9a20ffca3df8fce60dd182d021334b20ba (patch) | |
tree | 247dbba1f3a280337fd59032e0b7cb284b7141f1 | |
parent | 3cf240745873d005c94efe39352d2a38771fab11 (diff) |
add rcs_kflag_get() to validate kflags
-rw-r--r-- | usr.bin/cvs/rcs.c | 52 | ||||
-rw-r--r-- | usr.bin/cvs/rcs.h | 26 |
2 files changed, 71 insertions, 7 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index bf6d13c6294..6512bf28b2d 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.19 2004/12/18 17:20:40 jfb Exp $ */ +/* $OpenBSD: rcs.c,v 1.20 2005/01/12 19:23:27 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -127,6 +127,17 @@ static void rcs_freefoo (struct rcs_foo *); #define RCS_TOKLEN(rfp) ((struct rcs_pdata *)rfp->rf_pdata)->rp_blen +static struct rcs_kfl { + char rk_char; + int rk_val; +} rcs_kflags[] = { + { 'k', RCS_KWEXP_NAME }, + { 'v', RCS_KWEXP_VAL }, + { 'l', RCS_KWEXP_LKR }, + { 'o', RCS_KWEXP_OLD }, + { 'b', RCS_KWEXP_NONE }, +}; + static struct rcs_key { char rk_str[16]; int rk_id; @@ -702,6 +713,45 @@ rcs_findrev(RCSFILE *rfp, RCSNUM *rev) /* + * rcs_kflag_get() + * + * Get the keyword expansion mode from a set of character flags given in + * <flags> and return the appropriate flag mask. In case of an error, the + * returned mask will have the RCS_KWEXP_ERR bit set to 1. + */ +int +rcs_kflag_get(const char *flags) +{ + int fl; + size_t len; + const char *fp; + + fl = 0; + len = strlen(flags); + + for (fp = flags; *fp != '\0'; fp++) { + if (*fp == 'k') + fl |= RCS_KWEXP_NAME; + else if (*fp == 'v') + fl |= RCS_KWEXP_VAL; + else if (*fp == 'l') + fl |= RCS_KWEXP_LKR; + else if (*fp == 'o') { + if (len != 1) + fl |= RCS_KWEXP_ERR; + fl |= RCS_KWEXP_OLD; + } else if (*fp == 'b') { + if (len != 1) + fl |= RCS_KWEXP_ERR; + } else /* unknown letter */ + fl |= RCS_KWEXP_ERR; + } + + return (fl); +} + + +/* * rcs_parse() * * Parse the contents of file <path>, which are in the RCS format. diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h index aa39b0a5eb3..71ce078af8b 100644 --- a/usr.bin/cvs/rcs.h +++ b/usr.bin/cvs/rcs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.h,v 1.5 2005/01/03 22:10:12 jfb Exp $ */ +/* $OpenBSD: rcs.h,v 1.6 2005/01/12 19:23:27 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -42,6 +42,23 @@ #define RCS_HEAD_INIT "1.1" +/* RCS keyword expansion modes (kflags) */ +#define RCS_KWEXP_NONE 0x00 +#define RCS_KWEXP_NAME 0x01 /* include keyword name */ +#define RCS_KWEXP_VAL 0x02 /* include keyword value */ +#define RCS_KWEXP_LKR 0x04 /* include name of locker */ +#define RCS_KWEXP_OLD 0x08 /* generate old keyword string */ +#define RCS_KWEXP_ERR 0x10 /* mode has an error */ + +#define RCS_KWEXP_DEFAULT (RCS_KWEXP_NAME | RCS_KWEXP_VAL) +#define RCS_KWEXP_KVL (RCS_KWEXP_NAME | RCS_KWEXP_VAL | RCS_KWEXP_LKR) + +#define RCS_KWEXP_INVAL(k) (k & RCS_KWEXP_ERR) + + +#define RCSNUM_MAXNUM USHRT_MAX +#define RCSNUM_MAXLEN 64 + /* open modes */ #define RCS_MODE_READ 0x01 @@ -58,11 +75,6 @@ #define RCS_RD_DEAD 0x01 /* dead */ - -#define RCSNUM_MAXNUM USHRT_MAX -#define RCSNUM_MAXLEN 64 - - typedef struct rcs_num { u_int rn_len; u_int16_t *rn_id; @@ -139,6 +151,8 @@ BUF* rcs_getrev (RCSFILE *, RCSNUM *); BUF* rcs_gethead (RCSFILE *); RCSNUM* rcs_getrevbydate (RCSFILE *, struct tm *); +int rcs_kflag_get (const char *); + BUF* rcs_patch (const char *, const char *); size_t rcs_stresc (int, const char *, char *, size_t *); |