Default to stdin/stdout if no input files are
given to indent.  FreeBSD and GNU indent have had
this behaviour for a long time now.

Based on FreeBSD svn rev 40502 from back in 1998.

Index: indent.1
===================================================================
RCS file: /cvs/src/usr.bin/indent/indent.1,v
retrieving revision 1.21
diff -u -p -r1.21 indent.1
--- indent.1    20 Jun 2013 06:28:15 -0000      1.21
+++ indent.1    20 Jun 2013 06:50:52 -0000
@@ -41,7 +41,7 @@
 .Sh SYNOPSIS
 .Nm indent
 .Bk -words
-.Ar input-file Op Ar output-file
+.Op Ar input-file Op Ar output-file
 .Op Fl bad | nbad
 .Op Fl bap | nbap
 .Op Fl bbb | nbbb
@@ -114,6 +114,11 @@ is specified,
 .Nm
 checks to make sure it is different from
 .Ar input-file .
+.Pp
+If no
+.Ar input-file
+is specified
+input is read from stdin and the formatted file is written to stdout. 
 .Pp
 The options listed below control the formatting style imposed by
 .Nm .
Index: indent.c
===================================================================
RCS file: /cvs/src/usr.bin/indent/indent.c,v
retrieving revision 1.21
diff -u -p -r1.21 indent.c
--- indent.c    20 Jun 2013 06:28:15 -0000      1.21
+++ indent.c    20 Jun 2013 06:50:52 -0000
@@ -198,11 +198,10 @@ main(int argc, char **argv)
            set_option(argv[i]);
     }                          /* end of for */
     if (input == NULL) {
-       fprintf(stderr, "usage: indent input-file [output-file] [options]\n");
-       exit(1);
+       input = stdin;
     }
     if (output == NULL) {
-       if (troff)
+       if (troff || input == stdin)
            output = stdout;
        else {
            out_name = in_name;

Reply via email to