Ejemplo n.º 1
0
static int WordSylSeg(cst_utterance *u)
{
    cst_item *word;
    cst_relation *sylstructure,*seg,*syl;
    cst_val *phones;
    const cst_val *p;
    cst_item *ssword,*segitem;
    
    syl = utt_relation_create(u,"Syllable");
    sylstructure = utt_relation_create(u,"SylStructure");
    seg = utt_relation_create(u,"Segment");
    
    for (word=relation_head(utt_relation(u,"Word")); 
	 word; word=item_next(word))
    {
	printf("word: %s\n",item_feat_string(word,"name"));
	ssword = relation_append(sylstructure,word);
	phones = lex_lookup((cst_lexicon *)&cmu_lex,item_feat_string(word,"name"),0);
	for (p=phones; p; p=val_cdr(p))
	{
	    segitem = relation_append(seg,NULL);
	    item_set(segitem,"name",val_car(p));
	    printf("seg: %s\n",item_feat_string(segitem,"name"));
	    item_add_daughter(ssword,segitem);
	}
	delete_val_list(phones);
    }

    return TRUE;

}
Ejemplo n.º 2
0
static cst_utterance *cg_make_params(cst_utterance *utt)
{
    /* puts in the frame items */
    /* historically called "mcep" but can actually be any random vectors */
    cst_cg_db *cg_db;
    cst_relation *mcep, *mcep_link;
    cst_item *s, *mcep_parent, *mcep_frame;
    int num_frames;
    float start, end;
    float dur_stretch, tok_stretch;

    cg_db = val_cg_db(utt_feat_val(utt,"cg_db"));
    mcep = utt_relation_create(utt,"mcep");
    mcep_link = utt_relation_create(utt,"mcep_link");
    end = 0.0;
    num_frames = 0;
    dur_stretch = get_param_float(utt->features,"duration_stretch", 1.0);

    for (s = utt_rel_head(utt,"HMMstate"); s; s=item_next(s))
    {
        start = end;
        tok_stretch = ffeature_float(s,"R:segstate.parent.R:SylStructure.parent.parent.R:Token.parent.local_duration_stretch");
        if (tok_stretch == 0)
            tok_stretch = 1.0;
        end = start + (tok_stretch*dur_stretch*cg_state_duration(s,cg_db));
        item_set_float(s,"end",end);
        mcep_parent = relation_append(mcep_link, s);
        for ( ; (num_frames * cg_db->frame_advance) <= end; num_frames++ )
        {
            mcep_frame = relation_append(mcep,NULL);
            item_add_daughter(mcep_parent,mcep_frame);
            item_set_int(mcep_frame,"frame_number",num_frames);
            item_set(mcep_frame,"name",item_feat(mcep_parent,"name"));
        }
    }

    /* Copy duration up onto Segment relation */
    for (s = utt_rel_head(utt,"Segment"); s; s=item_next(s))
        item_set(s,"end",ffeature(s,"R:segstate.daughtern.end"));

    utt_set_feat_int(utt,"param_track_num_frames",num_frames);

    return utt;
}
Ejemplo n.º 3
0
struct item *add_item(struct page *pg, long money, const struct string *desc, const struct string *comment)
{
	struct item *p;
	if ((p = add_dummy_item(pg)) == NULL) return NULL;
	if (item_set(p, money, desc, comment) == NULL) {
		delete_item(p);
		return NULL;
	}
	return p;
}
Ejemplo n.º 4
0
void DataGrid::onCellChange(wxGridEvent &event)
{
	long money = 0, moneyI = 0, moneyO = 0;
	int row = event.GetRow();
	int col = event.GetCol();
	struct item *it = dataPosFromRow(row);
	wxString text;
	if (m_data == NULL || row == 0) return;
	if (!(text = GetCellValue(row, IncomeIndex)).IsEmpty()) {
		moneyI = -str_to_money(text);
	}
	if (!(text = GetCellValue(row, OutlayIndex)).IsEmpty()) {
		moneyO = str_to_money(text);
	}
	if (moneyI != 0 && moneyO != 0) {
		wxMessageBox(HaStrings::errDupMoney, HaStrings::appName, wxOK | wxICON_ERROR);
		if (col == IncomeIndex) {
			money = moneyI;
			SetCellValue(row, OutlayIndex, wxT(""));
		} else if (col == OutlayIndex) {
			money = moneyO;
			SetCellValue(row, IncomeIndex, wxT(""));
		}
	} else if (moneyI != 0) {
		money = moneyI;
		SetCellValue(row, OutlayIndex, wxT(""));
	} else {
		money = moneyO;
		SetCellValue(row, IncomeIndex, wxT(""));
	}
	wxString desc = GetCellValue(row, DescIndex);
	desc.Trim(true).Trim(false);
	wxString comment = GetCellValue(row, CommentIndex);
	comment.Trim(true).Trim(false);
	struct string s_desc, s_comment;
	string_fill_slice(&s_desc, desc, '\0');
	string_fill_slice(&s_comment, comment, '\0');
	if (item_set(it, money, &s_desc, &s_comment) == NULL) throw std::bad_alloc();
	m_data->setModified();
	if (col == IncomeIndex || col == OutlayIndex) {
		updateBalanceAndTotal();
	}
	if (is_dummy_item(it)) clearRow(row);
	wxCommandEvent ev(wxEVT_RESIZE_COL, GetId());
	ev.SetEventObject(this);
	ev.SetInt(col);
	wxPostEvent(this, ev);
}
Ejemplo n.º 5
0
//inline 
error_t remote_fifo_put(struct remote_fifo_s *remote_fifo, cid_t cid, void *item)
{
	size_t wridx;
	size_t rdidx;
	size_t total_slot_nbr;
	uint_t irq_state;

#if RF_PRINT
	uint32_t start;
	uint32_t end;

	start = cpu_time_stamp(); //cpu_get_ticks(current_cpu);
#endif

	total_slot_nbr  = remote_lw((void*)&remote_fifo->slot_nbr, cid);

	//assert(size);//if the message is bigger than cacheline, it could wrap arround the fifo => msg is not countigius

	mcs_lock_remote(&remote_fifo->lock, cid, &irq_state);

	wridx = remote_lw((void*)&remote_fifo->wridx, cid);
	rdidx = remote_lw((void*)&remote_fifo->rdidx, cid);

	if(((wridx + 1) % total_slot_nbr) == rdidx)
	{
		mcs_unlock_remote(&remote_fifo->lock, cid, irq_state);
		return EAGAIN;
	}

	item_set(remote_fifo, cid, item, wridx);

	remote_sw((void*)&remote_fifo->wridx, cid, 
				(wridx + 1) % total_slot_nbr);
	
	mcs_unlock_remote(&remote_fifo->lock, cid, irq_state);

#if RF_PRINT
	end = cpu_time_stamp();

	printk(INFO, "[%d] %s: posting in cid %d at %d\n", 
		cpu_get_id(), __FUNCTION__, cid, end-start);
#endif
	return 0;
}
Ejemplo n.º 6
0
/*
 * Display a menu for choosing among a number of options
 */
int dialog_menu(const char *title, const char *prompt,
                const void *selected, int *s_scroll)
{
	int i, j, x, y, box_x, box_y;
	int height, width, menu_height;
	int key = 0, button = 0, scroll = 0, choice = 0;
	int first_item =  0, max_choice;
	WINDOW *dialog, *menu;

do_resize:
	height = getmaxy(stdscr);
	width = getmaxx(stdscr);
	if (height < 15 || width < 65)
		return -ERRDISPLAYTOOSMALL;

	height -= 4;
	width  -= 5;
	menu_height = height - 10;

	max_choice = MIN(menu_height, item_count());

	/* center dialog box on screen */
	x = (COLS - width) / 2;
	y = (LINES - height) / 2;

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);
	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	wattrset(dialog, dlg.dialog.atr);
	print_autowrap(dialog, prompt, width - 2, 1, 3);

	menu_width = width - 6;
	box_y = height - menu_height - 5;
	box_x = (width - menu_width) / 2 - 1;

	/* create new window for the menu */
	menu = subwin(dialog, menu_height, menu_width,
		      y + box_y + 1, x + box_x + 1);
	keypad(menu, TRUE);

	/* draw a box around the menu items */
	draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
		 dlg.menubox_border.atr, dlg.menubox.atr);

	if (menu_width >= 80)
		item_x = (menu_width - 70) / 2;
	else
		item_x = 4;

	/* Set choice to default item */
	item_foreach()
		if (selected && (selected == item_data()))
			choice = item_n();
	/* get the saved scroll info */
	scroll = *s_scroll;
	if ((scroll <= choice) && (scroll + max_choice > choice) &&
	   (scroll >= 0) && (scroll + max_choice <= item_count())) {
		first_item = scroll;
		choice = choice - scroll;
	} else {
		scroll = 0;
	}
	if ((choice >= max_choice)) {
		if (choice >= item_count() - max_choice / 2)
			scroll = first_item = item_count() - max_choice;
		else
			scroll = first_item = choice - max_choice / 2;
		choice = choice - scroll;
	}

	/* Print the menu */
	for (i = 0; i < max_choice; i++) {
		print_item(first_item + i, i, i == choice);
	}

	wnoutrefresh(menu);

	print_arrows(dialog, item_count(), scroll,
		     box_y, box_x + item_x + 1, menu_height);

	print_buttons(dialog, height, width, 0);
	wmove(menu, choice, item_x + 1);
	wrefresh(menu);

	while (key != KEY_ESC) {
		key = wgetch(menu);

		if (key < 256 && isalpha(key))
			key = tolower(key);

		if (strchr("ynmh", key))
			i = max_choice;
		else {
			for (i = choice + 1; i < max_choice; i++) {
				item_set(scroll + i);
				j = first_alpha(item_str(), "YyNnMmHh");
				if (key == tolower(item_str()[j]))
					break;
			}
			if (i == max_choice)
				for (i = 0; i < max_choice; i++) {
					item_set(scroll + i);
					j = first_alpha(item_str(), "YyNnMmHh");
					if (key == tolower(item_str()[j]))
						break;
				}
		}

		if (i < max_choice ||
		    key == KEY_UP || key == KEY_DOWN ||
		    key == '-' || key == '+' ||
		    key == KEY_PPAGE || key == KEY_NPAGE) {
			/* Remove highligt of current item */
			print_item(scroll + choice, choice, FALSE);

			if (key == KEY_UP || key == '-') {
				if (choice < 2 && scroll) {
					/* Scroll menu down */
					do_scroll(menu, &scroll, -1);

					print_item(scroll, 0, FALSE);
				} else
					choice = MAX(choice - 1, 0);

			} else if (key == KEY_DOWN || key == '+') {
				print_item(scroll+choice, choice, FALSE);

				if ((choice > max_choice - 3) &&
				    (scroll + max_choice < item_count())) {
					/* Scroll menu up */
					do_scroll(menu, &scroll, 1);

					print_item(scroll+max_choice - 1,
						   max_choice - 1, FALSE);
				} else
					choice = MIN(choice + 1, max_choice - 1);

			} else if (key == KEY_PPAGE) {
				scrollok(menu, TRUE);
				for (i = 0; (i < max_choice); i++) {
					if (scroll > 0) {
						do_scroll(menu, &scroll, -1);
						print_item(scroll, 0, FALSE);
					} else {
						if (choice > 0)
							choice--;
					}
				}

			} else if (key == KEY_NPAGE) {
				for (i = 0; (i < max_choice); i++) {
					if (scroll + max_choice < item_count()) {
						do_scroll(menu, &scroll, 1);
						print_item(scroll+max_choice-1,
							   max_choice - 1, FALSE);
					} else {
						if (choice + 1 < max_choice)
							choice++;
					}
				}
			} else
				choice = i;

			print_item(scroll + choice, choice, TRUE);

			print_arrows(dialog, item_count(), scroll,
				     box_y, box_x + item_x + 1, menu_height);

			wnoutrefresh(dialog);
			wrefresh(menu);

			continue;	/* wait for another key press */
		}

		switch (key) {
		case KEY_LEFT:
		case TAB:
		case KEY_RIGHT:
			button = ((key == KEY_LEFT ? --button : ++button) < 0)
			    ? 2 : (button > 2 ? 0 : button);

			print_buttons(dialog, height, width, button);
			wrefresh(menu);
			break;
		case ' ':
		case 's':
		case 'y':
		case 'n':
		case 'm':
		case '/':
			/* save scroll info */
			*s_scroll = scroll;
			delwin(menu);
			delwin(dialog);
			item_set(scroll + choice);
			item_set_selected(1);
			switch (key) {
			case 's':
				return 3;
			case 'y':
				return 3;
			case 'n':
				return 4;
			case 'm':
				return 5;
			case ' ':
				return 6;
			case '/':
				return 7;
			}
			return 0;
		case 'h':
		case '?':
			button = 2;
		case '\n':
			*s_scroll = scroll;
			delwin(menu);
			delwin(dialog);
			item_set(scroll + choice);
			item_set_selected(1);
			return button;
		case 'e':
		case 'x':
			key = KEY_ESC;
			break;
		case KEY_ESC:
			key = on_key_esc(menu);
			break;
#ifdef NCURSES_VERSION
		case KEY_RESIZE:
			on_key_resize();
			delwin(menu);
			delwin(dialog);
			goto do_resize;
#endif
		}
	}
	delwin(menu);
	delwin(dialog);
	return key;		/* ESC pressed */
}
Ejemplo n.º 7
0
int dialog_checklist(const char *title, const char *prompt, int height,
		     int width, int list_height)
{
	int i, x, y, box_x, box_y;
	int key = 0, button = 0, choice = 0, scroll = 0, max_choice;
	WINDOW *dialog, *list;

	/*                         */
	item_foreach() {
		if (item_is_tag('X'))
			choice = item_n();
		if (item_is_selected()) {
			choice = item_n();
			break;
		}
	}

do_resize:
	if (getmaxy(stdscr) < (height + 6))
		return -ERRDISPLAYTOOSMALL;
	if (getmaxx(stdscr) < (width + 6))
		return -ERRDISPLAYTOOSMALL;

	max_choice = MIN(list_height, item_count());

	/*                             */
	x = (COLS - width) / 2;
	y = (LINES - height) / 2;

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);
	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	wattrset(dialog, dlg.dialog.atr);
	print_autowrap(dialog, prompt, width - 2, 1, 3);

	list_width = width - 6;
	box_y = height - list_height - 5;
	box_x = (width - list_width) / 2 - 1;

	/*                                */
	list = subwin(dialog, list_height, list_width, y + box_y + 1,
	              x + box_x + 1);

	keypad(list, TRUE);

	/*                                  */
	draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2,
	         dlg.menubox_border.atr, dlg.menubox.atr);

	/*                                                          */
	check_x = 0;
	item_foreach()
		check_x = MAX(check_x, strlen(item_str()) + 4);
	check_x = MIN(check_x, list_width);

	check_x = (list_width - check_x) / 2;
	item_x = check_x + 4;

	if (choice >= list_height) {
		scroll = choice - list_height + 1;
		choice -= scroll;
	}

	/*                */
	for (i = 0; i < max_choice; i++) {
		item_set(scroll + i);
		print_item(list, i, i == choice);
	}

	print_arrows(dialog, choice, item_count(), scroll,
		     box_y, box_x + check_x + 5, list_height);

	print_buttons(dialog, height, width, 0);

	wnoutrefresh(dialog);
	wnoutrefresh(list);
	doupdate();

	while (key != KEY_ESC) {
		key = wgetch(dialog);

		for (i = 0; i < max_choice; i++) {
			item_set(i + scroll);
			if (toupper(key) == toupper(item_str()[0]))
				break;
		}

		if (i < max_choice || key == KEY_UP || key == KEY_DOWN ||
		    key == '+' || key == '-') {
			if (key == KEY_UP || key == '-') {
				if (!choice) {
					if (!scroll)
						continue;
					/*                  */
					if (list_height > 1) {
						/*                                 */
						item_set(scroll);
						print_item(list, 0, FALSE);
						scrollok(list, TRUE);
						wscrl(list, -1);
						scrollok(list, FALSE);
					}
					scroll--;
					item_set(scroll);
					print_item(list, 0, TRUE);
					print_arrows(dialog, choice, item_count(),
						     scroll, box_y, box_x + check_x + 5, list_height);

					wnoutrefresh(dialog);
					wrefresh(list);

					continue;	/*                            */
				} else
					i = choice - 1;
			} else if (key == KEY_DOWN || key == '+') {
				if (choice == max_choice - 1) {
					if (scroll + choice >= item_count() - 1)
						continue;
					/*                */
					if (list_height > 1) {
						/*                                                    */
						item_set(scroll + max_choice - 1);
						print_item(list,
							    max_choice - 1,
							    FALSE);
						scrollok(list, TRUE);
						wscrl(list, 1);
						scrollok(list, FALSE);
					}
					scroll++;
					item_set(scroll + max_choice - 1);
					print_item(list, max_choice - 1, TRUE);

					print_arrows(dialog, choice, item_count(),
						     scroll, box_y, box_x + check_x + 5, list_height);

					wnoutrefresh(dialog);
					wrefresh(list);

					continue;	/*                            */
				} else
					i = choice + 1;
			}
			if (i != choice) {
				/*                           */
				item_set(scroll + choice);
				print_item(list, choice, FALSE);
				/*                    */
				choice = i;
				item_set(scroll + choice);
				print_item(list, choice, TRUE);
				wnoutrefresh(dialog);
				wrefresh(list);
			}
			continue;	/*                            */
		}
		switch (key) {
		case 'H':
		case 'h':
		case '?':
			button = 1;
			/*              */
		case 'S':
		case 's':
		case ' ':
		case '\n':
			item_foreach()
				item_set_selected(0);
			item_set(scroll + choice);
			item_set_selected(1);
			delwin(list);
			delwin(dialog);
			return button;
		case TAB:
		case KEY_LEFT:
		case KEY_RIGHT:
			button = ((key == KEY_LEFT ? --button : ++button) < 0)
			    ? 1 : (button > 1 ? 0 : button);

			print_buttons(dialog, height, width, button);
			wrefresh(dialog);
			break;
		case 'X':
		case 'x':
			key = KEY_ESC;
			break;
		case KEY_ESC:
			key = on_key_esc(dialog);
			break;
		case KEY_RESIZE:
			delwin(list);
			delwin(dialog);
			on_key_resize();
			goto do_resize;
		}

		/*                           */
		doupdate();
	}
	delwin(list);
	delwin(dialog);
	return key;		/*             */
}
Ejemplo n.º 8
0
int main(int argc, char **argv) {
    config_init();

    int c;
    
    while (-1 != (c = getopt(argc, argv, "n:m:k:d:p:h"))) {
        switch(c) {
            case 'n':
                config.num = atoi(optarg);
                break;
            case 'm':
                config.maxbytes = ((size_t)atoi(optarg)) * 1024 * 1024;
                break;
            case 'k':
                config.keysize = atoi(optarg);
                break;
            case 'd':
                config.datasize = atoi(optarg);
                break;
            case 'p':
                config.hashpower = atoi(optarg);
                break;
            case 'h':
                usage();
                return EXIT_SUCCESS;
            default:
                usage();
                return EXIT_FAILURE;
        }
    }

    generate_key_init();
    print_env();
    lru *l = lru_init(config.maxbytes, config.hashpower);

    char *bvalue = malloc(config.datasize);
    memset(bvalue, 'x', config.datasize);

    char *key = malloc(config.keysize);
    memset(key, 0, config.keysize);

    int gnum = config.keysize - num_;

    generate_key_reset();
    bench_start("SET");
    int i;
    for (i = 0; i < config.num; i++) {
        snprintf(key, config.keysize, fmt_, gnum, generate_key(gnum), i);
        int r = item_set(l, key, config.keysize, bvalue, config.datasize);
        assert(r == 0);
        process_report();
    }
    bench_stop();
    print_stat(l);

    char *buf = malloc(config.datasize);
    size_t sz;
    generate_key_reset();
    bench_start("GET");
    for (i = 0; i < config.num; i++) {
        snprintf(key, config.keysize, fmt_, gnum, generate_key(gnum), i);
        int r = item_get(l, key, config.keysize, buf, config.datasize, &sz);
        if (!r) {
            assert((int)sz == config.datasize);
            assert(memcmp(bvalue, buf, config.datasize) == 0);
        }
        memset(buf, 0, config.datasize);
        process_report();
    }
    bench_stop();
    print_stat(l);

    generate_key_reset();
    bench_start("DELETE");
    for (i = 0; i < config.num; i++) {
        snprintf(key, config.keysize, fmt_, gnum, generate_key(gnum), i);
        item_delete(l, key, config.keysize);
        process_report();
    }
    bench_stop();
    print_stat(l);
    
    free(buf);
    free(bvalue);
    free(key);
    free(fmt_);
    free(key_);
   
    lru_free(l);
    /*
    printf("print any key to exit...\n");
    getchar();
    */
    return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
Item *item_new(char const *str, int value) {
	Item *this = malloc(sizeof(Item));
	item_init(this);
	item_set(this, str, value);
	return this;
}