From: Jim Meyering Date: Sat, 1 May 2010 12:24:35 +0000 (+0200) Subject: maint: replace each "for (;;)" with "while (true)" X-Git-Tag: v8.6~150 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=da7a704cd36e1d2015d14247e5139fb1999b2211;p=platform%2Fupstream%2Fcoreutils.git maint: replace each "for (;;)" with "while (true)" Run this command: git ls-files | grep '\.[ch]$' \ | xargs perl -pi -e 's/for \(;;\)/while (true)/g' ...except for randint.c, which does not include stdbool.h. In that case, use "while (1)". * gl/lib/randint.c (randint_genmax): Use "while (1)" for infloops. * src/cat.c (simple_cat, cat): Use "while (true)" for infloops. * gl/lib/randread.c (readsource, readisaac): Likewise. * src/copy.c (copy_reg): Likewise. * src/csplit.c (record_line_starts, process_regexp): Likewise. * src/cut.c (set_fields): Likewise. * src/dd.c (iread, parse_symbols): Likewise. * src/df.c (find_mount_point, main): Likewise. * src/du.c (main): Likewise. * src/expand.c (expand): Likewise. * src/factor.c (factor_using_division, do_stdin): Likewise. * src/fmt.c (get_space): Likewise. * src/ls.c (decode_switches): Likewise. * src/od.c (main): Likewise. * src/pr.c (main, read_line): Likewise. * src/shred.c (dopass, genpattern): Likewise. * src/sort.c (initbuf, fillbuf, getmonth, keycompare): Likewise. * src/split.c (bytes_split, lines_split): Likewise. * src/tac.c (tac_seekable): Likewise. * src/test.c (and, or): Likewise. * src/tr.c (squeeze_filter, main): Likewise. * src/tsort.c (search_item): Likewise. * src/unexpand.c (unexpand): Likewise. * src/uniq.c (main): Likewise. * src/yes.c (main): Likewise. --- diff --git a/gl/lib/randint.c b/gl/lib/randint.c index cb39221..f3de3fc 100644 --- a/gl/lib/randint.c +++ b/gl/lib/randint.c @@ -125,7 +125,7 @@ randint_genmax (struct randint_source *s, randint genmax) randint randmax = s->randmax; randint choices = genmax + 1; - for (;;) + while (1) { if (randmax < genmax) { diff --git a/gl/lib/randread.c b/gl/lib/randread.c index 65e9d63..94b9928 100644 --- a/gl/lib/randread.c +++ b/gl/lib/randread.c @@ -199,7 +199,7 @@ randread_set_handler_arg (struct randread_source *s, void const *handler_arg) static void readsource (struct randread_source *s, unsigned char *p, size_t size) { - for (;;) + while (true) { size_t inbytes = fread (p, sizeof *p, size, s->source); int fread_errno = errno; @@ -221,7 +221,7 @@ readisaac (struct isaac *isaac, unsigned char *p, size_t size) { size_t inbytes = isaac->buffered; - for (;;) + while (true) { if (size <= inbytes) { diff --git a/src/cat.c b/src/cat.c index 8740e0e..eebfb97 100644 --- a/src/cat.c +++ b/src/cat.c @@ -160,7 +160,7 @@ simple_cat ( /* Loop until the end of the file. */ - for (;;) + while (true) { /* Read a block of input. */ @@ -269,7 +269,7 @@ cat ( bpout = outbuf; - for (;;) + while (true) { do { @@ -424,7 +424,7 @@ cat ( scan for chars that need conversion. */ if (show_nonprinting) { - for (;;) + while (true) { if (ch >= 32) { @@ -475,7 +475,7 @@ cat ( else { /* Not quoting, neither of -v, -e, or -t specified. */ - for (;;) + while (true) { if (ch == '\t' && show_tabs) { diff --git a/src/copy.c b/src/copy.c index c16cef6..78c97cc 100644 --- a/src/copy.c +++ b/src/copy.c @@ -707,7 +707,7 @@ copy_reg (char const *src_name, char const *dst_name, buf_alloc = xmalloc (buf_size + buf_alignment_slop); buf = ptr_align (buf_alloc, buf_alignment); - for (;;) + while (true) { word *wp = NULL; diff --git a/src/csplit.c b/src/csplit.c index 8cefdf3..40baba8 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -342,7 +342,7 @@ record_line_starts (struct buffer_record *b) line_start = b->buffer; bytes_left = b->bytes_used; - for (;;) + while (true) { line_end = memchr (line_start, '\n', bytes_left); if (line_end == NULL) @@ -773,7 +773,7 @@ process_regexp (struct control *p, uintmax_t repetition) if (p->offset >= 0) { - for (;;) + while (true) { line = find_line (++current_line); if (line == NULL) @@ -813,7 +813,7 @@ process_regexp (struct control *p, uintmax_t repetition) else { /* Buffer the lines. */ - for (;;) + while (true) { line = find_line (++current_line); if (line == NULL) diff --git a/src/cut.c b/src/cut.c index 087981c..8c93c89 100644 --- a/src/cut.c +++ b/src/cut.c @@ -358,7 +358,7 @@ set_fields (const char *fieldstr) /* Collect and store in RP the range end points. It also sets EOL_RANGE_START if appropriate. */ - for (;;) + while (true) { if (*fieldstr == '-') { diff --git a/src/dd.c b/src/dd.c index 1d8cfe0..30d3d28 100644 --- a/src/dd.c +++ b/src/dd.c @@ -796,7 +796,7 @@ process_signals (void) static ssize_t iread (int fd, char *buf, size_t size) { - for (;;) + while (true) { ssize_t nread; process_signals (); @@ -926,7 +926,7 @@ parse_symbols (char const *str, struct symbol_value const *table, { int value = 0; - for (;;) + while (true) { char const *strcomma = strchr (str, ','); struct symbol_value const *entry; diff --git a/src/df.c b/src/df.c index b862879..40011f8 100644 --- a/src/df.c +++ b/src/df.c @@ -574,7 +574,7 @@ find_mount_point (const char *file, const struct stat *file_stat) /* Now walk up FILE's parents until we find another file system or /, chdiring as we go. LAST_STAT holds stat information for the last place we visited. */ - for (;;) + while (true) { struct stat st; if (stat ("..", &st) < 0) @@ -873,7 +873,7 @@ main (int argc, char **argv) print_grand_total = false; grand_fsu.fsu_blocksize = 1; - for (;;) + while (true) { int oi = -1; int c = getopt_long (argc, argv, "aB:iF:hHklmPTt:vx:", long_options, diff --git a/src/du.c b/src/du.c index 5d83dc6..2704f0f 100644 --- a/src/du.c +++ b/src/du.c @@ -690,7 +690,7 @@ main (int argc, char **argv) human_options (getenv ("DU_BLOCK_SIZE"), &human_output_opts, &output_block_size); - for (;;) + while (true) { int oi = -1; int c = getopt_long (argc, argv, "0abd:chHklmsxB:DLPSX:", diff --git a/src/expand.c b/src/expand.c index fa1fdfe..6a04d36 100644 --- a/src/expand.c +++ b/src/expand.c @@ -270,7 +270,7 @@ expand (void) if (!fp) return; - for (;;) + while (true) { /* Input character, or EOF. */ int c; @@ -306,7 +306,7 @@ expand (void) if (tab_size) next_tab_column = column + (tab_size - column % tab_size); else - for (;;) + while (true) if (tab_index == first_free_tab) { next_tab_column = column + 1; diff --git a/src/factor.c b/src/factor.c index 80aa3e6..7291d28 100644 --- a/src/factor.c +++ b/src/factor.c @@ -107,7 +107,7 @@ factor_using_division (mpz_t t, unsigned int limit) --f; } - for (;;) + while (true) { mpz_tdiv_qr_ui (q, r, t, 3); if (mpz_cmp_ui (r, 0) != 0) @@ -116,7 +116,7 @@ factor_using_division (mpz_t t, unsigned int limit) emit_ul_factor (3); } - for (;;) + while (true) { mpz_tdiv_qr_ui (q, r, t, 5); if (mpz_cmp_ui (r, 0) != 0) @@ -516,7 +516,7 @@ do_stdin (void) init_tokenbuffer (&tokenbuffer); - for (;;) + while (true) { size_t token_length = readtoken (stdin, DELIM, sizeof (DELIM) - 1, &tokenbuffer); diff --git a/src/fmt.c b/src/fmt.c index 86b83ee..1a268ee 100644 --- a/src/fmt.c +++ b/src/fmt.c @@ -728,7 +728,7 @@ get_prefix (FILE *f) static int get_space (FILE *f, int c) { - for (;;) + while (true) { if (c == ' ') in_column++; diff --git a/src/ls.c b/src/ls.c index aa9fb6c..3c04438 100644 --- a/src/ls.c +++ b/src/ls.c @@ -1635,7 +1635,7 @@ decode_switches (int argc, char **argv) } } - for (;;) + while (true) { int oi = -1; int c = getopt_long (argc, argv, diff --git a/src/od.c b/src/od.c index 4508725..cde3bf9 100644 --- a/src/od.c +++ b/src/od.c @@ -1564,7 +1564,7 @@ main (int argc, char **argv) address_pad_len = 7; flag_dump_strings = false; - for (;;) + while (true) { uintmax_t tmp; enum strtol_error s_err; diff --git a/src/pr.c b/src/pr.c index a36b657..9d4c90f 100644 --- a/src/pr.c +++ b/src/pr.c @@ -876,7 +876,7 @@ main (int argc, char **argv) ? xmalloc ((argc - 1) * sizeof (char *)) : NULL); - for (;;) + while (true) { int oi = -1; int c = getopt_long (argc, argv, short_options, long_options, &oi); @@ -2526,7 +2526,7 @@ read_line (COLUMN *p) print_clump (p, chars, clump_buff); - for (;;) + while (true) { c = getc (p->fp); diff --git a/src/shred.c b/src/shred.c index 9385843..659ac5a 100644 --- a/src/shred.c +++ b/src/shred.c @@ -417,7 +417,7 @@ dopass (int fd, char const *qname, off_t *sizep, int type, } offset = 0; - for (;;) + while (true) { /* How much to write this time? */ lim = sizeof r; @@ -664,7 +664,7 @@ genpattern (int *dest, size_t num, struct randint_source *s) d = dest; /* Destination for generated pass list */ n = num; /* Passes remaining to fill */ - for (;;) + while (true) { k = *p++; /* Block descriptor word */ if (!k) diff --git a/src/sort.c b/src/sort.c index e6cc2c2..41194ba 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1453,7 +1453,7 @@ initbuf (struct buffer *buf, size_t line_bytes, size_t alloc) size cannot be allocated, repeatedly halve it until allocation succeeds. The smaller allocation may hurt overall performance, but that's better than failing. */ - for (;;) + while (true) { alloc += sizeof (struct line) - alloc % sizeof (struct line); buf->buf = malloc (alloc); @@ -1646,7 +1646,7 @@ fillbuf (struct buffer *buf, FILE *fp, char const *file) buf->nlines = 0; } - for (;;) + while (true) { char *ptr = buf->buf + buf->used; struct line *linelim = buffer_linelim (buf); @@ -1918,7 +1918,7 @@ getmonth (char const *month, size_t len, char const **ea) size_t hi = MONTHS_PER_YEAR; char const *monthlim = month + len; - for (;;) + while (true) { if (month == monthlim) return 0; @@ -2340,7 +2340,7 @@ keycompare (const struct line *a, const struct line *b, bool show_debug) int diff; - for (;;) + while (true) { char const *translate = key->translate; bool const *ignore = key->ignore; @@ -2445,7 +2445,7 @@ keycompare (const struct line *a, const struct line *b, bool show_debug) #define CMP_WITH_IGNORE(A, B) \ do \ { \ - for (;;) \ + while (true) \ { \ while (texta < lima && ignore[to_uchar (*texta)]) \ ++texta; \ @@ -2960,7 +2960,7 @@ mergelines (struct line *t, struct line const *lo, size_t nlo, struct line const *hi, size_t nhi) { - for (;;) + while (true) if (compare (lo - 1, hi - 1, false) <= 0) { *--t = *--lo; @@ -3210,7 +3210,7 @@ merge (struct sortfile *files, size_t ntemps, size_t nfiles, try to merge into the output, and then merge as much as we can into a temp file if we can't. Repeat. */ - for (;;) + while (true) { /* Merge directly into the output file if possible. */ FILE **fps; @@ -3648,7 +3648,7 @@ main (int argc, char **argv) files = xnmalloc (argc, sizeof *files); - for (;;) + while (true) { /* Parse an operand as a file after "--" was seen; or if pedantic and a file was seen, unless the POSIX version diff --git a/src/split.c b/src/split.c index 5bd9ebb..5be7207 100644 --- a/src/split.c +++ b/src/split.c @@ -233,7 +233,7 @@ bytes_split (uintmax_t n_bytes, char *buf, size_t bufsize) error (EXIT_FAILURE, errno, "%s", infile); bp_out = buf; to_read = n_read; - for (;;) + while (true) { if (to_read < to_write) { @@ -278,7 +278,7 @@ lines_split (uintmax_t n_lines, char *buf, size_t bufsize) bp = bp_out = buf; eob = bp + n_read; *eob = '\n'; - for (;;) + while (true) { bp = memchr (bp, '\n', eob - bp + 1); if (bp == eob) diff --git a/src/tac.c b/src/tac.c index c7af6c1..cec9736 100644 --- a/src/tac.c +++ b/src/tac.c @@ -245,7 +245,7 @@ tac_seekable (int input_fd, const char *file) if (sentinel_length) match_start -= match_length1; - for (;;) + while (true) { /* Search backward from `match_start' - 1 to `G_buffer' for a match with `separator'; for speed, use strncmp if `separator' contains no diff --git a/src/test.c b/src/test.c index 59d8b4e..e2247d2 100644 --- a/src/test.c +++ b/src/test.c @@ -511,7 +511,7 @@ and (void) { bool value = true; - for (;;) + while (true) { value &= term (); if (! (pos < argc && STREQ (argv[pos], "-a"))) @@ -530,7 +530,7 @@ or (void) { bool value = false; - for (;;) + while (true) { value |= and (); if (! (pos < argc && STREQ (argv[pos], "-o"))) diff --git a/src/tr.c b/src/tr.c index c7510c3..3722b4d 100644 --- a/src/tr.c +++ b/src/tr.c @@ -1489,7 +1489,7 @@ squeeze_filter (char *buf, size_t size, size_t (*reader) (char *, size_t)) size_t i = 0; size_t nr = 0; - for (;;) + while (true) { size_t begin; @@ -1763,7 +1763,7 @@ main (int argc, char **argv) { set_initialize (s1, complement, in_delete_set); - for (;;) + while (true) { size_t nr = read_and_delete (io_buf, sizeof io_buf); if (nr == 0) @@ -1817,7 +1817,7 @@ main (int argc, char **argv) xlate[i] = i; s1->state = BEGIN_STATE; s2->state = BEGIN_STATE; - for (;;) + while (true) { /* When the previous pair identified case-converting classes, advance S1 and S2 so that each points to the following @@ -1877,7 +1877,7 @@ main (int argc, char **argv) } else { - for (;;) + while (true) { size_t bytes_read = read_and_xlate (io_buf, sizeof io_buf); if (bytes_read == 0) diff --git a/src/tsort.c b/src/tsort.c index 3746f9e..b5c187b 100644 --- a/src/tsort.c +++ b/src/tsort.c @@ -136,7 +136,7 @@ search_item (struct item *root, const char *str) t = root; s = p = root->right; - for (;;) + while (true) { /* A2. Compare. */ a = strcmp (str, p->str); diff --git a/src/unexpand.c b/src/unexpand.c index dfe9305..a3bb4a8 100644 --- a/src/unexpand.c +++ b/src/unexpand.c @@ -299,7 +299,7 @@ unexpand (void) allocate MAX_COLUMN_WIDTH bytes to store the blanks. */ pending_blank = xmalloc (max_column_width); - for (;;) + while (true) { /* Input character, or EOF. */ int c; @@ -351,7 +351,7 @@ unexpand (void) next_tab_column = column + (tab_size - column % tab_size); else - for (;;) + while (true) if (tab_index == first_free_tab) { convert = false; diff --git a/src/uniq.c b/src/uniq.c index 9a72857..1f59469 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -434,7 +434,7 @@ main (int argc, char **argv) countmode = count_none; delimit_groups = DM_NONE; - for (;;) + while (true) { /* Parse an operand with leading "+" as a file after "--" was seen; or if pedantic and a file was seen; or if not diff --git a/src/yes.c b/src/yes.c index 9c79101..2548018 100644 --- a/src/yes.c +++ b/src/yes.c @@ -78,7 +78,7 @@ main (int argc, char **argv) argv[argc++] = bad_cast ("y"); } - for (;;) + while (true) { int i; for (i = optind; i < argc; i++)