Mirror of git://git.busybox.net/busybox with our patches on top
Source
static void puts_maybe_newline(char *s, FILE *file, char *last_puts_char, char last_gets_char)
/* vi: set sw=4 ts=4: */
/*
* sed.c - very minimalist version of sed
*
* Copyright (C) 1999,2000,2001 by Lineo, inc. and Mark Whitley
* Copyright (C) 1999,2000,2001 by Mark Whitley <markw@codepoet.org>
* Copyright (C) 2002 Matt Kraai
* Copyright (C) 2003 by Glenn McGrath <bug1@iinet.net.au>
* Copyright (C) 2003,2004 by Rob Landley <rob@landley.net>
*
* MAINTAINER: Rob Landley <rob@landley.net>
*
* Licensed under GPL version 2, see file LICENSE in this tarball for details.
*/
/* Code overview.
Files are laid out to avoid unnecessary function declarations. So for
example, every function add_cmd calls occurs before add_cmd in this file.
add_cmd() is called on each line of sed command text (from a file or from
the command line). It calls get_address() and parse_cmd_args(). The
resulting sed_cmd_t structures are appended to a linked list
(G.sed_cmd_head/G.sed_cmd_tail).
add_input_file() adds a FILE * to the list of input files. We need to
know all input sources ahead of time to find the last line for the $ match.
process_files() does actual sedding, reading data lines from each input FILE *
(which could be stdin) and applying the sed command list (sed_cmd_head) to
each of the resulting lines.
sed_main() is where external code calls into this, with a command line.
*/
/*
Supported features and commands in this version of sed:
- comments ('#')
- address matching: num|/matchstr/[,num|/matchstr/|$]command
- commands: (p)rint, (d)elete, (s)ubstitue (with g & I flags)
- edit commands: (a)ppend, (i)nsert, (c)hange
- file commands: (r)ead
- backreferences in substitution expressions (\0, \1, \2...\9)
- grouped commands: {cmd1;cmd2}
- transliteration (y/source-chars/dest-chars/)
- pattern space hold space storing / swapping (g, h, x)
- labels / branching (: label, b, t, T)
(Note: Specifying an address (range) to match is *optional*; commands
default to the whole pattern space if no specific address match was
requested.)
Todo:
- Create a wrapper around regex to make libc's regex conform with sed
Reference http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html
*/