import ctypes


class Callback(ctypes.Structure):
    pass


class Color(ctypes.Structure):
    pass


class FormItem(ctypes.Structure):
    pass


class ListItem(ctypes.Structure):
    pass


class MouseRegion(ctypes.Structure):
    pass


class State(ctypes.Structure):
    pass


class Vars(ctypes.Structure):
    pass


class Window(ctypes.Structure):
    pass


class Windows(ctypes.Structure):
    pass


chtype = ctypes.c_ulong
attr_t = chtype
File_p = ctypes.c_void_p

freeback = ctypes.CFUNCTYPE(None, ctypes.POINTER(Callback))
input_handler = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.POINTER(Callback))
input_menu = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.POINTER(ListItem), ctypes.c_int, ctypes.c_char_p)
getc_handler = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.POINTER(Callback), ctypes.c_int, ctypes.c_int,
                                ctypes.POINTER(ctypes.c_int))

STRUCTURES = {
    Callback: (
        ('next', ctypes.POINTER(Callback)),
        ('input', File_p),
        ('win', ctypes.POINTER(Window)),
        ('keep_bg', ctypes.c_bool),
        ('bg_task', ctypes.c_bool),
        ('handle_getc', getc_handler),
        ('keep_win', ctypes.c_bool),
        ('caller', ctypes.POINTER(ctypes.POINTER(Callback))),
        ('freeback', freeback),
        ('handle_input', input_handler),
        ('input_ready', ctypes.c_bool),
    ),
    Windows: (
        ('next', ctypes.POINTER(Windows)),
        ('normal', ctypes.POINTER(Window)),
        ('shadow', ctypes.POINTER(Window))
    ),
    State: (
        ('getc_callbacks', ctypes.POINTER(Callback)),
        ('getc_redirect', ctypes.POINTER(Callback)),
        ('all_windows', ctypes.POINTER(Windows)),
        ('all_subwindows', ctypes.POINTER(Windows)),
        ('output', File_p),
        ('pipe_input', File_p),
        ('screen_output', File_p),
        ('screen_initialized', ctypes.c_bool),
        ('use_colors', ctypes.c_bool),
        ('use_scrollbar', ctypes.c_bool),
        ('use_shadow', ctypes.c_bool),
        ('visit_items', ctypes.c_bool),
        ('separate_str', ctypes.c_char_p),
        ('aspect_ratio', ctypes.c_int),
        ('output_count', ctypes.c_int),
        ('tab_len', ctypes.c_int),
        ('input', File_p),
        ('trace_output', File_p),
        ('no_mouse', ctypes.c_bool),
        ('visit_cols', ctypes.c_int),
        ('finish_string', ctypes.c_bool),
        ('plain_buttons', ctypes.c_bool),
    ),
    Vars: (
        ('beep_after_signal', ctypes.c_bool),
        ('beep_signal', ctypes.c_bool),
        ('begin_set', ctypes.c_bool),
        ('cant_kill', ctypes.c_bool),
        ('colors', ctypes.c_bool),
        ('cr_wrap', ctypes.c_bool),
        ('defaultno', ctypes.c_bool),
        ('dlg_clear_screen', ctypes.c_bool),
        ('extra_button', ctypes.c_bool),
        ('help_button', ctypes.c_bool),
        ('help_status', ctypes.c_bool),
        ('input_menu', ctypes.c_bool),
        ('insecure', ctypes.c_bool),
        ('item_help', ctypes.c_bool),
        ('keep_window', ctypes.c_bool),
        ('nocancel', ctypes.c_bool),
        ('nocollapse', ctypes.c_bool),
        ('print_siz', ctypes.c_bool),
        ('separate_output', ctypes.c_bool),
        ('single_quoted', ctypes.c_bool),
        ('size_err', ctypes.c_bool),
        ('tab_correct', ctypes.c_bool),
        ('trim_whitespace', ctypes.c_bool),
        ('backtitle', ctypes.c_char_p),
        ('cancel_label', ctypes.c_char_p),
        ('default_item', ctypes.c_char_p),
        ('exit_label', ctypes.c_char_p),
        ('extra_label', ctypes.c_char_p),
        ('help_label', ctypes.c_char_p),
        ('input_result', ctypes.c_char_p),
        ('no_label', ctypes.c_char_p),
        ('ok_label', ctypes.c_char_p),
        ('title', ctypes.c_char_p),
        ('yes_label', ctypes.c_char_p),
        ('begin_x', ctypes.c_int),
        ('begin_y', ctypes.c_int),
        ('max_input', ctypes.c_int),
        ('scale_factor', ctypes.c_int),
        ('sleep_secs', ctypes.c_int),
        ('timeout_secs', ctypes.c_int),
        ('input_length', ctypes.c_uint),
        ('formitem_type', ctypes.c_uint),
        ('keep_tite', ctypes.c_bool),
        ('ascii_lines', ctypes.c_bool),
        ('no_lines', ctypes.c_bool),
        ('nook', ctypes.c_bool),
        ('quoted', ctypes.c_bool),
        ('column_header', ctypes.c_char_p),
        ('column_separator', ctypes.c_char_p),
        ('output_separator', ctypes.c_char_p),
        ('date_format', ctypes.c_char_p),
        ('time_format', ctypes.c_char_p),
        ('help_line', ctypes.c_char_p),
        ('help_file', ctypes.c_char_p),
        ('in_helpfile', ctypes.c_bool),
        ('no_nl_expand', ctypes.c_bool),
        ('default_button', ctypes.c_int),
        ('no_tags', ctypes.c_bool),
        ('no_items', ctypes.c_bool),
        ('last_key', ctypes.c_bool),
        ('help_tags', ctypes.c_bool),
        ('week_start', ctypes.c_char_p),
        ('iso_week', ctypes.c_bool),
        ('reorder', ctypes.c_bool),
    ),
    Color: (
        ('atr', chtype),
        ('fg', ctypes.c_int),
        ('bg', ctypes.c_int),
        ('hilite', ctypes.c_int),
        ('name', ctypes.c_char_p),
        ('comment', ctypes.c_char_p),
    ),
    ListItem: (
        ('name', ctypes.c_char_p),
        ('text', ctypes.c_char_p),
        ('help', ctypes.c_char_p),
        ('state', ctypes.c_int),
    ),
    FormItem: (
        ('type', ctypes.c_uint),
        ('name', ctypes.c_char_p),
        ('name_len', ctypes.c_int),
        ('name_y', ctypes.c_int),
        ('name_x', ctypes.c_int),
        ('name_free', ctypes.c_bool),
        ('text', ctypes.c_char_p),
        ('text_len', ctypes.c_int),
        ('text_y', ctypes.c_int),
        ('text_x', ctypes.c_int),
        ('text_flen', ctypes.c_int),
        ('text_ilen', ctypes.c_int),
        ('text_free', ctypes.c_bool),
        ('help', ctypes.c_char_p),
        ('help_free', ctypes.c_bool),
    ),
    MouseRegion: (
        ('x', ctypes.c_int),
        ('y', ctypes.c_int),
        ('X', ctypes.c_int),
        ('Y', ctypes.c_int),
        ('mode', ctypes.c_int),
        ('step_x', ctypes.c_int),
        ('step_y', ctypes.c_int),
        ('next', ctypes.POINTER(MouseRegion)),
    ),
    Window: (
        ('_cury', ctypes.c_short),
        ('_curx', ctypes.c_short),
        ('_maxy', ctypes.c_short),
        ('_maxx', ctypes.c_short),
        ('_begy', ctypes.c_short),
        ('_begx', ctypes.c_short),
        ('_flags', ctypes.c_short),
        ('_attrs', attr_t),
        ('_bkgd', chtype),
        ('_notimeout', ctypes.c_bool),
        ('_clear', ctypes.c_bool),
        ('_leaveok', ctypes.c_bool),
        ('_scroll', ctypes.c_bool),
        ('_idlok', ctypes.c_bool),
        ('_idcok', ctypes.c_bool),
        ('_immed', ctypes.c_bool),
        ('_sync', ctypes.c_bool),
        ('_use_keypad', ctypes.c_bool),
        ('_delay', ctypes.c_int),
        ('_line', ctypes.c_void_p),
        ('_regtop', ctypes.c_short),
        ('_regbottom', ctypes.c_short),
        ('_parx', ctypes.c_int),
        ('_pary', ctypes.c_int),
        ('_parent', ctypes.POINTER(Window)),
        ('_pad_y', ctypes.c_short),
        ('_pad_x', ctypes.c_short),
        ('_pad_top', ctypes.c_short),
        ('_pad_left', ctypes.c_short),
        ('_pad_bottom', ctypes.c_short),
        ('_pad_right', ctypes.c_short),
        ('_yoffset', ctypes.c_short),
    )
}

FUNCTIONS = {
    'dialog_version': (ctypes.c_char_p,),
    'dialog_buildlist': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                         ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int),
    'dialog_calendar': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                        ctypes.c_int, ctypes.c_int),
    'dialog_checklist': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                         ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int),
    'dialog_dselect': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dialog_editbox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dialog_form': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                    ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)),
    'dialog_fselect': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dialog_gauge': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dialog_helpfile': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dialog_inputbox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_char_p,
                        ctypes.c_int),
    'dialog_menu': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                    ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)),
    'dialog_mixedform': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                         ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)),
    'dialog_mixedgauge': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                          ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)),
    'dialog_msgbox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dialog_pause': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dialog_prgbox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int,
                      ctypes.c_int),
    'dialog_progressbox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dialog_rangebox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                        ctypes.c_int, ctypes.c_int),
    'dialog_tailbox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dialog_textbox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dialog_timebox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                       ctypes.c_int, ctypes.c_int),
    'dialog_treeview': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                        ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int),
    'dialog_yesno': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dlg_checklist': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                      ctypes.c_int, ctypes.POINTER(ListItem), ctypes.c_char_p, ctypes.c_int,
                      ctypes.POINTER(ctypes.c_int)),
    'dlg_form': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                 ctypes.POINTER(FormItem), ctypes.POINTER(ctypes.c_int)),
    'dlg_menu': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                 ctypes.POINTER(ListItem), ctypes.POINTER(ctypes.c_int), input_menu),
    'dlg_progressbox': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                        File_p),
    'dlg_string_to_argv': (ctypes.POINTER(ctypes.c_char_p), ctypes.c_char_p),
    'dlg_count_argv': (ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)),
    'dlg_eat_argv': (ctypes.c_int, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.POINTER(ctypes.c_char_p)),
                     ctypes.c_int, ctypes.c_int),
    'dlg_draw_arrows': (None, ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                        ctypes.c_int),
    'dlg_draw_arrows2': (None, ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                         ctypes.c_int, chtype, chtype),
    'dlg_draw_helpline': (None, ctypes.POINTER(Window), ctypes.c_bool),
    'dlg_draw_scrollbar': (None, ctypes.POINTER(Window), ctypes.c_long, ctypes.c_long, ctypes.c_long, ctypes.c_long,
                           ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, chtype, chtype),
    'dlg_buildlist': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                      ctypes.c_int, ctypes.POINTER(ListItem), ctypes.c_char_p, ctypes.c_int,
                      ctypes.POINTER(ctypes.c_int)),
    'dlg_exit_label': (ctypes.POINTER(ctypes.c_char_p)),
    'dlg_ok_label': (ctypes.POINTER(ctypes.c_char_p)),
    'dlg_ok_labels': (ctypes.POINTER(ctypes.c_char_p)),
    'dlg_yes_labels': (ctypes.POINTER(ctypes.c_char_p)),
    'dlg_button_count': (ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)),
    'dlg_button_to_char': (ctypes.c_int, ctypes.c_char_p),
    'dlg_button_x_step': (ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int, ctypes.POINTER(ctypes.c_int),
                          ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)),
    'dlg_char_to_button': (ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)),
    'dlg_exit_buttoncode': (ctypes.c_int, ctypes.c_int),
    'dlg_match_char': (ctypes.c_int, ctypes.c_int, ctypes.c_char_p),
    'dlg_next_button': (ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int),
    'dlg_next_ok_buttonindex': (ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dlg_ok_buttoncode': (ctypes.c_int, ctypes.c_int),
    'dlg_prev_button': (ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int),
    'dlg_prev_ok_buttonindex': (ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dlg_yes_buttoncode': (ctypes.c_int, ctypes.c_int),
    'dlg_button_layout': (None, ctypes.POINTER(ctypes.c_char_p), ctypes.POINTER(ctypes.c_int)),
    'dlg_button_sizes': (None, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int, ctypes.POINTER(ctypes.c_int),
                         ctypes.POINTER(ctypes.c_int)),
    'dlg_draw_buttons': (None, ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_char_p),
                         ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dlg_align_columns': (None, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int, ctypes.c_int),
    'dlg_free_columns': (None, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int, ctypes.c_int),
    'dlg_editbox': (ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(ctypes.POINTER(ctypes.c_char_p)),
                    ctypes.POINTER(ctypes.c_int), ctypes.c_int, ctypes.c_int),
    'dlg_default_formitem': (ctypes.c_int, ctypes.POINTER(FormItem)),
    'dlg_ordinate': (ctypes.c_int, ctypes.c_char_p),
    'dlg_free_formitems': (None, ctypes.POINTER(FormItem)),
    'dlg_allocate_gauge': (ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dlg_reallocate_gauge': (ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int,
                             ctypes.c_int, ctypes.c_int),
    'dlg_free_gauge': (None, ctypes.c_void_p),
    'dlg_update_gauge': (None, ctypes.c_void_p, ctypes.c_int),
    'dlg_edit_string': (ctypes.c_bool, ctypes.c_char_p, ctypes.POINTER(ctypes.c_int), ctypes.c_int, ctypes.c_int,
                        ctypes.c_bool),
    'dlg_index_columns': (ctypes.POINTER(ctypes.c_int), ctypes.c_char_p),
    'dlg_index_wchars': (ctypes.POINTER(ctypes.c_int), ctypes.c_char_p),
    'dlg_count_columns': (ctypes.c_int, ctypes.c_char_p),
    'dlg_count_wchars': (ctypes.c_int, ctypes.c_char_p),
    'dlg_edit_offset': (ctypes.c_int, ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dlg_find_index': (ctypes.c_int, ctypes.POINTER(ctypes.c_int), ctypes.c_int, ctypes.c_int),
    'dlg_limit_columns': (ctypes.c_int, ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dlg_finish_string': (None, ctypes.c_char_p),
    'dlg_show_string': (None, ctypes.POINTER(Window), ctypes.c_char_p, ctypes.c_int, chtype, ctypes.c_int, ctypes.c_int,
                        ctypes.c_int, ctypes.c_bool, ctypes.c_bool),
    'dlg_renamed_menutext': (ctypes.c_int, ctypes.POINTER(ListItem), ctypes.c_int, ctypes.c_char_p),
    'dlg_popen': (File_p, ctypes.c_char_p, ctypes.c_char_p),
    'dlg_parse_rc': (ctypes.c_int,),
    'dlg_create_rc': (None, ctypes.c_char_p),
    'dlg_treeview': (ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                     ctypes.c_int, ctypes.POINTER(ListItem), ctypes.c_char_p, ctypes.POINTER(ctypes.c_int),
                     ctypes.c_int, ctypes.POINTER(ctypes.c_int)),
    'dlg_getc': (ctypes.c_int, ctypes.POINTER(Window), ctypes.POINTER(ctypes.c_int)),
    'dlg_getc_callbacks': (ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int)),
    'dlg_last_getc': (ctypes.c_int,),
    'dlg_add_last_key': (None, ctypes.c_int),
    'dlg_add_callback': (None, ctypes.POINTER(Callback)),
    'dlg_add_callback_ref': (None, ctypes.POINTER(ctypes.POINTER(Callback)), freeback),
    'dlg_flush_getc': (None,),
    'dlg_remove_callback': (None, ctypes.POINTER(Callback)),
    'dlg_killall_bg': (None, ctypes.POINTER(ctypes.c_int)),
    'dlg_new_modal_window': (ctypes.POINTER(Window), ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.c_int,
                             ctypes.c_int),
    'dlg_new_window': (ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dlg_sub_window': (ctypes.POINTER(Window), ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.c_int,
                       ctypes.c_int),
    'dlg_need_separator': (ctypes.c_bool,),
    'dlg_set_result': (ctypes.c_char_p, ctypes.c_char_p),
    'dlg_strclone': (ctypes.c_char_p, ctypes.c_char_p),
    'dlg_strempty': (ctypes.c_char_p,),
    'dlg_asciibox': (chtype, chtype),
    'dlg_boxchar': (chtype, chtype),
    'dlg_get_attrs': (chtype, ctypes.POINTER(Window)),
    'dlg_prctypes.c_int_line': (ctypes.c_char_p, ctypes.POINTER(Window), ctypes.POINTER(chtype), ctypes.c_char_p,
                                ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int)),
    'dlg_box_x_ordinate': (ctypes.c_int, ctypes.c_int),
    'dlg_box_y_ordinate': (ctypes.c_int, ctypes.c_int),
    'dlg_calc_list_width': (ctypes.c_int, ctypes.c_int, ctypes.POINTER(ListItem)),
    'dlg_calc_listw': (ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int),
    'dlg_check_scrolled': (ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_bool),
                           ctypes.POINTER(ctypes.c_int)),
    'dlg_count_real_columns': (ctypes.c_int, ctypes.c_char_p),
    'dlg_default_item': (ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.c_int),
    'dlg_default_listitem': (ctypes.c_int, ctypes.POINTER(ListItem)),
    'dlg_defaultno_button': (ctypes.c_int,),
    'dlg_default_button': (ctypes.c_int,),
    'dlg_max_input': (ctypes.c_int, ctypes.c_int),
    'dlg_prctypes.c_int_scrolled': (ctypes.c_int, ctypes.POINTER(Window), ctypes.c_char_p, ctypes.c_int, ctypes.c_int,
                                    ctypes.c_int, ctypes.c_int),
    'dlg_add_help_formitem': (None, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_char_p),
                              ctypes.POINTER(FormItem)),
    'dlg_add_help_listitem': (None, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_char_p),
                              ctypes.POINTER(ListItem)),
    'dlg_add_quoted': (None, ctypes.c_char_p),
    'dlg_add_result': (None, ctypes.c_char_p),
    'dlg_add_separator': (None,),
    'dlg_add_string': (None, ctypes.c_char_p),
    'dlg_attr_clear': (None, ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, chtype),
    'dlg_auto_size': (None, ctypes.c_char_p, ctypes.c_char_p, ctypes.POINTER(ctypes.c_int),
                      ctypes.POINTER(ctypes.c_int), ctypes.c_int, ctypes.c_int),
    'dlg_auto_sizefile': (None, ctypes.c_char_p, ctypes.c_char_p, ctypes.POINTER(ctypes.c_int),
                          ctypes.POINTER(ctypes.c_int), ctypes.c_int, ctypes.c_int),
    'dlg_beeping': (None,),
    'dlg_calc_listh': (None, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.c_int),
    'dlg_clear': (None,),
    'dlg_clr_result': (None,),
    'dlg_ctl_size': (None, ctypes.c_int, ctypes.c_int),
    'dlg_del_window': (None, ctypes.POINTER(Window)),
    'dlg_does_output': (None,),
    'dlg_draw_bottom_box': (None, ctypes.POINTER(Window)),
    'dlg_draw_bottom_box2': (None, ctypes.POINTER(Window), chtype, chtype, chtype),
    'dlg_draw_box': (None, ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, chtype,
                     chtype),
    'dlg_draw_box2': (None, ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, chtype,
                      chtype, chtype),
    'dlg_draw_title': (None, ctypes.POINTER(Window), ctypes.c_char_p),
    'dlg_exit': (None, ctypes.c_int),
    'dlg_item_help': (None, ctypes.c_char_p),
    'dlg_prctypes.c_int_autowrap': (None, ctypes.POINTER(Window), ctypes.c_char_p, ctypes.c_int, ctypes.c_int),
    'dlg_prctypes.c_int_listitem': (None, ctypes.POINTER(Window), ctypes.c_char_p, ctypes.c_int, ctypes.c_bool,
                                    ctypes.c_int),
    'dlg_prctypes.c_int_size': (None, ctypes.c_int, ctypes.c_int),
    'dlg_prctypes.c_int_text': (None, ctypes.POINTER(Window), ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(chtype)),
    'dlg_put_backtitle': (None,),
    'dlg_restore_vars': (None, ctypes.POINTER(Vars)),
    'dlg_save_vars': (None, ctypes.POINTER(Vars)),
    'dlg_set_focus': (None, ctypes.POINTER(Window), ctypes.POINTER(Window)),
    'dlg_tab_correct_str': (None, ctypes.c_char_p),
    'dlg_trim_string': (None, ctypes.c_char_p),
    'end_dialog': (None,),
    'init_dialog': (None, File_p, File_p),
    'dlg_exiterr': (None, ctypes.c_char_p, ...),
    'dlg_color_pair': (chtype, ctypes.c_int, ctypes.c_int),
    'dlg_color_count': (ctypes.c_int,),
    'dlg_color_setup': (None,),
    'dlg_draw_shadow': (None, ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dlg_trace_msg': (None, ctypes.c_char_p, ...),
    'dlg_trace_win': (None, ctypes.POINTER(Window)),
    'dlg_trace_chr': (None, ctypes.c_int, ctypes.c_int),
    'dlg_trace': (None, ctypes.c_char_p),
    'dlg_move_window': (None, ctypes.POINTER(Window), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int),
    'dlg_mouse_mkregion': (ctypes.POINTER(MouseRegion), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                           ctypes.c_int),
    'dlg_mouse_free_regions': (None,),
    'dlg_mouse_mkbigregion': (None, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
                              ctypes.c_int, ctypes.c_int),
    'dlg_mouse_setbase': (None, ctypes.c_int, ctypes.c_int),
    'dlg_mouse_setcode': (None, ctypes.c_int),
    'dlg_mouse_region': (ctypes.POINTER(MouseRegion), ctypes.c_int, ctypes.c_int),
    'dlg_mouse_bigregion': (ctypes.POINTER(MouseRegion), ctypes.c_int, ctypes.c_int),
    'dlg_mouse_wgetch': (ctypes.c_int, ctypes.POINTER(Window), ctypes.POINTER(ctypes.c_int)),
    'dlg_mouse_wgetch_nowait': (ctypes.c_int, ctypes.POINTER(Window), ctypes.POINTER(ctypes.c_int)),
}

LIBC_FUNCTIONS = {
    'fdopen': (File_p, ctypes.c_int, ctypes.c_char_p),
    'fclose': (None, File_p),
    'malloc': (ctypes.c_void_p, ctypes.c_size_t),
    'free': (None, ctypes.c_void_p),
}


def _init_structures(table):
    for typ, fields in table.items():
        typ._fields_ = fields


_init_structures(STRUCTURES)
del _init_structures
