mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 04:21:24 +08:00
Minix Editline from Minix current 2008-06-06 (June 6th).
This commit is contained in:
commit
191d54898b
44
Makefile.in
Normal file
44
Makefile.in
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
## $Revision: 1390 $
|
||||||
|
##
|
||||||
|
## Unix makefile for editline library.
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
## Set your options:
|
||||||
|
## -DANSI_ARROWS ANSI arrows keys work like emacs.
|
||||||
|
## -DHAVE_STDLIB Have <stdlib.h>.
|
||||||
|
## -DHAVE_TCGETATTR Have , .
|
||||||
|
## -DHAVE_TERMIO Have "struct termio" and <termio.h>
|
||||||
|
## (If neither of above two, we use <sgttyb.h> and BSD ioctl's)
|
||||||
|
## -DHIDE Make static functions static (non debug).
|
||||||
|
## -DHIST_SIZE=n History size.
|
||||||
|
## -DNEED_STRDUP Don't have .
|
||||||
|
## -DUNIQUE_HISTORY Don't save command if same as last one.
|
||||||
|
## -DUSE_DIRENT Use <dirent.h>, not <sys/dir.h>?
|
||||||
|
## -DUSE_TERMCAP Use the termcap library for terminal size
|
||||||
|
## see LDFLAGS, below, if you set this.
|
||||||
|
## -DNEED_PERROR Don't have (used in testit)
|
||||||
|
DEFS="-DANSI_ARROWS -DHAVE_STDLIB -DHAVE_TCGETATTR -DHIDE -DUSE_DIRENT \
|
||||||
|
-DHIST_SIZE=100 -DUSE_TERMCAP -DSYS_UNIX"
|
||||||
|
#-DNEED_STRDUP
|
||||||
|
|
||||||
|
CFLAGS="-O -D_MINIX -D_POSIX_SOURCE $DEFS -wo"
|
||||||
|
#CC1 = $(CC) $(CFLAGS) -c
|
||||||
|
|
||||||
|
## If you have -DUSE_TERMCAP, set this as appropriate:
|
||||||
|
#LDFLAGS = -ltermlib
|
||||||
|
#LDFLAGS = -ltermcap
|
||||||
|
|
||||||
|
## End of configuration.
|
||||||
|
|
||||||
|
#SOURCES = editline.c complete.c sysunix.c
|
||||||
|
#LIBRARY = ../libedit.a
|
||||||
|
LIBRARIES=libedit
|
||||||
|
#OBJECTS = editline.o complete.o sysunix.o
|
||||||
|
libedit_FILES="editline.c complete.c sysunix.c"
|
||||||
|
#SHARFILES = README Makefile editline.3 editline.h unix.h editline.c \
|
||||||
|
|
||||||
|
TYPE=both
|
||||||
|
#include ../Makefile.inc
|
||||||
|
|
||||||
|
#$(call ADDDEPENDENCIES,$(libedit_OBJECTS),editline.h)
|
59
README
Executable file
59
README
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
$Revision: 5 $
|
||||||
|
|
||||||
|
This is a line-editing library. It can be linked into almost any
|
||||||
|
program to provide command-line editing and recall.
|
||||||
|
|
||||||
|
It is call-compatible with the FSF readline library, but it is a
|
||||||
|
fraction of the size (and offers fewer features). It does not use
|
||||||
|
standard I/O. It is distributed under a "C News-like" copyright.
|
||||||
|
|
||||||
|
Configuration is done in the Makefile. Type "make testit" to get
|
||||||
|
a small slow shell for testing.
|
||||||
|
|
||||||
|
An earlier version was distributed with Byron's rc. Principal
|
||||||
|
changes over that version include:
|
||||||
|
Faster.
|
||||||
|
Is eight-bit clean (thanks to brendan@cs.widener.edu)
|
||||||
|
Written in K&R C, but ANSI compliant (gcc all warnings)
|
||||||
|
Propagates EOF properly; rc trip test now passes
|
||||||
|
Doesn't need or use or provide memmove.
|
||||||
|
More robust
|
||||||
|
Calling sequence changed to be compatible with readline.
|
||||||
|
Test program, new manpage, better configuration
|
||||||
|
More system-independant; includes Unix and OS-9 support.
|
||||||
|
|
||||||
|
This contains some changes since the posting to comp.sources.misc:
|
||||||
|
Bugfix for completion on absolute pathnames.
|
||||||
|
Better handling of M-n versus showing raw 8bit chars.
|
||||||
|
Better signal handling.
|
||||||
|
Now supports termios/termio/sgttyb ioctl's.
|
||||||
|
Add M-m command to toggle how 8bit data is displayed.
|
||||||
|
|
||||||
|
There is one known bug:
|
||||||
|
History-searching redraws the line wrong if the text
|
||||||
|
retrieved is shorter then the prompt.
|
||||||
|
|
||||||
|
Enjoy,
|
||||||
|
Rich $alz
|
||||||
|
<rsalz@osf.org>
|
||||||
|
|
||||||
|
Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||||
|
|
||||||
|
This software is not subject to any license of the American Telephone
|
||||||
|
and Telegraph Company or of the Regents of the University of California.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose on
|
||||||
|
any computer system, and to alter it and redistribute it freely, subject
|
||||||
|
to the following restrictions:
|
||||||
|
1. The authors are not responsible for the consequences of use of this
|
||||||
|
software, no matter how awful, even if they arise from flaws in it.
|
||||||
|
2. The origin of this software must not be misrepresented, either by
|
||||||
|
explicit claim or by omission. Since few users ever read sources,
|
||||||
|
credits must appear in the documentation.
|
||||||
|
3. Altered versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software. Since few users
|
||||||
|
ever read sources, credits must appear in the documentation.
|
||||||
|
4. This notice may not be removed or altered.
|
||||||
|
|
||||||
|
--
|
||||||
|
$PchId: README,v 1.3 1996/02/22 21:18:51 philip Exp $
|
254
complete.c
Executable file
254
complete.c
Executable file
@ -0,0 +1,254 @@
|
|||||||
|
/* $Revision: 5 $
|
||||||
|
**
|
||||||
|
** History and file completion functions for editline library.
|
||||||
|
*/
|
||||||
|
#include "editline.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(NEED_STRDUP)
|
||||||
|
/*
|
||||||
|
** Return an allocated copy of a string.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
strdup(p)
|
||||||
|
char *p;
|
||||||
|
{
|
||||||
|
char *new;
|
||||||
|
|
||||||
|
if ((new = NEW(char, strlen(p) + 1)) != NULL)
|
||||||
|
(void)strcpy(new, p);
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
#endif /* defined(NEED_STRDUP) */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** strcmp-like sorting predicate for qsort.
|
||||||
|
*/
|
||||||
|
STATIC int
|
||||||
|
compare(p1, p2)
|
||||||
|
CONST void *p1;
|
||||||
|
CONST void *p2;
|
||||||
|
{
|
||||||
|
CONST char **v1;
|
||||||
|
CONST char **v2;
|
||||||
|
|
||||||
|
v1 = (CONST char **)p1;
|
||||||
|
v2 = (CONST char **)p2;
|
||||||
|
return strcmp(*v1, *v2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Fill in *avp with an array of names that match file, up to its length.
|
||||||
|
** Ignore . and .. .
|
||||||
|
*/
|
||||||
|
STATIC int
|
||||||
|
FindMatches(dir, file, avp)
|
||||||
|
char *dir;
|
||||||
|
char *file;
|
||||||
|
char ***avp;
|
||||||
|
{
|
||||||
|
char **av;
|
||||||
|
char **new;
|
||||||
|
char *p;
|
||||||
|
DIR *dp;
|
||||||
|
DIRENTRY *ep;
|
||||||
|
SIZE_T ac;
|
||||||
|
SIZE_T len;
|
||||||
|
SIZE_T choices;
|
||||||
|
SIZE_T total;
|
||||||
|
#define MAX_TOTAL (256 << sizeof(char *))
|
||||||
|
|
||||||
|
if ((dp = opendir(dir)) == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
av = NULL;
|
||||||
|
ac = 0;
|
||||||
|
len = strlen(file);
|
||||||
|
choices = 0;
|
||||||
|
total = 0;
|
||||||
|
while ((ep = readdir(dp)) != NULL) {
|
||||||
|
p = ep->d_name;
|
||||||
|
if (p[0] == '.' && (p[1] == '\0' || (p[1] == '.' && p[2] == '\0')))
|
||||||
|
continue;
|
||||||
|
if (len && strncmp(p, file, len) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
choices++;
|
||||||
|
if ((total += strlen(p)) > MAX_TOTAL) {
|
||||||
|
/* This is a bit too much. */
|
||||||
|
while (ac > 0) DISPOSE(av[--ac]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ac % MEM_INC) == 0) {
|
||||||
|
if ((new = NEW(char*, ac + MEM_INC)) == NULL) {
|
||||||
|
total = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ac) {
|
||||||
|
COPYFROMTO(new, av, ac * sizeof (char **));
|
||||||
|
DISPOSE(av);
|
||||||
|
}
|
||||||
|
*avp = av = new;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((av[ac] = strdup(p)) == NULL) {
|
||||||
|
if (ac == 0)
|
||||||
|
DISPOSE(av);
|
||||||
|
total = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ac++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clean up and return. */
|
||||||
|
(void)closedir(dp);
|
||||||
|
if (total > MAX_TOTAL) {
|
||||||
|
char many[sizeof(total) * 3];
|
||||||
|
p = many + sizeof(many);
|
||||||
|
*--p = '\0';
|
||||||
|
while (choices > 0) {
|
||||||
|
*--p = '0' + choices % 10;
|
||||||
|
choices /= 10;
|
||||||
|
}
|
||||||
|
while (p > many + sizeof(many) - 8) *--p = ' ';
|
||||||
|
if ((p = strdup(p)) != NULL) av[ac++] = p;
|
||||||
|
if ((p = strdup("choices")) != NULL) av[ac++] = p;
|
||||||
|
} else {
|
||||||
|
if (ac)
|
||||||
|
qsort(av, ac, sizeof (char **), compare);
|
||||||
|
}
|
||||||
|
return ac;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Split a pathname into allocated directory and trailing filename parts.
|
||||||
|
*/
|
||||||
|
STATIC int
|
||||||
|
SplitPath(path, dirpart, filepart)
|
||||||
|
char *path;
|
||||||
|
char **dirpart;
|
||||||
|
char **filepart;
|
||||||
|
{
|
||||||
|
static char DOT[] = ".";
|
||||||
|
char *dpart;
|
||||||
|
char *fpart;
|
||||||
|
|
||||||
|
if ((fpart = strrchr(path, '/')) == NULL) {
|
||||||
|
if ((dpart = strdup(DOT)) == NULL)
|
||||||
|
return -1;
|
||||||
|
if ((fpart = strdup(path)) == NULL) {
|
||||||
|
DISPOSE(dpart);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ((dpart = strdup(path)) == NULL)
|
||||||
|
return -1;
|
||||||
|
dpart[fpart - path + 1] = '\0';
|
||||||
|
if ((fpart = strdup(++fpart)) == NULL) {
|
||||||
|
DISPOSE(dpart);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*dirpart = dpart;
|
||||||
|
*filepart = fpart;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Attempt to complete the pathname, returning an allocated copy.
|
||||||
|
** Fill in *unique if we completed it, or set it to 0 if ambiguous.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
rl_complete(pathname, unique)
|
||||||
|
char *pathname;
|
||||||
|
int *unique;
|
||||||
|
{
|
||||||
|
char **av;
|
||||||
|
char *dir;
|
||||||
|
char *file;
|
||||||
|
char *new;
|
||||||
|
char *p;
|
||||||
|
SIZE_T ac;
|
||||||
|
SIZE_T end;
|
||||||
|
SIZE_T i;
|
||||||
|
SIZE_T j;
|
||||||
|
SIZE_T len;
|
||||||
|
|
||||||
|
if (SplitPath(pathname, &dir, &file) < 0)
|
||||||
|
return NULL;
|
||||||
|
if ((ac = FindMatches(dir, file, &av)) == 0) {
|
||||||
|
DISPOSE(dir);
|
||||||
|
DISPOSE(file);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = NULL;
|
||||||
|
len = strlen(file);
|
||||||
|
if (ac == 1) {
|
||||||
|
/* Exactly one match -- finish it off. */
|
||||||
|
*unique = 1;
|
||||||
|
j = strlen(av[0]) - len + 2;
|
||||||
|
if ((p = NEW(char, j + 1)) != NULL) {
|
||||||
|
COPYFROMTO(p, av[0] + len, j);
|
||||||
|
if ((new = NEW(char, strlen(dir) + strlen(av[0]) + 2)) != NULL) {
|
||||||
|
(void)strcpy(new, dir);
|
||||||
|
(void)strcat(new, "/");
|
||||||
|
(void)strcat(new, av[0]);
|
||||||
|
rl_add_slash(new, p);
|
||||||
|
DISPOSE(new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*unique = 0;
|
||||||
|
if (len) {
|
||||||
|
/* Find largest matching substring. */
|
||||||
|
for (i = len, end = strlen(av[0]); i < end; i++)
|
||||||
|
for (j = 1; j < ac; j++)
|
||||||
|
if (av[0][i] != av[j][i])
|
||||||
|
goto breakout;
|
||||||
|
breakout:
|
||||||
|
if (i > len) {
|
||||||
|
j = i - len + 1;
|
||||||
|
if ((p = NEW(char, j)) != NULL) {
|
||||||
|
COPYFROMTO(p, av[0] + len, j);
|
||||||
|
p[j - 1] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clean up and return. */
|
||||||
|
DISPOSE(dir);
|
||||||
|
DISPOSE(file);
|
||||||
|
for (i = 0; i < ac; i++)
|
||||||
|
DISPOSE(av[i]);
|
||||||
|
DISPOSE(av);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Return all possible completions.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
rl_list_possib(pathname, avp)
|
||||||
|
char *pathname;
|
||||||
|
char ***avp;
|
||||||
|
{
|
||||||
|
char *dir;
|
||||||
|
char *file;
|
||||||
|
int ac;
|
||||||
|
|
||||||
|
if (SplitPath(pathname, &dir, &file) < 0)
|
||||||
|
return 0;
|
||||||
|
ac = FindMatches(dir, file, avp);
|
||||||
|
DISPOSE(dir);
|
||||||
|
DISPOSE(file);
|
||||||
|
return ac;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* $PchId: complete.c,v 1.3 1996/02/22 21:18:51 philip Exp $
|
||||||
|
*/
|
1471
editline.c
Executable file
1471
editline.c
Executable file
File diff suppressed because it is too large
Load Diff
79
editline.h
Executable file
79
editline.h
Executable file
@ -0,0 +1,79 @@
|
|||||||
|
/* $Revision: 5 $
|
||||||
|
**
|
||||||
|
** Internal header file for editline library.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#if defined(HAVE_STDLIB)
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#endif /* defined(HAVE_STDLIB) */
|
||||||
|
#if defined(SYS_UNIX)
|
||||||
|
#include "unix.h"
|
||||||
|
#endif /* defined(SYS_UNIX) */
|
||||||
|
#if defined(SYS_OS9)
|
||||||
|
#include "os9.h"
|
||||||
|
#endif /* defined(SYS_OS9) */
|
||||||
|
|
||||||
|
#if !defined(SIZE_T)
|
||||||
|
#define SIZE_T unsigned int
|
||||||
|
#endif /* !defined(SIZE_T) */
|
||||||
|
|
||||||
|
typedef unsigned char CHAR;
|
||||||
|
|
||||||
|
#if defined(HIDE)
|
||||||
|
#define STATIC static
|
||||||
|
#else
|
||||||
|
#define STATIC /* NULL */
|
||||||
|
#endif /* !defined(HIDE) */
|
||||||
|
|
||||||
|
#if !defined(CONST)
|
||||||
|
#if defined(__STDC__)
|
||||||
|
#define CONST const
|
||||||
|
#else
|
||||||
|
#define CONST
|
||||||
|
#endif /* defined(__STDC__) */
|
||||||
|
#endif /* !defined(CONST) */
|
||||||
|
|
||||||
|
|
||||||
|
#define MEM_INC 64
|
||||||
|
#define SCREEN_INC 256
|
||||||
|
|
||||||
|
#define DISPOSE(p) free((char *)(p))
|
||||||
|
#define NEW(T, c) \
|
||||||
|
((T *)malloc((unsigned int)(sizeof (T) * (c))))
|
||||||
|
#define RENEW(p, T, c) \
|
||||||
|
(p = (T *)realloc((char *)(p), (unsigned int)(sizeof (T) * (c))))
|
||||||
|
#define COPYFROMTO(new, p, len) \
|
||||||
|
(void)memcpy((char *)(new), (char *)(p), (int)(len))
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Variables and routines internal to this package.
|
||||||
|
*/
|
||||||
|
extern int rl_eof;
|
||||||
|
extern int rl_erase;
|
||||||
|
extern int rl_intr;
|
||||||
|
extern int rl_kill;
|
||||||
|
extern int rl_quit;
|
||||||
|
extern char *rl_complete();
|
||||||
|
extern int rl_list_possib();
|
||||||
|
extern void rl_ttyset();
|
||||||
|
extern void rl_add_slash();
|
||||||
|
|
||||||
|
#if !defined(HAVE_STDLIB)
|
||||||
|
extern char *getenv();
|
||||||
|
extern char *malloc();
|
||||||
|
extern char *realloc();
|
||||||
|
extern char *memcpy();
|
||||||
|
extern char *strcat();
|
||||||
|
extern char *strchr();
|
||||||
|
extern char *strrchr();
|
||||||
|
extern char *strcpy();
|
||||||
|
extern int strcmp();
|
||||||
|
extern int strlen();
|
||||||
|
extern int strncmp();
|
||||||
|
#endif /* !defined(HAVE_STDLIB) */
|
||||||
|
|
||||||
|
#if defined(NEED_STRDUP)
|
||||||
|
extern char *strdup();
|
||||||
|
#endif
|
120
sysunix.c
Executable file
120
sysunix.c
Executable file
@ -0,0 +1,120 @@
|
|||||||
|
/* $Revision: 5 $
|
||||||
|
**
|
||||||
|
** Unix system-dependant routines for editline library.
|
||||||
|
*/
|
||||||
|
#include "editline.h"
|
||||||
|
|
||||||
|
#if defined(HAVE_TCGETATTR)
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
rl_ttyset(Reset)
|
||||||
|
int Reset;
|
||||||
|
{
|
||||||
|
static struct termios old;
|
||||||
|
struct termios new;
|
||||||
|
|
||||||
|
if (Reset == 0) {
|
||||||
|
(void)tcgetattr(0, &old);
|
||||||
|
rl_erase = old.c_cc[VERASE];
|
||||||
|
rl_kill = old.c_cc[VKILL];
|
||||||
|
rl_eof = old.c_cc[VEOF];
|
||||||
|
rl_intr = old.c_cc[VINTR];
|
||||||
|
rl_quit = old.c_cc[VQUIT];
|
||||||
|
|
||||||
|
new = old;
|
||||||
|
new.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN);
|
||||||
|
new.c_iflag &= ~(ICRNL);
|
||||||
|
new.c_cc[VMIN] = 1;
|
||||||
|
new.c_cc[VTIME] = 0;
|
||||||
|
(void)tcsetattr(0, TCSADRAIN, &new);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
(void)tcsetattr(0, TCSADRAIN, &old);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#if defined(HAVE_TERMIO)
|
||||||
|
#include <termio.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
rl_ttyset(Reset)
|
||||||
|
int Reset;
|
||||||
|
{
|
||||||
|
static struct termio old;
|
||||||
|
struct termio new;
|
||||||
|
|
||||||
|
if (Reset == 0) {
|
||||||
|
(void)ioctl(0, TCGETA, &old);
|
||||||
|
rl_erase = old.c_cc[VERASE];
|
||||||
|
rl_kill = old.c_cc[VKILL];
|
||||||
|
rl_eof = old.c_cc[VEOF];
|
||||||
|
rl_intr = old.c_cc[VINTR];
|
||||||
|
rl_quit = old.c_cc[VQUIT];
|
||||||
|
|
||||||
|
new = old;
|
||||||
|
new.c_cc[VINTR] = -1;
|
||||||
|
new.c_cc[VQUIT] = -1;
|
||||||
|
new.c_lflag &= ~(ECHO | ICANON);
|
||||||
|
new.c_cc[VMIN] = 1;
|
||||||
|
new.c_cc[VTIME] = 0;
|
||||||
|
(void)ioctl(0, TCSETAW, &new);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
(void)ioctl(0, TCSETAW, &old);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#include <sgtty.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
rl_ttyset(Reset)
|
||||||
|
int Reset;
|
||||||
|
{
|
||||||
|
static struct sgttyb old_sgttyb;
|
||||||
|
static struct tchars old_tchars;
|
||||||
|
struct sgttyb new_sgttyb;
|
||||||
|
struct tchars new_tchars;
|
||||||
|
|
||||||
|
if (Reset == 0) {
|
||||||
|
(void)ioctl(0, TIOCGETP, &old_sgttyb);
|
||||||
|
rl_erase = old_sgttyb.sg_erase;
|
||||||
|
rl_kill = old_sgttyb.sg_kill;
|
||||||
|
|
||||||
|
(void)ioctl(0, TIOCGETC, &old_tchars);
|
||||||
|
rl_eof = old_tchars.t_eofc;
|
||||||
|
rl_intr = old_tchars.t_intrc;
|
||||||
|
rl_quit = old_tchars.t_quitc;
|
||||||
|
|
||||||
|
new_sgttyb = old_sgttyb;
|
||||||
|
new_sgttyb.sg_flags &= ~ECHO;
|
||||||
|
new_sgttyb.sg_flags |= RAW;
|
||||||
|
(void)ioctl(0, TIOCSETP, &new_sgttyb);
|
||||||
|
|
||||||
|
new_tchars = old_tchars;
|
||||||
|
new_tchars.t_intrc = -1;
|
||||||
|
new_tchars.t_quitc = -1;
|
||||||
|
(void)ioctl(0, TIOCSETC, &new_tchars);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
(void)ioctl(0, TIOCSETP, &old_sgttyb);
|
||||||
|
(void)ioctl(0, TIOCSETC, &old_tchars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* defined(HAVE_TERMIO) */
|
||||||
|
#endif /* defined(HAVE_TCGETATTR) */
|
||||||
|
|
||||||
|
void
|
||||||
|
rl_add_slash(path, p)
|
||||||
|
char *path;
|
||||||
|
char *p;
|
||||||
|
{
|
||||||
|
struct stat Sb;
|
||||||
|
|
||||||
|
if (stat(path, &Sb) >= 0)
|
||||||
|
(void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* $PchId: sysunix.c,v 1.4 1996/02/22 21:16:56 philip Exp $
|
||||||
|
*/
|
68
testit.c
Executable file
68
testit.c
Executable file
@ -0,0 +1,68 @@
|
|||||||
|
/* $Revision: 5 $
|
||||||
|
**
|
||||||
|
** A "micro-shell" to test editline library.
|
||||||
|
** If given any arguments, commands aren't executed.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#if defined(HAVE_STDLIB)
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif /* defined(HAVE_STDLIB) */
|
||||||
|
|
||||||
|
extern char *readline();
|
||||||
|
extern void add_history();
|
||||||
|
|
||||||
|
#if !defined(HAVE_STDLIB)
|
||||||
|
extern int chdir();
|
||||||
|
extern int free();
|
||||||
|
extern int strncmp();
|
||||||
|
extern int system();
|
||||||
|
extern void exit();
|
||||||
|
extern char *getenv();
|
||||||
|
#endif /* !defined(HAVE_STDLIB) */
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(NEED_PERROR)
|
||||||
|
void
|
||||||
|
perror(s)
|
||||||
|
char *s;
|
||||||
|
{
|
||||||
|
extern int errno;
|
||||||
|
|
||||||
|
(voidf)printf(stderr, "%s: error %d\n", s, errno);
|
||||||
|
}
|
||||||
|
#endif /* defined(NEED_PERROR) */
|
||||||
|
|
||||||
|
|
||||||
|
/* ARGSUSED1 */
|
||||||
|
int
|
||||||
|
main(ac, av)
|
||||||
|
int ac;
|
||||||
|
char *av[];
|
||||||
|
{
|
||||||
|
char *prompt;
|
||||||
|
char *p;
|
||||||
|
int doit;
|
||||||
|
|
||||||
|
doit = ac == 1;
|
||||||
|
if ((prompt = getenv("TESTPROMPT")) == NULL)
|
||||||
|
prompt = "testit> ";
|
||||||
|
|
||||||
|
while ((p = readline(prompt)) != NULL) {
|
||||||
|
(void)printf("\t\t\t|%s|\n", p);
|
||||||
|
if (doit)
|
||||||
|
if (strncmp(p, "cd ", 3) == 0) {
|
||||||
|
if (chdir(&p[3]) < 0)
|
||||||
|
perror(&p[3]);
|
||||||
|
}
|
||||||
|
else if (system(p) != 0)
|
||||||
|
perror(p);
|
||||||
|
add_history(p);
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* $PchId: testit.c,v 1.3 1996/02/22 21:18:51 philip Exp $
|
||||||
|
*/
|
26
unix.h
Executable file
26
unix.h
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
/* $Revision: 5 $
|
||||||
|
**
|
||||||
|
** Editline system header file for Unix.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define CRLF "\r\n"
|
||||||
|
#define FORWARD STATIC
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#if defined(USE_DIRENT)
|
||||||
|
#include <dirent.h>
|
||||||
|
typedef struct dirent DIRENTRY;
|
||||||
|
#else
|
||||||
|
#include <sys/dir.h>
|
||||||
|
typedef struct direct DIRENTRY;
|
||||||
|
#endif /* defined(USE_DIRENT) */
|
||||||
|
|
||||||
|
#if !defined(S_ISDIR)
|
||||||
|
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||||
|
#endif /* !defined(S_ISDIR) */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* $PchId: unix.h,v 1.3 1996/02/22 21:18:51 philip Exp $
|
||||||
|
*/
|
Loading…
Reference in New Issue
Block a user