mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 12:31:10 +00:00
GIB: Added ifnot, fixed several bugs, updated zoom.gib yet again.
This commit is contained in:
parent
783602e6a4
commit
47d35f3e2d
5 changed files with 40 additions and 36 deletions
|
@ -34,8 +34,8 @@ global mult
|
|||
global zoomed
|
||||
|
||||
// clamp returns the second argument clamped
|
||||
// between the first and second
|
||||
function clamp {
|
||||
// between the first and third
|
||||
function zoom::clamp {
|
||||
if ($args[2] < $args[1]) {
|
||||
return $args[1]
|
||||
} else if ($args[2] > $args[3]) {
|
||||
|
@ -88,18 +88,18 @@ function zoom::toggle {
|
|||
}
|
||||
|
||||
function zoom::increase {
|
||||
if (!$zoomed) {
|
||||
ifnot $zoomed {
|
||||
return
|
||||
}
|
||||
mult = `clamp $min ($mult*$step) $max`
|
||||
mult = `zoom::clamp $min ($mult*$step) $max`
|
||||
zoom::adjust
|
||||
}
|
||||
|
||||
function zoom::decrease {
|
||||
if (!$zoomed) {
|
||||
ifnot $zoomed {
|
||||
return
|
||||
}
|
||||
mult = `clamp $min ($mult/$step) $max`
|
||||
mult = `zoom::clamp $min ($mult/$step) $max`
|
||||
zoom::adjust
|
||||
}
|
||||
|
||||
|
|
|
@ -33,16 +33,15 @@
|
|||
#define __GIB_TREE_H
|
||||
|
||||
#define TREE_NORMAL 0 // Normal node
|
||||
#define TREE_PERM 1 // Permanent (part of a function)
|
||||
#define TREE_CONCAT 2 // Concatenate to previous
|
||||
#define TREE_EMBED 4 // Embedded command (expect return value)
|
||||
#define TREE_P_EMBED 8 // Embedded stuff needs to be processed
|
||||
#define TREE_P_MATH 16 // Math needs be evaluated
|
||||
#define TREE_ASPLIT 32 // Token is the name of an array that should be split
|
||||
#define TREE_FUNC 64 // Node is the first in a function
|
||||
#define TREE_COND 128 // Conditional jump (if or while command)
|
||||
#define TREE_END 256 // Node ends a loop or conditional
|
||||
#define TREE_FORNEXT 512 // For loop is starting again
|
||||
#define TREE_CONCAT 1 // Concatenate to previous
|
||||
#define TREE_EMBED 2 // Embedded command (expect return value)
|
||||
#define TREE_P_EMBED 4 // Embedded stuff needs to be processed
|
||||
#define TREE_ASPLIT 8 // Token is the name of an array that should be split
|
||||
#define TREE_FUNC 16 // Node is the first in a function
|
||||
#define TREE_COND 32 // Conditional jump (if or while command)
|
||||
#define TREE_NOT 64
|
||||
#define TREE_END 128 // Node ends a loop or conditional
|
||||
#define TREE_FORNEXT 256 // For loop is starting again
|
||||
|
||||
typedef struct gib_tree_s {
|
||||
const char *str;
|
||||
|
|
|
@ -359,14 +359,16 @@ GIB_Slice_f (void)
|
|||
len = strlen (GIB_Argv(1));
|
||||
start = atoi (GIB_Argv(2));
|
||||
end = atoi (GIB_Argv(3));
|
||||
while (start < 0)
|
||||
start += len-1;
|
||||
while (end < 0)
|
||||
if (end < 1)
|
||||
end += len;
|
||||
if (start >= len)
|
||||
return;
|
||||
if (end > len || !end)
|
||||
else if (end > len)
|
||||
end = len;
|
||||
if (start < 0) {
|
||||
start += len;
|
||||
if (start < 0)
|
||||
start = 0;
|
||||
} else if (start >= len || start >= end)
|
||||
return;
|
||||
if ((ret = GIB_Return (0)))
|
||||
dstring_appendsubstr (ret, GIB_Argv(1)+start, end-start);
|
||||
}
|
||||
|
|
|
@ -93,16 +93,18 @@ GIB_Execute_Split_Array (cbuf_t *cbuf)
|
|||
break;
|
||||
}
|
||||
cbuf->args->argc--;
|
||||
if (!(var = GIB_Var_Get_Complex (&GIB_DATA(cbuf)->locals, &gib_globals, str, &i, false)))
|
||||
if (!(var = GIB_Var_Get_Complex (&GIB_DATA(cbuf)->locals, &GIB_DATA(cbuf)->globals, str, &i, false)))
|
||||
return;
|
||||
while (start < 0)
|
||||
start += var->size-1;
|
||||
while (end < 0)
|
||||
if (end < 1)
|
||||
end += var->size;
|
||||
if (start >= var->size)
|
||||
return;
|
||||
if (end >= var->size || !end)
|
||||
else if (end > var->size)
|
||||
end = var->size;
|
||||
if (start < 0) {
|
||||
start += var->size;
|
||||
if (start < 0)
|
||||
start = 0;
|
||||
} else if (start >= var->size || start >= end)
|
||||
return;
|
||||
for (i = start; i < end; i++) {
|
||||
if (var->array[i])
|
||||
Cbuf_ArgsAdd (cbuf->args, var->array[i]->str);
|
||||
|
@ -137,7 +139,7 @@ GIB_Execute_Prepare_Line (cbuf_t *cbuf, gib_tree_t *line)
|
|||
Cbuf_ArgsAdd (args, cur->str);
|
||||
args->argm[args->argc-1] = cur;
|
||||
}
|
||||
if (cur->flags & TREE_P_MATH && GIB_Process_Math (args->argv[args->argc-1], pos))
|
||||
if (cur->delim == '(' && GIB_Process_Math (args->argv[args->argc-1], pos))
|
||||
return -1;
|
||||
if (cur->flags & TREE_ASPLIT)
|
||||
GIB_Execute_Split_Array (cbuf);
|
||||
|
@ -168,6 +170,7 @@ GIB_Execute (cbuf_t *cbuf)
|
|||
gib_buffer_data_t *g = GIB_DATA (cbuf);
|
||||
gib_builtin_t *b;
|
||||
gib_function_t *f;
|
||||
int cond;
|
||||
|
||||
if (!g->program)
|
||||
return;
|
||||
|
@ -177,7 +180,8 @@ GIB_Execute (cbuf_t *cbuf)
|
|||
if (GIB_Execute_Prepare_Line (cbuf, g->ip))
|
||||
return;
|
||||
if (g->ip->flags & TREE_COND) {
|
||||
if (!atoi(cbuf->args->argv[1]->str))
|
||||
cond = g->ip->flags & TREE_NOT ? atoi (cbuf->args->argv[1]->str) : !atoi (cbuf->args->argv[1]->str);
|
||||
if (cond)
|
||||
g->ip = g->ip->jump;
|
||||
} else if (g->ip->flags & TREE_FORNEXT) {
|
||||
if (GIB_Execute_For_Next (cbuf))
|
||||
|
|
|
@ -289,11 +289,8 @@ GIB_Parse_Tokens (const char *program, unsigned int *i, unsigned int flags, gib_
|
|||
// We can handle escape characters now
|
||||
} else if (cur->delim == '\"')
|
||||
GIB_Process_Escapes (str);
|
||||
|
||||
cur->str = str;
|
||||
// Set proper flags for GIB_Execute_Prepare_Line
|
||||
if (cur->delim == '(')
|
||||
cur->flags |= TREE_P_MATH;
|
||||
|
||||
if (cat) {
|
||||
cur->flags |= TREE_CONCAT;
|
||||
cat = false;
|
||||
|
@ -320,7 +317,7 @@ GIB_Parse_Semantic_Preprocess (gib_tree_t *line)
|
|||
{
|
||||
gib_tree_t *p, *start = line;
|
||||
unsigned int flags = line->flags;
|
||||
while (!strcmp (line->children->str, "if")) {
|
||||
while (!strcmp (line->children->str, "if") || !strcmp (line->children->str, "ifnot")) {
|
||||
// Sanity checking
|
||||
if (!line->children->next || !line->children->next->next || !line->children->next->next->children || line->flags & TREE_EMBED) {
|
||||
gib_parse_error = true;
|
||||
|
@ -328,6 +325,8 @@ GIB_Parse_Semantic_Preprocess (gib_tree_t *line)
|
|||
}
|
||||
// Set conditional flag
|
||||
line->flags |= TREE_COND;
|
||||
if (line->children->str[2])
|
||||
line->flags |= TREE_NOT;
|
||||
// Save our spot
|
||||
p = line;
|
||||
// Move subprogram inline
|
||||
|
|
Loading…
Reference in a new issue