]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: use C99 for loop initial declarations where possible
authorPádraig Brady <P@draigBrady.com>
Sat, 17 Jun 2017 21:54:23 +0000 (14:54 -0700)
committerPádraig Brady <P@draigBrady.com>
Sat, 17 Jun 2017 22:51:59 +0000 (15:51 -0700)
This results in a net reduction of about 120 lines.

35 files changed:
src/base64.c
src/cksum.c
src/copy.c
src/cp.c
src/csplit.c
src/dd.c
src/df.c
src/du.c
src/expand-common.c
src/group-list.c
src/id.c
src/join.c
src/ln.c
src/ls.c
src/md5sum.c
src/mv.c
src/od.c
src/paste.c
src/pinky.c
src/pr.c
src/pwd.c
src/rm.c
src/set-fields.c
src/shuf.c
src/sleep.c
src/sort.c
src/stat.c
src/stdbuf.c
src/stty.c
src/sum.c
src/tac-pipe.c
src/tac.c
src/tail.c
src/tr.c
src/wc.c

index d005c262acda2db3b8f299ac5231ce4f7d3ec0e5..6e1855641bc8cdb6ca2c279b6f2f4a26773f7c13 100644 (file)
@@ -224,12 +224,13 @@ do_decode (FILE *in, FILE *out, bool ignore_garbage)
 
           if (ignore_garbage)
             {
-              size_t i;
-              for (i = 0; n > 0 && i < n;)
-                if (isbase (inbuf[sum + i]) || inbuf[sum + i] == '=')
-                  i++;
-                else
-                  memmove (inbuf + sum + i, inbuf + sum + i + 1, --n - i);
+              for (size_t i = 0; n > 0 && i < n;)
+                {
+                  if (isbase (inbuf[sum + i]) || inbuf[sum + i] == '=')
+                    i++;
+                  else
+                    memmove (inbuf + sum + i, inbuf + sum + i + 1, --n - i);
+                }
             }
 
           sum += n;
index b1a8f0c5fc79a66abc2619d60f96a3feca0bb2b6..e0929dafe7477ac6eecfc92f50aa6e14cc7497d0 100644 (file)
@@ -67,10 +67,8 @@ static uint_fast32_t r[8];
 static void
 fill_r (void)
 {
-  int i;
-
   r[0] = GEN;
-  for (i = 1; i < 8; i++)
+  for (int i = 1; i < 8; i++)
     r[i] = (r[i - 1] << 1) ^ ((r[i - 1] & SBIT) ? GEN : 0);
 }
 
@@ -78,9 +76,8 @@ static uint_fast32_t
 crc_remainder (int m)
 {
   uint_fast32_t rem = 0;
-  int i;
 
-  for (i = 0; i < 8; i++)
+  for (int i = 0; i < 8; i++)
     if (BIT (i) & m)
       rem ^= r[i];
 
@@ -90,11 +87,9 @@ crc_remainder (int m)
 int
 main (void)
 {
-  int i;
-
   fill_r ();
   printf ("static uint_fast32_t const crctab[256] =\n{\n  0x00000000");
-  for (i = 0; i < 51; i++)
+  for (int i = 0; i < 51; i++)
     {
       printf (",\n  0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x",
               crc_remainder (i * 5 + 1), crc_remainder (i * 5 + 2),
index 965e8190db03a8a4ba665ea6d4e9d5f44055ae63..a2eee1be5204630c33bb8d3008da3f7da018b8fe 100644 (file)
@@ -420,9 +420,8 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
           return false;
         }
 
-      unsigned int i;
       bool empty_extent = false;
-      for (i = 0; i < scan.ei_count || empty_extent; i++)
+      for (unsigned int i = 0; i < scan.ei_count || empty_extent; i++)
         {
           off_t ext_start;
           off_t ext_len;
index ec09ed5ddcb0e707e367206cdaced4bfc329ebd1..a6f0c64a8f18a84cf4606e8527c1baeb46bdb7aa 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -640,7 +640,6 @@ do_copy (int n_files, char **file, const char *target_directory,
       /* cp file1...filen edir
          Copy the files 'file1' through 'filen'
          to the existing directory 'edir'. */
-      int i;
 
       /* Initialize these hash tables only if we'll need them.
          The problems they're used to detect can arise only if
@@ -651,7 +650,7 @@ do_copy (int n_files, char **file, const char *target_directory,
           src_info_init (x);
         }
 
-      for (i = 0; i < n_files; i++)
+      for (int i = 0; i < n_files; i++)
         {
           char *dst_name;
           bool parent_exists = true;  /* True if dir_name (dst_name) exists. */
index a3f30e8745e3e70f7229c733b2c90c8b5d31d81b..a7c6cc1602082089d65656159848099bce574f9a 100644 (file)
@@ -900,9 +900,7 @@ process_regexp (struct control *p, uintmax_t repetition)
 static void
 split_file (void)
 {
-  size_t i;
-
-  for (i = 0; i < control_used; i++)
+  for (size_t i = 0; i < control_used; i++)
     {
       uintmax_t j;
       if (controls[i].regexpr)
@@ -983,12 +981,10 @@ create_output_file (void)
 static void
 delete_all_files (bool in_signal_handler)
 {
-  unsigned int i;
-
   if (! remove_files)
     return;
 
-  for (i = 0; i < files_created; i++)
+  for (unsigned int i = 0; i < files_created; i++)
     {
       const char *name = make_filename (i);
       if (unlink (name) != 0 && !in_signal_handler)
@@ -1178,12 +1174,11 @@ extract_regexp (int argnum, bool ignore, char const *str)
 static void
 parse_patterns (int argc, int start, char **argv)
 {
-  int i;                       /* Index into ARGV. */
   struct control *p;           /* New control record created. */
   uintmax_t val;
   static uintmax_t last_val = 0;
 
-  for (i = start; i < argc; i++)
+  for (int i = start; i < argc; i++)
     {
       if (*argv[i] == '/' || *argv[i] == '%')
         {
index 99ca1fa66495fdbc7896146eae997a5ea77dcdd0..ddeeb4f582841767bf451104d068e4193b0d4350 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -741,9 +741,7 @@ alloc_obuf (void)
 static void
 translate_charset (char const *new_trans)
 {
-  int i;
-
-  for (i = 0; i < 256; i++)
+  for (int i = 0; i < 256; i++)
     trans_table[i] = new_trans[trans_table[i]];
   translation_needed = true;
 }
@@ -1382,13 +1380,12 @@ operand_is (char const *operand, char const *name)
 static void
 scanargs (int argc, char *const *argv)
 {
-  int i;
   size_t blocksize = 0;
   uintmax_t count = (uintmax_t) -1;
   uintmax_t skip = 0;
   uintmax_t seek = 0;
 
-  for (i = optind; i < argc; i++)
+  for (int i = optind; i < argc; i++)
     {
       char const *name = argv[i];
       char const *val = strchr (name, '=');
@@ -1617,9 +1614,8 @@ apply_translations (void)
 static void
 translate_buffer (char *buf, size_t nread)
 {
-  char *cp;
   size_t i;
-
+  char *cp;
   for (i = nread, cp = buf; i; i--, cp++)
     *cp = trans_table[to_uchar (*cp)];
 }
@@ -1639,8 +1635,6 @@ static char *
 swab_buffer (char *buf, size_t *nread)
 {
   char *bufstart = buf;
-  char *cp;
-  size_t i;
 
   /* Is a char left from last time?  */
   if (char_is_saved)
@@ -1661,8 +1655,8 @@ swab_buffer (char *buf, size_t *nread)
      positions toward the end, working from the end of the buffer
      toward the beginning.  This way we only move half of the data.  */
 
-  cp = bufstart + *nread;      /* Start one char past the last.  */
-  for (i = *nread / 2; i; i--, cp -= 2)
+  char *cp = bufstart + *nread;        /* Start one char past the last.  */
+  for (size_t i = *nread / 2; i; i--, cp -= 2)
     *cp = *(cp - 2);
 
   return ++bufstart;
@@ -1933,9 +1927,7 @@ copy_simple (char const *buf, size_t nread)
 static void
 copy_with_block (char const *buf, size_t nread)
 {
-  size_t i;
-
-  for (i = nread; i; i--, buf++)
+  for (size_t i = nread; i; i--, buf++)
     {
       if (*buf == newline_character)
         {
@@ -1965,13 +1957,11 @@ copy_with_block (char const *buf, size_t nread)
 static void
 copy_with_unblock (char const *buf, size_t nread)
 {
-  size_t i;
-  char c;
   static size_t pending_spaces = 0;
 
-  for (i = 0; i < nread; i++)
+  for (size_t i = 0; i < nread; i++)
     {
-      c = buf[i];
+      char c = buf[i];
 
       if (col++ >= conversion_blocksize)
         {
@@ -2275,8 +2265,7 @@ dd_copy (void)
     {
       /* If the final input line didn't end with a '\n', pad
          the output block to 'conversion_blocksize' chars.  */
-      size_t i;
-      for (i = col; i < conversion_blocksize; i++)
+      for (size_t i = col; i < conversion_blocksize; i++)
         output_char (space_character);
     }
 
index 5788d216f4594e0a29f85c7068a389cee31193ac..678aa47fd24dece33b5dbfd5c0f3741a3458ea8c 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -1701,13 +1701,11 @@ main (int argc, char **argv)
 
   if (optind < argc)
     {
-      int i;
-
       /* Open each of the given entries to make sure any corresponding
          partition is automounted.  This must be done before reading the
          file system table.  */
       stats = xnmalloc (argc - optind, sizeof *stats);
-      for (i = optind; i < argc; ++i)
+      for (int i = optind; i < argc; ++i)
         {
           /* Prefer to open with O_NOCTTY and use fstat, but fall back
              on using "stat", in case the file is unreadable.  */
@@ -1759,12 +1757,10 @@ main (int argc, char **argv)
 
   if (optind < argc)
     {
-      int i;
-
       /* Display explicitly requested empty file systems.  */
       show_listed_fs = true;
 
-      for (i = optind; i < argc; ++i)
+      for (int i = optind; i < argc; ++i)
         if (argv[i])
           get_entry (argv[i], &stats[i - optind]);
 
index 8e88b562177a986072067438733c6c8951536a5f..95797ff0857f5d85cb25a3c5be2410e3978eaa5f 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -613,7 +613,6 @@ process_file (FTS *fts, FTSENT *ent)
              Clear the accumulators for *all* levels between prev_level
              and the current one.  The depth may change dramatically,
              e.g., from 1 to 10.  */
-          size_t i;
 
           if (n_alloc <= level)
             {
@@ -621,7 +620,7 @@ process_file (FTS *fts, FTSENT *ent)
               n_alloc = level * 2;
             }
 
-          for (i = prev_level + 1; i <= level; i++)
+          for (size_t i = prev_level + 1; i <= level; i++)
             {
               duinfo_init (&dulvl[i].ent);
               duinfo_init (&dulvl[i].subdir);
index 8c83fb36527ed5fa14289863da9f6a08e3a1b89d..53a7710197967637881166cad67da79a8364327b 100644 (file)
@@ -237,9 +237,8 @@ static void
 validate_tab_stops (uintmax_t const *tabs, size_t entries)
 {
   uintmax_t prev_tab = 0;
-  size_t i;
 
-  for (i = 0; i < entries; i++)
+  for (size_t i = 0; i < entries; i++)
     {
       if (tabs[i] == 0)
         die (EXIT_FAILURE, 0, _("tab size cannot be 0"));
index 274c5e6c1c2f60e223ed5d898102baf415632fa8..36b6144674babb281062f2fb374c02e0b2991e71 100644 (file)
@@ -59,7 +59,6 @@ print_group_list (const char *username,
 
   {
     gid_t *groups;
-    int i;
 
     int n_groups = xgetgroups (username, (pwd ? pwd->pw_gid : egid), &groups);
     if (n_groups < 0)
@@ -76,7 +75,7 @@ print_group_list (const char *username,
         return false;
       }
 
-    for (i = 0; i < n_groups; i++)
+    for (int i = 0; i < n_groups; i++)
       if (groups[i] != rgid && groups[i] != egid)
         {
           putchar (delim);
index ab7d53ef2dec40008bb05e3173b0620895e953dc..2bd417d7733a06d124193e52b484bff03035afe1 100644 (file)
--- a/src/id.c
+++ b/src/id.c
@@ -400,7 +400,6 @@ print_full_info (const char *username)
 
   {
     gid_t *groups;
-    int i;
 
     gid_t primary_group;
     if (username)
@@ -422,7 +421,7 @@ print_full_info (const char *username)
 
     if (n_groups > 0)
       fputs (_(" groups="), stdout);
-    for (i = 0; i < n_groups; i++)
+    for (int i = 0; i < n_groups; i++)
       {
         if (i > 0)
           putchar (',');
index 93570adeb4437b239215245bcbca8760f60368ab..ae10101fc60a2ecd0a07408478706eab7fbf720a 100644 (file)
@@ -480,9 +480,7 @@ get_line (FILE *fp, struct line **linep, int which)
 static void
 free_spareline (void)
 {
-  size_t i;
-
-  for (i = 0; i < ARRAY_CARDINALITY (spareline); i++)
+  for (size_t i = 0; i < ARRAY_CARDINALITY (spareline); i++)
     {
       if (spareline[i])
         {
@@ -507,9 +505,8 @@ getseq (FILE *fp, struct seq *seq, int whichfile)
 {
   if (seq->count == seq->alloc)
     {
-      size_t i;
       seq->lines = X2NREALLOC (seq->lines, &seq->alloc);
-      for (i = seq->count; i < seq->alloc; i++)
+      for (size_t i = seq->count; i < seq->alloc; i++)
         seq->lines[i] = NULL;
     }
 
@@ -535,8 +532,7 @@ advance_seq (FILE *fp, struct seq *seq, bool first, int whichfile)
 static void
 delseq (struct seq *seq)
 {
-  size_t i;
-  for (i = 0; i < seq->alloc; i++)
+  for (size_t i = 0; i < seq->alloc; i++)
     {
       freeline (seq->lines[i]);
       free (seq->lines[i]);
@@ -693,7 +689,6 @@ join (FILE *fp1, FILE *fp2)
 
   while (seq1.count && seq2.count)
     {
-      size_t i;
       diff = keycmp (seq1.lines[0], seq2.lines[0],
                      join_field_1, join_field_2);
       if (diff < 0)
@@ -741,7 +736,7 @@ join (FILE *fp1, FILE *fp2)
 
       if (print_pairables)
         {
-          for (i = 0; i < seq1.count - 1; ++i)
+          for (size_t i = 0; i < seq1.count - 1; ++i)
             {
               size_t j;
               for (j = 0; j < seq2.count - 1; ++j)
index 539d238c84b99d7d1b5c660d9fa3ce184e591c13..a70b7d50fe23cdd42cbfbf017da69161d8f5810a 100644 (file)
--- a/src/ln.c
+++ b/src/ln.c
@@ -575,8 +575,6 @@ main (int argc, char **argv)
 
   if (target_directory)
     {
-      int i;
-
       /* Create the data structure we'll use to record which hard links we
          create.  Used to ensure that ln detects an obscure corner case that
          might result in user data loss.  Create it only if needed.  */
@@ -600,7 +598,7 @@ main (int argc, char **argv)
         }
 
       ok = true;
-      for (i = 0; i < n_files; ++i)
+      for (int i = 0; i < n_files; ++i)
         {
           char *dest_base;
           char *dest = file_name_concat (target_directory,
index 9477d31be3366b1c983ea0f0169b4521e2f00a9e..4802d9218c65cb6073a6d9c88aa72ce50a375038 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -1041,12 +1041,9 @@ dired_dump_obstack (const char *prefix, struct obstack *os)
   n_pos = obstack_object_size (os) / sizeof (dired_pos);
   if (n_pos > 0)
     {
-      size_t i;
-      size_t *pos;
-
-      pos = (size_t *) obstack_finish (os);
+      size_t *pos = (size_t *) obstack_finish (os);
       fputs (prefix, stdout);
-      for (i = 0; i < n_pos; i++)
+      for (size_t i = 0; i < n_pos; i++)
         printf (" %lu", (unsigned long int) pos[i]);
       putchar ('\n');
     }
@@ -2198,8 +2195,7 @@ decode_switches (int argc, char **argv)
             case locale_time_style:
               if (hard_locale (LC_TIME))
                 {
-                  int i;
-                  for (i = 0; i < 2; i++)
+                  for (int i = 0; i < 2; i++)
                     long_time_format[i] =
                       dcgettext (NULL, long_time_format[i], LC_TIME);
                 }
@@ -2926,9 +2922,7 @@ free_ent (struct fileinfo *f)
 static void
 clear_files (void)
 {
-  size_t i;
-
-  for (i = 0; i < cwd_n_used; i++)
+  for (size_t i = 0; i < cwd_n_used; i++)
     {
       struct fileinfo *f = sorted_file[i];
       free_ent (f);
@@ -3708,8 +3702,7 @@ verify (ARRAY_CARDINALITY (sort_functions)
 static void
 initialize_ordering_vector (void)
 {
-  size_t i;
-  for (i = 0; i < cwd_n_used; i++)
+  for (size_t i = 0; i < cwd_n_used; i++)
     sorted_file[i] = &cwd_file[i];
 }
 
@@ -4965,9 +4958,8 @@ calculate_columns (bool by_columns)
     {
       struct fileinfo const *f = sorted_file[filesno];
       size_t name_length = length_of_file_name_and_frills (f);
-      size_t i;
 
-      for (i = 0; i < max_cols; ++i)
+      for (size_t i = 0; i < max_cols; ++i)
         {
           if (column_info[i].valid_len)
             {
index 9de0eb9217c5321e51bdd5252f7c4254a599c6fd..93db658e61eb86d56ffe012acb85d9524bc9c1f2 100644 (file)
@@ -347,8 +347,7 @@ filename_unescape (char *s, size_t s_len)
 static bool _GL_ATTRIBUTE_PURE
 hex_digits (unsigned char const *s)
 {
-  unsigned int i;
-  for (i = 0; i < digest_hex_bytes; i++)
+  for (unsigned int i = 0; i < digest_hex_bytes; i++)
     {
       if (!isxdigit (*s))
         return false;
@@ -1062,14 +1061,12 @@ main (int argc, char **argv)
                   fputs (") = ", stdout);
                 }
 
-              size_t i;
-
               /* Output a leading backslash if the file name contains
                  a newline or backslash.  */
               if (!prefix_tag && needs_escape)
                 putchar ('\\');
 
-              for (i = 0; i < (digest_hex_bytes / 2); ++i)
+              for (size_t i = 0; i < (digest_hex_bytes / 2); ++i)
                 printf ("%02x", bin_buffer[i]);
 
               if (!prefix_tag)
index d64786b9c3b24f8a45478543858480cf6c782a8c..a6c6e3978f649a684e11710b2ed78c815d8c623e 100644 (file)
--- a/src/mv.c
+++ b/src/mv.c
@@ -474,8 +474,6 @@ main (int argc, char **argv)
 
   if (target_directory)
     {
-      int i;
-
       /* Initialize the hash table only if we'll need it.
          The problem it is used to detect can arise only if there are
          two or more files to move.  */
@@ -483,7 +481,7 @@ main (int argc, char **argv)
         dest_info_init (&x);
 
       ok = true;
-      for (i = 0; i < n_files; ++i)
+      for (int i = 0; i < n_files; ++i)
         ok &= movefile (file[i], target_directory, true, &x);
     }
   else
index f469326ffe841a39e02b48e2ec59f925a7dc0777..52df7ae08f5a8da889b83bb3c28e3a0b4dc2f1d0 100644 (file)
--- a/src/od.c
+++ b/src/od.c
@@ -484,9 +484,8 @@ PRINT_FLOATTYPE (print_long_double, long double, ldtoastr, LDBL_BUFSIZE_BOUND)
 static void
 dump_hexl_mode_trailer (size_t n_bytes, const char *block)
 {
-  size_t i;
   fputs ("  >", stdout);
-  for (i = n_bytes; i > 0; i--)
+  for (size_t i = n_bytes; i > 0; i--)
     {
       unsigned char c = *block++;
       unsigned char c2 = (isprint (c) ? c : '.');
@@ -1205,10 +1204,8 @@ write_block (uintmax_t current_offset, size_t n_bytes,
     }
   else
     {
-      size_t i;
-
       prev_pair_equal = false;
-      for (i = 0; i < n_specs; i++)
+      for (size_t i = 0; i < n_specs; i++)
         {
           int datum_width = width_bytes[spec[i].size];
           int fields_per_block = bytes_per_block / datum_width;
@@ -1318,10 +1315,9 @@ read_block (size_t n, char *block, size_t *n_bytes_in_buffer)
 static int _GL_ATTRIBUTE_PURE
 get_lcm (void)
 {
-  size_t i;
   int l_c_m = 1;
 
-  for (i = 0; i < n_specs; i++)
+  for (size_t i = 0; i < n_specs; i++)
     l_c_m = lcm (l_c_m, width_bytes[spec[i].size]);
   return l_c_m;
 }
index 31ba4ca6b8aa410595e8f9e984dff59258850bbd..17ee393d87a25b83f64ca50fe038e801e3f884ae 100644 (file)
@@ -231,9 +231,8 @@ paste_parallel (size_t nfiles, char **fnamptr)
       bool somedone = false;
       char const *delimptr = delims;
       size_t delims_saved = 0; /* Number of delims saved in 'delbuf'. */
-      size_t i;
 
-      for (i = 0; i < nfiles && files_open; i++)
+      for (size_t i = 0; i < nfiles && files_open; i++)
         {
           int chr IF_LINT ( = 0);      /* Input character. */
           int err IF_LINT ( = 0);      /* Input errno value.  */
index 6db565bb7265c7229986cfe154051223ea28d6d4..44dae9afddc1889ebb68f57a5d63d5872e7a4e4f 100644 (file)
@@ -441,9 +441,7 @@ scan_entries (size_t n, const STRUCT_UTMP *utmp_buf,
         {
           if (argc_names)
             {
-              int i;
-
-              for (i = 0; i < argc_names; i++)
+              for (int i = 0; i < argc_names; i++)
                 if (STREQ_LEN (UT_USER (utmp_buf), argv_names[i], UT_USER_SIZE))
                   {
                     print_entry (utmp_buf);
@@ -477,9 +475,7 @@ short_pinky (const char *filename,
 static void
 long_pinky (const int argc_names, char *const argv_names[])
 {
-  int i;
-
-  for (i = 0; i < argc_names; i++)
+  for (int i = 0; i < argc_names; i++)
     print_long_entry (argv_names[i]);
 }
 
index 4580c5c78069cccfdd6b4d10759773fecb417db0..9455781d9340eca6c38b9137e81a65d73460c6eb 100644 (file)
--- a/src/pr.c
+++ b/src/pr.c
@@ -1136,8 +1136,7 @@ main (int argc, char **argv)
         print_files (n_files, file_names);
       else
         {
-          unsigned int i;
-          for (i = 0; i < n_files; i++)
+          for (unsigned int i = 0; i < n_files; i++)
             print_files (1, &file_names[i]);
         }
     }
@@ -1311,10 +1310,7 @@ init_parameters (int number_of_files)
 static bool
 init_fps (int number_of_files, char **av)
 {
-  int i, files_left;
   COLUMN *p;
-  FILE *firstfp;
-  char const *firstname;
 
   total_files = 0;
 
@@ -1323,7 +1319,7 @@ init_fps (int number_of_files, char **av)
 
   if (parallel_files)
     {
-      files_left = number_of_files;
+      int files_left = number_of_files;
       for (p = column_vector; files_left--; ++p, ++av)
         {
           if (! open_file (*av, p))
@@ -1358,8 +1354,9 @@ init_fps (int number_of_files, char **av)
           p->lines_stored = 0;
         }
 
-      firstname = p->name;
-      firstfp = p->fp;
+      char const *firstname = p->name;
+      FILE *firstfp = p->fp;
+      int i;
       for (i = columns - 1, ++p; i; --i, ++p)
         {
           p->name = firstname;
@@ -2077,12 +2074,10 @@ pad_across_to (int position)
 static void
 pad_down (unsigned int lines)
 {
-  unsigned int i;
-
   if (use_form_feed)
     putchar ('\f');
   else
-    for (i = lines; i; --i)
+    for (unsigned int i = lines; i; --i)
       putchar ('\n');
 }
 
@@ -2310,14 +2305,12 @@ print_char (char c)
 static bool
 skip_to_page (uintmax_t page)
 {
-  uintmax_t n;
-  int i;
-  int j;
-  COLUMN *p;
-
-  for (n = 1; n < page; ++n)
+  for (uintmax_t n = 1; n < page; ++n)
     {
-      for (i = 1; i < lines_per_body; ++i)
+      COLUMN *p;
+      int j;
+
+      for (int i = 1; i < lines_per_body; ++i)
         {
           for (j = 1, p = column_vector; j <= columns; ++j, ++p)
             if (p->status == OPEN)
@@ -2552,7 +2545,6 @@ static bool
 print_stored (COLUMN *p)
 {
   COLUMN *q;
-  int i;
 
   int line = p->current_line++;
   char *first = &buff[line_vector[line]];
@@ -2576,6 +2568,7 @@ print_stored (COLUMN *p)
 
   if (p->status == FF_FOUND)
     {
+      int i;
       for (i = 1, q = column_vector; i <= columns; ++i, ++q)
         q->status = ON_HOLD;
       if (column_vector->lines_to_print <= 0)
index 472e3a878b5fc7e7089fa5d3a8f19348b2ac85a1..8852ab4841d8b59e08a720f0b8147155cf27fe17 100644 (file)
--- a/src/pwd.c
+++ b/src/pwd.c
@@ -128,9 +128,8 @@ nth_parent (size_t n)
 {
   char *buf = xnmalloc (3, n);
   char *p = buf;
-  size_t i;
 
-  for (i = 0; i < n; i++)
+  for (size_t i = 0; i < n; i++)
     {
       memcpy (p, "../", 3);
       p += 3;
index 0dff18a4cdfcb20ce083062e87d0da41884dd3c1..51b80facf874c45d7cd358fd3394b06a5719bf81 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -105,9 +105,8 @@ diagnose_leading_hyphen (int argc, char **argv)
 {
   /* OPTIND is unreliable, so iterate through the arguments looking
      for a file name that looks like an option.  */
-  int i;
 
-  for (i = 1; i < argc; i++)
+  for (int i = 1; i < argc; i++)
     {
       char const *arg = argv[i];
       struct stat st;
index 076a77666b990d267dff00e6466fe210d770e4b3..2b3edccc232e845cf61c79697ab899edd04c72da 100644 (file)
@@ -73,7 +73,6 @@ complement_rp (void)
 {
   struct field_range_pair *c = frp;
   size_t n = n_frp;
-  size_t i;
 
   frp = NULL;
   n_frp = 0;
@@ -82,7 +81,7 @@ complement_rp (void)
   if (c[0].lo > 1)
     add_range_pair (1, c[0].lo - 1);
 
-  for (i = 1; i < n; ++i)
+  for (size_t i = 1; i < n; ++i)
     {
       if (c[i-1].hi + 1 == c[i].lo)
         continue;
@@ -144,7 +143,6 @@ set_fields (const char *fieldstr, unsigned int options)
   bool rhs_specified = false;
   bool dash_found = false;     /* True if a '-' is found in this field.  */
 
-  size_t i;
   bool in_digits = false;
 
   /* Collect and store in RP the range end points. */
@@ -285,7 +283,7 @@ set_fields (const char *fieldstr, unsigned int options)
   qsort (frp, n_frp, sizeof (frp[0]), compare_ranges);
 
   /* Merge range pairs (e.g. `2-5,3-4' becomes `2-5'). */
-  for (i = 0; i < n_frp; ++i)
+  for (size_t i = 0; i < n_frp; ++i)
     {
       for (size_t j = i + 1; j < n_frp; ++j)
         {
index 282cfd5c24450c1c4d44304f105f8422cacc727e..46556a89bebe93c69eb0cb96bb1ed0d88b54e337 100644 (file)
@@ -240,9 +240,7 @@ static int
 write_permuted_output_reservoir (size_t n_lines, struct linebuffer *lines,
                                  size_t const *permutation)
 {
-  size_t i;
-
-  for (i = 0; i < n_lines; i++)
+  for (size_t i = 0; i < n_lines; i++)
     {
       const struct linebuffer *p = &lines[permutation[i]];
       if (fwrite (p->buffer, sizeof (char), p->length, stdout) != p->length)
@@ -266,7 +264,6 @@ read_input (FILE *in, char eolbyte, char ***pline)
   size_t used;
   char *lim;
   char **line;
-  size_t i;
   size_t n_lines;
 
   /* TODO: We should limit the amount of data read here,
@@ -293,7 +290,7 @@ read_input (FILE *in, char eolbyte, char ***pline)
   *pline = line = xnmalloc (n_lines + 1, sizeof *line);
 
   line[0] = p = buf;
-  for (i = 1; i <= n_lines; i++)
+  for (size_t i = 1; i <= n_lines; i++)
     line[i] = p = next_line (p, eolbyte, lim - p);
 
   return n_lines;
@@ -307,9 +304,7 @@ static int
 write_permuted_lines (size_t n_lines, char *const *line,
                       size_t const *permutation)
 {
-  size_t i;
-
-  for (i = 0; i < n_lines; i++)
+  for (size_t i = 0; i < n_lines; i++)
     {
       char *const *p = line + permutation[i];
       size_t len = p[1] - p[0];
@@ -326,9 +321,7 @@ static int
 write_permuted_numbers (size_t n_lines, size_t lo_input,
                         size_t const *permutation, char eolbyte)
 {
-  size_t i;
-
-  for (i = 0; i < n_lines; i++)
+  for (size_t i = 0; i < n_lines; i++)
     {
       unsigned long int n = lo_input + permutation[i];
       if (printf ("%lu%c", n, eolbyte) < 0)
@@ -344,10 +337,9 @@ static int
 write_random_numbers (struct randint_source *s, size_t count,
                       size_t lo_input, size_t hi_input, char eolbyte)
 {
-  size_t i;
   const randint range = hi_input - lo_input + 1;
 
-  for (i = 0; i < count; i++)
+  for (size_t i = 0; i < count; i++)
     {
       unsigned long int j = lo_input + randint_choose (s, range);
       if (printf ("%lu%c", j, eolbyte) < 0)
@@ -364,9 +356,7 @@ static int
 write_random_lines (struct randint_source *s, size_t count,
                     char *const *lines, size_t n_lines)
 {
-  size_t i;
-
-  for (i = 0; i < count; i++)
+  for (size_t i = 0; i < count; i++)
     {
       const randint j = randint_choose (s, n_lines);
       char *const *p = lines + j;
index 403485ed75de83a66a281deeb633f91f825e3473..26e3fe22d53aa56740167751b6edd1fa138b6c61 100644 (file)
@@ -98,7 +98,6 @@ apply_suffix (double *x, char suffix_char)
 int
 main (int argc, char **argv)
 {
-  int i;
   double seconds = 0.0;
   bool ok = true;
 
@@ -121,7 +120,7 @@ main (int argc, char **argv)
       usage (EXIT_FAILURE);
     }
 
-  for (i = optind; i < argc; i++)
+  for (int i = optind; i < argc; i++)
     {
       double s;
       const char *p;
index d9a2edbfde5d2aeebc7e4b58e863dee328909b80..015e40e3a2173a6800760c70bb81dcf069449aa1 100644 (file)
@@ -1511,9 +1511,7 @@ sort_buffer_size (FILE *const *fps, size_t nfps,
      This extra room might be needed when preparing to read EOF.  */
   size_t size = worst_case_per_input_byte + 1;
 
-  size_t i;
-
-  for (i = 0; i < nfiles; i++)
+  for (size_t i = 0; i < nfiles; i++)
     {
       struct stat st;
       off_t file_size;
@@ -3692,12 +3690,11 @@ static void
 avoid_trashing_input (struct sortfile *files, size_t ntemps,
                       size_t nfiles, char const *outfile)
 {
-  size_t i;
   bool got_outstat = false;
   struct stat outstat;
   struct tempnode *tempcopy = NULL;
 
-  for (i = ntemps; i < nfiles; i++)
+  for (size_t i = ntemps; i < nfiles; i++)
     {
       bool is_stdin = STREQ (files[i].name, "-");
       bool same;
@@ -3748,8 +3745,7 @@ avoid_trashing_input (struct sortfile *files, size_t ntemps,
 static void
 check_inputs (char *const *files, size_t nfiles)
 {
-  size_t i;
-  for (i = 0; i < nfiles; i++)
+  for (size_t i = 0; i < nfiles; i++)
     {
       if (STREQ (files[i], "-"))
         continue;
@@ -3997,10 +3993,9 @@ sort (char *const *files, size_t nfiles, char const *output_file,
 
   if (! output_file_created)
     {
-      size_t i;
       struct tempnode *node = temphead;
       struct sortfile *tempfiles = xnmalloc (ntemps, sizeof *tempfiles);
-      for (i = 0; node; i++)
+      for (size_t i = 0; node; i++)
         {
           tempfiles[i].name = node->name;
           tempfiles[i].temp = node;
@@ -4613,11 +4608,10 @@ main (int argc, char **argv)
 
       if (tok.n_tok)
         {
-          size_t i;
           free (files);
           files = tok.tok;
           nfiles = tok.n_tok;
-          for (i = 0; i < nfiles; i++)
+          for (size_t i = 0; i < nfiles; i++)
             {
               if (STREQ (files[i], "-"))
                 die (SORT_FAILURE, 0, _("when reading file names from stdin, "
@@ -4747,9 +4741,8 @@ main (int argc, char **argv)
   if (mergeonly)
     {
       struct sortfile *sortfiles = xcalloc (nfiles, sizeof *sortfiles);
-      size_t i;
 
-      for (i = 0; i < nfiles; ++i)
+      for (size_t i = 0; i < nfiles; ++i)
         sortfiles[i].name = files[i];
 
       merge (sortfiles, 0, nfiles, outfile);
index f5e930b1be54c26a8bf09544660f35b1c56acb78..dcaa580dc88b6e6e0d704a16192471a114eb6b04 100644 (file)
@@ -820,8 +820,7 @@ print_statfs (char *pformat, size_t prefix_len, unsigned int m,
            with glibc's statvfs implementation.  */
         uintmax_t fsid = 0;
         int words = sizeof statfsbuf->f_fsid / sizeof *p;
-        int i;
-        for (i = 0; i < words && i * sizeof *p < sizeof fsid; i++)
+        for (int i = 0; i < words && i * sizeof *p < sizeof fsid; i++)
           {
             uintmax_t u = p[words - 1 - i];
             fsid |= u << (i * CHAR_BIT * sizeof *p);
@@ -1577,7 +1576,6 @@ int
 main (int argc, char *argv[])
 {
   int c;
-  int i;
   bool fs = false;
   bool terse = false;
   char *format = NULL;
@@ -1651,7 +1649,7 @@ main (int argc, char *argv[])
       format2 = default_format (fs, terse, /* device= */ true);
     }
 
-  for (i = optind; i < argc; i++)
+  for (int i = optind; i < argc; i++)
     ok &= (fs
            ? do_statfs (argv[i], format)
            : do_stat (argv[i], format, format2));
index 5342a26a13cb47df22bd8da95c66b4bc9c6d15e3..c81519db5c51c46fb7ac4f97944a63a6f7b3bcd3 100644 (file)
@@ -275,9 +275,8 @@ static bool
 set_libstdbuf_options (void)
 {
   bool env_set = false;
-  size_t i;
 
-  for (i = 0; i < ARRAY_CARDINALITY (stdbuf); i++)
+  for (size_t i = 0; i < ARRAY_CARDINALITY (stdbuf); i++)
     {
       if (stdbuf[i].optarg)
         {
index 32007e6df70d2e20e4669a4b44c71ec0f2ef6c4c..528f167823ae161e21bfdd8d8461d34cf8c4ae94 100644 (file)
@@ -1461,9 +1461,8 @@ main (int argc, char **argv)
                    quotef (device_name));
 #ifdef TESTING
               {
-                size_t i;
                 printf ("new_mode: mode\n");
-                for (i = 0; i < sizeof (new_mode); i++)
+                for (size_t i = 0; i < sizeof (new_mode); i++)
                   printf ("0x%02x: 0x%02x\n",
                           *(((unsigned char *) &new_mode) + i),
                           *(((unsigned char *) &mode) + i));
@@ -2076,14 +2075,12 @@ display_speed (struct termios *mode, bool fancy)
 static void
 display_recoverable (struct termios *mode)
 {
-  size_t i;
-
   printf ("%lx:%lx:%lx:%lx",
           (unsigned long int) mode->c_iflag,
           (unsigned long int) mode->c_oflag,
           (unsigned long int) mode->c_cflag,
           (unsigned long int) mode->c_lflag);
-  for (i = 0; i < NCCS; ++i)
+  for (size_t i = 0; i < NCCS; ++i)
     printf (":%lx", (unsigned long int) mode->c_cc[i]);
   putchar ('\n');
 }
@@ -2226,9 +2223,7 @@ static struct speed_map const speeds[] =
 static speed_t _GL_ATTRIBUTE_PURE
 string_to_baud (const char *arg)
 {
-  int i;
-
-  for (i = 0; speeds[i].string != NULL; ++i)
+  for (int i = 0; speeds[i].string != NULL; ++i)
     if (STREQ (arg, speeds[i].string))
       return speeds[i].speed;
   return (speed_t) -1;
@@ -2237,9 +2232,7 @@ string_to_baud (const char *arg)
 static unsigned long int _GL_ATTRIBUTE_PURE
 baud_to_value (speed_t speed)
 {
-  int i;
-
-  for (i = 0; speeds[i].string != NULL; ++i)
+  for (int i = 0; speeds[i].string != NULL; ++i)
     if (speed == speeds[i].speed)
       return speeds[i].value;
   return 0;
index cae5d3705469c4d3ee67df2f677dc64ce636316b..412a9a8d89371c2e467eac736fb8568f54028a22 100644 (file)
--- a/src/sum.c
+++ b/src/sum.c
@@ -181,7 +181,6 @@ sysv_sum_file (const char *file, int print_name)
 
   while (1)
     {
-      size_t i;
       size_t bytes_read = safe_read (fd, buf, sizeof buf);
 
       if (bytes_read == 0)
@@ -195,7 +194,7 @@ sysv_sum_file (const char *file, int print_name)
           return false;
         }
 
-      for (i = 0; i < bytes_read; i++)
+      for (size_t i = 0; i < bytes_read; i++)
         s += buf[i];
       total_bytes += bytes_read;
     }
index d31df43e442fc541723d3fde3b5b6f1fd0d4ed04..bdc003e11f874adfb1e7c01079f99eecd258e747 100644 (file)
@@ -127,8 +127,7 @@ buf_init_from_stdin (Buf *x, char eol_byte)
 static void
 buf_free (Buf *x)
 {
-  size_t i;
-  for (i = 0; i < x->n_bufs; i++)
+  for (size_t i = 0; i < x->n_bufs; i++)
     free (x->p[i].start);
   obstack_free (OBS, NULL);
 }
@@ -222,8 +221,7 @@ static void
 print_line (FILE *out_stream, const Buf *x,
             const Line_ptr *bol, const Line_ptr *bol_next)
 {
-  size_t i;
-  for (i = bol->i; i <= bol_next->i; i++)
+  for (size_t i = bol->i; i <= bol_next->i; i++)
     {
       char *a = (i == bol->i ? bol->ptr : x->p[i].start);
       char *b = (i == bol_next->i ? bol_next->ptr : ONE_PAST_END (x, i));
index 4e06b7623a26b7168ee2f586fcd61bad9a8c6607..3c6c52d673008896a53db6fe976a818f675972f2 100644 (file)
--- a/src/tac.c
+++ b/src/tac.c
@@ -690,9 +690,8 @@ main (int argc, char **argv)
   xset_binary_mode (STDOUT_FILENO, O_BINARY);
 
   {
-    size_t i;
     ok = true;
-    for (i = 0; file[i]; ++i)
+    for (size_t i = 0; file[i]; ++i)
       ok &= tac_file (file[i]);
   }
 
index b8be1d21df7016acec4a15532717d422039ccdae..ce34886cde636ef9ec71594aae2a0dfee90d98b9 100644 (file)
@@ -1099,15 +1099,13 @@ recheck (struct File_spec *f, bool blocking)
 static bool
 any_live_files (const struct File_spec *f, size_t n_files)
 {
-  size_t i;
-
   /* In inotify mode, ignore may be set for files
      which may later be replaced with new files.
      So always consider files live in -F mode.  */
   if (reopen_inaccessible_files && follow_mode == Follow_name)
     return true;
 
-  for (i = 0; i < n_files; i++)
+  for (size_t i = 0; i < n_files; i++)
     {
       if (0 <= f[i].fd)
         return true;
@@ -1300,9 +1298,7 @@ tail_forever (struct File_spec *f, size_t n_files, double sleep_interval)
 static bool
 any_remote_file (const struct File_spec *f, size_t n_files)
 {
-  size_t i;
-
-  for (i = 0; i < n_files; i++)
+  for (size_t i = 0; i < n_files; i++)
     if (0 <= f[i].fd && f[i].remote)
       return true;
   return false;
@@ -1314,9 +1310,7 @@ any_remote_file (const struct File_spec *f, size_t n_files)
 static bool
 any_non_remote_file (const struct File_spec *f, size_t n_files)
 {
-  size_t i;
-
-  for (i = 0; i < n_files; i++)
+  for (size_t i = 0; i < n_files; i++)
     if (0 <= f[i].fd && ! f[i].remote)
       return true;
   return false;
@@ -1330,10 +1324,8 @@ any_non_remote_file (const struct File_spec *f, size_t n_files)
 static bool
 any_symlinks (const struct File_spec *f, size_t n_files)
 {
-  size_t i;
-
   struct stat st;
-  for (i = 0; i < n_files; i++)
+  for (size_t i = 0; i < n_files; i++)
     if (lstat (f[i].name, &st) == 0 && S_ISLNK (st.st_mode))
       return true;
   return false;
@@ -1347,9 +1339,7 @@ any_symlinks (const struct File_spec *f, size_t n_files)
 static bool
 any_non_regular (const struct File_spec *f, size_t n_files)
 {
-  size_t i;
-
-  for (i = 0; i < n_files; i++)
+  for (size_t i = 0; i < n_files; i++)
     if (0 <= f[i].fd && ! S_ISREG (f[i].mode))
       return true;
   return false;
@@ -1361,9 +1351,7 @@ any_non_regular (const struct File_spec *f, size_t n_files)
 static bool
 tailable_stdin (const struct File_spec *f, size_t n_files)
 {
-  size_t i;
-
-  for (i = 0; i < n_files; i++)
+  for (size_t i = 0; i < n_files; i++)
     if (!f[i].ignore && STREQ (f[i].name, "-"))
       return true;
   return false;
@@ -2288,8 +2276,7 @@ ignore_fifo_and_pipe (struct File_spec *f, size_t n_files)
      ignore any "-" operand that corresponds to a pipe or FIFO.  */
   size_t n_viable = 0;
 
-  size_t i;
-  for (i = 0; i < n_files; i++)
+  for (size_t i = 0; i < n_files; i++)
     {
       bool is_a_fifo_or_pipe =
         (STREQ (f[i].name, "-")
index 0c770d7a9bf3090bb900b30ea8c50880e637522a..333aed04d06a4a4ba8036562d81acfc08a19634d 100644 (file)
--- a/src/tr.c
+++ b/src/tr.c
@@ -1167,7 +1167,6 @@ validate_case_classes (struct Spec_list *s1, struct Spec_list *s2)
 {
   size_t n_upper = 0;
   size_t n_lower = 0;
-  unsigned int i;
   int c1 = 0;
   int c2 = 0;
   count old_s1_len = s1->length;
@@ -1180,7 +1179,7 @@ validate_case_classes (struct Spec_list *s1, struct Spec_list *s2)
   if (!s2->has_char_class)
     return;
 
-  for (i = 0; i < N_CHARS; i++)
+  for (int i = 0; i < N_CHARS; i++)
     {
       if (isupper (i))
         n_upper++;
index 8a656c3d0bc201081367734d1a88ff160d0704b0..299a9665f68f49995f9abd69c7f6eb6abe9a3637 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -599,9 +599,7 @@ get_input_fstatus (size_t nfiles, char *const *file)
     fstatus[0].failed = 1;
   else
     {
-      size_t i;
-
-      for (i = 0; i < nfiles; i++)
+      for (size_t i = 0; i < nfiles; i++)
         fstatus[i].failed = (! file[i] || STREQ (file[i], "-")
                              ? fstat (STDIN_FILENO, &fstatus[i].st)
                              : stat (file[i], &fstatus[i].st));
@@ -623,9 +621,8 @@ compute_number_width (size_t nfiles, struct fstatus const *fstatus)
     {
       int minimum_width = 1;
       uintmax_t regular_total = 0;
-      size_t i;
 
-      for (i = 0; i < nfiles; i++)
+      for (size_t i = 0; i < nfiles; i++)
         if (! fstatus[i].failed)
           {
             if (S_ISREG (fstatus[i].st.st_mode))
@@ -774,9 +771,8 @@ main (int argc, char **argv)
   fstatus = get_input_fstatus (nfiles, files);
   number_width = compute_number_width (nfiles, fstatus);
 
-  int i;
   ok = true;
-  for (i = 0; /* */; i++)
+  for (int i = 0; /* */; i++)
     {
       bool skip_file = false;
       enum argv_iter_err ai_err;