Index: usr.bin/sed/main.c =================================================================== --- usr.bin/sed/main.c +++ usr.bin/sed/main.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #define _WITH_GETLINE @@ -121,6 +122,21 @@ static void add_file(char *); static void usage(void); +static struct option longopts[] = { + {"regexp-extended", no_argument, NULL, 'E'}, + {"in-place-separate", optional_argument, NULL, 'I'}, + {"truncate", no_argument, NULL, 'a'}, + {"expression", required_argument, NULL, 'e'}, + {"file", required_argument, NULL, 'f'}, + {"in-place", optional_argument, NULL, 'i'}, + {"line-buffered", no_argument, NULL, 'l'}, + {"quiet", no_argument, NULL, 'n'}, + {"silent", no_argument, NULL, 'n'}, /* GNU compat */ + /* r is for GNU compat */ + {"unbuffered", no_argument, NULL, 'u'}, + {NULL, 0, NULL, 0}, +}; + int main(int argc, char *argv[]) { @@ -131,16 +147,22 @@ fflag = 0; inplace = NULL; + ispan = 0; - while ((c = getopt(argc, argv, "EI:ae:f:i:lnru")) != -1) + while ((c = getopt_long(argc, argv, "EI::ae:f:i::lnru", longopts, NULL)) != -1) switch (c) { case 'r': /* Gnu sed compat */ case 'E': rflags = REG_EXTENDED; break; case 'I': - inplace = optarg; - ispan = 1; /* span across input files */ + ispan = 1; + /* FALLTHROUGH */ + case 'i': + if (optarg) + inplace = optarg; + else + inplace = ""; break; case 'a': aflag = 1; @@ -157,10 +179,6 @@ fflag = 1; add_compunit(CU_FILE, optarg); break; - case 'i': - inplace = optarg; - ispan = 0; /* don't span across input files */ - break; case 'l': if(setvbuf(stdout, NULL, _IOLBF, 0) != 0) warnx("setting line buffered output failed"); @@ -204,8 +222,8 @@ usage(void) { (void)fprintf(stderr, - "usage: %s script [-Ealnru] [-i extension] [file ...]\n" - "\t%s [-Ealnu] [-i extension] [-e script] ... [-f script_file]" + "usage: %s script [-Ealnru] [-I [extension]] [-i [extension]] [file ...]\n" + "\t%s [-Ealnu] [-I [extension]] [-i [extension]] [-e script] ... [-f script_file]" " ... [file ...]\n", getprogname(), getprogname()); exit(1); } Index: usr.bin/sed/sed.1 =================================================================== --- usr.bin/sed/sed.1 +++ usr.bin/sed/sed.1 @@ -46,8 +46,8 @@ .Op Fl Ealnr .Op Fl e Ar command .Op Fl f Ar command_file -.Op Fl I Ar extension -.Op Fl i Ar extension +.Op Fl I Bo Ar extension Bc +.Op Fl i Bo Ar extension Bc .Op Ar .Sh DESCRIPTION The @@ -68,13 +68,13 @@ .Pp The following options are available: .Bl -tag -width indent -.It Fl E +.It Fl E , Fl -regexp-extended Interpret regular expressions as extended (modern) regular expressions rather than basic regular expressions (BRE's). The .Xr re_format 7 manual page fully describes both formats. -.It Fl a +.It Fl a , Fl -truncate The files listed as parameters for the .Dq w functions are created (or truncated) before any processing begins, @@ -86,23 +86,23 @@ to delay opening each file until a command containing the related .Dq w function is applied to a line of input. -.It Fl e Ar command +.It Fl e Ar command No , Fl -expression Ar command Append the editing commands specified by the .Ar command argument to the list of commands. -.It Fl f Ar command_file +.It Fl f Ar command_file No , Fl -file Ar command_file Append the editing commands found in the file .Ar command_file to the list of commands. The editing commands should each be listed on a separate line. -.It Fl I Ar extension +.It Fl I Bo Ar extension Bc No , Fl -in-place-separate Bo Ar extension Bc Edit files in-place, saving backups with the specified .Ar extension . -If a zero-length +If no or a zero-length .Ar extension is given, no backup will be saved. -It is not recommended to give a zero-length +It recommended to provide an .Ar extension when in-place editing files, as you risk corruption or partial content in situations where disk space is exhausted, etc. @@ -122,7 +122,7 @@ where using .Fl i is desired. -.It Fl i Ar extension +.It Fl i Bo Ar extension Bc No , Fl -in-place Bo Ar extension Bc Edit files in-place similarly to .Fl I , but treat each file independently from other files. @@ -136,9 +136,9 @@ The net result is as though each file were edited by a separate .Nm instance. -.It Fl l +.It Fl l No , Fl -line-buffered Make output line buffered. -.It Fl n +.It Fl n No , Fl -quiet , Fl -silent By default, each line of input is echoed to the standard output after all of the commands have been applied to it. The @@ -148,7 +148,7 @@ Same as .Fl E for compatibility with GNU sed. -.It Fl u +.It Fl u No , Fl -unbuffered Make output unbuffered. .El .Pp