diffutils-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 09/17] diff: remove printint


From: Paul Eggert
Subject: [PATCH 09/17] diff: remove printint
Date: Sun, 22 Aug 2021 14:02:58 -0700

* src/system.h (printint): Remove.  All uses removed.  This type
was only for porting to pre-C89 hosts, and is no longer needed.
---
 src/context.c |  4 ++--
 src/diff.h    |  3 +--
 src/diff3.c   | 16 ++++++----------
 src/ed.c      |  2 +-
 src/ifdef.c   |  3 +--
 src/sdiff.c   | 30 ++++++++++++++----------------
 src/side.c    | 14 ++++----------
 src/system.h  | 25 +++----------------------
 src/util.c    | 18 +++++-------------
 9 files changed, 37 insertions(+), 78 deletions(-)

diff --git a/src/context.c b/src/context.c
index 814408a..30f8fd4 100644
--- a/src/context.c
+++ b/src/context.c
@@ -127,7 +127,7 @@ print_context_script (struct change *script, bool unidiff)
 static void
 print_context_number_range (struct file_data const *file, lin a, lin b)
 {
-  printint trans_a, trans_b;
+  lin trans_a, trans_b;
   translate_range (file, a, b, &trans_a, &trans_b);
 
   /* We can have B <= A in the case of a range of no lines.
@@ -296,7 +296,7 @@ pr_context_hunk (struct change *hunk)
 static void
 print_unidiff_number_range (struct file_data const *file, lin a, lin b)
 {
-  printint trans_a, trans_b;
+  lin trans_a, trans_b;
   translate_range (file, a, b, &trans_a, &trans_b);
 
   /* We can have B < A in the case of a range of no lines.
diff --git a/src/diff.h b/src/diff.h
index a51b9d2..227ca6a 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -408,8 +408,7 @@ extern void print_number_range (char, struct file_data *, 
lin, lin);
 extern void print_script (struct change *, struct change * (*) (struct change 
*),
                           void (*) (struct change *));
 extern void setup_output (char const *, char const *, bool);
-extern void translate_range (struct file_data const *, lin, lin,
-                             printint *, printint *);
+extern void translate_range (struct file_data const *, lin, lin, lin *, lin *);
 
 enum color_context
 {
diff --git a/src/diff3.c b/src/diff3.c
index 1f656b6..01e8ecd 100644
--- a/src/diff3.c
+++ b/src/diff3.c
@@ -1443,20 +1443,18 @@ output_diff3 (FILE *outputfile, struct diff3_block 
*diff,
           int realfile = mapping[i];
           lin lowt = D_LOWLINE (ptr, realfile);
           lin hight = D_HIGHLINE (ptr, realfile);
-          printint llowt = lowt;
-          printint lhight = hight;
 
           fprintf (outputfile, "%d:", i + 1);
           switch (lowt - hight)
             {
             case 1:
-              fprintf (outputfile, "%"pI"da\n", llowt - 1);
+              fprintf (outputfile, "%"pI"da\n", lowt - 1);
               break;
             case 0:
-              fprintf (outputfile, "%"pI"dc\n", llowt);
+              fprintf (outputfile, "%"pI"dc\n", lowt);
               break;
             default:
-              fprintf (outputfile, "%"pI"d,%"pI"dc\n", llowt, lhight);
+              fprintf (outputfile, "%"pI"d,%"pI"dc\n", lowt, hight);
               break;
             }
 
@@ -1513,7 +1511,7 @@ dotlines (FILE *outputfile, struct diff3_block *b, int 
filenum)
    and continuing for NUM lines.  */
 
 static void
-undotlines (FILE *outputfile, bool leading_dot, printint start, printint num)
+undotlines (FILE *outputfile, bool leading_dot, lin start, lin num)
 {
   fputs (".\n", outputfile);
   if (leading_dot)
@@ -1562,8 +1560,6 @@ output_diff3_edscript (FILE *outputfile, struct 
diff3_block *diff,
            ? DIFF_ALL
            : DIFF_1ST + rev_mapping[b->correspond - DIFF_1ST]);
 
-      printint low0, high0;
-
       /* If we aren't supposed to do this output block, skip it.  */
       switch (type)
         {
@@ -1573,8 +1569,8 @@ output_diff3_edscript (FILE *outputfile, struct 
diff3_block *diff,
         case DIFF_ALL: if (simple_only) continue; conflict = flagging; break;
         }
 
-      low0 = D_LOWLINE (b, mapping[FILE0]);
-      high0 = D_HIGHLINE (b, mapping[FILE0]);
+      lin low0 = D_LOWLINE (b, mapping[FILE0]);
+      lin high0 = D_HIGHLINE (b, mapping[FILE0]);
 
       if (conflict)
         {
diff --git a/src/ed.c b/src/ed.c
index 053e1fc..40df3d6 100644
--- a/src/ed.c
+++ b/src/ed.c
@@ -144,7 +144,7 @@ static void
 print_rcs_hunk (struct change *hunk)
 {
   lin i, f0, l0, f1, l1;
-  printint tf0, tl0, tf1, tl1;
+  lin tf0, tl0, tf1, tl1;
 
   /* Determine range of line numbers involved in each file.  */
   enum changes changes = analyze_hunk (hunk, &f0, &l0, &f1, &l1);
diff --git a/src/ifdef.c b/src/ifdef.c
index d40a88e..5a000cb 100644
--- a/src/ifdef.c
+++ b/src/ifdef.c
@@ -359,7 +359,6 @@ do_printf_spec (FILE *out, char const *spec,
           {
             /* For example, if the spec is "%3xn" and pI is "l", use the printf
                format spec "%3lx".  Here the spec prefix is "%3".  */
-            printint print_value = value;
             size_t spec_prefix_len = f - spec - 2;
             size_t pI_len = sizeof pI - 1;
             char *format = xmalloca (spec_prefix_len + pI_len + 2);
@@ -368,7 +367,7 @@ do_printf_spec (FILE *out, char const *spec,
             memcpy (format + spec_prefix_len, pI, pI_len);
             *p++ = c;
             *p = '\0';
-            fprintf (out, format, print_value);
+            fprintf (out, format, value);
             freea (format);
           }
       }
diff --git a/src/sdiff.c b/src/sdiff.c
index 232ebcd..cc20dac 100644
--- a/src/sdiff.c
+++ b/src/sdiff.c
@@ -968,14 +968,13 @@ edit (struct line_filter *left, char const *lname, lin 
lline, lin llen,
               {
               case 'd':
                 if (llen)
-                  {
-                    printint l1 = lline;
-                    printint l2 = lline + llen - 1;
-                    if (llen == 1)
-                      fprintf (tmp, "--- %s %"pI"d\n", lname, l1);
-                    else
-                      fprintf (tmp, "--- %s %"pI"d,%"pI"d\n", lname, l1, l2);
-                  }
+                 {
+                   if (llen == 1)
+                     fprintf (tmp, "--- %s %"pI"d\n", lname, lline);
+                   else
+                     fprintf (tmp, "--- %s %"pI"d,%"pI"d\n", lname, lline,
+                              lline + llen - 1);
+                 }
                 FALLTHROUGH;
               case '1': case 'b': case 'l':
                 lf_copy (left, llen, tmp);
@@ -990,14 +989,13 @@ edit (struct line_filter *left, char const *lname, lin 
lline, lin llen,
               {
               case 'd':
                 if (rlen)
-                  {
-                    printint l1 = rline;
-                    printint l2 = rline + rlen - 1;
-                    if (rlen == 1)
-                      fprintf (tmp, "+++ %s %"pI"d\n", rname, l1);
-                    else
-                      fprintf (tmp, "+++ %s %"pI"d,%"pI"d\n", rname, l1, l2);
-                  }
+                 {
+                   if (rlen == 1)
+                     fprintf (tmp, "+++ %s %"pI"d\n", rname, rline);
+                   else
+                     fprintf (tmp, "+++ %s %"pI"d,%"pI"d\n", rname, rline,
+                            rline + rlen - 1);
+                 }
                 FALLTHROUGH;
               case '2': case 'b': case 'r':
                 lf_copy (right, rlen, tmp);
diff --git a/src/side.c b/src/side.c
index 11d5f5c..15fa7ea 100644
--- a/src/side.c
+++ b/src/side.c
@@ -259,11 +259,7 @@ print_sdiff_common_lines (lin limit0, lin limit1)
   if (!suppress_common_lines && (i0 != limit0 || i1 != limit1))
     {
       if (sdiff_merge_assist)
-        {
-          printint len0 = limit0 - i0;
-          printint len1 = limit1 - i1;
-          fprintf (outfile, "i%"pI"d,%"pI"d\n", len0, len1);
-        }
+       fprintf (outfile, "i%"pI"d,%"pI"d\n", limit0 - i0, limit1 - i1);
 
       if (!left_column)
         {
@@ -301,11 +297,9 @@ print_sdiff_hunk (struct change *hunk)
   print_sdiff_common_lines (first0, first1);
 
   if (sdiff_merge_assist)
-    {
-      printint len0 = last0 - first0 + 1;
-      printint len1 = last1 - first1 + 1;
-      fprintf (outfile, "c%"pI"d,%"pI"d\n", len0, len1);
-    }
+    fprintf (outfile, "c%"pI"d,%"pI"d\n",
+            last0 - first0 + 1,
+            last1 - first1 + 1);
 
   /* Print "xxx  |  xxx " lines.  */
   if (changes == CHANGED)
diff --git a/src/system.h b/src/system.h
index f921a50..1e7c288 100644
--- a/src/system.h
+++ b/src/system.h
@@ -128,31 +128,12 @@ int strcasecmp (char const *, char const *);
 #endif
 
 /* The signed integer type of a line number.  Since files are read
-   into main memory, ptrdiff_t should be wide enough.  */
+   into main memory, ptrdiff_t should be wide enough.  pI is for
+   printing line numbers.  */
 
 typedef ptrdiff_t lin;
 #define LIN_MAX PTRDIFF_MAX
-
-/* The signed integer type for printing line numbers, and its printf
-   length modifier.  This is not simply ptrdiff_t, to cater to older
-   and/or nonstandard C libraries where "l" works but "ll" and "t" do
-   not, or where 'long' is too narrow and "ll" works but "t" does not.  */
-
-#if LIN_MAX <= LONG_MAX
-typedef long int printint;
-# define pI "l"
-#elif LIN_MAX <= LLONG_MAX
-typedef long long int printint;
-# define pI "ll"
-#else
-typedef ptrdiff_t printint;
-# define pI "t"
-#endif
-
-verify (TYPE_SIGNED (lin));
-verify (TYPE_SIGNED (printint));
-verify (LIN_MAX == TYPE_MAXIMUM (lin));
-verify (LIN_MAX <= TYPE_MAXIMUM (printint));
+#define pI "t"
 
 /* Limit so that 2 * CONTEXT + 1 does not overflow.  */
 
diff --git a/src/util.c b/src/util.c
index 8fd72e5..9963bb4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1399,14 +1399,12 @@ translate_line_number (struct file_data const *file, 
lin i)
   return i + file->prefix_lines + 1;
 }
 
-/* Translate a line number range.  This is always done for printing,
-   so for convenience translate to printint rather than lin, so that the
-   caller can use printf with "%"pI"d" without casting.  */
+/* Translate a line number range.  */
 
 void
 translate_range (struct file_data const *file,
                  lin a, lin b,
-                 printint *aptr, printint *bptr)
+                 lin *aptr, lin *bptr)
 {
   *aptr = translate_line_number (file, a - 1) + 1;
   *bptr = translate_line_number (file, b + 1) - 1;
@@ -1421,7 +1419,7 @@ translate_range (struct file_data const *file,
 void
 print_number_range (char sepchar, struct file_data *file, lin a, lin b)
 {
-  printint trans_a, trans_b;
+  lin trans_a, trans_b;
   translate_range (file, a, b, &trans_a, &trans_b);
 
   /* Note: we can have B < A in the case of a range of no lines.
@@ -1554,14 +1552,8 @@ debug_script (struct change *sp)
   fflush (stdout);
 
   for (; sp; sp = sp->link)
-    {
-      printint line0 = sp->line0;
-      printint line1 = sp->line1;
-      printint deleted = sp->deleted;
-      printint inserted = sp->inserted;
-      fprintf (stderr, "%3"pI"d %3"pI"d delete %"pI"d insert %"pI"d\n",
-               line0, line1, deleted, inserted);
-    }
+    fprintf (stderr, "%3"pI"d %3"pI"d delete %"pI"d insert %"pI"d\n",
+            sp->line0, sp->line1, sp->deleted, sp->inserted);
 
   fflush (stderr);
 }
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]