FreeBSD/contrib/dialog/checklist.c
/*
 * 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.
 */
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.
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:		
    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;
}
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 , " " ) ; 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 ++ ] , " " ) ; 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 : 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 ; }
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.
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 .
/* FALLTHRU */