Exemple #1
0
/**
 * Create an X11 window.
 */
static int Open (vout_window_t *wnd, const vout_window_cfg_t *cfg)
{
    xcb_generic_error_t *err;
    xcb_void_cookie_t ck;

    vout_window_sys_t *p_sys = malloc (sizeof (*p_sys));
    if (p_sys == NULL)
        return VLC_ENOMEM;
    p_sys->embedded = false;

    /* Connect to X */
    char *display = var_InheritString (wnd, "x11-display");
    int snum;

    xcb_connection_t *conn = xcb_connect (display, &snum);
    if (xcb_connection_has_error (conn) /*== NULL*/)
        goto error;

    /* Find configured screen */
    const xcb_setup_t *setup = xcb_get_setup (conn);
    const xcb_screen_t *scr = NULL;
    for (xcb_screen_iterator_t i = xcb_setup_roots_iterator (setup);
         i.rem > 0; xcb_screen_next (&i))
    {
        if (snum == 0)
        {
            scr = i.data;
            break;
        }
        snum--;
    }
    if (scr == NULL)
    {
        msg_Err (wnd, "bad X11 screen number");
        goto error;
    }

    /* Create window */
    const uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
    uint32_t values[2] = {
        /* XCB_CW_BACK_PIXEL */
        scr->black_pixel,
        /* XCB_CW_EVENT_MASK */
        XCB_EVENT_MASK_KEY_PRESS,
    };

    xcb_window_t window = xcb_generate_id (conn);
    ck = xcb_create_window_checked (conn, scr->root_depth, window, scr->root,
                                    cfg->x, cfg->y, cfg->width, cfg->height, 0,
                                    XCB_WINDOW_CLASS_INPUT_OUTPUT,
                                    scr->root_visual, mask, values);
    err = xcb_request_check (conn, ck);
    if (err)
    {
        msg_Err (wnd, "creating window: X11 error %d", err->error_code);
        free (err);
        goto error;
    }

    wnd->handle.xid = window;
    wnd->display.x11 = display;
    wnd->control = Control;
    wnd->sys = p_sys;

    p_sys->conn = conn;
    if (var_InheritBool (wnd, "keyboard-events"))
        p_sys->keys = CreateKeyHandler (VLC_OBJECT(wnd), conn);
    else
        p_sys->keys = NULL;
    p_sys->root = scr->root;

    /* ICCCM
     * No cut&paste nor drag&drop, only Window Manager communication. */
    set_ascii_prop (conn, window, XA_WM_NAME,
    /* xgettext: This is a plain ASCII spelling of "VLC media player"
       for the ICCCM window name. This must be pure ASCII.
       The limitation is partially with ICCCM and partially with VLC.
       For Latin script languages, you may need to strip accents.
       For other scripts, you will need to transliterate into Latin. */
                    vlc_pgettext ("ASCII", "VLC media player"));

    set_ascii_prop (conn, window, XA_WM_ICON_NAME,
    /* xgettext: This is a plain ASCII spelling of "VLC"
       for the ICCCM window name. This must be pure ASCII. */
                    vlc_pgettext ("ASCII", "VLC"));
    set_wm_hints (conn, window);
    xcb_change_property (conn, XCB_PROP_MODE_REPLACE, window, XA_WM_CLASS,
                         XA_STRING, 8, 8, "vlc\0Vlc");
    set_hostname_prop (conn, window);

    /* EWMH */
    xcb_intern_atom_cookie_t utf8_string_ck
        = intern_string (conn, "UTF8_STRING");;
    xcb_intern_atom_cookie_t net_wm_name_ck
        = intern_string (conn, "_NET_WM_NAME");
    xcb_intern_atom_cookie_t net_wm_icon_name_ck
        = intern_string (conn, "_NET_WM_ICON_NAME");
    xcb_intern_atom_cookie_t wm_window_role_ck
        = intern_string (conn, "WM_WINDOW_ROLE");

    xcb_atom_t utf8 = get_atom (conn, utf8_string_ck);

    xcb_atom_t net_wm_name = get_atom (conn, net_wm_name_ck);
    char *title = var_InheritString (wnd, "video-title");
    if (title)
    {
        set_string (conn, window, utf8, net_wm_name, title);
        free (title);
    }
    else
        set_string (conn, window, utf8, net_wm_name, _("VLC media player"));

    xcb_atom_t net_wm_icon_name = get_atom (conn, net_wm_icon_name_ck);
    set_string (conn, window, utf8, net_wm_icon_name, _("VLC"));

    xcb_atom_t wm_window_role = get_atom (conn, wm_window_role_ck);
    set_ascii_prop (conn, window, wm_window_role, "vlc-video");

    /* Cache any EWMH atom we may need later */
    CacheAtoms (p_sys);
#ifdef MATCHBOX_HACK
    if (p_sys->mb_current_app_window)
    {
        uint32_t value = XCB_EVENT_MASK_PROPERTY_CHANGE;
        xcb_change_window_attributes (conn, scr->root,
                                      XCB_CW_EVENT_MASK, &value);
    }
#endif

    /* Make the window visible */
    xcb_map_window (conn, window);

    if (var_InheritBool (wnd, "video-wallpaper"))
    {
        vout_window_SetState (wnd, VOUT_WINDOW_STATE_BELOW);
        vout_window_SetFullScreen (wnd, true);
    }

    /* Create the event thread. It will dequeue all events, so any checked
     * request from this thread must be completed at this point. */
    if ((p_sys->keys != NULL)
     && vlc_clone (&p_sys->thread, Thread, wnd, VLC_THREAD_PRIORITY_LOW))
        DestroyKeyHandler (p_sys->keys);

#ifdef MATCHBOX_HACK
    if (p_sys->mb_current_app_window)
        xcb_set_input_focus (p_sys->conn, XCB_INPUT_FOCUS_POINTER_ROOT,
                             wnd->handle.xid, XCB_CURRENT_TIME);
#endif
    xcb_flush (conn); /* Make sure map_window is sent (should be useless) */
    return VLC_SUCCESS;

error:
    xcb_disconnect (conn);
    free (display);
    free (p_sys);
    return VLC_EGENERIC;
}
Exemple #2
0
static obj_t parse_atom(struct Parser *st)
{
	struct token *t = next(st);
	size_t i;

	switch (t->type) {
	case DOT:
		reportlocf(st->rep, t->loc, "datum expected");
		return unspecific;
	case CPAREN:
		reportlocf(st->rep, t->loc, "unmatched parenthesis");
		return unspecific;
	case END:
		return unspecific;
	case CHAR:
		if (t->len == 2) {
			reportlocf(st->rep, t->loc,
				   "end-of-input in character literal");
			return unspecific;
		} else if (t->len == 3) {
			return make_char(t->text[2]);
		} else {
			/* Convert to lowercase */
			for (i = 0; i < t->len; i++)
				t->text[i] = tolower(t->text[i]);

			if (atom_eq("#\\space", t->text, t->len)) {
				/* Space character literal */
				return make_char(' ');
			} else if (atom_eq("#\\newline", t->text, t->len)) {
				/* Newline character literal */
				return make_char('\n');
			} else {
				reportlocf(st->rep, t->loc,
					   "illegal character literal");
				return unspecific;
			}
		}
	case ATOM:
		/* Convert to lowercase */
		for (i = 0; i < t->len; i++)
			t->text[i] = tolower(t->text[i]);

		if (atom_eq("#f", t->text, t->len)) {
			/* False constant */
			return false_obj;
		} else if (atom_eq("#t", t->text, t->len)) {
			/* True constant */
			return true_obj;
		} else if (is_number(t->text, t->len)) {
			/* Copy to buffer to make null-terminated */
			char *buf = GC_MALLOC_ATOMIC((t->len+1) * sizeof(char));
			strncpy(buf, t->text, t->len);
			buf[t->len] = 0;

			/* Convert to number */
			return make_num(atol(buf));
		} else if (is_ident(t->text, t->len)) {
			/* Symbol */
			return make_symbol(intern_string(string_from(t->text, t->len)));
		} else {
			/* Invalid atom */
			reportlocf(st->rep, t->loc, "unrecognized atom");
			return unspecific;
		}
	case STRING:
		return parse_string(st, t);
	case OARRAY:
		reportlocf(st->rep, t->loc, "array literals are not supported");
		/* fallthrough: continue processing as lists */
	case OPAREN:
		return parse_list(st);
	case QUOTE:
		return parse_quotation(S_QUOTE, st);
	case QUASIQUOTE:
		return parse_quotation(S_QUASIQUOTE, st);
	case UNQUOTE:
		return parse_quotation(S_UNQUOTE, st);
	case UNQUOTE_SPLICING:
		return parse_quotation(S_UNQUOTE_SPLICING, st);
	}

	/* We should never get to here */
	return unspecific;
}
Exemple #3
0
int main() {
	int64_t * quantity = new int64_t[N_ROWS];
	double * extended_price = new double[N_ROWS];
	double * discount = new double[N_ROWS];
	double * tax = new double[N_ROWS];
	int64_t * group = new int64_t[N_ROWS];
	//char * return_flag = new char[N_ROWS];
	//char * line_status = new char[N_ROWS];
	int64_t * ship_date = new int64_t[N_ROWS];

	int ref_date = convert_time(time_for_filter);
	printf("%d\n", ref_date);	
	FILE * file = fopen("../data/lineitem_small.tbl","r");
	assert(file);
	for(int i = 0; i < N_ROWS; i++) {
		char buf[4096];
		char * columns[N_COLS];
		char * str = fgets(buf,4096,file);
		assert(str != NULL);
		columns[0] = strtok(buf,"|");
		for(int j = 1; j < N_COLS; j++) {
			columns[j] = strtok(NULL,"|");
			assert(columns[j]);
		}
		char * end = strtok(NULL,"\n");
		assert(end == NULL);
		quantity[i] = atoi(columns[QUANTITY]);
		extended_price[i] = atof(columns[EXTENDEDPRICE]);
		discount[i] = atof(columns[DISCOUNT]);
		tax[i] = atof(columns[TAX]);
		char return_flag = intern_string(return_item_codes,columns[RETURNFLAG]);
		char line_status = intern_string(line_status_codes, columns[LINESTATUS]);
		group[i] = (return_flag << 1) + line_status;
		ship_date[i] = convert_time(columns[SHIPDATE]);
	}
	
#define CREATE(typ, name) \
	typ* name = new typ[N_GROUPS]; \
	memset(name,0,sizeof(typ) * N_GROUPS);
	
	CREATE(int64_t,sum_qty);
	CREATE(double,sum_base_price);
	CREATE(double,sum_disc_price);
	CREATE(double,sum_charge);
	CREATE(double,avg_qty);
	CREATE(double,avg_price);
	CREATE(double,avg_disc);
	CREATE(int64_t,count);

	double begin = current_time();
	for(int k = 0; k < 100; k++) {
	for(int i = 0; i < N_ROWS; i++) {
		if(ship_date[i] <= ref_date - 24 * 60 * 60 * interval) {
			int grp = group[i];
			sum_qty[grp] += quantity[i];
			sum_base_price[grp] += extended_price[i];
			sum_disc_price[0] += discount[i];
			sum_charge[0] += tax[i];
			//sum_disc_price[grp] += extended_price[i] * (1 - discount[i]);
			//sum_charge[grp] += extended_price[i]*(1-discount[i])*(1+tax[i]);
			//double invnp1 = 1.0/(count[grp]+1);
			//avg_qty[grp] = update_average(avg_qty[grp],quantity[i],invnp1);
			//avg_price[grp] = update_average(avg_price[grp],extended_price[i],invnp1);
			//avg_disc[grp] = update_average(avg_disc[grp],discount[i],invnp1);
			//count[grp]++;
		}
	}
	}

	printf("Elapsed: %f\n", current_time()-begin);
	
#define REPORT(typ,name) do {\
	printf("%s = {",#name); \
	for(int i = 0; i < N_GROUPS; i++) { \
		PRINT_##typ(name[i]); \
	} \
	printf("}\n"); \
} while(0)

#define PRINT_int64_t(x) printf("%d,",(int)x)
#define PRINT_double(x) printf("%f, ",x)
	for(int i = 0; i < N_GROUPS; i++) {
		printf("%c %c\n", return_item_codes[i>>1], line_status_codes[i&1]);
	}
	REPORT(int64_t,sum_qty);
	REPORT(double,sum_base_price);
	REPORT(double,sum_disc_price);
	REPORT(double,sum_charge);
	REPORT(double,avg_qty);
	REPORT(double,avg_price);
	REPORT(double,avg_disc);
	REPORT(int64_t,count);
	
	
	return 0;
}