Patch 8.2.3680
Problem:    Repeated code in xxd.
Solution:   Change exit_on_ferror() to getc_or_die(). (closes #9226)
Files:      src/xxd/xxd.c


*** ../vim-8.2.3679/src/xxd/xxd.c       2021-11-25 13:26:16.034041048 +0000
--- src/xxd/xxd.c       2021-11-26 13:50:26.097925035 +0000
***************
*** 252,262 ****
    exit(ret);
  }
  
!   static void
! exit_on_ferror(int c, FILE *fpi)
  {
    if (c == EOF && ferror(fpi))
      perror_exit(2);
  }
  
    static void
--- 252,264 ----
    exit(ret);
  }
  
!   static int
! getc_or_die(FILE *fpi)
  {
+   int c = getc(fpi);
    if (c == EOF && ferror(fpi))
      perror_exit(2);
+   return c;
  }
  
    static void
***************
*** 311,318 ****
  skip_to_eol(FILE *fpi, int c)
  {
    while (c != '\n' && c != EOF)
!     c = getc(fpi);
!   exit_on_ferror(c, fpi);
    return c;
  }
  
--- 313,319 ----
  skip_to_eol(FILE *fpi, int c)
  {
    while (c != '\n' && c != EOF)
!     c = getc_or_die(fpi);
    return c;
  }
  
***************
*** 736,744 ****
          long s = seekoff;
  
          while (s--)
!           if ((c = getc(fp)) == EOF)
            {
-             exit_on_ferror(c, fp);
              error_exit(4, "sorry cannot seek.");
            }
        }
--- 737,744 ----
          long s = seekoff;
  
          while (s--)
!           if ((c = getc_or_die(fp)) == EOF)
            {
              error_exit(4, "sorry cannot seek.");
            }
        }
***************
*** 756,775 ****
  
        p = 0;
        c = 0;
!       while ((length < 0 || p < length) && (c = getc(fp)) != EOF)
        {
          fprintf_or_die(fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X",
!               (p % cols) ? ", " : &",\n  "[2*!p],  c);
          p++;
        }
-       exit_on_ferror(c, fp);
  
        if (p)
        fputs_or_die("\n", fpo);
-       fputs_or_die(&"};\n"[3 * (fp == stdin)], fpo);
  
        if (fp != stdin)
        {
          fprintf_or_die(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? 
"__" : "", 0);
          for (e = 0; (c = argv[1][e]) != 0; e++)
            putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo);
--- 756,774 ----
  
        p = 0;
        c = 0;
!       while ((length < 0 || p < length) && (c = getc_or_die(fp)) != EOF)
        {
          fprintf_or_die(fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X",
!               (p % cols) ? ", " : (!p ? "  " : ",\n  "),  c);
          p++;
        }
  
        if (p)
        fputs_or_die("\n", fpo);
  
        if (fp != stdin)
        {
+         fputs_or_die("};\n", fpo);
          fprintf_or_die(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? 
"__" : "", 0);
          for (e = 0; (c = argv[1][e]) != 0; e++)
            putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo);
***************
*** 784,790 ****
      {
        p = cols;
        e = 0;
!       while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
        {
          putc_or_die(hexx[(e >> 4) & 0xf], fpo);
          putc_or_die(hexx[e & 0xf], fpo);
--- 783,789 ----
      {
        p = cols;
        e = 0;
!       while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF)
        {
          putc_or_die(hexx[(e >> 4) & 0xf], fpo);
          putc_or_die(hexx[e & 0xf], fpo);
***************
*** 795,801 ****
              p = cols;
            }
        }
-       exit_on_ferror(e, fp);
        if (p < cols)
        putc_or_die('\n', fpo);
        fclose_or_die(fp, fpo);
--- 794,799 ----
***************
*** 810,816 ****
      grplen = 8 * octspergrp + 1;
  
    e = 0;
!   while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
      {
        int x;
  
--- 808,814 ----
      grplen = 8 * octspergrp + 1;
  
    e = 0;
!   while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF)
      {
        int x;
  
***************
*** 856,862 ****
          p = 0;
        }
      }
-   exit_on_ferror(e, fp);
    if (p)
      {
        l[c] = '\n';
--- 854,859 ----
*** ../vim-8.2.3679/src/version.c       2021-11-26 13:01:36.988427354 +0000
--- src/version.c       2021-11-26 13:58:43.877882630 +0000
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     3680,
  /**/

-- 
ARTHUR: If you do not open these doors, we will take this castle by force ...
   [A bucket of slops land on ARTHUR.  He tries to retain his dignity.]
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20211126140001.8C2431C020B%40moolenaar.net.

Raspunde prin e-mail lui