diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-01-20 10:55:18 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-01-20 10:55:18 +0000 |
commit | 70e9163c9c18e995515598085cb824e554eb7ae7 (patch) | |
tree | a42dc8b2a6c031354bf31472de888bfc8a060132 /src/tac-pipe.c | |
parent | cbf5993c43f49281173f185863577d86bfac6eae (diff) | |
download | coreutils-tarball-master.tar.gz |
coreutils-8.25HEADcoreutils-8.25master
Diffstat (limited to 'src/tac-pipe.c')
-rw-r--r-- | src/tac-pipe.c | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/src/tac-pipe.c b/src/tac-pipe.c index d2c6f67..976570a 100644 --- a/src/tac-pipe.c +++ b/src/tac-pipe.c @@ -1,11 +1,11 @@ /* tac from a pipe. - Copyright (C) 1997, 1998, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1997-2016 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -13,8 +13,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* FIXME */ #include <assert.h> @@ -63,52 +62,52 @@ buf_init_from_stdin (Buf *x, char eol_byte) size_t bytes_read; if (buf == NULL) - { - /* Fall back on the code that relies on a temporary file. - Write all buffers to that file and free them. */ - /* FIXME */ - ok = false; - break; - } + { + /* Fall back on the code that relies on a temporary file. + Write all buffers to that file and free them. */ + /* FIXME */ + ok = false; + break; + } bytes_read = full_read (STDIN_FILENO, buf, BUFFER_SIZE); if (bytes_read != buffer_size && errno != 0) - error (EXIT_FAILURE, errno, _("read error")); + error (EXIT_FAILURE, errno, _("read error")); { - struct B_pair bp; - bp.start = buf; - bp.one_past_end = buf + bytes_read; - obstack_grow (OBS, &bp, sizeof (bp)); + struct B_pair bp; + bp.start = buf; + bp.one_past_end = buf + bytes_read; + obstack_grow (OBS, &bp, sizeof (bp)); } if (bytes_read != 0) - last_byte_is_eol_byte = (buf[bytes_read - 1] == eol_byte); + last_byte_is_eol_byte = (buf[bytes_read - 1] == eol_byte); if (bytes_read < BUFFER_SIZE) - break; + break; } if (ok) { /* If the file was non-empty and lacked an EOL_BYTE at its end, - then add a buffer containing just that one byte. */ + then add a buffer containing just that one byte. */ if (!last_byte_is_eol_byte) - { - char *buf = malloc (1); - if (buf == NULL) - { - /* FIXME: just like above */ - ok = false; - } - else - { - struct B_pair bp; - *buf = eol_byte; - bp.start = buf; - bp.one_past_end = buf + 1; - obstack_grow (OBS, &bp, sizeof (bp)); - } - } + { + char *buf = malloc (1); + if (buf == NULL) + { + /* FIXME: just like above */ + ok = false; + } + else + { + struct B_pair bp; + *buf = eol_byte; + bp.start = buf; + bp.one_past_end = buf + 1; + obstack_grow (OBS, &bp, sizeof (bp)); + } + } } x->n_bufs = obstack_object_size (OBS) / sizeof (x->p[0]); @@ -173,7 +172,7 @@ line_ptr_increment (const Buf *x, const Line_ptr *lp) static bool find_bol (const Buf *x, - const Line_ptr *last_bol, Line_ptr *new_bol, char eol_byte) + const Line_ptr *last_bol, Line_ptr *new_bol, char eol_byte) { size_t i; Line_ptr tmp; @@ -189,16 +188,16 @@ find_bol (const Buf *x, { char *nl = memrchr (x->p[i].start, last_bol_ptr, eol_byte); if (nl) - { - Line_ptr nl_pos; - nl_pos.i = i; - nl_pos.ptr = nl; - *new_bol = line_ptr_increment (x, &nl_pos); - return true; - } + { + Line_ptr nl_pos; + nl_pos.i = i; + nl_pos.ptr = nl; + *new_bol = line_ptr_increment (x, &nl_pos); + return true; + } if (i == 0) - break; + break; --i; last_bol_ptr = ONE_PAST_END (x, i); @@ -219,7 +218,7 @@ find_bol (const Buf *x, static void print_line (FILE *out_stream, const Buf *x, - const Line_ptr *bol, const Line_ptr *bol_next) + const Line_ptr *bol, const Line_ptr *bol_next) { size_t i; for (i = bol->i; i <= bol_next->i; i++) @@ -255,7 +254,7 @@ tac_mem () { Line_ptr new_bol; if (! find_bol (&x, &bol, &new_bol, eol_byte)) - break; + break; print_line (stdout, &x, &new_bol, &bol); bol = new_bol; } |