Skip to content

Commit

Permalink
Apply script to each file on command line.
Browse files Browse the repository at this point in the history
For this to work, the script must be seekable. And to avoid infinite
loops, if the script modifies the input file list, it is only applied
to the first file on the command line.
  • Loading branch information
slewsys committed Apr 3, 2024
1 parent 08e9c7b commit 3bc95d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/buf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* buf.c: Buffer routines for the ed line editor.
*
* Copyright © 1993-2022 Andrew L. Moore, SlewSys Research
* Copyright © 1993-2024 Andrew L. Moore, SlewSys Research
*
* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-or-later OR MIT
*/
Expand Down Expand Up @@ -193,8 +193,8 @@ init_ed_command (int init_glob, ed_buffer_t *ed)
/* File info */
#ifdef WANT_FILE_LOCK

/* GNU/Linux double-frees on fclose() here... */
#if __linux__
/* XXX: GNU/Linux double-frees on fclose(). */
#ifndef __linux__
if (ed->file->handle)

/* Assert: No writes since fopen(3). */
Expand Down
5 changes: 3 additions & 2 deletions src/io.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* io.c: I/O routines for the ed line editor.
*
* Copyright © 1993-2022 Andrew L. Moore, SlewSys Research
* Copyright © 1993-2024 Andrew L. Moore, SlewSys Research
*
* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-or-later OR MIT
*/
Expand Down Expand Up @@ -615,7 +615,8 @@ write_file (const char *fn, int is_default, off_t from, off_t to,
* File-locking requires file write access, so this case should not
* be reached.
*/
else if (file_already_open && fclose (ed->file->handle) < 0)
else if (file_already_open
&& (fclose (ed->file->handle) < 0 || !(ed->file->handle = NULL)))
{
fprintf (stderr, "%s: %s\n", ed->file->name, strerror (errno));
ed->exec->err = _("File close error");
Expand Down
9 changes: 8 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* main.c: Entry point for the ed line editor.
*
* Copyright © 1993-2023 Andrew L. Moore, SlewSys Research
* Copyright © 1993-2024 Andrew L. Moore, SlewSys Research
*
* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-or-later OR MIT
*/
Expand Down Expand Up @@ -410,6 +410,13 @@ main (int argc, char **argv)
goto error;
#endif

/* Command-line files still available and stdin seekable... */
if (ed->file->list->gl_offs && ed->file->list->gl_pathc > 1
&& FSEEK(stdin, 0L, SEEK_SET) != -1)
{
status = EOF_NEXT;
goto next;
}
quit (ed->exec->status, ed);
case EMOD:
ed->exec->err = _("WARNING: Buffer modified since last write");
Expand Down

0 comments on commit 3bc95d6

Please sign in to comment.