Exemple #1
0
char *s3d_read_file(const char *path, int text, int *size) {
    FILE *f = assert_ptr(fopen(path, "rb"));

    fseek(f, 0, SEEK_END);

    int _size = ftell(f);

    if(text) {
        ++_size;
    }

    if(size) {
        *size = _size;
    }

    fseek(f, 0, SEEK_SET);

    char *buf = assert_ptr(malloc(_size));
    fread(buf, 1, _size, f);

    if(text) {
        buf[_size - 1] = 0;
    }

    fclose(f);

    return buf;
}
Exemple #2
0
static char *
xalloc(size_t size)
{
    char *result = dlg_malloc(char, size);
    assert_ptr(result, "xalloc");
    return result;
}
Exemple #3
0
int StockInterAnim(char *lBufAnim, char *lBody, animTimerData *animTimerDataPtr) {  // copy the next keyFrame from a different buffer
	int temp;
	char *ptr;
	int *edi;
	int *esi;
	int var0;
	int var1;
	int var2;
	int counter;

	assert_ptr(lBufAnim);
	assert_ptr(lBody);

	temp = READ_LE_S16(lBody);

	if (temp & 2) {
		ptr = (lBody + 0x10);

		animTimerDataPtr->_time = lba_time;
		animTimerDataPtr->ptr = lBufAnim;

		var0 = READ_LE_S16(ptr - 2);
		ptr = ptr + var0;

		var1 = READ_LE_S16(ptr);
		var1 = var1 + var1 * 2;

		ptr = ptr + var1 * 2 + 2;

		var2 = READ_LE_S16(ptr);
		counter = var2;
		var2 = (var2 * 8) + 8;

		edi = (int *)(lBufAnim + 8);
		esi = (int *)(ptr + 10);

		do {
			WRITE_LE_U32(edi++, READ_LE_U32(esi++));
			WRITE_LE_U32(edi++, READ_LE_U32(esi++));

			esi = (int *)(((char *) esi) + 30);
		} while (--counter);

		return (var2);
	}
	return (0);
}
void
assert_string(const char *file, int line, const char *a1, const char *a2,
    const char *aa1, const char *aa2, enum test_predicate pred)
{
	int r;

	/* Verify pointers are not NULL */
	assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE);
	assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE);

	r = strcmp(aa1, aa2);
	TEST_CHECK_INT(r, pred);
	test_header(file, line, a1, a2, "STRING", pred);
	fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1, strlen(aa1));
	fprintf(stderr, "%12s = %s (len %zu)\n", a2, aa2, strlen(aa2));
	test_die();
}
void
assert_mem(const char *file, int line, const char *a1, const char *a2,
    const void *aa1, const void *aa2, size_t l, enum test_predicate pred)
{
	int r;

	if (l == 0)
		return;
	/* If length is >0, then verify pointers are not NULL */
	assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE);
	assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE);

	r = memcmp(aa1, aa2, l);
	TEST_CHECK_INT(r, pred);
	test_header(file, line, a1, a2, "STRING", pred);
	fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l);
	fprintf(stderr, "%12s = %s (len %zu)\n", a2, tohex(aa2, MIN(l, 256)), l);
	test_die();
}
Exemple #6
0
/*
 * Allocates a new object and fills it as per the arguments
 */
void *
dlg_allocate_gauge(const char *title,
		   const char *cprompt,
		   int height,
		   int width,
		   int percent)
{
    int x, y;
    char *prompt = dlg_strclone(cprompt);
    WINDOW *dialog;
    MY_OBJ *obj = 0;

    dlg_tab_correct_str(prompt);

    dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, MIN_WIDE);
    dlg_print_size(height, width);
    dlg_ctl_size(height, width);

    /* center dialog box on screen */
    x = dlg_box_x_ordinate(width);
    y = dlg_box_y_ordinate(height);

    dialog = dlg_new_window(height, width, y, x);

    obj = dlg_calloc(MY_OBJ, 1);
    assert_ptr(obj, "dialog_gauge");

    obj->obj.input = dialog_state.pipe_input;
    obj->obj.win = dialog;
    obj->obj.keep_win = TRUE;
    obj->obj.bg_task = TRUE;
    obj->obj.handle_getc = handle_my_getc;
    obj->obj.handle_input = handle_input;

    obj->title = title;
    obj->prompt = prompt;
    obj->percent = percent;
    obj->height = height;
    obj->width = width;

    obj->next = all_objects;
    all_objects = obj;

    return (void *) obj;
}
Exemple #7
0
static void
make_cache(CACHE * cache, const char *string)
{
    CACHE *p;

    p = dlg_calloc(CACHE, 1);
    assert_ptr(p, "load_cache");
    p->next = cache_list;
    cache_list = p;

    p->cache_at = cache;
    p->string_at = string;

    *cache = *p;
#ifdef HAVE_TSEARCH
    (void) tsearch(p, &sorted_cache, compare_cache);
#endif
}
Exemple #8
0
static CACHE *
make_cache(int cache_num, const char *string)
{
    CACHE *p;

    p = dlg_calloc(CACHE, 1);
    assert_ptr(p, "load_cache");
    p->next = cache_list;
    cache_list = p;

    p->cache_num = cache_num;
    p->string_at = string;

#ifdef HAVE_TSEARCH
    (void) tsearch(p, &sorted_cache, compare_cache);
#endif
    return p;
}
static char *
input_menu_edit(WINDOW *win, char **items, int choice)
{
    char *result;
    int offset = 0;
    int key = 0, fkey;
    int first = TRUE;
    /* see above */
    int y = ItemToRow(choice);

    result = malloc(dialog_vars.max_input);
    assert_ptr(result, "input_menu_edit");

    dialog_vars.max_input = dialog_vars.max_input;

    /* original item is used to initialize the input string. */
    result[0] = '\0';
    strcpy(result, ItemText(0));

    print_tag(win, items, choice, TRUE);

    /* taken out of inputbox.c - but somewhat modified */
    while (key != '\n' && key != '\r') {
	if (!first)
	    key = mouse_wgetch(win, &fkey);
	if (dlg_edit_string(result, &offset, key, fkey, first)) {
	    /* 
	     * menu_width - 2 ..... it's the actual number of maximal
	     *                      possible characters could be written
	     *                      to the screen.
	     *
	     * item_x - tag_x - 2 . same as "name_width"
	     *                      ( see in dialog_menu() )
	     */
	    dlg_show_string(win, result, offset, item_selected_attr,
			    y, item_x + 1, menu_width - item_x - 3,
			    FALSE, first);
	    first = FALSE;
	}
    }
    return result;
}
Exemple #10
0
mseRegion *
dlg_mouse_mkregion(int y, int x, int height, int width, int code)
{
    mseRegion *butPtr;

    if ((butPtr = find_region_by_code(code)) == 0) {
	butPtr = dlg_malloc(mseRegion, 1);
	assert_ptr(butPtr, "dlg_mouse_mkregion");
	butPtr->next = regionList;
	regionList = butPtr;
    }
    if (butPtr != 0) {
	butPtr->mode = -1;
	butPtr->step_x = 0;
	butPtr->step_y = 0;
	butPtr->y = basey + y;
	butPtr->Y = basey + y + height;
	butPtr->x = basex + x;
	butPtr->X = basex + x + width;
	butPtr->code = code;
    }
    return butPtr;
}
void
assert_mem_filled(const char *file, int line, const char *a1,
    const void *aa1, u_char v, size_t l, enum test_predicate pred)
{
	size_t where = -1;
	int r;
	char tmp[64];

	if (l == 0)
		return;
	/* If length is >0, then verify the pointer is not NULL */
	assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE);

	r = memvalcmp(aa1, v, l, &where);
	TEST_CHECK_INT(r, pred);
	test_header(file, line, a1, NULL, "MEM_ZERO", pred);
	fprintf(stderr, "%20s = %s%s (len %zu)\n", a1,
	    tohex(aa1, MIN(l, 20)), l > 20 ? "..." : "", l);
	snprintf(tmp, sizeof(tmp), "(%s)[%zu]", a1, where);
	fprintf(stderr, "%20s = 0x%02x (expected 0x%02x)\n", tmp,
	    ((u_char *)aa1)[where], v);
	test_die();
}
Exemple #12
0
/*
 * Display a dialog box with a list of options that can be turned on or off
 * The `flag' parameter is used to select between radiolist and checklist.
 */
int
dialog_checklist(const char *title,
		 const char *cprompt,
		 int height,
		 int width,
		 int list_height,
		 int item_no,
		 char **items,
		 int flag)
{
    int result;
    int i, j;
    DIALOG_LISTITEM *listitems;
    bool separate_output = ((flag == FLAG_CHECK)
			    && (dialog_vars.separate_output));
    bool show_status = FALSE;
    int current = 0;
    char *help_result;

    listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
    assert_ptr(listitems, "dialog_checklist");

    for (i = j = 0; i < item_no; ++i) {
	listitems[i].name = items[j++];
	listitems[i].text = (dialog_vars.no_items
			     ? dlg_strempty()
			     : items[j++]);
	listitems[i].state = !dlg_strcmp(items[j++], "on");
	listitems[i].help = ((dialog_vars.item_help)
			     ? items[j++]
			     : dlg_strempty());
    }
    dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);

    result = dlg_checklist(title,
			   cprompt,
			   height,
			   width,
			   list_height,
			   item_no,
			   listitems,
			   NULL,
			   flag,
			   &current);

    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
	show_status = TRUE;
	break;
    case DLG_EXIT_HELP:
	dlg_add_help_listitem(&result, &help_result, &listitems[current]);
	if ((show_status = dialog_vars.help_status)) {
	    if (separate_output) {
		dlg_add_string(help_result);
		dlg_add_separator();
	    } else {
		dlg_add_quoted(help_result);
	    }
	} else {
	    dlg_add_string(help_result);
	}
	break;
    }

    if (show_status) {
	for (i = 0; i < item_no; i++) {
	    if (listitems[i].state) {
		if (separate_output) {
		    dlg_add_string(listitems[i].name);
		    dlg_add_separator();
		} else {
		    if (dlg_need_separator())
			dlg_add_separator();
		    if (flag == FLAG_CHECK)
			dlg_add_quoted(listitems[i].name);
		    else
			dlg_add_string(listitems[i].name);
		}
	    }
	}
	dlg_add_last_key(separate_output);
    }

    dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
    free(listitems);
    return result;
}
Exemple #13
0
int
dlg_progressbox(const char *title,
		const char *cprompt,
		int height,
		int width,
		int pauseopt,
		FILE *fp)
{
    int i;
    int x, y, thigh;
    WINDOW *dialog, *text;
    MY_OBJ *obj;
    char *prompt = dlg_strclone(cprompt);
    int result;

    dlg_tab_correct_str(prompt);
    dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, MIN_WIDE);
    dlg_print_size(height, width);
    dlg_ctl_size(height, width);

    x = dlg_box_x_ordinate(width);
    y = dlg_box_y_ordinate(height);
    thigh = height - (2 * MARGIN);

    dialog = dlg_new_window(height, width, y, x);

    dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
    dlg_draw_title(dialog, title);
    dlg_draw_helpline(dialog, FALSE);

    if (*prompt != '\0') {
	int y2, x2;

	(void) wattrset(dialog, dialog_attr);
	dlg_print_autowrap(dialog, prompt, height, width);
	getyx(dialog, y2, x2);
	(void) x2;
	++y2;
	wmove(dialog, y2, MARGIN);
	for (i = 0; i < getmaxx(dialog) - 2 * MARGIN; i++)
	    (void) waddch(dialog, dlg_boxchar(ACS_HLINE));
	y += y2;
	thigh -= y2;
    }

    /* Create window for text region, used for scrolling text */
    text = dlg_sub_window(dialog,
			  thigh,
			  width - (2 * MARGIN),
			  y + MARGIN,
			  x + MARGIN);

    (void) wrefresh(dialog);

    (void) wmove(dialog, thigh, (MARGIN + 1));
    (void) wnoutrefresh(dialog);

    obj = dlg_calloc(MY_OBJ, 1);
    assert_ptr(obj, "dlg_progressbox");

    obj->obj.input = fp;
    obj->obj.win = dialog;
    obj->text = text;

    dlg_attr_clear(text, thigh, getmaxx(text), dialog_attr);
    for (i = 0; get_line(obj); i++) {
	if (i < thigh) {
	    print_line(obj, text, i, width - (2 * MARGIN));
	} else {
	    scrollok(text, TRUE);
	    scroll(text);
	    scrollok(text, FALSE);
	    print_line(obj, text, thigh - 1, width - (2 * MARGIN));
	}
	(void) wrefresh(text);
	dlg_trace_win(dialog);
	if (obj->is_eof)
	    break;
    }

    if (pauseopt) {
	scrollok(text, TRUE);
	wscrl(text, 1 + MARGIN);
	(void) wrefresh(text);
	result = pause_for_ok(dialog, height, width);
    } else {
	wrefresh(dialog);
	result = DLG_EXIT_OK;
    }

    dlg_del_window(dialog);
    free(prompt);
    free(obj);

    return result;
}
/*
 * Display a dialog box with a list of options that can be turned on or off
 * The `flag' parameter is used to select between radiolist and checklist.
 */
int
dialog_checklist(const char *title, const char *cprompt, int height, int width,
		 int list_height, int item_no, char **items, int flag,
		 int separate_output)
{
    int i, j, key2, found, x, y, cur_x, cur_y, box_x, box_y;
    int key = 0, fkey;
    int button = 0;
    int choice = 0;
    int scrollamt = 0;
    int max_choice, *status;
    int use_width, name_width, text_width;
    int result = DLG_EXIT_UNKNOWN;
    WINDOW *dialog, *list;
    char *prompt = strclone(cprompt);
    const char **buttons = dlg_ok_labels();

    tab_correct_str(prompt);
    if (list_height == 0) {
	use_width = calc_listw(item_no, items, CHECKBOX_TAGS) + 10;
	/* calculate height without items (4) */
	auto_size(title, prompt, &height, &width, 4, MAX(26, use_width));
	calc_listh(&height, &list_height, item_no);
    } else {
	auto_size(title, prompt, &height, &width, 4 + list_height, 26);
    }
    print_size(height, width);
    ctl_size(height, width);

    checkflag = flag;

    /* Allocate space for storing item on/off status */
    status = malloc(sizeof(int) * item_no);
    assert_ptr(status, "dialog_checklist");

    /* Initializes status */
    for (i = 0; i < item_no; i++)
	status[i] = !dlg_strcmp(ItemStatus(i), "on");

    max_choice = MIN(list_height, item_no);

    x = box_x_ordinate(width);
    y = box_y_ordinate(height);

    dialog = new_window(height, width, y, x);

    mouse_setbase(x, y);

    draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    draw_bottom_box(dialog);
    draw_title(dialog, title);

    wattrset(dialog, dialog_attr);
    print_autowrap(dialog, prompt, height, width);

    list_width = width - 6;
    getyx(dialog, cur_y, cur_x);
    box_y = cur_y + 1;
    box_x = (width - list_width) / 2 - 1;

    /* create new window for the list */
    list = sub_window(dialog, list_height, list_width,
		      y + box_y + 1, x + box_x + 1);

    /* draw a box around the list items */
    draw_box(dialog, box_y, box_x,
	     list_height + 2 * MARGIN,
	     list_width + 2 * MARGIN,
	     menubox_border_attr, menubox_attr);

    text_width = 0;
    name_width = 0;
    /* Find length of longest item to center checklist */
    for (i = 0; i < item_no; i++) {
	text_width = MAX(text_width, (int) strlen(ItemText(i)));
	name_width = MAX(name_width, (int) strlen(ItemName(i)));
    }

    /* If the name+text is wider than the list is allowed, then truncate
     * one or both of them.  If the name is no wider than 1/4 of the list,
     * leave it intact.
     */
    use_width = (list_width - 6);
    if (text_width + name_width > use_width) {
	int need = 0.25 * use_width;
	if (name_width > need) {
	    int want = use_width * ((double) name_width) / (text_width + name_width);
	    name_width = (want > need) ? want : need;
	}
	text_width = use_width - name_width;
    }

    check_x = (use_width - (text_width + name_width)) / 2;
    item_x = name_width + check_x + 6;

    /* Print the list */
    for (i = 0; i < max_choice; i++)
	print_item(list,
		   ItemData(i),
		   status[i], i, i == choice);
    (void) wnoutrefresh(list);

    /* register the new window, along with its borders */
    mouse_mkbigregion(box_y + 1, box_x, list_height, list_width + 2,
		      KEY_MAX, 1, 1, 1 /* by lines */ );

    dlg_draw_arrows(dialog, scrollamt,
		    scrollamt + max_choice < item_no - 1,
		    box_x + check_x + 5,
		    box_y,
		    box_y + list_height + 1);

    dlg_draw_buttons(dialog, height - 2, 0, buttons, 0, FALSE, width);

    wtimeout(dialog, WTIMEOUT_VAL);

    while (result == DLG_EXIT_UNKNOWN) {
	key = mouse_wgetch(dialog, &fkey);

	if (fkey && (key >= (M_EVENT + KEY_MAX))) {
	    getyx(dialog, cur_y, cur_x);
	    /* De-highlight current item */
	    print_item(list,
		       ItemData(scrollamt + choice),
		       status[scrollamt + choice], choice, FALSE);
	    /* Highlight new item */
	    choice = (key - (M_EVENT + KEY_MAX));
	    print_item(list,
		       ItemData(scrollamt + choice),
		       status[scrollamt + choice], choice, TRUE);
	    (void) wnoutrefresh(list);
	    (void) wmove(dialog, cur_y, cur_x);

	    key = ' ';		/* force the selected item to toggle */
	    fkey = FALSE;
	}

	/*
	 * A space toggles the item status.  We handle either a checklist
	 * (any number of items can be selected) or radio list (zero or one
	 * items can be selected).
	 */
	if (key == ' ') {
	    getyx(dialog, cur_y, cur_x);
	    if (flag == FLAG_CHECK) {	/* checklist? */
		status[scrollamt + choice] = !status[scrollamt + choice];
		print_item(list,
			   ItemData(scrollamt + choice),
			   status[scrollamt + choice], choice, TRUE);
	    } else {		/* radiolist */
		if (!status[scrollamt + choice]) {
		    for (i = 0; i < item_no; i++)
			status[i] = FALSE;
		    status[scrollamt + choice] = TRUE;
		    for (i = 0; i < max_choice; i++)
			print_item(list,
				   ItemData(scrollamt + i),
				   status[scrollamt + i], i, i == choice);
		}
	    }
	    (void) wnoutrefresh(list);
	    (void) wmove(dialog, cur_y, cur_x);
	    wrefresh(dialog);
	    continue;		/* wait for another key press */
	} else if (key == ESC) {
	    result = DLG_EXIT_ESC;
	    continue;
	}

	if (!fkey) {
	    fkey = TRUE;
	    switch (key) {
	    case '\n':
	    case '\r':
		key = KEY_ENTER;
		break;
	    case '-':
		key = KEY_UP;
		break;
	    case '+':
		key = KEY_DOWN;
		break;
	    case TAB:
		key = KEY_RIGHT;
		break;
	    default:
		fkey = FALSE;
		break;
	    }
	}

	/*
	 * Check if key pressed matches first character of any item tag in
	 * list.  If there is more than one match, we will cycle through
	 * each one as the same key is pressed repeatedly.
	 */
	found = FALSE;
	if (!fkey) {
	    for (j = scrollamt + choice + 1; j < item_no; j++) {
		if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
		    found = TRUE;
		    i = j - scrollamt;
		    break;
		}
	    }
	    if (!found) {
		for (j = 0; j <= scrollamt + choice; j++) {
		    if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
			found = TRUE;
			i = j - scrollamt;
			break;
		    }
		}
	    }
	    if (found)
		dlg_flush_getc();
	}

	/*
	 * A single digit (1-9) positions the selection to that line in the
	 * current screen.
	 */
	if (!found
	    && (key <= '9')
	    && (key > '0')
	    && (key - '1' < max_choice)) {
	    found = TRUE;
	    i = key - '1';
	}

	if (!found) {
	    if (fkey) {
		found = TRUE;
		switch (key) {
		case KEY_HOME:
		    i = -scrollamt;
		    break;
		case KEY_LL:
		case KEY_END:
		    i = item_no - 1 - scrollamt;
		    break;
		case M_EVENT + KEY_PPAGE:
		case KEY_PPAGE:
		    if (choice)
			i = 0;
		    else if (scrollamt != 0)
			i = -MIN(scrollamt, max_choice);
		    else
			continue;
		    break;
		case M_EVENT + KEY_NPAGE:
		case KEY_NPAGE:
		    i = MIN(choice + max_choice, item_no - scrollamt - 1);
		    break;
		case KEY_UP:
		    i = choice - 1;
		    if (choice == 0 && scrollamt == 0)
			continue;
		    break;
		case KEY_DOWN:
		    i = choice + 1;
		    if (scrollamt + choice >= item_no - 1)
			continue;
		    break;
		default:
		    found = FALSE;
		    break;
		}
	    }
	}

	if (found) {
	    if (i != choice) {
		getyx(dialog, cur_y, cur_x);
		if (i < 0 || i >= max_choice) {
#if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR < 5
		    /*
		     * Using wscrl to assist ncurses scrolling is not needed
		     * in version 5.x
		     */
		    if (i == -1) {
			if (list_height > 1) {
			    /* De-highlight current first item */
			    print_item(list,
				       ItemData(scrollamt),
				       status[scrollamt], 0, FALSE);
			    scrollok(list, TRUE);
			    wscrl(list, -1);
			    scrollok(list, FALSE);
			}
			scrollamt--;
			print_item(list,
				   ItemData(scrollamt),
				   status[scrollamt], 0, TRUE);
		    } else if (i == max_choice) {
			if (list_height > 1) {
			    /* De-highlight current last item before scrolling up */
			    print_item(list,
				       ItemData(scrollamt + max_choice - 1),
				       status[scrollamt + max_choice - 1],
				       max_choice - 1, FALSE);
			    scrollok(list, TRUE);
			    wscrl(list, 1);
			    scrollok(list, FALSE);
			}
			scrollamt++;
			print_item(list,
				   ItemData(scrollamt + max_choice - 1),
				   status[scrollamt + max_choice - 1],
				   max_choice - 1, TRUE);
		    } else
#endif
		    {
			if (i < 0) {
			    scrollamt += i;
			    choice = 0;
			} else {
			    choice = max_choice - 1;
			    scrollamt += (i - max_choice + 1);
			}
			for (i = 0; i < max_choice; i++) {
			    print_item(list,
				       ItemData(scrollamt + i),
				       status[scrollamt + i], i, i == choice);
			}
		    }
		    (void) wnoutrefresh(list);
		    dlg_draw_arrows(dialog, scrollamt,
				    scrollamt + choice < item_no - 1,
				    box_x + check_x + 5,
				    box_y,
				    box_y + list_height + 1);
		} else {
		    /* De-highlight current item */
		    print_item(list,
			       ItemData(scrollamt + choice),
			       status[scrollamt + choice], choice, FALSE);
		    /* Highlight new item */
		    choice = i;
		    print_item(list,
			       ItemData(scrollamt + choice),
			       status[scrollamt + choice], choice, TRUE);
		    (void) wnoutrefresh(list);
		    (void) wmove(dialog, cur_y, cur_x);
		    wrefresh(dialog);
		}
	    }
	    continue;		/* wait for another key press */
	}

	if (fkey) {
	    switch (key) {
	    case KEY_ENTER:
		result = dlg_ok_buttoncode(button);
		break;
	    case KEY_BTAB:
	    case KEY_LEFT:
		button = dlg_prev_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    case KEY_RIGHT:
		button = dlg_next_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    default:
		if (key >= M_EVENT) {
		    if ((key2 = dlg_ok_buttoncode(key - M_EVENT)) >= 0) {
			result = key2;
			break;
		    }
		    beep();
		}
	    }
	} else {
	    beep();
	}
    }

    del_window(dialog);
    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
	for (i = 0; i < item_no; i++) {
	    if (status[i]) {
		if (flag == FLAG_CHECK) {
		    if (separate_output) {
			dlg_add_result(ItemName(i));
			dlg_add_result("\n");
		    } else {
			dlg_add_result("\"");
			dlg_add_result(ItemName(i));
			dlg_add_result("\" ");
		    }
		} else {
		    dlg_add_result(ItemName(i));
		}
	    }
	}
	break;
    case DLG_EXIT_HELP:
	dlg_add_result("HELP ");
	if (USE_ITEM_HELP(ItemHelp(scrollamt + choice))) {
	    dlg_add_result(ItemHelp(scrollamt + choice));
	    result = DLG_EXIT_OK;	/* this is inconsistent */
	} else {
	    dlg_add_result(ItemName(scrollamt + choice));
	}
	break;
    }
    mouse_free_regions();
    free(status);
    free(prompt);
    return result;
}
Exemple #15
0
/*
 * Print a list of buttons at the given position.
 */
void
dlg_draw_buttons(WINDOW *win,
		 int y, int x,
		 const char **labels,
		 int selected,
		 int vertical,
		 int limit)
{
    chtype save = dlg_get_attrs(win);
    int n;
    int step = 0;
    int length;
    int longest;
    int final_x;
    int final_y;
    int gap;
    int margin;
    size_t need;
    char *buffer;

    dlg_mouse_setbase(getbegx(win), getbegy(win));

    getyx(win, final_y, final_x);

    dlg_button_sizes(labels, vertical, &longest, &length);

    if (vertical) {
	y += 1;
	step = 1;
    } else {
	dlg_button_x_step(labels, limit, &gap, &margin, &step);
	x += margin;
    }

    /*
     * Allocate a buffer big enough for any label.
     */
    need = (size_t) longest;
    for (n = 0; labels[n] != 0; ++n) {
	need += strlen(labels[n]) + 1;
    }
    buffer = dlg_malloc(char, need);
    assert_ptr(buffer, "dlg_draw_buttons");

    /*
     * Draw the labels.
     */
    for (n = 0; labels[n] != 0; n++) {
	center_label(buffer, longest, labels[n]);
	mouse_mkbutton(y, x, dlg_count_columns(buffer), n);
	print_button(win, buffer, y, x,
		     (selected == n) || (n == 0 && selected < 0));
	if (selected == n)
	    getyx(win, final_y, final_x);

	if (vertical) {
	    if ((y += step) > limit)
		break;
	} else {
	    if ((x += step) > limit)
		break;
	}
    }
    (void) wmove(win, final_y, final_x);
    wrefresh(win);
    free(buffer);
    wattrset(win, save);
}
Exemple #16
0
/*
 * Display a dialog box with a list of options that can be turned on or off
 * The `flag' parameter is used to select between radiolist and checklist.
 */
int
dialog_checklist(const char *title,
		 const char *cprompt,
		 int height,
		 int width,
		 int list_height,
		 int item_no,
		 char **items,
		 int flag)
{
    int result;
    int i;
    DIALOG_LISTITEM *listitems;
    bool separate_output = ((flag == FLAG_CHECK)
			    && (dialog_vars.separate_output));
    bool show_status = FALSE;
    int current = 0;

    listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
    assert_ptr(listitems, "dialog_checklist");

    for (i = 0; i < item_no; ++i) {
	listitems[i].name = ItemName(i);
	listitems[i].text = ItemText(i);
	listitems[i].help = ((dialog_vars.item_help)
			     ? ItemHelp(i)
			     : dlg_strempty());
	listitems[i].state = !dlg_strcmp(ItemStatus(i), "on");
    }
    dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);

    result = dlg_checklist(title,
			   cprompt,
			   height,
			   width,
			   list_height,
			   item_no,
			   listitems,
			   NULL,
			   flag,
			   &current);

    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
	show_status = TRUE;
	break;
    case DLG_EXIT_HELP:
	dlg_add_result("HELP ");
	show_status = dialog_vars.help_status;
	if (USE_ITEM_HELP(listitems[current].help)) {
	    if (show_status) {
		if (separate_output) {
		    dlg_add_string(listitems[current].help);
		    dlg_add_separator();
		} else {
		    dlg_add_quoted(listitems[current].help);
		}
	    } else {
		dlg_add_string(listitems[current].help);
	    }
	    result = DLG_EXIT_ITEM_HELP;
	} else {
	    if (show_status) {
		if (separate_output) {
		    dlg_add_string(listitems[current].name);
		    dlg_add_separator();
		} else {
		    dlg_add_quoted(listitems[current].name);
		}
	    } else {
		dlg_add_string(listitems[current].name);
	    }
	}
	break;
    }

    if (show_status) {
	for (i = 0; i < item_no; i++) {
	    if (listitems[i].state) {
		if (separate_output) {
		    dlg_add_string(listitems[i].name);
		    dlg_add_separator();
		} else {
		    if (dlg_need_separator())
			dlg_add_separator();
		    dlg_add_string(listitems[i].name);
		}
	    }
	}
    }

    dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
    free(listitems);
    return result;
}
Exemple #17
0
int
dialog_mixedform(const char *title,
                 const char *cprompt,
                 int height,
                 int width,
                 int form_height,
                 int item_no,
                 char **items)
{
    int result;
    int choice;
    int i;
    DIALOG_FORMITEM *listitems;
    DIALOG_VARS save_vars;
    bool show_status = FALSE;

    dlg_save_vars(&save_vars);
    dialog_vars.separate_output = TRUE;

    listitems = dlg_calloc(DIALOG_FORMITEM, (size_t) item_no + 1);
    assert_ptr(listitems, "dialog_mixedform");

    for (i = 0; i < item_no; ++i) {
        listitems[i].type = dialog_vars.formitem_type;
        listitems[i].name = ItemName(i);
        listitems[i].name_len = (int) strlen(ItemName(i));
        listitems[i].name_y = dlg_ordinate(ItemNameY(i));
        listitems[i].name_x = dlg_ordinate(ItemNameX(i));
        listitems[i].text = ItemText(i);
        listitems[i].text_len = (int) strlen(ItemText(i));
        listitems[i].text_y = dlg_ordinate(ItemTextY(i));
        listitems[i].text_x = dlg_ordinate(ItemTextX(i));
        listitems[i].text_flen = atoi(ItemTextFLen(i));
        listitems[i].text_ilen = atoi(ItemTextILen(i));
        listitems[i].help = (dialog_vars.item_help ? ItemHelp(i) :
                             dlg_strempty());
        listitems[i].type = (unsigned) atoi(ItemTypep(i));
    }

    result = dlg_form(title,
                      cprompt,
                      height,
                      width,
                      form_height,
                      item_no,
                      listitems,
                      &choice);

    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
        show_status = TRUE;
        break;
    case DLG_EXIT_HELP:
        dlg_add_result("HELP ");
        show_status = dialog_vars.help_status;
        if (USE_ITEM_HELP(listitems[choice].help)) {
            dlg_add_string(listitems[choice].help);
            result = DLG_EXIT_ITEM_HELP;
        } else {
            dlg_add_string(listitems[choice].name);
        }
        if (show_status)
            dlg_add_separator();
        break;
    }
    if (show_status) {
        for (i = 0; i < item_no; i++) {
            if (listitems[i].text_flen > 0) {
                dlg_add_string(listitems[i].text);
                dlg_add_separator();
            }
        }
        dlg_add_last_key(-1);
    }

    dlg_free_formitems(listitems);
    dlg_restore_vars(&save_vars);

    return result;
}
Exemple #18
0
/*
 * Display text from a file in a dialog box, like in a "tail -f".
 */
int
dialog_tailbox(const char *title, const char *file, int height, int width, int bg_task)
{
    /* *INDENT-OFF* */
    static DLG_KEYS_BINDING binding[] = {
	HELPKEY_BINDINGS,
	ENTERKEY_BINDINGS,
	DLG_KEYS_DATA( DLGK_BEGIN,      '0' ),
	DLG_KEYS_DATA( DLGK_BEGIN,      KEY_BEG ),
	DLG_KEYS_DATA( DLGK_GRID_LEFT,  'H' ),
	DLG_KEYS_DATA( DLGK_GRID_LEFT,  'h' ),
	DLG_KEYS_DATA( DLGK_GRID_LEFT,  KEY_LEFT ),
	DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'L' ),
	DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'l' ),
	DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_RIGHT ),
	END_KEYS_BINDING
    };
    /* *INDENT-ON* */

#ifdef KEY_RESIZE
    int old_height = height;
    int old_width = width;
#endif
    int fkey;
    int x, y, result, thigh;
    WINDOW *dialog, *text;
    const char **buttons = 0;
    MY_OBJ *obj;
    FILE *fd;
    int min_width = 12;

    /* Open input file for reading */
    if ((fd = fopen(file, "rb")) == NULL)
	dlg_exiterr("Can't open input file in dialog_tailbox().");

#ifdef KEY_RESIZE
  retry:
#endif
    dlg_auto_sizefile(title, file, &height, &width, 2, min_width);
    dlg_print_size(height, width);
    dlg_ctl_size(height, width);

    x = dlg_box_x_ordinate(width);
    y = dlg_box_y_ordinate(height);
    thigh = height - ((2 * MARGIN) + (bg_task ? 0 : 2));

    dialog = dlg_new_window(height, width, y, x);

    dlg_mouse_setbase(x, y);

    /* Create window for text region, used for scrolling text */
    text = dlg_sub_window(dialog,
			  thigh,
			  width - (2 * MARGIN),
			  y + MARGIN,
			  x + MARGIN);

    dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    dlg_draw_bottom_box(dialog);
    dlg_draw_title(dialog, title);
    dlg_draw_helpline(dialog, FALSE);

    if (!bg_task) {
	buttons = dlg_exit_label();
	dlg_button_layout(buttons, &min_width);
	dlg_draw_buttons(dialog, height - (2 * MARGIN), 0, buttons, FALSE,
			 FALSE, width);
    }

    (void) wmove(dialog, thigh, (MARGIN + 1));
    (void) wnoutrefresh(dialog);

    obj = dlg_calloc(MY_OBJ, 1);
    assert_ptr(obj, "dialog_tailbox");

    obj->obj.input = fd;
    obj->obj.win = dialog;
    obj->obj.handle_getc = handle_my_getc;
    obj->obj.handle_input = bg_task ? handle_input : 0;
    obj->obj.keep_bg = bg_task && dialog_vars.cant_kill;
    obj->obj.bg_task = bg_task;
    obj->text = text;
    obj->buttons = buttons;
    dlg_add_callback(&(obj->obj));

    dlg_register_window(dialog, "tailbox", binding);
    dlg_register_buttons(dialog, "tailbox", buttons);

    /* Print last page of text */
    dlg_attr_clear(text, thigh, getmaxx(text), dialog_attr);
    repaint_text(obj);

    if (bg_task) {
	result = DLG_EXIT_OK;
    } else {
	int ch;
	do {
	    ch = dlg_getc(dialog, &fkey);
#ifdef KEY_RESIZE
	    if (fkey && ch == KEY_RESIZE) {
		/* reset data */
		height = old_height;
		width = old_width;
		/* repaint */
		dlg_clear();
		dlg_del_window(dialog);
		refresh();
		dlg_mouse_free_regions();
		dlg_button_layout(buttons, &min_width);
		goto retry;
	    }
#endif
	}
	while (handle_my_getc(&(obj->obj), ch, fkey, &result));
    }
    dlg_mouse_free_regions();
    return result;
}
Exemple #19
0
int SetInterAnimObjet(int animState, char *animData, char *body, animTimerData *animTimerDataPtr) {
	short int animOpcode;

	short int var0;

	char *edi;
	char *ebx;
	int ebp;
	int eax;
	int keyFrameLength;
	int numOfPointInBody;
	int numOfPointInAnim;
	char *keyFramePtrOld;

	numOfPointInAnim = READ_LE_U16(animData + 2);

	keyFramePtr = ((numOfPointInAnim * 8 + 8) * animState) + animData + 8;

	keyFrameLength = READ_LE_U16(keyFramePtr);

	var0 = READ_LE_U16(body);

	if (!(var0 & 2)) {
		return (0);
	}

	edi = body + 16;

	ebx = animTimerDataPtr->ptr;
	ebp = animTimerDataPtr->_time;

	if (!ebx) {
		ebx = keyFramePtr;
		ebp = keyFrameLength;
	} else {
		assert_ptr(ebx);
	}

	lastKeyFramePtr = ebx;

	eax = READ_LE_S16(edi - 2);
	edi += eax;

	eax = READ_LE_S16(edi);
	eax = eax + eax * 2;
	edi = edi + eax * 2 + 12;

	numOfPointInBody = READ_LE_S16(edi - 10);

	if (numOfPointInAnim > numOfPointInBody) {
		numOfPointInAnim = numOfPointInBody;
	}

	eax = lba_time - ebp;

	if (eax >= keyFrameLength) {
		int *destPtr; // keyFrame
		int *sourcePtr;

		sourcePtr = (int *)(keyFramePtr + 8);
		destPtr = (int *) edi;

		do {
			WRITE_LE_U32(destPtr++, READ_LE_U32(sourcePtr++));
			WRITE_LE_U32(destPtr++, READ_LE_U32(sourcePtr++));

			destPtr = (int *)(((char *) destPtr) + 30);
		} while (--numOfPointInAnim);

		animTimerDataPtr->ptr = keyFramePtr;
		animTimerDataPtr->_time = lba_time;

		currentX = READ_LE_S16(keyFramePtr + 2);
		currentZ = READ_LE_S16(keyFramePtr + 4);
		currentY = READ_LE_S16(keyFramePtr + 6);

		processActorVar5 = READ_LE_S16(keyFramePtr + 8);
		processActorSub2Var0 = READ_LE_S16(keyFramePtr + 10);
		processActorVar6 = READ_LE_S16(keyFramePtr + 12);
		processActorSub2Var1 = READ_LE_S16(keyFramePtr + 14);

		return (1);
	} else {
		keyFramePtrOld = keyFramePtr;

		lastKeyFramePtr += 8;
		keyFramePtr += 8;

		processActorVar5 = READ_LE_S16(keyFramePtr);
		processActorSub2Var0 = (READ_LE_S16(keyFramePtr + 2) * eax) / keyFrameLength;
		processActorVar6 = (READ_LE_S16(keyFramePtr + 4) * eax) / keyFrameLength;
		processActorSub2Var1 = (READ_LE_S16(keyFramePtr + 6) * eax) / keyFrameLength;

		lastKeyFramePtr += 8;
		keyFramePtr += 8;

		edi += 38;

		if (--numOfPointInAnim) {
			animVar4 = numOfPointInAnim;

			do {
				animOpcode = PatchType(&edi);

				switch (animOpcode) {
				case 0: {   // allow global rotate
					PatchInterAngle(&edi, eax, keyFrameLength);
					PatchInterAngle(&edi, eax, keyFrameLength);
					PatchInterAngle(&edi, eax, keyFrameLength);
					break;
				}
				case 1: {   // dissallow global rotate
					PatchInterStep(&edi, eax, keyFrameLength);
					PatchInterStep(&edi, eax, keyFrameLength);
					PatchInterStep(&edi, eax, keyFrameLength);
					break;
				}
				case 2: {   // dissallow global rotate + hide
					PatchInterStep(&edi, eax, keyFrameLength);
					PatchInterStep(&edi, eax, keyFrameLength);
					PatchInterStep(&edi, eax, keyFrameLength);
					break;
				}
				default: {
					printf("Unsupported rotaton mode %d in SetInterAnimObjet!\n", animOpcode);
					exit(1);
				}
				}

				edi += 30;
			} while (--animVar4);
		}

		currentX = (READ_LE_S16(keyFramePtrOld + 2) * eax) / keyFrameLength;
		currentZ = (READ_LE_S16(keyFramePtrOld + 4) * eax) / keyFrameLength;
		currentY = (READ_LE_S16(keyFramePtrOld + 6) * eax) / keyFrameLength;
	}

	return (0);
}