session_t *session_new(size_t session_data_size, void (*data_cleanup)(session_t *)) { union Key k; // Must be hex binary int err = gen_random_data(&k.u64, 8); if (err != 0) { return NULL; } qlock(&session_map_mutex); session_t **sessionpp = (session_t**)mapinsert(&session_map, k); if (sessionpp == NULL) { return NULL; } *sessionpp = malloc(sizeof(session_t) + session_data_size); if (*sessionpp == NULL) { return NULL; } memset(*sessionpp, 0, sizeof(session_t) + session_data_size); qunlock(&session_map_mutex); //(*sessionpp)->tls_enabled = tls_enabled; (*sessionpp)->id = k.u64; (*sessionpp)->status = SESSION_ACTIVE; (*sessionpp)->refcount = 1; (*sessionpp)->data_cleanup = data_cleanup; return *sessionpp; }
static int gwinit (int argc, char *argv[]) { register int i; long color; gw_def_win.nextp = NULL; /* map the virtual keys. */ for (i = 0; gwkeys[i].label != 0; i++) if (gwkeys[i].cooked) mapinsert ((unsigned char *)gwkeys[i].rawin, strlen ((char *)gwkeys[i].rawin), (unsigned char *)gwkeys[i].cooked, strlen ((char *)gwkeys[i].cooked), (unsigned char *)gwkeys[i].label, gwkeys[i].flags, NULL); /* set default values for options */ optpreset (o_scrollbar (&gw_def_win), ElvTrue, OPT_REDRAW|OPT_HIDE); optpreset (o_toolbar (&gw_def_win), ElvTrue, OPT_REDRAW|OPT_HIDE); optpreset (o_statusbar (&gw_def_win), ElvTrue, OPT_REDRAW|OPT_HIDE); optpreset (o_menubar (&gw_def_win), ElvTrue, OPT_REDRAW|OPT_HIDE); optpreset (o_font (&gw_def_win), DEFAULT_FONT, OPT_REDRAW|OPT_HIDE); optpreset (o_propfont (&gw_def_win), DEFAULT_PROPFONT, OPT_REDRAW|OPT_HIDE); optpreset (o_titleformat (&gw_def_win), DEFAULT_TITLEFORMAT, OPT_HIDE); optpreset (o_scrollbgimage (&gw_def_win), ElvTrue, OPT_REDRAW|OPT_HIDE); /* install the global options */ optinsert("win32", QTY(gw_optglob_desc), gw_optglob_desc, gw_optglob_val); /* install default options */ optinsert("guiwin", NUM_OPTIONS, gw_opt_desc, (OPTVAL *)&gw_def_win.options); /* install the default printer */ gw_get_default_printer (); /* install default "normal" colors. */ colorinfo[COLOR_FONT_NORMAL].fg = color = GetSysColor(COLOR_WINDOWTEXT); colorinfo[COLOR_FONT_NORMAL].da.fg_rgb[0] = color & 0xff; colorinfo[COLOR_FONT_NORMAL].da.fg_rgb[1] = (color >> 8) & 0xff; colorinfo[COLOR_FONT_NORMAL].da.fg_rgb[2] = (color >> 16) & 0xff; colorinfo[COLOR_FONT_NORMAL].bg = color = GetSysColor(COLOR_WINDOW); colorinfo[COLOR_FONT_NORMAL].da.bg_rgb[0] = color & 0xff; colorinfo[COLOR_FONT_NORMAL].da.bg_rgb[1] = (color >> 8) & 0xff; colorinfo[COLOR_FONT_NORMAL].da.bg_rgb[2] = (color >> 16) & 0xff; colorinfo[COLOR_FONT_NORMAL].da.bits = COLOR_FG|COLOR_BG; /* locate the "guide" color */ guidefont = colorfind("guide"); return argc; }
static int handle_end_map(void *ctx) { struct parse_context *pctx = (struct parse_context *)ctx; Var map = new_map(); Var k, v; for (v = POP(pctx->top), k = POP(pctx->top); (int)v.type > MAP_SENTINEL && (int)k.type > MAP_SENTINEL; v = POP(pctx->top), k = POP(pctx->top)) { map = mapinsert(map, k, v); } PUSH(pctx->top, map); return 1; }
/* initialize the PC BIOS interface. */ static int vio_init (int argc, /* number of command-line arguments */ char **argv) /* values of command-line arguments */ { int i; /* Choose font colors in the absence of user settings. */ vc_term = vio_get_default_color (); vc_current = vc_term; vc_color = vc_term; vc_italic = 0xff; vc_underlined = 0xff; /* Dark if black or blue... */ o_background = (VC_BG (vc_term) <= 1)? 'd': 'l'; DPRINTF (("o_background: %x, %c\n", VC_BG (vc_term), o_background)); /* change the terminal mode to cbreak/noecho */ vio_resume (ElvTrue); /* try to get true screen size, from the operating system */ vio_getsize (); /* pretend the cursor is in an impossible place, so we're guaranteed * to move it on the first vio_moveto() or vio_draw() call. */ physx = physy = -100; /* map the arrow keys */ for (i = 0; i < QTY (keys); i++) { if (keys[i].cooked != NULL && keys[i].rawin != NULL) { mapinsert (toCHAR (keys[i].rawin), (int)strlen (keys[i].rawin), toCHAR (keys[i].cooked), (int)strlen (keys[i].cooked), toCHAR (keys[i].label), keys[i].flags, NULL); } } /* add the global options to the list known to :set */ o_ttyunderline = ElvTrue; optinsert ("vio", QTY (goptdesc), goptdesc, &ttygoptvals.term); return argc; }