Rewrite of the /FE scripting function, fixing these four problems:
fe ( x$chr(9)y ) a { echo $a }
(Crashes)
fe ( abc def ) xyz{ echo [$xyz] [$xy] }
(Uses wrong variable name)
fe ( abc def ) x{ echo $x }
(Endless loop)
fe ( abc def ) { echo x }
(Wrong error message)
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@30 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
142
source/if.c
142
source/if.c
@@ -361,17 +361,15 @@ BUILT_IN_COMMAND(fe)
|
|||||||
*placeholder,
|
*placeholder,
|
||||||
*sa,
|
*sa,
|
||||||
*vars,
|
*vars,
|
||||||
|
*varmem = NULL,
|
||||||
*var[255],
|
*var[255],
|
||||||
*word = NULL,
|
*word = NULL,
|
||||||
*todo = NULL,
|
*todo = NULL,
|
||||||
fec_buffer[2];
|
fec_buffer[2] = { 0 };
|
||||||
int ind, x, y, blah = 0, args_flag;
|
int ind, y, args_flag;
|
||||||
int old_display;
|
int old_display;
|
||||||
int doing_fe = !my_stricmp(command, "FE");
|
int doing_fe = !my_stricmp(command, "FE");
|
||||||
|
|
||||||
for (x = 0; x <= 254; var[x++] = NULL)
|
|
||||||
;
|
|
||||||
|
|
||||||
list = next_expr(&args, '(');
|
list = next_expr(&args, '(');
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
@@ -396,76 +394,121 @@ BUILT_IN_COMMAND(fe)
|
|||||||
new_free(&templist);
|
new_free(&templist);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((char *)var == (char *)args)
|
|
||||||
{
|
|
||||||
error("%s: You did not specify any variables", command);
|
|
||||||
new_free(&templist);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
args[-1] = '\0';
|
|
||||||
ind = 0;
|
|
||||||
|
|
||||||
while ((var[ind++] = next_arg(vars, &vars)))
|
/* This is subtle - we have to create a duplicate of the string
|
||||||
|
* containing the var names, in case there's no space between
|
||||||
|
* it and the commands. */
|
||||||
|
args[0] = '\0';
|
||||||
|
malloc_strcpy(&varmem, vars);
|
||||||
|
vars = varmem;
|
||||||
|
args[0] = '{';
|
||||||
|
|
||||||
|
ind = 0;
|
||||||
|
while ((var[ind] = next_arg(vars, &vars)))
|
||||||
{
|
{
|
||||||
|
ind++;
|
||||||
|
|
||||||
if (ind == 255)
|
if (ind == 255)
|
||||||
{
|
{
|
||||||
error("%s: Too many variables", command);
|
error("%s: Too many variables", command);
|
||||||
new_free(&templist);
|
new_free(&templist);
|
||||||
|
new_free(&varmem);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ind = ind ? ind - 1: 0;
|
|
||||||
|
if (ind < 1)
|
||||||
|
{
|
||||||
|
error("%s: You did not specify any variables", command);
|
||||||
|
new_free(&templist);
|
||||||
|
new_free(&varmem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(todo = next_expr(&args, '{'))) /* } { */
|
if (!(todo = next_expr(&args, '{'))) /* } { */
|
||||||
{
|
{
|
||||||
error("%s: Missing }", command);
|
error("%s: Missing }", command);
|
||||||
new_free(&templist);
|
new_free(&templist);
|
||||||
|
new_free(&varmem);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
old_display = window_display;
|
old_display = window_display;
|
||||||
|
|
||||||
if (!doing_fe)
|
|
||||||
{ word = fec_buffer; word[1] = 0; }
|
|
||||||
|
|
||||||
blah = ((doing_fe) ? (word_count(templist)) : (strlen(templist)));
|
|
||||||
placeholder = templist;
|
placeholder = templist;
|
||||||
|
|
||||||
will_catch_break_exceptions++;
|
will_catch_break_exceptions++;
|
||||||
will_catch_continue_exceptions++;
|
will_catch_continue_exceptions++;
|
||||||
|
|
||||||
make_local_stack(NULL);
|
make_local_stack(NULL);
|
||||||
for ( x = 0 ; x < blah ; )
|
|
||||||
{
|
|
||||||
window_display = 0;
|
|
||||||
for ( y = 0 ; y < ind ; y++ )
|
|
||||||
{
|
|
||||||
if (doing_fe)
|
|
||||||
word = ((x+y) < blah)
|
|
||||||
? new_next_arg(templist, &templist)
|
|
||||||
: empty_string;
|
|
||||||
else
|
|
||||||
word[0] = ((x+y) < blah)
|
|
||||||
? templist[x+y] : 0;
|
|
||||||
|
|
||||||
add_local_alias(var[y], word);
|
if (doing_fe) {
|
||||||
}
|
/* FE */
|
||||||
window_display = old_display;
|
word = new_next_arg(templist, &templist);
|
||||||
x += ind;
|
while (word)
|
||||||
parse_line(NULL, todo, subargs?subargs:empty_string, 0, 0, 0);
|
{
|
||||||
if (continue_exception)
|
window_display = 0;
|
||||||
{
|
for ( y = 0 ; y < ind ; y++ )
|
||||||
continue_exception = 0;
|
{
|
||||||
continue;
|
if (word) {
|
||||||
}
|
add_local_alias(var[y], word);
|
||||||
if (break_exception)
|
|
||||||
{
|
word = new_next_arg(templist, &templist);
|
||||||
break_exception = 0;
|
} else {
|
||||||
break;
|
add_local_alias(var[y], empty_string);
|
||||||
}
|
}
|
||||||
if (return_exception)
|
}
|
||||||
break;
|
window_display = old_display;
|
||||||
}
|
parse_line(NULL, todo, subargs?subargs:empty_string, 0, 0, 0);
|
||||||
|
if (continue_exception)
|
||||||
|
{
|
||||||
|
continue_exception = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (break_exception)
|
||||||
|
{
|
||||||
|
break_exception = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (return_exception)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* FEC */
|
||||||
|
word = fec_buffer;
|
||||||
|
|
||||||
|
word[0] = *templist++;
|
||||||
|
while(word[0])
|
||||||
|
{
|
||||||
|
window_display = 0;
|
||||||
|
for ( y = 0 ; y < ind ; y++ )
|
||||||
|
{
|
||||||
|
if (word[0]) {
|
||||||
|
add_local_alias(var[y], word);
|
||||||
|
|
||||||
|
word[0] = *templist++;
|
||||||
|
} else {
|
||||||
|
add_local_alias(var[y], empty_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window_display = old_display;
|
||||||
|
parse_line(NULL, todo, subargs?subargs:empty_string, 0, 0, 0);
|
||||||
|
if (continue_exception)
|
||||||
|
{
|
||||||
|
continue_exception = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (break_exception)
|
||||||
|
{
|
||||||
|
break_exception = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (return_exception)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
destroy_local_stack();
|
destroy_local_stack();
|
||||||
will_catch_break_exceptions--;
|
will_catch_break_exceptions--;
|
||||||
@@ -473,6 +516,7 @@ BUILT_IN_COMMAND(fe)
|
|||||||
|
|
||||||
window_display = old_display;
|
window_display = old_display;
|
||||||
new_free(&placeholder);
|
new_free(&placeholder);
|
||||||
|
new_free(&varmem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FOR command..... prototype:
|
/* FOR command..... prototype:
|
||||||
|
|||||||
Reference in New Issue
Block a user