FreeBSD/contrib/dialog/guage.c
/*
 * (Re)Allocates an object and fills it as per the arguments
 */
(Re)Allocates an object and fills it as per the arguments
( Re ) Allocates an object and fills it as per the arguments
void *
dlg_reallocate_gauge(void *objptr,
		     const char *title,
		     const char *cprompt,
		     int height,
		     int width,
		     int percent)
{
    char *prompt = dlg_strclone(cprompt);
    MY_OBJ *obj = objptr;
    bool save_finish_string = dialog_state.finish_string;
    dialog_state.finish_string = TRUE;
    dlg_tab_correct_str(prompt);
    if (objptr == 0) {
	obj = dlg_calloc(MY_OBJ, 1);
	assert_ptr(obj, "dialog_gauge");
	dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, MIN_WIDE);
	dlg_print_size(height, width);
	dlg_ctl_size(height, width);
    } else {
	obj = objptr;
	height = obj->height;
	width = obj->width;
    }
    if (obj->obj.win == 0) {
	int x = dlg_box_x_ordinate(width);
	int y = dlg_box_y_ordinate(height);
	WINDOW *dialog = dlg_new_window(height, width, y, x);
	obj->obj.win = dialog;
    }
    obj->obj.input = dialog_state.pipe_input;
    obj->obj.keep_win = TRUE;
    obj->obj.bg_task = TRUE;
    obj->obj.handle_getc = handle_my_getc;
    obj->obj.handle_input = handle_input;
    if (obj->title == 0 || strcmp(obj->title, title)) {
	dlg_finish_string(obj->title);
	free(obj->title);
	obj->title = dlg_strclone(title);
    }
    dlg_finish_string(obj->prompt);
    free(obj->prompt);
    obj->prompt = prompt;
    obj->percent = percent;
    obj->height = height;
    obj->width = width;
    if (objptr == 0) {
	obj->next = all_objects;
	all_objects = obj;
    }
    dialog_state.finish_string = save_finish_string;
    return (void *) obj;
}
void * dlg_reallocate_gauge ( void * objptr , const char * title , const char * cprompt , int height , int width , int percent ) { char * prompt = dlg_strclone ( cprompt ) ; MY_OBJ * obj = objptr ; bool save_finish_string = dialog_state . finish_string ; dialog_state . finish_string = TRUE ; dlg_tab_correct_str ( prompt ) ; if ( objptr == 0 ) { obj = dlg_calloc ( MY_OBJ , 1 ) ; assert_ptr ( obj , " " ) ; dlg_auto_size ( title , prompt , & height , & width , MIN_HIGH , MIN_WIDE ) ; dlg_print_size ( height , width ) ; dlg_ctl_size ( height , width ) ; } else { obj = objptr ; height = obj -> height ; width = obj -> width ; } if ( obj -> obj . win == 0 ) { int x = dlg_box_x_ordinate ( width ) ; int y = dlg_box_y_ordinate ( height ) ; WINDOW * dialog = dlg_new_window ( height , width , y , x ) ; obj -> obj . win = dialog ; } obj -> obj . input = dialog_state . pipe_input ; obj -> obj . keep_win = TRUE ; obj -> obj . bg_task = TRUE ; obj -> obj . handle_getc = handle_my_getc ; obj -> obj . handle_input = handle_input ; if ( obj -> title == 0 || strcmp ( obj -> title , title ) ) { dlg_finish_string ( obj -> title ) ; free ( obj -> title ) ; obj -> title = dlg_strclone ( title ) ; } dlg_finish_string ( obj -> prompt ) ; free ( obj -> prompt ) ; obj -> prompt = prompt ; obj -> percent = percent ; obj -> height = height ; obj -> width = width ; if ( objptr == 0 ) { obj -> next = all_objects ; all_objects = obj ; } dialog_state . finish_string = save_finish_string ; return ( void * ) obj ; }
(Re)Allocates an object and fills it as per the arguments
( Re ) Allocates an object and fills it as per the arguments
/* create a new object */ /* reuse an existing object */ /* center dialog box on screen */ /* if this was a new object, link it into the list */