ANSI-fication and lots of minor fixes inspired by Sparse warnings.

This commit is contained in:
Joachim Nilsson 2010-07-17 22:38:05 +02:00
parent 4c9c71faae
commit 34a314c8e7
4 changed files with 45 additions and 58 deletions

View File

@ -2,6 +2,9 @@
#ifndef __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
* example usage. */
extern char *(*rl_complete)(char *token, int *match);

View File

@ -532,7 +532,7 @@ static el_status_t h_last(void)
/*
** 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;
@ -549,7 +549,7 @@ static const char *search_hist(const char *search, const char *(*move)())
static char *old_search;
int len;
int pos;
int (*match)();
int (*match)(const char *s1, const char *s2, size_t n);
char *pat;
/* Save or get remembered search pattern. */

View File

@ -24,28 +24,24 @@
#endif
#ifdef SYS_UNIX
#include "unix.h"
#endif /* defined(SYS_UNIX) */
#if defined(SYS_OS9)
#endif
#ifdef SYS_OS9
#include "os9.h"
#endif /* defined(SYS_OS9) */
#endif
#if !defined(SIZE_T)
#ifndef SIZE_T
#define SIZE_T unsigned int
#endif /* !defined(SIZE_T) */
#endif
typedef unsigned char CHAR;
#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))
#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.
@ -55,17 +51,17 @@ extern int rl_erase;
extern int rl_intr;
extern int rl_kill;
extern int rl_quit;
#if defined(DO_SIGTSTP)
#ifdef DO_SIGTSTP
extern int rl_susp;
#endif /* defined(DO_SIGTSTP) */
#endif
#ifdef COMPLETE
extern char *default_rl_complete();
extern int default_rl_list_possib(char *pathname, char ***avp);
#endif
extern void rl_ttyset();
extern void rl_add_slash();
extern void rl_ttyset(int Reset);
extern void rl_add_slash(char *path, char *p);
#if !defined(HAVE_STDLIB_H)
#ifndef HAVE_STDLIB_H
extern char *getenv();
extern char *malloc();
extern char *realloc();
@ -78,10 +74,10 @@ extern char *strdup();
extern int strcmp();
extern int strlen();
extern int strncmp();
#endif /* !defined(HAVE_STDLIB) */
#endif/* !HAVE_STDLIB */
#if defined(NEED_STRDUP)
extern char *strdup();
#ifdef NEED_STRDUP
extern char *strdup(const char *s);
#endif
#include "../include/editline.h"

View File

@ -4,12 +4,10 @@
*/
#include "editline.h"
#if defined(HAVE_TCGETATTR)
#if defined(HAVE_TCGETATTR)
#include <termios.h>
void
rl_ttyset(Reset)
int Reset;
void rl_ttyset(int Reset)
{
static struct termios old;
struct termios new;
@ -21,9 +19,9 @@ rl_ttyset(Reset)
rl_eof = old.c_cc[VEOF];
rl_intr = old.c_cc[VINTR];
rl_quit = old.c_cc[VQUIT];
#if defined(DO_SIGTSTP)
#ifdef DO_SIGTSTP
rl_susp = old.c_cc[VSUSP];
#endif /* defined(DO_SIGTSTP) */
#endif
new = old;
new.c_lflag &= ~(ECHO | ICANON | ISIG);
@ -31,18 +29,15 @@ rl_ttyset(Reset)
new.c_cc[VMIN] = 1;
new.c_cc[VTIME] = 0;
if (tcsetattr(0, TCSADRAIN, &new) < 0) perror("tcsetattr");
}
else
} else {
(void)tcsetattr(0, TCSADRAIN, &old);
}
}
#else
#if defined(HAVE_TERMIO_H)
#elif defined(HAVE_TERMIO_H)
#include <termio.h>
void
rl_ttyset(Reset)
int Reset;
void rl_ttyset(int Reset)
{
static struct termio old;
struct termio new;
@ -54,9 +49,9 @@ rl_ttyset(Reset)
rl_eof = old.c_cc[VEOF];
rl_intr = old.c_cc[VINTR];
rl_quit = old.c_cc[VQUIT];
#if defined(DO_SIGTSTP)
#ifdef DO_SIGTSTP
rl_susp = old.c_cc[VSUSP];
#endif /* defined(DO_SIGTSTP) */
#endif
new = old;
new.c_lflag &= ~(ECHO | ICANON | ISIG);
@ -64,25 +59,23 @@ rl_ttyset(Reset)
new.c_cc[VMIN] = 1;
new.c_cc[VTIME] = 0;
(void)ioctl(0, TCSETAW, &new);
}
else
} else {
(void)ioctl(0, TCSETAW, &old);
}
}
#else
#else /* Neither HAVE_TERMIO_H or HAVE_TCGETATTR */
#include <sgtty.h>
void
rl_ttyset(Reset)
int Reset;
void rl_ttyset(int Reset)
{
static struct sgttyb old_sgttyb;
static struct tchars old_tchars;
struct sgttyb new_sgttyb;
struct tchars new_tchars;
#if defined(DO_SIGTSTP)
#ifdef DO_SIGTSTP
struct ltchars old_ltchars;
#endif /* defined(DO_SIGTSTP) */
#endif
if (Reset == 0) {
(void)ioctl(0, TIOCGETP, &old_sgttyb);
@ -94,36 +87,31 @@ rl_ttyset(Reset)
rl_intr = old_tchars.t_intrc;
rl_quit = old_tchars.t_quitc;
#if defined(DO_SIGTSTP)
#ifdef DO_SIGTSTP
(void)ioctl(0, TIOCGLTC, &old_ltchars);
rl_susp = old_ltchars.t_suspc;
#endif /* defined(DO_SIGTSTP) */
#endif
new_sgttyb = old_sgttyb;
new_sgttyb.sg_flags &= ~ECHO;
new_sgttyb.sg_flags |= RAW;
#if defined(PASS8)
#ifdef PASS8
new_sgttyb.sg_flags |= PASS8;
#endif /* defined(PASS8) */
#endif
(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 {
} else {
(void)ioctl(0, TIOCSETP, &old_sgttyb);
(void)ioctl(0, TIOCSETC, &old_tchars);
}
}
#endif /* defined(HAVE_TERMIO_H) */
#endif /* defined(HAVE_TCGETATTR) */
#endif /* Neither HAVE_TERMIO_H or HAVE_TCGETATTR */
void
rl_add_slash(path, p)
char *path;
char *p;
void rl_add_slash(char *path, char *p)
{
struct stat Sb;