add usage function
call parse_long_options
dcl, set program_name
- do FCLOSE/error checking
+ do fclose/error checking
*/
/* asa.c - interpret ASA carriage control characters
static void
form_feed ()
{
- PUTCHAR ('\f');
+ putchar ('\f');
}
static void
new_line ()
{
- PUTCHAR ('\n');
+ putchar ('\n');
}
static void
if (ch != ' ')
{
if (printed)
- PUTCHAR ('\b');
- PUTCHAR (ch);
+ putchar ('\b');
+ putchar (ch);
printed = 1;
}
}
}
if (!printed)
- PUTCHAR (' ');
+ putchar (' ');
}
for (j = 0; j < line_num; j++)
free (line_buffer[j].chr);
line_num = 0;
- PUTCHAR ('\n');
+ putchar ('\n');
}
static size_t
else
{
copy_file (fp);
- FCLOSE (fp);
+ fclose (fp);
}
}
}
}
}
- while ((bytes_read = FREAD (buf, 1, BUFLEN, fp)) > 0)
+ while ((bytes_read = fread (buf, 1, BUFLEN, fp)) > 0)
{
unsigned char *cp = buf;
crc = (crc << 8) ^ crctab[((crc >> 24) ^ *(cp++)) & 0xFF];
}
- if (FERROR (fp))
+ if (ferror (fp))
{
error (0, errno, "%s", file);
if (!STREQ (file, "-"))
- FCLOSE (fp);
+ fclose (fp);
return -1;
}
- if (!STREQ (file, "-") && FCLOSE (fp) == EOF)
+ if (!STREQ (file, "-") && fclose (fp) == EOF)
{
error (0, errno, "%s", file);
return -1;
printf ("%lu %ld", crc, length);
if (print_name)
printf (" %s", file);
- PUTCHAR ('\n');
+ putchar ('\n');
return 0;
}
errors = 1;
}
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
return;
/* Skip the tab stop for case 1, if we are printing case 1. */
if (only_file_1)
- PUTC ('\t', stream);
+ putc ('\t', stream);
break;
case 3:
return;
/* Skip the tab stop for case 1, if we are printing case 1. */
if (only_file_1)
- PUTC ('\t', stream);
+ putc ('\t', stream);
/* Skip the tab stop for case 2, if we are printing case 2. */
if (only_file_2)
- PUTC ('\t', stream);
+ putc ('\t', stream);
break;
}
- FWRITE (line->buffer, sizeof (char), line->length, stream);
- PUTC ('\n', stream);
+ fwrite (line->buffer, sizeof (char), line->length, stream);
+ putc ('\n', stream);
}
/* Compare INFILES[0] and INFILES[1].
for (i = 0; i < 2; i++)
{
free (lb1[i].buffer);
- if (FERROR (streams[i]) || fclose (streams[i]) == EOF)
+ if (ferror (streams[i]) || fclose (streams[i]) == EOF)
{
error (0, errno, "%s", infiles[i]);
ret = 1;
}
}
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
{
error (0, errno, _("write error"));
ret = 1;
{
if (output_stream)
{
- if (FERROR (output_stream) || fclose (output_stream) == EOF)
+ if (ferror (output_stream) || fclose (output_stream) == EOF)
{
error (0, errno, _("write error for `%s'"), output_filename);
output_stream = NULL;
static void
save_line_to_file (const struct cstring *line)
{
- FWRITE (line->str, sizeof (char), line->len, output_stream);
+ fwrite (line->str, sizeof (char), line->len, output_stream);
bytes_written += line->len;
}
cleanup_fatal ();
}
- if (!suppress_count && (FERROR (stdout) || fclose (stdout) == EOF))
+ if (!suppress_count && (ferror (stdout) || fclose (stdout) == EOF))
error (EXIT_FAILURE, errno, _("write error"));
exit (EXIT_SUCCESS);
for (;;)
{
- register int c = GETC (stream);
+ register int c = getc (stream);
/* We always want at least one char left in the buffer, since we
always (unless we get an error while reading the first char)
assert (*n - nchars_avail == read_pos - *lineptr);
}
- if (FEOF (stream) || ferror (stream))
+ if (feof (stream) || ferror (stream))
{
/* Return partial line, if any. */
if (read_pos == *lineptr)
{
register int c; /* Each character from the file. */
- c = GETC (stream);
+ c = getc (stream);
if (c == '\n')
{
- PUTCHAR ('\n');
+ putchar ('\n');
byte_idx = 0;
}
else if (c == EOF)
{
if (byte_idx > 0)
- PUTCHAR ('\n');
+ putchar ('\n');
break;
}
else
++byte_idx;
if (print_kth (byte_idx))
{
- PUTCHAR (c);
+ putchar (c);
}
}
}
found_any_selected_field = 0;
field_idx = 1;
- c = GETC (stream);
+ c = getc (stream);
empty_input = (c == EOF);
if (c != EOF)
ungetc (c, stream);
}
else
{
- FWRITE (field_1_buffer, sizeof (char), len, stdout);
+ fwrite (field_1_buffer, sizeof (char), len, stdout);
/* Make sure the output line is newline terminated. */
if (field_1_buffer[len - 1] != '\n')
- PUTCHAR ('\n');
+ putchar ('\n');
}
continue;
}
if (print_kth (1))
{
/* Print the field, but not the trailing delimiter. */
- FWRITE (field_1_buffer, sizeof (char), len - 1, stdout);
+ fwrite (field_1_buffer, sizeof (char), len - 1, stdout);
found_any_selected_field = 1;
}
++field_idx;
if (found_any_selected_field)
{
/* FIXME: use output delimiter here */
- PUTCHAR (delim);
+ putchar (delim);
}
found_any_selected_field = 1;
- while ((c = GETC (stream)) != delim && c != '\n' && c != EOF)
+ while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
{
- PUTCHAR (c);
+ putchar (c);
}
}
else
{
- while ((c = GETC (stream)) != delim && c != '\n' && c != EOF)
+ while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
{
/* Empty. */
}
if (c == '\n')
{
- c = GETC (stream);
+ c = getc (stream);
if (c != EOF)
{
ungetc (c, stream);
{
if (found_any_selected_field
|| (!empty_input && !(suppress_non_delimited && field_idx == 1)))
- PUTCHAR ('\n');
+ putchar ('\n');
if (c == EOF)
break;
field_idx = 1;
cut_stream (stream);
- if (FERROR (stream))
+ if (ferror (stream))
{
error (0, errno, "%s", file);
return 1;
}
if (STREQ (file, "-"))
- CLEARERR (stream); /* Also clear EOF. */
- else if (FCLOSE (stream) == EOF)
+ clearerr (stream); /* Also clear EOF. */
+ else if (fclose (stream) == EOF)
{
error (0, errno, "%s", file);
return 1;
for (; optind < argc; optind++)
exit_status |= cut_file (argv[optind]);
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
{
error (0, errno, "-");
exit_status = 1;
}
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
if (fp)
{
- if (FERROR (fp))
+ if (ferror (fp))
{
error (0, errno, "%s", prev_file);
exit_status = 1;
}
if (fp == stdin)
- CLEARERR (fp); /* Also clear EOF. */
- else if (FCLOSE (fp) == EOF)
+ clearerr (fp); /* Also clear EOF. */
+ else if (fclose (fp) == EOF)
{
error (0, errno, "%s", prev_file);
exit_status = 1;
return;
for (;;)
{
- c = GETC (fp);
+ c = getc (fp);
if (c == EOF)
{
fp = next_file (fp);
if (c == '\n')
{
- PUTCHAR (c);
+ putchar (c);
tab_index = 0;
column = 0;
convert = 1;
}
while (column < next_tab_column)
{
- PUTCHAR (' ');
+ putchar (' ');
++column;
}
}
convert = 0;
}
}
- PUTCHAR (c);
+ putchar (c);
}
}
}
expand ();
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
if (in_stream != NULL)
{
fmt (in_stream);
- if (FCLOSE (in_stream) == EOF)
+ if (fclose (in_stream) == EOF)
error (EXIT_FAILURE, errno, file);
}
else
}
}
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (EXIT_SUCCESS);
next_char = EOF;
return FALSE;
}
- PUTCHAR ('\n');
+ putchar ('\n');
c = get_prefix (f);
}
{
put_space (next_prefix_indent);
for (s = prefix; out_column != in_column && *s; out_column++)
- PUTCHAR (*s++);
+ putchar (*s++);
put_space (in_column - out_column);
}
while (c != '\n' && c != EOF)
{
- PUTCHAR (c);
- c = GETC (f);
+ putchar (c);
+ c = getc (f);
}
return c;
}
if (wptr == end_of_parabuf)
flush_paragraph ();
*wptr++ = c;
- c = GETC (f);
+ c = getc (f);
}
while (c != EOF && !ISSPACE (c));
in_column += word_limit->length = wptr - word_limit->text;
register const char *p;
in_column = 0;
- c = get_space (f, GETC (f));
+ c = get_space (f, getc (f));
if (prefix_length == 0)
next_prefix_indent = prefix_lead_space < in_column ?
prefix_lead_space : in_column;
if (c != *p)
return c;
in_column++;
- c = GETC (f);
+ c = getc (f);
}
c = get_space (f, c);
}
}
else
return c;
- c = GETC (f);
+ c = getc (f);
}
}
}
put_word (w);
last_line_length = out_column;
- PUTCHAR ('\n');
+ putchar ('\n');
}
/* Output to stdout the word W. */
s = w->text;
for (n = w->length; n != 0; n--)
- PUTCHAR (*s++);
+ putchar (*s++);
out_column += w->length;
}
if (out_column + 1 < tab_target)
while (out_column < tab_target)
{
- PUTCHAR ('\t');
+ putchar ('\t');
out_column = (out_column / TABWIDTH + 1) * TABWIDTH;
}
}
while (out_column < space_target)
{
- PUTCHAR (' ');
+ putchar (' ');
out_column++;
}
}
return 1;
}
- while ((c = GETC (istream)) != EOF)
+ while ((c = getc (istream)) != EOF)
{
if (offset_out + 1 >= allocated_out)
{
if (c == '\n')
{
line_out[offset_out++] = c;
- FWRITE (line_out, sizeof (char), (size_t) offset_out, stdout);
+ fwrite (line_out, sizeof (char), (size_t) offset_out, stdout);
column = offset_out = 0;
continue;
}
/* Found a blank. Don't output the part after it. */
logical_end++;
- FWRITE (line_out, sizeof (char), (size_t) logical_end,
+ fwrite (line_out, sizeof (char), (size_t) logical_end,
stdout);
- PUTCHAR ('\n');
+ putchar ('\n');
/* Move the remainder to the beginning of the next line.
The areas being copied here might overlap. */
memmove (line_out, line_out + logical_end,
}
}
line_out[offset_out++] = '\n';
- FWRITE (line_out, sizeof (char), (size_t) offset_out, stdout);
+ fwrite (line_out, sizeof (char), (size_t) offset_out, stdout);
column = offset_out = 0;
goto rescan;
}
}
if (offset_out)
- FWRITE (line_out, sizeof (char), (size_t) offset_out, stdout);
+ fwrite (line_out, sizeof (char), (size_t) offset_out, stdout);
- if (FERROR (istream))
+ if (ferror (istream))
{
error (0, errno, "%s", filename);
if (!STREQ (filename, "-"))
- FCLOSE (istream);
+ fclose (istream);
return 1;
}
- if (!STREQ (filename, "-") && FCLOSE (istream) == EOF)
+ if (!STREQ (filename, "-") && fclose (istream) == EOF)
{
error (0, errno, "%s", filename);
return 1;
}
- if (FERROR (stdout))
+ if (ferror (stdout))
{
error (0, errno, _("write error"));
return 1;
for (i = optind; i < argc; i++)
errs |= fold_file (argv[i], width);
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (FCLOSE (stdout) == EOF)
+ if (fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (errs == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
break;
if (bytes_read > bytes_to_write)
bytes_read = bytes_to_write;
- if (FWRITE (buffer, 1, bytes_read, stdout) == 0)
+ if (fwrite (buffer, 1, bytes_read, stdout) == 0)
error (EXIT_FAILURE, errno, _("write error"));
bytes_to_write -= bytes_read;
}
while (bytes_to_write < bytes_read)
if (buffer[bytes_to_write++] == '\n' && --lines_to_write == 0)
break;
- if (FWRITE (buffer, 1, bytes_to_write, stdout) == 0)
+ if (fwrite (buffer, 1, bytes_to_write, stdout) == 0)
error (EXIT_FAILURE, errno, _("write error"));
}
return 0;
if (have_read_stdin && close (0) < 0)
error (EXIT_FAILURE, errno, "-");
- if (FCLOSE (stdout) == EOF)
+ if (fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
int c, i;
char *ptr;
- if (FEOF (fp))
+ if (feof (fp))
return 0;
ptr = xmalloc (linesize);
- for (i = 0; (c = GETC (fp)) != EOF && c != '\n'; ++i)
+ for (i = 0; (c = getc (fp)) != EOF && c != '\n'; ++i)
{
if (i == linesize)
{
{
len = line->fields[n].len;
if (len)
- FWRITE (line->fields[n].beg, 1, len, stdout);
+ fwrite (line->fields[n].beg, 1, len, stdout);
else if (empty_filler)
fputs (empty_filler, stdout);
}
o = o->next;
if (o == NULL)
break;
- PUTCHAR (tab ? tab : ' ');
+ putchar (tab ? tab : ' ');
}
- PUTCHAR ('\n');
+ putchar ('\n');
}
else
{
prfield (join_field_1, line1);
for (i = 0; i < join_field_1 && i < line1->nfields; ++i)
{
- PUTCHAR (tab ? tab : ' ');
+ putchar (tab ? tab : ' ');
prfield (i, line1);
}
for (i = join_field_1 + 1; i < line1->nfields; ++i)
{
- PUTCHAR (tab ? tab : ' ');
+ putchar (tab ? tab : ' ');
prfield (i, line1);
}
for (i = 0; i < join_field_2 && i < line2->nfields; ++i)
{
- PUTCHAR (tab ? tab : ' ');
+ putchar (tab ? tab : ' ');
prfield (i, line2);
}
for (i = join_field_2 + 1; i < line2->nfields; ++i)
{
- PUTCHAR (tab ? tab : ' ');
+ putchar (tab ? tab : ' ');
prfield (i, line2);
}
- PUTCHAR ('\n');
+ putchar ('\n');
}
}
error (EXIT_FAILURE, errno, _("both files cannot be standard input"));
join (fp1, fp2);
- if (fp1 != stdin && FCLOSE (fp1) == EOF)
+ if (fp1 != stdin && fclose (fp1) == EOF)
error (EXIT_FAILURE, errno, "%s", names[0]);
- if (fp2 != stdin && FCLOSE (fp2) == EOF)
+ if (fp2 != stdin && fclose (fp2) == EOF)
error (EXIT_FAILURE, errno, "%s", names[1]);
- if ((fp1 == stdin || fp2 == stdin) && FCLOSE (stdin) == EOF)
+ if ((fp1 == stdin || fp2 == stdin) && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (EXIT_SUCCESS);
{
error (0, errno, "%s", filename);
if (fp != stdin)
- FCLOSE (fp);
+ fclose (fp);
return 1;
}
- if (fp != stdin && FCLOSE (fp) == EOF)
+ if (fp != stdin && fclose (fp) == EOF)
{
error (0, errno, "%s", filename);
return 1;
if (!status_only)
{
printf (_("%s: FAILED open or read\n"), filename);
- FFLUSH (stdout);
+ fflush (stdout);
}
}
else
{
printf ("%s: %s\n", filename,
(cnt != 16 ? _("FAILED") : _("OK")));
- FFLUSH (stdout);
+ fflush (stdout);
}
}
}
}
- while (!FEOF (checkfile_stream) && !ferror (checkfile_stream));
+ while (!feof (checkfile_stream) && !ferror (checkfile_stream));
if (line)
free (line);
- if (FERROR (checkfile_stream))
+ if (ferror (checkfile_stream))
{
error (0, 0, _("%s: read error"), checkfile_name);
return 1;
}
- if (checkfile_stream != stdin && FCLOSE (checkfile_stream) == EOF)
+ if (checkfile_stream != stdin && fclose (checkfile_stream) == EOF)
{
error (0, errno, "%s", checkfile_name);
return 1;
/* Output a leading backslash if the file name contains
a newline. */
if (strchr (file, '\n'))
- PUTCHAR ('\\');
+ putchar ('\\');
for (i = 0; i < 16; ++i)
printf ("%02x", md5buffer[i]);
- PUTCHAR (' ');
+ putchar (' ');
if (binary)
- PUTCHAR ('*');
+ putchar ('*');
else
- PUTCHAR (' ');
+ putchar (' ');
/* Translate each NEWLINE byte to the string, "\\n",
and each backslash to "\\\\". */
break;
default:
- PUTCHAR (file[i]);
+ putchar (file[i]);
break;
}
}
- PUTCHAR ('\n');
+ putchar ('\n');
}
}
}
- if (FCLOSE (stdout) == EOF)
+ if (fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, _("standard input"));
exit (err == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
current_regex = &header_regex;
if (reset_numbers)
line_no = starting_line_number;
- PUTCHAR ('\n');
+ putchar ('\n');
}
/* Switch to a body section. */
{
current_type = body_type;
current_regex = &body_regex;
- PUTCHAR ('\n');
+ putchar ('\n');
}
/* Switch to a footer section. */
{
current_type = footer_type;
current_regex = &footer_regex;
- PUTCHAR ('\n');
+ putchar ('\n');
}
/* Process a regular text line in `line_buf'. */
print_lineno ();
break;
}
- FWRITE (line_buf.buffer, sizeof (char), line_buf.length, stdout);
- PUTCHAR ('\n');
+ fwrite (line_buf.buffer, sizeof (char), line_buf.length, stdout);
+ putchar ('\n');
}
/* Return the type of line in `line_buf'. */
process_file (stream);
- if (FERROR (stream))
+ if (ferror (stream))
{
error (0, errno, "%s", file);
return 1;
}
if (STREQ (file, "-"))
- CLEARERR (stream); /* Also clear EOF. */
- else if (FCLOSE (stream) == EOF)
+ clearerr (stream); /* Also clear EOF. */
+ else if (fclose (stream) == EOF)
{
error (0, errno, "%s", file);
return 1;
for (; optind < argc; optind++)
exit_status |= nl_file (argv[optind]);
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
{
error (0, errno, "-");
exit_status = 1;
}
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
{
unsigned int c = *(const unsigned char *) block;
unsigned int c2 = (ISPRINT(c) ? c : '.');
- PUTCHAR (c2);
+ putchar (c2);
block += sizeof (unsigned char);
}
- PUTCHAR ('<');
+ putchar ('<');
}
static void
if (n_skip >= file_stats.st_size)
{
n_skip -= file_stats.st_size;
- if (in_stream != stdin && FCLOSE (in_stream) == EOF)
+ if (in_stream != stdin && fclose (in_stream) == EOF)
{
error (0, errno, "%s", input_filename);
err = 1;
? BUFSIZ
: n_skip % BUFSIZ);
size_t n_bytes_read;
- n_bytes_read = FREAD (buf, 1, n_bytes_to_read, in_stream);
+ n_bytes_read = fread (buf, 1, n_bytes_to_read, in_stream);
n_skip -= n_bytes_read;
if (n_bytes_read != n_bytes_to_read)
break;
printf ("%*s", blank_fields * field_width, "");
dump_hexl_mode_trailer (n_bytes, curr_block);
}
- PUTCHAR ('\n');
+ putchar ('\n');
}
}
first = 0;
int err;
err = 0;
- if (FERROR (in_stream))
+ if (ferror (in_stream))
{
error (0, errno, "%s", input_filename);
if (in_stream != stdin)
- FCLOSE (in_stream);
+ fclose (in_stream);
err = 1;
}
- else if (in_stream != stdin && FCLOSE (in_stream) == EOF)
+ else if (in_stream != stdin && fclose (in_stream) == EOF)
{
error (0, errno, "%s", input_filename);
err = 1;
}
- if (FERROR (stdout))
+ if (ferror (stdout))
{
error (0, errno, _("standard output"));
err = 1;
Then try to read the remaining bytes from the newly opened file.
Repeat if necessary until *FILE_LIST is NULL. Set *N_BYTES_IN_BUFFER
to the number of bytes read. If an error occurs, it will be detected
- through FERROR when the stream is about to be closed. If there is an
+ through ferror when the stream is about to be closed. If there is an
error, give a message but continue reading as usual and return nonzero.
Otherwise return zero. */
size_t n_read;
n_needed = n - *n_bytes_in_buffer;
- n_read = FREAD (block + *n_bytes_in_buffer, 1, n_needed, in_stream);
+ n_read = fread (block + *n_bytes_in_buffer, 1, n_needed, in_stream);
*n_bytes_in_buffer += n_read;
break;
default:
- PUTC (c, stdout);
+ putc (c, stdout);
}
}
- PUTCHAR ('\n');
+ putchar ('\n');
}
/* We reach this point only if we search through
cleanup:;
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, _("standard input"));
- if (FCLOSE (stdout) == EOF)
+ if (fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (err == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
line_length = 0; /* Clear so we can easily detect EOF. */
if (fileptr[i] != CLOSED)
{
- chr = GETC (fileptr[i]);
+ chr = getc (fileptr[i]);
if (chr != EOF && delims_saved)
{
- FWRITE (delbuf, sizeof (char), delims_saved, stdout);
+ fwrite (delbuf, sizeof (char), delims_saved, stdout);
delims_saved = 0;
}
line_length++;
if (chr == '\n')
break;
- PUTC (chr, stdout);
- chr = GETC (fileptr[i]);
+ putc (chr, stdout);
+ chr = getc (fileptr[i]);
}
}
If an EOF or error, close the file and mark it in the list. */
if (fileptr[i] != CLOSED)
{
- if (FERROR (fileptr[i]))
+ if (ferror (fileptr[i]))
{
error (0, errno, "%s", fnamptr[i]);
errors = 1;
}
if (fileptr[i] == stdin)
- CLEARERR (fileptr[i]); /* Also clear EOF. */
- else if (FCLOSE (fileptr[i]) == EOF)
+ clearerr (fileptr[i]); /* Also clear EOF. */
+ else if (fclose (fileptr[i]) == EOF)
{
error (0, errno, "%s", fnamptr[i]);
errors = 1;
/* No. Some files were not closed for this line. */
if (delims_saved)
{
- FWRITE (delbuf, sizeof (char), delims_saved, stdout);
+ fwrite (delbuf, sizeof (char), delims_saved, stdout);
delims_saved = 0;
}
- PUTC ('\n', stdout);
+ putc ('\n', stdout);
}
continue; /* Next read of files, or exit. */
}
if (fileptr[i + 1] != ENDLIST)
{
if (chr != '\n')
- PUTC (chr, stdout);
+ putc (chr, stdout);
if (*delimptr != EMPTY_DELIM)
- PUTC (*delimptr, stdout);
+ putc (*delimptr, stdout);
if (++delimptr == delim_end)
delimptr = delims;
}
else
- PUTC (chr, stdout);
+ putc (chr, stdout);
}
}
}
delimptr = delims; /* Set up for delimiter string. */
- charold = GETC (fileptr);
+ charold = getc (fileptr);
if (charold != EOF)
{
/* `charold' is set up. Hit it!
character if needed. After the EOF, output `charold'
if it's a newline; otherwise, output it and then a newline. */
- while ((charnew = GETC (fileptr)) != EOF)
+ while ((charnew = getc (fileptr)) != EOF)
{
/* Process the old character. */
if (charold == '\n')
{
if (*delimptr != EMPTY_DELIM)
- PUTC (*delimptr, stdout);
+ putc (*delimptr, stdout);
if (++delimptr == delim_end)
delimptr = delims;
}
else
- PUTC (charold, stdout);
+ putc (charold, stdout);
charold = charnew;
}
/* Hit EOF. Process that last character. */
- PUTC (charold, stdout);
+ putc (charold, stdout);
}
if (charold != '\n')
- PUTC ('\n', stdout);
+ putc ('\n', stdout);
- if (FERROR (fileptr))
+ if (ferror (fileptr))
{
error (0, errno, "%s", *fnamptr);
errors = 1;
}
if (fileptr == stdin)
- CLEARERR (fileptr); /* Also clear EOF. */
- else if (FCLOSE (fileptr) == EOF)
+ clearerr (fileptr); /* Also clear EOF. */
+ else if (fclose (fileptr) == EOF)
{
error (0, errno, "%s", *fnamptr);
errors = 1;
exit_status = paste_parallel (argc - optind, &argv[optind]);
else
exit_status = paste_serial (argc - optind, &argv[optind]);
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
cleanup ();
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, _("standard input"));
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
if (failed_opens > 0)
exit (EXIT_FAILURE);
if (p->status == CLOSED)
return;
- if (FERROR (p->fp))
+ if (ferror (p->fp))
error (EXIT_FAILURE, errno, "%s", p->name);
- if (p->fp != stdin && FCLOSE (p->fp) == EOF)
+ if (p->fp != stdin && fclose (p->fp) == EOF)
error (EXIT_FAILURE, errno, "%s", p->name);
if (!parallel_files)
if (pad_vertically)
{
- PUTCHAR ('\n');
+ putchar ('\n');
--lines_left_on_page;
}
if (double_space && pv)
{
- PUTCHAR ('\n');
+ putchar ('\n');
--lines_left_on_page;
}
}
pad_down (lines_left_on_page + lines_per_footer);
else if (keep_FF && print_a_FF)
{
- PUTCHAR ('\f');
+ putchar ('\f');
print_a_FF = FALSE;
}
else
{
while (++h <= position)
- PUTCHAR (' ');
+ putchar (' ');
output_position = position;
}
}
register int i;
if (use_form_feed)
- PUTCHAR ('\f');
+ putchar ('\f');
else
for (i = lines; i; --i)
- PUTCHAR ('\n');
+ putchar ('\n');
}
/* Read the rest of the line.
register int c;
FILE *f = p->fp;
- while ((c = GETC (f)) != '\n')
+ while ((c = getc (f)) != '\n')
{
if (c == '\f')
{
- if ((c = GETC (f)) != '\n')
+ if ((c = getc (f)) != '\n')
ungetc (c, f);
if (keep_FF)
print_a_FF = TRUE;
COLUMN *q;
/* Read 1st character in a line or any character succeeding a FF */
- if ((c = GETC (f)) == '\f' && p->full_page_printed)
+ if ((c = getc (f)) == '\f' && p->full_page_printed)
/* A FF-coincidence with a previous full_page_printed.
To avoid an additional empty page, eliminate the FF */
- if ((c = GETC (f)) == '\n')
- c = GETC (f);
+ if ((c = getc (f)) == '\n')
+ c = getc (f);
p->full_page_printed = FALSE;
p->full_page_printed = FALSE;
}
- if ((c = GETC (f)) != '\n')
+ if ((c = getc (f)) != '\n')
ungetc (c, f);
hold_file (p);
break;
close_file (p);
break;
}
- c = GETC (f);
+ c = getc (f);
}
if (skip_count)
while (goal - h_old > 1
&& (h_new = POS_AFTER_TAB (chars_per_output_tab, h_old)) <= goal)
{
- PUTCHAR (output_tab_char);
+ putchar (output_tab_char);
h_old = h_new;
}
while (++h_old <= goal)
- PUTCHAR (' ');
+ putchar (' ');
output_position = goal;
spaces_not_printed = 0;
for (; separators_not_printed > 0; --separators_not_printed)
{
while (l-- > 0)
- PUTCHAR (*s++);
+ putchar (*s++);
output_position += col_sep_length;
}
}
else
++output_position;
}
- PUTCHAR (c);
+ putchar (c);
}
/* Skip to page PAGE before printing. */
#endif
/* read 1st character in each line or any character succeeding a FF: */
- c = GETC (p->fp);
+ c = getc (p->fp);
last_input_position = input_position;
if (c == '\f' && p->full_page_printed)
- if ((c = GETC (p->fp)) == '\n')
- c = GETC (p->fp);
+ if ((c = getc (p->fp)) == '\n')
+ c = getc (p->fp);
p->full_page_printed = FALSE;
switch (c)
{
case '\f':
- if ((c = GETC (p->fp)) != '\n')
+ if ((c = getc (p->fp)) != '\n')
ungetc (c, p->fp);
FF_only = TRUE;
if (print_a_header && !storing_columns)
for (;;)
{
- c = GETC (p->fp);
+ c = getc (p->fp);
switch (c)
{
case '\n':
return TRUE;
case '\f':
- if ((c = GETC (p->fp)) != '\n')
+ if ((c = getc (p->fp)) != '\n')
ungetc (c, p->fp);
if (keep_FF)
print_a_FF = TRUE;
if (fp == stdin)
{
/* Allow reading stdin from tty more than once. */
- if (FEOF (fp))
- CLEARERR (fp);
+ if (feof (fp))
+ clearerr (fp);
}
else if (fp == stdout)
{
- if (FFLUSH (fp) != 0)
+ if (fflush (fp) != 0)
{
error (0, errno, _("flushing file"));
cleanup ();
}
else
{
- if (FCLOSE (fp) != 0)
+ if (fclose (fp) != 0)
{
error (0, errno, _("error closing file"));
cleanup ();
static void
write_bytes (const char *buf, size_t n_bytes, FILE *fp)
{
- if (FWRITE (buf, 1, n_bytes, fp) != n_bytes)
+ if (fwrite (buf, 1, n_bytes, fp) != n_bytes)
{
error (0, errno, _("write error"));
cleanup ();
memmove (buf->buf, buf->buf + buf->used - buf->left, buf->left);
buf->used = buf->left;
- while (!FEOF (fp) && (buf->used == 0
+ while (!feof (fp) && (buf->used == 0
|| !memchr (buf->buf, eolchar, buf->used)))
{
if (buf->used == buf->alloc)
buf->alloc *= 2;
buf->buf = xrealloc (buf->buf, buf->alloc);
}
- cc = FREAD (buf->buf + buf->used, 1, buf->alloc - buf->used, fp);
- if (FERROR (fp))
+ cc = fread (buf->buf + buf->used, 1, buf->alloc - buf->used, fp);
+ if (ferror (fp))
{
error (0, errno, _("read error"));
cleanup ();
buf->used += cc;
}
- if (FEOF (fp) && buf->used && buf->buf[buf->used - 1] != eolchar)
+ if (feof (fp) && buf->used && buf->buf[buf->used - 1] != eolchar)
{
if (buf->used == buf->alloc)
{
fprintf (stderr, _("%s: %s:%d: disorder: "), program_name, file_name,
disorder_line_number);
write_bytes (disorder_line->text, disorder_line->length, stderr);
- PUTC (eolchar, stderr);
+ putc (eolchar, stderr);
}
free (buf.buf);
if (savedflag && compare (&saved, &lines[ord[0]].lines[cur[ord[0]]]))
{
write_bytes (saved.text, saved.length, ofp);
- PUTC (eolchar, ofp);
+ putc (eolchar, ofp);
savedflag = 0;
}
if (!savedflag)
{
write_bytes (lines[ord[0]].lines[cur[ord[0]]].text,
lines[ord[0]].lines[cur[ord[0]]].length, ofp);
- PUTC (eolchar, ofp);
+ putc (eolchar, ofp);
}
/* Check if we need to read more lines into core. */
if (unique && savedflag)
{
write_bytes (saved.text, saved.length, ofp);
- PUTC (eolchar, ofp);
+ putc (eolchar, ofp);
free (saved.text);
}
}
nls_numeric_format (lines.lines, lines.used);
#endif
sortlines (lines.lines, lines.used, tmp);
- if (FEOF (fp) && !nfiles && !n_temp_files && !buf.left)
+ if (feof (fp) && !nfiles && !n_temp_files && !buf.left)
tfp = ofp;
else
{
|| compare (&lines.lines[i], &lines.lines[i - 1]))
{
write_bytes (lines.lines[i].text, lines.lines[i].length, tfp);
- PUTC (eolchar, tfp);
+ putc (eolchar, tfp);
}
if (tfp != ofp)
xfclose (tfp);
fp = xfopen (files[i], "r");
tmp = tempname ();
ofp = xtmpfopen (tmp);
- while ((cc = FREAD (buf, 1, sizeof buf, fp)) > 0)
+ while ((cc = fread (buf, 1, sizeof buf, fp)) > 0)
write_bytes (buf, cc, ofp);
- if (FERROR (fp))
+ if (ferror (fp))
{
error (0, errno, "%s", files[i]);
cleanup ();
/* If we wait for the implicit flush on exit, and the parent process
has closed stdout (e.g., exec >&- in a shell), then the output file
winds up empty. I don't understand why. This is under SunOS,
- Solaris, Ultrix, and Irix. This premature FFLUSH makes the output
+ Solaris, Ultrix, and Irix. This premature fflush makes the output
reappear. --karl@cs.umb.edu */
- if (FFLUSH (ofp) < 0)
+ if (fflush (ofp) < 0)
error (SORT_FAILURE, errno, _("%s: write error"), outfile);
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (SORT_FAILURE, errno, outfile);
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
error (SORT_FAILURE, errno, _("%s: write error"), outfile);
exit (EXIT_SUCCESS);
}
}
- while ((ch = GETC (fp)) != EOF)
+ while ((ch = getc (fp)) != EOF)
{
total_bytes++;
ROTATE_RIGHT (checksum);
checksum &= 0xffff; /* Keep it within bounds. */
}
- if (FERROR (fp))
+ if (ferror (fp))
{
error (0, errno, "%s", file);
if (!STREQ (file, "-"))
- FCLOSE (fp);
+ fclose (fp);
return -1;
}
- if (!STREQ (file, "-") && FCLOSE (fp) == EOF)
+ if (!STREQ (file, "-") && fclose (fp) == EOF)
{
error (0, errno, "%s", file);
return -1;
printf ("%05lu %5ld", checksum, (total_bytes + 1024 - 1) / 1024);
if (print_name > 1)
printf (" %s", file);
- PUTCHAR ('\n');
+ putchar ('\n');
return 0;
}
printf ("%lu %ld", checksum % 0xffff, (total_bytes + 512 - 1) / 512);
if (print_name)
printf (" %s", file);
- PUTCHAR ('\n');
+ putchar ('\n');
return 0;
}
if ((*sum_func) (argv[optind], files_given) < 0)
errors = 1;
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
{
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));
- FWRITE (a, 1, b - a, out_stream);
+ fwrite (a, 1, b - a, out_stream);
}
}
if (start == 0)
{
- FWRITE (buffer, 1, bytes_in_buffer, stdout);
+ fwrite (buffer, 1, bytes_in_buffer, stdout);
bytes_in_buffer = 0;
return;
}
memcpy (buffer + bytes_in_buffer, start, bytes_available);
bytes_to_add -= bytes_available;
start += bytes_available;
- FWRITE (buffer, 1, WRITESIZE, stdout);
+ fwrite (buffer, 1, WRITESIZE, stdout);
bytes_in_buffer = 0;
bytes_available = WRITESIZE;
}
return 1;
}
errors = tac_seekable (fileno (in), file);
- if (FERROR (in) || fclose (in) == EOF)
+ if (ferror (in) || fclose (in) == EOF)
{
error (0, errno, "%s", file);
return 1;
error (EXIT_FAILURE, errno, _("stdin: read error"));
/* Don't bother checking for failure inside the loop -- check after. */
- FWRITE (G_buffer, 1, bytes_read, tmp);
+ fwrite (G_buffer, 1, bytes_read, tmp);
}
- if (FERROR (tmp) || fflush (tmp) == EOF)
+ if (ferror (tmp) || fflush (tmp) == EOF)
error (EXIT_FAILURE, errno, "%s", tempfile);
rewind (tmp);
if (bol < buf + n_bytes)
{
/* Print out the line from bol to end of input. */
- FWRITE (bol, 1, (buf + n_bytes) - bol, out);
+ fwrite (bol, 1, (buf + n_bytes) - bol, out);
/* Add a newline here. Otherwise, the first and second lines
of output would appear to have been joined. */
- FPUTC ('\n', out);
+ fputc ('\n', out);
}
while ((nl = memrchr (buf, bol - 1, '\n')) != NULL)
{
/* Output the line (which includes a trailing newline)
from NL+1 to BOL-1. */
- FWRITE (nl + 1, 1, bol - (nl + 1), out);
+ fwrite (nl + 1, 1, bol - (nl + 1), out);
bol = nl + 1;
}
When the first byte of the input is a newline, there is nothing
left to do here. */
if (buf < bol)
- FWRITE (buf, 1, bol - buf, out);
+ fwrite (buf, 1, bol - buf, out);
/* FIXME: this is work in progress.... */
- return FERROR (out);
+ return ferror (out);
}
/* FIXME: describe */
if (have_read_stdin && close (0) < 0)
error (EXIT_FAILURE, errno, "-");
- if (FERROR (stdout) || fclose (stdout) == EOF)
+ if (ferror (stdout) || fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
{
assert (fd == 1);
assert (n_bytes >= 0);
- if (n_bytes > 0 && FWRITE (buffer, 1, n_bytes, stdout) == 0)
+ if (n_bytes > 0 && fwrite (buffer, 1, n_bytes, stdout) == 0)
error (EXIT_FAILURE, errno, _("write error"));
}
error (EXIT_FAILURE, errno, "%s", pretty_filename);
if (forever)
- FFLUSH (stdout);
+ fflush (stdout);
return total;
}
if (have_read_stdin && close (0) < 0)
error (EXIT_FAILURE, errno, "-");
- if (FCLOSE (stdout) == EOF)
+ if (fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
++i;
}
if (out_len > 0
- && FWRITE ((char *) &buf[begin], 1, out_len, stdout) == 0)
+ && fwrite ((char *) &buf[begin], 1, out_len, stdout) == 0)
error (EXIT_FAILURE, errno, _("write error"));
}
do
{
nr = read_and_delete (io_buf, IO_BUF_SIZE, NULL);
- if (nr > 0 && FWRITE ((char *) io_buf, 1, nr, stdout) == 0)
+ if (nr > 0 && fwrite ((char *) io_buf, 1, nr, stdout) == 0)
error (EXIT_FAILURE, errno, _("write error"));
}
while (nr > 0);
{
chars_read = read_and_xlate (io_buf, IO_BUF_SIZE, NULL);
if (chars_read > 0
- && FWRITE ((char *) io_buf, 1, chars_read, stdout) == 0)
+ && fwrite ((char *) io_buf, 1, chars_read, stdout) == 0)
error (EXIT_FAILURE, errno, _("write error"));
}
while (chars_read > 0);
}
}
- if (FCLOSE (stdout) == EOF)
+ if (fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
if (close (0) != 0)
if (fp)
{
- if (FERROR (fp))
+ if (ferror (fp))
{
error (0, errno, "%s", prev_file);
exit_status = 1;
}
if (fp == stdin)
- CLEARERR (fp); /* Also clear EOF. */
- else if (FCLOSE (fp) == EOF)
+ clearerr (fp); /* Also clear EOF. */
+ else if (fclose (fp) == EOF)
{
error (0, errno, "%s", prev_file);
exit_status = 1;
for (;;)
{
- c = GETC (fp);
+ c = getc (fp);
if (c == ' ' && convert)
{
then print the rest as spaces. */
if (pending == 1)
{
- PUTCHAR (' ');
+ putchar (' ');
pending = 0;
}
column -= pending;
}
if (next_tab_column - column <= pending)
{
- PUTCHAR ('\t');
+ putchar ('\t');
pending -= next_tab_column - column;
column = next_tab_column;
}
column += pending;
while (pending != 0)
{
- PUTCHAR (' ');
+ putchar (' ');
pending--;
}
}
}
}
- PUTCHAR (c);
+ putchar (c);
if (c == '\n')
{
unexpand ();
- if (have_read_stdin && FCLOSE (stdin) == EOF)
+ if (have_read_stdin && fclose (stdin) == EOF)
error (EXIT_FAILURE, errno, "-");
- if (FCLOSE (stdout) == EOF)
+ if (fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, _("write error"));
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
if (countmode == count_occurrences)
fprintf (stream, "%7d\t", linecount + 1);
- FWRITE (line->buffer, sizeof (char), line->length, stream);
- PUTC ('\n', stream);
+ fwrite (line->buffer, sizeof (char), line->length, stream);
+ putc ('\n', stream);
}
/* Process input file INFILE with output to OUTFILE.
prevfield = find_field (prevline);
prevlen = prevline->length - (prevfield - prevline->buffer);
- while (!FEOF (istream))
+ while (!feof (istream))
{
if (readline (thisline, istream) == 0)
break;
writeline (prevline, ostream, match_count);
closefiles:
- if (FERROR (istream) || fclose (istream) == EOF)
+ if (ferror (istream) || fclose (istream) == EOF)
error (EXIT_FAILURE, errno, _("error reading %s"), infile);
- if (FERROR (ostream) || fclose (ostream) == EOF)
+ if (ferror (ostream) || fclose (ostream) == EOF)
error (EXIT_FAILURE, errno, _("error writing %s"), outfile);
free (lb1.buffer);