r48237 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48236‎ | r48237 | r48238 >
Date:18:43, 9 March 2009
Author:river
Status:deferred
Tags:
Comment:
readline: read a line from the terminal and print it, for use in shell scripts
Modified paths:
  • /trunk/tools/tsutils/readline (added) (history)
  • /trunk/tools/tsutils/readline/Makefile (added) (history)
  • /trunk/tools/tsutils/readline/readline.c (added) (history)

Diff [purge]

Index: trunk/tools/tsutils/readline/readline.c
@@ -0,0 +1,39 @@
 2+/*
 3+ * Read a line from stdin using readline for line editing.
 4+ * $Id$
 5+ */
 6+
 7+#include <stdio.h>
 8+#include <string.h>
 9+#include <errno.h>
 10+#include <readline/readline.h>
 11+
 12+int
 13+main(argc, argv)
 14+ int argc
 15+#ifdef __GNUC__
 16+ __attribute__((unused))
 17+#endif
 18+ ;
 19+ char **argv;
 20+{
 21+char const *prompt = argv[1];
 22+char *response;
 23+FILE *tty;
 24+
 25+ if ((tty = fopen("/dev/tty", "w+")) == NULL) {
 26+ (void) fprintf(stderr,
 27+ "%s: cannot open /dev/tty: %s\n",
 28+ argv[0], strerror(errno));
 29+ return 1;
 30+ }
 31+
 32+ rl_instream = tty;
 33+ rl_outstream = tty;
 34+
 35+ if ((response = readline(prompt)) == NULL)
 36+ return 1;
 37+
 38+ (void) printf("%s\n", response);
 39+ return 0;
 40+}
Property changes on: trunk/tools/tsutils/readline/readline.c
___________________________________________________________________
Name: svn:keywords
141 + Id Revision
Index: trunk/tools/tsutils/readline/Makefile
@@ -0,0 +1,7 @@
 2+PROG = readline
 3+LIBS = -lreadline
 4+
 5+SRCS = readline.c
 6+OBJS = $(SRCS:.c=.o)
 7+
 8+include ../mk/prog.mk
Property changes on: trunk/tools/tsutils/readline/Makefile
___________________________________________________________________
Name: svn:keywords
19 + Id Revision

Status & tagging log