mirror of
https://github.com/coreutils/coreutils.git
synced 2024-12-20 07:17:31 +08:00
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.
This commit is contained in:
parent
5591f19e9c
commit
da7a704cd3
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 == '-')
|
||||
{
|
||||
|
4
src/dd.c
4
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;
|
||||
|
4
src/df.c
4
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,
|
||||
|
2
src/du.c
2
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:",
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -728,7 +728,7 @@ get_prefix (FILE *f)
|
||||
static int
|
||||
get_space (FILE *f, int c)
|
||||
{
|
||||
for (;;)
|
||||
while (true)
|
||||
{
|
||||
if (c == ' ')
|
||||
in_column++;
|
||||
|
2
src/ls.c
2
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,
|
||||
|
2
src/od.c
2
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;
|
||||
|
4
src/pr.c
4
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);
|
||||
|
||||
|
@ -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)
|
||||
|
16
src/sort.c
16
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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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")))
|
||||
|
8
src/tr.c
8
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)
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user