//=========================================================================== int varset_message(int tokencount, char *tokens[], bool from_core, module* caller) { int varnameidx; bool is_static; if (tokencount == 4) { varnameidx = 2; is_static = false; } else if (tokencount == 5 && !strcmp(tokens[2], "Static") ) { varnameidx = 3; is_static = true; } else return 1; int i = atoi(variables_get(tokens[varnameidx],"0", caller)); if ( config_set_int(tokens[varnameidx+1],&i) //Try reading it as an int || config_set_int_expr(tokens[varnameidx+1],&i) // Try calculating the string as an expression ) variables_set(is_static,tokens[varnameidx],i, caller); else variables_set(is_static, tokens[varnameidx], tokens[varnameidx+1], caller); return 0; }
static void fetch_variable(t_context *context, t_token *token) { char *var_value; token->type = CHARS; if (!ft_strcmp(token->lexeme, "?")) var_value = ft_itoa(context->last_status); else { var_value = variables_get(context->vars, token->lexeme); if (!var_value) var_value = environ_get(context, token->lexeme); var_value = (var_value ? ft_strdup(var_value) : ft_strnew(0)); } free(token->lexeme); token->lexeme = var_value; }
char *message_preprocess(char *buffer, module* defmodule) { char *start = buffer, *end = NULL; while (NULL != (start = strchr(start, '$')) && NULL != (end = strchr(start+1, '$'))) { int varlen = ++end - start - 2; const char *replacement = NULL; if (varlen) { char expression[400]; extract_string(expression, start+1, varlen); if (0 == memcmp(expression, "Mouse.", 6)) { POINT pt; GetCursorPos(&pt); switch (expression[6]) { case 'X': sprintf(expression, "%d", (int)pt.x-10), replacement = expression; break; case 'Y': sprintf(expression, "%d", (int)pt.y-10), replacement = expression; break; } } // Check if it's indirect access else if (expression[0] == '*') { //Indirection. if (char* cnameend = strchr(expression, '.')) // Refers to a property of a control. { char cname[64], propname[64]; int cnamelen = cnameend-expression-1; extract_string(cname, expression+1, cnamelen); extract_string(propname, cnameend+1, varlen-cnamelen-1); if (control *c = control_get(variables_get(cname, NULL, defmodule),defmodule) ) { get_property_by_name(expression, c, propname); replacement = expression; } else replacement = NULL; // No '.' in other variable names - we failed locating the control. } else { const char *key = variables_get(expression+1, NULL, defmodule); replacement = key ? variables_get(key,NULL, defmodule) : NULL; } } else { //No indirection. if (char* cnameend = strchr(expression, '.')) // Refers to a property of a control. { char cname[64], propname[64]; int cnamelen = cnameend-expression; extract_string(cname, expression, cnamelen); extract_string(propname, cnameend+1, varlen-cnamelen-1); // Try and look up the control with the given name if (!strcmp(cname,"DroppedFile")) // "fake" properties of the DroppedFile { strcpy(expression, variables_get("DroppedFile", NULL, defmodule)); if (!strcmp(propname, "Path")) { char* s = strrchr(expression, '\\'); replacement = s ? *s = 0, expression : NULL; } else if (!strcmp(propname, "Name")) { char* s = strrchr(expression, '\\'); char* t = strrchr(expression, '.'); s = s ? s+1 : expression; // step s past final slash, or set to start if (t && (t-s > 0)) *t = 0; replacement = s; } else if (!strcmp(propname, "Extension")) { char* s = strrchr(expression, '.'); replacement = s ? s+1 : NULL; } else if (!strcmp(propname, "Filename")) { char* s = strrchr(expression, '\\'); replacement = s ? s+1 : NULL; } else replacement = NULL; } else if (control *c = control_get(cname, defmodule) ) { get_property_by_name(expression, c, propname); replacement = expression; } else replacement = NULL; // No '.' in other variable names - we failed locating the control. } else replacement = variables_get(expression, NULL, defmodule); } } else replacement = "$"; // default: $$ becomes $ if (replacement) { int newlen = strlen(replacement); memmove(start + newlen, end, strlen(end) + 1); memmove(start, replacement, newlen); end = start + newlen; } start = end; } return buffer; }