mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 12:31:45 +08:00
Nuke NEW, DISPOSE, RENEW, and COPYFROMTO macros, by Johan Danielsson
This is a manual merge of 98c988dd10888cfb72c4 from http://github.com/heimdal/heimdal
This commit is contained in:
parent
64219dc1f0
commit
511a1a65a4
@ -27,12 +27,14 @@
|
|||||||
/* Return an allocated copy of a string. */
|
/* Return an allocated copy of a string. */
|
||||||
char *strdup(const char *p)
|
char *strdup(const char *p)
|
||||||
{
|
{
|
||||||
char *new;
|
char *new = malloc(sizeof(char) * strlen(p));
|
||||||
|
|
||||||
if ((new = NEW(char, strlen(p) + 1)) != NULL)
|
|
||||||
(void)strcpy(new, p);
|
|
||||||
|
|
||||||
|
if (new) {
|
||||||
|
strcpy(new, p);
|
||||||
return new;
|
return new;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -77,25 +79,26 @@ static int FindMatches(char *dir, char *file, char ***avp)
|
|||||||
choices++;
|
choices++;
|
||||||
if ((total += strlen(p)) > MAX_TOTAL_MATCHES) {
|
if ((total += strlen(p)) > MAX_TOTAL_MATCHES) {
|
||||||
/* This is a bit too much. */
|
/* This is a bit too much. */
|
||||||
while (ac > 0) DISPOSE(av[--ac]);
|
while (ac > 0) free(av[--ac]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ac % MEM_INC) == 0) {
|
if ((ac % MEM_INC) == 0) {
|
||||||
if ((new = NEW(char*, ac + MEM_INC)) == NULL) {
|
new = malloc(sizeof(char *) * (ac + MEM_INC));
|
||||||
|
if (!new) {
|
||||||
total = 0;
|
total = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ac) {
|
if (ac) {
|
||||||
COPYFROMTO(new, av, ac * sizeof (char **));
|
memcpy(new, av, ac * sizeof(char **));
|
||||||
DISPOSE(av);
|
free(av);
|
||||||
}
|
}
|
||||||
*avp = av = new;
|
*avp = av = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((av[ac] = strdup(p)) == NULL) {
|
if ((av[ac] = strdup(p)) == NULL) {
|
||||||
if (ac == 0)
|
if (ac == 0)
|
||||||
DISPOSE(av);
|
free(av);
|
||||||
total = 0;
|
total = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -134,7 +137,7 @@ static int SplitPath(char *path, char **dirpart, char **filepart)
|
|||||||
if ((dpart = strdup(DOT)) == NULL)
|
if ((dpart = strdup(DOT)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
if ((fpart = strdup(path)) == NULL) {
|
if ((fpart = strdup(path)) == NULL) {
|
||||||
DISPOSE(dpart);
|
free(dpart);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +146,7 @@ static int SplitPath(char *path, char **dirpart, char **filepart)
|
|||||||
return -1;
|
return -1;
|
||||||
dpart[fpart - path + 1] = '\0';
|
dpart[fpart - path + 1] = '\0';
|
||||||
if ((fpart = strdup(++fpart)) == NULL) {
|
if ((fpart = strdup(++fpart)) == NULL) {
|
||||||
DISPOSE(dpart);
|
free(dpart);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,8 +175,8 @@ char *default_rl_complete(char *pathname, int *unique)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((ac = FindMatches(dir, file, &av)) == 0) {
|
if ((ac = FindMatches(dir, file, &av)) == 0) {
|
||||||
DISPOSE(dir);
|
free(dir);
|
||||||
DISPOSE(file);
|
free(file);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -184,13 +187,15 @@ char *default_rl_complete(char *pathname, int *unique)
|
|||||||
/* Exactly one match -- finish it off. */
|
/* Exactly one match -- finish it off. */
|
||||||
*unique = 1;
|
*unique = 1;
|
||||||
j = strlen(av[0]) - len + 2;
|
j = strlen(av[0]) - len + 2;
|
||||||
if ((p = NEW(char, j + 1)) != NULL) {
|
p = malloc(sizeof(char) * (j + 1));
|
||||||
COPYFROMTO(p, av[0] + len, j);
|
if (p) {
|
||||||
|
memcpy(p, av[0] + len, j);
|
||||||
len = strlen(dir) + strlen(av[0]) + 2;
|
len = strlen(dir) + strlen(av[0]) + 2;
|
||||||
if ((new = NEW(char, len)) != NULL) {
|
new = malloc(sizeof(char) * len);
|
||||||
|
if (new) {
|
||||||
snprintf(new, len, "%s/%s", dir, av[0]);
|
snprintf(new, len, "%s/%s", dir, av[0]);
|
||||||
rl_add_slash(new, p);
|
rl_add_slash(new, p);
|
||||||
DISPOSE(new);
|
free(new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,8 +210,9 @@ char *default_rl_complete(char *pathname, int *unique)
|
|||||||
breakout:
|
breakout:
|
||||||
if (i > len) {
|
if (i > len) {
|
||||||
j = i - len + 1;
|
j = i - len + 1;
|
||||||
if ((p = NEW(char, j)) != NULL) {
|
p = malloc(sizeof(char) * j);
|
||||||
COPYFROMTO(p, av[0] + len, j);
|
if (p) {
|
||||||
|
memcpy(p, av[0] + len, j);
|
||||||
p[j - 1] = '\0';
|
p[j - 1] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,11 +220,11 @@ char *default_rl_complete(char *pathname, int *unique)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up and return. */
|
/* Clean up and return. */
|
||||||
DISPOSE(dir);
|
free(dir);
|
||||||
DISPOSE(file);
|
free(file);
|
||||||
for (i = 0; i < ac; i++)
|
for (i = 0; i < ac; i++)
|
||||||
DISPOSE(av[i]);
|
free(av[i]);
|
||||||
DISPOSE(av);
|
free(av);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -234,8 +240,8 @@ int default_rl_list_possib(char *pathname, char ***avp)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ac = FindMatches(dir, file, avp);
|
ac = FindMatches(dir, file, avp);
|
||||||
DISPOSE(dir);
|
free(dir);
|
||||||
DISPOSE(file);
|
free(file);
|
||||||
|
|
||||||
return ac;
|
return ac;
|
||||||
}
|
}
|
||||||
|
112
src/editline.c
112
src/editline.c
@ -70,7 +70,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int Size;
|
int Size;
|
||||||
int Pos;
|
int Pos;
|
||||||
const char *Lines[HIST_SIZE];
|
char *Lines[HIST_SIZE];
|
||||||
} el_hist_t;
|
} el_hist_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -85,7 +85,7 @@ int rl_quit;
|
|||||||
int rl_susp;
|
int rl_susp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char NIL[] = "";
|
static char NIL[] = "";
|
||||||
static const char *Input = NIL;
|
static const char *Input = NIL;
|
||||||
static const char *Prompt;
|
static const char *Prompt;
|
||||||
static char *Yanked;
|
static char *Yanked;
|
||||||
@ -145,7 +145,7 @@ static void tty_put(const 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, sizeof(char) * ScreenSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,11 +454,12 @@ static el_status_t insert_string(const char *p)
|
|||||||
|
|
||||||
len = strlen((char *)p);
|
len = strlen((char *)p);
|
||||||
if (rl_end + len >= Length) {
|
if (rl_end + len >= Length) {
|
||||||
if ((new = NEW(char, Length + len + MEM_INC)) == NULL)
|
new = malloc(sizeof(char) * (Length + len + MEM_INC));
|
||||||
|
if (!new)
|
||||||
return CSstay;
|
return CSstay;
|
||||||
if (Length) {
|
if (Length) {
|
||||||
COPYFROMTO(new, rl_line_buffer, Length);
|
memcpy(new, rl_line_buffer, Length);
|
||||||
DISPOSE(rl_line_buffer);
|
free(rl_line_buffer);
|
||||||
}
|
}
|
||||||
rl_line_buffer = new;
|
rl_line_buffer = new;
|
||||||
Length += len + MEM_INC;
|
Length += len + MEM_INC;
|
||||||
@ -466,7 +467,7 @@ static el_status_t insert_string(const char *p)
|
|||||||
|
|
||||||
for (q = &rl_line_buffer[rl_point], i = rl_end - rl_point; --i >= 0; )
|
for (q = &rl_line_buffer[rl_point], i = rl_end - rl_point; --i >= 0; )
|
||||||
q[len + i] = q[i];
|
q[len + i] = q[i];
|
||||||
COPYFROMTO(&rl_line_buffer[rl_point], p, len);
|
memcpy(&rl_line_buffer[rl_point], p, len);
|
||||||
rl_end += len;
|
rl_end += len;
|
||||||
rl_line_buffer[rl_end] = '\0';
|
rl_line_buffer[rl_end] = '\0';
|
||||||
tty_string(&rl_line_buffer[rl_point]);
|
tty_string(&rl_line_buffer[rl_point]);
|
||||||
@ -570,7 +571,7 @@ static const char *search_hist(const char *search, const char *(*move)(void))
|
|||||||
/* 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 = (char *)strdup((char *)search);
|
old_search = (char *)strdup((char *)search);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -594,6 +595,7 @@ static const char *search_hist(const char *search, const char *(*move)(void))
|
|||||||
if ((*match)((char *)H.Lines[H.Pos], pat, len) == 0)
|
if ((*match)((char *)H.Lines[H.Pos], pat, len) == 0)
|
||||||
return H.Lines[H.Pos];
|
return H.Lines[H.Pos];
|
||||||
H.Pos = pos;
|
H.Pos = pos;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,15 +649,16 @@ static el_status_t fd_char(void)
|
|||||||
static void save_yank(int begin, int i)
|
static void 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(char, (SIZE_T)i + 1)) != NULL) {
|
Yanked = malloc(sizeof(char) * (i + 1));
|
||||||
COPYFROMTO(Yanked, &rl_line_buffer[begin], i);
|
if (Yanked) {
|
||||||
|
memcpy(Yanked, &rl_line_buffer[begin], i);
|
||||||
Yanked[i] = '\0';
|
Yanked[i] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -768,14 +771,17 @@ static el_status_t insert_char(int c)
|
|||||||
return insert_string(buff);
|
return insert_string(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p = NEW(char, Repeat + 1)) == NULL)
|
p = malloc(sizeof(char) * (Repeat + 1));
|
||||||
|
if (!p)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,7 +956,7 @@ static char *editinput(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hist_add(const char *p)
|
static void hist_add(char *p)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -959,7 +965,7 @@ static void hist_add(const 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;
|
||||||
@ -974,14 +980,19 @@ static char *read_redirected(void)
|
|||||||
char *line;
|
char *line;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
p = line = NEW(char, size);
|
p = line = malloc(sizeof(char) * size);
|
||||||
|
if (!p)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
end = p + size;
|
end = p + size;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (p == end) {
|
if (p == end) {
|
||||||
int oldpos = end - line;
|
int oldpos = end - line;
|
||||||
|
|
||||||
size += MEM_INC;
|
size += MEM_INC;
|
||||||
p = RENEW(line, char, size);
|
p = line = realloc(line, sizeof(char) * size);
|
||||||
|
if (!p)
|
||||||
|
return NULL;
|
||||||
end = p + size;
|
end = p + size;
|
||||||
|
|
||||||
p += oldpos; /* Continue where we left off... */
|
p += oldpos; /* Continue where we left off... */
|
||||||
@ -996,6 +1007,7 @@ static char *read_redirected(void)
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1035,9 +1047,10 @@ char *readline(const char *prompt)
|
|||||||
return read_redirected();
|
return read_redirected();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rl_line_buffer == NULL) {
|
if (!rl_line_buffer) {
|
||||||
Length = MEM_INC;
|
Length = MEM_INC;
|
||||||
if ((rl_line_buffer = NEW(char, Length)) == NULL)
|
rl_line_buffer = malloc(sizeof(char) * Length);
|
||||||
|
if (!rl_line_buffer)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1045,7 +1058,10 @@ char *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(sizeof(char) * ScreenSize);
|
||||||
|
if (!Screen)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
Prompt = prompt ? prompt : NIL;
|
Prompt = prompt ? prompt : NIL;
|
||||||
tty_puts(Prompt);
|
tty_puts(Prompt);
|
||||||
if ((line = editinput()) != NULL) {
|
if ((line = editinput()) != NULL) {
|
||||||
@ -1054,14 +1070,14 @@ char *readline(const char *prompt)
|
|||||||
tty_flush();
|
tty_flush();
|
||||||
}
|
}
|
||||||
rl_ttyset(1);
|
rl_ttyset(1);
|
||||||
DISPOSE(Screen);
|
free(Screen);
|
||||||
DISPOSE(H.Lines[--H.Size]);
|
free(H.Lines[--H.Size]);
|
||||||
|
|
||||||
if (line != NULL && *line != '\0'
|
if (line != NULL && *line != '\0'
|
||||||
#ifdef CONFIG_UNIQUE_HISTORY
|
#ifdef CONFIG_UNIQUE_HISTORY
|
||||||
&& !(H.Pos && strcmp((char *) line, (char *) H.Lines[H.Pos - 1]) == 0)
|
&& !(H.Pos && strcmp(line, H.Lines[H.Pos - 1]) == 0)
|
||||||
#endif
|
#endif
|
||||||
&& !(H.Size && strcmp((char *) line, (char *) H.Lines[H.Size - 1]) == 0)
|
&& !(H.Size && strcmp(line, H.Lines[H.Size - 1]) == 0)
|
||||||
) {
|
) {
|
||||||
hist_add(line);
|
hist_add(line);
|
||||||
}
|
}
|
||||||
@ -1071,7 +1087,8 @@ char *readline(const char *prompt)
|
|||||||
Signal = 0;
|
Signal = 0;
|
||||||
kill(getpid(), s);
|
kill(getpid(), s);
|
||||||
}
|
}
|
||||||
return (char *)line;
|
|
||||||
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_history(char *p __attribute__ ((unused)))
|
void add_history(char *p __attribute__ ((unused)))
|
||||||
@ -1113,17 +1130,22 @@ static char *find_word(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
len = rl_point - (p - rl_line_buffer) + 1;
|
len = rl_point - (p - rl_line_buffer) + 1;
|
||||||
if ((new = NEW(char, len)) == NULL)
|
new = malloc(sizeof(char) * len);
|
||||||
|
if (!new)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
q = new;
|
q = new;
|
||||||
while (p < &rl_line_buffer[rl_point]) {
|
while (p < &rl_line_buffer[rl_point]) {
|
||||||
if (*p == '\\') {
|
if (*p == '\\') {
|
||||||
if (++p == &rl_line_buffer[rl_point]) break;
|
if (++p == &rl_line_buffer[rl_point])
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
*q++ = *p++;
|
*q++ = *p++;
|
||||||
}
|
}
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
|
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1140,12 +1162,13 @@ static el_status_t c_possible(void)
|
|||||||
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();
|
||||||
@ -1166,11 +1189,13 @@ static el_status_t c_complete(void)
|
|||||||
word = find_word();
|
word = find_word();
|
||||||
p = (char *)rl_complete((char *)word, &unique);
|
p = (char *)rl_complete((char *)word, &unique);
|
||||||
if (word)
|
if (word)
|
||||||
DISPOSE(word);
|
free(word);
|
||||||
if (p) {
|
if (p) {
|
||||||
len = strlen((char *)p);
|
len = strlen((char *)p);
|
||||||
word = p;
|
word = p;
|
||||||
new = q = NEW(char, 2 * len + 1);
|
new = q = malloc(sizeof(char) * (2 * len + 1));
|
||||||
|
if (!new)
|
||||||
|
return CSstay;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if ((*p < ' ' || strchr(SEPS, (char) *p) != NULL)
|
if ((*p < ' ' || strchr(SEPS, (char) *p) != NULL)
|
||||||
&& (!unique || p[1] != 0)) {
|
&& (!unique || p[1] != 0)) {
|
||||||
@ -1179,7 +1204,7 @@ static el_status_t c_complete(void)
|
|||||||
*q++ = *p++;
|
*q++ = *p++;
|
||||||
}
|
}
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
DISPOSE(word);
|
free(word);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
s = insert_string(new);
|
s = insert_string(new);
|
||||||
#ifdef CONFIG_ANNOYING_NOISE
|
#ifdef CONFIG_ANNOYING_NOISE
|
||||||
@ -1187,8 +1212,9 @@ static el_status_t c_complete(void)
|
|||||||
ring_bell();
|
ring_bell();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
DISPOSE(new);
|
free(new);
|
||||||
if (len > 0) return s;
|
if (len > 0)
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
return c_possible();
|
return c_possible();
|
||||||
}
|
}
|
||||||
@ -1352,7 +1378,8 @@ static int argify(char *line, char ***avp)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = MEM_INC;
|
i = MEM_INC;
|
||||||
if ((*avp = p = NEW(char *, i))== NULL)
|
*avp = p = malloc(sizeof(char *) * i);
|
||||||
|
if (!p)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (c = line; isspace(*c); c++)
|
for (c = line; isspace(*c); c++)
|
||||||
@ -1365,14 +1392,14 @@ static int argify(char *line, char ***avp)
|
|||||||
*c++ = '\0';
|
*c++ = '\0';
|
||||||
if (*c && *c != '\n') {
|
if (*c && *c != '\n') {
|
||||||
if (ac + 1 == i) {
|
if (ac + 1 == i) {
|
||||||
new = NEW(char *, i + MEM_INC);
|
new = malloc(sizeof(char *) * (i + MEM_INC));
|
||||||
if (new == NULL) {
|
if (!new) {
|
||||||
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;
|
||||||
@ -1406,8 +1433,9 @@ static el_status_t last_argument(void)
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +62,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.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user