version 1.4, 2006/04/27 07:59:33 |
version 1.5, 2006/04/29 05:31:28 |
|
|
rcs_write(RCSFILE *rfp) |
rcs_write(RCSFILE *rfp) |
{ |
{ |
FILE *fp; |
FILE *fp; |
char buf[1024], numbuf[64], fn[19] = ""; |
char buf[1024], numbuf[64], fn[20] = ""; |
void *bp; |
void *bp; |
struct rcs_access *ap; |
struct rcs_access *ap; |
struct rcs_sym *symp; |
struct rcs_sym *symp; |
|
|
/* Write operations need the whole file parsed */ |
/* Write operations need the whole file parsed */ |
rcs_parse_deltatexts(rfp, NULL); |
rcs_parse_deltatexts(rfp, NULL); |
|
|
strlcpy(fn, "/tmp/rcs.XXXXXXXXXX", sizeof(fn)); |
if (strlcpy(fn, "/tmp/rcs.XXXXXXXXXX", sizeof(fn)) >= sizeof(fn)) |
|
errx(1, "rcs_write: string truncated"); |
if ((fd = mkstemp(fn)) == -1) |
if ((fd = mkstemp(fn)) == -1) |
err(1, "%s", fn); |
err(1, "%s", fn); |
|
|
if ((fp = fdopen(fd, "w+")) == NULL) { |
if ((fp = fdopen(fd, "w+")) == NULL) { |
|
int saved_errno; |
|
|
|
saved_errno = errno; |
(void)unlink(fn); |
(void)unlink(fn); |
|
errno = saved_errno; |
err(1, "%s", fn); |
err(1, "%s", fn); |
} |
} |
|
|
|
|
fprintf(fp, "symbols"); |
fprintf(fp, "symbols"); |
TAILQ_FOREACH(symp, &(rfp->rf_symbols), rs_list) { |
TAILQ_FOREACH(symp, &(rfp->rf_symbols), rs_list) { |
rcsnum_tostr(symp->rs_num, numbuf, sizeof(numbuf)); |
rcsnum_tostr(symp->rs_num, numbuf, sizeof(numbuf)); |
strlcpy(buf, symp->rs_name, sizeof(buf)); |
if (strlcpy(buf, symp->rs_name, sizeof(buf)) >= sizeof(buf) || |
strlcat(buf, ":", sizeof(buf)); |
strlcat(buf, ":", sizeof(buf)) >= sizeof(buf) || |
strlcat(buf, numbuf, sizeof(buf)); |
strlcat(buf, numbuf, sizeof(buf)) >= sizeof(buf)) |
|
errx(1, "rcs_write: string overflow"); |
fprintf(fp, "\n\t%s", buf); |
fprintf(fp, "\n\t%s", buf); |
} |
} |
fprintf(fp, ";\n"); |
fprintf(fp, ";\n"); |
|
|
} |
} |
|
|
rdp->rd_text = xmalloc(RCS_TOKLEN(rfp) + 1); |
rdp->rd_text = xmalloc(RCS_TOKLEN(rfp) + 1); |
strlcpy(rdp->rd_text, RCS_TOKSTR(rfp), (RCS_TOKLEN(rfp) + 1)); |
if (strlcpy(rdp->rd_text, RCS_TOKSTR(rfp), (RCS_TOKLEN(rfp) + 1)) >= |
|
RCS_TOKLEN(rfp) + 1) |
|
errx(1, "rcs_parse_deltatext: strlcpy"); |
rdp->rd_tlen = RCS_TOKLEN(rfp); |
rdp->rd_tlen = RCS_TOKLEN(rfp); |
|
|
return (1); |
return (1); |
|
|
|
|
if (pdp->rp_pttype != RCS_TOK_ERR) { |
if (pdp->rp_pttype != RCS_TOK_ERR) { |
type = pdp->rp_pttype; |
type = pdp->rp_pttype; |
strlcpy(pdp->rp_buf, pdp->rp_ptok, pdp->rp_blen); |
if (strlcpy(pdp->rp_buf, pdp->rp_ptok, pdp->rp_blen) >= |
|
pdp->rp_blen) |
|
errx(1, "rcs_gettok: strlcpy"); |
pdp->rp_pttype = RCS_TOK_ERR; |
pdp->rp_pttype = RCS_TOK_ERR; |
return (type); |
return (type); |
} |
} |
|
|
return (-1); |
return (-1); |
|
|
pdp->rp_pttype = type; |
pdp->rp_pttype = type; |
strlcpy(pdp->rp_ptok, tok, sizeof(pdp->rp_ptok)); |
if (strlcpy(pdp->rp_ptok, tok, sizeof(pdp->rp_ptok)) >= |
|
sizeof(pdp->rp_ptok)) |
|
errx(1, "rcs_pushtok: strlcpy"); |
return (0); |
return (0); |
} |
} |
|
|
|
|
expbuf[0] = '\0'; |
expbuf[0] = '\0'; |
|
|
if (mode & RCS_KWEXP_NAME) { |
if (mode & RCS_KWEXP_NAME) { |
strlcat(expbuf, "$", sizeof(expbuf)); |
if (strlcat(expbuf, "$", sizeof(expbuf)) >= sizeof(expbuf) || |
strlcat(expbuf, kwstr, sizeof(expbuf)); |
strlcat(expbuf, kwstr, sizeof(expbuf)) >= sizeof(expbuf)) |
if (mode & RCS_KWEXP_VAL) |
errx(1, "rcs_expand_keywords: string truncated"); |
strlcat(expbuf, ": ", sizeof(expbuf)); |
if ((mode & RCS_KWEXP_VAL) && |
|
strlcat(expbuf, ": ", sizeof(expbuf)) >= sizeof(expbuf)) |
|
errx(1, "rcs_expand_keywords: string truncated"); |
} |
} |
|
|
/* |
/* |
|
|
if (mode & RCS_KWEXP_VAL) { |
if (mode & RCS_KWEXP_VAL) { |
if (kwtype & RCS_KW_RCSFILE) { |
if (kwtype & RCS_KW_RCSFILE) { |
if (!(kwtype & RCS_KW_FULLPATH)) |
if (!(kwtype & RCS_KW_FULLPATH)) |
strlcat(expbuf, |
(void)strlcat(expbuf, basename(rcsfile), sizeof(expbuf)); |
basename(rcsfile), |
|
sizeof(expbuf)); |
|
else |
else |
strlcat(expbuf, rcsfile, |
(void)strlcat(expbuf, rcsfile, sizeof(expbuf)); |
sizeof(expbuf)); |
if (strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) |
strlcat(expbuf, " ", sizeof(expbuf)); |
errx(1, "rcs_expand_keywords: string truncated"); |
} |
} |
|
|
if (kwtype & RCS_KW_REVISION) { |
if (kwtype & RCS_KW_REVISION) { |
rcsnum_tostr(rdp->rd_num, buf, |
rcsnum_tostr(rdp->rd_num, buf, sizeof(buf)); |
sizeof(buf)); |
if (strlcat(buf, " ", sizeof(buf)) >= sizeof(buf) || |
strlcat(buf, " ", sizeof(buf)); |
strlcat(expbuf, buf, sizeof(expbuf)) >= sizeof(buf)) |
strlcat(expbuf, buf, sizeof(expbuf)); |
errx(1, "rcs_expand_keywords: string truncated"); |
} |
} |
|
|
if (kwtype & RCS_KW_DATE) { |
if (kwtype & RCS_KW_DATE) { |
|
|
fmt = "%Y/%m/%d %H:%M:%S "; |
fmt = "%Y/%m/%d %H:%M:%S "; |
|
|
strftime(buf, sizeof(buf), fmt, &tb); |
strftime(buf, sizeof(buf), fmt, &tb); |
strlcat(expbuf, buf, sizeof(expbuf)); |
if (strlcat(expbuf, buf, sizeof(expbuf)) >= sizeof(expbuf)) |
|
errx(1, "rcs_expand_keywords: string truncated"); |
} |
} |
|
|
if (kwtype & RCS_KW_AUTHOR) { |
if (kwtype & RCS_KW_AUTHOR) { |
strlcat(expbuf, rdp->rd_author, |
if (strlcat(expbuf, rdp->rd_author, sizeof(expbuf)) >= sizeof(expbuf) || |
sizeof(expbuf)); |
strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) |
strlcat(expbuf, " ", sizeof(expbuf)); |
errx(1, "rcs_expand_keywords: string truncated"); |
} |
} |
|
|
if (kwtype & RCS_KW_STATE) { |
if (kwtype & RCS_KW_STATE) { |
strlcat(expbuf, rdp->rd_state, |
if (strlcat(expbuf, rdp->rd_state, sizeof(expbuf)) >= sizeof(expbuf) || |
sizeof(expbuf)); |
strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) |
strlcat(expbuf, " ", sizeof(expbuf)); |
errx(1, "rcs_expand_keywords: string truncated"); |
} |
} |
|
|
/* order does not matter anymore below */ |
/* order does not matter anymore below */ |
if (kwtype & RCS_KW_LOG) |
if (kwtype & RCS_KW_LOG) |
strlcat(expbuf, " ", sizeof(expbuf)); |
if (strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) |
|
errx(1, "rcs_expand_keywords: string truncated"); |
|
|
if (kwtype & RCS_KW_SOURCE) { |
if (kwtype & RCS_KW_SOURCE) { |
strlcat(expbuf, rcsfile, |
if (strlcat(expbuf, rcsfile, sizeof(expbuf)) >= sizeof(expbuf) || |
sizeof(expbuf)); |
strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) |
strlcat(expbuf, " ", sizeof(expbuf)); |
errx(1, "rcs_expand_keywords: string truncated"); |
} |
} |
|
|
if (kwtype & RCS_KW_NAME) |
if (kwtype & RCS_KW_NAME) |
strlcat(expbuf, " ", sizeof(expbuf)); |
if (strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) |
|
errx(1, "rcs_expand_keywords: string truncated"); |
} |
} |
|
|
/* end the expansion */ |
/* end the expansion */ |
if (mode & RCS_KWEXP_NAME) |
if (mode & RCS_KWEXP_NAME) |
strlcat(expbuf, "$", sizeof(expbuf)); |
if (strlcat(expbuf, "$", sizeof(expbuf)) >= sizeof(expbuf)) |
|
errx(1, "rcs_expand_keywords: string truncated"); |
|
|
sizdiff = strlen(expbuf) - (end - start); |
sizdiff = strlen(expbuf) - (end - start); |
tbuf = xstrdup(end); |
tbuf = xstrdup(end); |
|
|
start = data + start_offset; |
start = data + start_offset; |
c = data + c_offset; |
c = data + c_offset; |
} |
} |
strlcpy(start, expbuf, len); |
if (strlcpy(start, expbuf, len) >= len || |
strlcat(data, tbuf, len); |
strlcat(data, tbuf, len) >= len) |
|
errx(1, "rcs_expand_keywords: string truncated"); |
xfree(tbuf); |
xfree(tbuf); |
i += strlen(expbuf); |
i += strlen(expbuf); |
} |
} |
|
|
|
|
if (!(expmode & RCS_KWEXP_NONE)) { |
if (!(expmode & RCS_KWEXP_NONE)) { |
if ((rdp = rcs_findrev(rf, rev)) == NULL) |
if ((rdp = rcs_findrev(rf, rev)) == NULL) |
errx(1, "could not fetch revision"); |
errx(1, "could not fetch revision"); |
rcs_buf_putc(bp, '\0'); |
rcs_buf_putc(bp, '\0'); |
len = rcs_buf_len(bp); |
len = rcs_buf_len(bp); |
tbuf = rcs_buf_release(bp); |
tbuf = rcs_buf_release(bp); |