2 * rlcat - cat(1) using readline
7 /* Copyright (C) 1987-2002 Free Software Foundation, Inc.
9 This file is part of the GNU Readline Library, a library for
10 reading lines of text with interactive input and history editing.
12 The GNU Readline Library is free software; you can redistribute it
13 and/or modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2, or
15 (at your option) any later version.
17 The GNU Readline Library is distributed in the hope that it will be
18 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 The GNU General Public License is often shipped with GNU software, and
23 is generally kept in a file called COPYING or LICENSE. If you do not
24 have a copy of the license, write to the Free Software Foundation,
25 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
27 #if defined (HAVE_CONFIG_H)
35 #include <sys/types.h>
36 #include "posixstat.h"
47 #if defined (READLINE_LIBRARY)
48 # include "readline.h"
51 # include <readline/readline.h>
52 # include <readline/history.h>
60 static char *progname
;
66 fprintf (stderr
, "%s: usage: %s [-vEVN] [filename]\n", progname
, progname
);
75 int opt
, Vflag
, Nflag
;
77 progname
= strrchr(argv
[0], '/');
83 vflag
= Vflag
= Nflag
= 0;
84 while ((opt
= getopt(argc
, argv
, "vEVN")) != EOF
)
109 if (isatty(0) == 0 || argc
|| Nflag
)
110 return stdcat(argc
, argv
);
112 rl_variable_bind ("editing-mode", Vflag
? "vi" : "emacs");
113 while (temp
= readline (""))
117 printf ("%s\n", temp
);
120 return (ferror (stdout
));
130 while ((c
= getc(fp
)) != EOF
)
132 if (vflag
&& isascii ((unsigned char)c
) && isprint((unsigned char)c
) == 0)
134 x
= rl_untranslate_keyseq (c
);
135 if (fputs (x
, stdout
) != 0)
138 else if (putchar (c
) == EOF
)
141 return (ferror (stdout
));
154 return (fcopy(stdin
));
156 for (i
= 0, r
= 1; i
< argc
; i
++)
158 if (*argv
[i
] == '-' && argv
[i
][1] == 0)
162 fp
= fopen (argv
[i
], "r");
165 fprintf (stderr
, "%s: %s: cannot open: %s\n", progname
, argv
[i
], strerror(errno
));