mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 04:21:24 +08:00
ANSI-fication and lots of minor fixes inspired by Sparse warnings.
This commit is contained in:
parent
4c9c71faae
commit
34a314c8e7
@ -2,6 +2,9 @@
|
|||||||
#ifndef __EDITLINE_H__
|
#ifndef __EDITLINE_H__
|
||||||
#define __EDITLINE_H__
|
#define __EDITLINE_H__
|
||||||
|
|
||||||
|
/* Display print 8-bit chars as `M-x' or as the actual 8-bit char? (Default:1) */
|
||||||
|
extern int rl_meta_chars;
|
||||||
|
|
||||||
/* Assign these to get command completion, see cli.c for
|
/* Assign these to get command completion, see cli.c for
|
||||||
* example usage. */
|
* example usage. */
|
||||||
extern char *(*rl_complete)(char *token, int *match);
|
extern char *(*rl_complete)(char *token, int *match);
|
||||||
|
@ -532,7 +532,7 @@ static el_status_t h_last(void)
|
|||||||
/*
|
/*
|
||||||
** Return zero if pat appears as a substring in text.
|
** Return zero if pat appears as a substring in text.
|
||||||
*/
|
*/
|
||||||
static int substrcmp(char *text, char *pat, int len)
|
static int substrcmp(const char *text, const char *pat, size_t len)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
@ -549,7 +549,7 @@ static const char *search_hist(const char *search, const char *(*move)())
|
|||||||
static char *old_search;
|
static char *old_search;
|
||||||
int len;
|
int len;
|
||||||
int pos;
|
int pos;
|
||||||
int (*match)();
|
int (*match)(const char *s1, const char *s2, size_t n);
|
||||||
char *pat;
|
char *pat;
|
||||||
|
|
||||||
/* Save or get remembered search pattern. */
|
/* Save or get remembered search pattern. */
|
||||||
|
@ -24,14 +24,14 @@
|
|||||||
#endif
|
#endif
|
||||||
#ifdef SYS_UNIX
|
#ifdef SYS_UNIX
|
||||||
#include "unix.h"
|
#include "unix.h"
|
||||||
#endif /* defined(SYS_UNIX) */
|
#endif
|
||||||
#if defined(SYS_OS9)
|
#ifdef SYS_OS9
|
||||||
#include "os9.h"
|
#include "os9.h"
|
||||||
#endif /* defined(SYS_OS9) */
|
#endif
|
||||||
|
|
||||||
#if !defined(SIZE_T)
|
#ifndef SIZE_T
|
||||||
#define SIZE_T unsigned int
|
#define SIZE_T unsigned int
|
||||||
#endif /* !defined(SIZE_T) */
|
#endif
|
||||||
|
|
||||||
typedef unsigned char CHAR;
|
typedef unsigned char CHAR;
|
||||||
|
|
||||||
@ -39,13 +39,9 @@ typedef unsigned char CHAR;
|
|||||||
#define SCREEN_INC 256
|
#define SCREEN_INC 256
|
||||||
|
|
||||||
#define DISPOSE(p) free((char *)(p))
|
#define DISPOSE(p) free((char *)(p))
|
||||||
#define NEW(T, c) \
|
#define NEW(T, c) ((T *)malloc((unsigned int)(sizeof (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 RENEW(p, T, c) \
|
#define COPYFROMTO(new, p, len) (void)memcpy((char *)(new), (char *)(p), (int)(len))
|
||||||
(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.
|
** Variables and routines internal to this package.
|
||||||
@ -55,17 +51,17 @@ extern int rl_erase;
|
|||||||
extern int rl_intr;
|
extern int rl_intr;
|
||||||
extern int rl_kill;
|
extern int rl_kill;
|
||||||
extern int rl_quit;
|
extern int rl_quit;
|
||||||
#if defined(DO_SIGTSTP)
|
#ifdef DO_SIGTSTP
|
||||||
extern int rl_susp;
|
extern int rl_susp;
|
||||||
#endif /* defined(DO_SIGTSTP) */
|
#endif
|
||||||
#ifdef COMPLETE
|
#ifdef COMPLETE
|
||||||
extern char *default_rl_complete();
|
extern char *default_rl_complete();
|
||||||
extern int default_rl_list_possib(char *pathname, char ***avp);
|
extern int default_rl_list_possib(char *pathname, char ***avp);
|
||||||
#endif
|
#endif
|
||||||
extern void rl_ttyset();
|
extern void rl_ttyset(int Reset);
|
||||||
extern void rl_add_slash();
|
extern void rl_add_slash(char *path, char *p);
|
||||||
|
|
||||||
#if !defined(HAVE_STDLIB_H)
|
#ifndef HAVE_STDLIB_H
|
||||||
extern char *getenv();
|
extern char *getenv();
|
||||||
extern char *malloc();
|
extern char *malloc();
|
||||||
extern char *realloc();
|
extern char *realloc();
|
||||||
@ -78,10 +74,10 @@ extern char *strdup();
|
|||||||
extern int strcmp();
|
extern int strcmp();
|
||||||
extern int strlen();
|
extern int strlen();
|
||||||
extern int strncmp();
|
extern int strncmp();
|
||||||
#endif /* !defined(HAVE_STDLIB) */
|
#endif/* !HAVE_STDLIB */
|
||||||
|
|
||||||
#if defined(NEED_STRDUP)
|
#ifdef NEED_STRDUP
|
||||||
extern char *strdup();
|
extern char *strdup(const char *s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../include/editline.h"
|
#include "../include/editline.h"
|
||||||
|
@ -7,9 +7,7 @@
|
|||||||
#if defined(HAVE_TCGETATTR)
|
#if defined(HAVE_TCGETATTR)
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
||||||
void
|
void rl_ttyset(int Reset)
|
||||||
rl_ttyset(Reset)
|
|
||||||
int Reset;
|
|
||||||
{
|
{
|
||||||
static struct termios old;
|
static struct termios old;
|
||||||
struct termios new;
|
struct termios new;
|
||||||
@ -21,9 +19,9 @@ rl_ttyset(Reset)
|
|||||||
rl_eof = old.c_cc[VEOF];
|
rl_eof = old.c_cc[VEOF];
|
||||||
rl_intr = old.c_cc[VINTR];
|
rl_intr = old.c_cc[VINTR];
|
||||||
rl_quit = old.c_cc[VQUIT];
|
rl_quit = old.c_cc[VQUIT];
|
||||||
#if defined(DO_SIGTSTP)
|
#ifdef DO_SIGTSTP
|
||||||
rl_susp = old.c_cc[VSUSP];
|
rl_susp = old.c_cc[VSUSP];
|
||||||
#endif /* defined(DO_SIGTSTP) */
|
#endif
|
||||||
|
|
||||||
new = old;
|
new = old;
|
||||||
new.c_lflag &= ~(ECHO | ICANON | ISIG);
|
new.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||||
@ -31,18 +29,15 @@ rl_ttyset(Reset)
|
|||||||
new.c_cc[VMIN] = 1;
|
new.c_cc[VMIN] = 1;
|
||||||
new.c_cc[VTIME] = 0;
|
new.c_cc[VTIME] = 0;
|
||||||
if (tcsetattr(0, TCSADRAIN, &new) < 0) perror("tcsetattr");
|
if (tcsetattr(0, TCSADRAIN, &new) < 0) perror("tcsetattr");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
(void)tcsetattr(0, TCSADRAIN, &old);
|
(void)tcsetattr(0, TCSADRAIN, &old);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#elif defined(HAVE_TERMIO_H)
|
||||||
#if defined(HAVE_TERMIO_H)
|
|
||||||
#include <termio.h>
|
#include <termio.h>
|
||||||
|
|
||||||
void
|
void rl_ttyset(int Reset)
|
||||||
rl_ttyset(Reset)
|
|
||||||
int Reset;
|
|
||||||
{
|
{
|
||||||
static struct termio old;
|
static struct termio old;
|
||||||
struct termio new;
|
struct termio new;
|
||||||
@ -54,9 +49,9 @@ rl_ttyset(Reset)
|
|||||||
rl_eof = old.c_cc[VEOF];
|
rl_eof = old.c_cc[VEOF];
|
||||||
rl_intr = old.c_cc[VINTR];
|
rl_intr = old.c_cc[VINTR];
|
||||||
rl_quit = old.c_cc[VQUIT];
|
rl_quit = old.c_cc[VQUIT];
|
||||||
#if defined(DO_SIGTSTP)
|
#ifdef DO_SIGTSTP
|
||||||
rl_susp = old.c_cc[VSUSP];
|
rl_susp = old.c_cc[VSUSP];
|
||||||
#endif /* defined(DO_SIGTSTP) */
|
#endif
|
||||||
|
|
||||||
new = old;
|
new = old;
|
||||||
new.c_lflag &= ~(ECHO | ICANON | ISIG);
|
new.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||||
@ -64,25 +59,23 @@ rl_ttyset(Reset)
|
|||||||
new.c_cc[VMIN] = 1;
|
new.c_cc[VMIN] = 1;
|
||||||
new.c_cc[VTIME] = 0;
|
new.c_cc[VTIME] = 0;
|
||||||
(void)ioctl(0, TCSETAW, &new);
|
(void)ioctl(0, TCSETAW, &new);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
(void)ioctl(0, TCSETAW, &old);
|
(void)ioctl(0, TCSETAW, &old);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else /* Neither HAVE_TERMIO_H or HAVE_TCGETATTR */
|
||||||
#include <sgtty.h>
|
#include <sgtty.h>
|
||||||
|
|
||||||
void
|
void rl_ttyset(int Reset)
|
||||||
rl_ttyset(Reset)
|
|
||||||
int Reset;
|
|
||||||
{
|
{
|
||||||
static struct sgttyb old_sgttyb;
|
static struct sgttyb old_sgttyb;
|
||||||
static struct tchars old_tchars;
|
static struct tchars old_tchars;
|
||||||
struct sgttyb new_sgttyb;
|
struct sgttyb new_sgttyb;
|
||||||
struct tchars new_tchars;
|
struct tchars new_tchars;
|
||||||
#if defined(DO_SIGTSTP)
|
#ifdef DO_SIGTSTP
|
||||||
struct ltchars old_ltchars;
|
struct ltchars old_ltchars;
|
||||||
#endif /* defined(DO_SIGTSTP) */
|
#endif
|
||||||
|
|
||||||
if (Reset == 0) {
|
if (Reset == 0) {
|
||||||
(void)ioctl(0, TIOCGETP, &old_sgttyb);
|
(void)ioctl(0, TIOCGETP, &old_sgttyb);
|
||||||
@ -94,36 +87,31 @@ rl_ttyset(Reset)
|
|||||||
rl_intr = old_tchars.t_intrc;
|
rl_intr = old_tchars.t_intrc;
|
||||||
rl_quit = old_tchars.t_quitc;
|
rl_quit = old_tchars.t_quitc;
|
||||||
|
|
||||||
#if defined(DO_SIGTSTP)
|
#ifdef DO_SIGTSTP
|
||||||
(void)ioctl(0, TIOCGLTC, &old_ltchars);
|
(void)ioctl(0, TIOCGLTC, &old_ltchars);
|
||||||
rl_susp = old_ltchars.t_suspc;
|
rl_susp = old_ltchars.t_suspc;
|
||||||
#endif /* defined(DO_SIGTSTP) */
|
#endif
|
||||||
|
|
||||||
new_sgttyb = old_sgttyb;
|
new_sgttyb = old_sgttyb;
|
||||||
new_sgttyb.sg_flags &= ~ECHO;
|
new_sgttyb.sg_flags &= ~ECHO;
|
||||||
new_sgttyb.sg_flags |= RAW;
|
new_sgttyb.sg_flags |= RAW;
|
||||||
#if defined(PASS8)
|
#ifdef PASS8
|
||||||
new_sgttyb.sg_flags |= PASS8;
|
new_sgttyb.sg_flags |= PASS8;
|
||||||
#endif /* defined(PASS8) */
|
#endif
|
||||||
(void)ioctl(0, TIOCSETP, &new_sgttyb);
|
(void)ioctl(0, TIOCSETP, &new_sgttyb);
|
||||||
|
|
||||||
new_tchars = old_tchars;
|
new_tchars = old_tchars;
|
||||||
new_tchars.t_intrc = -1;
|
new_tchars.t_intrc = -1;
|
||||||
new_tchars.t_quitc = -1;
|
new_tchars.t_quitc = -1;
|
||||||
(void)ioctl(0, TIOCSETC, &new_tchars);
|
(void)ioctl(0, TIOCSETC, &new_tchars);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
(void)ioctl(0, TIOCSETP, &old_sgttyb);
|
(void)ioctl(0, TIOCSETP, &old_sgttyb);
|
||||||
(void)ioctl(0, TIOCSETC, &old_tchars);
|
(void)ioctl(0, TIOCSETC, &old_tchars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* defined(HAVE_TERMIO_H) */
|
#endif /* Neither HAVE_TERMIO_H or HAVE_TCGETATTR */
|
||||||
#endif /* defined(HAVE_TCGETATTR) */
|
|
||||||
|
|
||||||
void
|
void rl_add_slash(char *path, char *p)
|
||||||
rl_add_slash(path, p)
|
|
||||||
char *path;
|
|
||||||
char *p;
|
|
||||||
{
|
{
|
||||||
struct stat Sb;
|
struct stat Sb;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user