static const Binding *put_binding(Env *env, const wchar_t *name, const Value *val) { assert(env != 0); assert(name != 0); assert(val != 0); return env->bindings = make_binding(name, val, env->bindings); }
/* Make a copy of BINDING without duplicating the data. */ SEARCH_BINDING * copy_binding (SEARCH_BINDING *binding) { SEARCH_BINDING *copy; copy = make_binding (binding->buffer, binding->start, binding->end); copy->flags = binding->flags; return copy; }
void env_bind(env_t *env, obj_t *name, binding_type_t type, mutability_t mutability, obj_t *value) { assert(!is_null(env)); assert(is_symbol(name)); PUSH_ROOT(env); AUTO_ROOT(binding, make_binding(name, type, mutability, value)); obj_t *frame = pair_car(env); frame = make_pair(binding, frame); pair_set_car(env, frame); POP_FUNCTION_ROOTS(); }
struct Env * bind_operands( lambda_t * lambda, cell_t * operands, struct Env * env ){ struct Env * lenv = bind_env( lambda->closure ); cell_t * operand_value; cell_t * operand = operands; cell_t * parameter = lambda->parameters; while( operand != NULL && parameter != NULL ){ operand_value = eval( operand, env ); make_binding( lenv, (char *) parameter->value, operand_value ); operand = operand->next; parameter = paramter->next; } return lenv; }
/* * Parse the parameters of the "bindkeys" configuration-file entry. This * expects widget name which may be "*", followed by curses key definition and * then dialog key definition. * * The curses key "should" be one of the names (ignoring case) from * curses_names[], but may also be a single control character (prefix "^" or * "~" depending on whether it is C0 or C1), or an escaped single character. * Binding a printable character with dialog is possible but not useful. * * The dialog key must be one of the names from dialog_names[]. */ int dlg_parse_bindkey(char *params) { char *p = skip_white(params); char *q; bool escaped = FALSE; int modified = 0; int result = FALSE; unsigned xx; char *widget; int is_function = FALSE; int curses_key; int dialog_key; curses_key = -1; dialog_key = -1; widget = p; p = skip_black(p); if (p != widget && *p != '\0') { *p++ = '\0'; q = p; while (*p != '\0' && curses_key < 0) { if (escaped) { escaped = FALSE; curses_key = *p; } else if (*p == '\\') { escaped = TRUE; } else if (modified) { if (*p == '?') { curses_key = ((modified == '^') ? 127 : 255); } else { curses_key = ((modified == '^') ? (*p & 0x1f) : ((*p & 0x1f) | 0x80)); } } else if (*p == '^') { modified = *p; } else if (*p == '~') { modified = *p; } else if (isspace(UCH(*p))) { break; } ++p; } if (!isspace(UCH(*p))) { ; } else { *p++ = '\0'; if (curses_key < 0) { char fprefix[2]; char check[2]; int keynumber; if (sscanf(q, "%[Ff]%d%c", fprefix, &keynumber, check) == 2) { curses_key = KEY_F(keynumber); is_function = TRUE; } else { for (xx = 0; xx < COUNT_CURSES; ++xx) { if (!dlg_strcmp(curses_names[xx].name, q)) { curses_key = curses_names[xx].code; is_function = TRUE; break; } } } } } q = skip_white(p); p = skip_black(q); if (p != q) { for (xx = 0; xx < COUNT_DIALOG; ++xx) { if (!dlg_strcmp(dialog_names[xx].name, q)) { dialog_key = dialog_names[xx].code; break; } } } if (*widget != '\0' && curses_key >= 0 && dialog_key >= 0 && make_binding(widget, curses_key, is_function, dialog_key) != 0) { result = TRUE; } } return result; }
ContextBase::ContextBase() : versionMajor(1), versionMinor(0) { if (bindings.size() <= 0) { //set up list with function pointers bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glActiveTexture, "glActiveTexture")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glCreateShader, "glCreateShader")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glShaderSource, "glShaderSource")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glCompileShader, "glCompileShader")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glCreateProgram, "glCreateProgram")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glAttachShader, "glAttachShader")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glLinkProgram, "glLinkProgram")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUseProgram, "glUseProgram")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glDetachShader, "glDetachShader")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glDeleteShader, "glDeleteShader")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glValidateProgram, "glValidateProgram")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glGetUniformLocation, "glGetUniformLocation")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform1f, "glUniform1f")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform2f, "glUniform2f")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform3f, "glUniform3f")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform4f, "glUniform4f")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform1fv, "glUniform1fv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform2fv, "glUniform2fv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform3fv, "glUniform3fv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform4fv, "glUniform4fv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform1i, "glUniform1i")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform2i, "glUniform2i")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform3i, "glUniform3i")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform4i, "glUniform4i")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform1iv, "glUniform1iv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform2iv, "glUniform2iv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform3iv, "glUniform3iv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniform4iv, "glUniform4iv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniformMatrix2fv, "glUniformMatrix2fv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniformMatrix3fv, "glUniformMatrix3fv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUniformMatrix4fv, "glUniformMatrix4fv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glGetAttribLocation, "glGetAttribLocation")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glBindAttribLocation, "glBindAttribLocation")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glVertexAttribPointer, "glVertexAttribPointer")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glEnableVertexAttribArray, "glEnableVertexAttribArray")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glDisableVertexAttribArray, "glDisableVertexAttribArray")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glDrawArrays, "glDrawArrays")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glDrawArrays, "glDrawArraysEXT")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glDeleteProgram, "glDeleteProgram")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glGetShaderiv, "glGetShaderiv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glGetShaderInfoLog, "glGetShaderInfoLog")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glGetProgramiv, "glGetProgramiv")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glGetProgramInfoLog, "glGetProgramInfoLog")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glClampColor, "glClampColor")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glGenFramebuffers, "glGenFramebuffers")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glDeleteFramebuffers, "glDeleteFramebuffers")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glBindFramebuffer, "glBindFramebuffer")); //bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glFramebufferTexture, "glFramebufferTexture")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glFramebufferTexture2D, "glFramebufferTexture2D")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glBlitFramebuffer, "glBlitFramebuffer")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glCheckFramebufferStatus, "glCheckFramebufferStatus")); #ifdef USE_OPENGL_ES bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glDiscardFramebuffer, "glDiscardFramebuffer")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glDiscardFramebuffer, "glDiscardFramebufferEXT")); #endif bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glGenBuffers, "glGenBuffers")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glBindBuffer, "glBindBuffer")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glBufferData, "glBufferData")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glMapBuffer, "glMapBuffer")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glUnmapBuffer, "glUnmapBuffer")); #if defined(WIN32) || defined(_WIN32) bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&wglGetSwapInterval, "wglGetSwapIntervalEXT")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&wglSwapInterval, "wglSwapIntervalEXT")); //try to find wglChoosePixelFormat as both regular and ARB function (needed for some systems) bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&wglChoosePixelFormat, "wglChoosePixelFormat")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&wglChoosePixelFormat, "wglChoosePixelFormatARB")); #elif defined(__linux__) #ifdef USE_OPENGL_DESKTOP bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glXSwapInterval, "glXSwapInterval")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glXCreateContextAttribs, "glXCreateContextAttribs")); bindings.push_back(make_binding((void (GLAPIENTRYP*)(void))&glXCreateContextAttribs, "glXCreateContextAttribsARB")); #endif #endif } }
int main (int argc, char **argv) { int c; unsigned short port = 0; binding_t *source = 0; binding_t *dest = 0; binding_t *s, *d; char packet[8192]; int n; int i; int nsource; int soopts; int verbose = 0; int source_set = 0; int dest_set = 0; struct pollfd *fds; while ((c = getopt (argc, argv, "vp:s:d:")) >= 0) { switch (c) { case 'p': port = atoi (optarg); if (port <= 0) usage (argv[0]); break; case 's': s = make_binding (optarg); s->next = source; source = s; break; case 'd': d = make_binding (optarg); d->next = dest; dest = d; break; case 'v': verbose++; break; default: usage (argv[0]); break; } } if (!port || !source || !dest) usage (argv[0]); nsource = 0; for (s = source; s; s = s->next) { set_source (s, port); if (verbose) dump_addr (s->fd, "source", 0); nsource++; } if (nsource > 1) { fds = malloc (nsource * sizeof (struct pollfd)); if (!fds) losing (argv[0], "malloc fds"); i = 0; for (s = source; s; s = s->next) { fds[i].fd = s->fd; fds[i].events = POLLIN; fds[i].revents = 0; } } else fds = 0; for (d = dest; d; d = d->next) { set_dest (d, port); if (verbose) dump_addr (d->fd, "dest", 1); } /* spend a while shipping packets around */ for (;;) { if (fds) { i = poll (fds, nsource, -1); if (i < 0) break; } i = 0; for (s = source, i = 0; s; s = s->next, i++) { if (!fds || fds[i].revents & POLLIN) { n = read (s->fd, packet, sizeof (packet)); if (n < 0) losing (argv[0], "read"); if (verbose) fprintf (stderr, "%d\n", n ); for (d = dest; d; d = d->next) { if (write (d->fd, packet, n) < n) losing (argv[0], "write"); } } } } }