mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 12:31:45 +08:00
Refactor: replace variables named 'new' with non-reserved word.
The word 'new' is a reserved keyword in C++ and C#, replacing it with something else is one step further to making it possible to build editline with a C++ compiler. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
cd50714e29
commit
e53ccf61f2
@ -37,7 +37,7 @@ static int compare(const void *p1, const void *p2)
|
|||||||
static int FindMatches(char *dir, char *file, char ***avp)
|
static int FindMatches(char *dir, char *file, char ***avp)
|
||||||
{
|
{
|
||||||
char **av;
|
char **av;
|
||||||
char **new;
|
char **word;
|
||||||
char *p;
|
char *p;
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
DIRENTRY *ep;
|
DIRENTRY *ep;
|
||||||
@ -69,16 +69,16 @@ static int FindMatches(char *dir, char *file, char ***avp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((ac % MEM_INC) == 0) {
|
if ((ac % MEM_INC) == 0) {
|
||||||
new = malloc(sizeof(char *) * (ac + MEM_INC));
|
word = malloc(sizeof(char *) * (ac + MEM_INC));
|
||||||
if (!new) {
|
if (!word) {
|
||||||
total = 0;
|
total = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ac) {
|
if (ac) {
|
||||||
memcpy(new, av, ac * sizeof(char **));
|
memcpy(word, av, ac * sizeof(char **));
|
||||||
free(av);
|
free(av);
|
||||||
}
|
}
|
||||||
*avp = av = new;
|
*avp = av = word;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((av[ac] = strdup(p)) == NULL) {
|
if ((av[ac] = strdup(p)) == NULL) {
|
||||||
@ -157,7 +157,7 @@ char *el_filename_complete(char *pathname, int *match)
|
|||||||
char **av;
|
char **av;
|
||||||
char *dir;
|
char *dir;
|
||||||
char *file;
|
char *file;
|
||||||
char *new;
|
char *path;
|
||||||
char *p;
|
char *p;
|
||||||
size_t ac;
|
size_t ac;
|
||||||
size_t end;
|
size_t end;
|
||||||
@ -185,11 +185,11 @@ char *el_filename_complete(char *pathname, int *match)
|
|||||||
if (p) {
|
if (p) {
|
||||||
memcpy(p, av[0] + len, j);
|
memcpy(p, av[0] + len, j);
|
||||||
len = strlen(dir) + strlen(av[0]) + 2;
|
len = strlen(dir) + strlen(av[0]) + 2;
|
||||||
new = malloc(sizeof(char) * len);
|
path = malloc(sizeof(char) * len);
|
||||||
if (new) {
|
if (path) {
|
||||||
snprintf(new, len, "%s/%s", dir, av[0]);
|
snprintf(path, len, "%s/%s", dir, av[0]);
|
||||||
rl_add_slash(new, p);
|
rl_add_slash(path, p);
|
||||||
free(new);
|
free(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -467,24 +467,27 @@ static el_status_t insert_string(const char *p)
|
|||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
int i;
|
int i;
|
||||||
char *new;
|
char *line;
|
||||||
char *q;
|
char *q;
|
||||||
|
|
||||||
len = strlen(p);
|
len = strlen(p);
|
||||||
if (rl_end + len >= Length) {
|
if (rl_end + len >= Length) {
|
||||||
new = malloc(sizeof(char) * (Length + len + MEM_INC));
|
line = malloc(sizeof(char) * (Length + len + MEM_INC));
|
||||||
if (!new)
|
if (!line)
|
||||||
return CSstay;
|
return CSstay;
|
||||||
|
|
||||||
if (Length) {
|
if (Length) {
|
||||||
memcpy(new, rl_line_buffer, Length);
|
memcpy(line, rl_line_buffer, Length);
|
||||||
free(rl_line_buffer);
|
free(rl_line_buffer);
|
||||||
}
|
}
|
||||||
rl_line_buffer = new;
|
|
||||||
|
rl_line_buffer = line;
|
||||||
Length += len + MEM_INC;
|
Length += len + MEM_INC;
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
memcpy(&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';
|
||||||
@ -1275,9 +1278,9 @@ int write_history(const char *filename)
|
|||||||
if (fp) {
|
if (fp) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (i < H.Size) {
|
while (i < H.Size)
|
||||||
fprintf(fp, "%s\n", H.Lines[i++]);
|
fprintf(fp, "%s\n", H.Lines[i++]);
|
||||||
}
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1294,7 +1297,7 @@ int write_history(const char *filename)
|
|||||||
char *el_find_word(void)
|
char *el_find_word(void)
|
||||||
{
|
{
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
char *new;
|
char *word;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
p = &rl_line_buffer[rl_point];
|
p = &rl_line_buffer[rl_point];
|
||||||
@ -1311,11 +1314,11 @@ char *el_find_word(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = rl_point - (p - rl_line_buffer) + 1;
|
len = rl_point - (p - rl_line_buffer) + 1;
|
||||||
new = malloc(sizeof(char) * len);
|
word = malloc(sizeof(char) * len);
|
||||||
if (!new)
|
if (!word)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
q = new;
|
q = word;
|
||||||
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])
|
if (++p == &rl_line_buffer[rl_point])
|
||||||
@ -1325,7 +1328,7 @@ char *el_find_word(void)
|
|||||||
}
|
}
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
|
|
||||||
return new;
|
return word;
|
||||||
}
|
}
|
||||||
|
|
||||||
static el_status_t c_possible(void)
|
static el_status_t c_possible(void)
|
||||||
@ -1353,7 +1356,7 @@ static el_status_t c_possible(void)
|
|||||||
static el_status_t c_complete(void)
|
static el_status_t c_complete(void)
|
||||||
{
|
{
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
char *word, *new;
|
char *word, *string;
|
||||||
size_t len;
|
size_t len;
|
||||||
int unique;
|
int unique;
|
||||||
el_status_t s = CSdone;
|
el_status_t s = CSdone;
|
||||||
@ -1368,11 +1371,13 @@ static el_status_t c_complete(void)
|
|||||||
if (p) {
|
if (p) {
|
||||||
len = strlen(p);
|
len = strlen(p);
|
||||||
word = p;
|
word = p;
|
||||||
new = q = malloc(sizeof(char) * (2 * len + 1));
|
|
||||||
if (!new) {
|
string = q = malloc(sizeof(char) * (2 * len + 1));
|
||||||
|
if (!string) {
|
||||||
free(word);
|
free(word);
|
||||||
return CSstay;
|
return CSstay;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if ((*p < ' ' || strchr(SEPS, *p) != NULL)
|
if ((*p < ' ' || strchr(SEPS, *p) != NULL)
|
||||||
&& (!unique || p[1] != 0)) {
|
&& (!unique || p[1] != 0)) {
|
||||||
@ -1382,17 +1387,20 @@ static el_status_t c_complete(void)
|
|||||||
}
|
}
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
free(word);
|
free(word);
|
||||||
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
s = insert_string(new);
|
s = insert_string(string);
|
||||||
#ifdef CONFIG_ANNOYING_NOISE
|
#ifdef CONFIG_ANNOYING_NOISE
|
||||||
if (!unique)
|
if (!unique)
|
||||||
el_ring_bell();
|
el_ring_bell();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
free(new);
|
free(string);
|
||||||
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c_possible();
|
return c_possible();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1542,7 +1550,7 @@ static int argify(char *line, char ***avp)
|
|||||||
{
|
{
|
||||||
char *c;
|
char *c;
|
||||||
char **p;
|
char **p;
|
||||||
char **new;
|
char **arg;
|
||||||
int ac;
|
int ac;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1559,17 +1567,19 @@ static int argify(char *line, char ***avp)
|
|||||||
for (ac = 0, p[ac++] = c; *c && *c != '\n'; ) {
|
for (ac = 0, p[ac++] = c; *c && *c != '\n'; ) {
|
||||||
if (isspace(*c)) {
|
if (isspace(*c)) {
|
||||||
*c++ = '\0';
|
*c++ = '\0';
|
||||||
|
|
||||||
if (*c && *c != '\n') {
|
if (*c && *c != '\n') {
|
||||||
if (ac + 1 == i) {
|
if (ac + 1 == i) {
|
||||||
new = malloc(sizeof(char *) * (i + MEM_INC));
|
arg = malloc(sizeof(char *) * (i + MEM_INC));
|
||||||
if (!new) {
|
if (!arg) {
|
||||||
p[ac] = NULL;
|
p[ac] = NULL;
|
||||||
return ac;
|
return ac;
|
||||||
}
|
}
|
||||||
memcpy(new, p, i * sizeof(char **));
|
|
||||||
|
memcpy(arg, p, i * sizeof(char **));
|
||||||
i += MEM_INC;
|
i += MEM_INC;
|
||||||
free(p);
|
free(p);
|
||||||
*avp = p = new;
|
*avp = p = arg;
|
||||||
}
|
}
|
||||||
p[ac++] = c;
|
p[ac++] = c;
|
||||||
}
|
}
|
||||||
@ -1577,6 +1587,7 @@ static int argify(char *line, char ***avp)
|
|||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
p[ac] = NULL;
|
p[ac] = NULL;
|
||||||
|
|
||||||
@ -1593,10 +1604,11 @@ static el_status_t last_argument(void)
|
|||||||
if (H.Size == 1 || (p = (char *)H.Lines[H.Size - 2]) == NULL)
|
if (H.Size == 1 || (p = (char *)H.Lines[H.Size - 2]) == NULL)
|
||||||
return el_ring_bell();
|
return el_ring_bell();
|
||||||
|
|
||||||
if ((p = strdup(p)) == NULL)
|
p = strdup(p);
|
||||||
|
if (!p)
|
||||||
return CSstay;
|
return CSstay;
|
||||||
ac = argify(p, &av);
|
|
||||||
|
|
||||||
|
ac = argify(p, &av);
|
||||||
if (Repeat != NO_ARG)
|
if (Repeat != NO_ARG)
|
||||||
s = Repeat < ac ? insert_string(av[Repeat]) : el_ring_bell();
|
s = Repeat < ac ? insert_string(av[Repeat]) : el_ring_bell();
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user