Bash  5.0-beta2
Bash - Bourne Again shell
rlcat.c File Reference
#include <sys/types.h>
#include "posixstat.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <readline/readline.h>
#include <readline/history.h>

Go to the source code of this file.

Functions

void exit ()
 
static int stdcat ()
 
static void usage ()
 
int main (int argc, char **argv)
 
static int fcopy (FILE *fp)
 
int stdcat (int argc, char **argv)
 

Variables

int errno
 
int optind
 
char * optarg
 
static char * progname
 
static int vflag
 

Function Documentation

◆ exit()

void exit ( )

Referenced by main().

Here is the caller graph for this function:

◆ stdcat() [1/2]

static int stdcat ( )
static

Referenced by main().

Here is the caller graph for this function:

◆ usage()

static void usage ( void  )
static

Definition at line 69 of file rlcat.c.

References progname.

Referenced by main().

70 {
71  fprintf (stderr, "%s: usage: %s [-vEVN] [filename]\n", progname, progname);
72 }
static char * progname
Definition: rlcat.c:65
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 75 of file rlcat.c.

References add_history(), argc, argv, exit(), optind, progname, readline(), rl_variable_bind(), stdcat(), strrchr(), temp, usage(), and vflag.

78 {
79  char *temp;
80  int opt, Vflag, Nflag;
81 
82  progname = strrchr(argv[0], '/');
83  if (progname == 0)
84  progname = argv[0];
85  else
86  progname++;
87 
88  vflag = Vflag = Nflag = 0;
89  while ((opt = getopt(argc, argv, "vEVN")) != EOF)
90  {
91  switch (opt)
92  {
93  case 'v':
94  vflag = 1;
95  break;
96  case 'V':
97  Vflag = 1;
98  break;
99  case 'E':
100  Vflag = 0;
101  break;
102  case 'N':
103  Nflag = 1;
104  break;
105  default:
106  usage ();
107  exit (2);
108  }
109  }
110 
111  argc -= optind;
112  argv += optind;
113 
114  if (isatty(0) == 0 || argc || Nflag)
115  return stdcat(argc, argv);
116 
117  rl_variable_bind ("editing-mode", Vflag ? "vi" : "emacs");
118  while (temp = readline (""))
119  {
120  if (*temp)
121  add_history (temp);
122  printf ("%s\n", temp);
123  }
124 
125  return (ferror (stdout));
126 }
static void usage()
Definition: rlcat.c:69
static char ** argv
Definition: test.c:110
void add_history(const char *string)
Definition: history.c:272
int rl_variable_bind(const char *name, const char *value)
Definition: bind.c:1935
static int vflag
Definition: rlcat.c:66
char * strrchr()
static char * progname
Definition: rlcat.c:65
void exit()
static int argc
Definition: test.c:109
char * readline(const char *prompt)
Definition: readline.c:344
static int stdcat()
int optind
temp
Definition: subst.c:10040
Here is the call graph for this function:

◆ fcopy()

static int fcopy ( FILE *  fp)
static

Definition at line 129 of file rlcat.c.

References c, isascii, isprint, rl_untranslate_keyseq(), and vflag.

Referenced by stdcat().

131 {
132  int c;
133  char *x;
134 
135  while ((c = getc(fp)) != EOF)
136  {
137  if (vflag && isascii ((unsigned char)c) && isprint((unsigned char)c) == 0)
138  {
139  x = rl_untranslate_keyseq (c);
140  if (fputs (x, stdout) == EOF)
141  return 1;
142  }
143  else if (putchar (c) == EOF)
144  return 1;
145  }
146  return (ferror (stdout));
147 }
char * rl_untranslate_keyseq(int seq)
Definition: bind.c:652
register GCHAR c
Definition: glob_loop.c:26
static int vflag
Definition: rlcat.c:66
#define isascii(c)
Definition: smatch.c:128
#define isprint(c)
Definition: chartypes.h:49
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stdcat() [2/2]

int stdcat ( int  argc,
char **  argv 
)

Definition at line 150 of file rlcat.c.

References argc, argv, errno, fcopy(), i, progname, and strerror().

153 {
154  int i, fd, r;
155  char *s;
156  FILE *fp;
157 
158  if (argc == 0)
159  return (fcopy(stdin));
160 
161  for (i = 0, r = 1; i < argc; i++)
162  {
163  if (*argv[i] == '-' && argv[i][1] == 0)
164  fp = stdin;
165  else
166  {
167  fp = fopen (argv[i], "r");
168  if (fp == 0)
169  {
170  fprintf (stderr, "%s: %s: cannot open: %s\n", progname, argv[i], strerror(errno));
171  continue;
172  }
173  }
174  r = fcopy (fp);
175  if (fp != stdin)
176  fclose(fp);
177  }
178  return r;
179 }
static char ** argv
Definition: test.c:110
static int fcopy(FILE *fp)
Definition: rlcat.c:129
char * strerror()
static char * progname
Definition: rlcat.c:65
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
int errno
static int argc
Definition: test.c:109
Here is the call graph for this function:

Variable Documentation

◆ errno

int errno

Referenced by stdcat().

◆ optind

int optind

Referenced by main().

◆ optarg

char* optarg

◆ progname

char* progname
static

Definition at line 65 of file rlcat.c.

Referenced by main(), stdcat(), and usage().

◆ vflag

int vflag
static

Definition at line 66 of file rlcat.c.

Referenced by fcopy(), main(), and realpath_builtin().