summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2005-06-05 20:47:45 +0000
committerJoris Vink <joris@cvs.openbsd.org>2005-06-05 20:47:45 +0000
commitf1f10cf08e3dd40224298f07caf3af91ae721f16 (patch)
treeee5b124fccd1fe2641f9500f9d4432488a3404fa /usr.bin
parente96f0405d6ef8a5a7d63b7b6f92e89143e2b99be (diff)
* introduce cvs_putchar(), to output a single character to stdout.
if we are in server mode send 'M' when needed. * switch diff command to cvs_printf() and cvs_putchar() so it will output correctly in local and server mode. ok xsa@, jfb@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/diff.c84
-rw-r--r--usr.bin/cvs/log.c20
-rw-r--r--usr.bin/cvs/log.h3
3 files changed, 62 insertions, 45 deletions
diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c
index add3e62ea70..b9954a8afa3 100644
--- a/usr.bin/cvs/diff.c
+++ b/usr.bin/cvs/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.41 2005/05/31 08:58:47 xsa Exp $ */
+/* $OpenBSD: diff.c,v 1.42 2005/06/05 20:47:44 joris Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -669,11 +669,11 @@ cvs_diff_local(CVSFILE *cf, void *arg)
return (CVS_EX_DATA);
}
- printf("%s", diffargs);
- printf(" -r%s", buf);
+ cvs_printf("%s", diffargs);
+ cvs_printf(" -r%s", buf);
if (dap->rev2 != NULL)
- printf(" -r%s", dap->rev2);
- printf(" %s\n", diff_file);
+ cvs_printf(" -r%s", dap->rev2);
+ cvs_printf(" %s\n", diff_file);
strlcpy(path_tmp1, "/tmp/diff1.XXXXXXXXXX", sizeof(path_tmp1));
if (cvs_buf_write_stmp(b1, path_tmp1, 0600) == -1) {
cvs_buf_free(b1);
@@ -1145,7 +1145,7 @@ check(FILE *f1, FILE *f2)
ixnew[j] = ctnew += skipline(f2);
/*
* if (jackpot)
- * fprintf(stderr, "jackpot\n");
+ * cvs_printf("jackpot\n");
*/
}
@@ -1236,7 +1236,7 @@ output(const char *file1, FILE *f1, const char *file2, FILE *f2)
#define c i0
if ((c = getc(f1)) == EOF)
return;
- putchar(c);
+ cvs_putchar(c);
}
#undef c
}
@@ -1251,20 +1251,20 @@ output(const char *file1, FILE *f1, const char *file2, FILE *f2)
static __inline void
range(int a, int b, char *separator)
{
- printf("%d", a > b ? b : a);
+ cvs_printf("%d", a > b ? b : a);
if (a < b)
- printf("%s%d", separator, b);
+ cvs_printf("%s%d", separator, b);
}
static __inline void
uni_range(int a, int b)
{
if (a < b)
- printf("%d,%d", a, b - a + 1);
+ cvs_printf("%d,%d", a, b - a + 1);
else if (a == b)
- printf("%d", b);
+ cvs_printf("%d", b);
else
- printf("%d,0", b);
+ cvs_printf("%d,0", b);
}
static char *
@@ -1354,10 +1354,10 @@ proceed:
/*
* Print the context/unidiff header first time through.
*/
- printf("%s %s %s",
+ cvs_printf("%s %s %s",
format == D_CONTEXT ? "***" : "---", diff_file,
ctime(&stb1.st_mtime));
- printf("%s %s %s",
+ cvs_printf("%s %s %s",
format == D_CONTEXT ? "---" : "+++", diff_file,
ctime(&stb2.st_mtime));
anychange = 1;
@@ -1386,19 +1386,19 @@ proceed:
return;
case D_NORMAL:
range(a, b, ",");
- putchar(a > b ? 'a' : c > d ? 'd' : 'c');
+ cvs_putchar(a > b ? 'a' : c > d ? 'd' : 'c');
if (format == D_NORMAL)
range(c, d, ",");
- putchar('\n');
+ cvs_putchar('\n');
break;
case D_RCSDIFF:
if (a > b)
- printf("a%d %d\n", b, d - c + 1);
+ cvs_printf("a%d %d\n", b, d - c + 1);
else {
- printf("d%d %d\n", a, b - a + 1);
+ cvs_printf("d%d %d\n", a, b - a + 1);
if (!(c > d)) /* add changed lines */
- printf("a%d %d\n", b, d - c + 1);
+ cvs_printf("a%d %d\n", b, d - c + 1);
}
break;
}
@@ -1409,7 +1409,7 @@ proceed:
}
i = fetch(ixnew, c, d, f2, format == D_NORMAL ? '>' : '\0', 0);
if (inifdef) {
- printf("#endif /* %s */\n", ifdefname);
+ cvs_printf("#endif /* %s */\n", ifdefname);
inifdef = 0;
}
}
@@ -1428,19 +1428,19 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile)
/* print through if append (a>b), else to (nb: 0 vs 1 orig) */
nc = f[a > b ? b : a - 1] - curpos;
for (i = 0; i < nc; i++)
- putchar(getc(lb));
+ cvs_putchar(getc(lb));
}
if (a > b)
return (0);
if (format == D_IFDEF) {
if (inifdef) {
- printf("#else /* %s%s */\n",
+ cvs_printf("#else /* %s%s */\n",
oldfile == 1 ? "!" : "", ifdefname);
} else {
if (oldfile)
- printf("#ifndef %s\n", ifdefname);
+ cvs_printf("#ifndef %s\n", ifdefname);
else
- printf("#ifdef %s\n", ifdefname);
+ cvs_printf("#ifdef %s\n", ifdefname);
}
inifdef = 1 + oldfile;
}
@@ -1448,12 +1448,12 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile)
fseek(lb, f[i - 1], SEEK_SET);
nc = f[i] - f[i - 1];
if (format != D_IFDEF && ch != '\0') {
- putchar(ch);
+ cvs_putchar(ch);
if (Tflag && (format == D_NORMAL || format == D_CONTEXT
|| format == D_UNIFIED))
- putchar('\t');
+ cvs_putchar('\t');
else if (format != D_UNIFIED)
- putchar(' ');
+ cvs_putchar(' ');
}
col = 0;
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
@@ -1466,10 +1466,10 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile)
}
if (c == '\t' && tflag) {
do {
- putchar(' ');
+ cvs_putchar(' ');
} while (++col & 7);
} else {
- putchar(c);
+ cvs_putchar(c);
col++;
}
}
@@ -1606,17 +1606,17 @@ dump_context_vec(FILE *f1, FILE *f2)
lowc = MAX(1, cvp->c - context);
upd = MIN(diff_len[1], context_vec_ptr->d + context);
- printf("***************");
+ cvs_printf("***************");
if (pflag) {
f = match_function(ixold, lowa - 1, f1);
if (f != NULL) {
- putchar(' ');
- fputs(f, stdout);
+ cvs_putchar(' ');
+ cvs_printf("%s", f);
}
}
- printf("\n*** ");
+ cvs_printf("\n*** ");
range(lowa, upb, ",");
- printf(" ****\n");
+ cvs_printf(" ****\n");
/*
* Output changes to the "old" file. The first loop suppresses
@@ -1655,9 +1655,9 @@ dump_context_vec(FILE *f1, FILE *f2)
fetch(ixold, b + 1, upb, f1, ' ', 0);
}
/* output changes to the "new" file */
- printf("--- ");
+ cvs_printf("--- ");
range(lowc, upd, ",");
- printf(" ----\n");
+ cvs_printf(" ----\n");
do_output = 0;
for (cvp = context_vec_start; cvp <= context_vec_ptr; cvp++)
@@ -1711,19 +1711,19 @@ dump_unified_vec(FILE *f1, FILE *f2)
lowc = MAX(1, cvp->c - context);
upd = MIN(diff_len[1], context_vec_ptr->d + context);
- fputs("@@ -", stdout);
+ cvs_printf("@@ -");
uni_range(lowa, upb);
- fputs(" +", stdout);
+ cvs_printf(" +");
uni_range(lowc, upd);
- fputs(" @@", stdout);
+ cvs_printf(" @@");
if (pflag) {
f = match_function(ixold, lowa - 1, f1);
if (f != NULL) {
- putchar(' ');
- fputs(f, stdout);
+ cvs_putchar(' ');
+ cvs_printf("%s", f);
}
}
- putchar('\n');
+ cvs_putchar('\n');
/*
* Output changes in "unified" diff format--the old and new lines
diff --git a/usr.bin/cvs/log.c b/usr.bin/cvs/log.c
index c78eb32926e..32561ec0e02 100644
--- a/usr.bin/cvs/log.c
+++ b/usr.bin/cvs/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.18 2005/06/02 20:16:48 joris Exp $ */
+/* $OpenBSD: log.c,v 1.19 2005/06/05 20:47:44 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -65,6 +65,7 @@ static int cvs_slpriomap[LP_MAX + 1] = {
LOG_DEBUG,
};
+static int send_m = 1;
static u_int cvs_log_dest = LD_STD;
static u_int cvs_log_flags = 0;
@@ -299,7 +300,6 @@ cvs_printf(const char *fmt, ...)
int ret;
char *nstr, *dp, *sp;
va_list vap;
- static int send_m = 1;
va_start(vap, fmt);
@@ -336,4 +336,20 @@ cvs_printf(const char *fmt, ...)
va_end(vap);
return (ret);
}
+
+void
+cvs_putchar(int c)
+{
+ if (cvs_cmdop == CVS_OP_SERVER && send_m) {
+ send_m = 0;
+ putc('M', stdout);
+ putc(' ', stdout);
+ }
+
+ putc(c, stdout);
+
+ if (cvs_cmdop == CVS_OP_SERVER && c == '\n')
+ send_m = 1;
+}
+
#endif
diff --git a/usr.bin/cvs/log.h b/usr.bin/cvs/log.h
index 40fe0293072..76c923bdd28 100644
--- a/usr.bin/cvs/log.h
+++ b/usr.bin/cvs/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.8 2005/05/31 16:23:43 xsa Exp $ */
+/* $OpenBSD: log.h,v 1.9 2005/06/05 20:47:44 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -66,5 +66,6 @@ int cvs_log_filter (u_int, u_int);
int cvs_log (u_int, const char *, ...);
int cvs_vlog (u_int, const char *, va_list);
int cvs_printf (const char *, ...);
+void cvs_putchar (int);
#endif /* LOG_H */