forked from pool/patch
75 lines
2.0 KiB
Diff
75 lines
2.0 KiB
Diff
---
|
|
util.c | 30 +++++++++++++++++++++++++++---
|
|
util.h | 2 ++
|
|
2 files changed, 29 insertions(+), 3 deletions(-)
|
|
|
|
Index: b/util.c
|
|
===================================================================
|
|
--- a/util.c
|
|
+++ b/util.c
|
|
@@ -466,10 +466,9 @@ remove_prefix (char *p, size_t prefixlen
|
|
continue;
|
|
}
|
|
|
|
-char *
|
|
-format_linenum (char numbuf[LINENUM_LENGTH_BOUND + 1], LINENUM n)
|
|
+static char *
|
|
+__format_linenum (char *p, LINENUM n)
|
|
{
|
|
- char *p = numbuf + LINENUM_LENGTH_BOUND;
|
|
*p = '\0';
|
|
|
|
if (n < 0)
|
|
@@ -490,6 +489,31 @@ format_linenum (char numbuf[LINENUM_LENG
|
|
return p;
|
|
}
|
|
|
|
+char *
|
|
+format_linenum (char numbuf[LINENUM_LENGTH_BOUND + 1], LINENUM n)
|
|
+{
|
|
+ return __format_linenum(numbuf + LINENUM_LENGTH_BOUND, n);
|
|
+}
|
|
+
|
|
+char *
|
|
+format_startcount (char rangebuf[LINERANGE_LENGTH_BOUND + 1],
|
|
+ LINENUM first, LINENUM lines)
|
|
+{
|
|
+ char *p = rangebuf + LINERANGE_LENGTH_BOUND;
|
|
+
|
|
+ if (lines == 1)
|
|
+ rangebuf = __format_linenum (p, first);
|
|
+ else
|
|
+ {
|
|
+ if (lines == 0 && first == 1)
|
|
+ first = 0; /* what diff produces ... */
|
|
+ p = __format_linenum(p, lines);
|
|
+ rangebuf = __format_linenum(--p, first);
|
|
+ *p = ',';
|
|
+ }
|
|
+ return rangebuf;
|
|
+}
|
|
+
|
|
#if !HAVE_VPRINTF
|
|
#define vfprintf my_vfprintf
|
|
static int
|
|
Index: b/util.h
|
|
===================================================================
|
|
--- a/util.h
|
|
+++ b/util.h
|
|
@@ -25,6 +25,7 @@
|
|
/* An upper bound on the print length of a signed decimal line number.
|
|
Add one for the sign. */
|
|
#define LINENUM_LENGTH_BOUND (sizeof (LINENUM) * CHAR_BIT / 3 + 1)
|
|
+#define LINERANGE_LENGTH_BOUND (LINENUM_LENGTH_BOUND * 2 + 1)
|
|
|
|
XTERN enum backup_type backup_type;
|
|
|
|
@@ -45,6 +46,7 @@ bool version_get (char const *, char con
|
|
int create_file (char const *, int, mode_t);
|
|
int systemic (char const *);
|
|
char *format_linenum (char[LINENUM_LENGTH_BOUND + 1], LINENUM);
|
|
+char *format_startcount (char[LINERANGE_LENGTH_BOUND + 1], LINENUM, LINENUM);
|
|
void Fseek (FILE *, file_offset, int);
|
|
void copy_file (char const *, char const *, int, mode_t);
|
|
void exit_with_signal (int) __attribute__ ((noreturn));
|