nuke NEW, DISPOSE, RENEW, and COPYFROMTO macros

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5885 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1999-04-08 13:40:59 +00:00
parent 86cb7cdfe4
commit 98c988dd10
2 changed files with 51 additions and 47 deletions

View File

@@ -114,9 +114,10 @@ int rl_meta_chars = 1;
/* /*
** Declarations. ** Declarations.
*/ */
static unsigned char *editinput(); static unsigned char *editinput(void);
extern char *tgetstr(); char *tgetstr(const char*, char**);
extern int tgetent(); int tgetent(char*, const char*);
int tgetnum(const char*);
/* /*
** TTY input/output functions. ** TTY input/output functions.
@@ -137,7 +138,7 @@ TTYput(unsigned char c)
Screen[ScreenCount] = c; Screen[ScreenCount] = c;
if (++ScreenCount >= ScreenSize - 1) { if (++ScreenCount >= ScreenSize - 1) {
ScreenSize += SCREEN_INC; ScreenSize += SCREEN_INC;
RENEW(Screen, char, ScreenSize); Screen = realloc(Screen, ScreenSize);
} }
} }
@@ -460,11 +461,11 @@ insert_string(unsigned char *p)
len = strlen((char *)p); len = strlen((char *)p);
if (End + len >= Length) { if (End + len >= Length) {
if ((new = NEW(unsigned char, Length + len + MEM_INC)) == NULL) if ((new = malloc(sizeof(unsigned char) * (Length + len + MEM_INC))) == NULL)
return CSstay; return CSstay;
if (Length) { if (Length) {
COPYFROMTO(new, Line, Length); memcpy(new, Line, Length);
DISPOSE(Line); free(Line);
} }
Line = new; Line = new;
Length += len + MEM_INC; Length += len + MEM_INC;
@@ -472,7 +473,7 @@ insert_string(unsigned char *p)
for (q = &Line[Point], i = End - Point; --i >= 0; ) for (q = &Line[Point], i = End - Point; --i >= 0; )
q[len + i] = q[i]; q[len + i] = q[i];
COPYFROMTO(&Line[Point], p, len); memcpy(&Line[Point], p, len);
End += len; End += len;
Line[End] = '\0'; Line[End] = '\0';
TTYstring(&Line[Point]); TTYstring(&Line[Point]);
@@ -572,7 +573,7 @@ search_hist(unsigned char *search, unsigned char *(*move)())
/* Save or get remembered search pattern. */ /* Save or get remembered search pattern. */
if (search && *search) { if (search && *search) {
if (old_search) if (old_search)
DISPOSE(old_search); free(old_search);
old_search = (unsigned char *)strdup((char *)search); old_search = (unsigned char *)strdup((char *)search);
} }
else { else {
@@ -643,16 +644,16 @@ static void
save_yank(int begin, int i) save_yank(int begin, int i)
{ {
if (Yanked) { if (Yanked) {
DISPOSE(Yanked); free(Yanked);
Yanked = NULL; Yanked = NULL;
} }
if (i < 1) if (i < 1)
return; return;
if ((Yanked = NEW(unsigned char, (size_t)i + 1)) != NULL) { if ((Yanked = malloc(sizeof(unsigned char) * (i + 1))) != NULL) {
COPYFROMTO(Yanked, &Line[begin], i); memcpy(Yanked, &Line[begin], i);
Yanked[i] = '\0'; Yanked[i+1] = '\0';
} }
} }
@@ -778,14 +779,14 @@ insert_char(int c)
return insert_string(buff); return insert_string(buff);
} }
if ((p = NEW(unsigned char, Repeat + 1)) == NULL) if ((p = malloc(Repeat + 1)) == NULL)
return CSstay; return CSstay;
for (i = Repeat, q = p; --i >= 0; ) for (i = Repeat, q = p; --i >= 0; )
*q++ = c; *q++ = c;
*q = '\0'; *q = '\0';
Repeat = 0; Repeat = 0;
s = insert_string(p); s = insert_string(p);
DISPOSE(p); free(p);
return s; return s;
} }
@@ -921,7 +922,7 @@ hist_add(unsigned char *p)
if (H.Size < HIST_SIZE) if (H.Size < HIST_SIZE)
H.Lines[H.Size++] = p; H.Lines[H.Size++] = p;
else { else {
DISPOSE(H.Lines[0]); free(H.Lines[0]);
for (i = 0; i < HIST_SIZE - 1; i++) for (i = 0; i < HIST_SIZE - 1; i++)
H.Lines[i] = H.Lines[i + 1]; H.Lines[i] = H.Lines[i + 1];
H.Lines[i] = p; H.Lines[i] = p;
@@ -939,7 +940,7 @@ rl_reset_terminal(char *p)
} }
void void
rl_initialize() rl_initialize(void)
{ {
} }
@@ -950,7 +951,7 @@ readline(const char* prompt)
if (Line == NULL) { if (Line == NULL) {
Length = MEM_INC; Length = MEM_INC;
if ((Line = NEW(unsigned char, Length)) == NULL) if ((Line = malloc(Length)) == NULL)
return NULL; return NULL;
} }
@@ -958,7 +959,7 @@ readline(const char* prompt)
rl_ttyset(0); rl_ttyset(0);
hist_add(NIL); hist_add(NIL);
ScreenSize = SCREEN_INC; ScreenSize = SCREEN_INC;
Screen = NEW(char, ScreenSize); Screen = malloc(ScreenSize);
Prompt = prompt ? prompt : (char *)NIL; Prompt = prompt ? prompt : (char *)NIL;
TTYputs((unsigned char *)Prompt); TTYputs((unsigned char *)Prompt);
if ((line = editinput()) != NULL) { if ((line = editinput()) != NULL) {
@@ -967,8 +968,8 @@ readline(const char* prompt)
TTYflush(); TTYflush();
} }
rl_ttyset(1); rl_ttyset(1);
DISPOSE(Screen); free(Screen);
DISPOSE(H.Lines[--H.Size]); free(H.Lines[--H.Size]);
return (char *)line; return (char *)line;
} }
@@ -1027,9 +1028,9 @@ find_word()
for (p = &Line[Point]; p > Line && strchr(SEPS, (char)p[-1]) == NULL; p--) for (p = &Line[Point]; p > Line && strchr(SEPS, (char)p[-1]) == NULL; p--)
continue; continue;
len = Point - (p - Line) + 1; len = Point - (p - Line) + 1;
if ((new = NEW(unsigned char, len)) == NULL) if ((new = malloc(len)) == NULL)
return NULL; return NULL;
COPYFROMTO(new, p, len); memcpy(new, p, len);
new[len - 1] = '\0'; new[len - 1] = '\0';
return new; return new;
} }
@@ -1045,12 +1046,12 @@ c_complete()
word = find_word(); word = find_word();
p = (unsigned char *)rl_complete((char *)word, &unique); p = (unsigned char *)rl_complete((char *)word, &unique);
if (word) if (word)
DISPOSE(word); free(word);
if (p && *p) { if (p && *p) {
s = insert_string(p); s = insert_string(p);
if (!unique) if (!unique)
ring_bell(); ring_bell();
DISPOSE(p); free(p);
return s; return s;
} }
return ring_bell(); return ring_bell();
@@ -1066,12 +1067,12 @@ c_possible()
word = find_word(); word = find_word();
ac = rl_list_possib((char *)word, (char ***)&av); ac = rl_list_possib((char *)word, (char ***)&av);
if (word) if (word)
DISPOSE(word); free(word);
if (ac) { if (ac) {
columns(ac, av); columns(ac, av);
while (--ac >= 0) while (--ac >= 0)
DISPOSE(av[ac]); free(av[ac]);
DISPOSE(av); free(av);
return CSmove; return CSmove;
} }
return ring_bell(); return ring_bell();
@@ -1250,7 +1251,7 @@ argify(unsigned char *line, unsigned char ***avp)
int i; int i;
i = MEM_INC; i = MEM_INC;
if ((*avp = p = NEW(unsigned char*, i))== NULL) if ((*avp = p = malloc(sizeof(unsigned char*) * i))== NULL)
return 0; return 0;
for (c = line; isspace(*c); c++) for (c = line; isspace(*c); c++)
@@ -1263,14 +1264,14 @@ argify(unsigned char *line, unsigned char ***avp)
*c++ = '\0'; *c++ = '\0';
if (*c && *c != '\n') { if (*c && *c != '\n') {
if (ac + 1 == i) { if (ac + 1 == i) {
new = NEW(unsigned char*, i + MEM_INC); new = malloc(sizeof(unsigned char*) * (i + MEM_INC));
if (new == NULL) { if (new == NULL) {
p[ac] = NULL; p[ac] = NULL;
return ac; return ac;
} }
COPYFROMTO(new, p, i * sizeof (char **)); memcpy(new, p, i * sizeof (char **));
i += MEM_INC; i += MEM_INC;
DISPOSE(p); free(p);
*avp = p = new; *avp = p = new;
} }
p[ac++] = c; p[ac++] = c;
@@ -1305,8 +1306,8 @@ last_argument()
s = ac ? insert_string(av[ac - 1]) : CSstay; s = ac ? insert_string(av[ac - 1]) : CSstay;
if (ac) if (ac)
DISPOSE(av); free(av);
DISPOSE(p); free(p);
return s; return s;
} }

View File

@@ -38,15 +38,6 @@ typedef unsigned char CHAR;
#define MEM_INC 64 #define MEM_INC 64
#define SCREEN_INC 256 #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. ** Variables and routines internal to this package.
*/ */
@@ -55,7 +46,19 @@ 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;
extern char *rl_complete(char *, int *);
extern int rl_list_possib(char *, char ***); typedef char* (*rl_complete_func_t)(char*, int*);
extern void rl_ttyset(int);
extern void rl_add_slash(char *, char *); typedef int (*rl_list_possib_func_t)(char*, char***);
void add_history (char*);
char* readline (const char* prompt);
void rl_add_slash (char*, char*);
char* rl_complete (char*, int*);
void rl_initialize (void);
int rl_list_possib (char*, char***);
void rl_reset_terminal (char*);
void rl_ttyset (int);
rl_complete_func_t rl_set_complete_func (rl_complete_func_t);
rl_list_possib_func_t rl_set_list_possib_func (rl_list_possib_func_t);