code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231 values | license stringclasses 13 values | size int64 1 2.01M |
|---|---|---|---|---|---|
/* hardcopy.c */
char_u *parse_printoptions __ARGS((void));
char_u *parse_printmbfont __ARGS((void));
int prt_header_height __ARGS((void));
int prt_use_number __ARGS((void));
int prt_get_unit __ARGS((int idx));
void ex_hardcopy __ARGS((exarg_T *eap));
void mch_print_cleanup __ARGS((void));
int mch_print_init __ARGS((prt_settings_T *psettings, char_u *jobname, int forceit));
int mch_print_begin __ARGS((prt_settings_T *psettings));
void mch_print_end __ARGS((prt_settings_T *psettings));
int mch_print_end_page __ARGS((void));
int mch_print_begin_page __ARGS((char_u *str));
int mch_print_blank_page __ARGS((void));
void mch_print_start_line __ARGS((int margin, int page_line));
int mch_print_text_out __ARGS((char_u *p, int len));
void mch_print_set_font __ARGS((int iBold, int iItalic, int iUnderline));
void mch_print_set_bg __ARGS((long_u bgcol));
void mch_print_set_fg __ARGS((long_u fgcol));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/hardcopy.pro | C | gpl2 | 922 |
/* os_mswin.c */
void mch_exit __ARGS((int r));
void mch_early_init __ARGS((void));
int mch_input_isatty __ARGS((void));
void mch_settitle __ARGS((char_u *title, char_u *icon));
void mch_restore_title __ARGS((int which));
int mch_can_restore_title __ARGS((void));
int mch_can_restore_icon __ARGS((void));
int mch_FullName __ARGS((char_u *fname, char_u *buf, int len, int force));
int mch_isFullName __ARGS((char_u *fname));
void slash_adjust __ARGS((char_u *p));
int vim_stat __ARGS((const char *name, struct stat *stp));
void mch_settmode __ARGS((int tmode));
int mch_get_shellsize __ARGS((void));
void mch_set_shellsize __ARGS((void));
void mch_new_shellsize __ARGS((void));
void mch_suspend __ARGS((void));
void display_errors __ARGS((void));
int mch_has_exp_wildcard __ARGS((char_u *p));
int mch_has_wildcard __ARGS((char_u *p));
int mch_chdir __ARGS((char *path));
int can_end_termcap_mode __ARGS((int give_msg));
int mch_screenmode __ARGS((char_u *arg));
int mch_libcall __ARGS((char_u *libname, char_u *funcname, char_u *argstring, int argint, char_u **string_result, int *number_result));
int utf8_to_utf16 __ARGS((char_u *instr, int inlen, short_u *outstr, int *unconvlenp));
int utf16_to_utf8 __ARGS((short_u *instr, int inlen, char_u *outstr));
void MultiByteToWideChar_alloc __ARGS((UINT cp, DWORD flags, LPCSTR in, int inlen, LPWSTR *out, int *outlen));
void WideCharToMultiByte_alloc __ARGS((UINT cp, DWORD flags, LPCWSTR in, int inlen, LPSTR *out, int *outlen, LPCSTR def, LPBOOL useddef));
int clip_mch_own_selection __ARGS((VimClipboard *cbd));
void clip_mch_lose_selection __ARGS((VimClipboard *cbd));
short_u *enc_to_utf16 __ARGS((char_u *str, int *lenp));
char_u *utf16_to_enc __ARGS((short_u *str, int *lenp));
void clip_mch_request_selection __ARGS((VimClipboard *cbd));
void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
void clip_mch_set_selection __ARGS((VimClipboard *cbd));
void DumpPutS __ARGS((const char *psz));
int mch_get_winpos __ARGS((int *x, int *y));
void mch_set_winpos __ARGS((int x, int y));
void mch_print_cleanup __ARGS((void));
int mch_print_init __ARGS((prt_settings_T *psettings, char_u *jobname, int forceit));
int mch_print_begin __ARGS((prt_settings_T *psettings));
void mch_print_end __ARGS((prt_settings_T *psettings));
int mch_print_end_page __ARGS((void));
int mch_print_begin_page __ARGS((char_u *msg));
int mch_print_blank_page __ARGS((void));
void mch_print_start_line __ARGS((int margin, int page_line));
int mch_print_text_out __ARGS((char_u *p, int len));
void mch_print_set_font __ARGS((int iBold, int iItalic, int iUnderline));
void mch_print_set_bg __ARGS((long_u bgcol));
void mch_print_set_fg __ARGS((long_u fgcol));
char_u *mch_resolve_shortcut __ARGS((char_u *fname));
void win32_set_foreground __ARGS((void));
void serverInitMessaging __ARGS((void));
void serverSetName __ARGS((char_u *name));
char_u *serverGetVimNames __ARGS((void));
int serverSendReply __ARGS((char_u *name, char_u *reply));
int serverSendToVim __ARGS((char_u *name, char_u *cmd, char_u **result, void *ptarget, int asExpr, int silent));
void serverForeground __ARGS((char_u *name));
char_u *serverGetReply __ARGS((HWND server, int *expr_res, int remove, int wait));
void serverProcessPendingMessages __ARGS((void));
char *charset_id2name __ARGS((int id));
int get_logfont __ARGS((LOGFONT *lf, char_u *name, HDC printer_dc, int verbose));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/os_mswin.pro | C | gpl2 | 3,425 |
/* move.c */
void update_topline_redraw __ARGS((void));
void update_topline __ARGS((void));
void update_curswant __ARGS((void));
void check_cursor_moved __ARGS((win_T *wp));
void changed_window_setting __ARGS((void));
void changed_window_setting_win __ARGS((win_T *wp));
void set_topline __ARGS((win_T *wp, linenr_T lnum));
void changed_cline_bef_curs __ARGS((void));
void changed_cline_bef_curs_win __ARGS((win_T *wp));
void changed_line_abv_curs __ARGS((void));
void changed_line_abv_curs_win __ARGS((win_T *wp));
void validate_botline __ARGS((void));
void invalidate_botline __ARGS((void));
void invalidate_botline_win __ARGS((win_T *wp));
void approximate_botline_win __ARGS((win_T *wp));
int cursor_valid __ARGS((void));
void validate_cursor __ARGS((void));
void validate_cline_row __ARGS((void));
void validate_virtcol __ARGS((void));
void validate_virtcol_win __ARGS((win_T *wp));
void validate_cursor_col __ARGS((void));
int win_col_off __ARGS((win_T *wp));
int curwin_col_off __ARGS((void));
int win_col_off2 __ARGS((win_T *wp));
int curwin_col_off2 __ARGS((void));
void curs_columns __ARGS((int scroll));
void scrolldown __ARGS((long line_count, int byfold));
void scrollup __ARGS((long line_count, int byfold));
void check_topfill __ARGS((win_T *wp, int down));
void scrolldown_clamp __ARGS((void));
void scrollup_clamp __ARGS((void));
void scroll_cursor_top __ARGS((int min_scroll, int always));
void set_empty_rows __ARGS((win_T *wp, int used));
void scroll_cursor_bot __ARGS((int min_scroll, int set_topbot));
void scroll_cursor_halfway __ARGS((int atend));
void cursor_correct __ARGS((void));
int onepage __ARGS((int dir, long count));
void halfpage __ARGS((int flag, linenr_T Prenum));
void do_check_cursorbind __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/move.pro | C | gpl2 | 1,765 |
/* os_unix.c */
int mch_chdir __ARGS((char *path));
void mch_write __ARGS((char_u *s, int len));
int mch_inchar __ARGS((char_u *buf, int maxlen, long wtime, int tb_change_cnt));
int mch_char_avail __ARGS((void));
long_u mch_total_mem __ARGS((int special));
void mch_delay __ARGS((long msec, int ignoreinput));
int mch_stackcheck __ARGS((char *p));
void mch_startjmp __ARGS((void));
void mch_endjmp __ARGS((void));
void mch_didjmp __ARGS((void));
void mch_suspend __ARGS((void));
void mch_init __ARGS((void));
void reset_signals __ARGS((void));
int vim_handle_signal __ARGS((int sig));
int mch_check_win __ARGS((int argc, char **argv));
int mch_input_isatty __ARGS((void));
int mch_can_restore_title __ARGS((void));
int mch_can_restore_icon __ARGS((void));
void mch_settitle __ARGS((char_u *title, char_u *icon));
void mch_restore_title __ARGS((int which));
int vim_is_xterm __ARGS((char_u *name));
int use_xterm_like_mouse __ARGS((char_u *name));
int use_xterm_mouse __ARGS((void));
int vim_is_iris __ARGS((char_u *name));
int vim_is_vt300 __ARGS((char_u *name));
int vim_is_fastterm __ARGS((char_u *name));
int mch_get_user_name __ARGS((char_u *s, int len));
int mch_get_uname __ARGS((uid_t uid, char_u *s, int len));
void mch_get_host_name __ARGS((char_u *s, int len));
long mch_get_pid __ARGS((void));
int mch_dirname __ARGS((char_u *buf, int len));
void slash_adjust __ARGS((char_u *p));
int mch_FullName __ARGS((char_u *fname, char_u *buf, int len, int force));
int mch_isFullName __ARGS((char_u *fname));
void fname_case __ARGS((char_u *name, int len));
long mch_getperm __ARGS((char_u *name));
int mch_setperm __ARGS((char_u *name, long perm));
void mch_copy_sec __ARGS((char_u *from_file, char_u *to_file));
vim_acl_T mch_get_acl __ARGS((char_u *fname));
void mch_set_acl __ARGS((char_u *fname, vim_acl_T aclent));
void mch_free_acl __ARGS((vim_acl_T aclent));
void mch_hide __ARGS((char_u *name));
int mch_isdir __ARGS((char_u *name));
int mch_can_exe __ARGS((char_u *name));
int mch_nodetype __ARGS((char_u *name));
void mch_early_init __ARGS((void));
void mch_free_mem __ARGS((void));
void mch_exit __ARGS((int r));
void mch_settmode __ARGS((int tmode));
void get_stty __ARGS((void));
void mch_setmouse __ARGS((int on));
void check_mouse_termcode __ARGS((void));
int mch_screenmode __ARGS((char_u *arg));
int mch_get_shellsize __ARGS((void));
void mch_set_shellsize __ARGS((void));
void mch_new_shellsize __ARGS((void));
int mch_call_shell __ARGS((char_u *cmd, int options));
void mch_breakcheck __ARGS((void));
int mch_expandpath __ARGS((garray_T *gap, char_u *path, int flags));
int mch_expand_wildcards __ARGS((int num_pat, char_u **pat, int *num_file, char_u ***file, int flags));
int mch_has_exp_wildcard __ARGS((char_u *p));
int mch_has_wildcard __ARGS((char_u *p));
int mch_libcall __ARGS((char_u *libname, char_u *funcname, char_u *argstring, int argint, char_u **string_result, int *number_result));
void setup_term_clip __ARGS((void));
void start_xterm_trace __ARGS((int button));
void stop_xterm_trace __ARGS((void));
void clear_xterm_clip __ARGS((void));
int clip_xterm_own_selection __ARGS((VimClipboard *cbd));
void clip_xterm_lose_selection __ARGS((VimClipboard *cbd));
void clip_xterm_request_selection __ARGS((VimClipboard *cbd));
void clip_xterm_set_selection __ARGS((VimClipboard *cbd));
int xsmp_handle_requests __ARGS((void));
void xsmp_init __ARGS((void));
void xsmp_close __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/os_unix.pro | C | gpl2 | 3,444 |
/* ops.c */
int get_op_type __ARGS((int char1, int char2));
int op_on_lines __ARGS((int op));
int get_op_char __ARGS((int optype));
int get_extra_op_char __ARGS((int optype));
void op_shift __ARGS((oparg_T *oap, int curs_top, int amount));
void shift_line __ARGS((int left, int round, int amount, int call_changed_bytes));
void op_reindent __ARGS((oparg_T *oap, int (*how)(void)));
int get_expr_register __ARGS((void));
void set_expr_line __ARGS((char_u *new_line));
char_u *get_expr_line __ARGS((void));
char_u *get_expr_line_src __ARGS((void));
int valid_yank_reg __ARGS((int regname, int writing));
void get_yank_register __ARGS((int regname, int writing));
int may_get_selection __ARGS((int regname));
void *get_register __ARGS((int name, int copy));
void put_register __ARGS((int name, void *reg));
int yank_register_mline __ARGS((int regname));
int do_record __ARGS((int c));
int do_execreg __ARGS((int regname, int colon, int addcr, int silent));
int insert_reg __ARGS((int regname, int literally));
int get_spec_reg __ARGS((int regname, char_u **argp, int *allocated, int errmsg));
int cmdline_paste_reg __ARGS((int regname, int literally, int remcr));
void adjust_clip_reg __ARGS((int *rp));
int op_delete __ARGS((oparg_T *oap));
int op_replace __ARGS((oparg_T *oap, int c));
void op_tilde __ARGS((oparg_T *oap));
int swapchar __ARGS((int op_type, pos_T *pos));
void op_insert __ARGS((oparg_T *oap, long count1));
int op_change __ARGS((oparg_T *oap));
void init_yank __ARGS((void));
void clear_registers __ARGS((void));
int op_yank __ARGS((oparg_T *oap, int deleting, int mess));
void do_put __ARGS((int regname, int dir, long count, int flags));
void adjust_cursor_eol __ARGS((void));
int preprocs_left __ARGS((void));
int get_register_name __ARGS((int num));
void ex_display __ARGS((exarg_T *eap));
int do_join __ARGS((long count, int insert_space, int save_undo, int use_formatoptions));
void op_format __ARGS((oparg_T *oap, int keep_cursor));
void op_formatexpr __ARGS((oparg_T *oap));
int fex_format __ARGS((linenr_T lnum, long count, int c));
void format_lines __ARGS((linenr_T line_count, int avoid_fex));
int paragraph_start __ARGS((linenr_T lnum));
int do_addsub __ARGS((int command, linenr_T Prenum1));
int read_viminfo_register __ARGS((vir_T *virp, int force));
void write_viminfo_registers __ARGS((FILE *fp));
void x11_export_final_selection __ARGS((void));
void clip_free_selection __ARGS((VimClipboard *cbd));
void clip_get_selection __ARGS((VimClipboard *cbd));
void clip_yank_selection __ARGS((int type, char_u *str, long len, VimClipboard *cbd));
int clip_convert_selection __ARGS((char_u **str, long_u *len, VimClipboard *cbd));
void dnd_yank_drag_data __ARGS((char_u *str, long len));
char_u get_reg_type __ARGS((int regname, long *reglen));
char_u *get_reg_contents __ARGS((int regname, int allowexpr, int expr_src));
void write_reg_contents __ARGS((int name, char_u *str, int maxlen, int must_append));
void write_reg_contents_ex __ARGS((int name, char_u *str, int maxlen, int must_append, int yank_type, long block_len));
void clear_oparg __ARGS((oparg_T *oap));
void cursor_pos_info __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/ops.pro | C | gpl2 | 3,153 |
/* if_cscope.c */
char_u *get_cscope_name __ARGS((expand_T *xp, int idx));
void set_context_in_cscope_cmd __ARGS((expand_T *xp, char_u *arg, cmdidx_T cmdidx));
void do_cscope __ARGS((exarg_T *eap));
void do_scscope __ARGS((exarg_T *eap));
void do_cstag __ARGS((exarg_T *eap));
int cs_fgets __ARGS((char_u *buf, int size));
void cs_free_tags __ARGS((void));
void cs_print_tags __ARGS((void));
int cs_connection __ARGS((int num, char_u *dbpath, char_u *ppath));
void cs_end __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/if_cscope.pro | C | gpl2 | 510 |
/* auto/if_perl.c */
int perl_enabled __ARGS((int verbose));
void perl_end __ARGS((void));
void msg_split __ARGS((char_u *s, int attr));
void perl_win_free __ARGS((win_T *wp));
void perl_buf_free __ARGS((buf_T *bp));
void ex_perl __ARGS((exarg_T *eap));
void ex_perldo __ARGS((exarg_T *eap));
| zyz2011-vim | src/proto/if_perl.pro | IDL | gpl2 | 293 |
/* if_ruby.c */
int ruby_enabled __ARGS((int verbose));
void ruby_end __ARGS((void));
void ex_ruby __ARGS((exarg_T *eap));
void ex_rubydo __ARGS((exarg_T *eap));
void ex_rubyfile __ARGS((exarg_T *eap));
void ruby_buffer_free __ARGS((buf_T *buf));
void ruby_window_free __ARGS((win_T *win));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/if_ruby.pro | C | gpl2 | 313 |
/* gui_motif.c */
void gui_x11_create_widgets __ARGS((void));
void gui_x11_destroy_widgets __ARGS((void));
void gui_mch_set_text_area_pos __ARGS((int x, int y, int w, int h));
void gui_x11_set_back_color __ARGS((void));
void manage_centered __ARGS((Widget dialog_child));
XmFontList gui_motif_create_fontlist __ARGS((XFontStruct *font));
XmFontList gui_motif_fontset2fontlist __ARGS((XFontSet *fontset));
void gui_mch_enable_menu __ARGS((int flag));
void gui_motif_set_mnemonics __ARGS((int enable));
void gui_mch_add_menu __ARGS((vimmenu_T *menu, int idx));
void gui_mch_toggle_tearoffs __ARGS((int enable));
int gui_mch_text_area_extra_height __ARGS((void));
void gui_mch_compute_menu_height __ARGS((Widget id));
void gui_mch_add_menu_item __ARGS((vimmenu_T *menu, int idx));
void gui_motif_update_mousemodel __ARGS((vimmenu_T *menu));
void gui_mch_new_menu_colors __ARGS((void));
void gui_mch_new_menu_font __ARGS((void));
void gui_mch_new_tooltip_font __ARGS((void));
void gui_mch_new_tooltip_colors __ARGS((void));
void gui_mch_destroy_menu __ARGS((vimmenu_T *menu));
void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu));
void gui_mch_def_colors __ARGS((void));
void gui_mch_set_scrollbar_thumb __ARGS((scrollbar_T *sb, long val, long size, long max));
void gui_mch_set_scrollbar_pos __ARGS((scrollbar_T *sb, int x, int y, int w, int h));
void gui_mch_enable_scrollbar __ARGS((scrollbar_T *sb, int flag));
void gui_mch_create_scrollbar __ARGS((scrollbar_T *sb, int orient));
void gui_mch_destroy_scrollbar __ARGS((scrollbar_T *sb));
void gui_mch_set_scrollbar_colors __ARGS((scrollbar_T *sb));
Window gui_x11_get_wid __ARGS((void));
char_u *gui_mch_browse __ARGS((int saving, char_u *title, char_u *dflt, char_u *ext, char_u *initdir, char_u *filter));
int gui_mch_dialog __ARGS((int type, char_u *title, char_u *message, char_u *button_names, int dfltbutton, char_u *textfield, int ex_cmd));
void gui_mch_enable_footer __ARGS((int showit));
void gui_mch_set_footer __ARGS((char_u *s));
void gui_mch_show_toolbar __ARGS((int showit));
int gui_mch_compute_toolbar_height __ARGS((void));
void motif_get_toolbar_colors __ARGS((Pixel *bgp, Pixel *fgp, Pixel *bsp, Pixel *tsp, Pixel *hsp));
void gui_mch_show_tabline __ARGS((int showit));
int gui_mch_showing_tabline __ARGS((void));
void gui_mch_update_tabline __ARGS((void));
void gui_mch_set_curtab __ARGS((int nr));
void gui_motif_menu_fontlist __ARGS((Widget id));
void gui_mch_find_dialog __ARGS((exarg_T *eap));
void gui_mch_replace_dialog __ARGS((exarg_T *eap));
void gui_motif_synch_fonts __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_motif.pro | C | gpl2 | 2,586 |
/* memline.c */
int ml_open __ARGS((buf_T *buf));
void ml_set_crypt_key __ARGS((buf_T *buf, char_u *old_key, int old_cm));
void ml_setname __ARGS((buf_T *buf));
void ml_open_files __ARGS((void));
void ml_open_file __ARGS((buf_T *buf));
void check_need_swap __ARGS((int newfile));
void ml_close __ARGS((buf_T *buf, int del_file));
void ml_close_all __ARGS((int del_file));
void ml_close_notmod __ARGS((void));
void ml_timestamp __ARGS((buf_T *buf));
void ml_recover __ARGS((void));
int recover_names __ARGS((char_u *fname, int list, int nr, char_u **fname_out));
void ml_sync_all __ARGS((int check_file, int check_char));
void ml_preserve __ARGS((buf_T *buf, int message));
char_u *ml_get __ARGS((linenr_T lnum));
char_u *ml_get_pos __ARGS((pos_T *pos));
char_u *ml_get_curline __ARGS((void));
char_u *ml_get_cursor __ARGS((void));
char_u *ml_get_buf __ARGS((buf_T *buf, linenr_T lnum, int will_change));
int ml_line_alloced __ARGS((void));
int ml_append __ARGS((linenr_T lnum, char_u *line, colnr_T len, int newfile));
int ml_append_buf __ARGS((buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, int newfile));
int ml_replace __ARGS((linenr_T lnum, char_u *line, int copy));
int ml_delete __ARGS((linenr_T lnum, int message));
void ml_setmarked __ARGS((linenr_T lnum));
linenr_T ml_firstmarked __ARGS((void));
void ml_clearmarked __ARGS((void));
int resolve_symlink __ARGS((char_u *fname, char_u *buf));
char_u *makeswapname __ARGS((char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name));
char_u *get_file_in_dir __ARGS((char_u *fname, char_u *dname));
void ml_setflags __ARGS((buf_T *buf));
char_u *ml_encrypt_data __ARGS((memfile_T *mfp, char_u *data, off_t offset, unsigned size));
void ml_decrypt_data __ARGS((memfile_T *mfp, char_u *data, off_t offset, unsigned size));
long ml_find_line_or_offset __ARGS((buf_T *buf, linenr_T lnum, long *offp));
void goto_byte __ARGS((long cnt));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/memline.pro | C | gpl2 | 1,919 |
/* mbyte.c */
int enc_canon_props __ARGS((char_u *name));
char_u *mb_init __ARGS((void));
int bomb_size __ARGS((void));
void remove_bom __ARGS((char_u *s));
int mb_get_class __ARGS((char_u *p));
int dbcs_class __ARGS((unsigned lead, unsigned trail));
int latin_char2len __ARGS((int c));
int latin_char2bytes __ARGS((int c, char_u *buf));
int latin_ptr2len __ARGS((char_u *p));
int latin_ptr2len_len __ARGS((char_u *p, int size));
int utf_char2cells __ARGS((int c));
int latin_ptr2cells __ARGS((char_u *p));
int utf_ptr2cells __ARGS((char_u *p));
int dbcs_ptr2cells __ARGS((char_u *p));
int latin_ptr2cells_len __ARGS((char_u *p, int size));
int latin_char2cells __ARGS((int c));
int mb_string2cells __ARGS((char_u *p, int len));
int latin_off2cells __ARGS((unsigned off, unsigned max_off));
int dbcs_off2cells __ARGS((unsigned off, unsigned max_off));
int utf_off2cells __ARGS((unsigned off, unsigned max_off));
int latin_ptr2char __ARGS((char_u *p));
int utf_ptr2char __ARGS((char_u *p));
int mb_ptr2char_adv __ARGS((char_u **pp));
int mb_cptr2char_adv __ARGS((char_u **pp));
int arabic_combine __ARGS((int one, int two));
int arabic_maycombine __ARGS((int two));
int utf_composinglike __ARGS((char_u *p1, char_u *p2));
int utfc_ptr2char __ARGS((char_u *p, int *pcc));
int utfc_ptr2char_len __ARGS((char_u *p, int *pcc, int maxlen));
int utfc_char2bytes __ARGS((int off, char_u *buf));
int utf_ptr2len __ARGS((char_u *p));
int utf_byte2len __ARGS((int b));
int utf_ptr2len_len __ARGS((char_u *p, int size));
int utfc_ptr2len __ARGS((char_u *p));
int utfc_ptr2len_len __ARGS((char_u *p, int size));
int utf_char2len __ARGS((int c));
int utf_char2bytes __ARGS((int c, char_u *buf));
int utf_iscomposing __ARGS((int c));
int utf_printable __ARGS((int c));
int utf_class __ARGS((int c));
int utf_fold __ARGS((int a));
int utf_toupper __ARGS((int a));
int utf_islower __ARGS((int a));
int utf_tolower __ARGS((int a));
int utf_isupper __ARGS((int a));
int mb_strnicmp __ARGS((char_u *s1, char_u *s2, size_t nn));
void show_utf8 __ARGS((void));
int latin_head_off __ARGS((char_u *base, char_u *p));
int dbcs_head_off __ARGS((char_u *base, char_u *p));
int dbcs_screen_head_off __ARGS((char_u *base, char_u *p));
int utf_head_off __ARGS((char_u *base, char_u *p));
void mb_copy_char __ARGS((char_u **fp, char_u **tp));
int mb_off_next __ARGS((char_u *base, char_u *p));
int mb_tail_off __ARGS((char_u *base, char_u *p));
void utf_find_illegal __ARGS((void));
int utf_valid_string __ARGS((char_u *s, char_u *end));
int dbcs_screen_tail_off __ARGS((char_u *base, char_u *p));
void mb_adjust_cursor __ARGS((void));
void mb_adjustpos __ARGS((buf_T *buf, pos_T *lp));
char_u *mb_prevptr __ARGS((char_u *line, char_u *p));
int mb_charlen __ARGS((char_u *str));
int mb_charlen_len __ARGS((char_u *str, int len));
char_u *mb_unescape __ARGS((char_u **pp));
int mb_lefthalve __ARGS((int row, int col));
int mb_fix_col __ARGS((int col, int row));
char_u *enc_skip __ARGS((char_u *p));
char_u *enc_canonize __ARGS((char_u *enc));
char_u *enc_locale __ARGS((void));
int encname2codepage __ARGS((char_u *name));
void *my_iconv_open __ARGS((char_u *to, char_u *from));
int iconv_enabled __ARGS((int verbose));
void iconv_end __ARGS((void));
void im_set_active __ARGS((int active));
void xim_set_focus __ARGS((int focus));
void im_set_position __ARGS((int row, int col));
void xim_set_preedit __ARGS((void));
int im_get_feedback_attr __ARGS((int col));
void xim_init __ARGS((void));
void im_shutdown __ARGS((void));
int im_xim_isvalid_imactivate __ARGS((void));
void xim_reset __ARGS((void));
int xim_queue_key_press_event __ARGS((GdkEventKey *event, int down));
int im_get_status __ARGS((void));
int preedit_get_status __ARGS((void));
int im_is_preediting __ARGS((void));
void xim_set_status_area __ARGS((void));
int xim_get_status_area_height __ARGS((void));
int convert_setup __ARGS((vimconv_T *vcp, char_u *from, char_u *to));
int convert_setup_ext __ARGS((vimconv_T *vcp, char_u *from, int from_unicode_is_utf8, char_u *to, int to_unicode_is_utf8));
int convert_input __ARGS((char_u *ptr, int len, int maxlen));
int convert_input_safe __ARGS((char_u *ptr, int len, int maxlen, char_u **restp, int *restlenp));
char_u *string_convert __ARGS((vimconv_T *vcp, char_u *ptr, int *lenp));
char_u *string_convert_ext __ARGS((vimconv_T *vcp, char_u *ptr, int *lenp, int *unconvlenp));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/mbyte.pro | C | gpl2 | 4,382 |
/* os_win32.c */
HINSTANCE vimLoadLib __ARGS((char *name));
int dyn_libintl_init __ARGS((char *libname));
void dyn_libintl_end __ARGS((void));
void PlatformId __ARGS((void));
int mch_windows95 __ARGS((void));
void mch_setmouse __ARGS((int on));
void mch_update_cursor __ARGS((void));
int mch_char_avail __ARGS((void));
int mch_inchar __ARGS((char_u *buf, int maxlen, long time, int tb_change_cnt));
void mch_init __ARGS((void));
void mch_exit __ARGS((int r));
int mch_check_win __ARGS((int argc, char **argv));
void fname_case __ARGS((char_u *name, int len));
int mch_get_user_name __ARGS((char_u *s, int len));
void mch_get_host_name __ARGS((char_u *s, int len));
long mch_get_pid __ARGS((void));
int mch_dirname __ARGS((char_u *buf, int len));
long mch_getperm __ARGS((char_u *name));
int mch_setperm __ARGS((char_u *name, long perm));
void mch_hide __ARGS((char_u *name));
int mch_isdir __ARGS((char_u *name));
int mch_mkdir __ARGS((char_u *name));
int mch_is_linked __ARGS((char_u *fname));
int win32_fileinfo __ARGS((char_u *name, BY_HANDLE_FILE_INFORMATION *lpFileInfo));
int mch_writable __ARGS((char_u *name));
int mch_can_exe __ARGS((char_u *name));
int mch_nodetype __ARGS((char_u *name));
vim_acl_T mch_get_acl __ARGS((char_u *fname));
void mch_set_acl __ARGS((char_u *fname, vim_acl_T acl));
void mch_free_acl __ARGS((vim_acl_T acl));
void mch_settmode __ARGS((int tmode));
int mch_get_shellsize __ARGS((void));
void mch_set_shellsize __ARGS((void));
void mch_new_shellsize __ARGS((void));
void mch_set_winsize_now __ARGS((void));
int mch_call_shell __ARGS((char_u *cmd, int options));
void mch_set_normal_colors __ARGS((void));
void mch_write __ARGS((char_u *s, int len));
void mch_delay __ARGS((long msec, int ignoreinput));
int mch_remove __ARGS((char_u *name));
void mch_breakcheck __ARGS((void));
long_u mch_avail_mem __ARGS((int special));
int mch_wrename __ARGS((WCHAR *wold, WCHAR *wnew));
int mch_rename __ARGS((const char *pszOldFile, const char *pszNewFile));
char *default_shell __ARGS((void));
int mch_access __ARGS((char *n, int p));
int mch_open __ARGS((char *name, int flags, int mode));
FILE *mch_fopen __ARGS((char *name, char *mode));
int mch_copy_file_attribute __ARGS((char_u *from, char_u *to));
int myresetstkoflw __ARGS((void));
int get_cmd_argsW __ARGS((char ***argvp));
void free_cmd_argsW __ARGS((void));
void used_file_arg __ARGS((char *name, int literal, int full_path, int diff_mode));
void set_alist_count __ARGS((void));
void fix_arg_enc __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/os_win32.pro | C | gpl2 | 2,520 |
/* ex_eval.c */
int aborting __ARGS((void));
void update_force_abort __ARGS((void));
int should_abort __ARGS((int retcode));
int aborted_in_try __ARGS((void));
int cause_errthrow __ARGS((char_u *mesg, int severe, int *ignore));
void do_errthrow __ARGS((struct condstack *cstack, char_u *cmdname));
int do_intthrow __ARGS((struct condstack *cstack));
void discard_current_exception __ARGS((void));
void report_make_pending __ARGS((int pending, void *value));
void report_resume_pending __ARGS((int pending, void *value));
void report_discard_pending __ARGS((int pending, void *value));
void ex_if __ARGS((exarg_T *eap));
void ex_endif __ARGS((exarg_T *eap));
void ex_else __ARGS((exarg_T *eap));
void ex_while __ARGS((exarg_T *eap));
void ex_continue __ARGS((exarg_T *eap));
void ex_break __ARGS((exarg_T *eap));
void ex_endwhile __ARGS((exarg_T *eap));
void ex_throw __ARGS((exarg_T *eap));
void do_throw __ARGS((struct condstack *cstack));
void ex_try __ARGS((exarg_T *eap));
void ex_catch __ARGS((exarg_T *eap));
void ex_finally __ARGS((exarg_T *eap));
void ex_endtry __ARGS((exarg_T *eap));
void enter_cleanup __ARGS((cleanup_T *csp));
void leave_cleanup __ARGS((cleanup_T *csp));
int cleanup_conditionals __ARGS((struct condstack *cstack, int searched_cond, int inclusive));
void rewind_conditionals __ARGS((struct condstack *cstack, int idx, int cond_type, int *cond_level));
void ex_endfunction __ARGS((exarg_T *eap));
int has_loop_cmd __ARGS((char_u *p));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/ex_eval.pro | C | gpl2 | 1,485 |
/* hangulin.c */
int hangul_input_state_get __ARGS((void));
void hangul_input_state_set __ARGS((int state));
int im_get_status __ARGS((void));
void hangul_input_state_toggle __ARGS((void));
void hangul_keyboard_set __ARGS((void));
int hangul_input_process __ARGS((char_u *s, int len));
void hangul_input_clear __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/hangulin.pro | C | gpl2 | 348 |
/* if_xcmdsrv.c */
int serverRegisterName __ARGS((Display *dpy, char_u *name));
void serverChangeRegisteredWindow __ARGS((Display *dpy, Window newwin));
int serverSendToVim __ARGS((Display *dpy, char_u *name, char_u *cmd, char_u **result, Window *server, int asExpr, int localLoop, int silent));
char_u *serverGetVimNames __ARGS((Display *dpy));
Window serverStrToWin __ARGS((char_u *str));
int serverSendReply __ARGS((char_u *name, char_u *str));
int serverReadReply __ARGS((Display *dpy, Window win, char_u **str, int localLoop));
int serverPeekReply __ARGS((Display *dpy, Window win, char_u **str));
void serverEventProc __ARGS((Display *dpy, XEvent *eventPtr));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/if_xcmdsrv.pro | C | gpl2 | 688 |
/* if_lua.c */
int lua_enabled __ARGS((int verbose));
void lua_end __ARGS((void));
void ex_lua __ARGS((exarg_T *eap));
void ex_luado __ARGS((exarg_T *eap));
void ex_luafile __ARGS((exarg_T *eap));
void lua_buffer_free __ARGS((buf_T *buf));
void lua_window_free __ARGS((win_T *win));
void do_luaeval __ARGS((char_u *str, typval_T *arg, typval_T *rettv));
void set_ref_in_lua __ARGS((int copyID));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/if_lua.pro | C | gpl2 | 418 |
/* if_ole.cpp */
void InitOLE __ARGS((int* pbDoRestart));
void UninitOLE __ARGS((void));
void RegisterMe __ARGS((int silent));
void UnregisterMe __ARGS((int bNotifyUser));
| zyz2011-vim | src/proto/if_ole.pro | Prolog | gpl2 | 172 |
/* quickfix.c */
int qf_init __ARGS((win_T *wp, char_u *efile, char_u *errorformat, int newlist, char_u *qf_title));
void qf_free_all __ARGS((win_T *wp));
void copy_loclist __ARGS((win_T *from, win_T *to));
void qf_jump __ARGS((qf_info_T *qi, int dir, int errornr, int forceit));
void qf_list __ARGS((exarg_T *eap));
void qf_age __ARGS((exarg_T *eap));
void qf_mark_adjust __ARGS((win_T *wp, linenr_T line1, linenr_T line2, long amount, long amount_after));
void ex_cwindow __ARGS((exarg_T *eap));
void ex_cclose __ARGS((exarg_T *eap));
void ex_copen __ARGS((exarg_T *eap));
linenr_T qf_current_entry __ARGS((win_T *wp));
int bt_quickfix __ARGS((buf_T *buf));
int bt_nofile __ARGS((buf_T *buf));
int bt_dontwrite __ARGS((buf_T *buf));
int bt_dontwrite_msg __ARGS((buf_T *buf));
int buf_hide __ARGS((buf_T *buf));
int grep_internal __ARGS((cmdidx_T cmdidx));
void ex_make __ARGS((exarg_T *eap));
void ex_cc __ARGS((exarg_T *eap));
void ex_cnext __ARGS((exarg_T *eap));
void ex_cfile __ARGS((exarg_T *eap));
void ex_vimgrep __ARGS((exarg_T *eap));
char_u *skip_vimgrep_pat __ARGS((char_u *p, char_u **s, int *flags));
int get_errorlist __ARGS((win_T *wp, list_T *list));
int set_errorlist __ARGS((win_T *wp, list_T *list, int action, char_u *title));
void ex_cbuffer __ARGS((exarg_T *eap));
void ex_cexpr __ARGS((exarg_T *eap));
void ex_helpgrep __ARGS((exarg_T *eap));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/quickfix.pro | C | gpl2 | 1,390 |
/* misc2.c */
int virtual_active __ARGS((void));
int getviscol __ARGS((void));
int getviscol2 __ARGS((colnr_T col, colnr_T coladd));
int coladvance_force __ARGS((colnr_T wcol));
int coladvance __ARGS((colnr_T wcol));
int getvpos __ARGS((pos_T *pos, colnr_T wcol));
int inc_cursor __ARGS((void));
int inc __ARGS((pos_T *lp));
int incl __ARGS((pos_T *lp));
int dec_cursor __ARGS((void));
int dec __ARGS((pos_T *lp));
int decl __ARGS((pos_T *lp));
linenr_T get_cursor_rel_lnum __ARGS((win_T *wp, linenr_T lnum));
void check_cursor_lnum __ARGS((void));
void check_cursor_col __ARGS((void));
void check_cursor_col_win __ARGS((win_T *win));
void check_cursor __ARGS((void));
void adjust_cursor_col __ARGS((void));
int leftcol_changed __ARGS((void));
void vim_mem_profile_dump __ARGS((void));
char_u *alloc __ARGS((unsigned size));
char_u *alloc_clear __ARGS((unsigned size));
char_u *alloc_check __ARGS((unsigned size));
char_u *lalloc_clear __ARGS((long_u size, int message));
char_u *lalloc __ARGS((long_u size, int message));
void *mem_realloc __ARGS((void *ptr, size_t size));
void do_outofmem_msg __ARGS((long_u size));
void free_all_mem __ARGS((void));
char_u *vim_strsave __ARGS((char_u *string));
char_u *vim_strnsave __ARGS((char_u *string, int len));
char_u *vim_strsave_escaped __ARGS((char_u *string, char_u *esc_chars));
char_u *vim_strsave_escaped_ext __ARGS((char_u *string, char_u *esc_chars, int cc, int bsl));
int csh_like_shell __ARGS((void));
char_u *vim_strsave_shellescape __ARGS((char_u *string, int do_special));
char_u *vim_strsave_up __ARGS((char_u *string));
char_u *vim_strnsave_up __ARGS((char_u *string, int len));
void vim_strup __ARGS((char_u *p));
char_u *strup_save __ARGS((char_u *orig));
void copy_spaces __ARGS((char_u *ptr, size_t count));
void copy_chars __ARGS((char_u *ptr, size_t count, int c));
void del_trailing_spaces __ARGS((char_u *ptr));
void vim_strncpy __ARGS((char_u *to, char_u *from, size_t len));
void vim_strcat __ARGS((char_u *to, char_u *from, size_t tosize));
int copy_option_part __ARGS((char_u **option, char_u *buf, int maxlen, char *sep_chars));
void vim_free __ARGS((void *x));
int vim_stricmp __ARGS((char *s1, char *s2));
int vim_strnicmp __ARGS((char *s1, char *s2, size_t len));
char_u *vim_strchr __ARGS((char_u *string, int c));
char_u *vim_strbyte __ARGS((char_u *string, int c));
char_u *vim_strrchr __ARGS((char_u *string, int c));
int vim_isspace __ARGS((int x));
void ga_clear __ARGS((garray_T *gap));
void ga_clear_strings __ARGS((garray_T *gap));
void ga_init __ARGS((garray_T *gap));
void ga_init2 __ARGS((garray_T *gap, int itemsize, int growsize));
int ga_grow __ARGS((garray_T *gap, int n));
char_u *ga_concat_strings __ARGS((garray_T *gap));
void ga_concat __ARGS((garray_T *gap, char_u *s));
void ga_append __ARGS((garray_T *gap, int c));
void append_ga_line __ARGS((garray_T *gap));
int name_to_mod_mask __ARGS((int c));
int simplify_key __ARGS((int key, int *modifiers));
int handle_x_keys __ARGS((int key));
char_u *get_special_key_name __ARGS((int c, int modifiers));
int trans_special __ARGS((char_u **srcp, char_u *dst, int keycode));
int find_special_key __ARGS((char_u **srcp, int *modp, int keycode, int keep_x_key));
int extract_modifiers __ARGS((int key, int *modp));
int find_special_key_in_table __ARGS((int c));
int get_special_key_code __ARGS((char_u *name));
char_u *get_key_name __ARGS((int i));
int get_mouse_button __ARGS((int code, int *is_click, int *is_drag));
int get_pseudo_mouse_code __ARGS((int button, int is_click, int is_drag));
int get_fileformat __ARGS((buf_T *buf));
int get_fileformat_force __ARGS((buf_T *buf, exarg_T *eap));
void set_fileformat __ARGS((int t, int opt_flags));
int default_fileformat __ARGS((void));
int call_shell __ARGS((char_u *cmd, int opt));
int get_real_state __ARGS((void));
int after_pathsep __ARGS((char_u *b, char_u *p));
int same_directory __ARGS((char_u *f1, char_u *f2));
int vim_chdirfile __ARGS((char_u *fname));
int illegal_slash __ARGS((char *name));
char_u *parse_shape_opt __ARGS((int what));
int get_shape_idx __ARGS((int mouse));
void update_mouseshape __ARGS((int shape_idx));
int crypt_method_from_string __ARGS((char_u *s));
int get_crypt_method __ARGS((buf_T *buf));
void set_crypt_method __ARGS((buf_T *buf, int method));
void crypt_push_state __ARGS((void));
void crypt_pop_state __ARGS((void));
void crypt_encode __ARGS((char_u *from, size_t len, char_u *to));
void crypt_decode __ARGS((char_u *ptr, long len));
void crypt_init_keys __ARGS((char_u *passwd));
void free_crypt_key __ARGS((char_u *key));
char_u *get_crypt_key __ARGS((int store, int twice));
void *vim_findfile_init __ARGS((char_u *path, char_u *filename, char_u *stopdirs, int level, int free_visited, int find_what, void *search_ctx_arg, int tagfile, char_u *rel_fname));
char_u *vim_findfile_stopdir __ARGS((char_u *buf));
void vim_findfile_cleanup __ARGS((void *ctx));
char_u *vim_findfile __ARGS((void *search_ctx_arg));
void vim_findfile_free_visited __ARGS((void *search_ctx_arg));
char_u *find_file_in_path __ARGS((char_u *ptr, int len, int options, int first, char_u *rel_fname));
char_u *find_directory_in_path __ARGS((char_u *ptr, int len, int options, char_u *rel_fname));
char_u *find_file_in_path_option __ARGS((char_u *ptr, int len, int options, int first, char_u *path_option, int find_what, char_u *rel_fname, char_u *suffixes));
int vim_chdir __ARGS((char_u *new_dir));
int get_user_name __ARGS((char_u *buf, int len));
void sort_strings __ARGS((char_u **files, int count));
int pathcmp __ARGS((const char *p, const char *q, int maxlen));
int filewritable __ARGS((char_u *fname));
int emsg3 __ARGS((char_u *s, char_u *a1, char_u *a2));
int emsgn __ARGS((char_u *s, long n));
int get2c __ARGS((FILE *fd));
int get3c __ARGS((FILE *fd));
int get4c __ARGS((FILE *fd));
time_t get8ctime __ARGS((FILE *fd));
char_u *read_string __ARGS((FILE *fd, int cnt));
int put_bytes __ARGS((FILE *fd, long_u nr, int len));
void put_time __ARGS((FILE *fd, time_t the_time));
int has_non_ascii __ARGS((char_u *s));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/misc2.pro | C | gpl2 | 6,054 |
/* gui_gtk_x11.c */
void gui_mch_prepare __ARGS((int *argc, char **argv));
void gui_mch_free_all __ARGS((void));
void gui_mch_set_blinking __ARGS((long waittime, long on, long off));
void gui_mch_stop_blink __ARGS((void));
void gui_mch_start_blink __ARGS((void));
int gui_mch_early_init_check __ARGS((void));
int gui_mch_init_check __ARGS((void));
void gui_mch_show_tabline __ARGS((int showit));
int gui_mch_showing_tabline __ARGS((void));
void gui_mch_update_tabline __ARGS((void));
void gui_mch_set_curtab __ARGS((int nr));
void gui_gtk_set_selection_targets __ARGS((void));
void gui_gtk_set_dnd_targets __ARGS((void));
int gui_mch_init __ARGS((void));
void gui_mch_forked __ARGS((void));
void gui_mch_new_colors __ARGS((void));
int gui_mch_open __ARGS((void));
void gui_mch_exit __ARGS((int rc));
int gui_mch_get_winpos __ARGS((int *x, int *y));
void gui_mch_set_winpos __ARGS((int x, int y));
int gui_mch_maximized __ARGS((void));
void gui_mch_unmaximize __ARGS((void));
void gui_mch_newfont __ARGS((void));
void gui_mch_set_shellsize __ARGS((int width, int height, int min_width, int min_height, int base_width, int base_height, int direction));
void gui_mch_get_screen_dimensions __ARGS((int *screen_w, int *screen_h));
void gui_mch_settitle __ARGS((char_u *title, char_u *icon));
void gui_mch_enable_menu __ARGS((int showit));
void gui_mch_show_toolbar __ARGS((int showit));
int gui_mch_adjust_charheight __ARGS((void));
char_u *gui_mch_font_dialog __ARGS((char_u *oldval));
int gui_mch_init_font __ARGS((char_u *font_name, int fontset));
GuiFont gui_mch_get_font __ARGS((char_u *name, int report_error));
char_u *gui_mch_get_fontname __ARGS((GuiFont font, char_u *name));
void gui_mch_free_font __ARGS((GuiFont font));
guicolor_T gui_mch_get_color __ARGS((char_u *name));
void gui_mch_set_fg_color __ARGS((guicolor_T color));
void gui_mch_set_bg_color __ARGS((guicolor_T color));
void gui_mch_set_sp_color __ARGS((guicolor_T color));
int gui_gtk2_draw_string __ARGS((int row, int col, char_u *s, int len, int flags));
int gui_mch_haskey __ARGS((char_u *name));
int gui_get_x11_windis __ARGS((Window *win, Display **dis));
Display *gui_mch_get_display __ARGS((void));
void gui_mch_beep __ARGS((void));
void gui_mch_flash __ARGS((int msec));
void gui_mch_invert_rectangle __ARGS((int r, int c, int nr, int nc));
void gui_mch_iconify __ARGS((void));
void gui_mch_set_foreground __ARGS((void));
void gui_mch_draw_hollow_cursor __ARGS((guicolor_T color));
void gui_mch_draw_part_cursor __ARGS((int w, int h, guicolor_T color));
void gui_mch_update __ARGS((void));
int gui_mch_wait_for_chars __ARGS((long wtime));
void gui_mch_flush __ARGS((void));
void gui_mch_clear_block __ARGS((int row1, int col1, int row2, int col2));
void gui_mch_clear_all __ARGS((void));
void gui_mch_delete_lines __ARGS((int row, int num_lines));
void gui_mch_insert_lines __ARGS((int row, int num_lines));
void clip_mch_request_selection __ARGS((VimClipboard *cbd));
void clip_mch_lose_selection __ARGS((VimClipboard *cbd));
int clip_mch_own_selection __ARGS((VimClipboard *cbd));
void clip_mch_set_selection __ARGS((VimClipboard *cbd));
void gui_mch_menu_grey __ARGS((vimmenu_T *menu, int grey));
void gui_mch_menu_hidden __ARGS((vimmenu_T *menu, int hidden));
void gui_mch_draw_menubar __ARGS((void));
void gui_mch_enable_scrollbar __ARGS((scrollbar_T *sb, int flag));
long_u gui_mch_get_rgb __ARGS((guicolor_T pixel));
void gui_mch_getmouse __ARGS((int *x, int *y));
void gui_mch_setmouse __ARGS((int x, int y));
void gui_mch_mousehide __ARGS((int hide));
void mch_set_mouse_shape __ARGS((int shape));
void gui_mch_drawsign __ARGS((int row, int col, int typenr));
void *gui_mch_register_sign __ARGS((char_u *signfile));
void gui_mch_destroy_sign __ARGS((void *sign));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_gtk_x11.pro | C | gpl2 | 3,772 |
/* spell.c */
int spell_check __ARGS((win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, int docount));
int spell_move_to __ARGS((win_T *wp, int dir, int allwords, int curline, hlf_T *attrp));
void spell_cat_line __ARGS((char_u *buf, char_u *line, int maxlen));
char_u *did_set_spelllang __ARGS((win_T *wp));
void spell_free_all __ARGS((void));
void spell_reload __ARGS((void));
int spell_check_msm __ARGS((void));
void ex_mkspell __ARGS((exarg_T *eap));
void ex_spell __ARGS((exarg_T *eap));
void spell_add_word __ARGS((char_u *word, int len, int bad, int idx, int undo));
void init_spell_chartab __ARGS((void));
int spell_check_sps __ARGS((void));
void spell_suggest __ARGS((int count));
void ex_spellrepall __ARGS((exarg_T *eap));
void spell_suggest_list __ARGS((garray_T *gap, char_u *word, int maxcount, int need_cap, int interactive));
char_u *eval_soundfold __ARGS((char_u *word));
void ex_spellinfo __ARGS((exarg_T *eap));
void ex_spelldump __ARGS((exarg_T *eap));
void spell_dump_compl __ARGS((char_u *pat, int ic, int *dir, int dumpflags_arg));
char_u *spell_to_word_end __ARGS((char_u *start, win_T *win));
int spell_word_start __ARGS((int startcol));
void spell_expand_check_cap __ARGS((colnr_T col));
int expand_spelling __ARGS((linenr_T lnum, char_u *pat, char_u ***matchp));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/spell.pro | C | gpl2 | 1,312 |
/* getchar.c */
void free_buff __ARGS((struct buffheader *buf));
char_u *get_recorded __ARGS((void));
char_u *get_inserted __ARGS((void));
int stuff_empty __ARGS((void));
void typeahead_noflush __ARGS((int c));
void flush_buffers __ARGS((int flush_typeahead));
void ResetRedobuff __ARGS((void));
void CancelRedo __ARGS((void));
void saveRedobuff __ARGS((void));
void restoreRedobuff __ARGS((void));
void AppendToRedobuff __ARGS((char_u *s));
void AppendToRedobuffLit __ARGS((char_u *str, int len));
void AppendCharToRedobuff __ARGS((int c));
void AppendNumberToRedobuff __ARGS((long n));
void stuffReadbuff __ARGS((char_u *s));
void stuffReadbuffLen __ARGS((char_u *s, long len));
void stuffReadbuffSpec __ARGS((char_u *s));
void stuffcharReadbuff __ARGS((int c));
void stuffnumReadbuff __ARGS((long n));
int start_redo __ARGS((long count, int old_redo));
int start_redo_ins __ARGS((void));
void stop_redo_ins __ARGS((void));
int ins_typebuf __ARGS((char_u *str, int noremap, int offset, int nottyped, int silent));
void ins_char_typebuf __ARGS((int c));
int typebuf_changed __ARGS((int tb_change_cnt));
int typebuf_typed __ARGS((void));
int typebuf_maplen __ARGS((void));
void del_typebuf __ARGS((int len, int offset));
int alloc_typebuf __ARGS((void));
void free_typebuf __ARGS((void));
int save_typebuf __ARGS((void));
void save_typeahead __ARGS((tasave_T *tp));
void restore_typeahead __ARGS((tasave_T *tp));
void openscript __ARGS((char_u *name, int directly));
void close_all_scripts __ARGS((void));
int using_script __ARGS((void));
void before_blocking __ARGS((void));
void updatescript __ARGS((int c));
int vgetc __ARGS((void));
int safe_vgetc __ARGS((void));
int plain_vgetc __ARGS((void));
int vpeekc __ARGS((void));
int vpeekc_nomap __ARGS((void));
int vpeekc_any __ARGS((void));
int char_avail __ARGS((void));
void vungetc __ARGS((int c));
int inchar __ARGS((char_u *buf, int maxlen, long wait_time, int tb_change_cnt));
int fix_input_buffer __ARGS((char_u *buf, int len, int script));
int input_available __ARGS((void));
int do_map __ARGS((int maptype, char_u *arg, int mode, int abbrev));
int get_map_mode __ARGS((char_u **cmdp, int forceit));
void map_clear __ARGS((char_u *cmdp, char_u *arg, int forceit, int abbr));
void map_clear_int __ARGS((buf_T *buf, int mode, int local, int abbr));
char_u *map_mode_to_chars __ARGS((int mode));
int map_to_exists __ARGS((char_u *str, char_u *modechars, int abbr));
int map_to_exists_mode __ARGS((char_u *rhs, int mode, int abbr));
char_u *set_context_in_map_cmd __ARGS((expand_T *xp, char_u *cmd, char_u *arg, int forceit, int isabbrev, int isunmap, cmdidx_T cmdidx));
int ExpandMappings __ARGS((regmatch_T *regmatch, int *num_file, char_u ***file));
int check_abbr __ARGS((int c, char_u *ptr, int col, int mincol));
char_u *vim_strsave_escape_csi __ARGS((char_u *p));
void vim_unescape_csi __ARGS((char_u *p));
int makemap __ARGS((FILE *fd, buf_T *buf));
int put_escstr __ARGS((FILE *fd, char_u *strstart, int what));
void check_map_keycodes __ARGS((void));
char_u *check_map __ARGS((char_u *keys, int mode, int exact, int ign_mod, int abbr, mapblock_T **mp_ptr, int *local_ptr));
void init_mappings __ARGS((void));
void add_map __ARGS((char_u *map, int mode));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/getchar.pro | C | gpl2 | 3,241 |
/* fold.c */
void copyFoldingState __ARGS((win_T *wp_from, win_T *wp_to));
int hasAnyFolding __ARGS((win_T *win));
int hasFolding __ARGS((linenr_T lnum, linenr_T *firstp, linenr_T *lastp));
int hasFoldingWin __ARGS((win_T *win, linenr_T lnum, linenr_T *firstp, linenr_T *lastp, int cache, foldinfo_T *infop));
int foldLevel __ARGS((linenr_T lnum));
int lineFolded __ARGS((win_T *win, linenr_T lnum));
long foldedCount __ARGS((win_T *win, linenr_T lnum, foldinfo_T *infop));
int foldmethodIsManual __ARGS((win_T *wp));
int foldmethodIsIndent __ARGS((win_T *wp));
int foldmethodIsExpr __ARGS((win_T *wp));
int foldmethodIsMarker __ARGS((win_T *wp));
int foldmethodIsSyntax __ARGS((win_T *wp));
int foldmethodIsDiff __ARGS((win_T *wp));
void closeFold __ARGS((linenr_T lnum, long count));
void closeFoldRecurse __ARGS((linenr_T lnum));
void opFoldRange __ARGS((linenr_T first, linenr_T last, int opening, int recurse, int had_visual));
void openFold __ARGS((linenr_T lnum, long count));
void openFoldRecurse __ARGS((linenr_T lnum));
void foldOpenCursor __ARGS((void));
void newFoldLevel __ARGS((void));
void foldCheckClose __ARGS((void));
int foldManualAllowed __ARGS((int create));
void foldCreate __ARGS((linenr_T start, linenr_T end));
void deleteFold __ARGS((linenr_T start, linenr_T end, int recursive, int had_visual));
void clearFolding __ARGS((win_T *win));
void foldUpdate __ARGS((win_T *wp, linenr_T top, linenr_T bot));
void foldUpdateAll __ARGS((win_T *win));
int foldMoveTo __ARGS((int updown, int dir, long count));
void foldInitWin __ARGS((win_T *newwin));
int find_wl_entry __ARGS((win_T *win, linenr_T lnum));
void foldAdjustVisual __ARGS((void));
void foldAdjustCursor __ARGS((void));
void cloneFoldGrowArray __ARGS((garray_T *from, garray_T *to));
void deleteFoldRecurse __ARGS((garray_T *gap));
void foldMarkAdjust __ARGS((win_T *wp, linenr_T line1, linenr_T line2, long amount, long amount_after));
int getDeepestNesting __ARGS((void));
char_u *get_foldtext __ARGS((win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T *foldinfo, char_u *buf));
void foldtext_cleanup __ARGS((char_u *str));
int put_folds __ARGS((FILE *fd, win_T *wp));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/fold.pro | C | gpl2 | 2,175 |
/* os_win16.c */
void mch_setmouse __ARGS((int on));
void mch_init __ARGS((void));
int mch_check_win __ARGS((int argc, char **argv));
long mch_get_pid __ARGS((void));
int mch_call_shell __ARGS((char_u *cmd, int options));
void mch_delay __ARGS((long msec, int ignoreinput));
void mch_breakcheck __ARGS((void));
long_u mch_avail_mem __ARGS((int special));
int mch_rename __ARGS((const char *pszOldFile, const char *pszNewFile));
char *default_shell __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/os_win16.pro | C | gpl2 | 486 |
/* ui.c */
void ui_write __ARGS((char_u *s, int len));
void ui_inchar_undo __ARGS((char_u *s, int len));
int ui_inchar __ARGS((char_u *buf, int maxlen, long wtime, int tb_change_cnt));
int ui_char_avail __ARGS((void));
void ui_delay __ARGS((long msec, int ignoreinput));
void ui_suspend __ARGS((void));
void suspend_shell __ARGS((void));
int ui_get_shellsize __ARGS((void));
void ui_set_shellsize __ARGS((int mustset));
void ui_new_shellsize __ARGS((void));
void ui_breakcheck __ARGS((void));
void clip_init __ARGS((int can_use));
void clip_update_selection __ARGS((void));
void clip_own_selection __ARGS((VimClipboard *cbd));
void clip_lose_selection __ARGS((VimClipboard *cbd));
void clip_copy_selection __ARGS((void));
void clip_auto_select __ARGS((void));
int clip_isautosel __ARGS((void));
void clip_modeless __ARGS((int button, int is_click, int is_drag));
void clip_start_selection __ARGS((int col, int row, int repeated_click));
void clip_process_selection __ARGS((int button, int col, int row, int_u repeated_click));
void clip_may_redraw_selection __ARGS((int row, int col, int len));
void clip_clear_selection __ARGS((void));
void clip_may_clear_selection __ARGS((int row1, int row2));
void clip_scroll_selection __ARGS((int rows));
void clip_copy_modeless_selection __ARGS((int both));
int clip_gen_own_selection __ARGS((VimClipboard *cbd));
void clip_gen_lose_selection __ARGS((VimClipboard *cbd));
void clip_gen_set_selection __ARGS((VimClipboard *cbd));
void clip_gen_request_selection __ARGS((VimClipboard *cbd));
int vim_is_input_buf_full __ARGS((void));
int vim_is_input_buf_empty __ARGS((void));
int vim_free_in_input_buf __ARGS((void));
int vim_used_in_input_buf __ARGS((void));
char_u *get_input_buf __ARGS((void));
void set_input_buf __ARGS((char_u *p));
void add_to_input_buf __ARGS((char_u *s, int len));
void add_to_input_buf_csi __ARGS((char_u *str, int len));
void push_raw_key __ARGS((char_u *s, int len));
void trash_input_buf __ARGS((void));
int read_from_input_buf __ARGS((char_u *buf, long maxlen));
void fill_input_buf __ARGS((int exit_on_error));
void read_error_exit __ARGS((void));
void ui_cursor_shape __ARGS((void));
int check_col __ARGS((int col));
int check_row __ARGS((int row));
void open_app_context __ARGS((void));
void x11_setup_atoms __ARGS((Display *dpy));
void x11_setup_selection __ARGS((Widget w));
void clip_x11_request_selection __ARGS((Widget myShell, Display *dpy, VimClipboard *cbd));
void clip_x11_lose_selection __ARGS((Widget myShell, VimClipboard *cbd));
int clip_x11_own_selection __ARGS((Widget myShell, VimClipboard *cbd));
void clip_x11_set_selection __ARGS((VimClipboard *cbd));
void yank_cut_buffer0 __ARGS((Display *dpy, VimClipboard *cbd));
int jump_to_mouse __ARGS((int flags, int *inclusive, int which_button));
int mouse_comp_pos __ARGS((win_T *win, int *rowp, int *colp, linenr_T *lnump));
win_T *mouse_find_win __ARGS((int *rowp, int *colp));
int get_fpos_of_mouse __ARGS((pos_T *mpos));
int vcol2col __ARGS((win_T *wp, linenr_T lnum, int vcol));
void ui_focus_change __ARGS((int in_focus));
void im_save_status __ARGS((long *psave));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/ui.pro | C | gpl2 | 3,129 |
/* buffer.c */
int open_buffer __ARGS((int read_stdin, exarg_T *eap, int flags));
int buf_valid __ARGS((buf_T *buf));
void close_buffer __ARGS((win_T *win, buf_T *buf, int action, int abort_if_last));
void buf_clear_file __ARGS((buf_T *buf));
void buf_freeall __ARGS((buf_T *buf, int flags));
void goto_buffer __ARGS((exarg_T *eap, int start, int dir, int count));
void handle_swap_exists __ARGS((buf_T *old_curbuf));
char_u *do_bufdel __ARGS((int command, char_u *arg, int addr_count, int start_bnr, int end_bnr, int forceit));
int do_buffer __ARGS((int action, int start, int dir, int count, int forceit));
void set_curbuf __ARGS((buf_T *buf, int action));
void enter_buffer __ARGS((buf_T *buf));
void do_autochdir __ARGS((void));
buf_T *buflist_new __ARGS((char_u *ffname, char_u *sfname, linenr_T lnum, int flags));
void free_buf_options __ARGS((buf_T *buf, int free_p_ff));
int buflist_getfile __ARGS((int n, linenr_T lnum, int options, int forceit));
void buflist_getfpos __ARGS((void));
buf_T *buflist_findname_exp __ARGS((char_u *fname));
buf_T *buflist_findname __ARGS((char_u *ffname));
int buflist_findpat __ARGS((char_u *pattern, char_u *pattern_end, int unlisted, int diffmode));
int ExpandBufnames __ARGS((char_u *pat, int *num_file, char_u ***file, int options));
buf_T *buflist_findnr __ARGS((int nr));
char_u *buflist_nr2name __ARGS((int n, int fullname, int helptail));
void get_winopts __ARGS((buf_T *buf));
pos_T *buflist_findfpos __ARGS((buf_T *buf));
linenr_T buflist_findlnum __ARGS((buf_T *buf));
void buflist_list __ARGS((exarg_T *eap));
int buflist_name_nr __ARGS((int fnum, char_u **fname, linenr_T *lnum));
int setfname __ARGS((buf_T *buf, char_u *ffname, char_u *sfname, int message));
void buf_set_name __ARGS((int fnum, char_u *name));
void buf_name_changed __ARGS((buf_T *buf));
buf_T *setaltfname __ARGS((char_u *ffname, char_u *sfname, linenr_T lnum));
char_u *getaltfname __ARGS((int errmsg));
int buflist_add __ARGS((char_u *fname, int flags));
void buflist_slash_adjust __ARGS((void));
void buflist_altfpos __ARGS((win_T *win));
int otherfile __ARGS((char_u *ffname));
void buf_setino __ARGS((buf_T *buf));
void fileinfo __ARGS((int fullname, int shorthelp, int dont_truncate));
void col_print __ARGS((char_u *buf, size_t buflen, int col, int vcol));
void maketitle __ARGS((void));
void resettitle __ARGS((void));
void free_titles __ARGS((void));
int build_stl_str_hl __ARGS((win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use_sandbox, int fillchar, int maxwidth, struct stl_hlrec *hltab, struct stl_hlrec *tabtab));
void get_rel_pos __ARGS((win_T *wp, char_u *buf, int buflen));
char_u *fix_fname __ARGS((char_u *fname));
void fname_expand __ARGS((buf_T *buf, char_u **ffname, char_u **sfname));
char_u *alist_name __ARGS((aentry_T *aep));
void do_arg_all __ARGS((int count, int forceit, int keep_tabs));
void ex_buffer_all __ARGS((exarg_T *eap));
void do_modelines __ARGS((int flags));
int read_viminfo_bufferlist __ARGS((vir_T *virp, int writing));
void write_viminfo_bufferlist __ARGS((FILE *fp));
char *buf_spname __ARGS((buf_T *buf));
void buf_addsign __ARGS((buf_T *buf, int id, linenr_T lnum, int typenr));
linenr_T buf_change_sign_type __ARGS((buf_T *buf, int markId, int typenr));
int buf_getsigntype __ARGS((buf_T *buf, linenr_T lnum, int type));
linenr_T buf_delsign __ARGS((buf_T *buf, int id));
int buf_findsign __ARGS((buf_T *buf, int id));
int buf_findsign_id __ARGS((buf_T *buf, linenr_T lnum));
int buf_findsigntype_id __ARGS((buf_T *buf, linenr_T lnum, int typenr));
int buf_signcount __ARGS((buf_T *buf, linenr_T lnum));
void buf_delete_all_signs __ARGS((void));
void sign_list_placed __ARGS((buf_T *rbuf));
void sign_mark_adjust __ARGS((linenr_T line1, linenr_T line2, long amount, long amount_after));
void set_buflisted __ARGS((int on));
int buf_contents_changed __ARGS((buf_T *buf));
void wipe_buffer __ARGS((buf_T *buf, int aucmd));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/buffer.pro | C | gpl2 | 3,926 |
/* gui_athena.c */
void gui_x11_create_widgets __ARGS((void));
void gui_x11_destroy_widgets __ARGS((void));
void gui_mch_set_toolbar_pos __ARGS((int x, int y, int w, int h));
void gui_mch_set_text_area_pos __ARGS((int x, int y, int w, int h));
void gui_x11_set_back_color __ARGS((void));
void gui_mch_enable_menu __ARGS((int flag));
void gui_mch_set_menu_pos __ARGS((int x, int y, int w, int h));
void gui_mch_add_menu __ARGS((vimmenu_T *menu, int idx));
void gui_mch_new_menu_font __ARGS((void));
void gui_mch_new_tooltip_font __ARGS((void));
void gui_mch_new_tooltip_colors __ARGS((void));
void gui_mch_add_menu_item __ARGS((vimmenu_T *menu, int idx));
void gui_mch_show_toolbar __ARGS((int showit));
int gui_mch_compute_toolbar_height __ARGS((void));
void gui_mch_get_toolbar_colors __ARGS((Pixel *bgp, Pixel *fgp, Pixel *bsp, Pixel *tsp, Pixel *hsp));
void gui_mch_toggle_tearoffs __ARGS((int enable));
void gui_mch_new_menu_colors __ARGS((void));
void gui_mch_destroy_menu __ARGS((vimmenu_T *menu));
void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu));
void gui_mch_def_colors __ARGS((void));
void gui_mch_set_scrollbar_thumb __ARGS((scrollbar_T *sb, long val, long size, long max));
void gui_mch_set_scrollbar_pos __ARGS((scrollbar_T *sb, int x, int y, int w, int h));
void gui_mch_enable_scrollbar __ARGS((scrollbar_T *sb, int flag));
void gui_mch_create_scrollbar __ARGS((scrollbar_T *sb, int orient));
void gui_mch_destroy_scrollbar __ARGS((scrollbar_T *sb));
void gui_mch_set_scrollbar_colors __ARGS((scrollbar_T *sb));
Window gui_x11_get_wid __ARGS((void));
char_u *gui_mch_browse __ARGS((int saving, char_u *title, char_u *dflt, char_u *ext, char_u *initdir, char_u *filter));
int gui_mch_dialog __ARGS((int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_athena.pro | C | gpl2 | 1,848 |
/* blowfish.c */
void bf_key_init __ARGS((char_u *password, char_u *salt, int salt_len));
void bf_ofb_init __ARGS((char_u *iv, int iv_len));
void bf_crypt_encode __ARGS((char_u *from, size_t len, char_u *to));
void bf_crypt_decode __ARGS((char_u *ptr, long len));
void bf_crypt_init_keys __ARGS((char_u *passwd));
void bf_crypt_save __ARGS((void));
void bf_crypt_restore __ARGS((void));
int blowfish_self_test __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/blowfish.pro | C | gpl2 | 448 |
/* syntax.c */
void syntax_start __ARGS((win_T *wp, linenr_T lnum));
void syn_stack_free_all __ARGS((synblock_T *block));
void syn_stack_apply_changes __ARGS((buf_T *buf));
void syntax_end_parsing __ARGS((linenr_T lnum));
int syntax_check_changed __ARGS((linenr_T lnum));
int get_syntax_attr __ARGS((colnr_T col, int *can_spell, int keep_state));
void syntax_clear __ARGS((synblock_T *block));
void reset_synblock __ARGS((win_T *wp));
void ex_syntax __ARGS((exarg_T *eap));
void ex_ownsyntax __ARGS((exarg_T *eap));
int syntax_present __ARGS((win_T *win));
void reset_expand_highlight __ARGS((void));
void set_context_in_echohl_cmd __ARGS((expand_T *xp, char_u *arg));
void set_context_in_syntax_cmd __ARGS((expand_T *xp, char_u *arg));
char_u *get_syntax_name __ARGS((expand_T *xp, int idx));
int syn_get_id __ARGS((win_T *wp, long lnum, colnr_T col, int trans, int *spellp, int keep_state));
int get_syntax_info __ARGS((int *seqnrp));
int syn_get_sub_char __ARGS((void));
int syn_get_stack_item __ARGS((int i));
int syn_get_foldlevel __ARGS((win_T *wp, long lnum));
void init_highlight __ARGS((int both, int reset));
int load_colors __ARGS((char_u *name));
void do_highlight __ARGS((char_u *line, int forceit, int init));
void free_highlight __ARGS((void));
void restore_cterm_colors __ARGS((void));
void set_normal_colors __ARGS((void));
char_u *hl_get_font_name __ARGS((void));
void hl_set_font_name __ARGS((char_u *font_name));
void hl_set_bg_color_name __ARGS((char_u *name));
void hl_set_fg_color_name __ARGS((char_u *name));
void clear_hl_tables __ARGS((void));
int hl_combine_attr __ARGS((int char_attr, int prim_attr));
attrentry_T *syn_gui_attr2entry __ARGS((int attr));
int syn_attr2attr __ARGS((int attr));
attrentry_T *syn_term_attr2entry __ARGS((int attr));
attrentry_T *syn_cterm_attr2entry __ARGS((int attr));
char_u *highlight_has_attr __ARGS((int id, int flag, int modec));
char_u *highlight_color __ARGS((int id, char_u *what, int modec));
long_u highlight_gui_color_rgb __ARGS((int id, int fg));
int syn_name2id __ARGS((char_u *name));
int highlight_exists __ARGS((char_u *name));
char_u *syn_id2name __ARGS((int id));
int syn_namen2id __ARGS((char_u *linep, int len));
int syn_check_group __ARGS((char_u *pp, int len));
int syn_id2attr __ARGS((int hl_id));
int syn_id2colors __ARGS((int hl_id, guicolor_T *fgp, guicolor_T *bgp));
int syn_get_final_id __ARGS((int hl_id));
void highlight_gui_started __ARGS((void));
int highlight_changed __ARGS((void));
void set_context_in_highlight_cmd __ARGS((expand_T *xp, char_u *arg));
char_u *get_highlight_name __ARGS((expand_T *xp, int idx));
void free_highlight_fonts __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/syntax.pro | C | gpl2 | 2,670 |
/* search.c */
int search_regcomp __ARGS((char_u *pat, int pat_save, int pat_use, int options, regmmatch_T *regmatch));
char_u *get_search_pat __ARGS((void));
char_u *reverse_text __ARGS((char_u *s));
void save_search_patterns __ARGS((void));
void restore_search_patterns __ARGS((void));
void free_search_patterns __ARGS((void));
int ignorecase __ARGS((char_u *pat));
int pat_has_uppercase __ARGS((char_u *pat));
char_u *last_search_pat __ARGS((void));
void reset_search_dir __ARGS((void));
void set_last_search_pat __ARGS((char_u *s, int idx, int magic, int setlast));
void last_pat_prog __ARGS((regmmatch_T *regmatch));
int searchit __ARGS((win_T *win, buf_T *buf, pos_T *pos, int dir, char_u *pat, long count, int options, int pat_use, linenr_T stop_lnum, proftime_T *tm));
void set_search_direction __ARGS((int cdir));
int do_search __ARGS((oparg_T *oap, int dirc, char_u *pat, long count, int options, proftime_T *tm));
int search_for_exact_line __ARGS((buf_T *buf, pos_T *pos, int dir, char_u *pat));
int searchc __ARGS((cmdarg_T *cap, int t_cmd));
pos_T *findmatch __ARGS((oparg_T *oap, int initc));
pos_T *findmatchlimit __ARGS((oparg_T *oap, int initc, int flags, int maxtravel));
void showmatch __ARGS((int c));
int findsent __ARGS((int dir, long count));
int findpar __ARGS((int *pincl, int dir, long count, int what, int both));
int startPS __ARGS((linenr_T lnum, int para, int both));
int fwd_word __ARGS((long count, int bigword, int eol));
int bck_word __ARGS((long count, int bigword, int stop));
int end_word __ARGS((long count, int bigword, int stop, int empty));
int bckend_word __ARGS((long count, int bigword, int eol));
int current_word __ARGS((oparg_T *oap, long count, int include, int bigword));
int current_sent __ARGS((oparg_T *oap, long count, int include));
int current_block __ARGS((oparg_T *oap, long count, int include, int what, int other));
int current_tagblock __ARGS((oparg_T *oap, long count_arg, int include));
int current_par __ARGS((oparg_T *oap, long count, int include, int type));
int current_quote __ARGS((oparg_T *oap, long count, int include, int quotechar));
int linewhite __ARGS((linenr_T lnum));
void find_pattern_in_path __ARGS((char_u *ptr, int dir, int len, int whole, int skip_comments, int type, long count, int action, linenr_T start_lnum, linenr_T end_lnum));
int read_viminfo_search_pattern __ARGS((vir_T *virp, int force));
void write_viminfo_search_pattern __ARGS((FILE *fp));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/search.pro | C | gpl2 | 2,458 |
/* gui_gtk.c */
void gui_gtk_register_stock_icons __ARGS((void));
void gui_mch_add_menu __ARGS((vimmenu_T *menu, int idx));
void gui_mch_add_menu_item __ARGS((vimmenu_T *menu, int idx));
void gui_mch_set_text_area_pos __ARGS((int x, int y, int w, int h));
void gui_gtk_set_mnemonics __ARGS((int enable));
void gui_mch_toggle_tearoffs __ARGS((int enable));
void gui_mch_menu_set_tip __ARGS((vimmenu_T *menu));
void gui_mch_destroy_menu __ARGS((vimmenu_T *menu));
void gui_mch_set_scrollbar_thumb __ARGS((scrollbar_T *sb, long val, long size, long max));
void gui_mch_set_scrollbar_pos __ARGS((scrollbar_T *sb, int x, int y, int w, int h));
void gui_mch_create_scrollbar __ARGS((scrollbar_T *sb, int orient));
void gui_mch_destroy_scrollbar __ARGS((scrollbar_T *sb));
char_u *gui_mch_browse __ARGS((int saving, char_u *title, char_u *dflt, char_u *ext, char_u *initdir, char_u *filter));
char_u *gui_mch_browsedir __ARGS((char_u *title, char_u *initdir));
int gui_mch_dialog __ARGS((int type, char_u *title, char_u *message, char_u *buttons, int def_but, char_u *textfield, int ex_cmd));
void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu));
void gui_make_popup __ARGS((char_u *path_name, int mouse_pos));
void gui_mch_find_dialog __ARGS((exarg_T *eap));
void gui_mch_replace_dialog __ARGS((exarg_T *eap));
void ex_helpfind __ARGS((exarg_T *eap));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_gtk.pro | C | gpl2 | 1,369 |
/* if_mzsch.c */
int mzscheme_enabled __ARGS((int verbose));
void mzscheme_end __ARGS((void));
void ex_mzscheme __ARGS((exarg_T *eap));
void ex_mzfile __ARGS((exarg_T *eap));
void mzscheme_buffer_free __ARGS((buf_T *buf));
void mzscheme_window_free __ARGS((win_T *win));
char *mzscheme_version __ARGS((void));
void raise_vim_exn(const char *add_info);
void raise_if_error __ARGS((void));
buf_T *get_valid_buffer __ARGS((void *));
win_T *get_valid_window __ARGS((void *));
void mzvim_check_threads __ARGS((void));
void mzvim_reset_timer __ARGS((void));
void *mzvim_eval_string __ARGS((char_u *str));
int mzthreads_allowed __ARGS((void));
int mzscheme_main __ARGS((int argc, char **argv));
void do_mzeval __ARGS((char_u *str, typval_T *rettv));
int vim_main2 __ARGS((int argc, char **argv));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/if_mzsch.pro | C | gpl2 | 812 |
/* os_qnx.c */
void qnx_init __ARGS((void));
void qnx_clip_init __ARGS((void));
int clip_mch_own_selection __ARGS((VimClipboard *cbd));
void clip_mch_lose_selection __ARGS((VimClipboard *cbd));
void clip_mch_request_selection __ARGS((VimClipboard *cbd));
void clip_mch_set_selection __ARGS((VimClipboard *cbd));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/os_qnx.pro | C | gpl2 | 334 |
/* normal.c */
void init_normal_cmds __ARGS((void));
void normal_cmd __ARGS((oparg_T *oap, int toplevel));
void do_pending_operator __ARGS((cmdarg_T *cap, int old_col, int gui_yank));
int do_mouse __ARGS((oparg_T *oap, int c, int dir, long count, int fixindent));
void check_visual_highlight __ARGS((void));
void end_visual_mode __ARGS((void));
void reset_VIsual_and_resel __ARGS((void));
void reset_VIsual __ARGS((void));
int find_ident_under_cursor __ARGS((char_u **string, int find_type));
int find_ident_at_pos __ARGS((win_T *wp, linenr_T lnum, colnr_T startcol, char_u **string, int find_type));
void clear_showcmd __ARGS((void));
int add_to_showcmd __ARGS((int c));
void add_to_showcmd_c __ARGS((int c));
void push_showcmd __ARGS((void));
void pop_showcmd __ARGS((void));
void do_check_scrollbind __ARGS((int check));
void check_scrollbind __ARGS((linenr_T topline_diff, long leftcol_diff));
int find_decl __ARGS((char_u *ptr, int len, int locally, int thisblock, int searchflags));
void scroll_redraw __ARGS((int up, long count));
void handle_tabmenu __ARGS((void));
void do_nv_ident __ARGS((int c1, int c2));
int get_visual_text __ARGS((cmdarg_T *cap, char_u **pp, int *lenp));
void start_selection __ARGS((void));
void may_start_select __ARGS((int c));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/normal.pro | C | gpl2 | 1,284 |
/* version.c */
void make_version __ARGS((void));
int highest_patch __ARGS((void));
int has_patch __ARGS((int n));
void ex_version __ARGS((exarg_T *eap));
void list_version __ARGS((void));
void intro_message __ARGS((int colon));
void ex_intro __ARGS((exarg_T *eap));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/version.pro | C | gpl2 | 289 |
/* digraph.c */
int do_digraph __ARGS((int c));
int get_digraph __ARGS((int cmdline));
int getdigraph __ARGS((int char1, int char2, int meta));
void putdigraph __ARGS((char_u *str));
void listdigraphs __ARGS((void));
char_u *keymap_init __ARGS((void));
void ex_loadkeymap __ARGS((exarg_T *eap));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/digraph.pro | C | gpl2 | 318 |
/* menu.c */
void ex_menu __ARGS((exarg_T *eap));
char_u *set_context_in_menu_cmd __ARGS((expand_T *xp, char_u *cmd, char_u *arg, int forceit));
char_u *get_menu_name __ARGS((expand_T *xp, int idx));
char_u *get_menu_names __ARGS((expand_T *xp, int idx));
char_u *menu_name_skip __ARGS((char_u *name));
int get_menu_index __ARGS((vimmenu_T *menu, int state));
int menu_is_menubar __ARGS((char_u *name));
int menu_is_popup __ARGS((char_u *name));
int menu_is_child_of_popup __ARGS((vimmenu_T *menu));
int menu_is_toolbar __ARGS((char_u *name));
int menu_is_separator __ARGS((char_u *name));
int check_menu_pointer __ARGS((vimmenu_T *root, vimmenu_T *menu_to_check));
void gui_create_initial_menus __ARGS((vimmenu_T *menu));
void gui_update_menus __ARGS((int modes));
int gui_is_menu_shortcut __ARGS((int key));
void gui_show_popupmenu __ARGS((void));
void gui_mch_toggle_tearoffs __ARGS((int enable));
void ex_emenu __ARGS((exarg_T *eap));
vimmenu_T *gui_find_menu __ARGS((char_u *path_name));
void ex_menutranslate __ARGS((exarg_T *eap));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/menu.pro | C | gpl2 | 1,061 |
/* window.c */
void do_window __ARGS((int nchar, long Prenum, int xchar));
int win_split __ARGS((int size, int flags));
int win_split_ins __ARGS((int size, int flags, win_T *new_wp, int dir));
int win_valid __ARGS((win_T *win));
int win_count __ARGS((void));
int make_windows __ARGS((int count, int vertical));
void win_move_after __ARGS((win_T *win1, win_T *win2));
void win_equal __ARGS((win_T *next_curwin, int current, int dir));
void close_windows __ARGS((buf_T *buf, int keep_curwin));
int one_window __ARGS((void));
void win_close __ARGS((win_T *win, int free_buf));
void win_close_othertab __ARGS((win_T *win, int free_buf, tabpage_T *tp));
void win_free_all __ARGS((void));
win_T *winframe_remove __ARGS((win_T *win, int *dirp, tabpage_T *tp));
void close_others __ARGS((int message, int forceit));
void curwin_init __ARGS((void));
void win_init_empty __ARGS((win_T *wp));
int win_alloc_first __ARGS((void));
void win_alloc_aucmd_win __ARGS((void));
void win_init_size __ARGS((void));
void free_tabpage __ARGS((tabpage_T *tp));
int win_new_tabpage __ARGS((int after));
int may_open_tabpage __ARGS((void));
int make_tabpages __ARGS((int maxcount));
int valid_tabpage __ARGS((tabpage_T *tpc));
tabpage_T *find_tabpage __ARGS((int n));
int tabpage_index __ARGS((tabpage_T *ftp));
void goto_tabpage __ARGS((int n));
void goto_tabpage_tp __ARGS((tabpage_T *tp, int trigger_autocmds));
void goto_tabpage_win __ARGS((tabpage_T *tp, win_T *wp));
void tabpage_move __ARGS((int nr));
void win_goto __ARGS((win_T *wp));
win_T *win_find_nr __ARGS((int winnr));
void win_enter __ARGS((win_T *wp, int undo_sync));
win_T *buf_jump_open_win __ARGS((buf_T *buf));
win_T *buf_jump_open_tab __ARGS((buf_T *buf));
void win_append __ARGS((win_T *after, win_T *wp));
void win_remove __ARGS((win_T *wp, tabpage_T *tp));
int win_alloc_lines __ARGS((win_T *wp));
void win_free_lsize __ARGS((win_T *wp));
void shell_new_rows __ARGS((void));
void shell_new_columns __ARGS((void));
void win_size_save __ARGS((garray_T *gap));
void win_size_restore __ARGS((garray_T *gap));
int win_comp_pos __ARGS((void));
void win_setheight __ARGS((int height));
void win_setheight_win __ARGS((int height, win_T *win));
void win_setwidth __ARGS((int width));
void win_setwidth_win __ARGS((int width, win_T *wp));
void win_setminheight __ARGS((void));
void win_drag_status_line __ARGS((win_T *dragwin, int offset));
void win_drag_vsep_line __ARGS((win_T *dragwin, int offset));
void win_comp_scroll __ARGS((win_T *wp));
void command_height __ARGS((void));
void last_status __ARGS((int morewin));
int tabline_height __ARGS((void));
char_u *grab_file_name __ARGS((long count, linenr_T *file_lnum));
char_u *file_name_at_cursor __ARGS((int options, long count, linenr_T *file_lnum));
char_u *file_name_in_line __ARGS((char_u *line, int col, int options, long count, char_u *rel_fname, linenr_T *file_lnum));
char_u *find_file_name_in_path __ARGS((char_u *ptr, int len, int options, long count, char_u *rel_fname));
int path_with_url __ARGS((char_u *fname));
int vim_isAbsName __ARGS((char_u *name));
int vim_FullName __ARGS((char_u *fname, char_u *buf, int len, int force));
int min_rows __ARGS((void));
int only_one_window __ARGS((void));
void check_lnums __ARGS((int do_curwin));
void make_snapshot __ARGS((int idx));
void restore_snapshot __ARGS((int idx, int close_curwin));
int win_hasvertsplit __ARGS((void));
int match_add __ARGS((win_T *wp, char_u *grp, char_u *pat, int prio, int id));
int match_delete __ARGS((win_T *wp, int id, int perr));
void clear_matches __ARGS((win_T *wp));
matchitem_T *get_match __ARGS((win_T *wp, int id));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/window.pro | C | gpl2 | 3,626 |
/* workshop.c */
void workshop_init __ARGS((void));
void workshop_postinit __ARGS((void));
void ex_wsverb __ARGS((exarg_T *eap));
char *workshop_get_editor_name __ARGS((void));
char *workshop_get_editor_version __ARGS((void));
void workshop_load_file __ARGS((char *filename, int line, char *frameid));
void workshop_reload_file __ARGS((char *filename, int line));
void workshop_show_file __ARGS((char *filename));
void workshop_goto_line __ARGS((char *filename, int lineno));
void workshop_front_file __ARGS((char *filename));
void workshop_save_file __ARGS((char *filename));
void workshop_save_files __ARGS((void));
void workshop_quit __ARGS((void));
void workshop_minimize __ARGS((void));
void workshop_maximize __ARGS((void));
void workshop_add_mark_type __ARGS((int idx, char *colorspec, char *sign));
void workshop_set_mark __ARGS((char *filename, int lineno, int markId, int idx));
void workshop_change_mark_type __ARGS((char *filename, int markId, int idx));
void workshop_goto_mark __ARGS((char *filename, int markId, char *message));
void workshop_delete_mark __ARGS((char *filename, int markId));
int workshop_get_mark_lineno __ARGS((char *filename, int markId));
void workshop_moved_marks __ARGS((char *filename));
int workshop_get_font_height __ARGS((void));
void workshop_footer_message __ARGS((char *message, int severity));
void workshop_menu_begin __ARGS((char *label));
void workshop_submenu_begin __ARGS((char *label));
void workshop_submenu_end __ARGS((void));
void workshop_menu_item __ARGS((char *label, char *verb, char *accelerator, char *acceleratorText, char *name, char *filepos, char *sensitive));
void workshop_menu_end __ARGS((void));
void workshop_toolbar_begin __ARGS((void));
void workshop_toolbar_end __ARGS((void));
void workshop_toolbar_button __ARGS((char *label, char *verb, char *senseVerb, char *filepos, char *help, char *sense, char *file, char *left));
void workshop_frame_sensitivities __ARGS((VerbSense *vs));
void workshop_set_option __ARGS((char *option, char *value));
void workshop_balloon_mode __ARGS((Boolean on));
void workshop_balloon_delay __ARGS((int delay));
void workshop_show_balloon_tip __ARGS((char *tip));
void workshop_hotkeys __ARGS((Boolean on));
int workshop_get_positions __ARGS((void *clientData, char **filename, int *curLine, int *curCol, int *selStartLine, int *selStartCol, int *selEndLine, int *selEndCol, int *selLength, char **selection));
char *workshop_test_getcurrentfile __ARGS((void));
int workshop_test_getcursorrow __ARGS((void));
int workshop_test_getcursorcol __ARGS((void));
char *workshop_test_getcursorrowtext __ARGS((void));
char *workshop_test_getselectedtext __ARGS((void));
void workshop_save_sensitivity __ARGS((char *filename));
void workshop_beval_cb __ARGS((BalloonEval *beval, int state));
void findYourself __ARGS((char *argv0));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/workshop.pro | C | gpl2 | 2,848 |
/* netbeans.c */
void netbeans_parse_messages __ARGS((void));
void netbeans_read __ARGS((void));
int isNetbeansBuffer __ARGS((buf_T *bufp));
int isNetbeansModified __ARGS((buf_T *bufp));
void netbeans_end __ARGS((void));
void ex_nbclose __ARGS((exarg_T *eap));
void ex_nbkey __ARGS((exarg_T *eap));
void ex_nbstart __ARGS((exarg_T *eap));
void netbeans_beval_cb __ARGS((BalloonEval *beval, int state));
int netbeans_active __ARGS((void));
int netbeans_filedesc __ARGS((void));
void netbeans_gui_register __ARGS((void));
void netbeans_open __ARGS((char *params, int doabort));
void netbeans_send_disconnect __ARGS((void));
void netbeans_frame_moved __ARGS((int new_x, int new_y));
void netbeans_file_activated __ARGS((buf_T *bufp));
void netbeans_file_opened __ARGS((buf_T *bufp));
void netbeans_file_killed __ARGS((buf_T *bufp));
void netbeans_inserted __ARGS((buf_T *bufp, linenr_T linenr, colnr_T col, char_u *txt, int newlen));
void netbeans_removed __ARGS((buf_T *bufp, linenr_T linenr, colnr_T col, long len));
void netbeans_unmodified __ARGS((buf_T *bufp));
void netbeans_button_release __ARGS((int button));
int netbeans_keycommand __ARGS((int key));
void netbeans_save_buffer __ARGS((buf_T *bufp));
void netbeans_deleted_all_lines __ARGS((buf_T *bufp));
int netbeans_is_guarded __ARGS((linenr_T top, linenr_T bot));
void netbeans_draw_multisign_indicator __ARGS((int row));
void netbeans_gutter_click __ARGS((linenr_T lnum));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/netbeans.pro | C | gpl2 | 1,456 |
/* message.c */
int msg __ARGS((char_u *s));
int verb_msg __ARGS((char_u *s));
int msg_attr __ARGS((char_u *s, int attr));
int msg_attr_keep __ARGS((char_u *s, int attr, int keep));
char_u *msg_strtrunc __ARGS((char_u *s, int force));
void trunc_string __ARGS((char_u *s, char_u *buf, int room, int buflen));
void reset_last_sourcing __ARGS((void));
void msg_source __ARGS((int attr));
int emsg_not_now __ARGS((void));
int emsg __ARGS((char_u *s));
int emsg2 __ARGS((char_u *s, char_u *a1));
void emsg_invreg __ARGS((int name));
char_u *msg_trunc_attr __ARGS((char_u *s, int force, int attr));
char_u *msg_may_trunc __ARGS((int force, char_u *s));
int delete_first_msg __ARGS((void));
void ex_messages __ARGS((exarg_T *eap));
void msg_end_prompt __ARGS((void));
void wait_return __ARGS((int redraw));
void set_keep_msg __ARGS((char_u *s, int attr));
void set_keep_msg_from_hist __ARGS((void));
void msg_start __ARGS((void));
void msg_starthere __ARGS((void));
void msg_putchar __ARGS((int c));
void msg_putchar_attr __ARGS((int c, int attr));
void msg_outnum __ARGS((long n));
void msg_home_replace __ARGS((char_u *fname));
void msg_home_replace_hl __ARGS((char_u *fname));
int msg_outtrans __ARGS((char_u *str));
int msg_outtrans_attr __ARGS((char_u *str, int attr));
int msg_outtrans_len __ARGS((char_u *str, int len));
char_u *msg_outtrans_one __ARGS((char_u *p, int attr));
int msg_outtrans_len_attr __ARGS((char_u *msgstr, int len, int attr));
void msg_make __ARGS((char_u *arg));
int msg_outtrans_special __ARGS((char_u *strstart, int from));
char_u *str2special_save __ARGS((char_u *str, int is_lhs));
char_u *str2special __ARGS((char_u **sp, int from));
void str2specialbuf __ARGS((char_u *sp, char_u *buf, int len));
void msg_prt_line __ARGS((char_u *s, int list));
void msg_puts __ARGS((char_u *s));
void msg_puts_title __ARGS((char_u *s));
void msg_puts_long_attr __ARGS((char_u *longstr, int attr));
void msg_puts_long_len_attr __ARGS((char_u *longstr, int len, int attr));
void msg_puts_attr __ARGS((char_u *s, int attr));
void may_clear_sb_text __ARGS((void));
void clear_sb_text __ARGS((void));
void show_sb_text __ARGS((void));
void msg_sb_eol __ARGS((void));
int msg_use_printf __ARGS((void));
void mch_errmsg __ARGS((char *str));
void mch_msg __ARGS((char *str));
void msg_moremsg __ARGS((int full));
void repeat_message __ARGS((void));
void msg_clr_eos __ARGS((void));
void msg_clr_eos_force __ARGS((void));
void msg_clr_cmdline __ARGS((void));
int msg_end __ARGS((void));
void msg_check __ARGS((void));
int redirecting __ARGS((void));
void verbose_enter __ARGS((void));
void verbose_leave __ARGS((void));
void verbose_enter_scroll __ARGS((void));
void verbose_leave_scroll __ARGS((void));
void verbose_stop __ARGS((void));
int verbose_open __ARGS((void));
void give_warning __ARGS((char_u *message, int hl));
void msg_advance __ARGS((int col));
int do_dialog __ARGS((int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd));
void display_confirm_msg __ARGS((void));
int vim_dialog_yesno __ARGS((int type, char_u *title, char_u *message, int dflt));
int vim_dialog_yesnocancel __ARGS((int type, char_u *title, char_u *message, int dflt));
int vim_dialog_yesnoallcancel __ARGS((int type, char_u *title, char_u *message, int dflt));
char_u *do_browse __ARGS((int flags, char_u *title, char_u *dflt, char_u *ext, char_u *initdir, char_u *filter, buf_T *buf));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/message.pro | C | gpl2 | 3,448 |
/* termlib.c */
int tgetent __ARGS((char *tbuf, char *term));
int tgetflag __ARGS((char *id));
int tgetnum __ARGS((char *id));
char *tgetstr __ARGS((char *id, char **buf));
char *tgoto __ARGS((char *cm, int col, int line));
int tputs __ARGS((char *cp, int affcnt, void (*outc)(unsigned int)));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/termlib.pro | C | gpl2 | 316 |
/* ex_cmds.c */
void do_ascii __ARGS((exarg_T *eap));
void ex_align __ARGS((exarg_T *eap));
void ex_sort __ARGS((exarg_T *eap));
void ex_retab __ARGS((exarg_T *eap));
int do_move __ARGS((linenr_T line1, linenr_T line2, linenr_T dest));
void ex_copy __ARGS((linenr_T line1, linenr_T line2, linenr_T n));
void free_prev_shellcmd __ARGS((void));
void do_bang __ARGS((int addr_count, exarg_T *eap, int forceit, int do_in, int do_out));
void do_shell __ARGS((char_u *cmd, int flags));
char_u *make_filter_cmd __ARGS((char_u *cmd, char_u *itmp, char_u *otmp));
void append_redir __ARGS((char_u *buf, int buflen, char_u *opt, char_u *fname));
int viminfo_error __ARGS((char *errnum, char *message, char_u *line));
int read_viminfo __ARGS((char_u *file, int flags));
void write_viminfo __ARGS((char_u *file, int forceit));
int viminfo_readline __ARGS((vir_T *virp));
char_u *viminfo_readstring __ARGS((vir_T *virp, int off, int convert));
void viminfo_writestring __ARGS((FILE *fd, char_u *p));
void do_fixdel __ARGS((exarg_T *eap));
void print_line_no_prefix __ARGS((linenr_T lnum, int use_number, int list));
void print_line __ARGS((linenr_T lnum, int use_number, int list));
void ex_file __ARGS((exarg_T *eap));
void ex_update __ARGS((exarg_T *eap));
void ex_write __ARGS((exarg_T *eap));
int do_write __ARGS((exarg_T *eap));
int check_overwrite __ARGS((exarg_T *eap, buf_T *buf, char_u *fname, char_u *ffname, int other));
void ex_wnext __ARGS((exarg_T *eap));
void do_wqall __ARGS((exarg_T *eap));
int not_writing __ARGS((void));
int getfile __ARGS((int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum, int forceit));
int do_ecmd __ARGS((int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T newlnum, int flags, win_T *oldwin));
void ex_append __ARGS((exarg_T *eap));
void ex_change __ARGS((exarg_T *eap));
void ex_z __ARGS((exarg_T *eap));
int check_restricted __ARGS((void));
int check_secure __ARGS((void));
void do_sub __ARGS((exarg_T *eap));
int do_sub_msg __ARGS((int count_only));
void ex_global __ARGS((exarg_T *eap));
void global_exe __ARGS((char_u *cmd));
int read_viminfo_sub_string __ARGS((vir_T *virp, int force));
void write_viminfo_sub_string __ARGS((FILE *fp));
void free_old_sub __ARGS((void));
int prepare_tagpreview __ARGS((int undo_sync));
void ex_help __ARGS((exarg_T *eap));
char_u *check_help_lang __ARGS((char_u *arg));
int help_heuristic __ARGS((char_u *matched_string, int offset, int wrong_case));
int find_help_tags __ARGS((char_u *arg, int *num_matches, char_u ***matches, int keep_lang));
void fix_help_buffer __ARGS((void));
void ex_exusage __ARGS((exarg_T *eap));
void ex_viusage __ARGS((exarg_T *eap));
void ex_helptags __ARGS((exarg_T *eap));
void ex_sign __ARGS((exarg_T *eap));
void sign_gui_started __ARGS((void));
int sign_get_attr __ARGS((int typenr, int line));
char_u *sign_get_text __ARGS((int typenr));
void *sign_get_image __ARGS((int typenr));
char_u *sign_typenr2name __ARGS((int typenr));
void free_signs __ARGS((void));
char_u *get_sign_name __ARGS((expand_T *xp, int idx));
void set_context_in_sign_cmd __ARGS((expand_T *xp, char_u *arg));
void ex_drop __ARGS((exarg_T *eap));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/ex_cmds.pro | C | gpl2 | 3,171 |
/* eval.c */
void eval_init __ARGS((void));
void eval_clear __ARGS((void));
char_u *func_name __ARGS((void *cookie));
linenr_T *func_breakpoint __ARGS((void *cookie));
int *func_dbg_tick __ARGS((void *cookie));
int func_level __ARGS((void *cookie));
int current_func_returned __ARGS((void));
void set_internal_string_var __ARGS((char_u *name, char_u *value));
int var_redir_start __ARGS((char_u *name, int append));
void var_redir_str __ARGS((char_u *value, int value_len));
void var_redir_stop __ARGS((void));
int eval_charconvert __ARGS((char_u *enc_from, char_u *enc_to, char_u *fname_from, char_u *fname_to));
int eval_printexpr __ARGS((char_u *fname, char_u *args));
void eval_diff __ARGS((char_u *origfile, char_u *newfile, char_u *outfile));
void eval_patch __ARGS((char_u *origfile, char_u *difffile, char_u *outfile));
int eval_to_bool __ARGS((char_u *arg, int *error, char_u **nextcmd, int skip));
char_u *eval_to_string_skip __ARGS((char_u *arg, char_u **nextcmd, int skip));
int skip_expr __ARGS((char_u **pp));
char_u *eval_to_string __ARGS((char_u *arg, char_u **nextcmd, int convert));
char_u *eval_to_string_safe __ARGS((char_u *arg, char_u **nextcmd, int use_sandbox));
int eval_to_number __ARGS((char_u *expr));
list_T *eval_spell_expr __ARGS((char_u *badword, char_u *expr));
int get_spellword __ARGS((list_T *list, char_u **pp));
typval_T *eval_expr __ARGS((char_u *arg, char_u **nextcmd));
int call_vim_function __ARGS((char_u *func, int argc, char_u **argv, int safe, typval_T *rettv));
void *call_func_retstr __ARGS((char_u *func, int argc, char_u **argv, int safe));
long call_func_retnr __ARGS((char_u *func, int argc, char_u **argv, int safe));
void *call_func_retlist __ARGS((char_u *func, int argc, char_u **argv, int safe));
void *save_funccal __ARGS((void));
void restore_funccal __ARGS((void *vfc));
void prof_child_enter __ARGS((proftime_T *tm));
void prof_child_exit __ARGS((proftime_T *tm));
int eval_foldexpr __ARGS((char_u *arg, int *cp));
void ex_let __ARGS((exarg_T *eap));
void *eval_for_line __ARGS((char_u *arg, int *errp, char_u **nextcmdp, int skip));
int next_for_item __ARGS((void *fi_void, char_u *arg));
void free_for_info __ARGS((void *fi_void));
void set_context_for_expression __ARGS((expand_T *xp, char_u *arg, cmdidx_T cmdidx));
void ex_call __ARGS((exarg_T *eap));
void ex_unlet __ARGS((exarg_T *eap));
void ex_lockvar __ARGS((exarg_T *eap));
int do_unlet __ARGS((char_u *name, int forceit));
void del_menutrans_vars __ARGS((void));
char_u *get_user_var_name __ARGS((expand_T *xp, int idx));
list_T *list_alloc __ARGS((void));
void list_unref __ARGS((list_T *l));
void list_free __ARGS((list_T *l, int recurse));
dictitem_T *dict_lookup __ARGS((hashitem_T *hi));
char_u *list_find_str __ARGS((list_T *l, long idx));
int list_append_tv __ARGS((list_T *l, typval_T *tv));
int list_append_dict __ARGS((list_T *list, dict_T *dict));
int list_append_string __ARGS((list_T *l, char_u *str, int len));
int garbage_collect __ARGS((void));
dict_T *dict_alloc __ARGS((void));
void dict_unref __ARGS((dict_T *d));
dictitem_T *dictitem_alloc __ARGS((char_u *key));
void dictitem_free __ARGS((dictitem_T *item));
int dict_add __ARGS((dict_T *d, dictitem_T *item));
int dict_add_nr_str __ARGS((dict_T *d, char *key, long nr, char_u *str));
int dict_add_list __ARGS((dict_T *d, char *key, list_T *list));
dictitem_T *dict_find __ARGS((dict_T *d, char_u *key, int len));
char_u *get_dict_string __ARGS((dict_T *d, char_u *key, int save));
long get_dict_number __ARGS((dict_T *d, char_u *key));
char_u *get_function_name __ARGS((expand_T *xp, int idx));
char_u *get_expr_name __ARGS((expand_T *xp, int idx));
long do_searchpair __ARGS((char_u *spat, char_u *mpat, char_u *epat, int dir, char_u *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit));
void set_vim_var_nr __ARGS((int idx, long val));
long get_vim_var_nr __ARGS((int idx));
char_u *get_vim_var_str __ARGS((int idx));
list_T *get_vim_var_list __ARGS((int idx));
void set_vim_var_char __ARGS((int c));
void set_vcount __ARGS((long count, long count1, int set_prevcount));
void set_vim_var_string __ARGS((int idx, char_u *val, int len));
void set_vim_var_list __ARGS((int idx, list_T *val));
void set_reg_var __ARGS((int c));
char_u *v_exception __ARGS((char_u *oldval));
char_u *v_throwpoint __ARGS((char_u *oldval));
char_u *set_cmdarg __ARGS((exarg_T *eap, char_u *oldarg));
void free_tv __ARGS((typval_T *varp));
void clear_tv __ARGS((typval_T *varp));
long get_tv_number_chk __ARGS((typval_T *varp, int *denote));
char_u *get_tv_string_chk __ARGS((typval_T *varp));
char_u *get_var_value __ARGS((char_u *name));
void new_script_vars __ARGS((scid_T id));
void init_var_dict __ARGS((dict_T *dict, dictitem_T *dict_var));
void vars_clear __ARGS((hashtab_T *ht));
void copy_tv __ARGS((typval_T *from, typval_T *to));
void ex_echo __ARGS((exarg_T *eap));
void ex_echohl __ARGS((exarg_T *eap));
void ex_execute __ARGS((exarg_T *eap));
void ex_function __ARGS((exarg_T *eap));
void free_all_functions __ARGS((void));
void func_dump_profile __ARGS((FILE *fd));
char_u *get_user_func_name __ARGS((expand_T *xp, int idx));
void ex_delfunction __ARGS((exarg_T *eap));
void ex_return __ARGS((exarg_T *eap));
int do_return __ARGS((exarg_T *eap, int reanimate, int is_cmd, void *rettv));
void discard_pending_return __ARGS((void *rettv));
char_u *get_return_cmd __ARGS((void *rettv));
char_u *get_func_line __ARGS((int c, void *cookie, int indent));
void func_line_start __ARGS((void *cookie));
void func_line_exec __ARGS((void *cookie));
void func_line_end __ARGS((void *cookie));
int func_has_ended __ARGS((void *cookie));
int func_has_abort __ARGS((void *cookie));
int read_viminfo_varlist __ARGS((vir_T *virp, int writing));
void write_viminfo_varlist __ARGS((FILE *fp));
int store_session_globals __ARGS((FILE *fd));
void last_set_msg __ARGS((scid_T scriptID));
void ex_oldfiles __ARGS((exarg_T *eap));
int modify_fname __ARGS((char_u *src, int *usedlen, char_u **fnamep, char_u **bufp, int *fnamelen));
char_u *do_string_sub __ARGS((char_u *str, char_u *pat, char_u *sub, char_u *flags));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/eval.pro | C | gpl2 | 6,124 |
/* mark.c */
int setmark __ARGS((int c));
int setmark_pos __ARGS((int c, pos_T *pos, int fnum));
void setpcmark __ARGS((void));
void checkpcmark __ARGS((void));
pos_T *movemark __ARGS((int count));
pos_T *movechangelist __ARGS((int count));
pos_T *getmark __ARGS((int c, int changefile));
pos_T *getmark_fnum __ARGS((int c, int changefile, int *fnum));
pos_T *getnextmark __ARGS((pos_T *startpos, int dir, int begin_line));
void fmarks_check_names __ARGS((buf_T *buf));
int check_mark __ARGS((pos_T *pos));
void clrallmarks __ARGS((buf_T *buf));
char_u *fm_getname __ARGS((fmark_T *fmark, int lead_len));
void do_marks __ARGS((exarg_T *eap));
void ex_delmarks __ARGS((exarg_T *eap));
void ex_jumps __ARGS((exarg_T *eap));
void ex_changes __ARGS((exarg_T *eap));
void mark_adjust __ARGS((linenr_T line1, linenr_T line2, long amount, long amount_after));
void mark_col_adjust __ARGS((linenr_T lnum, colnr_T mincol, long lnum_amount, long col_amount));
void copy_jumplist __ARGS((win_T *from, win_T *to));
void free_jumplist __ARGS((win_T *wp));
void set_last_cursor __ARGS((win_T *win));
void free_all_marks __ARGS((void));
int read_viminfo_filemark __ARGS((vir_T *virp, int force));
void write_viminfo_filemarks __ARGS((FILE *fp));
int removable __ARGS((char_u *name));
int write_viminfo_marks __ARGS((FILE *fp_out));
void copy_viminfo_marks __ARGS((vir_T *virp, FILE *fp_out, int count, int eof, int flags));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/mark.pro | C | gpl2 | 1,431 |
/* hashtab.c */
void hash_init __ARGS((hashtab_T *ht));
void hash_clear __ARGS((hashtab_T *ht));
void hash_clear_all __ARGS((hashtab_T *ht, int off));
hashitem_T *hash_find __ARGS((hashtab_T *ht, char_u *key));
hashitem_T *hash_lookup __ARGS((hashtab_T *ht, char_u *key, hash_T hash));
void hash_debug_results __ARGS((void));
int hash_add __ARGS((hashtab_T *ht, char_u *key));
int hash_add_item __ARGS((hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash));
void hash_remove __ARGS((hashtab_T *ht, hashitem_T *hi));
void hash_lock __ARGS((hashtab_T *ht));
void hash_unlock __ARGS((hashtab_T *ht));
hash_T hash_hash __ARGS((char_u *key));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/hashtab.pro | C | gpl2 | 664 |
/* ex_getln.c */
char_u *getcmdline __ARGS((int firstc, long count, int indent));
char_u *getcmdline_prompt __ARGS((int firstc, char_u *prompt, int attr, int xp_context, char_u *xp_arg));
int text_locked __ARGS((void));
void text_locked_msg __ARGS((void));
int curbuf_locked __ARGS((void));
int allbuf_locked __ARGS((void));
char_u *getexline __ARGS((int c, void *cookie, int indent));
char_u *getexmodeline __ARGS((int promptc, void *cookie, int indent));
int cmdline_overstrike __ARGS((void));
int cmdline_at_end __ARGS((void));
colnr_T cmdline_getvcol_cursor __ARGS((void));
void free_cmdline_buf __ARGS((void));
void putcmdline __ARGS((int c, int shift));
void unputcmdline __ARGS((void));
int put_on_cmdline __ARGS((char_u *str, int len, int redraw));
char_u *save_cmdline_alloc __ARGS((void));
void restore_cmdline_alloc __ARGS((char_u *p));
void cmdline_paste_str __ARGS((char_u *s, int literally));
void redrawcmdline __ARGS((void));
void redrawcmd __ARGS((void));
void compute_cmdrow __ARGS((void));
void gotocmdline __ARGS((int clr));
char_u *ExpandOne __ARGS((expand_T *xp, char_u *str, char_u *orig, int options, int mode));
void ExpandInit __ARGS((expand_T *xp));
void ExpandCleanup __ARGS((expand_T *xp));
void ExpandEscape __ARGS((expand_T *xp, char_u *str, int numfiles, char_u **files, int options));
char_u *vim_strsave_fnameescape __ARGS((char_u *fname, int shell));
void tilde_replace __ARGS((char_u *orig_pat, int num_files, char_u **files));
char_u *sm_gettail __ARGS((char_u *s));
char_u *addstar __ARGS((char_u *fname, int len, int context));
void set_cmd_context __ARGS((expand_T *xp, char_u *str, int len, int col));
int expand_cmdline __ARGS((expand_T *xp, char_u *str, int col, int *matchcount, char_u ***matches));
int ExpandGeneric __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int)), int escaped));
char_u *globpath __ARGS((char_u *path, char_u *file, int expand_options));
void init_history __ARGS((void));
int get_histtype __ARGS((char_u *name));
void add_to_history __ARGS((int histype, char_u *new_entry, int in_map, int sep));
int get_history_idx __ARGS((int histype));
char_u *get_cmdline_str __ARGS((void));
int get_cmdline_pos __ARGS((void));
int set_cmdline_pos __ARGS((int pos));
int get_cmdline_type __ARGS((void));
char_u *get_history_entry __ARGS((int histype, int idx));
int clr_history __ARGS((int histype));
int del_history_entry __ARGS((int histype, char_u *str));
int del_history_idx __ARGS((int histype, int idx));
void remove_key_from_history __ARGS((void));
int get_list_range __ARGS((char_u **str, int *num1, int *num2));
void ex_history __ARGS((exarg_T *eap));
void prepare_viminfo_history __ARGS((int asklen));
int read_viminfo_history __ARGS((vir_T *virp));
void finish_viminfo_history __ARGS((void));
void write_viminfo_history __ARGS((FILE *fp));
void cmd_pchar __ARGS((int c, int offset));
int cmd_gchar __ARGS((int offset));
char_u *script_get __ARGS((exarg_T *eap, char_u *cmd));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/ex_getln.pro | C | gpl2 | 3,021 |
/* gui_photon.c */
void gui_ph_encoding_changed __ARGS((int new_encoding));
void gui_mch_prepare __ARGS((int *argc, char **argv));
int gui_mch_init __ARGS((void));
int gui_mch_init_check __ARGS((void));
int gui_mch_open __ARGS((void));
void gui_mch_exit __ARGS((int rc));
void gui_mch_update __ARGS((void));
int gui_mch_wait_for_chars __ARGS((int wtime));
char_u *gui_mch_browse __ARGS((int saving, char_u *title, char_u *default_name, char_u *ext, char_u *initdir, char_u *filter));
int gui_mch_dialog __ARGS((int type, char_u *title, char_u *message, char_u *buttons, int default_button, char_u *textfield, int ex_cmd));
int gui_mch_get_winpos __ARGS((int *x, int *y));
void gui_mch_set_winpos __ARGS((int x, int y));
void gui_mch_set_shellsize __ARGS((int width, int height, int min_width, int min_height, int base_width, int base_height, int direction));
void gui_mch_get_screen_dimensions __ARGS((int *screen_w, int *screen_h));
void gui_mch_iconify __ARGS((void));
void gui_mch_set_foreground __ARGS((void));
void gui_mch_settitle __ARGS((char_u *title, char_u *icon));
void gui_mch_set_scrollbar_thumb __ARGS((scrollbar_T *sb, int val, int size, int max));
void gui_mch_set_scrollbar_pos __ARGS((scrollbar_T *sb, int x, int y, int w, int h));
void gui_mch_create_scrollbar __ARGS((scrollbar_T *sb, int orient));
void gui_mch_enable_scrollbar __ARGS((scrollbar_T *sb, int flag));
void gui_mch_destroy_scrollbar __ARGS((scrollbar_T *sb));
void mch_set_mouse_shape __ARGS((int shape));
void gui_mch_mousehide __ARGS((int hide));
void gui_mch_getmouse __ARGS((int *x, int *y));
void gui_mch_setmouse __ARGS((int x, int y));
long_u gui_mch_get_rgb __ARGS((guicolor_T pixel));
void gui_mch_new_colors __ARGS((void));
guicolor_T gui_mch_get_color __ARGS((char_u *name));
void gui_mch_set_fg_color __ARGS((guicolor_T color));
void gui_mch_set_bg_color __ARGS((guicolor_T color));
void gui_mch_set_sp_color __ARGS((guicolor_T color));
void gui_mch_invert_rectangle __ARGS((int row, int col, int nr, int nc));
void gui_mch_clear_block __ARGS((int row1, int col1, int row2, int col2));
void gui_mch_clear_all __ARGS((void));
void gui_mch_delete_lines __ARGS((int row, int num_lines));
void gui_mch_insert_lines __ARGS((int row, int num_lines));
void gui_mch_draw_string __ARGS((int row, int col, char_u *s, int len, int flags));
void gui_mch_draw_hollow_cursor __ARGS((guicolor_T color));
void gui_mch_draw_part_cursor __ARGS((int w, int h, guicolor_T color));
void gui_mch_set_blinking __ARGS((long wait, long on, long off));
void gui_mch_start_blink __ARGS((void));
void gui_mch_stop_blink __ARGS((void));
void gui_mch_beep __ARGS((void));
void gui_mch_flash __ARGS((int msec));
void gui_mch_flush __ARGS((void));
void gui_mch_set_text_area_pos __ARGS((int x, int y, int w, int h));
int gui_mch_haskey __ARGS((char_u *name));
void gui_mch_enable_menu __ARGS((int flag));
void gui_mch_set_menu_pos __ARGS((int x, int y, int w, int h));
void gui_mch_add_menu __ARGS((vimmenu_T *menu, int index));
void gui_mch_add_menu_item __ARGS((vimmenu_T *menu, int index));
void gui_mch_destroy_menu __ARGS((vimmenu_T *menu));
void gui_mch_menu_grey __ARGS((vimmenu_T *menu, int grey));
void gui_mch_menu_hidden __ARGS((vimmenu_T *menu, int hidden));
void gui_mch_draw_menubar __ARGS((void));
void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu));
void gui_mch_toggle_tearoffs __ARGS((int enable));
void gui_mch_show_toolbar __ARGS((int showit));
int gui_mch_init_font __ARGS((char_u *vim_font_name, int fontset));
int gui_mch_adjust_charheight __ARGS((void));
GuiFont gui_mch_get_font __ARGS((char_u *vim_font_name, int report_error));
char_u *gui_mch_get_fontname __ARGS((GuiFont font, char_u *name));
void gui_mch_set_font __ARGS((GuiFont font));
void gui_mch_free_font __ARGS((GuiFont font));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_photon.pro | C | gpl2 | 3,803 |
/* tag.c */
int do_tag __ARGS((char_u *tag, int type, int count, int forceit, int verbose));
void tag_freematch __ARGS((void));
void do_tags __ARGS((exarg_T *eap));
int find_tags __ARGS((char_u *pat, int *num_matches, char_u ***matchesp, int flags, int mincount, char_u *buf_ffname));
void free_tag_stuff __ARGS((void));
int get_tagfname __ARGS((tagname_T *tnp, int first, char_u *buf));
void tagname_free __ARGS((tagname_T *tnp));
void simplify_filename __ARGS((char_u *filename));
int expand_tags __ARGS((int tagnames, char_u *pat, int *num_file, char_u ***file));
int get_tags __ARGS((list_T *list, char_u *pat));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/tag.pro | C | gpl2 | 639 |
/* screen.c */
void redraw_later __ARGS((int type));
void redraw_win_later __ARGS((win_T *wp, int type));
void redraw_later_clear __ARGS((void));
void redraw_all_later __ARGS((int type));
void redraw_curbuf_later __ARGS((int type));
void redraw_buf_later __ARGS((buf_T *buf, int type));
void redrawWinline __ARGS((linenr_T lnum, int invalid));
void update_curbuf __ARGS((int type));
void update_screen __ARGS((int type));
int conceal_cursor_line __ARGS((win_T *wp));
void conceal_check_cursur_line __ARGS((void));
void update_single_line __ARGS((win_T *wp, linenr_T lnum));
void update_debug_sign __ARGS((buf_T *buf, linenr_T lnum));
void updateWindow __ARGS((win_T *wp));
void rl_mirror __ARGS((char_u *str));
void status_redraw_all __ARGS((void));
void status_redraw_curbuf __ARGS((void));
void redraw_statuslines __ARGS((void));
void win_redraw_last_status __ARGS((frame_T *frp));
void win_redr_status_matches __ARGS((expand_T *xp, int num_matches, char_u **matches, int match, int showtail));
void win_redr_status __ARGS((win_T *wp));
int stl_connected __ARGS((win_T *wp));
int get_keymap_str __ARGS((win_T *wp, char_u *buf, int len));
void screen_putchar __ARGS((int c, int row, int col, int attr));
void screen_getbytes __ARGS((int row, int col, char_u *bytes, int *attrp));
void screen_puts __ARGS((char_u *text, int row, int col, int attr));
void screen_puts_len __ARGS((char_u *text, int len, int row, int col, int attr));
void screen_stop_highlight __ARGS((void));
void reset_cterm_colors __ARGS((void));
void screen_draw_rectangle __ARGS((int row, int col, int height, int width, int invert));
void screen_fill __ARGS((int start_row, int end_row, int start_col, int end_col, int c1, int c2, int attr));
void check_for_delay __ARGS((int check_msg_scroll));
int screen_valid __ARGS((int clear));
void screenalloc __ARGS((int clear));
void free_screenlines __ARGS((void));
void screenclear __ARGS((void));
int can_clear __ARGS((char_u *p));
void screen_start __ARGS((void));
void windgoto __ARGS((int row, int col));
void setcursor __ARGS((void));
int win_ins_lines __ARGS((win_T *wp, int row, int line_count, int invalid, int mayclear));
int win_del_lines __ARGS((win_T *wp, int row, int line_count, int invalid, int mayclear));
int screen_ins_lines __ARGS((int off, int row, int line_count, int end, win_T *wp));
int screen_del_lines __ARGS((int off, int row, int line_count, int end, int force, win_T *wp));
int showmode __ARGS((void));
void unshowmode __ARGS((int force));
void get_trans_bufname __ARGS((buf_T *buf));
int redrawing __ARGS((void));
int messaging __ARGS((void));
void showruler __ARGS((int always));
int number_width __ARGS((win_T *wp));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/screen.pro | C | gpl2 | 2,687 |
/* gui.c */
void gui_start __ARGS((void));
void gui_prepare __ARGS((int *argc, char **argv));
int gui_init_check __ARGS((void));
void gui_init __ARGS((void));
void gui_exit __ARGS((int rc));
void gui_shell_closed __ARGS((void));
int gui_init_font __ARGS((char_u *font_list, int fontset));
int gui_get_wide_font __ARGS((void));
void gui_set_cursor __ARGS((int row, int col));
void gui_update_cursor __ARGS((int force, int clear_selection));
void gui_position_menu __ARGS((void));
int gui_get_base_width __ARGS((void));
int gui_get_base_height __ARGS((void));
void gui_resize_shell __ARGS((int pixel_width, int pixel_height));
void gui_may_resize_shell __ARGS((void));
int gui_get_shellsize __ARGS((void));
void gui_set_shellsize __ARGS((int mustset, int fit_to_display, int direction));
void gui_new_shellsize __ARGS((void));
void gui_reset_scroll_region __ARGS((void));
void gui_start_highlight __ARGS((int mask));
void gui_stop_highlight __ARGS((int mask));
void gui_clear_block __ARGS((int row1, int col1, int row2, int col2));
void gui_update_cursor_later __ARGS((void));
void gui_write __ARGS((char_u *s, int len));
void gui_dont_update_cursor __ARGS((void));
void gui_can_update_cursor __ARGS((void));
int gui_outstr_nowrap __ARGS((char_u *s, int len, int flags, guicolor_T fg, guicolor_T bg, int back));
void gui_undraw_cursor __ARGS((void));
void gui_redraw __ARGS((int x, int y, int w, int h));
int gui_redraw_block __ARGS((int row1, int col1, int row2, int col2, int flags));
int gui_wait_for_chars __ARGS((long wtime));
void gui_send_mouse_event __ARGS((int button, int x, int y, int repeated_click, int_u modifiers));
int gui_xy2colrow __ARGS((int x, int y, int *colp));
void gui_menu_cb __ARGS((vimmenu_T *menu));
void gui_init_which_components __ARGS((char_u *oldval));
int gui_use_tabline __ARGS((void));
void gui_update_tabline __ARGS((void));
void get_tabline_label __ARGS((tabpage_T *tp, int tooltip));
int send_tabline_event __ARGS((int nr));
void send_tabline_menu_event __ARGS((int tabidx, int event));
void gui_remove_scrollbars __ARGS((void));
void gui_create_scrollbar __ARGS((scrollbar_T *sb, int type, win_T *wp));
scrollbar_T *gui_find_scrollbar __ARGS((long ident));
void gui_drag_scrollbar __ARGS((scrollbar_T *sb, long value, int still_dragging));
void gui_may_update_scrollbars __ARGS((void));
void gui_update_scrollbars __ARGS((int force));
int gui_do_scroll __ARGS((void));
int gui_do_horiz_scroll __ARGS((long_u leftcol, int compute_longest_lnum));
void gui_check_colors __ARGS((void));
guicolor_T gui_get_color __ARGS((char_u *name));
int gui_get_lightness __ARGS((guicolor_T pixel));
void gui_new_scrollbar_colors __ARGS((void));
void gui_focus_change __ARGS((int in_focus));
void gui_mouse_moved __ARGS((int x, int y));
void gui_mouse_correct __ARGS((void));
void ex_gui __ARGS((exarg_T *eap));
int gui_find_bitmap __ARGS((char_u *name, char_u *buffer, char *ext));
void gui_find_iconfile __ARGS((char_u *name, char_u *buffer, char *ext));
void display_errors __ARGS((void));
int no_console_input __ARGS((void));
void gui_update_screen __ARGS((void));
char_u *get_find_dialog_text __ARGS((char_u *arg, int *wwordp, int *mcasep));
int gui_do_findrepl __ARGS((int flags, char_u *find_text, char_u *repl_text, int down));
void gui_handle_drop __ARGS((int x, int y, int_u modifiers, char_u **fnames, int count));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui.pro | C | gpl2 | 3,367 |
/* charset.c */
int init_chartab __ARGS((void));
int buf_init_chartab __ARGS((buf_T *buf, int global));
void trans_characters __ARGS((char_u *buf, int bufsize));
char_u *transstr __ARGS((char_u *s));
char_u *str_foldcase __ARGS((char_u *str, int orglen, char_u *buf, int buflen));
char_u *transchar __ARGS((int c));
char_u *transchar_byte __ARGS((int c));
void transchar_nonprint __ARGS((char_u *buf, int c));
void transchar_hex __ARGS((char_u *buf, int c));
int byte2cells __ARGS((int b));
int char2cells __ARGS((int c));
int ptr2cells __ARGS((char_u *p));
int vim_strsize __ARGS((char_u *s));
int vim_strnsize __ARGS((char_u *s, int len));
int chartabsize __ARGS((char_u *p, colnr_T col));
int linetabsize __ARGS((char_u *s));
int linetabsize_col __ARGS((int startcol, char_u *s));
int win_linetabsize __ARGS((win_T *wp, char_u *p, colnr_T len));
int vim_isIDc __ARGS((int c));
int vim_iswordc __ARGS((int c));
int vim_iswordp __ARGS((char_u *p));
int vim_iswordc_buf __ARGS((char_u *p, buf_T *buf));
int vim_isfilec __ARGS((int c));
int vim_isfilec_or_wc __ARGS((int c));
int vim_isprintc __ARGS((int c));
int vim_isprintc_strict __ARGS((int c));
int lbr_chartabsize __ARGS((unsigned char *s, colnr_T col));
int lbr_chartabsize_adv __ARGS((char_u **s, colnr_T col));
int win_lbr_chartabsize __ARGS((win_T *wp, char_u *s, colnr_T col, int *headp));
int in_win_border __ARGS((win_T *wp, colnr_T vcol));
void getvcol __ARGS((win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end));
colnr_T getvcol_nolist __ARGS((pos_T *posp));
void getvvcol __ARGS((win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end));
void getvcols __ARGS((win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, colnr_T *right));
char_u *skipwhite __ARGS((char_u *q));
char_u *skipdigits __ARGS((char_u *q));
char_u *skiphex __ARGS((char_u *q));
char_u *skiptodigit __ARGS((char_u *q));
char_u *skiptohex __ARGS((char_u *q));
int vim_isdigit __ARGS((int c));
int vim_isxdigit __ARGS((int c));
int vim_islower __ARGS((int c));
int vim_isupper __ARGS((int c));
int vim_toupper __ARGS((int c));
int vim_tolower __ARGS((int c));
char_u *skiptowhite __ARGS((char_u *p));
char_u *skiptowhite_esc __ARGS((char_u *p));
long getdigits __ARGS((char_u **pp));
int vim_isblankline __ARGS((char_u *lbuf));
void vim_str2nr __ARGS((char_u *start, int *hexp, int *len, int dooct, int dohex, long *nptr, unsigned long *unptr));
int hex2nr __ARGS((int c));
int hexhex2nr __ARGS((char_u *p));
int rem_backslash __ARGS((char_u *str));
void backslash_halve __ARGS((char_u *p));
char_u *backslash_halve_save __ARGS((char_u *p));
void ebcdic2ascii __ARGS((char_u *buffer, int len));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/charset.pro | C | gpl2 | 2,681 |
/* gui_xmdlg.c */
char_u *gui_xm_select_font __ARGS((char_u *current));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_xmdlg.pro | C | gpl2 | 94 |
/* fileio.c */
void filemess __ARGS((buf_T *buf, char_u *name, char_u *s, int attr));
int readfile __ARGS((char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_skip, linenr_T lines_to_read, exarg_T *eap, int flags));
int prep_exarg __ARGS((exarg_T *eap, buf_T *buf));
int prepare_crypt_read __ARGS((FILE *fp));
char_u *prepare_crypt_write __ARGS((buf_T *buf, int *lenp));
int check_file_readonly __ARGS((char_u *fname, int perm));
int buf_write __ARGS((buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, int filtering));
void msg_add_fname __ARGS((buf_T *buf, char_u *fname));
void msg_add_lines __ARGS((int insert_space, long lnum, off_t nchars));
char_u *shorten_fname1 __ARGS((char_u *full_path));
char_u *shorten_fname __ARGS((char_u *full_path, char_u *dir_name));
void shorten_fnames __ARGS((int force));
void shorten_filenames __ARGS((char_u **fnames, int count));
char_u *modname __ARGS((char_u *fname, char_u *ext, int prepend_dot));
char_u *buf_modname __ARGS((int shortname, char_u *fname, char_u *ext, int prepend_dot));
int vim_fgets __ARGS((char_u *buf, int size, FILE *fp));
int tag_fgets __ARGS((char_u *buf, int size, FILE *fp));
int vim_rename __ARGS((char_u *from, char_u *to));
int check_timestamps __ARGS((int focus));
int buf_check_timestamp __ARGS((buf_T *buf, int focus));
void buf_reload __ARGS((buf_T *buf, int orig_mode));
void buf_store_time __ARGS((buf_T *buf, struct stat *st, char_u *fname));
void write_lnum_adjust __ARGS((linenr_T offset));
void vim_deltempdir __ARGS((void));
char_u *vim_tempname __ARGS((int extra_char));
void forward_slash __ARGS((char_u *fname));
void aubuflocal_remove __ARGS((buf_T *buf));
int au_has_group __ARGS((char_u *name));
void do_augroup __ARGS((char_u *arg, int del_group));
void free_all_autocmds __ARGS((void));
int check_ei __ARGS((void));
char_u *au_event_disable __ARGS((char *what));
void au_event_restore __ARGS((char_u *old_ei));
void do_autocmd __ARGS((char_u *arg, int forceit));
int do_doautocmd __ARGS((char_u *arg, int do_msg));
void ex_doautoall __ARGS((exarg_T *eap));
int check_nomodeline __ARGS((char_u **argp));
void aucmd_prepbuf __ARGS((aco_save_T *aco, buf_T *buf));
void aucmd_restbuf __ARGS((aco_save_T *aco));
int apply_autocmds __ARGS((event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf));
int apply_autocmds_retval __ARGS((event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, int *retval));
int has_cursorhold __ARGS((void));
int trigger_cursorhold __ARGS((void));
int has_cursormoved __ARGS((void));
int has_cursormovedI __ARGS((void));
int has_insertcharpre __ARGS((void));
void block_autocmds __ARGS((void));
void unblock_autocmds __ARGS((void));
int has_autocmd __ARGS((event_T event, char_u *sfname, buf_T *buf));
char_u *get_augroup_name __ARGS((expand_T *xp, int idx));
char_u *set_context_in_autocmd __ARGS((expand_T *xp, char_u *arg, int doautocmd));
char_u *get_event_name __ARGS((expand_T *xp, int idx));
int autocmd_supported __ARGS((char_u *name));
int au_exists __ARGS((char_u *arg));
int match_file_pat __ARGS((char_u *pattern, regprog_T *prog, char_u *fname, char_u *sfname, char_u *tail, int allow_dirs));
int match_file_list __ARGS((char_u *list, char_u *sfname, char_u *ffname));
char_u *file_pat_to_reg_pat __ARGS((char_u *pat, char_u *pat_end, char *allow_dirs, int no_bslash));
long read_eintr __ARGS((int fd, void *buf, size_t bufsize));
long write_eintr __ARGS((int fd, void *buf, size_t bufsize));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/fileio.pro | C | gpl2 | 3,565 |
/* edit.c */
int edit __ARGS((int cmdchar, int startln, long count));
void edit_putchar __ARGS((int c, int highlight));
void edit_unputchar __ARGS((void));
void display_dollar __ARGS((colnr_T col));
void change_indent __ARGS((int type, int amount, int round, int replaced, int call_changed_bytes));
void truncate_spaces __ARGS((char_u *line));
void backspace_until_column __ARGS((int col));
int vim_is_ctrl_x_key __ARGS((int c));
int ins_compl_add_infercase __ARGS((char_u *str, int len, int icase, char_u *fname, int dir, int flags));
void set_completion __ARGS((colnr_T startcol, list_T *list));
void ins_compl_show_pum __ARGS((void));
char_u *find_word_start __ARGS((char_u *ptr));
char_u *find_word_end __ARGS((char_u *ptr));
int ins_compl_active __ARGS((void));
int ins_compl_add_tv __ARGS((typval_T *tv, int dir));
void ins_compl_check_keys __ARGS((int frequency));
int get_literal __ARGS((void));
void insertchar __ARGS((int c, int flags, int second_indent));
void auto_format __ARGS((int trailblank, int prev_line));
int comp_textwidth __ARGS((int ff));
int stop_arrow __ARGS((void));
void set_last_insert __ARGS((int c));
void free_last_insert __ARGS((void));
char_u *add_char2buf __ARGS((int c, char_u *s));
void beginline __ARGS((int flags));
int oneright __ARGS((void));
int oneleft __ARGS((void));
int cursor_up __ARGS((long n, int upd_topline));
int cursor_down __ARGS((long n, int upd_topline));
int stuff_inserted __ARGS((int c, long count, int no_esc));
char_u *get_last_insert __ARGS((void));
char_u *get_last_insert_save __ARGS((void));
void replace_push __ARGS((int c));
int replace_push_mb __ARGS((char_u *p));
void fixthisline __ARGS((int (*get_the_indent)(void)));
void fix_indent __ARGS((void));
int in_cinkeys __ARGS((int keytyped, int when, int line_is_empty));
int hkmap __ARGS((int c));
void ins_scroll __ARGS((void));
void ins_horscroll __ARGS((void));
int ins_copychar __ARGS((linenr_T lnum));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/edit.pro | C | gpl2 | 1,946 |
/* term.c */
int set_termname __ARGS((char_u *term));
void set_mouse_termcode __ARGS((int n, char_u *s));
void del_mouse_termcode __ARGS((int n));
void getlinecol __ARGS((long *cp, long *rp));
int add_termcap_entry __ARGS((char_u *name, int force));
int term_is_8bit __ARGS((char_u *name));
int term_is_gui __ARGS((char_u *name));
char_u *tltoa __ARGS((unsigned long i));
void termcapinit __ARGS((char_u *name));
void out_flush __ARGS((void));
void out_flush_check __ARGS((void));
void out_trash __ARGS((void));
void out_char __ARGS((unsigned c));
void out_str_nf __ARGS((char_u *s));
void out_str __ARGS((char_u *s));
void term_windgoto __ARGS((int row, int col));
void term_cursor_right __ARGS((int i));
void term_append_lines __ARGS((int line_count));
void term_delete_lines __ARGS((int line_count));
void term_set_winpos __ARGS((int x, int y));
void term_set_winsize __ARGS((int width, int height));
void term_fg_color __ARGS((int n));
void term_bg_color __ARGS((int n));
void term_settitle __ARGS((char_u *title));
void ttest __ARGS((int pairs));
void add_long_to_buf __ARGS((long_u val, char_u *dst));
void check_shellsize __ARGS((void));
void win_new_shellsize __ARGS((void));
void shell_resized __ARGS((void));
void shell_resized_check __ARGS((void));
void set_shellsize __ARGS((int width, int height, int mustset));
void settmode __ARGS((int tmode));
void starttermcap __ARGS((void));
void stoptermcap __ARGS((void));
void may_req_termresponse __ARGS((void));
int swapping_screen __ARGS((void));
void setmouse __ARGS((void));
int mouse_has __ARGS((int c));
int mouse_model_popup __ARGS((void));
void scroll_start __ARGS((void));
void cursor_on __ARGS((void));
void cursor_off __ARGS((void));
void term_cursor_shape __ARGS((void));
void scroll_region_set __ARGS((win_T *wp, int off));
void scroll_region_reset __ARGS((void));
void clear_termcodes __ARGS((void));
void add_termcode __ARGS((char_u *name, char_u *string, int flags));
char_u *find_termcode __ARGS((char_u *name));
char_u *get_termcode __ARGS((int i));
void del_termcode __ARGS((char_u *name));
void set_mouse_topline __ARGS((win_T *wp));
int check_termcode __ARGS((int max_offset, char_u *buf, int bufsize, int *buflen));
char_u *replace_termcodes __ARGS((char_u *from, char_u **bufp, int from_part, int do_lt, int special));
int find_term_bykeys __ARGS((char_u *src));
void show_termcodes __ARGS((void));
int show_one_termcode __ARGS((char_u *name, char_u *code, int printit));
char_u *translate_mapping __ARGS((char_u *str, int expmap));
void update_tcap __ARGS((int attr));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/term.pro | C | gpl2 | 2,571 |
/* gui_w16.c */
void gui_mch_set_blinking __ARGS((long wait, long on, long off));
void gui_mch_stop_blink __ARGS((void));
void gui_mch_start_blink __ARGS((void));
LRESULT WINAPI vim_WindowProc __ARGS((HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam));
void gui_mch_new_colors __ARGS((void));
void gui_mch_def_colors __ARGS((void));
int gui_mch_open __ARGS((void));
int gui_mch_get_winpos __ARGS((int *x, int *y));
void gui_mch_set_winpos __ARGS((int x, int y));
void gui_mch_set_text_area_pos __ARGS((int x, int y, int w, int h));
void gui_mch_enable_scrollbar __ARGS((scrollbar_T *sb, int flag));
void gui_mch_set_scrollbar_pos __ARGS((scrollbar_T *sb, int x, int y, int w, int h));
void gui_mch_create_scrollbar __ARGS((scrollbar_T *sb, int orient));
int gui_mch_adjust_charheight __ARGS((void));
GuiFont gui_mch_get_font __ARGS((char_u *name, int giveErrorIfMissing));
char_u *gui_mch_get_fontname __ARGS((GuiFont font, char_u *name));
void gui_mch_free_font __ARGS((GuiFont font));
guicolor_T gui_mch_get_color __ARGS((char_u *name));
int gui_mch_haskey __ARGS((char_u *name));
void gui_mch_beep __ARGS((void));
void gui_mch_invert_rectangle __ARGS((int r, int c, int nr, int nc));
void gui_mch_iconify __ARGS((void));
void gui_mch_draw_hollow_cursor __ARGS((guicolor_T color));
void gui_mch_draw_part_cursor __ARGS((int w, int h, guicolor_T color));
void gui_mch_update __ARGS((void));
int gui_mch_wait_for_chars __ARGS((int wtime));
void gui_mch_clear_block __ARGS((int row1, int col1, int row2, int col2));
void gui_mch_clear_all __ARGS((void));
void gui_mch_enable_menu __ARGS((int flag));
void gui_mch_set_menu_pos __ARGS((int x, int y, int w, int h));
void gui_mch_menu_hidden __ARGS((vimmenu_T *menu, int hidden));
void gui_mch_draw_menubar __ARGS((void));
long_u gui_mch_get_rgb __ARGS((guicolor_T pixel));
void gui_mch_activate_window __ARGS((void));
void gui_mch_show_toolbar __ARGS((int showit));
void gui_mch_show_tabline __ARGS((int showit));
int gui_mch_showing_tabline __ARGS((void));
void gui_mch_update_tabline __ARGS((void));
void gui_mch_set_curtab __ARGS((int nr));
void ex_simalt __ARGS((exarg_T *eap));
void gui_mch_find_dialog __ARGS((exarg_T *eap));
void gui_mch_replace_dialog __ARGS((exarg_T *eap));
void gui_mch_mousehide __ARGS((int hide));
void gui_mch_destroy_scrollbar __ARGS((scrollbar_T *sb));
void gui_mch_getmouse __ARGS((int *x, int *y));
void gui_mch_setmouse __ARGS((int x, int y));
void gui_mch_flash __ARGS((int msec));
void gui_mch_delete_lines __ARGS((int row, int num_lines));
void gui_mch_insert_lines __ARGS((int row, int num_lines));
void gui_mch_exit __ARGS((int rc));
int gui_mch_init_font __ARGS((char_u *font_name, int fontset));
int gui_mch_maximized __ARGS((void));
void gui_mch_newfont __ARGS((void));
void gui_mch_settitle __ARGS((char_u *title, char_u *icon));
void mch_set_mouse_shape __ARGS((int shape));
char_u *gui_mch_browsedir __ARGS((char_u *title, char_u *initdir));
char_u *gui_mch_browse __ARGS((int saving, char_u *title, char_u *dflt, char_u *ext, char_u *initdir, char_u *filter));
int get_cmd_args __ARGS((char *prog, char *cmdline, char ***argvp, char **tofree));
void gui_mch_prepare __ARGS((int *argc, char **argv));
int gui_mch_init __ARGS((void));
void gui_mch_set_shellsize __ARGS((int width, int height, int min_width, int min_height, int base_width, int base_height, int direction));
void gui_mch_set_scrollbar_thumb __ARGS((scrollbar_T *sb, long val, long size, long max));
void gui_mch_set_font __ARGS((GuiFont font));
void gui_mch_set_fg_color __ARGS((guicolor_T color));
void gui_mch_set_bg_color __ARGS((guicolor_T color));
void gui_mch_set_sp_color __ARGS((guicolor_T color));
void gui_mch_draw_string __ARGS((int row, int col, char_u *text, int len, int flags));
void gui_mch_flush __ARGS((void));
void gui_mch_get_screen_dimensions __ARGS((int *screen_w, int *screen_h));
void gui_mch_add_menu __ARGS((vimmenu_T *menu, int pos));
void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu));
void gui_make_popup __ARGS((char_u *path_name, int mouse_pos));
void gui_mch_add_menu_item __ARGS((vimmenu_T *menu, int idx));
void gui_mch_destroy_menu __ARGS((vimmenu_T *menu));
void gui_mch_menu_grey __ARGS((vimmenu_T *menu, int grey));
int gui_mch_dialog __ARGS((int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd));
void gui_mch_set_foreground __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_w16.pro | C | gpl2 | 4,421 |
/* pty.c */
int OpenPTY __ARGS((char **ttyn));
int SetupSlavePTY __ARGS((int fd));
| zyz2011-vim | src/proto/pty.pro | IDL | gpl2 | 83 |
/* option.c */
void set_init_1 __ARGS((void));
void set_string_default __ARGS((char *name, char_u *val));
void set_number_default __ARGS((char *name, long val));
void free_all_options __ARGS((void));
void set_init_2 __ARGS((void));
void set_init_3 __ARGS((void));
void set_helplang_default __ARGS((char_u *lang));
void init_gui_options __ARGS((void));
void set_title_defaults __ARGS((void));
int do_set __ARGS((char_u *arg, int opt_flags));
void set_options_bin __ARGS((int oldval, int newval, int opt_flags));
int get_viminfo_parameter __ARGS((int type));
char_u *find_viminfo_parameter __ARGS((int type));
void check_options __ARGS((void));
void check_buf_options __ARGS((buf_T *buf));
void free_string_option __ARGS((char_u *p));
void clear_string_option __ARGS((char_u **pp));
void set_term_option_alloced __ARGS((char_u **p));
int was_set_insecurely __ARGS((char_u *opt, int opt_flags));
void set_string_option_direct __ARGS((char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid));
char_u *check_colorcolumn __ARGS((win_T *wp));
char_u *check_stl_option __ARGS((char_u *s));
int get_option_value __ARGS((char_u *name, long *numval, char_u **stringval, int opt_flags));
void set_option_value __ARGS((char_u *name, long number, char_u *string, int opt_flags));
char_u *get_term_code __ARGS((char_u *tname));
char_u *get_highlight_default __ARGS((void));
char_u *get_encoding_default __ARGS((void));
int makeset __ARGS((FILE *fd, int opt_flags, int local_only));
int makefoldset __ARGS((FILE *fd));
void clear_termoptions __ARGS((void));
void free_termoptions __ARGS((void));
void free_one_termoption __ARGS((char_u *var));
void set_term_defaults __ARGS((void));
void comp_col __ARGS((void));
char_u *get_equalprg __ARGS((void));
void win_copy_options __ARGS((win_T *wp_from, win_T *wp_to));
void copy_winopt __ARGS((winopt_T *from, winopt_T *to));
void check_win_options __ARGS((win_T *win));
void check_winopt __ARGS((winopt_T *wop));
void clear_winopt __ARGS((winopt_T *wop));
void buf_copy_options __ARGS((buf_T *buf, int flags));
void reset_modifiable __ARGS((void));
void set_iminsert_global __ARGS((void));
void set_imsearch_global __ARGS((void));
void set_context_in_set_cmd __ARGS((expand_T *xp, char_u *arg, int opt_flags));
int ExpandSettings __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file));
int ExpandOldSetting __ARGS((int *num_file, char_u ***file));
int langmap_adjust_mb __ARGS((int c));
int has_format_option __ARGS((int x));
int shortmess __ARGS((int x));
void vimrc_found __ARGS((char_u *fname, char_u *envname));
void change_compatible __ARGS((int on));
int option_was_set __ARGS((char_u *name));
int can_bs __ARGS((int what));
void save_file_ff __ARGS((buf_T *buf));
int file_ff_differs __ARGS((buf_T *buf, int ignore_empty));
int check_ff_value __ARGS((char_u *p));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/option.pro | C | gpl2 | 2,854 |
/* misc1.c */
int get_indent __ARGS((void));
int get_indent_lnum __ARGS((linenr_T lnum));
int get_indent_buf __ARGS((buf_T *buf, linenr_T lnum));
int get_indent_str __ARGS((char_u *ptr, int ts));
int set_indent __ARGS((int size, int flags));
int get_number_indent __ARGS((linenr_T lnum));
int open_line __ARGS((int dir, int flags, int old_indent));
int get_leader_len __ARGS((char_u *line, char_u **flags, int backward, int do_skip_space));
int get_last_leader_offset __ARGS((char_u *line, char_u **flags));
int plines __ARGS((linenr_T lnum));
int plines_win __ARGS((win_T *wp, linenr_T lnum, int winheight));
int plines_nofill __ARGS((linenr_T lnum));
int plines_win_nofill __ARGS((win_T *wp, linenr_T lnum, int winheight));
int plines_win_nofold __ARGS((win_T *wp, linenr_T lnum));
int plines_win_col __ARGS((win_T *wp, linenr_T lnum, long column));
int plines_m_win __ARGS((win_T *wp, linenr_T first, linenr_T last));
void ins_bytes __ARGS((char_u *p));
void ins_bytes_len __ARGS((char_u *p, int len));
void ins_char __ARGS((int c));
void ins_char_bytes __ARGS((char_u *buf, int charlen));
void ins_str __ARGS((char_u *s));
int del_char __ARGS((int fixpos));
int del_chars __ARGS((long count, int fixpos));
int del_bytes __ARGS((long count, int fixpos_arg, int use_delcombine));
int truncate_line __ARGS((int fixpos));
void del_lines __ARGS((long nlines, int undo));
int gchar_pos __ARGS((pos_T *pos));
int gchar_cursor __ARGS((void));
void pchar_cursor __ARGS((int c));
int inindent __ARGS((int extra));
char_u *skip_to_option_part __ARGS((char_u *p));
void changed __ARGS((void));
void changed_int __ARGS((void));
void changed_bytes __ARGS((linenr_T lnum, colnr_T col));
void appended_lines __ARGS((linenr_T lnum, long count));
void appended_lines_mark __ARGS((linenr_T lnum, long count));
void deleted_lines __ARGS((linenr_T lnum, long count));
void deleted_lines_mark __ARGS((linenr_T lnum, long count));
void changed_lines __ARGS((linenr_T lnum, colnr_T col, linenr_T lnume, long xtra));
void unchanged __ARGS((buf_T *buf, int ff));
void check_status __ARGS((buf_T *buf));
void change_warning __ARGS((int col));
int ask_yesno __ARGS((char_u *str, int direct));
int get_keystroke __ARGS((void));
int get_number __ARGS((int colon, int *mouse_used));
int prompt_for_number __ARGS((int *mouse_used));
void msgmore __ARGS((long n));
void beep_flush __ARGS((void));
void vim_beep __ARGS((void));
void init_homedir __ARGS((void));
void free_homedir __ARGS((void));
char_u *expand_env_save __ARGS((char_u *src));
char_u *expand_env_save_opt __ARGS((char_u *src, int one));
void expand_env __ARGS((char_u *src, char_u *dst, int dstlen));
void expand_env_esc __ARGS((char_u *srcp, char_u *dst, int dstlen, int esc, int one, char_u *startstr));
char_u *vim_getenv __ARGS((char_u *name, int *mustfree));
void vim_setenv __ARGS((char_u *name, char_u *val));
char_u *get_env_name __ARGS((expand_T *xp, int idx));
void home_replace __ARGS((buf_T *buf, char_u *src, char_u *dst, int dstlen, int one));
char_u *home_replace_save __ARGS((buf_T *buf, char_u *src));
int fullpathcmp __ARGS((char_u *s1, char_u *s2, int checkname));
char_u *gettail __ARGS((char_u *fname));
char_u *gettail_sep __ARGS((char_u *fname));
char_u *getnextcomp __ARGS((char_u *fname));
char_u *get_past_head __ARGS((char_u *path));
int vim_ispathsep __ARGS((int c));
int vim_ispathlistsep __ARGS((int c));
void shorten_dir __ARGS((char_u *str));
int dir_of_file_exists __ARGS((char_u *fname));
int vim_fnamecmp __ARGS((char_u *x, char_u *y));
int vim_fnamencmp __ARGS((char_u *x, char_u *y, size_t len));
char_u *concat_fnames __ARGS((char_u *fname1, char_u *fname2, int sep));
char_u *concat_str __ARGS((char_u *str1, char_u *str2));
void add_pathsep __ARGS((char_u *p));
char_u *FullName_save __ARGS((char_u *fname, int force));
pos_T *find_start_comment __ARGS((int ind_maxcomment));
void do_c_expr_indent __ARGS((void));
int cin_islabel __ARGS((int ind_maxcomment));
int cin_iscase __ARGS((char_u *s, int strict));
int cin_isscopedecl __ARGS((char_u *s));
int get_c_indent __ARGS((void));
int get_expr_indent __ARGS((void));
int get_lisp_indent __ARGS((void));
void prepare_to_exit __ARGS((void));
void preserve_exit __ARGS((void));
int vim_fexists __ARGS((char_u *fname));
void line_breakcheck __ARGS((void));
void fast_breakcheck __ARGS((void));
int expand_wildcards_eval __ARGS((char_u **pat, int *num_file, char_u ***file, int flags));
int expand_wildcards __ARGS((int num_pat, char_u **pat, int *num_file, char_u ***file, int flags));
int match_suffix __ARGS((char_u *fname));
int unix_expandpath __ARGS((garray_T *gap, char_u *path, int wildoff, int flags, int didstar));
void remove_duplicates __ARGS((garray_T *gap));
int gen_expand_wildcards __ARGS((int num_pat, char_u **pat, int *num_file, char_u ***file, int flags));
void addfile __ARGS((garray_T *gap, char_u *f, int flags));
char_u *get_cmd_output __ARGS((char_u *cmd, char_u *infile, int flags));
void FreeWild __ARGS((int count, char_u **files));
int goto_im __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/misc1.pro | C | gpl2 | 5,033 |
/* sha256.c */
void sha256_start __ARGS((context_sha256_T *ctx));
void sha256_update __ARGS((context_sha256_T *ctx, char_u *input, UINT32_T length));
void sha256_finish __ARGS((context_sha256_T *ctx, char_u digest[32]));
char_u *sha256_key __ARGS((char_u *buf, char_u *salt, int salt_len));
int sha256_self_test __ARGS((void));
void sha2_seed __ARGS((char_u *header, int header_len, char_u *salt, int salt_len));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/sha256.pro | C | gpl2 | 435 |
/* popupmnu.c */
void pum_display __ARGS((pumitem_T *array, int size, int selected));
void pum_redraw __ARGS((void));
void pum_undisplay __ARGS((void));
void pum_clear __ARGS((void));
int pum_visible __ARGS((void));
int pum_get_height __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/popupmnu.pro | C | gpl2 | 273 |
/* if_perlsfio.c */
int *sfdcnewvim __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/if_perlsfio.pro | C | gpl2 | 74 |
/* diff.c */
void diff_buf_delete __ARGS((buf_T *buf));
void diff_buf_adjust __ARGS((win_T *win));
void diff_buf_add __ARGS((buf_T *buf));
void diff_invalidate __ARGS((buf_T *buf));
void diff_mark_adjust __ARGS((linenr_T line1, linenr_T line2, long amount, long amount_after));
void ex_diffupdate __ARGS((exarg_T *eap));
void ex_diffpatch __ARGS((exarg_T *eap));
void ex_diffsplit __ARGS((exarg_T *eap));
void ex_diffthis __ARGS((exarg_T *eap));
void diff_win_options __ARGS((win_T *wp, int addbuf));
void ex_diffoff __ARGS((exarg_T *eap));
void diff_clear __ARGS((tabpage_T *tp));
int diff_check __ARGS((win_T *wp, linenr_T lnum));
int diff_check_fill __ARGS((win_T *wp, linenr_T lnum));
void diff_set_topline __ARGS((win_T *fromwin, win_T *towin));
int diffopt_changed __ARGS((void));
int diffopt_horizontal __ARGS((void));
int diff_find_change __ARGS((win_T *wp, linenr_T lnum, int *startp, int *endp));
int diff_infold __ARGS((win_T *wp, linenr_T lnum));
void nv_diffgetput __ARGS((int put));
void ex_diffgetput __ARGS((exarg_T *eap));
int diff_mode_buf __ARGS((buf_T *buf));
int diff_move_to __ARGS((int dir, long count));
linenr_T diff_get_corresponding_line __ARGS((buf_T *buf1, linenr_T lnum1, buf_T *buf2, linenr_T lnum3));
linenr_T diff_lnum_win __ARGS((linenr_T lnum, win_T *wp));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/diff.pro | C | gpl2 | 1,314 |
/* os_vms.c */
void mch_settmode __ARGS((int tmode));
int mch_get_shellsize __ARGS((void));
void mch_set_shellsize __ARGS((void));
char_u *mch_getenv __ARGS((char_u *lognam));
int mch_setenv __ARGS((char *var, char *value, int x));
int vms_sys __ARGS((char *cmd, char *out, char *inp));
int vms_sys_status __ARGS((int status));
int vms_read __ARGS((char *inbuf, size_t nbytes));
int mch_expand_wildcards __ARGS((int num_pat, char_u **pat, int *num_file, char_u ***file, int flags));
int mch_expandpath __ARGS((garray_T *gap, char_u *path, int flags));
void *vms_fixfilename __ARGS((void *instring));
void vms_remove_version __ARGS((void *fname));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/os_vms.pro | C | gpl2 | 669 |
/* memfile.c */
memfile_T *mf_open __ARGS((char_u *fname, int flags));
int mf_open_file __ARGS((memfile_T *mfp, char_u *fname));
void mf_close __ARGS((memfile_T *mfp, int del_file));
void mf_close_file __ARGS((buf_T *buf, int getlines));
void mf_new_page_size __ARGS((memfile_T *mfp, unsigned new_size));
bhdr_T *mf_new __ARGS((memfile_T *mfp, int negative, int page_count));
bhdr_T *mf_get __ARGS((memfile_T *mfp, blocknr_T nr, int page_count));
void mf_put __ARGS((memfile_T *mfp, bhdr_T *hp, int dirty, int infile));
void mf_free __ARGS((memfile_T *mfp, bhdr_T *hp));
int mf_sync __ARGS((memfile_T *mfp, int flags));
void mf_set_dirty __ARGS((memfile_T *mfp));
int mf_release_all __ARGS((void));
blocknr_T mf_trans_del __ARGS((memfile_T *mfp, blocknr_T old_nr));
void mf_set_ffname __ARGS((memfile_T *mfp));
void mf_fullname __ARGS((memfile_T *mfp));
int mf_need_trans __ARGS((memfile_T *mfp));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/memfile.pro | C | gpl2 | 920 |
/* if_tcl.c */
void vim_tcl_init __ARGS((char *arg));
int tcl_enabled __ARGS((int verbose));
void tcl_end __ARGS((void));
void ex_tcl __ARGS((exarg_T *eap));
void ex_tclfile __ARGS((exarg_T *eap));
void ex_tcldo __ARGS((exarg_T *eap));
void tcl_buffer_free __ARGS((buf_T *buf));
void tcl_window_free __ARGS((win_T *win));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/if_tcl.pro | C | gpl2 | 344 |
/* os_mac_conv.c */
char_u *mac_string_convert __ARGS((char_u *ptr, int len, int *lenp, int fail_on_error, int from_enc, int to_enc, int *unconvlenp));
int macroman2enc __ARGS((char_u *ptr, long *sizep, long real_size));
int enc2macroman __ARGS((char_u *from, size_t fromlen, char_u *to, int *tolenp, int maxtolen, char_u *rest, int *restlenp));
void mac_conv_init __ARGS((void));
void mac_conv_cleanup __ARGS((void));
char_u *mac_utf16_to_enc __ARGS((unsigned short *from, size_t fromLen, size_t *actualLen));
unsigned short *mac_enc_to_utf16 __ARGS((char_u *from, size_t fromLen, size_t *actualLen));
void * mac_enc_to_cfstring __ARGS((char_u *from, size_t fromLen));
char_u *mac_precompose_path __ARGS((char_u *decompPath, size_t decompLen, size_t *precompLen));
void mac_lang_init __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/os_mac_conv.pro | C | gpl2 | 823 |
/* gui_mac.c */
/*
* Mac specific prototypes
*/
pascal Boolean WaitNextEventWrp __ARGS((EventMask eventMask, EventRecord *theEvent, UInt32 sleep, RgnHandle mouseRgn));
pascal void gui_mac_scroll_action __ARGS((ControlHandle theControl, short partCode));
pascal void gui_mac_drag_thumb (ControlHandle theControl, short partCode);
void gui_mac_handle_event __ARGS((EventRecord *event));
void gui_mac_doMouseDown __ARGS((EventRecord *theEvent));
void gui_mac_do_key __ARGS((EventRecord *theEvent));
void gui_mac_handle_menu __ARGS((long menuChoice));
void gui_mac_focus_change __ARGS((EventRecord *event));
void gui_mac_update __ARGS((EventRecord *event));
short gui_mch_get_mac_menu_item_index __ARGS((vimmenu_T *menu, vimmenu_T *parent));
void gui_mch_set_blinking __ARGS((long wait, long on, long off));
void gui_mch_stop_blink __ARGS((void));
void gui_mch_start_blink __ARGS((void));
void gui_mch_getmouse __ARGS((int *x, int *y));
void gui_mch_setmouse __ARGS((int x, int y));
void gui_mch_prepare __ARGS((int *argc, char **argv));
int gui_mch_init_check __ARGS((void));
int gui_mch_init __ARGS((void));
void gui_mch_new_colors __ARGS((void));
int gui_mch_open __ARGS((void));
void gui_mch_exit __ARGS((int));
void gui_mch_set_winsize __ARGS((int width, int height, int min_width, int min_height, int base_width, int base_height));
int gui_mch_get_winpos __ARGS((int *x, int *y));
void gui_mch_set_winpos __ARGS((int x, int y));
void gui_mch_set_shellsize __ARGS((int width, int height, int min_width, int min_height, int base_width, int base_height, int direction));
void gui_mch_get_screen_dimensions __ARGS((int *screen_w, int *screen_h));
void gui_mch_set_text_area_pos __ARGS((int x, int y, int w, int h));
void gui_mch_enable_scrollbar __ARGS((scrollbar_T *sb, int flag));
void gui_mch_set_scrollbar_thumb __ARGS((scrollbar_T *sb, long val, long size, long max));
void gui_mch_set_scrollbar_pos __ARGS((scrollbar_T *sb, int x, int y, int w, int h));
void gui_mch_create_scrollbar __ARGS((scrollbar_T *sb, int orient));
void gui_mch_destroy_scrollbar __ARGS((scrollbar_T *sb));
int gui_mch_adjust_charheight __ARGS((void));
int gui_mch_init_font __ARGS((char_u *font_name, int fontset));
GuiFont gui_mch_get_font __ARGS((char_u *name, int giveErrorIfMissing));
char_u *gui_mch_get_fontname __ARGS((GuiFont font, char_u *name));
GuiFont gui_mac_find_font __ARGS((char_u *font_name));
void gui_mch_set_font __ARGS((GuiFont font));
int gui_mch_same_font __ARGS((GuiFont f1, GuiFont f2));
void gui_mch_free_font __ARGS((GuiFont font));
guicolor_T gui_mch_get_color __ARGS((char_u *name));
void gui_mch_set_fg_color __ARGS((guicolor_T color));
void gui_mch_set_bg_color __ARGS((guicolor_T color));
void gui_mch_set_sp_color __ARGS((guicolor_T color));
void gui_mch_draw_string __ARGS((int row, int col, char_u *s, int len, int flags));
int gui_mch_haskey __ARGS((char_u *name));
void gui_mch_beep __ARGS((void));
void gui_mch_flash __ARGS((int msec));
void gui_mch_invert_rectangle __ARGS((int r, int c, int nr, int nc));
void gui_mch_iconify __ARGS((void));
void gui_mch_settitle __ARGS((char_u *title, char_u *icon));
void gui_mch_draw_hollow_cursor __ARGS((guicolor_T color));
void gui_mch_draw_part_cursor __ARGS((int w, int h, guicolor_T color));
void gui_mch_update __ARGS((void));
int gui_mch_wait_for_chars __ARGS((int wtime));
void gui_mch_flush __ARGS((void));
void gui_mch_clear_block __ARGS((int row1, int col1, int row2, int col2));
void gui_mch_clear_all __ARGS((void));
void gui_mch_delete_lines __ARGS((int row, int num_lines));
void gui_mch_insert_lines __ARGS((int row, int num_lines));
void gui_mch_enable_menu __ARGS((int flag));
void gui_mch_set_menu_pos __ARGS((int x, int y, int w, int h));
/*void gui_mch_add_menu __ARGS((vimmenu_T *menu, vimmenu_T *parent, int idx));*/
void gui_mch_add_menu __ARGS((vimmenu_T *menu, int pos));
/*void gui_mch_add_menu_item __ARGS((vimmenu_T *menu, vimmenu_T *parent, int idx));*/
void gui_mch_add_menu_item __ARGS((vimmenu_T *menu, int idx));
void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu));
void gui_mch_destroy_menu __ARGS((vimmenu_T *menu));
void gui_mch_menu_grey __ARGS((vimmenu_T *menu, int grey));
void gui_mch_menu_hidden __ARGS((vimmenu_T *menu, int hidden));
void gui_mch_draw_menubar __ARGS((void));
int gui_mch_get_lightness __ARGS((guicolor_T pixel));
long_u gui_mch_get_rgb __ARGS((guicolor_T pixel));
int gui_mch_get_mouse_x __ARGS((void));
int gui_mch_get_mouse_y __ARGS((void));
void gui_mch_setmouse __ARGS((int x, int y));
void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu));
int gui_mch_dialog __ARGS((int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd));
char_u *gui_mch_browse __ARGS((int saving, char_u *title, char_u *dflt, char_u *ext, char_u *initdir, char_u *filter));
void gui_mch_set_foreground __ARGS((void));
void gui_mch_show_tabline __ARGS((int showit));
int gui_mch_showing_tabline __ARGS((void));
void gui_mch_update_tabline __ARGS((void));
void gui_mch_set_curtab __ARGS((int nr));
char_u *C2Pascal_save __ARGS((char_u *Cstring));
char_u *C2Pascal_save_and_remove_backslash __ARGS((char_u *Cstring));
int_u EventModifiers2VimMouseModifiers __ARGS((EventModifiers macModifiers));
char_u **new_fnames_from_AEDesc __ARGS((AEDesc *theList, long *numFiles, OSErr *error));
void gui_request_selection __ARGS((void));
void gui_mch_lose_selection __ARGS((void));
int gui_mch_own_selection __ARGS((void));
void gui_mch_clear_selection __ARGS((void));
void gui_win_new_height __ARGS((win_T *wp));
void gui_win_comp_pos __ARGS((void));
void gui_win_free __ARGS((win_T *wp));
void gui_win_alloc __ARGS((win_T *wp));
void mch_post_buffer_write (buf_T *buf);
void mch_errmsg __ARGS((char *str));
void mch_display_error __ARGS((void));
void clip_mch_lose_selection __ARGS((VimClipboard *cbd));
void clip_mch_request_selection __ARGS((VimClipboard *cbd));
void clip_mch_set_selection __ARGS((VimClipboard *cbd));
int clip_mch_own_selection __ARGS((VimClipboard *cbd));
pascal OSErr FindProcessBySignature( const OSType targetType,
const OSType targetCreator, ProcessSerialNumberPtr psnPtr );
OSErr InstallAEHandlers (void);
pascal OSErr HandleODocAE (const AppleEvent *theAEvent, AppleEvent *theReply, long refCon);
pascal OSErr Handle_aevt_oapp_AE (const AppleEvent *theAEvent, AppleEvent *theReply, long refCon);
pascal OSErr Handle_aevt_quit_AE (const AppleEvent *theAEvent, AppleEvent *theReply, long refCon);
pascal OSErr Handle_aevt_pdoc_AE (const AppleEvent *theAEvent, AppleEvent *theReply, long refCon);
pascal OSErr Handle_unknown_AE (const AppleEvent *theAEvent, AppleEvent *theReply, long refCon);
/* Shoulde we return MenuItemIndex? IMO yes, I did that for 5.7 ak*/
short gui_mac_get_menu_item_index (vimmenu_T *pMenu);
pascal OSErr Handle_KAHL_SRCH_AE (const AppleEvent *theAEvent, AppleEvent *theReply, long refCon);
pascal OSErr Handle_KAHL_MOD_AE (const AppleEvent *theAEvent, AppleEvent *theReply, long refCon);
pascal OSErr Handle_KAHL_GTTX_AE (const AppleEvent *theAEvent, AppleEvent *theReply, long refCon);
void Send_KAHL_MOD_AE (buf_T *buf);
void gui_mac_doInContentClick __ARGS((EventRecord *theEvent, WindowPtr whichWindow));
void gui_mac_doInDragClick __ARGS((Point where, WindowPtr whichWindow));
void gui_mac_doInGrowClick __ARGS((Point where, WindowPtr whichWindow));
void gui_mac_doUpdateEvent __ARGS((EventRecord *event));
void gui_mac_doActivateEvent __ARGS((EventRecord *event));
void gui_mac_doSuspendEvent __ARGS((EventRecord *event));
void gui_mac_doKeyEvent __ARGS((EventRecord *theEvent));
void gui_mac_doMouseDownEvent __ARGS((EventRecord *theEvent));
void gui_mac_doMouseMovedEvent __ARGS((EventRecord *event));
void gui_mac_doMouseUpEvent __ARGS((EventRecord *theEvent));
void gui_mch_mousehide __ARGS((int hide));
int C2PascalString (char_u *CString, Str255 *PascalString);
int GetFSSpecFromPath ( char_u *file, FSSpec *fileFSSpec);
char_u *FullPathFromFSSpec_save (FSSpec file);
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_mac.pro | C | gpl2 | 8,010 |
/* gui_beval.c */
void general_beval_cb __ARGS((BalloonEval *beval, int state));
BalloonEval *gui_mch_create_beval_area __ARGS((void *target, char_u *mesg, void (*mesgCB)(BalloonEval *, int), void *clientData));
void gui_mch_destroy_beval_area __ARGS((BalloonEval *beval));
void gui_mch_enable_beval_area __ARGS((BalloonEval *beval));
void gui_mch_disable_beval_area __ARGS((BalloonEval *beval));
BalloonEval *gui_mch_currently_showing_beval __ARGS((void));
int get_beval_info __ARGS((BalloonEval *beval, int getword, win_T **winp, linenr_T *lnump, char_u **textp, int *colp));
void gui_mch_post_balloon __ARGS((BalloonEval *beval, char_u *mesg));
void gui_mch_unpost_balloon __ARGS((BalloonEval *beval));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_beval.pro | C | gpl2 | 728 |
/* gui_w32.c */
void gui_mch_set_blinking __ARGS((long wait, long on, long off));
void gui_mch_stop_blink __ARGS((void));
void gui_mch_start_blink __ARGS((void));
LRESULT WINAPI vim_WindowProc __ARGS((HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam));
void gui_mch_new_colors __ARGS((void));
void gui_mch_def_colors __ARGS((void));
int gui_mch_open __ARGS((void));
int gui_mch_get_winpos __ARGS((int *x, int *y));
void gui_mch_set_winpos __ARGS((int x, int y));
void gui_mch_set_text_area_pos __ARGS((int x, int y, int w, int h));
void gui_mch_enable_scrollbar __ARGS((scrollbar_T *sb, int flag));
void gui_mch_set_scrollbar_pos __ARGS((scrollbar_T *sb, int x, int y, int w, int h));
void gui_mch_create_scrollbar __ARGS((scrollbar_T *sb, int orient));
int gui_mch_adjust_charheight __ARGS((void));
GuiFont gui_mch_get_font __ARGS((char_u *name, int giveErrorIfMissing));
char_u *gui_mch_get_fontname __ARGS((GuiFont font, char_u *name));
void gui_mch_free_font __ARGS((GuiFont font));
guicolor_T gui_mch_get_color __ARGS((char_u *name));
int gui_mch_haskey __ARGS((char_u *name));
void gui_mch_beep __ARGS((void));
void gui_mch_invert_rectangle __ARGS((int r, int c, int nr, int nc));
void gui_mch_iconify __ARGS((void));
void gui_mch_draw_hollow_cursor __ARGS((guicolor_T color));
void gui_mch_draw_part_cursor __ARGS((int w, int h, guicolor_T color));
void gui_mch_update __ARGS((void));
int gui_mch_wait_for_chars __ARGS((int wtime));
void gui_mch_clear_block __ARGS((int row1, int col1, int row2, int col2));
void gui_mch_clear_all __ARGS((void));
void gui_mch_enable_menu __ARGS((int flag));
void gui_mch_set_menu_pos __ARGS((int x, int y, int w, int h));
void gui_mch_menu_hidden __ARGS((vimmenu_T *menu, int hidden));
void gui_mch_draw_menubar __ARGS((void));
long_u gui_mch_get_rgb __ARGS((guicolor_T pixel));
void gui_mch_activate_window __ARGS((void));
void gui_mch_show_toolbar __ARGS((int showit));
void gui_mch_show_tabline __ARGS((int showit));
int gui_mch_showing_tabline __ARGS((void));
void gui_mch_update_tabline __ARGS((void));
void gui_mch_set_curtab __ARGS((int nr));
void ex_simalt __ARGS((exarg_T *eap));
void gui_mch_find_dialog __ARGS((exarg_T *eap));
void gui_mch_replace_dialog __ARGS((exarg_T *eap));
void gui_mch_mousehide __ARGS((int hide));
void gui_mch_destroy_scrollbar __ARGS((scrollbar_T *sb));
void gui_mch_getmouse __ARGS((int *x, int *y));
void gui_mch_setmouse __ARGS((int x, int y));
void gui_mch_flash __ARGS((int msec));
void gui_mch_delete_lines __ARGS((int row, int num_lines));
void gui_mch_insert_lines __ARGS((int row, int num_lines));
void gui_mch_exit __ARGS((int rc));
int gui_mch_init_font __ARGS((char_u *font_name, int fontset));
int gui_mch_maximized __ARGS((void));
void gui_mch_newfont __ARGS((void));
void gui_mch_settitle __ARGS((char_u *title, char_u *icon));
void mch_set_mouse_shape __ARGS((int shape));
char_u *gui_mch_browsedir __ARGS((char_u *title, char_u *initdir));
char_u *gui_mch_browse __ARGS((int saving, char_u *title, char_u *dflt, char_u *ext, char_u *initdir, char_u *filter));
int get_cmd_args __ARGS((char *prog, char *cmdline, char ***argvp, char **tofree));
int gui_is_win32s __ARGS((void));
void gui_mch_set_parent __ARGS((char *title));
void gui_mch_prepare __ARGS((int *argc, char **argv));
int gui_mch_init __ARGS((void));
void gui_mch_set_shellsize __ARGS((int width, int height, int min_width, int min_height, int base_width, int base_height, int direction));
void gui_mch_set_scrollbar_thumb __ARGS((scrollbar_T *sb, long val, long size, long max));
void gui_mch_set_font __ARGS((GuiFont font));
void gui_mch_set_fg_color __ARGS((guicolor_T color));
void gui_mch_set_bg_color __ARGS((guicolor_T color));
void gui_mch_set_sp_color __ARGS((guicolor_T color));
void im_set_font __ARGS((LOGFONT *lf));
void im_set_position __ARGS((int row, int col));
void im_set_active __ARGS((int active));
int im_get_status __ARGS((void));
void gui_mch_draw_string __ARGS((int row, int col, char_u *text, int len, int flags));
void gui_mch_flush __ARGS((void));
void gui_mch_get_screen_dimensions __ARGS((int *screen_w, int *screen_h));
void gui_mch_add_menu __ARGS((vimmenu_T *menu, int pos));
void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu));
void gui_make_popup __ARGS((char_u *path_name, int mouse_pos));
void gui_make_tearoff __ARGS((char_u *path_name));
void gui_mch_add_menu_item __ARGS((vimmenu_T *menu, int idx));
void gui_mch_destroy_menu __ARGS((vimmenu_T *menu));
void gui_mch_menu_grey __ARGS((vimmenu_T *menu, int grey));
int gui_mch_dialog __ARGS((int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd));
void gui_mch_set_foreground __ARGS((void));
void gui_mch_drawsign __ARGS((int row, int col, int typenr));
void *gui_mch_register_sign __ARGS((char_u *signfile));
void gui_mch_destroy_sign __ARGS((void *sign));
int multiline_balloon_available __ARGS((void));
void gui_mch_disable_beval_area __ARGS((BalloonEval *beval));
void gui_mch_enable_beval_area __ARGS((BalloonEval *beval));
void gui_mch_post_balloon __ARGS((BalloonEval *beval, char_u *mesg));
BalloonEval *gui_mch_create_beval_area __ARGS((void *target, char_u *mesg, void (*mesgCB)(BalloonEval *, int), void *clientData));
void gui_mch_destroy_beval_area __ARGS((BalloonEval *beval));
void netbeans_draw_multisign_indicator __ARGS((int row));
void netbeans_init_winsock __ARGS((void));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/gui_w32.pro | C | gpl2 | 5,418 |
/* undo.c */
int u_save_cursor __ARGS((void));
int u_save __ARGS((linenr_T top, linenr_T bot));
int u_savesub __ARGS((linenr_T lnum));
int u_inssub __ARGS((linenr_T lnum));
int u_savedel __ARGS((linenr_T lnum, long nlines));
int undo_allowed __ARGS((void));
int u_savecommon __ARGS((linenr_T top, linenr_T bot, linenr_T newbot, int reload));
void u_compute_hash __ARGS((char_u *hash));
char_u *u_get_undo_file_name __ARGS((char_u *buf_ffname, int reading));
void u_write_undo __ARGS((char_u *name, int forceit, buf_T *buf, char_u *hash));
void u_read_undo __ARGS((char_u *name, char_u *hash, char_u *orig_name));
void u_undo __ARGS((int count));
void u_redo __ARGS((int count));
void undo_time __ARGS((long step, int sec, int file, int absolute));
void u_sync __ARGS((int force));
void ex_undolist __ARGS((exarg_T *eap));
void ex_undojoin __ARGS((exarg_T *eap));
void u_unchanged __ARGS((buf_T *buf));
void u_find_first_changed __ARGS((void));
void u_update_save_nr __ARGS((buf_T *buf));
void u_clearall __ARGS((buf_T *buf));
void u_saveline __ARGS((linenr_T lnum));
void u_clearline __ARGS((void));
void u_undoline __ARGS((void));
void u_blockfree __ARGS((buf_T *buf));
int bufIsChanged __ARGS((buf_T *buf));
int curbufIsChanged __ARGS((void));
void u_eval_tree __ARGS((u_header_T *first_uhp, list_T *list));
/* vim: set ft=c : */
| zyz2011-vim | src/proto/undo.pro | C | gpl2 | 1,332 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* message.c: functions for displaying messages on the command line
*/
#define MESSAGE_FILE /* don't include prototype for smsg() */
#include "vim.h"
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
# include <math.h>
#endif
static int other_sourcing_name __ARGS((void));
static char_u *get_emsg_source __ARGS((void));
static char_u *get_emsg_lnum __ARGS((void));
static void add_msg_hist __ARGS((char_u *s, int len, int attr));
static void hit_return_msg __ARGS((void));
static void msg_home_replace_attr __ARGS((char_u *fname, int attr));
#ifdef FEAT_MBYTE
static char_u *screen_puts_mbyte __ARGS((char_u *s, int l, int attr));
#endif
static void msg_puts_attr_len __ARGS((char_u *str, int maxlen, int attr));
static void msg_puts_display __ARGS((char_u *str, int maxlen, int attr, int recurse));
static void msg_scroll_up __ARGS((void));
static void inc_msg_scrolled __ARGS((void));
static void store_sb_text __ARGS((char_u **sb_str, char_u *s, int attr, int *sb_col, int finish));
static void t_puts __ARGS((int *t_col, char_u *t_s, char_u *s, int attr));
static void msg_puts_printf __ARGS((char_u *str, int maxlen));
static int do_more_prompt __ARGS((int typed_char));
static void msg_screen_putchar __ARGS((int c, int attr));
static int msg_check_screen __ARGS((void));
static void redir_write __ARGS((char_u *s, int maxlen));
#ifdef FEAT_CON_DIALOG
static char_u *msg_show_console_dialog __ARGS((char_u *message, char_u *buttons, int dfltbutton));
static int confirm_msg_used = FALSE; /* displaying confirm_msg */
static char_u *confirm_msg = NULL; /* ":confirm" message */
static char_u *confirm_msg_tail; /* tail of confirm_msg */
#endif
struct msg_hist
{
struct msg_hist *next;
char_u *msg;
int attr;
};
static struct msg_hist *first_msg_hist = NULL;
static struct msg_hist *last_msg_hist = NULL;
static int msg_hist_len = 0;
static FILE *verbose_fd = NULL;
static int verbose_did_open = FALSE;
/*
* When writing messages to the screen, there are many different situations.
* A number of variables is used to remember the current state:
* msg_didany TRUE when messages were written since the last time the
* user reacted to a prompt.
* Reset: After hitting a key for the hit-return prompt,
* hitting <CR> for the command line or input().
* Set: When any message is written to the screen.
* msg_didout TRUE when something was written to the current line.
* Reset: When advancing to the next line, when the current
* text can be overwritten.
* Set: When any message is written to the screen.
* msg_nowait No extra delay for the last drawn message.
* Used in normal_cmd() before the mode message is drawn.
* emsg_on_display There was an error message recently. Indicates that there
* should be a delay before redrawing.
* msg_scroll The next message should not overwrite the current one.
* msg_scrolled How many lines the screen has been scrolled (because of
* messages). Used in update_screen() to scroll the screen
* back. Incremented each time the screen scrolls a line.
* msg_scrolled_ign TRUE when msg_scrolled is non-zero and msg_puts_attr()
* writes something without scrolling should not make
* need_wait_return to be set. This is a hack to make ":ts"
* work without an extra prompt.
* lines_left Number of lines available for messages before the
* more-prompt is to be given. -1 when not set.
* need_wait_return TRUE when the hit-return prompt is needed.
* Reset: After giving the hit-return prompt, when the user
* has answered some other prompt.
* Set: When the ruler or typeahead display is overwritten,
* scrolling the screen for some message.
* keep_msg Message to be displayed after redrawing the screen, in
* main_loop().
* This is an allocated string or NULL when not used.
*/
/*
* msg(s) - displays the string 's' on the status line
* When terminal not initialized (yet) mch_errmsg(..) is used.
* return TRUE if wait_return not called
*/
int
msg(s)
char_u *s;
{
return msg_attr_keep(s, 0, FALSE);
}
#if defined(FEAT_EVAL) || defined(FEAT_X11) || defined(USE_XSMP) \
|| defined(FEAT_GUI_GTK) || defined(PROTO)
/*
* Like msg() but keep it silent when 'verbosefile' is set.
*/
int
verb_msg(s)
char_u *s;
{
int n;
verbose_enter();
n = msg_attr_keep(s, 0, FALSE);
verbose_leave();
return n;
}
#endif
int
msg_attr(s, attr)
char_u *s;
int attr;
{
return msg_attr_keep(s, attr, FALSE);
}
int
msg_attr_keep(s, attr, keep)
char_u *s;
int attr;
int keep; /* TRUE: set keep_msg if it doesn't scroll */
{
static int entered = 0;
int retval;
char_u *buf = NULL;
#ifdef FEAT_EVAL
if (attr == 0)
set_vim_var_string(VV_STATUSMSG, s, -1);
#endif
/*
* It is possible that displaying a messages causes a problem (e.g.,
* when redrawing the window), which causes another message, etc.. To
* break this loop, limit the recursiveness to 3 levels.
*/
if (entered >= 3)
return TRUE;
++entered;
/* Add message to history (unless it's a repeated kept message or a
* truncated message) */
if (s != keep_msg
|| (*s != '<'
&& last_msg_hist != NULL
&& last_msg_hist->msg != NULL
&& STRCMP(s, last_msg_hist->msg)))
add_msg_hist(s, -1, attr);
/* When displaying keep_msg, don't let msg_start() free it, caller must do
* that. */
if (s == keep_msg)
keep_msg = NULL;
/* Truncate the message if needed. */
msg_start();
buf = msg_strtrunc(s, FALSE);
if (buf != NULL)
s = buf;
msg_outtrans_attr(s, attr);
msg_clr_eos();
retval = msg_end();
if (keep && retval && vim_strsize(s) < (int)(Rows - cmdline_row - 1)
* Columns + sc_col)
set_keep_msg(s, 0);
vim_free(buf);
--entered;
return retval;
}
/*
* Truncate a string such that it can be printed without causing a scroll.
* Returns an allocated string or NULL when no truncating is done.
*/
char_u *
msg_strtrunc(s, force)
char_u *s;
int force; /* always truncate */
{
char_u *buf = NULL;
int len;
int room;
/* May truncate message to avoid a hit-return prompt */
if ((!msg_scroll && !need_wait_return && shortmess(SHM_TRUNCALL)
&& !exmode_active && msg_silent == 0) || force)
{
len = vim_strsize(s);
if (msg_scrolled != 0)
/* Use all the columns. */
room = (int)(Rows - msg_row) * Columns - 1;
else
/* Use up to 'showcmd' column. */
room = (int)(Rows - msg_row - 1) * Columns + sc_col - 1;
if (len > room && room > 0)
{
#ifdef FEAT_MBYTE
if (enc_utf8)
/* may have up to 18 bytes per cell (6 per char, up to two
* composing chars) */
len = (room + 2) * 18;
else if (enc_dbcs == DBCS_JPNU)
/* may have up to 2 bytes per cell for euc-jp */
len = (room + 2) * 2;
else
#endif
len = room + 2;
buf = alloc(len);
if (buf != NULL)
trunc_string(s, buf, room, len);
}
}
return buf;
}
/*
* Truncate a string "s" to "buf" with cell width "room".
* "s" and "buf" may be equal.
*/
void
trunc_string(s, buf, room, buflen)
char_u *s;
char_u *buf;
int room;
int buflen;
{
int half;
int len;
int e;
int i;
int n;
room -= 3;
half = room / 2;
len = 0;
/* First part: Start of the string. */
for (e = 0; len < half && e < buflen; ++e)
{
if (s[e] == NUL)
{
/* text fits without truncating! */
buf[e] = NUL;
return;
}
n = ptr2cells(s + e);
if (len + n >= half)
break;
len += n;
buf[e] = s[e];
#ifdef FEAT_MBYTE
if (has_mbyte)
for (n = (*mb_ptr2len)(s + e); --n > 0; )
{
if (++e == buflen)
break;
buf[e] = s[e];
}
#endif
}
/* Last part: End of the string. */
i = e;
#ifdef FEAT_MBYTE
if (enc_dbcs != 0)
{
/* For DBCS going backwards in a string is slow, but
* computing the cell width isn't too slow: go forward
* until the rest fits. */
n = vim_strsize(s + i);
while (len + n > room)
{
n -= ptr2cells(s + i);
i += (*mb_ptr2len)(s + i);
}
}
else if (enc_utf8)
{
/* For UTF-8 we can go backwards easily. */
half = i = (int)STRLEN(s);
for (;;)
{
do
half = half - (*mb_head_off)(s, s + half - 1) - 1;
while (utf_iscomposing(utf_ptr2char(s + half)) && half > 0);
n = ptr2cells(s + half);
if (len + n > room)
break;
len += n;
i = half;
}
}
else
#endif
{
for (i = (int)STRLEN(s); len + (n = ptr2cells(s + i - 1)) <= room; --i)
len += n;
}
/* Set the middle and copy the last part. */
if (e + 3 < buflen)
{
mch_memmove(buf + e, "...", (size_t)3);
len = (int)STRLEN(s + i) + 1;
if (len >= buflen - e - 3)
len = buflen - e - 3 - 1;
mch_memmove(buf + e + 3, s + i, len);
buf[e + 3 + len - 1] = NUL;
}
else
{
buf[e - 1] = NUL; /* make sure it is truncated */
}
}
/*
* Automatic prototype generation does not understand this function.
* Note: Caller of smgs() and smsg_attr() must check the resulting string is
* shorter than IOSIZE!!!
*/
#ifndef PROTO
# ifndef HAVE_STDARG_H
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg __ARGS((char_u *, long, long, long,
long, long, long, long, long, long, long));
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg_attr __ARGS((int, char_u *, long, long, long,
long, long, long, long, long, long, long));
int vim_snprintf __ARGS((char *, size_t, char *, long, long, long,
long, long, long, long, long, long, long));
/*
* smsg(str, arg, ...) is like using sprintf(buf, str, arg, ...) and then
* calling msg(buf).
* The buffer used is IObuff, the message is truncated at IOSIZE.
*/
/* VARARGS */
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg(s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
char_u *s;
long a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
{
return smsg_attr(0, s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
}
/* VARARGS */
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg_attr(attr, s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
int attr;
char_u *s;
long a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
{
vim_snprintf((char *)IObuff, IOSIZE, (char *)s,
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
return msg_attr(IObuff, attr);
}
# else /* HAVE_STDARG_H */
int vim_snprintf(char *str, size_t str_m, char *fmt, ...);
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg(char_u *s, ...)
{
va_list arglist;
va_start(arglist, s);
vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist, NULL);
va_end(arglist);
return msg(IObuff);
}
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg_attr(int attr, char_u *s, ...)
{
va_list arglist;
va_start(arglist, s);
vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist, NULL);
va_end(arglist);
return msg_attr(IObuff, attr);
}
# endif /* HAVE_STDARG_H */
#endif
/*
* Remember the last sourcing name/lnum used in an error message, so that it
* isn't printed each time when it didn't change.
*/
static int last_sourcing_lnum = 0;
static char_u *last_sourcing_name = NULL;
/*
* Reset the last used sourcing name/lnum. Makes sure it is displayed again
* for the next error message;
*/
void
reset_last_sourcing()
{
vim_free(last_sourcing_name);
last_sourcing_name = NULL;
last_sourcing_lnum = 0;
}
/*
* Return TRUE if "sourcing_name" differs from "last_sourcing_name".
*/
static int
other_sourcing_name()
{
if (sourcing_name != NULL)
{
if (last_sourcing_name != NULL)
return STRCMP(sourcing_name, last_sourcing_name) != 0;
return TRUE;
}
return FALSE;
}
/*
* Get the message about the source, as used for an error message.
* Returns an allocated string with room for one more character.
* Returns NULL when no message is to be given.
*/
static char_u *
get_emsg_source()
{
char_u *Buf, *p;
if (sourcing_name != NULL && other_sourcing_name())
{
p = (char_u *)_("Error detected while processing %s:");
Buf = alloc((unsigned)(STRLEN(sourcing_name) + STRLEN(p)));
if (Buf != NULL)
sprintf((char *)Buf, (char *)p, sourcing_name);
return Buf;
}
return NULL;
}
/*
* Get the message about the source lnum, as used for an error message.
* Returns an allocated string with room for one more character.
* Returns NULL when no message is to be given.
*/
static char_u *
get_emsg_lnum()
{
char_u *Buf, *p;
/* lnum is 0 when executing a command from the command line
* argument, we don't want a line number then */
if (sourcing_name != NULL
&& (other_sourcing_name() || sourcing_lnum != last_sourcing_lnum)
&& sourcing_lnum != 0)
{
p = (char_u *)_("line %4ld:");
Buf = alloc((unsigned)(STRLEN(p) + 20));
if (Buf != NULL)
sprintf((char *)Buf, (char *)p, (long)sourcing_lnum);
return Buf;
}
return NULL;
}
/*
* Display name and line number for the source of an error.
* Remember the file name and line number, so that for the next error the info
* is only displayed if it changed.
*/
void
msg_source(attr)
int attr;
{
char_u *p;
++no_wait_return;
p = get_emsg_source();
if (p != NULL)
{
msg_attr(p, attr);
vim_free(p);
}
p = get_emsg_lnum();
if (p != NULL)
{
msg_attr(p, hl_attr(HLF_N));
vim_free(p);
last_sourcing_lnum = sourcing_lnum; /* only once for each line */
}
/* remember the last sourcing name printed, also when it's empty */
if (sourcing_name == NULL || other_sourcing_name())
{
vim_free(last_sourcing_name);
if (sourcing_name == NULL)
last_sourcing_name = NULL;
else
last_sourcing_name = vim_strsave(sourcing_name);
}
--no_wait_return;
}
/*
* Return TRUE if not giving error messages right now:
* If "emsg_off" is set: no error messages at the moment.
* If "msg" is in 'debug': do error message but without side effects.
* If "emsg_skip" is set: never do error messages.
*/
int
emsg_not_now()
{
if ((emsg_off > 0 && vim_strchr(p_debug, 'm') == NULL
&& vim_strchr(p_debug, 't') == NULL)
#ifdef FEAT_EVAL
|| emsg_skip > 0
#endif
)
return TRUE;
return FALSE;
}
/*
* emsg() - display an error message
*
* Rings the bell, if appropriate, and calls message() to do the real work
* When terminal not initialized (yet) mch_errmsg(..) is used.
*
* return TRUE if wait_return not called
*/
int
emsg(s)
char_u *s;
{
int attr;
char_u *p;
#ifdef FEAT_EVAL
int ignore = FALSE;
int severe;
#endif
/* Skip this if not giving error messages at the moment. */
if (emsg_not_now())
return TRUE;
called_emsg = TRUE;
ex_exitval = 1;
/*
* If "emsg_severe" is TRUE: When an error exception is to be thrown,
* prefer this message over previous messages for the same command.
*/
#ifdef FEAT_EVAL
severe = emsg_severe;
emsg_severe = FALSE;
#endif
if (!emsg_off || vim_strchr(p_debug, 't') != NULL)
{
#ifdef FEAT_EVAL
/*
* Cause a throw of an error exception if appropriate. Don't display
* the error message in this case. (If no matching catch clause will
* be found, the message will be displayed later on.) "ignore" is set
* when the message should be ignored completely (used for the
* interrupt message).
*/
if (cause_errthrow(s, severe, &ignore) == TRUE)
{
if (!ignore)
did_emsg = TRUE;
return TRUE;
}
/* set "v:errmsg", also when using ":silent! cmd" */
set_vim_var_string(VV_ERRMSG, s, -1);
#endif
/*
* When using ":silent! cmd" ignore error messages.
* But do write it to the redirection file.
*/
if (emsg_silent != 0)
{
msg_start();
p = get_emsg_source();
if (p != NULL)
{
STRCAT(p, "\n");
redir_write(p, -1);
vim_free(p);
}
p = get_emsg_lnum();
if (p != NULL)
{
STRCAT(p, "\n");
redir_write(p, -1);
vim_free(p);
}
redir_write(s, -1);
return TRUE;
}
/* Reset msg_silent, an error causes messages to be switched back on. */
msg_silent = 0;
cmd_silent = FALSE;
if (global_busy) /* break :global command */
++global_busy;
if (p_eb)
beep_flush(); /* also includes flush_buffers() */
else
flush_buffers(FALSE); /* flush internal buffers */
did_emsg = TRUE; /* flag for DoOneCmd() */
}
emsg_on_display = TRUE; /* remember there is an error message */
++msg_scroll; /* don't overwrite a previous message */
attr = hl_attr(HLF_E); /* set highlight mode for error messages */
if (msg_scrolled != 0)
need_wait_return = TRUE; /* needed in case emsg() is called after
* wait_return has reset need_wait_return
* and a redraw is expected because
* msg_scrolled is non-zero */
/*
* Display name and line number for the source of the error.
*/
msg_source(attr);
/*
* Display the error message itself.
*/
msg_nowait = FALSE; /* wait for this msg */
return msg_attr(s, attr);
}
/*
* Print an error message with one "%s" and one string argument.
*/
int
emsg2(s, a1)
char_u *s, *a1;
{
return emsg3(s, a1, NULL);
}
/* emsg3() and emsgn() are in misc2.c to avoid warnings for the prototypes. */
void
emsg_invreg(name)
int name;
{
EMSG2(_("E354: Invalid register name: '%s'"), transchar(name));
}
/*
* Like msg(), but truncate to a single line if p_shm contains 't', or when
* "force" is TRUE. This truncates in another way as for normal messages.
* Careful: The string may be changed by msg_may_trunc()!
* Returns a pointer to the printed message, if wait_return() not called.
*/
char_u *
msg_trunc_attr(s, force, attr)
char_u *s;
int force;
int attr;
{
int n;
/* Add message to history before truncating */
add_msg_hist(s, -1, attr);
s = msg_may_trunc(force, s);
msg_hist_off = TRUE;
n = msg_attr(s, attr);
msg_hist_off = FALSE;
if (n)
return s;
return NULL;
}
/*
* Check if message "s" should be truncated at the start (for filenames).
* Return a pointer to where the truncated message starts.
* Note: May change the message by replacing a character with '<'.
*/
char_u *
msg_may_trunc(force, s)
int force;
char_u *s;
{
int n;
int room;
room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1;
if ((force || (shortmess(SHM_TRUNC) && !exmode_active))
&& (n = (int)STRLEN(s) - room) > 0)
{
#ifdef FEAT_MBYTE
if (has_mbyte)
{
int size = vim_strsize(s);
/* There may be room anyway when there are multibyte chars. */
if (size <= room)
return s;
for (n = 0; size >= room; )
{
size -= (*mb_ptr2cells)(s + n);
n += (*mb_ptr2len)(s + n);
}
--n;
}
#endif
s += n;
*s = '<';
}
return s;
}
static void
add_msg_hist(s, len, attr)
char_u *s;
int len; /* -1 for undetermined length */
int attr;
{
struct msg_hist *p;
if (msg_hist_off || msg_silent != 0)
return;
/* Don't let the message history get too big */
while (msg_hist_len > MAX_MSG_HIST_LEN)
(void)delete_first_msg();
/* allocate an entry and add the message at the end of the history */
p = (struct msg_hist *)alloc((int)sizeof(struct msg_hist));
if (p != NULL)
{
if (len < 0)
len = (int)STRLEN(s);
/* remove leading and trailing newlines */
while (len > 0 && *s == '\n')
{
++s;
--len;
}
while (len > 0 && s[len - 1] == '\n')
--len;
p->msg = vim_strnsave(s, len);
p->next = NULL;
p->attr = attr;
if (last_msg_hist != NULL)
last_msg_hist->next = p;
last_msg_hist = p;
if (first_msg_hist == NULL)
first_msg_hist = last_msg_hist;
++msg_hist_len;
}
}
/*
* Delete the first (oldest) message from the history.
* Returns FAIL if there are no messages.
*/
int
delete_first_msg()
{
struct msg_hist *p;
if (msg_hist_len <= 0)
return FAIL;
p = first_msg_hist;
first_msg_hist = p->next;
if (first_msg_hist == NULL)
last_msg_hist = NULL; /* history is empty */
vim_free(p->msg);
vim_free(p);
--msg_hist_len;
return OK;
}
/*
* ":messages" command.
*/
void
ex_messages(eap)
exarg_T *eap UNUSED;
{
struct msg_hist *p;
char_u *s;
msg_hist_off = TRUE;
s = mch_getenv((char_u *)"LANG");
if (s != NULL && *s != NUL)
msg_attr((char_u *)
_("Messages maintainer: Bram Moolenaar <Bram@vim.org>"),
hl_attr(HLF_T));
for (p = first_msg_hist; p != NULL && !got_int; p = p->next)
if (p->msg != NULL)
msg_attr(p->msg, p->attr);
msg_hist_off = FALSE;
}
#if defined(FEAT_CON_DIALOG) || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
/*
* Call this after prompting the user. This will avoid a hit-return message
* and a delay.
*/
void
msg_end_prompt()
{
need_wait_return = FALSE;
emsg_on_display = FALSE;
cmdline_row = msg_row;
msg_col = 0;
msg_clr_eos();
lines_left = -1;
}
#endif
/*
* wait for the user to hit a key (normally a return)
* if 'redraw' is TRUE, clear and redraw the screen
* if 'redraw' is FALSE, just redraw the screen
* if 'redraw' is -1, don't redraw at all
*/
void
wait_return(redraw)
int redraw;
{
int c;
int oldState;
int tmpState;
int had_got_int;
if (redraw == TRUE)
must_redraw = CLEAR;
/* If using ":silent cmd", don't wait for a return. Also don't set
* need_wait_return to do it later. */
if (msg_silent != 0)
return;
/*
* When inside vgetc(), we can't wait for a typed character at all.
* With the global command (and some others) we only need one return at
* the end. Adjust cmdline_row to avoid the next message overwriting the
* last one.
*/
if (vgetc_busy > 0)
return;
need_wait_return = TRUE;
if (no_wait_return)
{
if (!exmode_active)
cmdline_row = msg_row;
return;
}
redir_off = TRUE; /* don't redirect this message */
oldState = State;
if (quit_more)
{
c = CAR; /* just pretend CR was hit */
quit_more = FALSE;
got_int = FALSE;
}
else if (exmode_active)
{
MSG_PUTS(" "); /* make sure the cursor is on the right line */
c = CAR; /* no need for a return in ex mode */
got_int = FALSE;
}
else
{
/* Make sure the hit-return prompt is on screen when 'guioptions' was
* just changed. */
screenalloc(FALSE);
State = HITRETURN;
#ifdef FEAT_MOUSE
setmouse();
#endif
#ifdef USE_ON_FLY_SCROLL
dont_scroll = TRUE; /* disallow scrolling here */
#endif
hit_return_msg();
do
{
/* Remember "got_int", if it is set vgetc() probably returns a
* CTRL-C, but we need to loop then. */
had_got_int = got_int;
/* Don't do mappings here, we put the character back in the
* typeahead buffer. */
++no_mapping;
++allow_keys;
c = safe_vgetc();
if (had_got_int && !global_busy)
got_int = FALSE;
--no_mapping;
--allow_keys;
#ifdef FEAT_CLIPBOARD
/* Strange way to allow copying (yanking) a modeless selection at
* the hit-enter prompt. Use CTRL-Y, because the same is used in
* Cmdline-mode and it's harmless when there is no selection. */
if (c == Ctrl_Y && clip_star.state == SELECT_DONE)
{
clip_copy_modeless_selection(TRUE);
c = K_IGNORE;
}
#endif
/*
* Allow scrolling back in the messages.
* Also accept scroll-down commands when messages fill the screen,
* to avoid that typing one 'j' too many makes the messages
* disappear.
*/
if (p_more && !p_cp)
{
if (c == 'b' || c == 'k' || c == 'u' || c == 'g' || c == K_UP)
{
/* scroll back to show older messages */
do_more_prompt(c);
if (quit_more)
{
c = CAR; /* just pretend CR was hit */
quit_more = FALSE;
got_int = FALSE;
}
else
{
c = K_IGNORE;
hit_return_msg();
}
}
else if (msg_scrolled > Rows - 2
&& (c == 'j' || c == K_DOWN || c == 'd' || c == 'f'))
c = K_IGNORE;
}
} while ((had_got_int && c == Ctrl_C)
|| c == K_IGNORE
#ifdef FEAT_GUI
|| c == K_VER_SCROLLBAR || c == K_HOR_SCROLLBAR
#endif
#ifdef FEAT_MOUSE
|| c == K_LEFTDRAG || c == K_LEFTRELEASE
|| c == K_MIDDLEDRAG || c == K_MIDDLERELEASE
|| c == K_RIGHTDRAG || c == K_RIGHTRELEASE
|| c == K_MOUSELEFT || c == K_MOUSERIGHT
|| c == K_MOUSEDOWN || c == K_MOUSEUP
|| (!mouse_has(MOUSE_RETURN)
&& mouse_row < msg_row
&& (c == K_LEFTMOUSE
|| c == K_MIDDLEMOUSE
|| c == K_RIGHTMOUSE
|| c == K_X1MOUSE
|| c == K_X2MOUSE))
#endif
);
ui_breakcheck();
#ifdef FEAT_MOUSE
/*
* Avoid that the mouse-up event causes visual mode to start.
*/
if (c == K_LEFTMOUSE || c == K_MIDDLEMOUSE || c == K_RIGHTMOUSE
|| c == K_X1MOUSE || c == K_X2MOUSE)
(void)jump_to_mouse(MOUSE_SETPOS, NULL, 0);
else
#endif
if (vim_strchr((char_u *)"\r\n ", c) == NULL && c != Ctrl_C)
{
/* Put the character back in the typeahead buffer. Don't use the
* stuff buffer, because lmaps wouldn't work. */
ins_char_typebuf(c);
do_redraw = TRUE; /* need a redraw even though there is
typeahead */
}
}
redir_off = FALSE;
/*
* If the user hits ':', '?' or '/' we get a command line from the next
* line.
*/
if (c == ':' || c == '?' || c == '/')
{
if (!exmode_active)
cmdline_row = msg_row;
skip_redraw = TRUE; /* skip redraw once */
do_redraw = FALSE;
}
/*
* If the window size changed set_shellsize() will redraw the screen.
* Otherwise the screen is only redrawn if 'redraw' is set and no ':'
* typed.
*/
tmpState = State;
State = oldState; /* restore State before set_shellsize */
#ifdef FEAT_MOUSE
setmouse();
#endif
msg_check();
#if defined(UNIX) || defined(VMS)
/*
* When switching screens, we need to output an extra newline on exit.
*/
if (swapping_screen() && !termcap_active)
newline_on_exit = TRUE;
#endif
need_wait_return = FALSE;
did_wait_return = TRUE;
emsg_on_display = FALSE; /* can delete error message now */
lines_left = -1; /* reset lines_left at next msg_start() */
reset_last_sourcing();
if (keep_msg != NULL && vim_strsize(keep_msg) >=
(Rows - cmdline_row - 1) * Columns + sc_col)
{
vim_free(keep_msg);
keep_msg = NULL; /* don't redisplay message, it's too long */
}
if (tmpState == SETWSIZE) /* got resize event while in vgetc() */
{
starttermcap(); /* start termcap before redrawing */
shell_resized();
}
else if (!skip_redraw
&& (redraw == TRUE || (msg_scrolled != 0 && redraw != -1)))
{
starttermcap(); /* start termcap before redrawing */
redraw_later(VALID);
}
}
/*
* Write the hit-return prompt.
*/
static void
hit_return_msg()
{
int save_p_more = p_more;
p_more = FALSE; /* don't want see this message when scrolling back */
if (msg_didout) /* start on a new line */
msg_putchar('\n');
if (got_int)
MSG_PUTS(_("Interrupt: "));
MSG_PUTS_ATTR(_("Press ENTER or type command to continue"), hl_attr(HLF_R));
if (!msg_use_printf())
msg_clr_eos();
p_more = save_p_more;
}
/*
* Set "keep_msg" to "s". Free the old value and check for NULL pointer.
*/
void
set_keep_msg(s, attr)
char_u *s;
int attr;
{
vim_free(keep_msg);
if (s != NULL && msg_silent == 0)
keep_msg = vim_strsave(s);
else
keep_msg = NULL;
keep_msg_more = FALSE;
keep_msg_attr = attr;
}
#if defined(FEAT_TERMRESPONSE) || defined(PROTO)
/*
* If there currently is a message being displayed, set "keep_msg" to it, so
* that it will be displayed again after redraw.
*/
void
set_keep_msg_from_hist()
{
if (keep_msg == NULL && last_msg_hist != NULL && msg_scrolled == 0
&& (State & NORMAL))
set_keep_msg(last_msg_hist->msg, last_msg_hist->attr);
}
#endif
/*
* Prepare for outputting characters in the command line.
*/
void
msg_start()
{
int did_return = FALSE;
if (!msg_silent)
{
vim_free(keep_msg);
keep_msg = NULL; /* don't display old message now */
}
#ifdef FEAT_EVAL
if (need_clr_eos)
{
/* Halfway an ":echo" command and getting an (error) message: clear
* any text from the command. */
need_clr_eos = FALSE;
msg_clr_eos();
}
#endif
if (!msg_scroll && full_screen) /* overwrite last message */
{
msg_row = cmdline_row;
msg_col =
#ifdef FEAT_RIGHTLEFT
cmdmsg_rl ? Columns - 1 :
#endif
0;
}
else if (msg_didout) /* start message on next line */
{
msg_putchar('\n');
did_return = TRUE;
if (exmode_active != EXMODE_NORMAL)
cmdline_row = msg_row;
}
if (!msg_didany || lines_left < 0)
msg_starthere();
if (msg_silent == 0)
{
msg_didout = FALSE; /* no output on current line yet */
cursor_off();
}
/* when redirecting, may need to start a new line. */
if (!did_return)
redir_write((char_u *)"\n", -1);
}
/*
* Note that the current msg position is where messages start.
*/
void
msg_starthere()
{
lines_left = cmdline_row;
msg_didany = FALSE;
}
void
msg_putchar(c)
int c;
{
msg_putchar_attr(c, 0);
}
void
msg_putchar_attr(c, attr)
int c;
int attr;
{
#ifdef FEAT_MBYTE
char_u buf[MB_MAXBYTES + 1];
#else
char_u buf[4];
#endif
if (IS_SPECIAL(c))
{
buf[0] = K_SPECIAL;
buf[1] = K_SECOND(c);
buf[2] = K_THIRD(c);
buf[3] = NUL;
}
else
{
#ifdef FEAT_MBYTE
buf[(*mb_char2bytes)(c, buf)] = NUL;
#else
buf[0] = c;
buf[1] = NUL;
#endif
}
msg_puts_attr(buf, attr);
}
void
msg_outnum(n)
long n;
{
char_u buf[20];
sprintf((char *)buf, "%ld", n);
msg_puts(buf);
}
void
msg_home_replace(fname)
char_u *fname;
{
msg_home_replace_attr(fname, 0);
}
#if defined(FEAT_FIND_ID) || defined(PROTO)
void
msg_home_replace_hl(fname)
char_u *fname;
{
msg_home_replace_attr(fname, hl_attr(HLF_D));
}
#endif
static void
msg_home_replace_attr(fname, attr)
char_u *fname;
int attr;
{
char_u *name;
name = home_replace_save(NULL, fname);
if (name != NULL)
msg_outtrans_attr(name, attr);
vim_free(name);
}
/*
* Output 'len' characters in 'str' (including NULs) with translation
* if 'len' is -1, output upto a NUL character.
* Use attributes 'attr'.
* Return the number of characters it takes on the screen.
*/
int
msg_outtrans(str)
char_u *str;
{
return msg_outtrans_attr(str, 0);
}
int
msg_outtrans_attr(str, attr)
char_u *str;
int attr;
{
return msg_outtrans_len_attr(str, (int)STRLEN(str), attr);
}
int
msg_outtrans_len(str, len)
char_u *str;
int len;
{
return msg_outtrans_len_attr(str, len, 0);
}
/*
* Output one character at "p". Return pointer to the next character.
* Handles multi-byte characters.
*/
char_u *
msg_outtrans_one(p, attr)
char_u *p;
int attr;
{
#ifdef FEAT_MBYTE
int l;
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
{
msg_outtrans_len_attr(p, l, attr);
return p + l;
}
#endif
msg_puts_attr(transchar_byte(*p), attr);
return p + 1;
}
int
msg_outtrans_len_attr(msgstr, len, attr)
char_u *msgstr;
int len;
int attr;
{
int retval = 0;
char_u *str = msgstr;
char_u *plain_start = msgstr;
char_u *s;
#ifdef FEAT_MBYTE
int mb_l;
int c;
#endif
/* if MSG_HIST flag set, add message to history */
if (attr & MSG_HIST)
{
add_msg_hist(str, len, attr);
attr &= ~MSG_HIST;
}
#ifdef FEAT_MBYTE
/* If the string starts with a composing character first draw a space on
* which the composing char can be drawn. */
if (enc_utf8 && utf_iscomposing(utf_ptr2char(msgstr)))
msg_puts_attr((char_u *)" ", attr);
#endif
/*
* Go over the string. Special characters are translated and printed.
* Normal characters are printed several at a time.
*/
while (--len >= 0)
{
#ifdef FEAT_MBYTE
if (enc_utf8)
/* Don't include composing chars after the end. */
mb_l = utfc_ptr2len_len(str, len + 1);
else if (has_mbyte)
mb_l = (*mb_ptr2len)(str);
else
mb_l = 1;
if (has_mbyte && mb_l > 1)
{
c = (*mb_ptr2char)(str);
if (vim_isprintc(c))
/* printable multi-byte char: count the cells. */
retval += (*mb_ptr2cells)(str);
else
{
/* unprintable multi-byte char: print the printable chars so
* far and the translation of the unprintable char. */
if (str > plain_start)
msg_puts_attr_len(plain_start, (int)(str - plain_start),
attr);
plain_start = str + mb_l;
msg_puts_attr(transchar(c), attr == 0 ? hl_attr(HLF_8) : attr);
retval += char2cells(c);
}
len -= mb_l - 1;
str += mb_l;
}
else
#endif
{
s = transchar_byte(*str);
if (s[1] != NUL)
{
/* unprintable char: print the printable chars so far and the
* translation of the unprintable char. */
if (str > plain_start)
msg_puts_attr_len(plain_start, (int)(str - plain_start),
attr);
plain_start = str + 1;
msg_puts_attr(s, attr == 0 ? hl_attr(HLF_8) : attr);
retval += (int)STRLEN(s);
}
else
++retval;
++str;
}
}
if (str > plain_start)
/* print the printable chars at the end */
msg_puts_attr_len(plain_start, (int)(str - plain_start), attr);
return retval;
}
#if defined(FEAT_QUICKFIX) || defined(PROTO)
void
msg_make(arg)
char_u *arg;
{
int i;
static char_u *str = (char_u *)"eeffoc", *rs = (char_u *)"Plon#dqg#vxjduB";
arg = skipwhite(arg);
for (i = 5; *arg && i >= 0; --i)
if (*arg++ != str[i])
break;
if (i < 0)
{
msg_putchar('\n');
for (i = 0; rs[i]; ++i)
msg_putchar(rs[i] - 3);
}
}
#endif
/*
* Output the string 'str' upto a NUL character.
* Return the number of characters it takes on the screen.
*
* If K_SPECIAL is encountered, then it is taken in conjunction with the
* following character and shown as <F1>, <S-Up> etc. Any other character
* which is not printable shown in <> form.
* If 'from' is TRUE (lhs of a mapping), a space is shown as <Space>.
* If a character is displayed in one of these special ways, is also
* highlighted (its highlight name is '8' in the p_hl variable).
* Otherwise characters are not highlighted.
* This function is used to show mappings, where we want to see how to type
* the character/string -- webb
*/
int
msg_outtrans_special(strstart, from)
char_u *strstart;
int from; /* TRUE for lhs of a mapping */
{
char_u *str = strstart;
int retval = 0;
char_u *string;
int attr;
int len;
attr = hl_attr(HLF_8);
while (*str != NUL)
{
/* Leading and trailing spaces need to be displayed in <> form. */
if ((str == strstart || str[1] == NUL) && *str == ' ')
{
string = (char_u *)"<Space>";
++str;
}
else
string = str2special(&str, from);
len = vim_strsize(string);
/* Highlight special keys */
msg_puts_attr(string, len > 1
#ifdef FEAT_MBYTE
&& (*mb_ptr2len)(string) <= 1
#endif
? attr : 0);
retval += len;
}
return retval;
}
#if defined(FEAT_EVAL) || defined(PROTO)
/*
* Return the lhs or rhs of a mapping, with the key codes turned into printable
* strings, in an allocated string.
*/
char_u *
str2special_save(str, is_lhs)
char_u *str;
int is_lhs; /* TRUE for lhs, FALSE for rhs */
{
garray_T ga;
char_u *p = str;
ga_init2(&ga, 1, 40);
while (*p != NUL)
ga_concat(&ga, str2special(&p, is_lhs));
ga_append(&ga, NUL);
return (char_u *)ga.ga_data;
}
#endif
/*
* Return the printable string for the key codes at "*sp".
* Used for translating the lhs or rhs of a mapping to printable chars.
* Advances "sp" to the next code.
*/
char_u *
str2special(sp, from)
char_u **sp;
int from; /* TRUE for lhs of mapping */
{
int c;
static char_u buf[7];
char_u *str = *sp;
int modifiers = 0;
int special = FALSE;
#ifdef FEAT_MBYTE
if (has_mbyte)
{
char_u *p;
/* Try to un-escape a multi-byte character. Return the un-escaped
* string if it is a multi-byte character. */
p = mb_unescape(sp);
if (p != NULL)
return p;
}
#endif
c = *str;
if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
{
if (str[1] == KS_MODIFIER)
{
modifiers = str[2];
str += 3;
c = *str;
}
if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
{
c = TO_SPECIAL(str[1], str[2]);
str += 2;
if (c == K_ZERO) /* display <Nul> as ^@ */
c = NUL;
}
if (IS_SPECIAL(c) || modifiers) /* special key */
special = TRUE;
}
#ifdef FEAT_MBYTE
if (has_mbyte && !IS_SPECIAL(c))
{
int len = (*mb_ptr2len)(str);
/* For multi-byte characters check for an illegal byte. */
if (has_mbyte && MB_BYTE2LEN(*str) > len)
{
transchar_nonprint(buf, c);
*sp = str + 1;
return buf;
}
/* Since 'special' is TRUE the multi-byte character 'c' will be
* processed by get_special_key_name() */
c = (*mb_ptr2char)(str);
*sp = str + len;
}
else
#endif
*sp = str + 1;
/* Make unprintable characters in <> form, also <M-Space> and <Tab>.
* Use <Space> only for lhs of a mapping. */
if (special || char2cells(c) > 1 || (from && c == ' '))
return get_special_key_name(c, modifiers);
buf[0] = c;
buf[1] = NUL;
return buf;
}
/*
* Translate a key sequence into special key names.
*/
void
str2specialbuf(sp, buf, len)
char_u *sp;
char_u *buf;
int len;
{
char_u *s;
*buf = NUL;
while (*sp)
{
s = str2special(&sp, FALSE);
if ((int)(STRLEN(s) + STRLEN(buf)) < len)
STRCAT(buf, s);
}
}
/*
* print line for :print or :list command
*/
void
msg_prt_line(s, list)
char_u *s;
int list;
{
int c;
int col = 0;
int n_extra = 0;
int c_extra = 0;
char_u *p_extra = NULL; /* init to make SASC shut up */
int n;
int attr = 0;
char_u *trail = NULL;
#ifdef FEAT_MBYTE
int l;
char_u buf[MB_MAXBYTES + 1];
#endif
if (curwin->w_p_list)
list = TRUE;
/* find start of trailing whitespace */
if (list && lcs_trail)
{
trail = s + STRLEN(s);
while (trail > s && vim_iswhite(trail[-1]))
--trail;
}
/* output a space for an empty line, otherwise the line will be
* overwritten */
if (*s == NUL && !(list && lcs_eol != NUL))
msg_putchar(' ');
while (!got_int)
{
if (n_extra > 0)
{
--n_extra;
if (c_extra)
c = c_extra;
else
c = *p_extra++;
}
#ifdef FEAT_MBYTE
else if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1)
{
col += (*mb_ptr2cells)(s);
if (lcs_nbsp != NUL && list && mb_ptr2char(s) == 160)
{
mb_char2bytes(lcs_nbsp, buf);
buf[(*mb_ptr2len)(buf)] = NUL;
}
else
{
mch_memmove(buf, s, (size_t)l);
buf[l] = NUL;
}
msg_puts(buf);
s += l;
continue;
}
#endif
else
{
attr = 0;
c = *s++;
if (c == TAB && (!list || lcs_tab1))
{
/* tab amount depends on current column */
n_extra = curbuf->b_p_ts - col % curbuf->b_p_ts - 1;
if (!list)
{
c = ' ';
c_extra = ' ';
}
else
{
c = lcs_tab1;
c_extra = lcs_tab2;
attr = hl_attr(HLF_8);
}
}
else if (c == 160 && list && lcs_nbsp != NUL)
{
c = lcs_nbsp;
attr = hl_attr(HLF_8);
}
else if (c == NUL && list && lcs_eol != NUL)
{
p_extra = (char_u *)"";
c_extra = NUL;
n_extra = 1;
c = lcs_eol;
attr = hl_attr(HLF_AT);
--s;
}
else if (c != NUL && (n = byte2cells(c)) > 1)
{
n_extra = n - 1;
p_extra = transchar_byte(c);
c_extra = NUL;
c = *p_extra++;
/* Use special coloring to be able to distinguish <hex> from
* the same in plain text. */
attr = hl_attr(HLF_8);
}
else if (c == ' ' && trail != NULL && s > trail)
{
c = lcs_trail;
attr = hl_attr(HLF_8);
}
}
if (c == NUL)
break;
msg_putchar_attr(c, attr);
col++;
}
msg_clr_eos();
}
#ifdef FEAT_MBYTE
/*
* Use screen_puts() to output one multi-byte character.
* Return the pointer "s" advanced to the next character.
*/
static char_u *
screen_puts_mbyte(s, l, attr)
char_u *s;
int l;
int attr;
{
int cw;
msg_didout = TRUE; /* remember that line is not empty */
cw = (*mb_ptr2cells)(s);
if (cw > 1 && (
#ifdef FEAT_RIGHTLEFT
cmdmsg_rl ? msg_col <= 1 :
#endif
msg_col == Columns - 1))
{
/* Doesn't fit, print a highlighted '>' to fill it up. */
msg_screen_putchar('>', hl_attr(HLF_AT));
return s;
}
screen_puts_len(s, l, msg_row, msg_col, attr);
#ifdef FEAT_RIGHTLEFT
if (cmdmsg_rl)
{
msg_col -= cw;
if (msg_col == 0)
{
msg_col = Columns;
++msg_row;
}
}
else
#endif
{
msg_col += cw;
if (msg_col >= Columns)
{
msg_col = 0;
++msg_row;
}
}
return s + l;
}
#endif
/*
* Output a string to the screen at position msg_row, msg_col.
* Update msg_row and msg_col for the next message.
*/
void
msg_puts(s)
char_u *s;
{
msg_puts_attr(s, 0);
}
void
msg_puts_title(s)
char_u *s;
{
msg_puts_attr(s, hl_attr(HLF_T));
}
/*
* Show a message in such a way that it always fits in the line. Cut out a
* part in the middle and replace it with "..." when necessary.
* Does not handle multi-byte characters!
*/
void
msg_puts_long_attr(longstr, attr)
char_u *longstr;
int attr;
{
msg_puts_long_len_attr(longstr, (int)STRLEN(longstr), attr);
}
void
msg_puts_long_len_attr(longstr, len, attr)
char_u *longstr;
int len;
int attr;
{
int slen = len;
int room;
room = Columns - msg_col;
if (len > room && room >= 20)
{
slen = (room - 3) / 2;
msg_outtrans_len_attr(longstr, slen, attr);
msg_puts_attr((char_u *)"...", hl_attr(HLF_8));
}
msg_outtrans_len_attr(longstr + len - slen, slen, attr);
}
/*
* Basic function for writing a message with highlight attributes.
*/
void
msg_puts_attr(s, attr)
char_u *s;
int attr;
{
msg_puts_attr_len(s, -1, attr);
}
/*
* Like msg_puts_attr(), but with a maximum length "maxlen" (in bytes).
* When "maxlen" is -1 there is no maximum length.
* When "maxlen" is >= 0 the message is not put in the history.
*/
static void
msg_puts_attr_len(str, maxlen, attr)
char_u *str;
int maxlen;
int attr;
{
/*
* If redirection is on, also write to the redirection file.
*/
redir_write(str, maxlen);
/*
* Don't print anything when using ":silent cmd".
*/
if (msg_silent != 0)
return;
/* if MSG_HIST flag set, add message to history */
if ((attr & MSG_HIST) && maxlen < 0)
{
add_msg_hist(str, -1, attr);
attr &= ~MSG_HIST;
}
/*
* When writing something to the screen after it has scrolled, requires a
* wait-return prompt later. Needed when scrolling, resetting
* need_wait_return after some prompt, and then outputting something
* without scrolling
*/
if (msg_scrolled != 0 && !msg_scrolled_ign)
need_wait_return = TRUE;
msg_didany = TRUE; /* remember that something was outputted */
/*
* If there is no valid screen, use fprintf so we can see error messages.
* If termcap is not active, we may be writing in an alternate console
* window, cursor positioning may not work correctly (window size may be
* different, e.g. for Win32 console) or we just don't know where the
* cursor is.
*/
if (msg_use_printf())
msg_puts_printf(str, maxlen);
else
msg_puts_display(str, maxlen, attr, FALSE);
}
/*
* The display part of msg_puts_attr_len().
* May be called recursively to display scroll-back text.
*/
static void
msg_puts_display(str, maxlen, attr, recurse)
char_u *str;
int maxlen;
int attr;
int recurse;
{
char_u *s = str;
char_u *t_s = str; /* string from "t_s" to "s" is still todo */
int t_col = 0; /* screen cells todo, 0 when "t_s" not used */
#ifdef FEAT_MBYTE
int l;
int cw;
#endif
char_u *sb_str = str;
int sb_col = msg_col;
int wrap;
int did_last_char;
did_wait_return = FALSE;
while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL)
{
/*
* We are at the end of the screen line when:
* - When outputting a newline.
* - When outputting a character in the last column.
*/
if (!recurse && msg_row >= Rows - 1 && (*s == '\n' || (
#ifdef FEAT_RIGHTLEFT
cmdmsg_rl
? (
msg_col <= 1
|| (*s == TAB && msg_col <= 7)
# ifdef FEAT_MBYTE
|| (has_mbyte && (*mb_ptr2cells)(s) > 1 && msg_col <= 2)
# endif
)
:
#endif
(msg_col + t_col >= Columns - 1
|| (*s == TAB && msg_col + t_col >= ((Columns - 1) & ~7))
# ifdef FEAT_MBYTE
|| (has_mbyte && (*mb_ptr2cells)(s) > 1
&& msg_col + t_col >= Columns - 2)
# endif
))))
{
/*
* The screen is scrolled up when at the last row (some terminals
* scroll automatically, some don't. To avoid problems we scroll
* ourselves).
*/
if (t_col > 0)
/* output postponed text */
t_puts(&t_col, t_s, s, attr);
/* When no more prompt and no more room, truncate here */
if (msg_no_more && lines_left == 0)
break;
/* Scroll the screen up one line. */
msg_scroll_up();
msg_row = Rows - 2;
if (msg_col >= Columns) /* can happen after screen resize */
msg_col = Columns - 1;
/* Display char in last column before showing more-prompt. */
if (*s >= ' '
#ifdef FEAT_RIGHTLEFT
&& !cmdmsg_rl
#endif
)
{
#ifdef FEAT_MBYTE
if (has_mbyte)
{
if (enc_utf8 && maxlen >= 0)
/* avoid including composing chars after the end */
l = utfc_ptr2len_len(s, (int)((str + maxlen) - s));
else
l = (*mb_ptr2len)(s);
s = screen_puts_mbyte(s, l, attr);
}
else
#endif
msg_screen_putchar(*s++, attr);
did_last_char = TRUE;
}
else
did_last_char = FALSE;
if (p_more)
/* store text for scrolling back */
store_sb_text(&sb_str, s, attr, &sb_col, TRUE);
inc_msg_scrolled();
need_wait_return = TRUE; /* may need wait_return in main() */
if (must_redraw < VALID)
must_redraw = VALID;
redraw_cmdline = TRUE;
if (cmdline_row > 0 && !exmode_active)
--cmdline_row;
/*
* If screen is completely filled and 'more' is set then wait
* for a character.
*/
if (lines_left > 0)
--lines_left;
if (p_more && lines_left == 0 && State != HITRETURN
&& !msg_no_more && !exmode_active)
{
#ifdef FEAT_CON_DIALOG
if (do_more_prompt(NUL))
s = confirm_msg_tail;
#else
(void)do_more_prompt(NUL);
#endif
if (quit_more)
return;
}
/* When we displayed a char in last column need to check if there
* is still more. */
if (did_last_char)
continue;
}
wrap = *s == '\n'
|| msg_col + t_col >= Columns
#ifdef FEAT_MBYTE
|| (has_mbyte && (*mb_ptr2cells)(s) > 1
&& msg_col + t_col >= Columns - 1)
#endif
;
if (t_col > 0 && (wrap || *s == '\r' || *s == '\b'
|| *s == '\t' || *s == BELL))
/* output any postponed text */
t_puts(&t_col, t_s, s, attr);
if (wrap && p_more && !recurse)
/* store text for scrolling back */
store_sb_text(&sb_str, s, attr, &sb_col, TRUE);
if (*s == '\n') /* go to next line */
{
msg_didout = FALSE; /* remember that line is empty */
#ifdef FEAT_RIGHTLEFT
if (cmdmsg_rl)
msg_col = Columns - 1;
else
#endif
msg_col = 0;
if (++msg_row >= Rows) /* safety check */
msg_row = Rows - 1;
}
else if (*s == '\r') /* go to column 0 */
{
msg_col = 0;
}
else if (*s == '\b') /* go to previous char */
{
if (msg_col)
--msg_col;
}
else if (*s == TAB) /* translate Tab into spaces */
{
do
msg_screen_putchar(' ', attr);
while (msg_col & 7);
}
else if (*s == BELL) /* beep (from ":sh") */
vim_beep();
else
{
#ifdef FEAT_MBYTE
if (has_mbyte)
{
cw = (*mb_ptr2cells)(s);
if (enc_utf8 && maxlen >= 0)
/* avoid including composing chars after the end */
l = utfc_ptr2len_len(s, (int)((str + maxlen) - s));
else
l = (*mb_ptr2len)(s);
}
else
{
cw = 1;
l = 1;
}
#endif
/* When drawing from right to left or when a double-wide character
* doesn't fit, draw a single character here. Otherwise collect
* characters and draw them all at once later. */
#if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
if (
# ifdef FEAT_RIGHTLEFT
cmdmsg_rl
# ifdef FEAT_MBYTE
||
# endif
# endif
# ifdef FEAT_MBYTE
(cw > 1 && msg_col + t_col >= Columns - 1)
# endif
)
{
# ifdef FEAT_MBYTE
if (l > 1)
s = screen_puts_mbyte(s, l, attr) - 1;
else
# endif
msg_screen_putchar(*s, attr);
}
else
#endif
{
/* postpone this character until later */
if (t_col == 0)
t_s = s;
#ifdef FEAT_MBYTE
t_col += cw;
s += l - 1;
#else
++t_col;
#endif
}
}
++s;
}
/* output any postponed text */
if (t_col > 0)
t_puts(&t_col, t_s, s, attr);
if (p_more && !recurse)
store_sb_text(&sb_str, s, attr, &sb_col, FALSE);
msg_check();
}
/*
* Scroll the screen up one line for displaying the next message line.
*/
static void
msg_scroll_up()
{
#ifdef FEAT_GUI
/* Remove the cursor before scrolling, ScreenLines[] is going
* to become invalid. */
if (gui.in_use)
gui_undraw_cursor();
#endif
/* scrolling up always works */
screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL);
if (!can_clear((char_u *)" "))
{
/* Scrolling up doesn't result in the right background. Set the
* background here. It's not efficient, but avoids that we have to do
* it all over the code. */
screen_fill((int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0);
/* Also clear the last char of the last but one line if it was not
* cleared before to avoid a scroll-up. */
if (ScreenAttrs[LineOffset[Rows - 2] + Columns - 1] == (sattr_T)-1)
screen_fill((int)Rows - 2, (int)Rows - 1,
(int)Columns - 1, (int)Columns, ' ', ' ', 0);
}
}
/*
* Increment "msg_scrolled".
*/
static void
inc_msg_scrolled()
{
#ifdef FEAT_EVAL
if (*get_vim_var_str(VV_SCROLLSTART) == NUL)
{
char_u *p = sourcing_name;
char_u *tofree = NULL;
int len;
/* v:scrollstart is empty, set it to the script/function name and line
* number */
if (p == NULL)
p = (char_u *)_("Unknown");
else
{
len = (int)STRLEN(p) + 40;
tofree = alloc(len);
if (tofree != NULL)
{
vim_snprintf((char *)tofree, len, _("%s line %ld"),
p, (long)sourcing_lnum);
p = tofree;
}
}
set_vim_var_string(VV_SCROLLSTART, p, -1);
vim_free(tofree);
}
#endif
++msg_scrolled;
}
/*
* To be able to scroll back at the "more" and "hit-enter" prompts we need to
* store the displayed text and remember where screen lines start.
*/
typedef struct msgchunk_S msgchunk_T;
struct msgchunk_S
{
msgchunk_T *sb_next;
msgchunk_T *sb_prev;
char sb_eol; /* TRUE when line ends after this text */
int sb_msg_col; /* column in which text starts */
int sb_attr; /* text attributes */
char_u sb_text[1]; /* text to be displayed, actually longer */
};
static msgchunk_T *last_msgchunk = NULL; /* last displayed text */
static msgchunk_T *msg_sb_start __ARGS((msgchunk_T *mps));
static msgchunk_T *disp_sb_line __ARGS((int row, msgchunk_T *smp));
static int do_clear_sb_text = FALSE; /* clear text on next msg */
/*
* Store part of a printed message for displaying when scrolling back.
*/
static void
store_sb_text(sb_str, s, attr, sb_col, finish)
char_u **sb_str; /* start of string */
char_u *s; /* just after string */
int attr;
int *sb_col;
int finish; /* line ends */
{
msgchunk_T *mp;
if (do_clear_sb_text)
{
clear_sb_text();
do_clear_sb_text = FALSE;
}
if (s > *sb_str)
{
mp = (msgchunk_T *)alloc((int)(sizeof(msgchunk_T) + (s - *sb_str)));
if (mp != NULL)
{
mp->sb_eol = finish;
mp->sb_msg_col = *sb_col;
mp->sb_attr = attr;
vim_strncpy(mp->sb_text, *sb_str, s - *sb_str);
if (last_msgchunk == NULL)
{
last_msgchunk = mp;
mp->sb_prev = NULL;
}
else
{
mp->sb_prev = last_msgchunk;
last_msgchunk->sb_next = mp;
last_msgchunk = mp;
}
mp->sb_next = NULL;
}
}
else if (finish && last_msgchunk != NULL)
last_msgchunk->sb_eol = TRUE;
*sb_str = s;
*sb_col = 0;
}
/*
* Finished showing messages, clear the scroll-back text on the next message.
*/
void
may_clear_sb_text()
{
do_clear_sb_text = TRUE;
}
/*
* Clear any text remembered for scrolling back.
* Called when redrawing the screen.
*/
void
clear_sb_text()
{
msgchunk_T *mp;
while (last_msgchunk != NULL)
{
mp = last_msgchunk->sb_prev;
vim_free(last_msgchunk);
last_msgchunk = mp;
}
}
/*
* "g<" command.
*/
void
show_sb_text()
{
msgchunk_T *mp;
/* Only show something if there is more than one line, otherwise it looks
* weird, typing a command without output results in one line. */
mp = msg_sb_start(last_msgchunk);
if (mp == NULL || mp->sb_prev == NULL)
vim_beep();
else
{
do_more_prompt('G');
wait_return(FALSE);
}
}
/*
* Move to the start of screen line in already displayed text.
*/
static msgchunk_T *
msg_sb_start(mps)
msgchunk_T *mps;
{
msgchunk_T *mp = mps;
while (mp != NULL && mp->sb_prev != NULL && !mp->sb_prev->sb_eol)
mp = mp->sb_prev;
return mp;
}
/*
* Mark the last message chunk as finishing the line.
*/
void
msg_sb_eol()
{
if (last_msgchunk != NULL)
last_msgchunk->sb_eol = TRUE;
}
/*
* Display a screen line from previously displayed text at row "row".
* Returns a pointer to the text for the next line (can be NULL).
*/
static msgchunk_T *
disp_sb_line(row, smp)
int row;
msgchunk_T *smp;
{
msgchunk_T *mp = smp;
char_u *p;
for (;;)
{
msg_row = row;
msg_col = mp->sb_msg_col;
p = mp->sb_text;
if (*p == '\n') /* don't display the line break */
++p;
msg_puts_display(p, -1, mp->sb_attr, TRUE);
if (mp->sb_eol || mp->sb_next == NULL)
break;
mp = mp->sb_next;
}
return mp->sb_next;
}
/*
* Output any postponed text for msg_puts_attr_len().
*/
static void
t_puts(t_col, t_s, s, attr)
int *t_col;
char_u *t_s;
char_u *s;
int attr;
{
/* output postponed text */
msg_didout = TRUE; /* remember that line is not empty */
screen_puts_len(t_s, (int)(s - t_s), msg_row, msg_col, attr);
msg_col += *t_col;
*t_col = 0;
#ifdef FEAT_MBYTE
/* If the string starts with a composing character don't increment the
* column position for it. */
if (enc_utf8 && utf_iscomposing(utf_ptr2char(t_s)))
--msg_col;
#endif
if (msg_col >= Columns)
{
msg_col = 0;
++msg_row;
}
}
/*
* Returns TRUE when messages should be printed with mch_errmsg().
* This is used when there is no valid screen, so we can see error messages.
* If termcap is not active, we may be writing in an alternate console
* window, cursor positioning may not work correctly (window size may be
* different, e.g. for Win32 console) or we just don't know where the
* cursor is.
*/
int
msg_use_printf()
{
return (!msg_check_screen()
#if defined(WIN3264) && !defined(FEAT_GUI_MSWIN)
|| !termcap_active
#endif
|| (swapping_screen() && !termcap_active)
);
}
/*
* Print a message when there is no valid screen.
*/
static void
msg_puts_printf(str, maxlen)
char_u *str;
int maxlen;
{
char_u *s = str;
char_u buf[4];
char_u *p;
#ifdef WIN3264
if (!(silent_mode && p_verbose == 0))
mch_settmode(TMODE_COOK); /* handle '\r' and '\n' correctly */
#endif
while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen))
{
if (!(silent_mode && p_verbose == 0))
{
/* NL --> CR NL translation (for Unix, not for "--version") */
/* NL --> CR translation (for Mac) */
p = &buf[0];
if (*s == '\n' && !info_message)
*p++ = '\r';
#if defined(USE_CR) && !defined(MACOS_X_UNIX)
else
#endif
*p++ = *s;
*p = '\0';
if (info_message) /* informative message, not an error */
mch_msg((char *)buf);
else
mch_errmsg((char *)buf);
}
/* primitive way to compute the current column */
#ifdef FEAT_RIGHTLEFT
if (cmdmsg_rl)
{
if (*s == '\r' || *s == '\n')
msg_col = Columns - 1;
else
--msg_col;
}
else
#endif
{
if (*s == '\r' || *s == '\n')
msg_col = 0;
else
++msg_col;
}
++s;
}
msg_didout = TRUE; /* assume that line is not empty */
#ifdef WIN3264
if (!(silent_mode && p_verbose == 0))
mch_settmode(TMODE_RAW);
#endif
}
/*
* Show the more-prompt and handle the user response.
* This takes care of scrolling back and displaying previously displayed text.
* When at hit-enter prompt "typed_char" is the already typed character,
* otherwise it's NUL.
* Returns TRUE when jumping ahead to "confirm_msg_tail".
*/
static int
do_more_prompt(typed_char)
int typed_char;
{
int used_typed_char = typed_char;
int oldState = State;
int c;
#ifdef FEAT_CON_DIALOG
int retval = FALSE;
#endif
int toscroll;
msgchunk_T *mp_last = NULL;
msgchunk_T *mp;
int i;
if (typed_char == 'G')
{
/* "g<": Find first line on the last page. */
mp_last = msg_sb_start(last_msgchunk);
for (i = 0; i < Rows - 2 && mp_last != NULL
&& mp_last->sb_prev != NULL; ++i)
mp_last = msg_sb_start(mp_last->sb_prev);
}
State = ASKMORE;
#ifdef FEAT_MOUSE
setmouse();
#endif
if (typed_char == NUL)
msg_moremsg(FALSE);
for (;;)
{
/*
* Get a typed character directly from the user.
*/
if (used_typed_char != NUL)
{
c = used_typed_char; /* was typed at hit-enter prompt */
used_typed_char = NUL;
}
else
c = get_keystroke();
#if defined(FEAT_MENU) && defined(FEAT_GUI)
if (c == K_MENU)
{
int idx = get_menu_index(current_menu, ASKMORE);
/* Used a menu. If it starts with CTRL-Y, it must
* be a "Copy" for the clipboard. Otherwise
* assume that we end */
if (idx == MENU_INDEX_INVALID)
continue;
c = *current_menu->strings[idx];
if (c != NUL && current_menu->strings[idx][1] != NUL)
ins_typebuf(current_menu->strings[idx] + 1,
current_menu->noremap[idx], 0, TRUE,
current_menu->silent[idx]);
}
#endif
toscroll = 0;
switch (c)
{
case BS: /* scroll one line back */
case K_BS:
case 'k':
case K_UP:
toscroll = -1;
break;
case CAR: /* one extra line */
case NL:
case 'j':
case K_DOWN:
toscroll = 1;
break;
case 'u': /* Up half a page */
toscroll = -(Rows / 2);
break;
case 'd': /* Down half a page */
toscroll = Rows / 2;
break;
case 'b': /* one page back */
case K_PAGEUP:
toscroll = -(Rows - 1);
break;
case ' ': /* one extra page */
case 'f':
case K_PAGEDOWN:
case K_LEFTMOUSE:
toscroll = Rows - 1;
break;
case 'g': /* all the way back to the start */
toscroll = -999999;
break;
case 'G': /* all the way to the end */
toscroll = 999999;
lines_left = 999999;
break;
case ':': /* start new command line */
#ifdef FEAT_CON_DIALOG
if (!confirm_msg_used)
#endif
{
/* Since got_int is set all typeahead will be flushed, but we
* want to keep this ':', remember that in a special way. */
typeahead_noflush(':');
cmdline_row = Rows - 1; /* put ':' on this line */
skip_redraw = TRUE; /* skip redraw once */
need_wait_return = FALSE; /* don't wait in main() */
}
/*FALLTHROUGH*/
case 'q': /* quit */
case Ctrl_C:
case ESC:
#ifdef FEAT_CON_DIALOG
if (confirm_msg_used)
{
/* Jump to the choices of the dialog. */
retval = TRUE;
}
else
#endif
{
got_int = TRUE;
quit_more = TRUE;
}
/* When there is some more output (wrapping line) display that
* without another prompt. */
lines_left = Rows - 1;
break;
#ifdef FEAT_CLIPBOARD
case Ctrl_Y:
/* Strange way to allow copying (yanking) a modeless
* selection at the more prompt. Use CTRL-Y,
* because the same is used in Cmdline-mode and at the
* hit-enter prompt. However, scrolling one line up
* might be expected... */
if (clip_star.state == SELECT_DONE)
clip_copy_modeless_selection(TRUE);
continue;
#endif
default: /* no valid response */
msg_moremsg(TRUE);
continue;
}
if (toscroll != 0)
{
if (toscroll < 0)
{
/* go to start of last line */
if (mp_last == NULL)
mp = msg_sb_start(last_msgchunk);
else if (mp_last->sb_prev != NULL)
mp = msg_sb_start(mp_last->sb_prev);
else
mp = NULL;
/* go to start of line at top of the screen */
for (i = 0; i < Rows - 2 && mp != NULL && mp->sb_prev != NULL;
++i)
mp = msg_sb_start(mp->sb_prev);
if (mp != NULL && mp->sb_prev != NULL)
{
/* Find line to be displayed at top. */
for (i = 0; i > toscroll; --i)
{
if (mp == NULL || mp->sb_prev == NULL)
break;
mp = msg_sb_start(mp->sb_prev);
if (mp_last == NULL)
mp_last = msg_sb_start(last_msgchunk);
else
mp_last = msg_sb_start(mp_last->sb_prev);
}
if (toscroll == -1 && screen_ins_lines(0, 0, 1,
(int)Rows, NULL) == OK)
{
/* display line at top */
(void)disp_sb_line(0, mp);
}
else
{
/* redisplay all lines */
screenclear();
for (i = 0; mp != NULL && i < Rows - 1; ++i)
{
mp = disp_sb_line(i, mp);
++msg_scrolled;
}
}
toscroll = 0;
}
}
else
{
/* First display any text that we scrolled back. */
while (toscroll > 0 && mp_last != NULL)
{
/* scroll up, display line at bottom */
msg_scroll_up();
inc_msg_scrolled();
screen_fill((int)Rows - 2, (int)Rows - 1, 0,
(int)Columns, ' ', ' ', 0);
mp_last = disp_sb_line((int)Rows - 2, mp_last);
--toscroll;
}
}
if (toscroll <= 0)
{
/* displayed the requested text, more prompt again */
screen_fill((int)Rows - 1, (int)Rows, 0,
(int)Columns, ' ', ' ', 0);
msg_moremsg(FALSE);
continue;
}
/* display more text, return to caller */
lines_left = toscroll;
}
break;
}
/* clear the --more-- message */
screen_fill((int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0);
State = oldState;
#ifdef FEAT_MOUSE
setmouse();
#endif
if (quit_more)
{
msg_row = Rows - 1;
msg_col = 0;
}
#ifdef FEAT_RIGHTLEFT
else if (cmdmsg_rl)
msg_col = Columns - 1;
#endif
#ifdef FEAT_CON_DIALOG
return retval;
#else
return FALSE;
#endif
}
#if defined(USE_MCH_ERRMSG) || defined(PROTO)
#ifdef mch_errmsg
# undef mch_errmsg
#endif
#ifdef mch_msg
# undef mch_msg
#endif
/*
* Give an error message. To be used when the screen hasn't been initialized
* yet. When stderr can't be used, collect error messages until the GUI has
* started and they can be displayed in a message box.
*/
void
mch_errmsg(str)
char *str;
{
int len;
#if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI)
/* On Unix use stderr if it's a tty.
* When not going to start the GUI also use stderr.
* On Mac, when started from Finder, stderr is the console. */
if (
# ifdef UNIX
# ifdef MACOS_X_UNIX
(isatty(2) && strcmp("/dev/console", ttyname(2)) != 0)
# else
isatty(2)
# endif
# ifdef FEAT_GUI
||
# endif
# endif
# ifdef FEAT_GUI
!(gui.in_use || gui.starting)
# endif
)
{
fprintf(stderr, "%s", str);
return;
}
#endif
/* avoid a delay for a message that isn't there */
emsg_on_display = FALSE;
len = (int)STRLEN(str) + 1;
if (error_ga.ga_growsize == 0)
{
error_ga.ga_growsize = 80;
error_ga.ga_itemsize = 1;
}
if (ga_grow(&error_ga, len) == OK)
{
mch_memmove((char_u *)error_ga.ga_data + error_ga.ga_len,
(char_u *)str, len);
#ifdef UNIX
/* remove CR characters, they are displayed */
{
char_u *p;
p = (char_u *)error_ga.ga_data + error_ga.ga_len;
for (;;)
{
p = vim_strchr(p, '\r');
if (p == NULL)
break;
*p = ' ';
}
}
#endif
--len; /* don't count the NUL at the end */
error_ga.ga_len += len;
}
}
/*
* Give a message. To be used when the screen hasn't been initialized yet.
* When there is no tty, collect messages until the GUI has started and they
* can be displayed in a message box.
*/
void
mch_msg(str)
char *str;
{
#if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI)
/* On Unix use stdout if we have a tty. This allows "vim -h | more" and
* uses mch_errmsg() when started from the desktop.
* When not going to start the GUI also use stdout.
* On Mac, when started from Finder, stderr is the console. */
if (
# ifdef UNIX
# ifdef MACOS_X_UNIX
(isatty(2) && strcmp("/dev/console", ttyname(2)) != 0)
# else
isatty(2)
# endif
# ifdef FEAT_GUI
||
# endif
# endif
# ifdef FEAT_GUI
!(gui.in_use || gui.starting)
# endif
)
{
printf("%s", str);
return;
}
# endif
mch_errmsg(str);
}
#endif /* USE_MCH_ERRMSG */
/*
* Put a character on the screen at the current message position and advance
* to the next position. Only for printable ASCII!
*/
static void
msg_screen_putchar(c, attr)
int c;
int attr;
{
msg_didout = TRUE; /* remember that line is not empty */
screen_putchar(c, msg_row, msg_col, attr);
#ifdef FEAT_RIGHTLEFT
if (cmdmsg_rl)
{
if (--msg_col == 0)
{
msg_col = Columns;
++msg_row;
}
}
else
#endif
{
if (++msg_col >= Columns)
{
msg_col = 0;
++msg_row;
}
}
}
void
msg_moremsg(full)
int full;
{
int attr;
char_u *s = (char_u *)_("-- More --");
attr = hl_attr(HLF_M);
screen_puts(s, (int)Rows - 1, 0, attr);
if (full)
screen_puts((char_u *)
_(" SPACE/d/j: screen/page/line down, b/u/k: up, q: quit "),
(int)Rows - 1, vim_strsize(s), attr);
}
/*
* Repeat the message for the current mode: ASKMORE, EXTERNCMD, CONFIRM or
* exmode_active.
*/
void
repeat_message()
{
if (State == ASKMORE)
{
msg_moremsg(TRUE); /* display --more-- message again */
msg_row = Rows - 1;
}
#ifdef FEAT_CON_DIALOG
else if (State == CONFIRM)
{
display_confirm_msg(); /* display ":confirm" message again */
msg_row = Rows - 1;
}
#endif
else if (State == EXTERNCMD)
{
windgoto(msg_row, msg_col); /* put cursor back */
}
else if (State == HITRETURN || State == SETWSIZE)
{
if (msg_row == Rows - 1)
{
/* Avoid drawing the "hit-enter" prompt below the previous one,
* overwrite it. Esp. useful when regaining focus and a
* FocusGained autocmd exists but didn't draw anything. */
msg_didout = FALSE;
msg_col = 0;
msg_clr_eos();
}
hit_return_msg();
msg_row = Rows - 1;
}
}
/*
* msg_check_screen - check if the screen is initialized.
* Also check msg_row and msg_col, if they are too big it may cause a crash.
* While starting the GUI the terminal codes will be set for the GUI, but the
* output goes to the terminal. Don't use the terminal codes then.
*/
static int
msg_check_screen()
{
if (!full_screen || !screen_valid(FALSE))
return FALSE;
if (msg_row >= Rows)
msg_row = Rows - 1;
if (msg_col >= Columns)
msg_col = Columns - 1;
return TRUE;
}
/*
* Clear from current message position to end of screen.
* Skip this when ":silent" was used, no need to clear for redirection.
*/
void
msg_clr_eos()
{
if (msg_silent == 0)
msg_clr_eos_force();
}
/*
* Clear from current message position to end of screen.
* Note: msg_col is not updated, so we remember the end of the message
* for msg_check().
*/
void
msg_clr_eos_force()
{
if (msg_use_printf())
{
if (full_screen) /* only when termcap codes are valid */
{
if (*T_CD)
out_str(T_CD); /* clear to end of display */
else if (*T_CE)
out_str(T_CE); /* clear to end of line */
}
}
else
{
#ifdef FEAT_RIGHTLEFT
if (cmdmsg_rl)
{
screen_fill(msg_row, msg_row + 1, 0, msg_col + 1, ' ', ' ', 0);
screen_fill(msg_row + 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0);
}
else
#endif
{
screen_fill(msg_row, msg_row + 1, msg_col, (int)Columns,
' ', ' ', 0);
screen_fill(msg_row + 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0);
}
}
}
/*
* Clear the command line.
*/
void
msg_clr_cmdline()
{
msg_row = cmdline_row;
msg_col = 0;
msg_clr_eos_force();
}
/*
* end putting a message on the screen
* call wait_return if the message does not fit in the available space
* return TRUE if wait_return not called.
*/
int
msg_end()
{
/*
* if the string is larger than the window,
* or the ruler option is set and we run into it,
* we have to redraw the window.
* Do not do this if we are abandoning the file or editing the command line.
*/
if (!exiting && need_wait_return && !(State & CMDLINE))
{
wait_return(FALSE);
return FALSE;
}
out_flush();
return TRUE;
}
/*
* If the written message runs into the shown command or ruler, we have to
* wait for hit-return and redraw the window later.
*/
void
msg_check()
{
if (msg_row == Rows - 1 && msg_col >= sc_col)
{
need_wait_return = TRUE;
redraw_cmdline = TRUE;
}
}
/*
* May write a string to the redirection file.
* When "maxlen" is -1 write the whole string, otherwise up to "maxlen" bytes.
*/
static void
redir_write(str, maxlen)
char_u *str;
int maxlen;
{
char_u *s = str;
static int cur_col = 0;
/* Don't do anything for displaying prompts and the like. */
if (redir_off)
return;
/* If 'verbosefile' is set prepare for writing in that file. */
if (*p_vfile != NUL && verbose_fd == NULL)
verbose_open();
if (redirecting())
{
/* If the string doesn't start with CR or NL, go to msg_col */
if (*s != '\n' && *s != '\r')
{
while (cur_col < msg_col)
{
#ifdef FEAT_EVAL
if (redir_reg)
write_reg_contents(redir_reg, (char_u *)" ", -1, TRUE);
else if (redir_vname)
var_redir_str((char_u *)" ", -1);
else
#endif
if (redir_fd != NULL)
fputs(" ", redir_fd);
if (verbose_fd != NULL)
fputs(" ", verbose_fd);
++cur_col;
}
}
#ifdef FEAT_EVAL
if (redir_reg)
write_reg_contents(redir_reg, s, maxlen, TRUE);
if (redir_vname)
var_redir_str(s, maxlen);
#endif
/* Write and adjust the current column. */
while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen))
{
#ifdef FEAT_EVAL
if (!redir_reg && !redir_vname)
#endif
if (redir_fd != NULL)
putc(*s, redir_fd);
if (verbose_fd != NULL)
putc(*s, verbose_fd);
if (*s == '\r' || *s == '\n')
cur_col = 0;
else if (*s == '\t')
cur_col += (8 - cur_col % 8);
else
++cur_col;
++s;
}
if (msg_silent != 0) /* should update msg_col */
msg_col = cur_col;
}
}
int
redirecting()
{
return redir_fd != NULL || *p_vfile != NUL
#ifdef FEAT_EVAL
|| redir_reg || redir_vname
#endif
;
}
/*
* Before giving verbose message.
* Must always be called paired with verbose_leave()!
*/
void
verbose_enter()
{
if (*p_vfile != NUL)
++msg_silent;
}
/*
* After giving verbose message.
* Must always be called paired with verbose_enter()!
*/
void
verbose_leave()
{
if (*p_vfile != NUL)
if (--msg_silent < 0)
msg_silent = 0;
}
/*
* Like verbose_enter() and set msg_scroll when displaying the message.
*/
void
verbose_enter_scroll()
{
if (*p_vfile != NUL)
++msg_silent;
else
/* always scroll up, don't overwrite */
msg_scroll = TRUE;
}
/*
* Like verbose_leave() and set cmdline_row when displaying the message.
*/
void
verbose_leave_scroll()
{
if (*p_vfile != NUL)
{
if (--msg_silent < 0)
msg_silent = 0;
}
else
cmdline_row = msg_row;
}
/*
* Called when 'verbosefile' is set: stop writing to the file.
*/
void
verbose_stop()
{
if (verbose_fd != NULL)
{
fclose(verbose_fd);
verbose_fd = NULL;
}
verbose_did_open = FALSE;
}
/*
* Open the file 'verbosefile'.
* Return FAIL or OK.
*/
int
verbose_open()
{
if (verbose_fd == NULL && !verbose_did_open)
{
/* Only give the error message once. */
verbose_did_open = TRUE;
verbose_fd = mch_fopen((char *)p_vfile, "a");
if (verbose_fd == NULL)
{
EMSG2(_(e_notopen), p_vfile);
return FAIL;
}
}
return OK;
}
/*
* Give a warning message (for searching).
* Use 'w' highlighting and may repeat the message after redrawing
*/
void
give_warning(message, hl)
char_u *message;
int hl;
{
/* Don't do this for ":silent". */
if (msg_silent != 0)
return;
/* Don't want a hit-enter prompt here. */
++no_wait_return;
#ifdef FEAT_EVAL
set_vim_var_string(VV_WARNINGMSG, message, -1);
#endif
vim_free(keep_msg);
keep_msg = NULL;
if (hl)
keep_msg_attr = hl_attr(HLF_W);
else
keep_msg_attr = 0;
if (msg_attr(message, keep_msg_attr) && msg_scrolled == 0)
set_keep_msg(message, keep_msg_attr);
msg_didout = FALSE; /* overwrite this message */
msg_nowait = TRUE; /* don't wait for this message */
msg_col = 0;
--no_wait_return;
}
/*
* Advance msg cursor to column "col".
*/
void
msg_advance(col)
int col;
{
if (msg_silent != 0) /* nothing to advance to */
{
msg_col = col; /* for redirection, may fill it up later */
return;
}
if (col >= Columns) /* not enough room */
col = Columns - 1;
#ifdef FEAT_RIGHTLEFT
if (cmdmsg_rl)
while (msg_col > Columns - col)
msg_putchar(' ');
else
#endif
while (msg_col < col)
msg_putchar(' ');
}
#if defined(FEAT_CON_DIALOG) || defined(PROTO)
/*
* Used for "confirm()" function, and the :confirm command prefix.
* Versions which haven't got flexible dialogs yet, and console
* versions, get this generic handler which uses the command line.
*
* type = one of:
* VIM_QUESTION, VIM_INFO, VIM_WARNING, VIM_ERROR or VIM_GENERIC
* title = title string (can be NULL for default)
* (neither used in console dialogs at the moment)
*
* Format of the "buttons" string:
* "Button1Name\nButton2Name\nButton3Name"
* The first button should normally be the default/accept
* The second button should be the 'Cancel' button
* Other buttons- use your imagination!
* A '&' in a button name becomes a shortcut, so each '&' should be before a
* different letter.
*/
int
do_dialog(type, title, message, buttons, dfltbutton, textfield, ex_cmd)
int type UNUSED;
char_u *title UNUSED;
char_u *message;
char_u *buttons;
int dfltbutton;
char_u *textfield UNUSED; /* IObuff for inputdialog(), NULL
otherwise */
int ex_cmd; /* when TRUE pressing : accepts default and starts
Ex command */
{
int oldState;
int retval = 0;
char_u *hotkeys;
int c;
int i;
#ifndef NO_CONSOLE
/* Don't output anything in silent mode ("ex -s") */
if (silent_mode)
return dfltbutton; /* return default option */
#endif
#ifdef FEAT_GUI_DIALOG
/* When GUI is running and 'c' not in 'guioptions', use the GUI dialog */
if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL)
{
c = gui_mch_dialog(type, title, message, buttons, dfltbutton,
textfield, ex_cmd);
/* avoid a hit-enter prompt without clearing the cmdline */
need_wait_return = FALSE;
emsg_on_display = FALSE;
cmdline_row = msg_row;
/* Flush output to avoid that further messages and redrawing is done
* in the wrong order. */
out_flush();
gui_mch_update();
return c;
}
#endif
oldState = State;
State = CONFIRM;
#ifdef FEAT_MOUSE
setmouse();
#endif
/*
* Since we wait for a keypress, don't make the
* user press RETURN as well afterwards.
*/
++no_wait_return;
hotkeys = msg_show_console_dialog(message, buttons, dfltbutton);
if (hotkeys != NULL)
{
for (;;)
{
/* Get a typed character directly from the user. */
c = get_keystroke();
switch (c)
{
case CAR: /* User accepts default option */
case NL:
retval = dfltbutton;
break;
case Ctrl_C: /* User aborts/cancels */
case ESC:
retval = 0;
break;
default: /* Could be a hotkey? */
if (c < 0) /* special keys are ignored here */
continue;
if (c == ':' && ex_cmd)
{
retval = dfltbutton;
ins_char_typebuf(':');
break;
}
/* Make the character lowercase, as chars in "hotkeys" are. */
c = MB_TOLOWER(c);
retval = 1;
for (i = 0; hotkeys[i]; ++i)
{
#ifdef FEAT_MBYTE
if (has_mbyte)
{
if ((*mb_ptr2char)(hotkeys + i) == c)
break;
i += (*mb_ptr2len)(hotkeys + i) - 1;
}
else
#endif
if (hotkeys[i] == c)
break;
++retval;
}
if (hotkeys[i])
break;
/* No hotkey match, so keep waiting */
continue;
}
break;
}
vim_free(hotkeys);
}
State = oldState;
#ifdef FEAT_MOUSE
setmouse();
#endif
--no_wait_return;
msg_end_prompt();
return retval;
}
static int copy_char __ARGS((char_u *from, char_u *to, int lowercase));
/*
* Copy one character from "*from" to "*to", taking care of multi-byte
* characters. Return the length of the character in bytes.
*/
static int
copy_char(from, to, lowercase)
char_u *from;
char_u *to;
int lowercase; /* make character lower case */
{
#ifdef FEAT_MBYTE
int len;
int c;
if (has_mbyte)
{
if (lowercase)
{
c = MB_TOLOWER((*mb_ptr2char)(from));
return (*mb_char2bytes)(c, to);
}
else
{
len = (*mb_ptr2len)(from);
mch_memmove(to, from, (size_t)len);
return len;
}
}
else
#endif
{
if (lowercase)
*to = (char_u)TOLOWER_LOC(*from);
else
*to = *from;
return 1;
}
}
/*
* Format the dialog string, and display it at the bottom of
* the screen. Return a string of hotkey chars (if defined) for
* each 'button'. If a button has no hotkey defined, the first character of
* the button is used.
* The hotkeys can be multi-byte characters, but without combining chars.
*
* Returns an allocated string with hotkeys, or NULL for error.
*/
static char_u *
msg_show_console_dialog(message, buttons, dfltbutton)
char_u *message;
char_u *buttons;
int dfltbutton;
{
int len = 0;
#ifdef FEAT_MBYTE
# define HOTK_LEN (has_mbyte ? MB_MAXBYTES : 1)
#else
# define HOTK_LEN 1
#endif
int lenhotkey = HOTK_LEN; /* count first button */
char_u *hotk = NULL;
char_u *msgp = NULL;
char_u *hotkp = NULL;
char_u *r;
int copy;
#define HAS_HOTKEY_LEN 30
char_u has_hotkey[HAS_HOTKEY_LEN];
int first_hotkey = FALSE; /* first char of button is hotkey */
int idx;
has_hotkey[0] = FALSE;
/*
* First loop: compute the size of memory to allocate.
* Second loop: copy to the allocated memory.
*/
for (copy = 0; copy <= 1; ++copy)
{
r = buttons;
idx = 0;
while (*r)
{
if (*r == DLG_BUTTON_SEP)
{
if (copy)
{
*msgp++ = ',';
*msgp++ = ' '; /* '\n' -> ', ' */
/* advance to next hotkey and set default hotkey */
#ifdef FEAT_MBYTE
if (has_mbyte)
hotkp += STRLEN(hotkp);
else
#endif
++hotkp;
hotkp[copy_char(r + 1, hotkp, TRUE)] = NUL;
if (dfltbutton)
--dfltbutton;
/* If no hotkey is specified first char is used. */
if (idx < HAS_HOTKEY_LEN - 1 && !has_hotkey[++idx])
first_hotkey = TRUE;
}
else
{
len += 3; /* '\n' -> ', '; 'x' -> '(x)' */
lenhotkey += HOTK_LEN; /* each button needs a hotkey */
if (idx < HAS_HOTKEY_LEN - 1)
has_hotkey[++idx] = FALSE;
}
}
else if (*r == DLG_HOTKEY_CHAR || first_hotkey)
{
if (*r == DLG_HOTKEY_CHAR)
++r;
first_hotkey = FALSE;
if (copy)
{
if (*r == DLG_HOTKEY_CHAR) /* '&&a' -> '&a' */
*msgp++ = *r;
else
{
/* '&a' -> '[a]' */
*msgp++ = (dfltbutton == 1) ? '[' : '(';
msgp += copy_char(r, msgp, FALSE);
*msgp++ = (dfltbutton == 1) ? ']' : ')';
/* redefine hotkey */
hotkp[copy_char(r, hotkp, TRUE)] = NUL;
}
}
else
{
++len; /* '&a' -> '[a]' */
if (idx < HAS_HOTKEY_LEN - 1)
has_hotkey[idx] = TRUE;
}
}
else
{
/* everything else copy literally */
if (copy)
msgp += copy_char(r, msgp, FALSE);
}
/* advance to the next character */
mb_ptr_adv(r);
}
if (copy)
{
*msgp++ = ':';
*msgp++ = ' ';
*msgp = NUL;
}
else
{
len += (int)(STRLEN(message)
+ 2 /* for the NL's */
+ STRLEN(buttons)
+ 3); /* for the ": " and NUL */
lenhotkey++; /* for the NUL */
/* If no hotkey is specified first char is used. */
if (!has_hotkey[0])
{
first_hotkey = TRUE;
len += 2; /* "x" -> "[x]" */
}
/*
* Now allocate and load the strings
*/
vim_free(confirm_msg);
confirm_msg = alloc(len);
if (confirm_msg == NULL)
return NULL;
*confirm_msg = NUL;
hotk = alloc(lenhotkey);
if (hotk == NULL)
return NULL;
*confirm_msg = '\n';
STRCPY(confirm_msg + 1, message);
msgp = confirm_msg + 1 + STRLEN(message);
hotkp = hotk;
/* Define first default hotkey. Keep the hotkey string NUL
* terminated to avoid reading past the end. */
hotkp[copy_char(buttons, hotkp, TRUE)] = NUL;
/* Remember where the choices start, displaying starts here when
* "hotkp" typed at the more prompt. */
confirm_msg_tail = msgp;
*msgp++ = '\n';
}
}
display_confirm_msg();
return hotk;
}
/*
* Display the ":confirm" message. Also called when screen resized.
*/
void
display_confirm_msg()
{
/* avoid that 'q' at the more prompt truncates the message here */
++confirm_msg_used;
if (confirm_msg != NULL)
msg_puts_attr(confirm_msg, hl_attr(HLF_M));
--confirm_msg_used;
}
#endif /* FEAT_CON_DIALOG */
#if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)
int
vim_dialog_yesno(type, title, message, dflt)
int type;
char_u *title;
char_u *message;
int dflt;
{
if (do_dialog(type,
title == NULL ? (char_u *)_("Question") : title,
message,
(char_u *)_("&Yes\n&No"), dflt, NULL, FALSE) == 1)
return VIM_YES;
return VIM_NO;
}
int
vim_dialog_yesnocancel(type, title, message, dflt)
int type;
char_u *title;
char_u *message;
int dflt;
{
switch (do_dialog(type,
title == NULL ? (char_u *)_("Question") : title,
message,
(char_u *)_("&Yes\n&No\n&Cancel"), dflt, NULL, FALSE))
{
case 1: return VIM_YES;
case 2: return VIM_NO;
}
return VIM_CANCEL;
}
int
vim_dialog_yesnoallcancel(type, title, message, dflt)
int type;
char_u *title;
char_u *message;
int dflt;
{
switch (do_dialog(type,
title == NULL ? (char_u *)"Question" : title,
message,
(char_u *)_("&Yes\n&No\nSave &All\n&Discard All\n&Cancel"),
dflt, NULL, FALSE))
{
case 1: return VIM_YES;
case 2: return VIM_NO;
case 3: return VIM_ALL;
case 4: return VIM_DISCARDALL;
}
return VIM_CANCEL;
}
#endif /* FEAT_GUI_DIALOG || FEAT_CON_DIALOG */
#if defined(FEAT_BROWSE) || defined(PROTO)
/*
* Generic browse function. Calls gui_mch_browse() when possible.
* Later this may pop-up a non-GUI file selector (external command?).
*/
char_u *
do_browse(flags, title, dflt, ext, initdir, filter, buf)
int flags; /* BROWSE_SAVE and BROWSE_DIR */
char_u *title; /* title for the window */
char_u *dflt; /* default file name (may include directory) */
char_u *ext; /* extension added */
char_u *initdir; /* initial directory, NULL for current dir or
when using path from "dflt" */
char_u *filter; /* file name filter */
buf_T *buf; /* buffer to read/write for */
{
char_u *fname;
static char_u *last_dir = NULL; /* last used directory */
char_u *tofree = NULL;
int save_browse = cmdmod.browse;
/* Must turn off browse to avoid that autocommands will get the
* flag too! */
cmdmod.browse = FALSE;
if (title == NULL || *title == NUL)
{
if (flags & BROWSE_DIR)
title = (char_u *)_("Select Directory dialog");
else if (flags & BROWSE_SAVE)
title = (char_u *)_("Save File dialog");
else
title = (char_u *)_("Open File dialog");
}
/* When no directory specified, use default file name, default dir, buffer
* dir, last dir or current dir */
if ((initdir == NULL || *initdir == NUL) && dflt != NULL && *dflt != NUL)
{
if (mch_isdir(dflt)) /* default file name is a directory */
{
initdir = dflt;
dflt = NULL;
}
else if (gettail(dflt) != dflt) /* default file name includes a path */
{
tofree = vim_strsave(dflt);
if (tofree != NULL)
{
initdir = tofree;
*gettail(initdir) = NUL;
dflt = gettail(dflt);
}
}
}
if (initdir == NULL || *initdir == NUL)
{
/* When 'browsedir' is a directory, use it */
if (STRCMP(p_bsdir, "last") != 0
&& STRCMP(p_bsdir, "buffer") != 0
&& STRCMP(p_bsdir, "current") != 0
&& mch_isdir(p_bsdir))
initdir = p_bsdir;
/* When saving or 'browsedir' is "buffer", use buffer fname */
else if (((flags & BROWSE_SAVE) || *p_bsdir == 'b')
&& buf != NULL && buf->b_ffname != NULL)
{
if (dflt == NULL || *dflt == NUL)
dflt = gettail(curbuf->b_ffname);
tofree = vim_strsave(curbuf->b_ffname);
if (tofree != NULL)
{
initdir = tofree;
*gettail(initdir) = NUL;
}
}
/* When 'browsedir' is "last", use dir from last browse */
else if (*p_bsdir == 'l')
initdir = last_dir;
/* When 'browsedir is "current", use current directory. This is the
* default already, leave initdir empty. */
}
# ifdef FEAT_GUI
if (gui.in_use) /* when this changes, also adjust f_has()! */
{
if (filter == NULL
# ifdef FEAT_EVAL
&& (filter = get_var_value((char_u *)"b:browsefilter")) == NULL
&& (filter = get_var_value((char_u *)"g:browsefilter")) == NULL
# endif
)
filter = BROWSE_FILTER_DEFAULT;
if (flags & BROWSE_DIR)
{
# if defined(FEAT_GUI_GTK) || defined(WIN3264)
/* For systems that have a directory dialog. */
fname = gui_mch_browsedir(title, initdir);
# else
/* Generic solution for selecting a directory: select a file and
* remove the file name. */
fname = gui_mch_browse(0, title, dflt, ext, initdir, (char_u *)"");
# endif
# if !defined(FEAT_GUI_GTK)
/* Win32 adds a dummy file name, others return an arbitrary file
* name. GTK+ 2 returns only the directory, */
if (fname != NULL && *fname != NUL && !mch_isdir(fname))
{
/* Remove the file name. */
char_u *tail = gettail_sep(fname);
if (tail == fname)
*tail++ = '.'; /* use current dir */
*tail = NUL;
}
# endif
}
else
fname = gui_mch_browse(flags & BROWSE_SAVE,
title, dflt, ext, initdir, filter);
/* We hang around in the dialog for a while, the user might do some
* things to our files. The Win32 dialog allows deleting or renaming
* a file, check timestamps. */
need_check_timestamps = TRUE;
did_check_timestamps = FALSE;
}
else
# endif
{
/* TODO: non-GUI file selector here */
EMSG(_("E338: Sorry, no file browser in console mode"));
fname = NULL;
}
/* keep the directory for next time */
if (fname != NULL)
{
vim_free(last_dir);
last_dir = vim_strsave(fname);
if (last_dir != NULL && !(flags & BROWSE_DIR))
{
*gettail(last_dir) = NUL;
if (*last_dir == NUL)
{
/* filename only returned, must be in current dir */
vim_free(last_dir);
last_dir = alloc(MAXPATHL);
if (last_dir != NULL)
mch_dirname(last_dir, MAXPATHL);
}
}
}
vim_free(tofree);
cmdmod.browse = save_browse;
return fname;
}
#endif
#if defined(HAVE_STDARG_H) && defined(FEAT_EVAL)
static char *e_printf = N_("E766: Insufficient arguments for printf()");
static long tv_nr __ARGS((typval_T *tvs, int *idxp));
static char *tv_str __ARGS((typval_T *tvs, int *idxp));
# ifdef FEAT_FLOAT
static double tv_float __ARGS((typval_T *tvs, int *idxp));
# endif
/*
* Get number argument from "idxp" entry in "tvs". First entry is 1.
*/
static long
tv_nr(tvs, idxp)
typval_T *tvs;
int *idxp;
{
int idx = *idxp - 1;
long n = 0;
int err = FALSE;
if (tvs[idx].v_type == VAR_UNKNOWN)
EMSG(_(e_printf));
else
{
++*idxp;
n = get_tv_number_chk(&tvs[idx], &err);
if (err)
n = 0;
}
return n;
}
/*
* Get string argument from "idxp" entry in "tvs". First entry is 1.
* Returns NULL for an error.
*/
static char *
tv_str(tvs, idxp)
typval_T *tvs;
int *idxp;
{
int idx = *idxp - 1;
char *s = NULL;
if (tvs[idx].v_type == VAR_UNKNOWN)
EMSG(_(e_printf));
else
{
++*idxp;
s = (char *)get_tv_string_chk(&tvs[idx]);
}
return s;
}
# ifdef FEAT_FLOAT
/*
* Get float argument from "idxp" entry in "tvs". First entry is 1.
*/
static double
tv_float(tvs, idxp)
typval_T *tvs;
int *idxp;
{
int idx = *idxp - 1;
double f = 0;
if (tvs[idx].v_type == VAR_UNKNOWN)
EMSG(_(e_printf));
else
{
++*idxp;
if (tvs[idx].v_type == VAR_FLOAT)
f = tvs[idx].vval.v_float;
else if (tvs[idx].v_type == VAR_NUMBER)
f = tvs[idx].vval.v_number;
else
EMSG(_("E807: Expected Float argument for printf()"));
}
return f;
}
# endif
#endif
/*
* This code was included to provide a portable vsnprintf() and snprintf().
* Some systems may provide their own, but we always use this one for
* consistency.
*
* This code is based on snprintf.c - a portable implementation of snprintf
* by Mark Martinec <mark.martinec@ijs.si>, Version 2.2, 2000-10-06.
* Included with permission. It was heavily modified to fit in Vim.
* The original code, including useful comments, can be found here:
* http://www.ijs.si/software/snprintf/
*
* This snprintf() only supports the following conversion specifiers:
* s, c, d, u, o, x, X, p (and synonyms: i, D, U, O - see below)
* with flags: '-', '+', ' ', '0' and '#'.
* An asterisk is supported for field width as well as precision.
*
* Limited support for floating point was added: 'f', 'e', 'E', 'g', 'G'.
*
* Length modifiers 'h' (short int) and 'l' (long int) are supported.
* 'll' (long long int) is not supported.
*
* The locale is not used, the string is used as a byte string. This is only
* relevant for double-byte encodings where the second byte may be '%'.
*
* It is permitted for "str_m" to be zero, and it is permitted to specify NULL
* pointer for resulting string argument if "str_m" is zero (as per ISO C99).
*
* The return value is the number of characters which would be generated
* for the given input, excluding the trailing null. If this value
* is greater or equal to "str_m", not all characters from the result
* have been stored in str, output bytes beyond the ("str_m"-1) -th character
* are discarded. If "str_m" is greater than zero it is guaranteed
* the resulting string will be null-terminated.
*/
/*
* When va_list is not supported we only define vim_snprintf().
*
* vim_vsnprintf() can be invoked with either "va_list" or a list of
* "typval_T". When the latter is not used it must be NULL.
*/
/* When generating prototypes all of this is skipped, cproto doesn't
* understand this. */
#ifndef PROTO
# ifdef HAVE_STDARG_H
/* Like vim_vsnprintf() but append to the string. */
int
vim_snprintf_add(char *str, size_t str_m, char *fmt, ...)
{
va_list ap;
int str_l;
size_t len = STRLEN(str);
size_t space;
if (str_m <= len)
space = 0;
else
space = str_m - len;
va_start(ap, fmt);
str_l = vim_vsnprintf(str + len, space, fmt, ap, NULL);
va_end(ap);
return str_l;
}
# else
/* Like vim_vsnprintf() but append to the string. */
int
vim_snprintf_add(str, str_m, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
char *str;
size_t str_m;
char *fmt;
long a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
{
size_t len = STRLEN(str);
size_t space;
if (str_m <= len)
space = 0;
else
space = str_m - len;
return vim_vsnprintf(str + len, space, fmt,
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
}
# endif
# ifdef HAVE_STDARG_H
int
vim_snprintf(char *str, size_t str_m, char *fmt, ...)
{
va_list ap;
int str_l;
va_start(ap, fmt);
str_l = vim_vsnprintf(str, str_m, fmt, ap, NULL);
va_end(ap);
return str_l;
}
int
vim_vsnprintf(str, str_m, fmt, ap, tvs)
# else
/* clumsy way to work around missing va_list */
# define get_a_arg(i) (++i, i == 2 ? a1 : i == 3 ? a2 : i == 4 ? a3 : i == 5 ? a4 : i == 6 ? a5 : i == 7 ? a6 : i == 8 ? a7 : i == 9 ? a8 : i == 10 ? a9 : a10)
/* VARARGS */
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
vim_snprintf(str, str_m, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
# endif
char *str;
size_t str_m;
char *fmt;
# ifdef HAVE_STDARG_H
va_list ap;
typval_T *tvs;
# else
long a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
# endif
{
size_t str_l = 0;
char *p = fmt;
int arg_idx = 1;
if (p == NULL)
p = "";
while (*p != NUL)
{
if (*p != '%')
{
char *q = strchr(p + 1, '%');
size_t n = (q == NULL) ? STRLEN(p) : (size_t)(q - p);
/* Copy up to the next '%' or NUL without any changes. */
if (str_l < str_m)
{
size_t avail = str_m - str_l;
mch_memmove(str + str_l, p, n > avail ? avail : n);
}
p += n;
str_l += n;
}
else
{
size_t min_field_width = 0, precision = 0;
int zero_padding = 0, precision_specified = 0, justify_left = 0;
int alternate_form = 0, force_sign = 0;
/* If both the ' ' and '+' flags appear, the ' ' flag should be
* ignored. */
int space_for_positive = 1;
/* allowed values: \0, h, l, L */
char length_modifier = '\0';
/* temporary buffer for simple numeric->string conversion */
#ifdef FEAT_FLOAT
# define TMP_LEN 350 /* On my system 1e308 is the biggest number possible.
* That sounds reasonable to use as the maximum
* printable. */
#else
# define TMP_LEN 32
#endif
char tmp[TMP_LEN];
/* string address in case of string argument */
char *str_arg;
/* natural field width of arg without padding and sign */
size_t str_arg_l;
/* unsigned char argument value - only defined for c conversion.
* N.B. standard explicitly states the char argument for the c
* conversion is unsigned */
unsigned char uchar_arg;
/* number of zeros to be inserted for numeric conversions as
* required by the precision or minimal field width */
size_t number_of_zeros_to_pad = 0;
/* index into tmp where zero padding is to be inserted */
size_t zero_padding_insertion_ind = 0;
/* current conversion specifier character */
char fmt_spec = '\0';
str_arg = NULL;
p++; /* skip '%' */
/* parse flags */
while (*p == '0' || *p == '-' || *p == '+' || *p == ' '
|| *p == '#' || *p == '\'')
{
switch (*p)
{
case '0': zero_padding = 1; break;
case '-': justify_left = 1; break;
case '+': force_sign = 1; space_for_positive = 0; break;
case ' ': force_sign = 1;
/* If both the ' ' and '+' flags appear, the ' '
* flag should be ignored */
break;
case '#': alternate_form = 1; break;
case '\'': break;
}
p++;
}
/* If the '0' and '-' flags both appear, the '0' flag should be
* ignored. */
/* parse field width */
if (*p == '*')
{
int j;
p++;
j =
#ifndef HAVE_STDARG_H
get_a_arg(arg_idx);
#else
# if defined(FEAT_EVAL)
tvs != NULL ? tv_nr(tvs, &arg_idx) :
# endif
va_arg(ap, int);
#endif
if (j >= 0)
min_field_width = j;
else
{
min_field_width = -j;
justify_left = 1;
}
}
else if (VIM_ISDIGIT((int)(*p)))
{
/* size_t could be wider than unsigned int; make sure we treat
* argument like common implementations do */
unsigned int uj = *p++ - '0';
while (VIM_ISDIGIT((int)(*p)))
uj = 10 * uj + (unsigned int)(*p++ - '0');
min_field_width = uj;
}
/* parse precision */
if (*p == '.')
{
p++;
precision_specified = 1;
if (*p == '*')
{
int j;
j =
#ifndef HAVE_STDARG_H
get_a_arg(arg_idx);
#else
# if defined(FEAT_EVAL)
tvs != NULL ? tv_nr(tvs, &arg_idx) :
# endif
va_arg(ap, int);
#endif
p++;
if (j >= 0)
precision = j;
else
{
precision_specified = 0;
precision = 0;
}
}
else if (VIM_ISDIGIT((int)(*p)))
{
/* size_t could be wider than unsigned int; make sure we
* treat argument like common implementations do */
unsigned int uj = *p++ - '0';
while (VIM_ISDIGIT((int)(*p)))
uj = 10 * uj + (unsigned int)(*p++ - '0');
precision = uj;
}
}
/* parse 'h', 'l' and 'll' length modifiers */
if (*p == 'h' || *p == 'l')
{
length_modifier = *p;
p++;
if (length_modifier == 'l' && *p == 'l')
{
/* double l = long long */
length_modifier = 'l'; /* treat it as a single 'l' */
p++;
}
}
fmt_spec = *p;
/* common synonyms: */
switch (fmt_spec)
{
case 'i': fmt_spec = 'd'; break;
case 'D': fmt_spec = 'd'; length_modifier = 'l'; break;
case 'U': fmt_spec = 'u'; length_modifier = 'l'; break;
case 'O': fmt_spec = 'o'; length_modifier = 'l'; break;
case 'F': fmt_spec = 'f'; break;
default: break;
}
/* get parameter value, do initial processing */
switch (fmt_spec)
{
/* '%' and 'c' behave similar to 's' regarding flags and field
* widths */
case '%':
case 'c':
case 's':
length_modifier = '\0';
str_arg_l = 1;
switch (fmt_spec)
{
case '%':
str_arg = p;
break;
case 'c':
{
int j;
j =
#ifndef HAVE_STDARG_H
get_a_arg(arg_idx);
#else
# if defined(FEAT_EVAL)
tvs != NULL ? tv_nr(tvs, &arg_idx) :
# endif
va_arg(ap, int);
#endif
/* standard demands unsigned char */
uchar_arg = (unsigned char)j;
str_arg = (char *)&uchar_arg;
break;
}
case 's':
str_arg =
#ifndef HAVE_STDARG_H
(char *)get_a_arg(arg_idx);
#else
# if defined(FEAT_EVAL)
tvs != NULL ? tv_str(tvs, &arg_idx) :
# endif
va_arg(ap, char *);
#endif
if (str_arg == NULL)
{
str_arg = "[NULL]";
str_arg_l = 6;
}
/* make sure not to address string beyond the specified
* precision !!! */
else if (!precision_specified)
str_arg_l = strlen(str_arg);
/* truncate string if necessary as requested by precision */
else if (precision == 0)
str_arg_l = 0;
else
{
/* Don't put the #if inside memchr(), it can be a
* macro. */
#if SIZEOF_INT <= 2
char *q = memchr(str_arg, '\0', precision);
#else
/* memchr on HP does not like n > 2^31 !!! */
char *q = memchr(str_arg, '\0',
precision <= (size_t)0x7fffffffL ? precision
: (size_t)0x7fffffffL);
#endif
str_arg_l = (q == NULL) ? precision
: (size_t)(q - str_arg);
}
break;
default:
break;
}
break;
case 'd': case 'u': case 'o': case 'x': case 'X': case 'p':
{
/* NOTE: the u, o, x, X and p conversion specifiers
* imply the value is unsigned; d implies a signed
* value */
/* 0 if numeric argument is zero (or if pointer is
* NULL for 'p'), +1 if greater than zero (or nonzero
* for unsigned arguments), -1 if negative (unsigned
* argument is never negative) */
int arg_sign = 0;
/* only defined for length modifier h, or for no
* length modifiers */
int int_arg = 0;
unsigned int uint_arg = 0;
/* only defined for length modifier l */
long int long_arg = 0;
unsigned long int ulong_arg = 0;
/* pointer argument value -only defined for p
* conversion */
void *ptr_arg = NULL;
if (fmt_spec == 'p')
{
length_modifier = '\0';
ptr_arg =
#ifndef HAVE_STDARG_H
(void *)get_a_arg(arg_idx);
#else
# if defined(FEAT_EVAL)
tvs != NULL ? (void *)tv_str(tvs, &arg_idx) :
# endif
va_arg(ap, void *);
#endif
if (ptr_arg != NULL)
arg_sign = 1;
}
else if (fmt_spec == 'd')
{
/* signed */
switch (length_modifier)
{
case '\0':
case 'h':
/* char and short arguments are passed as int. */
int_arg =
#ifndef HAVE_STDARG_H
get_a_arg(arg_idx);
#else
# if defined(FEAT_EVAL)
tvs != NULL ? tv_nr(tvs, &arg_idx) :
# endif
va_arg(ap, int);
#endif
if (int_arg > 0)
arg_sign = 1;
else if (int_arg < 0)
arg_sign = -1;
break;
case 'l':
long_arg =
#ifndef HAVE_STDARG_H
get_a_arg(arg_idx);
#else
# if defined(FEAT_EVAL)
tvs != NULL ? tv_nr(tvs, &arg_idx) :
# endif
va_arg(ap, long int);
#endif
if (long_arg > 0)
arg_sign = 1;
else if (long_arg < 0)
arg_sign = -1;
break;
}
}
else
{
/* unsigned */
switch (length_modifier)
{
case '\0':
case 'h':
uint_arg =
#ifndef HAVE_STDARG_H
get_a_arg(arg_idx);
#else
# if defined(FEAT_EVAL)
tvs != NULL ? (unsigned)
tv_nr(tvs, &arg_idx) :
# endif
va_arg(ap, unsigned int);
#endif
if (uint_arg != 0)
arg_sign = 1;
break;
case 'l':
ulong_arg =
#ifndef HAVE_STDARG_H
get_a_arg(arg_idx);
#else
# if defined(FEAT_EVAL)
tvs != NULL ? (unsigned long)
tv_nr(tvs, &arg_idx) :
# endif
va_arg(ap, unsigned long int);
#endif
if (ulong_arg != 0)
arg_sign = 1;
break;
}
}
str_arg = tmp;
str_arg_l = 0;
/* NOTE:
* For d, i, u, o, x, and X conversions, if precision is
* specified, the '0' flag should be ignored. This is so
* with Solaris 2.6, Digital UNIX 4.0, HPUX 10, Linux,
* FreeBSD, NetBSD; but not with Perl.
*/
if (precision_specified)
zero_padding = 0;
if (fmt_spec == 'd')
{
if (force_sign && arg_sign >= 0)
tmp[str_arg_l++] = space_for_positive ? ' ' : '+';
/* leave negative numbers for sprintf to handle, to
* avoid handling tricky cases like (short int)-32768 */
}
else if (alternate_form)
{
if (arg_sign != 0
&& (fmt_spec == 'x' || fmt_spec == 'X') )
{
tmp[str_arg_l++] = '0';
tmp[str_arg_l++] = fmt_spec;
}
/* alternate form should have no effect for p
* conversion, but ... */
}
zero_padding_insertion_ind = str_arg_l;
if (!precision_specified)
precision = 1; /* default precision is 1 */
if (precision == 0 && arg_sign == 0)
{
/* When zero value is formatted with an explicit
* precision 0, the resulting formatted string is
* empty (d, i, u, o, x, X, p). */
}
else
{
char f[5];
int f_l = 0;
/* construct a simple format string for sprintf */
f[f_l++] = '%';
if (!length_modifier)
;
else if (length_modifier == '2')
{
f[f_l++] = 'l';
f[f_l++] = 'l';
}
else
f[f_l++] = length_modifier;
f[f_l++] = fmt_spec;
f[f_l++] = '\0';
if (fmt_spec == 'p')
str_arg_l += sprintf(tmp + str_arg_l, f, ptr_arg);
else if (fmt_spec == 'd')
{
/* signed */
switch (length_modifier)
{
case '\0':
case 'h': str_arg_l += sprintf(
tmp + str_arg_l, f, int_arg);
break;
case 'l': str_arg_l += sprintf(
tmp + str_arg_l, f, long_arg);
break;
}
}
else
{
/* unsigned */
switch (length_modifier)
{
case '\0':
case 'h': str_arg_l += sprintf(
tmp + str_arg_l, f, uint_arg);
break;
case 'l': str_arg_l += sprintf(
tmp + str_arg_l, f, ulong_arg);
break;
}
}
/* include the optional minus sign and possible
* "0x" in the region before the zero padding
* insertion point */
if (zero_padding_insertion_ind < str_arg_l
&& tmp[zero_padding_insertion_ind] == '-')
zero_padding_insertion_ind++;
if (zero_padding_insertion_ind + 1 < str_arg_l
&& tmp[zero_padding_insertion_ind] == '0'
&& (tmp[zero_padding_insertion_ind + 1] == 'x'
|| tmp[zero_padding_insertion_ind + 1] == 'X'))
zero_padding_insertion_ind += 2;
}
{
size_t num_of_digits = str_arg_l
- zero_padding_insertion_ind;
if (alternate_form && fmt_spec == 'o'
/* unless zero is already the first
* character */
&& !(zero_padding_insertion_ind < str_arg_l
&& tmp[zero_padding_insertion_ind] == '0'))
{
/* assure leading zero for alternate-form
* octal numbers */
if (!precision_specified
|| precision < num_of_digits + 1)
{
/* precision is increased to force the
* first character to be zero, except if a
* zero value is formatted with an
* explicit precision of zero */
precision = num_of_digits + 1;
precision_specified = 1;
}
}
/* zero padding to specified precision? */
if (num_of_digits < precision)
number_of_zeros_to_pad = precision - num_of_digits;
}
/* zero padding to specified minimal field width? */
if (!justify_left && zero_padding)
{
int n = (int)(min_field_width - (str_arg_l
+ number_of_zeros_to_pad));
if (n > 0)
number_of_zeros_to_pad += n;
}
break;
}
#ifdef FEAT_FLOAT
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
{
/* Floating point. */
double f;
double abs_f;
char format[40];
int l;
int remove_trailing_zeroes = FALSE;
f =
# ifndef HAVE_STDARG_H
get_a_arg(arg_idx);
# else
# if defined(FEAT_EVAL)
tvs != NULL ? tv_float(tvs, &arg_idx) :
# endif
va_arg(ap, double);
# endif
abs_f = f < 0 ? -f : f;
if (fmt_spec == 'g' || fmt_spec == 'G')
{
/* Would be nice to use %g directly, but it prints
* "1.0" as "1", we don't want that. */
if ((abs_f >= 0.001 && abs_f < 10000000.0)
|| abs_f == 0.0)
fmt_spec = 'f';
else
fmt_spec = fmt_spec == 'g' ? 'e' : 'E';
remove_trailing_zeroes = TRUE;
}
if (fmt_spec == 'f' &&
#ifdef VAX
abs_f > 1.0e38
#else
abs_f > 1.0e307
#endif
)
{
/* Avoid a buffer overflow */
strcpy(tmp, "inf");
str_arg_l = 3;
}
else
{
format[0] = '%';
l = 1;
if (precision_specified)
{
size_t max_prec = TMP_LEN - 10;
/* Make sure we don't get more digits than we
* have room for. */
if (fmt_spec == 'f' && abs_f > 1.0)
max_prec -= (size_t)log10(abs_f);
if (precision > max_prec)
precision = max_prec;
l += sprintf(format + 1, ".%d", (int)precision);
}
format[l] = fmt_spec;
format[l + 1] = NUL;
str_arg_l = sprintf(tmp, format, f);
if (remove_trailing_zeroes)
{
int i;
char *tp;
/* Using %g or %G: remove superfluous zeroes. */
if (fmt_spec == 'f')
tp = tmp + str_arg_l - 1;
else
{
tp = (char *)vim_strchr((char_u *)tmp,
fmt_spec == 'e' ? 'e' : 'E');
if (tp != NULL)
{
/* Remove superfluous '+' and leading
* zeroes from the exponent. */
if (tp[1] == '+')
{
/* Change "1.0e+07" to "1.0e07" */
STRMOVE(tp + 1, tp + 2);
--str_arg_l;
}
i = (tp[1] == '-') ? 2 : 1;
while (tp[i] == '0')
{
/* Change "1.0e07" to "1.0e7" */
STRMOVE(tp + i, tp + i + 1);
--str_arg_l;
}
--tp;
}
}
if (tp != NULL && !precision_specified)
/* Remove trailing zeroes, but keep the one
* just after a dot. */
while (tp > tmp + 2 && *tp == '0'
&& tp[-1] != '.')
{
STRMOVE(tp, tp + 1);
--tp;
--str_arg_l;
}
}
else
{
char *tp;
/* Be consistent: some printf("%e") use 1.0e+12
* and some 1.0e+012. Remove one zero in the last
* case. */
tp = (char *)vim_strchr((char_u *)tmp,
fmt_spec == 'e' ? 'e' : 'E');
if (tp != NULL && (tp[1] == '+' || tp[1] == '-')
&& tp[2] == '0'
&& vim_isdigit(tp[3])
&& vim_isdigit(tp[4]))
{
STRMOVE(tp + 2, tp + 3);
--str_arg_l;
}
}
}
str_arg = tmp;
break;
}
#endif
default:
/* unrecognized conversion specifier, keep format string
* as-is */
zero_padding = 0; /* turn zero padding off for non-numeric
conversion */
justify_left = 1;
min_field_width = 0; /* reset flags */
/* discard the unrecognized conversion, just keep *
* the unrecognized conversion character */
str_arg = p;
str_arg_l = 0;
if (*p != NUL)
str_arg_l++; /* include invalid conversion specifier
unchanged if not at end-of-string */
break;
}
if (*p != NUL)
p++; /* step over the just processed conversion specifier */
/* insert padding to the left as requested by min_field_width;
* this does not include the zero padding in case of numerical
* conversions*/
if (!justify_left)
{
/* left padding with blank or zero */
int pn = (int)(min_field_width - (str_arg_l + number_of_zeros_to_pad));
if (pn > 0)
{
if (str_l < str_m)
{
size_t avail = str_m - str_l;
vim_memset(str + str_l, zero_padding ? '0' : ' ',
(size_t)pn > avail ? avail
: (size_t)pn);
}
str_l += pn;
}
}
/* zero padding as requested by the precision or by the minimal
* field width for numeric conversions required? */
if (number_of_zeros_to_pad == 0)
{
/* will not copy first part of numeric right now, *
* force it to be copied later in its entirety */
zero_padding_insertion_ind = 0;
}
else
{
/* insert first part of numerics (sign or '0x') before zero
* padding */
int zn = (int)zero_padding_insertion_ind;
if (zn > 0)
{
if (str_l < str_m)
{
size_t avail = str_m - str_l;
mch_memmove(str + str_l, str_arg,
(size_t)zn > avail ? avail
: (size_t)zn);
}
str_l += zn;
}
/* insert zero padding as requested by the precision or min
* field width */
zn = (int)number_of_zeros_to_pad;
if (zn > 0)
{
if (str_l < str_m)
{
size_t avail = str_m-str_l;
vim_memset(str + str_l, '0',
(size_t)zn > avail ? avail
: (size_t)zn);
}
str_l += zn;
}
}
/* insert formatted string
* (or as-is conversion specifier for unknown conversions) */
{
int sn = (int)(str_arg_l - zero_padding_insertion_ind);
if (sn > 0)
{
if (str_l < str_m)
{
size_t avail = str_m - str_l;
mch_memmove(str + str_l,
str_arg + zero_padding_insertion_ind,
(size_t)sn > avail ? avail : (size_t)sn);
}
str_l += sn;
}
}
/* insert right padding */
if (justify_left)
{
/* right blank padding to the field width */
int pn = (int)(min_field_width
- (str_arg_l + number_of_zeros_to_pad));
if (pn > 0)
{
if (str_l < str_m)
{
size_t avail = str_m - str_l;
vim_memset(str + str_l, ' ',
(size_t)pn > avail ? avail
: (size_t)pn);
}
str_l += pn;
}
}
}
}
if (str_m > 0)
{
/* make sure the string is nul-terminated even at the expense of
* overwriting the last character (shouldn't happen, but just in case)
* */
str[str_l <= str_m - 1 ? str_l : str_m - 1] = '\0';
}
#ifdef HAVE_STDARG_H
if (tvs != NULL && tvs[arg_idx - 1].v_type != VAR_UNKNOWN)
EMSG(_("E767: Too many arguments to printf()"));
#endif
/* Return the number of characters formatted (excluding trailing nul
* character), that is, the number of characters that would have been
* written to the buffer if it were large enough. */
return (int)str_l;
}
#endif /* PROTO */
| zyz2011-vim | src/message.c | C | gpl2 | 113,273 |
/* vi:set ts=8 sts=4 sw=4:
*
* MzScheme interface for Vim, wrapper around scheme.h
*/
#ifndef _IF_MZSCH_H_
#define _IF_MZSCH_H_
#ifdef __MINGW32__
/* Hack to engage Cygwin-specific settings */
# define __CYGWIN32__
#endif
/* #ifdef needed for "make depend" */
#ifdef FEAT_MZSCHEME
# include <schvers.h>
# include <scheme.h>
#endif
#ifdef __MINGW32__
# undef __CYGWIN32__
#endif
#if MZSCHEME_VERSION_MAJOR >= 299
/* macros to be compatible with 20x versions */
# define scheme_config scheme_current_config()
# define scheme_make_string scheme_make_byte_string
# define scheme_make_string_output_port scheme_make_byte_string_output_port
# define scheme_get_sized_string_output scheme_get_sized_byte_string_output
# define scheme_write_string scheme_write_byte_string
# define scheme_make_sized_string scheme_make_sized_byte_string
# define SCHEME_STRINGP(obj) (SCHEME_BYTE_STRINGP(obj) || SCHEME_CHAR_STRINGP(obj))
# define SCHEME_STR_VAL(obj) SCHEME_BYTE_STR_VAL( \
(SCHEME_BYTE_STRINGP(obj) ? obj : scheme_char_string_to_byte_string(obj)))
# define GUARANTEE_STRING(fname, argnum) GUARANTEE_TYPE(fname, argnum, SCHEME_STRINGP, "string")
# ifdef scheme_format
# undef scheme_format
# endif
# define scheme_format scheme_format_utf8
# define SCHEME_GET_BYTE_STRING(obj) (SCHEME_BYTE_STRINGP(obj) ? obj : \
scheme_char_string_to_byte_string(obj))
#else
# define SCHEME_GET_BYTE_STRING(obj) (obj)
# define SCHEME_BYTE_STRLEN_VAL SCHEME_STRLEN_VAL
# define SCHEME_BYTE_STR_VAL SCHEME_STR_VAL
# define scheme_byte_string_to_char_string(obj) (obj)
#endif
/* Precise GC macros */
#ifndef MZ_GC_DECL_REG
# define MZ_GC_DECL_REG(size) /* empty */
#endif
#ifndef MZ_GC_VAR_IN_REG
# define MZ_GC_VAR_IN_REG(x, v) /* empty */
#endif
#ifndef MZ_GC_ARRAY_VAR_IN_REG
# define MZ_GC_ARRAY_VAR_IN_REG(x, v, l) /* empty */
#endif
#ifndef MZ_GC_REG
# define MZ_GC_REG() /* empty */
#endif
#ifndef MZ_GC_UNREG
# define MZ_GC_UNREG() /* empty */
#endif
#ifdef MZSCHEME_FORCE_GC
/*
* force garbage collection to check all references are registered
* seg faults will indicate not registered refs
*/
# define MZ_GC_CHECK() scheme_collect_garbage();
#else
# define MZ_GC_CHECK() /* empty */
#endif
#endif /* _IF_MZSCH_H_ */
| zyz2011-vim | src/if_mzsch.h | C | gpl2 | 2,233 |
/* vi:set ts=8 sts=8 sw=8:
*
* VIM - Vi IMproved by Bram Moolenaar
* Visual Workshop integration by Gordon Prieur
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*/
#ifndef WSDEBUG_H
#define WSDEBUG_H
#ifdef WSDEBUG
#ifndef ASSERT
#define ASSERT(c) \
if (!(c)) { \
fprintf(stderr, "Assertion failed: line %d, file %s\n", \
__LINE__, __FILE__); \
fflush(stderr); \
abort(); \
}
#endif
#define WS_TRACE 0x00000001
#define WS_TRACE_VERBOSE 0x00000002
#define WS_TRACE_COLONCMD 0x00000004
#define WS_DEBUG_ALL 0xffffffff
#define WSDLEVEL(flags) (ws_debug != NULL && (ws_dlevel & (flags)))
#ifdef USE_WDDUMP
#include "wdump.h"
#endif
#define WSDEBUG_TRACE 1
//#define WSDEBUG_SENSE 2
typedef enum {
WT_ENV = 1, /* look for env var if set */
WT_WAIT, /* look for ~/.gvimwait if set */
WT_STOP /* look for ~/.gvimstop if set */
} WtWait;
void wsdebug(char *, ...);
void wstrace(char *, ...);
extern FILE *ws_debug;
extern u_int ws_dlevel; /* ws_debug verbosity level */
# else /* not WSDEBUG */
#ifndef ASSERT
# define ASSERT(c)
#endif
/*
* The following 2 stubs are needed because a macro cannot be used because of
* the variable number of arguments.
*/
void
wsdebug(
char *fmt,
...)
{
}
void
wstrace(
char *fmt,
...)
{
}
#endif /* WSDEBUG */
#endif /* WSDEBUG_H */
| zyz2011-vim | src/wsdebug.h | C | gpl2 | 1,420 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*/
#ifdef __QNXNTO__
# include <sys/procmgr.h>
#endif
#define USE_TMPNAM
#define POSIX /* Used by pty.c */
#if defined(FEAT_GUI_PHOTON)
extern int is_photon_available;
#endif
| zyz2011-vim | src/os_qnx.h | C | gpl2 | 393 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* dosinst.c: Install program for Vim on MS-DOS and MS-Windows
*
* Compile with Make_mvc.mak, Make_bc3.mak, Make_bc5.mak or Make_djg.mak.
*/
/*
* Include common code for dosinst.c and uninstal.c.
*/
#define DOSINST
#include "dosinst.h"
/* Macro to do an error check I was typing over and over */
#define CHECK_REG_ERROR(code) if (code != ERROR_SUCCESS) { printf("%ld error number: %ld\n", (long)__LINE__, (long)code); return 1; }
int has_vim = 0; /* installable vim.exe exists */
int has_gvim = 0; /* installable gvim.exe exists */
char oldvimrc[BUFSIZE]; /* name of existing vimrc file */
char vimrc[BUFSIZE]; /* name of vimrc file to create */
char *default_bat_dir = NULL; /* when not NULL, use this as the default
directory to write .bat files in */
char *default_vim_dir = NULL; /* when not NULL, use this as the default
install dir for NSIS */
/*
* Structure used for each choice the user can make.
*/
struct choice
{
int active; /* non-zero when choice is active */
char *text; /* text displayed for this choice */
void (*changefunc)(int idx); /* function to change this choice */
int arg; /* argument for function */
void (*installfunc)(int idx); /* function to install this choice */
};
struct choice choices[30]; /* choices the user can make */
int choice_count = 0; /* number of choices available */
#define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s))
enum
{
compat_vi = 1,
compat_some_enhancements,
compat_all_enhancements
};
char *(compat_choices[]) =
{
"\nChoose the default way to run Vim:",
"Vi compatible",
"with some Vim enhancements",
"with syntax highlighting and other features switched on",
};
int compat_choice = (int)compat_all_enhancements;
char *compat_text = "- run Vim %s";
enum
{
remap_no = 1,
remap_win
};
char *(remap_choices[]) =
{
"\nChoose:",
"Do not remap keys for Windows behavior",
"Remap a few keys for Windows behavior (<C-V>, <C-C>, etc)",
};
int remap_choice = (int)remap_win;
char *remap_text = "- %s";
enum
{
mouse_xterm = 1,
mouse_mswin
};
char *(mouse_choices[]) =
{
"\nChoose the way how Vim uses the mouse:",
"right button extends selection (the Unix way)",
"right button has a popup menu (the Windows way)",
};
int mouse_choice = (int)mouse_mswin;
char *mouse_text = "- The mouse %s";
enum
{
vimfiles_dir_none = 1,
vimfiles_dir_vim,
vimfiles_dir_home
};
static char *(vimfiles_dir_choices[]) =
{
"\nCreate plugin directories:",
"No",
"In the VIM directory",
"In your HOME directory",
};
static int vimfiles_dir_choice;
/* non-zero when selected to install the popup menu entry. */
static int install_popup = 0;
/* non-zero when selected to install the "Open with" entry. */
static int install_openwith = 0;
/* non-zero when need to add an uninstall entry in the registry */
static int need_uninstall_entry = 0;
/*
* Definitions of the directory name (under $VIM) of the vimfiles directory
* and its subdirectories:
*/
static char *(vimfiles_subdirs[]) =
{
"colors",
"compiler",
"doc",
"ftdetect",
"ftplugin",
"indent",
"keymap",
"plugin",
"syntax",
};
/*
* Obtain a choice from a table.
* First entry is a question, others are choices.
*/
static int
get_choice(char **table, int entries)
{
int answer;
int idx;
char dummy[100];
do
{
for (idx = 0; idx < entries; ++idx)
{
if (idx)
printf("%2d ", idx);
printf(table[idx]);
printf("\n");
}
printf("Choice: ");
if (scanf("%d", &answer) != 1)
{
scanf("%99s", dummy);
answer = 0;
}
}
while (answer < 1 || answer >= entries);
return answer;
}
/*
* Check if the user unpacked the archives properly.
* Sets "runtimeidx".
*/
static void
check_unpack(void)
{
char buf[BUFSIZE];
FILE *fd;
struct stat st;
/* check for presence of the correct version number in installdir[] */
runtimeidx = strlen(installdir) - strlen(VIM_VERSION_NODOT);
if (runtimeidx <= 0
|| stricmp(installdir + runtimeidx, VIM_VERSION_NODOT) != 0
|| (installdir[runtimeidx - 1] != '/'
&& installdir[runtimeidx - 1] != '\\'))
{
printf("ERROR: Install program not in directory \"%s\"\n",
VIM_VERSION_NODOT);
printf("This program can only work when it is located in its original directory\n");
myexit(1);
}
/* check if filetype.vim is present, which means the runtime archive has
* been unpacked */
sprintf(buf, "%s\\filetype.vim", installdir);
if (stat(buf, &st) < 0)
{
printf("ERROR: Cannot find filetype.vim in \"%s\"\n", installdir);
printf("It looks like you did not unpack the runtime archive.\n");
printf("You must unpack the runtime archive \"vim%srt.zip\" before installing.\n",
VIM_VERSION_NODOT + 3);
myexit(1);
}
/* Check if vim.exe or gvim.exe is in the current directory. */
if ((fd = fopen("gvim.exe", "r")) != NULL)
{
fclose(fd);
has_gvim = 1;
}
if ((fd = fopen("vim.exe", "r")) != NULL)
{
fclose(fd);
has_vim = 1;
}
if (!has_gvim && !has_vim)
{
printf("ERROR: Cannot find any Vim executables in \"%s\"\n\n",
installdir);
myexit(1);
}
}
/*
* Compare paths "p[plen]" to "q[qlen]". Return 0 if they match.
* Ignores case and differences between '/' and '\'.
* "plen" and "qlen" can be negative, strlen() is used then.
*/
static int
pathcmp(char *p, int plen, char *q, int qlen)
{
int i;
if (plen < 0)
plen = strlen(p);
if (qlen < 0)
qlen = strlen(q);
for (i = 0; ; ++i)
{
/* End of "p": check if "q" also ends or just has a slash. */
if (i == plen)
{
if (i == qlen) /* match */
return 0;
if (i == qlen - 1 && (q[i] == '\\' || q[i] == '/'))
return 0; /* match with trailing slash */
return 1; /* no match */
}
/* End of "q": check if "p" also ends or just has a slash. */
if (i == qlen)
{
if (i == plen) /* match */
return 0;
if (i == plen - 1 && (p[i] == '\\' || p[i] == '/'))
return 0; /* match with trailing slash */
return 1; /* no match */
}
if (!(mytoupper(p[i]) == mytoupper(q[i])
|| ((p[i] == '/' || p[i] == '\\')
&& (q[i] == '/' || q[i] == '\\'))))
return 1; /* no match */
}
/*NOTREACHED*/
}
/*
* If the executable "**destination" is in the install directory, find another
* one in $PATH.
* On input "**destination" is the path of an executable in allocated memory
* (or NULL).
* "*destination" is set to NULL or the location of the file.
*/
static void
findoldfile(char **destination)
{
char *bp = *destination;
size_t indir_l = strlen(installdir);
char *cp = bp + indir_l;
char *tmpname;
char *farname;
/*
* No action needed if exe not found or not in this directory.
*/
if (bp == NULL
|| strnicmp(bp, installdir, indir_l) != 0
|| strchr("/\\", *cp++) == NULL
|| strchr(cp, '\\') != NULL
|| strchr(cp, '/') != NULL)
return;
tmpname = alloc((int)strlen(cp) + 1);
strcpy(tmpname, cp);
tmpname[strlen(tmpname) - 1] = 'x'; /* .exe -> .exx */
if (access(tmpname, 0) == 0)
{
printf("\nERROR: %s and %s clash. Remove or rename %s.\n",
tmpname, cp, tmpname);
myexit(1);
}
if (rename(cp, tmpname) != 0)
{
printf("\nERROR: failed to rename %s to %s: %s\n",
cp, tmpname, strerror(0));
myexit(1);
}
farname = searchpath_save(cp);
if (rename(tmpname, cp) != 0)
{
printf("\nERROR: failed to rename %s back to %s: %s\n",
tmpname, cp, strerror(0));
myexit(1);
}
free(*destination);
free(tmpname);
*destination = farname;
}
/*
* Check if there is a vim.[exe|bat|, gvim.[exe|bat|, etc. in the path.
* When "check_bat_only" is TRUE, only find "default_bat_dir".
*/
static void
find_bat_exe(int check_bat_only)
{
int i;
/* avoid looking in the "installdir" by chdir to system root */
mch_chdir(sysdrive);
mch_chdir("\\");
for (i = 1; i < TARGET_COUNT; ++i)
{
targets[i].oldbat = searchpath_save(targets[i].batname);
if (!check_bat_only)
targets[i].oldexe = searchpath_save(targets[i].exename);
if (default_bat_dir == NULL && targets[i].oldbat != NULL)
{
default_bat_dir = alloc(strlen(targets[i].oldbat) + 1);
strcpy(default_bat_dir, targets[i].oldbat);
remove_tail(default_bat_dir);
}
if (check_bat_only && targets[i].oldbat != NULL)
{
free(targets[i].oldbat);
targets[i].oldbat = NULL;
}
}
mch_chdir(installdir);
}
#ifdef WIN3264
/*
* Get the value of $VIMRUNTIME or $VIM and write it in $TEMP/vimini.ini, so
* that NSIS can read it.
* When not set, use the directory of a previously installed Vim.
*/
static void
get_vim_env(void)
{
char *vim;
char buf[BUFSIZE];
FILE *fd;
char fname[BUFSIZE];
/* First get $VIMRUNTIME. If it's set, remove the tail. */
vim = getenv("VIMRUNTIME");
if (vim != NULL && *vim != 0)
{
strcpy(buf, vim);
remove_tail(buf);
vim = buf;
}
else
{
vim = getenv("VIM");
if (vim == NULL || *vim == 0)
{
/* Use the directory from an old uninstall entry. */
if (default_vim_dir != NULL)
vim = default_vim_dir;
else
/* Let NSIS know there is no default, it should use
* $PROGRAMFILES. */
vim = "";
}
}
/* NSIS also uses GetTempPath(), thus we should get the same directory
* name as where NSIS will look for vimini.ini. */
GetTempPath(BUFSIZE, fname);
add_pathsep(fname);
strcat(fname, "vimini.ini");
fd = fopen(fname, "w");
if (fd != NULL)
{
/* Make it look like an .ini file, so that NSIS can read it with a
* ReadINIStr command. */
fprintf(fd, "[vimini]\n");
fprintf(fd, "dir=\"%s\"\n", vim);
fclose(fd);
}
else
{
printf("Failed to open %s\n", fname);
sleep(2);
}
}
static int num_windows;
/*
* Callback used for EnumWindows():
* Count the window if the title looks like it is for the uninstaller.
*/
/*ARGSUSED*/
static BOOL CALLBACK
window_cb(HWND hwnd, LPARAM lparam)
{
char title[256];
title[0] = 0;
GetWindowText(hwnd, title, 256);
if (strstr(title, "Vim ") != NULL && strstr(title, "Uninstall:") != NULL)
++num_windows;
return TRUE;
}
/*
* Check for already installed Vims.
* Return non-zero when found one.
*/
static int
uninstall_check(int skip_question)
{
HKEY key_handle;
HKEY uninstall_key_handle;
char *uninstall_key = "software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
char subkey_name_buff[BUFSIZE];
char temp_string_buffer[BUFSIZE];
DWORD local_bufsize = BUFSIZE;
FILETIME temp_pfiletime;
DWORD key_index;
char input;
long code;
DWORD value_type;
DWORD orig_num_keys;
DWORD new_num_keys;
int foundone = 0;
code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, uninstall_key, 0,
KEY_WOW64_64KEY | KEY_READ, &key_handle);
CHECK_REG_ERROR(code);
for (key_index = 0;
RegEnumKeyEx(key_handle, key_index, subkey_name_buff, &local_bufsize,
NULL, NULL, NULL, &temp_pfiletime) != ERROR_NO_MORE_ITEMS;
key_index++)
{
local_bufsize = BUFSIZE;
if (strncmp("Vim", subkey_name_buff, 3) == 0)
{
/* Open the key named Vim* */
code = RegOpenKeyEx(key_handle, subkey_name_buff, 0,
KEY_WOW64_64KEY | KEY_READ, &uninstall_key_handle);
CHECK_REG_ERROR(code);
/* get the DisplayName out of it to show the user */
code = RegQueryValueEx(uninstall_key_handle, "displayname", 0,
&value_type, (LPBYTE)temp_string_buffer,
&local_bufsize);
local_bufsize = BUFSIZE;
CHECK_REG_ERROR(code);
foundone = 1;
printf("\n*********************************************************\n");
printf("Vim Install found what looks like an existing Vim version.\n");
printf("The name of the entry is:\n");
printf("\n \"%s\"\n\n", temp_string_buffer);
printf("Installing the new version will disable part of the existing version.\n");
printf("(The batch files used in a console and the \"Edit with Vim\" entry in\n");
printf("the popup menu will use the new version)\n");
if (skip_question)
printf("\nRunning uninstall program for \"%s\"\n", temp_string_buffer);
else
printf("\nDo you want to uninstall \"%s\" now?\n(y)es/(n)o) ", temp_string_buffer);
fflush(stdout);
/* get the UninstallString */
code = RegQueryValueEx(uninstall_key_handle, "uninstallstring", 0,
&value_type, (LPBYTE)temp_string_buffer, &local_bufsize);
local_bufsize = BUFSIZE;
CHECK_REG_ERROR(code);
/* Remember the directory, it is used as the default for NSIS. */
default_vim_dir = alloc(strlen(temp_string_buffer) + 1);
strcpy(default_vim_dir, temp_string_buffer);
remove_tail(default_vim_dir);
remove_tail(default_vim_dir);
input = 'n';
do
{
if (input != 'n')
printf("%c is an invalid reply. Please enter either 'y' or 'n'\n", input);
if (skip_question)
input = 'y';
else
{
rewind(stdin);
scanf("%c", &input);
}
switch (input)
{
case 'y':
case 'Y':
/* save the number of uninstall keys so we can know if
* it changed */
RegQueryInfoKey(key_handle, NULL, NULL, NULL,
&orig_num_keys, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
/* Find existing .bat files before deleting them. */
find_bat_exe(TRUE);
/* Execute the uninstall program. Put it in double
* quotes if there is an embedded space. */
{
char buf[BUFSIZE];
if (strchr(temp_string_buffer, ' ') != NULL)
sprintf(buf, "\"%s\"", temp_string_buffer);
else
strcpy(buf, temp_string_buffer);
run_command(buf);
}
/* Count the number of windows with a title that match
* the installer, so that we can check when it's done.
* The uninstaller copies itself, executes the copy
* and exits, thus we can't wait for the process to
* finish. */
sleep(1); /* wait for uninstaller to start up */
num_windows = 0;
EnumWindows(window_cb, 0);
sleep(1); /* wait for windows to be counted */
if (num_windows == 0)
{
/* Did not find the uninstaller, ask user to press
* Enter when done. Just in case. */
printf("Press Enter when the uninstaller is finished\n");
rewind(stdin);
(void)getchar();
}
else
{
printf("Waiting for the uninstaller to finish (press CTRL-C to abort).");
do
{
printf(".");
fflush(stdout);
num_windows = 0;
EnumWindows(window_cb, 0);
sleep(1); /* wait for windows to be counted */
} while (num_windows > 0);
}
printf("\nDone!\n");
/* Check if an uninstall reg key was deleted.
* if it was, we want to decrement key_index.
* if we don't do this, we will skip the key
* immediately after any key that we delete. */
RegQueryInfoKey(key_handle, NULL, NULL, NULL,
&new_num_keys, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
if (new_num_keys < orig_num_keys)
key_index--;
input = 'y';
break;
case 'n':
case 'N':
/* Do not uninstall */
input = 'n';
break;
default: /* just drop through and redo the loop */
break;
}
} while (input != 'n' && input != 'y');
RegCloseKey(uninstall_key_handle);
}
}
RegCloseKey(key_handle);
return foundone;
}
#endif
/*
* Find out information about the system.
*/
static void
inspect_system(void)
{
char *p;
char buf[BUFSIZE];
FILE *fd;
int i;
int foundone;
/* This may take a little while, let the user know what we're doing. */
printf("Inspecting system...\n");
/*
* If $VIM is set, check that it's pointing to our directory.
*/
p = getenv("VIM");
if (p != NULL && pathcmp(p, -1, installdir, runtimeidx - 1) != 0)
{
printf("------------------------------------------------------\n");
printf("$VIM is set to \"%s\".\n", p);
printf("This is different from where this version of Vim is:\n");
strcpy(buf, installdir);
*(buf + runtimeidx - 1) = NUL;
printf("\"%s\"\n", buf);
printf("You must adjust or remove the setting of $VIM,\n");
if (interactive)
{
printf("to be able to use this install program.\n");
myexit(1);
}
printf("otherwise Vim WILL NOT WORK properly!\n");
printf("------------------------------------------------------\n");
}
/*
* If $VIMRUNTIME is set, check that it's pointing to our runtime directory.
*/
p = getenv("VIMRUNTIME");
if (p != NULL && pathcmp(p, -1, installdir, -1) != 0)
{
printf("------------------------------------------------------\n");
printf("$VIMRUNTIME is set to \"%s\".\n", p);
printf("This is different from where this version of Vim is:\n");
printf("\"%s\"\n", installdir);
printf("You must adjust or remove the setting of $VIMRUNTIME,\n");
if (interactive)
{
printf("to be able to use this install program.\n");
myexit(1);
}
printf("otherwise Vim WILL NOT WORK properly!\n");
printf("------------------------------------------------------\n");
}
/*
* Check if there is a vim.[exe|bat|, gvim.[exe|bat|, etc. in the path.
*/
find_bat_exe(FALSE);
/*
* A .exe in the install directory may be found anyway on Windows 2000.
* Check for this situation and find another executable if necessary.
* w.briscoe@ponl.com 2001-01-20
*/
foundone = 0;
for (i = 1; i < TARGET_COUNT; ++i)
{
findoldfile(&(targets[i].oldexe));
if (targets[i].oldexe != NULL)
foundone = 1;
}
if (foundone)
{
printf("Warning: Found Vim executable(s) in your $PATH:\n");
for (i = 1; i < TARGET_COUNT; ++i)
if (targets[i].oldexe != NULL)
printf("%s\n", targets[i].oldexe);
printf("It will be used instead of the version you are installing.\n");
printf("Please delete or rename it, or adjust your $PATH setting.\n");
}
/*
* Check if there is an existing ../_vimrc or ../.vimrc file.
*/
strcpy(oldvimrc, installdir);
strcpy(oldvimrc + runtimeidx, "_vimrc");
if ((fd = fopen(oldvimrc, "r")) == NULL)
{
strcpy(oldvimrc + runtimeidx, "vimrc~1"); /* short version of .vimrc */
if ((fd = fopen(oldvimrc, "r")) == NULL)
{
strcpy(oldvimrc + runtimeidx, ".vimrc");
fd = fopen(oldvimrc, "r");
}
}
if (fd != NULL)
fclose(fd);
else
*oldvimrc = NUL;
}
/*
* Add a dummy choice to avoid that the numbering changes depending on items
* in the environment. The user may type a number he remembered without
* looking.
*/
static void
add_dummy_choice(void)
{
choices[choice_count].installfunc = NULL;
choices[choice_count].active = 0;
choices[choice_count].changefunc = NULL;
choices[choice_count].installfunc = NULL;
++choice_count;
}
/***********************************************
* stuff for creating the batch files.
*/
/*
* Install the vim.bat, gvim.bat, etc. files.
*/
static void
install_bat_choice(int idx)
{
char *batpath = targets[choices[idx].arg].batpath;
char *oldname = targets[choices[idx].arg].oldbat;
char *exename = targets[choices[idx].arg].exenamearg;
char *vimarg = targets[choices[idx].arg].exearg;
FILE *fd;
if (*batpath != NUL)
{
fd = fopen(batpath, "w");
if (fd == NULL)
printf("\nERROR: Cannot open \"%s\" for writing.\n", batpath);
else
{
need_uninstall_entry = 1;
fprintf(fd, "@echo off\n");
fprintf(fd, "rem -- Run Vim --\n");
fprintf(fd, "\n");
/* Don't use double quotes for the "set" argument, also when it
* contains a space. The quotes would be included in the value
* for MSDOS and NT.
* The order of preference is:
* 1. $VIMRUNTIME/vim.exe (user preference)
* 2. $VIM/vim70/vim.exe (hard coded version)
* 3. installdir/vim.exe (hard coded install directory)
*/
fprintf(fd, "set VIM_EXE_DIR=%s\n", installdir);
fprintf(fd, "if exist \"%%VIM%%\\%s\\%s\" set VIM_EXE_DIR=%%VIM%%\\%s\n",
VIM_VERSION_NODOT, exename, VIM_VERSION_NODOT);
fprintf(fd, "if exist \"%%VIMRUNTIME%%\\%s\" set VIM_EXE_DIR=%%VIMRUNTIME%%\n", exename);
fprintf(fd, "\n");
/* Give an error message when the executable could not be found. */
fprintf(fd, "if exist \"%%VIM_EXE_DIR%%\\%s\" goto havevim\n",
exename);
fprintf(fd, "echo \"%%VIM_EXE_DIR%%\\%s\" not found\n", exename);
fprintf(fd, "goto eof\n");
fprintf(fd, "\n");
fprintf(fd, ":havevim\n");
fprintf(fd, "rem collect the arguments in VIMARGS for Win95\n");
fprintf(fd, "set VIMARGS=\n");
if (*exename == 'g')
fprintf(fd, "set VIMNOFORK=\n");
fprintf(fd, ":loopstart\n");
fprintf(fd, "if .%%1==. goto loopend\n");
if (*exename == 'g')
{
fprintf(fd, "if NOT .%%1==.-f goto noforkarg\n");
fprintf(fd, "set VIMNOFORK=1\n");
fprintf(fd, ":noforkarg\n");
}
fprintf(fd, "set VIMARGS=%%VIMARGS%% %%1\n");
fprintf(fd, "shift\n");
fprintf(fd, "goto loopstart\n");
fprintf(fd, ":loopend\n");
fprintf(fd, "\n");
fprintf(fd, "if .%%OS%%==.Windows_NT goto ntaction\n");
fprintf(fd, "\n");
/* For gvim.exe use "start" to avoid that the console window stays
* open. */
if (*exename == 'g')
{
fprintf(fd, "if .%%VIMNOFORK%%==.1 goto nofork\n");
fprintf(fd, "start ");
}
/* Always use quotes, $VIM or $VIMRUNTIME might have a space. */
fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n",
exename, vimarg);
fprintf(fd, "goto eof\n");
fprintf(fd, "\n");
if (*exename == 'g')
{
fprintf(fd, ":nofork\n");
fprintf(fd, "start /w ");
/* Always use quotes, $VIM or $VIMRUNTIME might have a space. */
fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n",
exename, vimarg);
fprintf(fd, "goto eof\n");
fprintf(fd, "\n");
}
fprintf(fd, ":ntaction\n");
fprintf(fd, "rem for WinNT we can use %%*\n");
/* For gvim.exe use "start /b" to avoid that the console window
* stays open. */
if (*exename == 'g')
{
fprintf(fd, "if .%%VIMNOFORK%%==.1 goto noforknt\n");
fprintf(fd, "start \"dummy\" /b ");
}
/* Always use quotes, $VIM or $VIMRUNTIME might have a space. */
fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", exename, vimarg);
fprintf(fd, "goto eof\n");
fprintf(fd, "\n");
if (*exename == 'g')
{
fprintf(fd, ":noforknt\n");
fprintf(fd, "start \"dummy\" /b /wait ");
/* Always use quotes, $VIM or $VIMRUNTIME might have a space. */
fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n",
exename, vimarg);
}
fprintf(fd, "\n:eof\n");
fprintf(fd, "set VIMARGS=\n");
if (*exename == 'g')
fprintf(fd, "set VIMNOFORK=\n");
fclose(fd);
printf("%s has been %s\n", batpath,
oldname == NULL ? "created" : "overwritten");
}
}
}
/*
* Make the text string for choice "idx".
* The format "fmt" is must have one %s item, which "arg" is used for.
*/
static void
alloc_text(int idx, char *fmt, char *arg)
{
if (choices[idx].text != NULL)
free(choices[idx].text);
choices[idx].text = alloc((int)(strlen(fmt) + strlen(arg)) - 1);
sprintf(choices[idx].text, fmt, arg);
}
/*
* Toggle the "Overwrite .../vim.bat" to "Don't overwrite".
*/
static void
toggle_bat_choice(int idx)
{
char *batname = targets[choices[idx].arg].batpath;
char *oldname = targets[choices[idx].arg].oldbat;
if (*batname == NUL)
{
alloc_text(idx, " Overwrite %s", oldname);
strcpy(batname, oldname);
}
else
{
alloc_text(idx, " Do NOT overwrite %s", oldname);
*batname = NUL;
}
}
/*
* Do some work for a batch file entry: Append the batch file name to the path
* and set the text for the choice.
*/
static void
set_bat_text(int idx, char *batpath, char *name)
{
strcat(batpath, name);
alloc_text(idx, " Create %s", batpath);
}
/*
* Select a directory to write the batch file line.
*/
static void
change_bat_choice(int idx)
{
char *path;
char *batpath;
char *name;
int n;
char *s;
char *p;
int count;
char **names = NULL;
int i;
int target = choices[idx].arg;
name = targets[target].batname;
batpath = targets[target].batpath;
path = getenv("PATH");
if (path == NULL)
{
printf("\nERROR: The variable $PATH is not set\n");
return;
}
/*
* first round: count number of names in path;
* second round: save names to names[].
*/
for (;;)
{
count = 1;
for (p = path; *p; )
{
s = strchr(p, ';');
if (s == NULL)
s = p + strlen(p);
if (names != NULL)
{
names[count] = alloc((int)(s - p) + 1);
strncpy(names[count], p, s - p);
names[count][s - p] = NUL;
}
++count;
p = s;
if (*p != NUL)
++p;
}
if (names != NULL)
break;
names = alloc((int)(count + 1) * sizeof(char *));
}
names[0] = alloc(50);
sprintf(names[0], "Select directory to create %s in:", name);
names[count] = alloc(50);
if (choices[idx].arg == 0)
sprintf(names[count], "Do not create any .bat file.");
else
sprintf(names[count], "Do not create a %s file.", name);
n = get_choice(names, count + 1);
if (n == count)
{
/* Selected last item, don't create bat file. */
*batpath = NUL;
if (choices[idx].arg != 0)
alloc_text(idx, " Do NOT create %s", name);
}
else
{
/* Selected one of the paths. For the first item only keep the path,
* for the others append the batch file name. */
strcpy(batpath, names[n]);
add_pathsep(batpath);
if (choices[idx].arg != 0)
set_bat_text(idx, batpath, name);
}
for (i = 0; i <= count; ++i)
free(names[i]);
free(names);
}
char *bat_text_yes = "Install .bat files to use Vim at the command line:";
char *bat_text_no = "do NOT install .bat files to use Vim at the command line";
static void
change_main_bat_choice(int idx)
{
int i;
/* let the user select a default directory or NONE */
change_bat_choice(idx);
if (targets[0].batpath[0] != NUL)
choices[idx].text = bat_text_yes;
else
choices[idx].text = bat_text_no;
/* update the individual batch file selections */
for (i = 1; i < TARGET_COUNT; ++i)
{
/* Only make it active when the first item has a path and the vim.exe
* or gvim.exe exists (there is a changefunc then). */
if (targets[0].batpath[0] != NUL
&& choices[idx + i].changefunc != NULL)
{
choices[idx + i].active = 1;
if (choices[idx + i].changefunc == change_bat_choice
&& targets[i].batpath[0] != NUL)
{
strcpy(targets[i].batpath, targets[0].batpath);
set_bat_text(idx + i, targets[i].batpath, targets[i].batname);
}
}
else
choices[idx + i].active = 0;
}
}
/*
* Initialize a choice for creating a batch file.
*/
static void
init_bat_choice(int target)
{
char *batpath = targets[target].batpath;
char *oldbat = targets[target].oldbat;
char *p;
int i;
choices[choice_count].arg = target;
choices[choice_count].installfunc = install_bat_choice;
choices[choice_count].active = 1;
choices[choice_count].text = NULL; /* will be set below */
if (oldbat != NULL)
{
/* A [g]vim.bat exists: Only choice is to overwrite it or not. */
choices[choice_count].changefunc = toggle_bat_choice;
*batpath = NUL;
toggle_bat_choice(choice_count);
}
else
{
if (default_bat_dir != NULL)
/* Prefer using the same path as an existing .bat file. */
strcpy(batpath, default_bat_dir);
else
{
/* No [g]vim.bat exists: Write it to a directory in $PATH. Use
* $WINDIR by default, if it's empty the first item in $PATH. */
p = getenv("WINDIR");
if (p != NULL && *p != NUL)
strcpy(batpath, p);
else
{
p = getenv("PATH");
if (p == NULL || *p == NUL) /* "cannot happen" */
strcpy(batpath, "C:/Windows");
else
{
i = 0;
while (*p != NUL && *p != ';')
batpath[i++] = *p++;
batpath[i] = NUL;
}
}
}
add_pathsep(batpath);
set_bat_text(choice_count, batpath, targets[target].batname);
choices[choice_count].changefunc = change_bat_choice;
}
++choice_count;
}
/*
* Set up the choices for installing .bat files.
* For these items "arg" is the index in targets[].
*/
static void
init_bat_choices(void)
{
int i;
/* The first item is used to switch installing batch files on/off and
* setting the default path. */
choices[choice_count].text = bat_text_yes;
choices[choice_count].changefunc = change_main_bat_choice;
choices[choice_count].installfunc = NULL;
choices[choice_count].active = 1;
choices[choice_count].arg = 0;
++choice_count;
/* Add items for each batch file target. Only used when not disabled by
* the first item. When a .exe exists, don't offer to create a .bat. */
for (i = 1; i < TARGET_COUNT; ++i)
if (targets[i].oldexe == NULL
&& (targets[i].exenamearg[0] == 'g' ? has_gvim : has_vim))
init_bat_choice(i);
else
add_dummy_choice();
}
/*
* Install the vimrc file.
*/
static void
install_vimrc(int idx)
{
FILE *fd, *tfd;
char *fname;
/* If an old vimrc file exists, overwrite it.
* Otherwise create a new one. */
if (*oldvimrc != NUL)
fname = oldvimrc;
else
fname = vimrc;
fd = fopen(fname, "w");
if (fd == NULL)
{
printf("\nERROR: Cannot open \"%s\" for writing.\n", fname);
return;
}
switch (compat_choice)
{
case compat_vi:
fprintf(fd, "set compatible\n");
break;
case compat_some_enhancements:
fprintf(fd, "set nocompatible\n");
break;
case compat_all_enhancements:
fprintf(fd, "set nocompatible\n");
fprintf(fd, "source $VIMRUNTIME/vimrc_example.vim\n");
break;
}
switch (remap_choice)
{
case remap_no:
break;
case remap_win:
fprintf(fd, "source $VIMRUNTIME/mswin.vim\n");
break;
}
switch (mouse_choice)
{
case mouse_xterm:
fprintf(fd, "behave xterm\n");
break;
case mouse_mswin:
fprintf(fd, "behave mswin\n");
break;
}
if ((tfd = fopen("diff.exe", "r")) != NULL)
{
/* Use the diff.exe that comes with the self-extracting gvim.exe. */
fclose(tfd);
fprintf(fd, "\n");
fprintf(fd, "set diffexpr=MyDiff()\n");
fprintf(fd, "function MyDiff()\n");
fprintf(fd, " let opt = '-a --binary '\n");
fprintf(fd, " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif\n");
fprintf(fd, " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif\n");
/* Use quotes only when needed, they may cause trouble. */
fprintf(fd, " let arg1 = v:fname_in\n");
fprintf(fd, " if arg1 =~ ' ' | let arg1 = '\"' . arg1 . '\"' | endif\n");
fprintf(fd, " let arg2 = v:fname_new\n");
fprintf(fd, " if arg2 =~ ' ' | let arg2 = '\"' . arg2 . '\"' | endif\n");
fprintf(fd, " let arg3 = v:fname_out\n");
fprintf(fd, " if arg3 =~ ' ' | let arg3 = '\"' . arg3 . '\"' | endif\n");
/* If the path has a space: When using cmd.exe (Win NT/2000/XP) put
* quotes around the whole command and around the diff command.
* Otherwise put a double quote just before the space and at the
* end of the command. Putting quotes around the whole thing
* doesn't work on Win 95/98/ME. This is mostly guessed! */
fprintf(fd, " let eq = ''\n");
fprintf(fd, " if $VIMRUNTIME =~ ' '\n");
fprintf(fd, " if &sh =~ '\\<cmd'\n");
fprintf(fd, " let cmd = '\"\"' . $VIMRUNTIME . '\\diff\"'\n");
fprintf(fd, " let eq = '\"'\n");
fprintf(fd, " else\n");
fprintf(fd, " let cmd = substitute($VIMRUNTIME, ' ', '\" ', '') . '\\diff\"'\n");
fprintf(fd, " endif\n");
fprintf(fd, " else\n");
fprintf(fd, " let cmd = $VIMRUNTIME . '\\diff'\n");
fprintf(fd, " endif\n");
fprintf(fd, " silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq\n");
fprintf(fd, "endfunction\n");
fprintf(fd, "\n");
}
fclose(fd);
printf("%s has been written\n", fname);
}
static void
change_vimrc_choice(int idx)
{
if (choices[idx].installfunc != NULL)
{
/* Switch to NOT change or create a vimrc file. */
if (*oldvimrc != NUL)
alloc_text(idx, "Do NOT change startup file %s", oldvimrc);
else
alloc_text(idx, "Do NOT create startup file %s", vimrc);
choices[idx].installfunc = NULL;
choices[idx + 1].active = 0;
choices[idx + 2].active = 0;
choices[idx + 3].active = 0;
}
else
{
/* Switch to change or create a vimrc file. */
if (*oldvimrc != NUL)
alloc_text(idx, "Overwrite startup file %s with:", oldvimrc);
else
alloc_text(idx, "Create startup file %s with:", vimrc);
choices[idx].installfunc = install_vimrc;
choices[idx + 1].active = 1;
choices[idx + 2].active = 1;
choices[idx + 3].active = 1;
}
}
/*
* Change the choice how to run Vim.
*/
static void
change_run_choice(int idx)
{
compat_choice = get_choice(compat_choices, TABLE_SIZE(compat_choices));
alloc_text(idx, compat_text, compat_choices[compat_choice]);
}
/*
* Change the choice if keys are to be remapped.
*/
static void
change_remap_choice(int idx)
{
remap_choice = get_choice(remap_choices, TABLE_SIZE(remap_choices));
alloc_text(idx, remap_text, remap_choices[remap_choice]);
}
/*
* Change the choice how to select text.
*/
static void
change_mouse_choice(int idx)
{
mouse_choice = get_choice(mouse_choices, TABLE_SIZE(mouse_choices));
alloc_text(idx, mouse_text, mouse_choices[mouse_choice]);
}
static void
init_vimrc_choices(void)
{
/* set path for a new _vimrc file (also when not used) */
strcpy(vimrc, installdir);
strcpy(vimrc + runtimeidx, "_vimrc");
/* Set opposite value and then toggle it by calling change_vimrc_choice() */
if (*oldvimrc == NUL)
choices[choice_count].installfunc = NULL;
else
choices[choice_count].installfunc = install_vimrc;
choices[choice_count].text = NULL;
change_vimrc_choice(choice_count);
choices[choice_count].changefunc = change_vimrc_choice;
choices[choice_count].active = 1;
++choice_count;
/* default way to run Vim */
alloc_text(choice_count, compat_text, compat_choices[compat_choice]);
choices[choice_count].changefunc = change_run_choice;
choices[choice_count].installfunc = NULL;
choices[choice_count].active = (*oldvimrc == NUL);
++choice_count;
/* Whether to remap keys */
alloc_text(choice_count, remap_text , remap_choices[remap_choice]);
choices[choice_count].changefunc = change_remap_choice;
choices[choice_count].installfunc = NULL;;
choices[choice_count].active = (*oldvimrc == NUL);
++choice_count;
/* default way to use the mouse */
alloc_text(choice_count, mouse_text, mouse_choices[mouse_choice]);
choices[choice_count].changefunc = change_mouse_choice;
choices[choice_count].installfunc = NULL;;
choices[choice_count].active = (*oldvimrc == NUL);
++choice_count;
}
#if defined(WIN3264)
static LONG
reg_create_key(
HKEY root,
const char *subkey,
PHKEY phKey)
{
DWORD disp;
*phKey = NULL;
return RegCreateKeyEx(
root, subkey,
0, NULL, REG_OPTION_NON_VOLATILE,
KEY_WOW64_64KEY | KEY_WRITE,
NULL, phKey, &disp);
}
static LONG
reg_set_string_value(
HKEY hKey,
const char *value_name,
const char *data)
{
return RegSetValueEx(hKey, value_name, 0, REG_SZ,
(LPBYTE)data, (DWORD)(1 + strlen(data)));
}
static LONG
reg_create_key_and_value(
HKEY hRootKey,
const char *subkey,
const char *value_name,
const char *data)
{
HKEY hKey;
LONG lRet = reg_create_key(hRootKey, subkey, &hKey);
if (ERROR_SUCCESS == lRet)
{
lRet = reg_set_string_value(hKey, value_name, data);
RegCloseKey(hKey);
}
return lRet;
}
static LONG
register_inproc_server(
HKEY hRootKey,
const char *clsid,
const char *extname,
const char *module,
const char *threading_model)
{
CHAR subkey[BUFSIZE];
LONG lRet;
sprintf(subkey, "CLSID\\%s", clsid);
lRet = reg_create_key_and_value(hRootKey, subkey, NULL, extname);
if (ERROR_SUCCESS == lRet)
{
sprintf(subkey, "CLSID\\%s\\InProcServer32", clsid);
lRet = reg_create_key_and_value(hRootKey, subkey, NULL, module);
if (ERROR_SUCCESS == lRet)
{
lRet = reg_create_key_and_value(hRootKey, subkey,
"ThreadingModel", threading_model);
}
}
return lRet;
}
static LONG
register_shellex(
HKEY hRootKey,
const char *clsid,
const char *name,
const char *exe_path)
{
LONG lRet = reg_create_key_and_value(
hRootKey,
"*\\shellex\\ContextMenuHandlers\\gvim",
NULL,
clsid);
if (ERROR_SUCCESS == lRet)
{
lRet = reg_create_key_and_value(
HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved",
clsid,
name);
if (ERROR_SUCCESS == lRet)
{
lRet = reg_create_key_and_value(
HKEY_LOCAL_MACHINE,
"Software\\Vim\\Gvim",
"path",
exe_path);
}
}
return lRet;
}
static LONG
register_openwith(
HKEY hRootKey,
const char *exe_path)
{
char exe_cmd[BUFSIZE];
LONG lRet;
sprintf(exe_cmd, "\"%s\" \"%%1\"", exe_path);
lRet = reg_create_key_and_value(
hRootKey,
"Applications\\gvim.exe\\shell\\edit\\command",
NULL,
exe_cmd);
if (ERROR_SUCCESS == lRet)
{
int i;
static const char *openwith[] = {
".htm\\OpenWithList\\gvim.exe",
".vim\\OpenWithList\\gvim.exe",
"*\\OpenWithList\\gvim.exe",
};
for (i = 0; ERROR_SUCCESS == lRet
&& i < sizeof(openwith) / sizeof(openwith[0]); i++)
{
lRet = reg_create_key_and_value(hRootKey, openwith[i], NULL, "");
}
}
return lRet;
}
static LONG
register_uninstall(
HKEY hRootKey,
const char *appname,
const char *display_name,
const char *uninstall_string)
{
LONG lRet = reg_create_key_and_value(hRootKey, appname,
"DisplayName", display_name);
if (ERROR_SUCCESS == lRet)
lRet = reg_create_key_and_value(hRootKey, appname,
"UninstallString", uninstall_string);
return lRet;
}
#endif /* WIN3264 */
/*
* Add some entries to the registry:
* - to add "Edit with Vim" to the context * menu
* - to add Vim to the "Open with..." list
* - to uninstall Vim
*/
/*ARGSUSED*/
static int
install_registry(void)
{
#ifdef WIN3264
LONG lRet = ERROR_SUCCESS;
const char *vim_ext_ThreadingModel = "Apartment";
const char *vim_ext_name = "Vim Shell Extension";
const char *vim_ext_clsid = "{51EEE242-AD87-11d3-9C1E-0090278BBD99}";
char vim_exe_path[BUFSIZE];
char display_name[BUFSIZE];
char uninstall_string[BUFSIZE];
sprintf(vim_exe_path, "%s\\gvim.exe", installdir);
if (install_popup)
{
char bufg[BUFSIZE];
struct stat st;
if (stat("gvimext.dll", &st) >= 0)
sprintf(bufg, "%s\\gvimext.dll", installdir);
else
/* gvimext.dll is in gvimext subdir */
sprintf(bufg, "%s\\gvimext\\gvimext.dll", installdir);
printf("Creating \"Edit with Vim\" popup menu entry\n");
lRet = register_inproc_server(
HKEY_CLASSES_ROOT, vim_ext_clsid, vim_ext_name,
bufg, vim_ext_ThreadingModel);
if (ERROR_SUCCESS != lRet)
return FAIL;
lRet = register_shellex(
HKEY_CLASSES_ROOT, vim_ext_clsid, vim_ext_name, vim_exe_path);
if (ERROR_SUCCESS != lRet)
return FAIL;
}
if (install_openwith)
{
printf("Creating \"Open with ...\" list entry\n");
lRet = register_openwith(HKEY_CLASSES_ROOT, vim_exe_path);
if (ERROR_SUCCESS != lRet)
return FAIL;
}
printf("Creating an uninstall entry\n");
/* For the NSIS installer use the generated uninstaller. */
if (interactive)
{
sprintf(display_name, "Vim " VIM_VERSION_SHORT);
sprintf(uninstall_string, "%s\\uninstal.exe", installdir);
}
else
{
sprintf(display_name, "Vim " VIM_VERSION_SHORT " (self-installing)");
sprintf(uninstall_string, "%s\\uninstall-gui.exe", installdir);
}
lRet = register_uninstall(
HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Vim " VIM_VERSION_SHORT,
display_name,
uninstall_string);
if (ERROR_SUCCESS != lRet)
return FAIL;
#endif /* WIN3264 */
return OK;
}
static void
change_popup_choice(int idx)
{
if (install_popup == 0)
{
choices[idx].text = "Install an entry for Vim in the popup menu for the right\n mouse button so that you can edit any file with Vim";
install_popup = 1;
}
else
{
choices[idx].text = "Do NOT install an entry for Vim in the popup menu for the\n right mouse button to edit any file with Vim";
install_popup = 0;
}
}
/*
* Only add the choice for the popup menu entry when gvim.exe was found and
* both gvimext.dll and regedit.exe exist.
*/
static void
init_popup_choice(void)
{
struct stat st;
if (has_gvim
&& (stat("gvimext.dll", &st) >= 0
|| stat("gvimext/gvimext.dll", &st) >= 0)
#ifndef WIN3264
&& searchpath("regedit.exe") != NULL
#endif
)
{
choices[choice_count].changefunc = change_popup_choice;
choices[choice_count].installfunc = NULL;
choices[choice_count].active = 1;
change_popup_choice(choice_count); /* set the text */
++choice_count;
}
else
add_dummy_choice();
}
static void
change_openwith_choice(int idx)
{
if (install_openwith == 0)
{
choices[idx].text = "Add Vim to the \"Open With...\" list in the popup menu for the right\n mouse button so that you can edit any file with Vim";
install_openwith = 1;
}
else
{
choices[idx].text = "Do NOT add Vim to the \"Open With...\" list in the popup menu for the\n right mouse button to edit any file with Vim";
install_openwith = 0;
}
}
/*
* Only add the choice for the open-with menu entry when gvim.exe was found
* and and regedit.exe exist.
*/
static void
init_openwith_choice(void)
{
if (has_gvim
#ifndef WIN3264
&& searchpath("regedit.exe") != NULL
#endif
)
{
choices[choice_count].changefunc = change_openwith_choice;
choices[choice_count].installfunc = NULL;
choices[choice_count].active = 1;
change_openwith_choice(choice_count); /* set the text */
++choice_count;
}
else
add_dummy_choice();
}
#ifdef WIN3264
/* create_shortcut
*
* Create a shell link.
*
* returns 0 on failure, non-zero on successful completion.
*
* NOTE: Currently untested with mingw.
*/
int
create_shortcut(
const char *shortcut_name,
const char *iconfile_path,
int iconindex,
const char *shortcut_target,
const char *shortcut_args,
const char *workingdir
)
{
IShellLink *shelllink_ptr;
HRESULT hres;
IPersistFile *persistfile_ptr;
/* Initialize COM library */
hres = CoInitialize(NULL);
if (!SUCCEEDED(hres))
{
printf("Error: Could not open the COM library. Not creating shortcut.\n");
return FAIL;
}
/* Instantiate a COM object for the ShellLink, store a pointer to it
* in shelllink_ptr. */
hres = CoCreateInstance(&CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
&IID_IShellLink,
(void **) &shelllink_ptr);
if (SUCCEEDED(hres)) /* If the instantiation was successful... */
{
/* ...Then build a PersistFile interface for the ShellLink so we can
* save it as a file after we build it. */
hres = shelllink_ptr->lpVtbl->QueryInterface(shelllink_ptr,
&IID_IPersistFile, (void **) &persistfile_ptr);
if (SUCCEEDED(hres))
{
wchar_t wsz[BUFSIZE];
/* translate the (possibly) multibyte shortcut filename to windows
* Unicode so it can be used as a file name.
*/
MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, BUFSIZE);
/* set the attributes */
shelllink_ptr->lpVtbl->SetPath(shelllink_ptr, shortcut_target);
shelllink_ptr->lpVtbl->SetWorkingDirectory(shelllink_ptr,
workingdir);
shelllink_ptr->lpVtbl->SetIconLocation(shelllink_ptr,
iconfile_path, iconindex);
shelllink_ptr->lpVtbl->SetArguments(shelllink_ptr, shortcut_args);
/* save the shortcut to a file and return the PersistFile object*/
persistfile_ptr->lpVtbl->Save(persistfile_ptr, wsz, 1);
persistfile_ptr->lpVtbl->Release(persistfile_ptr);
}
else
{
printf("QueryInterface Error\n");
return FAIL;
}
/* Return the ShellLink object */
shelllink_ptr->lpVtbl->Release(shelllink_ptr);
}
else
{
printf("CoCreateInstance Error - hres = %08x\n", (int)hres);
return FAIL;
}
return OK;
}
/*
* Build a path to where we will put a specified link.
*
* Return 0 on error, non-zero on success
*/
int
build_link_name(
char *link_path,
const char *link_name,
const char *shell_folder_name)
{
char shell_folder_path[BUFSIZE];
if (get_shell_folder_path(shell_folder_path, shell_folder_name) == FAIL)
{
printf("An error occurred while attempting to find the path to %s.\n",
shell_folder_name);
return FAIL;
}
/* Make sure the directory exists (create Start Menu\Programs\Vim).
* Ignore errors if it already exists. */
vim_mkdir(shell_folder_path, 0755);
/* build the path to the shortcut and the path to gvim.exe */
sprintf(link_path, "%s\\%s.lnk", shell_folder_path, link_name);
return OK;
}
static int
build_shortcut(
const char *name, /* Name of the shortcut */
const char *exename, /* Name of the executable (e.g., vim.exe) */
const char *args,
const char *shell_folder,
const char *workingdir)
{
char executable_path[BUFSIZE];
char link_name[BUFSIZE];
sprintf(executable_path, "%s\\%s", installdir, exename);
if (build_link_name(link_name, name, shell_folder) == FAIL)
{
printf("An error has occurred. A shortcut to %s will not be created %s.\n",
name,
*shell_folder == 'd' ? "on the desktop" : "in the Start menu");
return FAIL;
}
/* Create the shortcut: */
return create_shortcut(link_name, executable_path, 0,
executable_path, args, workingdir);
}
/*
* We used to use "homedir" as the working directory, but that is a bad choice
* on multi-user systems. Not specifying a directory appears to work best.
*/
#define WORKDIR ""
/*
* Create shortcut(s) in the Start Menu\Programs\Vim folder.
*/
static void
install_start_menu(int idx)
{
need_uninstall_entry = 1;
printf("Creating start menu\n");
if (has_vim)
{
if (build_shortcut("Vim", "vim.exe", "",
VIM_STARTMENU, WORKDIR) == FAIL)
return;
if (build_shortcut("Vim Read-only", "vim.exe", "-R",
VIM_STARTMENU, WORKDIR) == FAIL)
return;
if (build_shortcut("Vim Diff", "vim.exe", "-d",
VIM_STARTMENU, WORKDIR) == FAIL)
return;
}
if (has_gvim)
{
if (build_shortcut("gVim", "gvim.exe", "",
VIM_STARTMENU, WORKDIR) == FAIL)
return;
if (build_shortcut("gVim Easy", "gvim.exe", "-y",
VIM_STARTMENU, WORKDIR) == FAIL)
return;
if (build_shortcut("gVim Read-only", "gvim.exe", "-R",
VIM_STARTMENU, WORKDIR) == FAIL)
return;
if (build_shortcut("gVim Diff", "gvim.exe", "-d",
VIM_STARTMENU, WORKDIR) == FAIL)
return;
}
if (build_shortcut("Uninstall",
interactive ? "uninstal.exe" : "uninstall-gui.exe", "",
VIM_STARTMENU, installdir) == FAIL)
return;
/* For Windows NT the working dir of the vimtutor.bat must be right,
* otherwise gvim.exe won't be found and using gvimbat doesn't work. */
if (build_shortcut("Vim tutor", "vimtutor.bat", "",
VIM_STARTMENU, installdir) == FAIL)
return;
if (build_shortcut("Help", has_gvim ? "gvim.exe" : "vim.exe", "-c h",
VIM_STARTMENU, WORKDIR) == FAIL)
return;
{
char shell_folder_path[BUFSIZE];
/* Creating the URL shortcut works a bit differently... */
if (get_shell_folder_path(shell_folder_path, VIM_STARTMENU) == FAIL)
{
printf("Finding the path of the Start menu failed\n");
return ;
}
add_pathsep(shell_folder_path);
strcat(shell_folder_path, "Vim Online.url");
if (!WritePrivateProfileString("InternetShortcut", "URL",
"http://vim.sf.net/", shell_folder_path))
{
printf("Creating the Vim online URL failed\n");
return;
}
}
}
static void
toggle_startmenu_choice(int idx)
{
if (choices[idx].installfunc == NULL)
{
choices[idx].installfunc = install_start_menu;
choices[idx].text = "Add Vim to the Start menu";
}
else
{
choices[idx].installfunc = NULL;
choices[idx].text = "Do NOT add Vim to the Start menu";
}
}
/*
* Function to actually create the shortcuts
*
* Currently I am supplying no working directory to the shortcut. This
* means that the initial working dir will be:
* - the location of the shortcut if no file is supplied
* - the location of the file being edited if a file is supplied (ie via
* drag and drop onto the shortcut).
*/
void
install_shortcut_gvim(int idx)
{
/* Create shortcut(s) on the desktop */
if (choices[idx].arg)
{
(void)build_shortcut(icon_names[0], "gvim.exe",
"", "desktop", WORKDIR);
need_uninstall_entry = 1;
}
}
void
install_shortcut_evim(int idx)
{
if (choices[idx].arg)
{
(void)build_shortcut(icon_names[1], "gvim.exe",
"-y", "desktop", WORKDIR);
need_uninstall_entry = 1;
}
}
void
install_shortcut_gview(int idx)
{
if (choices[idx].arg)
{
(void)build_shortcut(icon_names[2], "gvim.exe",
"-R", "desktop", WORKDIR);
need_uninstall_entry = 1;
}
}
void
toggle_shortcut_choice(int idx)
{
char *arg;
if (choices[idx].installfunc == install_shortcut_gvim)
arg = "gVim";
else if (choices[idx].installfunc == install_shortcut_evim)
arg = "gVim Easy";
else
arg = "gVim Read-only";
if (choices[idx].arg)
{
choices[idx].arg = 0;
alloc_text(idx, "Do NOT create a desktop icon for %s", arg);
}
else
{
choices[idx].arg = 1;
alloc_text(idx, "Create a desktop icon for %s", arg);
}
}
#endif /* WIN3264 */
static void
init_startmenu_choice(void)
{
#ifdef WIN3264
/* Start menu */
choices[choice_count].changefunc = toggle_startmenu_choice;
choices[choice_count].installfunc = NULL;
choices[choice_count].active = 1;
toggle_startmenu_choice(choice_count); /* set the text */
++choice_count;
#else
add_dummy_choice();
#endif
}
/*
* Add the choice for the desktop shortcuts.
*/
static void
init_shortcut_choices(void)
{
#ifdef WIN3264
/* Shortcut to gvim */
choices[choice_count].text = NULL;
choices[choice_count].arg = 0;
choices[choice_count].active = has_gvim;
choices[choice_count].changefunc = toggle_shortcut_choice;
choices[choice_count].installfunc = install_shortcut_gvim;
toggle_shortcut_choice(choice_count);
++choice_count;
/* Shortcut to evim */
choices[choice_count].text = NULL;
choices[choice_count].arg = 0;
choices[choice_count].active = has_gvim;
choices[choice_count].changefunc = toggle_shortcut_choice;
choices[choice_count].installfunc = install_shortcut_evim;
toggle_shortcut_choice(choice_count);
++choice_count;
/* Shortcut to gview */
choices[choice_count].text = NULL;
choices[choice_count].arg = 0;
choices[choice_count].active = has_gvim;
choices[choice_count].changefunc = toggle_shortcut_choice;
choices[choice_count].installfunc = install_shortcut_gview;
toggle_shortcut_choice(choice_count);
++choice_count;
#else
add_dummy_choice();
add_dummy_choice();
add_dummy_choice();
#endif
}
#ifdef WIN3264
/*
* Attempt to register OLE for Vim.
*/
static void
install_OLE_register(void)
{
char register_command_string[BUFSIZE + 30];
printf("\n--- Attempting to register Vim with OLE ---\n");
printf("(There is no message whether this works or not.)\n");
#ifndef __CYGWIN__
sprintf(register_command_string, "\"%s\\gvim.exe\" -silent -register", installdir);
#else
/* handle this differently for Cygwin which sometimes has trouble with
* Windows-style pathnames here. */
sprintf(register_command_string, "./gvim.exe -silent -register");
#endif
system(register_command_string);
}
#endif /* WIN3264 */
/*
* Remove the last part of directory "path[]" to get its parent, and put the
* result in "to[]".
*/
static void
dir_remove_last(const char *path, char to[BUFSIZE])
{
char c;
long last_char_to_copy;
long path_length = strlen(path);
/* skip the last character just in case it is a '\\' */
last_char_to_copy = path_length - 2;
c = path[last_char_to_copy];
while (c != '\\')
{
last_char_to_copy--;
c = path[last_char_to_copy];
}
strncpy(to, path, (size_t)last_char_to_copy);
to[last_char_to_copy] = NUL;
}
static void
set_directories_text(int idx)
{
if (vimfiles_dir_choice == (int)vimfiles_dir_none)
alloc_text(idx, "Do NOT create plugin directories%s", "");
else
alloc_text(idx, "Create plugin directories: %s",
vimfiles_dir_choices[vimfiles_dir_choice]);
}
/*
* Change the directory that the vim plugin directories will be created in:
* $HOME, $VIM or nowhere.
*/
static void
change_directories_choice(int idx)
{
int choice_count = TABLE_SIZE(vimfiles_dir_choices);
/* Don't offer the $HOME choice if $HOME isn't set. */
if (getenv("HOME") == NULL)
--choice_count;
vimfiles_dir_choice = get_choice(vimfiles_dir_choices, choice_count);
set_directories_text(idx);
}
/*
* Create the plugin directories...
*/
/*ARGSUSED*/
static void
install_vimfilesdir(int idx)
{
int i;
char *p;
char vimdir_path[BUFSIZE];
char vimfiles_path[BUFSIZE];
char tmp_dirname[BUFSIZE];
/* switch on the location that the user wants the plugin directories
* built in */
switch (vimfiles_dir_choice)
{
case vimfiles_dir_vim:
{
/* Go to the %VIM% directory - check env first, then go one dir
* below installdir if there is no %VIM% environment variable.
* The accuracy of $VIM is checked in inspect_system(), so we
* can be sure it is ok to use here. */
p = getenv("VIM");
if (p == NULL) /* No $VIM in path */
dir_remove_last(installdir, vimdir_path);
else
strcpy(vimdir_path, p);
break;
}
case vimfiles_dir_home:
{
/* Find the $HOME directory. Its existence was already checked. */
p = getenv("HOME");
if (p == NULL)
{
printf("Internal error: $HOME is NULL\n");
p = "c:\\";
}
strcpy(vimdir_path, p);
break;
}
case vimfiles_dir_none:
{
/* Do not create vim plugin directory */
return;
}
}
/* Now, just create the directory. If it already exists, it will fail
* silently. */
sprintf(vimfiles_path, "%s\\vimfiles", vimdir_path);
vim_mkdir(vimfiles_path, 0755);
printf("Creating the following directories in \"%s\":\n", vimfiles_path);
for (i = 0; i < TABLE_SIZE(vimfiles_subdirs); i++)
{
sprintf(tmp_dirname, "%s\\%s", vimfiles_path, vimfiles_subdirs[i]);
printf(" %s", vimfiles_subdirs[i]);
vim_mkdir(tmp_dirname, 0755);
}
printf("\n");
}
/*
* Add the creation of runtime files to the setup sequence.
*/
static void
init_directories_choice(void)
{
struct stat st;
char tmp_dirname[BUFSIZE];
char *p;
choices[choice_count].text = alloc(150);
choices[choice_count].changefunc = change_directories_choice;
choices[choice_count].installfunc = install_vimfilesdir;
choices[choice_count].active = 1;
/* Check if the "compiler" directory already exists. That's a good
* indication that the plugin directories were already created. */
if (getenv("HOME") != NULL)
{
vimfiles_dir_choice = (int)vimfiles_dir_home;
sprintf(tmp_dirname, "%s\\vimfiles\\compiler", getenv("HOME"));
if (stat(tmp_dirname, &st) == 0)
vimfiles_dir_choice = (int)vimfiles_dir_none;
}
else
{
vimfiles_dir_choice = (int)vimfiles_dir_vim;
p = getenv("VIM");
if (p == NULL) /* No $VIM in path, use the install dir */
dir_remove_last(installdir, tmp_dirname);
else
strcpy(tmp_dirname, p);
strcat(tmp_dirname, "\\vimfiles\\compiler");
if (stat(tmp_dirname, &st) == 0)
vimfiles_dir_choice = (int)vimfiles_dir_none;
}
set_directories_text(choice_count);
++choice_count;
}
/*
* Setup the choices and the default values.
*/
static void
setup_choices(void)
{
/* install the batch files */
init_bat_choices();
/* (over) write _vimrc file */
init_vimrc_choices();
/* Whether to add Vim to the popup menu */
init_popup_choice();
/* Whether to add Vim to the "Open With..." menu */
init_openwith_choice();
/* Whether to add Vim to the Start Menu. */
init_startmenu_choice();
/* Whether to add shortcuts to the Desktop. */
init_shortcut_choices();
/* Whether to create the runtime directories. */
init_directories_choice();
}
static void
print_cmd_line_help(void)
{
printf("Vim installer non-interactive command line arguments:\n");
printf("\n");
printf("-create-batfiles [vim gvim evim view gview vimdiff gvimdiff]\n");
printf(" Create .bat files for Vim variants in the Windows directory.\n");
printf("-create-vimrc\n");
printf(" Create a default _vimrc file if one does not already exist.\n");
printf("-install-popup\n");
printf(" Install the Edit-with-Vim context menu entry\n");
printf("-install-openwith\n");
printf(" Add Vim to the \"Open With...\" context menu list\n");
#ifdef WIN3264
printf("-add-start-menu");
printf(" Add Vim to the start menu\n");
printf("-install-icons");
printf(" Create icons for gVim executables on the desktop\n");
#endif
printf("-create-directories [vim|home]\n");
printf(" Create runtime directories to drop plugins into; in the $VIM\n");
printf(" or $HOME directory\n");
#ifdef WIN3264
printf("-register-OLE");
printf(" Ignored\n");
#endif
printf("\n");
}
/*
* Setup installation choices based on command line switches
*/
static void
command_line_setup_choices(int argc, char **argv)
{
int i, j;
for (i = 1; i < argc; i++)
{
if (strcmp(argv[i], "-create-batfiles") == 0)
{
if (i + 1 == argc)
continue;
while (argv[i + 1][0] != '-' && i < argc)
{
i++;
for (j = 1; j < TARGET_COUNT; ++j)
if ((targets[j].exenamearg[0] == 'g' ? has_gvim : has_vim)
&& strcmp(argv[i], targets[j].name) == 0)
{
init_bat_choice(j);
break;
}
if (j == TARGET_COUNT)
printf("%s is not a valid choice for -create-batfiles\n",
argv[i]);
if (i + 1 == argc)
break;
}
}
else if (strcmp(argv[i], "-create-vimrc") == 0)
{
/* Setup default vimrc choices. If there is already a _vimrc file,
* it will NOT be overwritten.
*/
init_vimrc_choices();
}
else if (strcmp(argv[i], "-install-popup") == 0)
{
init_popup_choice();
}
else if (strcmp(argv[i], "-install-openwith") == 0)
{
init_openwith_choice();
}
else if (strcmp(argv[i], "-add-start-menu") == 0)
{
init_startmenu_choice();
}
else if (strcmp(argv[i], "-install-icons") == 0)
{
init_shortcut_choices();
}
else if (strcmp(argv[i], "-create-directories") == 0)
{
init_directories_choice();
if (argv[i + 1][0] != '-')
{
i++;
if (strcmp(argv[i], "vim") == 0)
vimfiles_dir_choice = (int)vimfiles_dir_vim;
else if (strcmp(argv[i], "home") == 0)
{
if (getenv("HOME") == NULL) /* No $HOME in environment */
vimfiles_dir_choice = (int)vimfiles_dir_vim;
else
vimfiles_dir_choice = (int)vimfiles_dir_home;
}
else
{
printf("Unknown argument for -create-directories: %s\n",
argv[i]);
print_cmd_line_help();
}
}
else /* No choice specified, default to vim directory */
vimfiles_dir_choice = (int)vimfiles_dir_vim;
}
#ifdef WIN3264
else if (strcmp(argv[i], "-register-OLE") == 0)
{
/* This is always done when gvim is found */
}
#endif
else /* Unknown switch */
{
printf("Got unknown argument argv[%d] = %s\n", i, argv[i]);
print_cmd_line_help();
}
}
}
/*
* Show a few screens full of helpful information.
*/
static void
show_help(void)
{
static char *(items[]) =
{
"Installing .bat files\n"
"---------------------\n"
"The vim.bat file is written in one of the directories in $PATH.\n"
"This makes it possible to start Vim from the command line.\n"
"If vim.exe can be found in $PATH, the choice for vim.bat will not be\n"
"present. It is assumed you will use the existing vim.exe.\n"
"If vim.bat can already be found in $PATH this is probably for an old\n"
"version of Vim (but this is not checked!). You can overwrite it.\n"
"If no vim.bat already exists, you can select one of the directories in\n"
"$PATH for creating the batch file, or disable creating a vim.bat file.\n"
"\n"
"If you choose not to create the vim.bat file, Vim can still be executed\n"
"in other ways, but not from the command line.\n"
"\n"
"The same applies to choices for gvim, evim, (g)view, and (g)vimdiff.\n"
"The first item can be used to change the path for all of them.\n"
,
"Creating a _vimrc file\n"
"----------------------\n"
"The _vimrc file is used to set options for how Vim behaves.\n"
"The install program can create a _vimrc file with a few basic choices.\n"
"You can edit this file later to tune your preferences.\n"
"If you already have a _vimrc or .vimrc file it can be overwritten.\n"
"Don't do that if you have made changes to it.\n"
,
"Vim features\n"
"------------\n"
"(this choice is only available when creating a _vimrc file)\n"
"1. Vim can run in Vi-compatible mode. Many nice Vim features are then\n"
" disabled. In the not-Vi-compatible mode Vim is still mostly Vi\n"
" compatible, but adds nice features like multi-level undo. Only\n"
" choose Vi-compatible if you really need full Vi compatibility.\n"
"2. Running Vim with some enhancements is useful when you want some of\n"
" the nice Vim features, but have a slow computer and want to keep it\n"
" really fast.\n"
"3. Syntax highlighting shows many files in color. Not only does this look\n"
" nice, it also makes it easier to spot errors and you can work faster.\n"
" The other features include editing compressed files.\n"
,
"Windows key mapping\n"
"-------------------\n"
"(this choice is only available when creating a _vimrc file)\n"
"Under MS-Windows the CTRL-C key copies text to the clipboard and CTRL-V\n"
"pastes text from the clipboard. There are a few more keys like these.\n"
"Unfortunately, in Vim these keys normally have another meaning.\n"
"1. Choose to have the keys like they normally are in Vim (useful if you\n"
" also use Vim on other systems).\n"
"2. Choose to have the keys work like they are used on MS-Windows (useful\n"
" if you mostly work on MS-Windows).\n"
,
"Mouse use\n"
"---------\n"
"(this choice is only available when creating a _vimrc file)\n"
"The right mouse button can be used in two ways:\n"
"1. The Unix way is to extend an existing selection. The popup menu is\n"
" not available.\n"
"2. The MS-Windows way is to show a popup menu, which allows you to\n"
" copy/paste text, undo/redo, etc. Extending the selection can still be\n"
" done by keeping SHIFT pressed while using the left mouse button\n"
,
"Edit-with-Vim context menu entry\n"
"--------------------------------\n"
"(this choice is only available when gvim.exe and gvimext.dll are present)\n"
"You can associate different file types with Vim, so that you can (double)\n"
"click on a file to edit it with Vim. This means you have to individually\n"
"select each file type.\n"
"An alternative is the option offered here: Install an \"Edit with Vim\"\n"
"entry in the popup menu for the right mouse button. This means you can\n"
"edit any file with Vim.\n"
,
"\"Open With...\" context menu entry\n"
"--------------------------------\n"
"(this choice is only available when gvim.exe is present)\n"
"This option adds Vim to the \"Open With...\" entry in the popup menu for\n"
"the right mouse button. This also makes it possible to edit HTML files\n"
"directly from Internet Explorer.\n"
,
"Add Vim to the Start menu\n"
"-------------------------\n"
"In Windows 95 and later, Vim can be added to the Start menu. This will\n"
"create a submenu with an entry for vim, gvim, evim, vimdiff, etc..\n"
,
"Icons on the desktop\n"
"--------------------\n"
"(these choices are only available when installing gvim)\n"
"In Windows 95 and later, shortcuts (icons) can be created on the Desktop.\n"
,
"Create plugin directories\n"
"-------------------------\n"
"Plugin directories allow extending Vim by dropping a file into a directory.\n"
"This choice allows creating them in $HOME (if you have a home directory) or\n"
"$VIM (used for everybody on the system).\n"
,
NULL
};
int i;
int c;
rewind(stdin);
printf("\n");
for (i = 0; items[i] != NULL; ++i)
{
printf(items[i]);
printf("\n");
printf("Hit Enter to continue, b (back) or q (quit help): ");
c = getchar();
rewind(stdin);
if (c == 'b' || c == 'B')
{
if (i == 0)
--i;
else
i -= 2;
}
if (c == 'q' || c == 'Q')
break;
printf("\n");
}
}
/*
* Install the choices.
*/
static void
install(void)
{
int i;
/* Install the selected choices. */
for (i = 0; i < choice_count; ++i)
if (choices[i].installfunc != NULL && choices[i].active)
(choices[i].installfunc)(i);
/* Add some entries to the registry, if needed. */
if (install_popup
|| install_openwith
|| (need_uninstall_entry && interactive)
|| !interactive)
install_registry();
#ifdef WIN3264
/* Register gvim with OLE. */
if (has_gvim)
install_OLE_register();
#endif
}
/*
* request_choice
*/
static void
request_choice(void)
{
int i;
printf("\n\nInstall will do for you:\n");
for (i = 0; i < choice_count; ++i)
if (choices[i].active)
printf("%2d %s\n", i + 1, choices[i].text);
printf("To change an item, enter its number\n\n");
printf("Enter item number, h (help), d (do it) or q (quit): ");
}
int
main(int argc, char **argv)
{
int i;
char buf[BUFSIZE];
/*
* Run interactively if there are no command line arguments.
*/
if (argc > 1)
interactive = 0;
else
interactive = 1;
/* Initialize this program. */
do_inits(argv);
#ifdef WIN3264
if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0)
{
/* Only check for already installed Vims. Used by NSIS installer. */
i = uninstall_check(1);
/* Find the value of $VIM, because NSIS isn't able to do this by
* itself. */
get_vim_env();
/* When nothing found exit quietly. If something found wait for
* a little while, so that the user can read the messages. */
if (i)
sleep(3);
exit(0);
}
#endif
printf("This program sets up the installation of Vim "
VIM_VERSION_MEDIUM "\n\n");
/* Check if the user unpacked the archives properly. */
check_unpack();
#ifdef WIN3264
/* Check for already installed Vims. */
if (interactive)
uninstall_check(0);
#endif
/* Find out information about the system. */
inspect_system();
if (interactive)
{
/* Setup all the choices. */
setup_choices();
/* Let the user change choices and finally install (or quit). */
for (;;)
{
request_choice();
rewind(stdin);
if (scanf("%99s", buf) == 1)
{
if (isdigit(buf[0]))
{
/* Change a choice. */
i = atoi(buf);
if (i > 0 && i <= choice_count && choices[i - 1].active)
(choices[i - 1].changefunc)(i - 1);
else
printf("\nIllegal choice\n");
}
else if (buf[0] == 'h' || buf[0] == 'H')
{
/* Help */
show_help();
}
else if (buf[0] == 'd' || buf[0] == 'D')
{
/* Install! */
install();
printf("\nThat finishes the installation. Happy Vimming!\n");
break;
}
else if (buf[0] == 'q' || buf[0] == 'Q')
{
/* Quit */
printf("\nExiting without anything done\n");
break;
}
else
printf("\nIllegal choice\n");
}
}
printf("\n");
myexit(0);
}
else
{
/*
* Run non-interactive - setup according to the command line switches
*/
command_line_setup_choices(argc, argv);
install();
/* Avoid that the user has to hit Enter, just wait a little bit to
* allow reading the messages. */
sleep(2);
}
return 0;
}
| zyz2011-vim | src/dosinst.c | C | gpl2 | 69,125 |
/* vi:set ts=8 sts=4 sw=4:
*
* Load XPM image.
*
* This function is placed in separate file because Xpm headers conflict with
* Vim ones :(
*
* Written by Sergey Khorev.
* http://iamphet.nm.ru/vim/index.html
*/
#ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
/* reduced def from Vim.h */
#ifndef __ARGS
# if defined(__STDC__) || defined(__GNUC__) || defined(WIN3264)
# define __ARGS(x) x
# else
# define __ARGS(x) ()
# endif
#endif
#include "xpm_w32.h"
/* Engage Windows support in libXpm */
#define FOR_MSW
#include "xpm.h"
/*
* Tries to load an Xpm image from the file "filename".
* Returns -1 on failure.
* Returns 0 on success and stores image and mask BITMAPS in "hImage" and
* "hShape".
*/
int
LoadXpmImage(filename, hImage, hShape)
char *filename;
HBITMAP *hImage;
HBITMAP *hShape;
{
XImage *img; /* loaded image */
XImage *shp; /* shapeimage */
XpmAttributes attr;
int res;
HDC hdc = CreateCompatibleDC(NULL);
attr.valuemask = 0;
res = XpmReadFileToImage(&hdc, filename, &img, &shp, &attr);
DeleteDC(hdc);
if (res < 0)
return -1;
if (shp == NULL)
{
if (img)
XDestroyImage(img);
return -1;
}
*hImage = img->bitmap;
*hShape = shp->bitmap;
return 0;
}
| zyz2011-vim | src/xpm_w32.c | C | gpl2 | 1,333 |
@echo off
rem To be used on MS-Windows for Visual C++ 2010 Express Edition
rem aka Microsoft Visual Studio 10.0.
rem See INSTALLpc.txt for information.
@echo on
call "%VS100COMNTOOLS%%vsvars32.bat"
| zyz2011-vim | src/msvc2010.bat | Batchfile | gpl2 | 201 |
/* vim:set ts=8 sts=4 sw=4:
* vim600:fdm=marker fdl=1 fdc=3:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* fold.c: code for folding
*/
#include "vim.h"
#if defined(FEAT_FOLDING) || defined(PROTO)
/* local declarations. {{{1 */
/* typedef fold_T {{{2 */
/*
* The toplevel folds for each window are stored in the w_folds growarray.
* Each toplevel fold can contain an array of second level folds in the
* fd_nested growarray.
* The info stored in both growarrays is the same: An array of fold_T.
*/
typedef struct
{
linenr_T fd_top; /* first line of fold; for nested fold
* relative to parent */
linenr_T fd_len; /* number of lines in the fold */
garray_T fd_nested; /* array of nested folds */
char fd_flags; /* see below */
char fd_small; /* TRUE, FALSE or MAYBE: fold smaller than
'foldminlines'; MAYBE applies to nested
folds too */
} fold_T;
#define FD_OPEN 0 /* fold is open (nested ones can be closed) */
#define FD_CLOSED 1 /* fold is closed */
#define FD_LEVEL 2 /* depends on 'foldlevel' (nested folds too) */
#define MAX_LEVEL 20 /* maximum fold depth */
/* static functions {{{2 */
static void newFoldLevelWin __ARGS((win_T *wp));
static int checkCloseRec __ARGS((garray_T *gap, linenr_T lnum, int level));
static int foldFind __ARGS((garray_T *gap, linenr_T lnum, fold_T **fpp));
static int foldLevelWin __ARGS((win_T *wp, linenr_T lnum));
static void checkupdate __ARGS((win_T *wp));
static void setFoldRepeat __ARGS((linenr_T lnum, long count, int do_open));
static linenr_T setManualFold __ARGS((linenr_T lnum, int opening, int recurse, int *donep));
static linenr_T setManualFoldWin __ARGS((win_T *wp, linenr_T lnum, int opening, int recurse, int *donep));
static void foldOpenNested __ARGS((fold_T *fpr));
static void deleteFoldEntry __ARGS((garray_T *gap, int idx, int recursive));
static void foldMarkAdjustRecurse __ARGS((garray_T *gap, linenr_T line1, linenr_T line2, long amount, long amount_after));
static int getDeepestNestingRecurse __ARGS((garray_T *gap));
static int check_closed __ARGS((win_T *win, fold_T *fp, int *use_levelp, int level, int *maybe_smallp, linenr_T lnum_off));
static void checkSmall __ARGS((win_T *wp, fold_T *fp, linenr_T lnum_off));
static void setSmallMaybe __ARGS((garray_T *gap));
static void foldCreateMarkers __ARGS((linenr_T start, linenr_T end));
static void foldAddMarker __ARGS((linenr_T lnum, char_u *marker, int markerlen));
static void deleteFoldMarkers __ARGS((fold_T *fp, int recursive, linenr_T lnum_off));
static void foldDelMarker __ARGS((linenr_T lnum, char_u *marker, int markerlen));
static void foldUpdateIEMS __ARGS((win_T *wp, linenr_T top, linenr_T bot));
static void parseMarker __ARGS((win_T *wp));
static char *e_nofold = N_("E490: No fold found");
/*
* While updating the folds lines between invalid_top and invalid_bot have an
* undefined fold level. Only used for the window currently being updated.
*/
static linenr_T invalid_top = (linenr_T)0;
static linenr_T invalid_bot = (linenr_T)0;
/*
* When using 'foldexpr' we sometimes get the level of the next line, which
* calls foldlevel() to get the level of the current line, which hasn't been
* stored yet. To get around this chicken-egg problem the level of the
* previous line is stored here when available. prev_lnum is zero when the
* level is not available.
*/
static linenr_T prev_lnum = 0;
static int prev_lnum_lvl = -1;
/* Flags used for "done" argument of setManualFold. */
#define DONE_NOTHING 0
#define DONE_ACTION 1 /* did close or open a fold */
#define DONE_FOLD 2 /* did find a fold */
static int foldstartmarkerlen;
static char_u *foldendmarker;
static int foldendmarkerlen;
/* Exported folding functions. {{{1 */
/* copyFoldingState() {{{2 */
#if defined(FEAT_WINDOWS) || defined(PROTO)
/*
* Copy that folding state from window "wp_from" to window "wp_to".
*/
void
copyFoldingState(wp_from, wp_to)
win_T *wp_from;
win_T *wp_to;
{
wp_to->w_fold_manual = wp_from->w_fold_manual;
wp_to->w_foldinvalid = wp_from->w_foldinvalid;
cloneFoldGrowArray(&wp_from->w_folds, &wp_to->w_folds);
}
#endif
/* hasAnyFolding() {{{2 */
/*
* Return TRUE if there may be folded lines in the current window.
*/
int
hasAnyFolding(win)
win_T *win;
{
/* very simple now, but can become more complex later */
return (win->w_p_fen
&& (!foldmethodIsManual(win) || win->w_folds.ga_len > 0));
}
/* hasFolding() {{{2 */
/*
* Return TRUE if line "lnum" in the current window is part of a closed
* fold.
* When returning TRUE, *firstp and *lastp are set to the first and last
* lnum of the sequence of folded lines (skipped when NULL).
*/
int
hasFolding(lnum, firstp, lastp)
linenr_T lnum;
linenr_T *firstp;
linenr_T *lastp;
{
return hasFoldingWin(curwin, lnum, firstp, lastp, TRUE, NULL);
}
/* hasFoldingWin() {{{2 */
int
hasFoldingWin(win, lnum, firstp, lastp, cache, infop)
win_T *win;
linenr_T lnum;
linenr_T *firstp;
linenr_T *lastp;
int cache; /* when TRUE: use cached values of window */
foldinfo_T *infop; /* where to store fold info */
{
int had_folded = FALSE;
linenr_T first = 0;
linenr_T last = 0;
linenr_T lnum_rel = lnum;
int x;
fold_T *fp;
int level = 0;
int use_level = FALSE;
int maybe_small = FALSE;
garray_T *gap;
int low_level = 0;;
checkupdate(win);
/*
* Return quickly when there is no folding at all in this window.
*/
if (!hasAnyFolding(win))
{
if (infop != NULL)
infop->fi_level = 0;
return FALSE;
}
if (cache)
{
/*
* First look in cached info for displayed lines. This is probably
* the fastest, but it can only be used if the entry is still valid.
*/
x = find_wl_entry(win, lnum);
if (x >= 0)
{
first = win->w_lines[x].wl_lnum;
last = win->w_lines[x].wl_lastlnum;
had_folded = win->w_lines[x].wl_folded;
}
}
if (first == 0)
{
/*
* Recursively search for a fold that contains "lnum".
*/
gap = &win->w_folds;
for (;;)
{
if (!foldFind(gap, lnum_rel, &fp))
break;
/* Remember lowest level of fold that starts in "lnum". */
if (lnum_rel == fp->fd_top && low_level == 0)
low_level = level + 1;
first += fp->fd_top;
last += fp->fd_top;
/* is this fold closed? */
had_folded = check_closed(win, fp, &use_level, level,
&maybe_small, lnum - lnum_rel);
if (had_folded)
{
/* Fold closed: Set last and quit loop. */
last += fp->fd_len - 1;
break;
}
/* Fold found, but it's open: Check nested folds. Line number is
* relative to containing fold. */
gap = &fp->fd_nested;
lnum_rel -= fp->fd_top;
++level;
}
}
if (!had_folded)
{
if (infop != NULL)
{
infop->fi_level = level;
infop->fi_lnum = lnum - lnum_rel;
infop->fi_low_level = low_level == 0 ? level : low_level;
}
return FALSE;
}
if (lastp != NULL)
*lastp = last;
if (firstp != NULL)
*firstp = first;
if (infop != NULL)
{
infop->fi_level = level + 1;
infop->fi_lnum = first;
infop->fi_low_level = low_level == 0 ? level + 1 : low_level;
}
return TRUE;
}
/* foldLevel() {{{2 */
/*
* Return fold level at line number "lnum" in the current window.
*/
int
foldLevel(lnum)
linenr_T lnum;
{
/* While updating the folds lines between invalid_top and invalid_bot have
* an undefined fold level. Otherwise update the folds first. */
if (invalid_top == (linenr_T)0)
checkupdate(curwin);
else if (lnum == prev_lnum && prev_lnum_lvl >= 0)
return prev_lnum_lvl;
else if (lnum >= invalid_top && lnum <= invalid_bot)
return -1;
/* Return quickly when there is no folding at all in this window. */
if (!hasAnyFolding(curwin))
return 0;
return foldLevelWin(curwin, lnum);
}
/* lineFolded() {{{2 */
/*
* Low level function to check if a line is folded. Doesn't use any caching.
* Return TRUE if line is folded.
* Return FALSE if line is not folded.
* Return MAYBE if the line is folded when next to a folded line.
*/
int
lineFolded(win, lnum)
win_T *win;
linenr_T lnum;
{
return foldedCount(win, lnum, NULL) != 0;
}
/* foldedCount() {{{2 */
/*
* Count the number of lines that are folded at line number "lnum".
* Normally "lnum" is the first line of a possible fold, and the returned
* number is the number of lines in the fold.
* Doesn't use caching from the displayed window.
* Returns number of folded lines from "lnum", or 0 if line is not folded.
* When "infop" is not NULL, fills *infop with the fold level info.
*/
long
foldedCount(win, lnum, infop)
win_T *win;
linenr_T lnum;
foldinfo_T *infop;
{
linenr_T last;
if (hasFoldingWin(win, lnum, NULL, &last, FALSE, infop))
return (long)(last - lnum + 1);
return 0;
}
/* foldmethodIsManual() {{{2 */
/*
* Return TRUE if 'foldmethod' is "manual"
*/
int
foldmethodIsManual(wp)
win_T *wp;
{
return (wp->w_p_fdm[3] == 'u');
}
/* foldmethodIsIndent() {{{2 */
/*
* Return TRUE if 'foldmethod' is "indent"
*/
int
foldmethodIsIndent(wp)
win_T *wp;
{
return (wp->w_p_fdm[0] == 'i');
}
/* foldmethodIsExpr() {{{2 */
/*
* Return TRUE if 'foldmethod' is "expr"
*/
int
foldmethodIsExpr(wp)
win_T *wp;
{
return (wp->w_p_fdm[1] == 'x');
}
/* foldmethodIsMarker() {{{2 */
/*
* Return TRUE if 'foldmethod' is "marker"
*/
int
foldmethodIsMarker(wp)
win_T *wp;
{
return (wp->w_p_fdm[2] == 'r');
}
/* foldmethodIsSyntax() {{{2 */
/*
* Return TRUE if 'foldmethod' is "syntax"
*/
int
foldmethodIsSyntax(wp)
win_T *wp;
{
return (wp->w_p_fdm[0] == 's');
}
/* foldmethodIsDiff() {{{2 */
/*
* Return TRUE if 'foldmethod' is "diff"
*/
int
foldmethodIsDiff(wp)
win_T *wp;
{
return (wp->w_p_fdm[0] == 'd');
}
/* closeFold() {{{2 */
/*
* Close fold for current window at line "lnum".
* Repeat "count" times.
*/
void
closeFold(lnum, count)
linenr_T lnum;
long count;
{
setFoldRepeat(lnum, count, FALSE);
}
/* closeFoldRecurse() {{{2 */
/*
* Close fold for current window at line "lnum" recursively.
*/
void
closeFoldRecurse(lnum)
linenr_T lnum;
{
(void)setManualFold(lnum, FALSE, TRUE, NULL);
}
/* opFoldRange() {{{2 */
/*
* Open or Close folds for current window in lines "first" to "last".
* Used for "zo", "zO", "zc" and "zC" in Visual mode.
*/
void
opFoldRange(first, last, opening, recurse, had_visual)
linenr_T first;
linenr_T last;
int opening; /* TRUE to open, FALSE to close */
int recurse; /* TRUE to do it recursively */
int had_visual; /* TRUE when Visual selection used */
{
int done = DONE_NOTHING; /* avoid error messages */
linenr_T lnum;
linenr_T lnum_next;
for (lnum = first; lnum <= last; lnum = lnum_next + 1)
{
lnum_next = lnum;
/* Opening one level only: next fold to open is after the one going to
* be opened. */
if (opening && !recurse)
(void)hasFolding(lnum, NULL, &lnum_next);
(void)setManualFold(lnum, opening, recurse, &done);
/* Closing one level only: next line to close a fold is after just
* closed fold. */
if (!opening && !recurse)
(void)hasFolding(lnum, NULL, &lnum_next);
}
if (done == DONE_NOTHING)
EMSG(_(e_nofold));
#ifdef FEAT_VISUAL
/* Force a redraw to remove the Visual highlighting. */
if (had_visual)
redraw_curbuf_later(INVERTED);
#endif
}
/* openFold() {{{2 */
/*
* Open fold for current window at line "lnum".
* Repeat "count" times.
*/
void
openFold(lnum, count)
linenr_T lnum;
long count;
{
setFoldRepeat(lnum, count, TRUE);
}
/* openFoldRecurse() {{{2 */
/*
* Open fold for current window at line "lnum" recursively.
*/
void
openFoldRecurse(lnum)
linenr_T lnum;
{
(void)setManualFold(lnum, TRUE, TRUE, NULL);
}
/* foldOpenCursor() {{{2 */
/*
* Open folds until the cursor line is not in a closed fold.
*/
void
foldOpenCursor()
{
int done;
checkupdate(curwin);
if (hasAnyFolding(curwin))
for (;;)
{
done = DONE_NOTHING;
(void)setManualFold(curwin->w_cursor.lnum, TRUE, FALSE, &done);
if (!(done & DONE_ACTION))
break;
}
}
/* newFoldLevel() {{{2 */
/*
* Set new foldlevel for current window.
*/
void
newFoldLevel()
{
newFoldLevelWin(curwin);
#ifdef FEAT_DIFF
if (foldmethodIsDiff(curwin) && curwin->w_p_scb)
{
win_T *wp;
/*
* Set the same foldlevel in other windows in diff mode.
*/
FOR_ALL_WINDOWS(wp)
{
if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb)
{
wp->w_p_fdl = curwin->w_p_fdl;
newFoldLevelWin(wp);
}
}
}
#endif
}
static void
newFoldLevelWin(wp)
win_T *wp;
{
fold_T *fp;
int i;
checkupdate(wp);
if (wp->w_fold_manual)
{
/* Set all flags for the first level of folds to FD_LEVEL. Following
* manual open/close will then change the flags to FD_OPEN or
* FD_CLOSED for those folds that don't use 'foldlevel'. */
fp = (fold_T *)wp->w_folds.ga_data;
for (i = 0; i < wp->w_folds.ga_len; ++i)
fp[i].fd_flags = FD_LEVEL;
wp->w_fold_manual = FALSE;
}
changed_window_setting_win(wp);
}
/* foldCheckClose() {{{2 */
/*
* Apply 'foldlevel' to all folds that don't contain the cursor.
*/
void
foldCheckClose()
{
if (*p_fcl != NUL) /* can only be "all" right now */
{
checkupdate(curwin);
if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum,
(int)curwin->w_p_fdl))
changed_window_setting();
}
}
/* checkCloseRec() {{{2 */
static int
checkCloseRec(gap, lnum, level)
garray_T *gap;
linenr_T lnum;
int level;
{
fold_T *fp;
int retval = FALSE;
int i;
fp = (fold_T *)gap->ga_data;
for (i = 0; i < gap->ga_len; ++i)
{
/* Only manually opened folds may need to be closed. */
if (fp[i].fd_flags == FD_OPEN)
{
if (level <= 0 && (lnum < fp[i].fd_top
|| lnum >= fp[i].fd_top + fp[i].fd_len))
{
fp[i].fd_flags = FD_LEVEL;
retval = TRUE;
}
else
retval |= checkCloseRec(&fp[i].fd_nested, lnum - fp[i].fd_top,
level - 1);
}
}
return retval;
}
/* foldCreateAllowed() {{{2 */
/*
* Return TRUE if it's allowed to manually create or delete a fold.
* Give an error message and return FALSE if not.
*/
int
foldManualAllowed(create)
int create;
{
if (foldmethodIsManual(curwin) || foldmethodIsMarker(curwin))
return TRUE;
if (create)
EMSG(_("E350: Cannot create fold with current 'foldmethod'"));
else
EMSG(_("E351: Cannot delete fold with current 'foldmethod'"));
return FALSE;
}
/* foldCreate() {{{2 */
/*
* Create a fold from line "start" to line "end" (inclusive) in the current
* window.
*/
void
foldCreate(start, end)
linenr_T start;
linenr_T end;
{
fold_T *fp;
garray_T *gap;
garray_T fold_ga;
int i, j;
int cont;
int use_level = FALSE;
int closed = FALSE;
int level = 0;
linenr_T start_rel = start;
linenr_T end_rel = end;
if (start > end)
{
/* reverse the range */
end = start_rel;
start = end_rel;
start_rel = start;
end_rel = end;
}
/* When 'foldmethod' is "marker" add markers, which creates the folds. */
if (foldmethodIsMarker(curwin))
{
foldCreateMarkers(start, end);
return;
}
checkupdate(curwin);
/* Find the place to insert the new fold. */
gap = &curwin->w_folds;
for (;;)
{
if (!foldFind(gap, start_rel, &fp))
break;
if (fp->fd_top + fp->fd_len > end_rel)
{
/* New fold is completely inside this fold: Go one level deeper. */
gap = &fp->fd_nested;
start_rel -= fp->fd_top;
end_rel -= fp->fd_top;
if (use_level || fp->fd_flags == FD_LEVEL)
{
use_level = TRUE;
if (level >= curwin->w_p_fdl)
closed = TRUE;
}
else if (fp->fd_flags == FD_CLOSED)
closed = TRUE;
++level;
}
else
{
/* This fold and new fold overlap: Insert here and move some folds
* inside the new fold. */
break;
}
}
i = (int)(fp - (fold_T *)gap->ga_data);
if (ga_grow(gap, 1) == OK)
{
fp = (fold_T *)gap->ga_data + i;
ga_init2(&fold_ga, (int)sizeof(fold_T), 10);
/* Count number of folds that will be contained in the new fold. */
for (cont = 0; i + cont < gap->ga_len; ++cont)
if (fp[cont].fd_top > end_rel)
break;
if (cont > 0 && ga_grow(&fold_ga, cont) == OK)
{
/* If the first fold starts before the new fold, let the new fold
* start there. Otherwise the existing fold would change. */
if (start_rel > fp->fd_top)
start_rel = fp->fd_top;
/* When last contained fold isn't completely contained, adjust end
* of new fold. */
if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1)
end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1;
/* Move contained folds to inside new fold. */
mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont);
fold_ga.ga_len += cont;
i += cont;
/* Adjust line numbers in contained folds to be relative to the
* new fold. */
for (j = 0; j < cont; ++j)
((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel;
}
/* Move remaining entries to after the new fold. */
if (i < gap->ga_len)
mch_memmove(fp + 1, (fold_T *)gap->ga_data + i,
sizeof(fold_T) * (gap->ga_len - i));
gap->ga_len = gap->ga_len + 1 - cont;
/* insert new fold */
fp->fd_nested = fold_ga;
fp->fd_top = start_rel;
fp->fd_len = end_rel - start_rel + 1;
/* We want the new fold to be closed. If it would remain open because
* of using 'foldlevel', need to adjust fd_flags of containing folds.
*/
if (use_level && !closed && level < curwin->w_p_fdl)
closeFold(start, 1L);
if (!use_level)
curwin->w_fold_manual = TRUE;
fp->fd_flags = FD_CLOSED;
fp->fd_small = MAYBE;
/* redraw */
changed_window_setting();
}
}
/* deleteFold() {{{2 */
/*
* Delete a fold at line "start" in the current window.
* When "end" is not 0, delete all folds from "start" to "end".
* When "recursive" is TRUE delete recursively.
*/
void
deleteFold(start, end, recursive, had_visual)
linenr_T start;
linenr_T end;
int recursive;
int had_visual; /* TRUE when Visual selection used */
{
garray_T *gap;
fold_T *fp;
garray_T *found_ga;
fold_T *found_fp = NULL;
linenr_T found_off = 0;
int use_level;
int maybe_small = FALSE;
int level = 0;
linenr_T lnum = start;
linenr_T lnum_off;
int did_one = FALSE;
linenr_T first_lnum = MAXLNUM;
linenr_T last_lnum = 0;
checkupdate(curwin);
while (lnum <= end)
{
/* Find the deepest fold for "start". */
gap = &curwin->w_folds;
found_ga = NULL;
lnum_off = 0;
use_level = FALSE;
for (;;)
{
if (!foldFind(gap, lnum - lnum_off, &fp))
break;
/* lnum is inside this fold, remember info */
found_ga = gap;
found_fp = fp;
found_off = lnum_off;
/* if "lnum" is folded, don't check nesting */
if (check_closed(curwin, fp, &use_level, level,
&maybe_small, lnum_off))
break;
/* check nested folds */
gap = &fp->fd_nested;
lnum_off += fp->fd_top;
++level;
}
if (found_ga == NULL)
{
++lnum;
}
else
{
lnum = found_fp->fd_top + found_fp->fd_len + found_off;
if (foldmethodIsManual(curwin))
deleteFoldEntry(found_ga,
(int)(found_fp - (fold_T *)found_ga->ga_data), recursive);
else
{
if (first_lnum > found_fp->fd_top + found_off)
first_lnum = found_fp->fd_top + found_off;
if (last_lnum < lnum)
last_lnum = lnum;
if (!did_one)
parseMarker(curwin);
deleteFoldMarkers(found_fp, recursive, found_off);
}
did_one = TRUE;
/* redraw window */
changed_window_setting();
}
}
if (!did_one)
{
EMSG(_(e_nofold));
#ifdef FEAT_VISUAL
/* Force a redraw to remove the Visual highlighting. */
if (had_visual)
redraw_curbuf_later(INVERTED);
#endif
}
else
/* Deleting markers may make cursor column invalid. */
check_cursor_col();
if (last_lnum > 0)
changed_lines(first_lnum, (colnr_T)0, last_lnum, 0L);
}
/* clearFolding() {{{2 */
/*
* Remove all folding for window "win".
*/
void
clearFolding(win)
win_T *win;
{
deleteFoldRecurse(&win->w_folds);
win->w_foldinvalid = FALSE;
}
/* foldUpdate() {{{2 */
/*
* Update folds for changes in the buffer of a window.
* Note that inserted/deleted lines must have already been taken care of by
* calling foldMarkAdjust().
* The changes in lines from top to bot (inclusive).
*/
void
foldUpdate(wp, top, bot)
win_T *wp;
linenr_T top;
linenr_T bot;
{
fold_T *fp;
/* Mark all folds from top to bot as maybe-small. */
(void)foldFind(&curwin->w_folds, top, &fp);
while (fp < (fold_T *)curwin->w_folds.ga_data + curwin->w_folds.ga_len
&& fp->fd_top < bot)
{
fp->fd_small = MAYBE;
++fp;
}
if (foldmethodIsIndent(wp)
|| foldmethodIsExpr(wp)
|| foldmethodIsMarker(wp)
#ifdef FEAT_DIFF
|| foldmethodIsDiff(wp)
#endif
|| foldmethodIsSyntax(wp))
{
int save_got_int = got_int;
/* reset got_int here, otherwise it won't work */
got_int = FALSE;
foldUpdateIEMS(wp, top, bot);
got_int |= save_got_int;
}
}
/* foldUpdateAll() {{{2 */
/*
* Update all lines in a window for folding.
* Used when a fold setting changes or after reloading the buffer.
* The actual updating is postponed until fold info is used, to avoid doing
* every time a setting is changed or a syntax item is added.
*/
void
foldUpdateAll(win)
win_T *win;
{
win->w_foldinvalid = TRUE;
redraw_win_later(win, NOT_VALID);
}
/* foldMoveTo() {{{2 */
/*
* If "updown" is FALSE: Move to the start or end of the fold.
* If "updown" is TRUE: move to fold at the same level.
* If not moved return FAIL.
*/
int
foldMoveTo(updown, dir, count)
int updown;
int dir; /* FORWARD or BACKWARD */
long count;
{
long n;
int retval = FAIL;
linenr_T lnum_off;
linenr_T lnum_found;
linenr_T lnum;
int use_level;
int maybe_small;
garray_T *gap;
fold_T *fp;
int level;
int last;
checkupdate(curwin);
/* Repeat "count" times. */
for (n = 0; n < count; ++n)
{
/* Find nested folds. Stop when a fold is closed. The deepest fold
* that moves the cursor is used. */
lnum_off = 0;
gap = &curwin->w_folds;
use_level = FALSE;
maybe_small = FALSE;
lnum_found = curwin->w_cursor.lnum;
level = 0;
last = FALSE;
for (;;)
{
if (!foldFind(gap, curwin->w_cursor.lnum - lnum_off, &fp))
{
if (!updown)
break;
/* When moving up, consider a fold above the cursor; when
* moving down consider a fold below the cursor. */
if (dir == FORWARD)
{
if (fp - (fold_T *)gap->ga_data >= gap->ga_len)
break;
--fp;
}
else
{
if (fp == (fold_T *)gap->ga_data)
break;
}
/* don't look for contained folds, they will always move
* the cursor too far. */
last = TRUE;
}
if (!last)
{
/* Check if this fold is closed. */
if (check_closed(curwin, fp, &use_level, level,
&maybe_small, lnum_off))
last = TRUE;
/* "[z" and "]z" stop at closed fold */
if (last && !updown)
break;
}
if (updown)
{
if (dir == FORWARD)
{
/* to start of next fold if there is one */
if (fp + 1 - (fold_T *)gap->ga_data < gap->ga_len)
{
lnum = fp[1].fd_top + lnum_off;
if (lnum > curwin->w_cursor.lnum)
lnum_found = lnum;
}
}
else
{
/* to end of previous fold if there is one */
if (fp > (fold_T *)gap->ga_data)
{
lnum = fp[-1].fd_top + lnum_off + fp[-1].fd_len - 1;
if (lnum < curwin->w_cursor.lnum)
lnum_found = lnum;
}
}
}
else
{
/* Open fold found, set cursor to its start/end and then check
* nested folds. */
if (dir == FORWARD)
{
lnum = fp->fd_top + lnum_off + fp->fd_len - 1;
if (lnum > curwin->w_cursor.lnum)
lnum_found = lnum;
}
else
{
lnum = fp->fd_top + lnum_off;
if (lnum < curwin->w_cursor.lnum)
lnum_found = lnum;
}
}
if (last)
break;
/* Check nested folds (if any). */
gap = &fp->fd_nested;
lnum_off += fp->fd_top;
++level;
}
if (lnum_found != curwin->w_cursor.lnum)
{
if (retval == FAIL)
setpcmark();
curwin->w_cursor.lnum = lnum_found;
curwin->w_cursor.col = 0;
retval = OK;
}
else
break;
}
return retval;
}
/* foldInitWin() {{{2 */
/*
* Init the fold info in a new window.
*/
void
foldInitWin(new_win)
win_T *new_win;
{
ga_init2(&new_win->w_folds, (int)sizeof(fold_T), 10);
}
/* find_wl_entry() {{{2 */
/*
* Find an entry in the win->w_lines[] array for buffer line "lnum".
* Only valid entries are considered (for entries where wl_valid is FALSE the
* line number can be wrong).
* Returns index of entry or -1 if not found.
*/
int
find_wl_entry(win, lnum)
win_T *win;
linenr_T lnum;
{
int i;
for (i = 0; i < win->w_lines_valid; ++i)
if (win->w_lines[i].wl_valid)
{
if (lnum < win->w_lines[i].wl_lnum)
return -1;
if (lnum <= win->w_lines[i].wl_lastlnum)
return i;
}
return -1;
}
/* foldAdjustVisual() {{{2 */
#ifdef FEAT_VISUAL
/*
* Adjust the Visual area to include any fold at the start or end completely.
*/
void
foldAdjustVisual()
{
pos_T *start, *end;
char_u *ptr;
if (!VIsual_active || !hasAnyFolding(curwin))
return;
if (ltoreq(VIsual, curwin->w_cursor))
{
start = &VIsual;
end = &curwin->w_cursor;
}
else
{
start = &curwin->w_cursor;
end = &VIsual;
}
if (hasFolding(start->lnum, &start->lnum, NULL))
start->col = 0;
if (hasFolding(end->lnum, NULL, &end->lnum))
{
ptr = ml_get(end->lnum);
end->col = (colnr_T)STRLEN(ptr);
if (end->col > 0 && *p_sel == 'o')
--end->col;
#ifdef FEAT_MBYTE
/* prevent cursor from moving on the trail byte */
if (has_mbyte)
mb_adjust_cursor();
#endif
}
}
#endif
/* cursor_foldstart() {{{2 */
/*
* Move the cursor to the first line of a closed fold.
*/
void
foldAdjustCursor()
{
(void)hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL);
}
/* Internal functions for "fold_T" {{{1 */
/* cloneFoldGrowArray() {{{2 */
/*
* Will "clone" (i.e deep copy) a garray_T of folds.
*
* Return FAIL if the operation cannot be completed, otherwise OK.
*/
void
cloneFoldGrowArray(from, to)
garray_T *from;
garray_T *to;
{
int i;
fold_T *from_p;
fold_T *to_p;
ga_init2(to, from->ga_itemsize, from->ga_growsize);
if (from->ga_len == 0 || ga_grow(to, from->ga_len) == FAIL)
return;
from_p = (fold_T *)from->ga_data;
to_p = (fold_T *)to->ga_data;
for (i = 0; i < from->ga_len; i++)
{
to_p->fd_top = from_p->fd_top;
to_p->fd_len = from_p->fd_len;
to_p->fd_flags = from_p->fd_flags;
to_p->fd_small = from_p->fd_small;
cloneFoldGrowArray(&from_p->fd_nested, &to_p->fd_nested);
++to->ga_len;
++from_p;
++to_p;
}
}
/* foldFind() {{{2 */
/*
* Search for line "lnum" in folds of growarray "gap".
* Set *fpp to the fold struct for the fold that contains "lnum" or
* the first fold below it (careful: it can be beyond the end of the array!).
* Returns FALSE when there is no fold that contains "lnum".
*/
static int
foldFind(gap, lnum, fpp)
garray_T *gap;
linenr_T lnum;
fold_T **fpp;
{
linenr_T low, high;
fold_T *fp;
int i;
/*
* Perform a binary search.
* "low" is lowest index of possible match.
* "high" is highest index of possible match.
*/
fp = (fold_T *)gap->ga_data;
low = 0;
high = gap->ga_len - 1;
while (low <= high)
{
i = (low + high) / 2;
if (fp[i].fd_top > lnum)
/* fold below lnum, adjust high */
high = i - 1;
else if (fp[i].fd_top + fp[i].fd_len <= lnum)
/* fold above lnum, adjust low */
low = i + 1;
else
{
/* lnum is inside this fold */
*fpp = fp + i;
return TRUE;
}
}
*fpp = fp + low;
return FALSE;
}
/* foldLevelWin() {{{2 */
/*
* Return fold level at line number "lnum" in window "wp".
*/
static int
foldLevelWin(wp, lnum)
win_T *wp;
linenr_T lnum;
{
fold_T *fp;
linenr_T lnum_rel = lnum;
int level = 0;
garray_T *gap;
/* Recursively search for a fold that contains "lnum". */
gap = &wp->w_folds;
for (;;)
{
if (!foldFind(gap, lnum_rel, &fp))
break;
/* Check nested folds. Line number is relative to containing fold. */
gap = &fp->fd_nested;
lnum_rel -= fp->fd_top;
++level;
}
return level;
}
/* checkupdate() {{{2 */
/*
* Check if the folds in window "wp" are invalid and update them if needed.
*/
static void
checkupdate(wp)
win_T *wp;
{
if (wp->w_foldinvalid)
{
foldUpdate(wp, (linenr_T)1, (linenr_T)MAXLNUM); /* will update all */
wp->w_foldinvalid = FALSE;
}
}
/* setFoldRepeat() {{{2 */
/*
* Open or close fold for current window at line "lnum".
* Repeat "count" times.
*/
static void
setFoldRepeat(lnum, count, do_open)
linenr_T lnum;
long count;
int do_open;
{
int done;
long n;
for (n = 0; n < count; ++n)
{
done = DONE_NOTHING;
(void)setManualFold(lnum, do_open, FALSE, &done);
if (!(done & DONE_ACTION))
{
/* Only give an error message when no fold could be opened. */
if (n == 0 && !(done & DONE_FOLD))
EMSG(_(e_nofold));
break;
}
}
}
/* setManualFold() {{{2 */
/*
* Open or close the fold in the current window which contains "lnum".
* Also does this for other windows in diff mode when needed.
*/
static linenr_T
setManualFold(lnum, opening, recurse, donep)
linenr_T lnum;
int opening; /* TRUE when opening, FALSE when closing */
int recurse; /* TRUE when closing/opening recursive */
int *donep;
{
#ifdef FEAT_DIFF
if (foldmethodIsDiff(curwin) && curwin->w_p_scb)
{
win_T *wp;
linenr_T dlnum;
/*
* Do the same operation in other windows in diff mode. Calculate the
* line number from the diffs.
*/
FOR_ALL_WINDOWS(wp)
{
if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb)
{
dlnum = diff_lnum_win(curwin->w_cursor.lnum, wp);
if (dlnum != 0)
(void)setManualFoldWin(wp, dlnum, opening, recurse, NULL);
}
}
}
#endif
return setManualFoldWin(curwin, lnum, opening, recurse, donep);
}
/* setManualFoldWin() {{{2 */
/*
* Open or close the fold in window "wp" which contains "lnum".
* "donep", when not NULL, points to flag that is set to DONE_FOLD when some
* fold was found and to DONE_ACTION when some fold was opened or closed.
* When "donep" is NULL give an error message when no fold was found for
* "lnum", but only if "wp" is "curwin".
* Return the line number of the next line that could be closed.
* It's only valid when "opening" is TRUE!
*/
static linenr_T
setManualFoldWin(wp, lnum, opening, recurse, donep)
win_T *wp;
linenr_T lnum;
int opening; /* TRUE when opening, FALSE when closing */
int recurse; /* TRUE when closing/opening recursive */
int *donep;
{
fold_T *fp;
fold_T *fp2;
fold_T *found = NULL;
int j;
int level = 0;
int use_level = FALSE;
int found_fold = FALSE;
garray_T *gap;
linenr_T next = MAXLNUM;
linenr_T off = 0;
int done = 0;
checkupdate(wp);
/*
* Find the fold, open or close it.
*/
gap = &wp->w_folds;
for (;;)
{
if (!foldFind(gap, lnum, &fp))
{
/* If there is a following fold, continue there next time. */
if (fp < (fold_T *)gap->ga_data + gap->ga_len)
next = fp->fd_top + off;
break;
}
/* lnum is inside this fold */
found_fold = TRUE;
/* If there is a following fold, continue there next time. */
if (fp + 1 < (fold_T *)gap->ga_data + gap->ga_len)
next = fp[1].fd_top + off;
/* Change from level-dependent folding to manual. */
if (use_level || fp->fd_flags == FD_LEVEL)
{
use_level = TRUE;
if (level >= wp->w_p_fdl)
fp->fd_flags = FD_CLOSED;
else
fp->fd_flags = FD_OPEN;
fp2 = (fold_T *)fp->fd_nested.ga_data;
for (j = 0; j < fp->fd_nested.ga_len; ++j)
fp2[j].fd_flags = FD_LEVEL;
}
/* Simple case: Close recursively means closing the fold. */
if (!opening && recurse)
{
if (fp->fd_flags != FD_CLOSED)
{
done |= DONE_ACTION;
fp->fd_flags = FD_CLOSED;
}
}
else if (fp->fd_flags == FD_CLOSED)
{
/* When opening, open topmost closed fold. */
if (opening)
{
fp->fd_flags = FD_OPEN;
done |= DONE_ACTION;
if (recurse)
foldOpenNested(fp);
}
break;
}
/* fold is open, check nested folds */
found = fp;
gap = &fp->fd_nested;
lnum -= fp->fd_top;
off += fp->fd_top;
++level;
}
if (found_fold)
{
/* When closing and not recurse, close deepest open fold. */
if (!opening && found != NULL)
{
found->fd_flags = FD_CLOSED;
done |= DONE_ACTION;
}
wp->w_fold_manual = TRUE;
if (done & DONE_ACTION)
changed_window_setting_win(wp);
done |= DONE_FOLD;
}
else if (donep == NULL && wp == curwin)
EMSG(_(e_nofold));
if (donep != NULL)
*donep |= done;
return next;
}
/* foldOpenNested() {{{2 */
/*
* Open all nested folds in fold "fpr" recursively.
*/
static void
foldOpenNested(fpr)
fold_T *fpr;
{
int i;
fold_T *fp;
fp = (fold_T *)fpr->fd_nested.ga_data;
for (i = 0; i < fpr->fd_nested.ga_len; ++i)
{
foldOpenNested(&fp[i]);
fp[i].fd_flags = FD_OPEN;
}
}
/* deleteFoldEntry() {{{2 */
/*
* Delete fold "idx" from growarray "gap".
* When "recursive" is TRUE also delete all the folds contained in it.
* When "recursive" is FALSE contained folds are moved one level up.
*/
static void
deleteFoldEntry(gap, idx, recursive)
garray_T *gap;
int idx;
int recursive;
{
fold_T *fp;
int i;
long moved;
fold_T *nfp;
fp = (fold_T *)gap->ga_data + idx;
if (recursive || fp->fd_nested.ga_len == 0)
{
/* recursively delete the contained folds */
deleteFoldRecurse(&fp->fd_nested);
--gap->ga_len;
if (idx < gap->ga_len)
mch_memmove(fp, fp + 1, sizeof(fold_T) * (gap->ga_len - idx));
}
else
{
/* Move nested folds one level up, to overwrite the fold that is
* deleted. */
moved = fp->fd_nested.ga_len;
if (ga_grow(gap, (int)(moved - 1)) == OK)
{
/* Get "fp" again, the array may have been reallocated. */
fp = (fold_T *)gap->ga_data + idx;
/* adjust fd_top and fd_flags for the moved folds */
nfp = (fold_T *)fp->fd_nested.ga_data;
for (i = 0; i < moved; ++i)
{
nfp[i].fd_top += fp->fd_top;
if (fp->fd_flags == FD_LEVEL)
nfp[i].fd_flags = FD_LEVEL;
if (fp->fd_small == MAYBE)
nfp[i].fd_small = MAYBE;
}
/* move the existing folds down to make room */
if (idx + 1 < gap->ga_len)
mch_memmove(fp + moved, fp + 1,
sizeof(fold_T) * (gap->ga_len - (idx + 1)));
/* move the contained folds one level up */
mch_memmove(fp, nfp, (size_t)(sizeof(fold_T) * moved));
vim_free(nfp);
gap->ga_len += moved - 1;
}
}
}
/* deleteFoldRecurse() {{{2 */
/*
* Delete nested folds in a fold.
*/
void
deleteFoldRecurse(gap)
garray_T *gap;
{
int i;
for (i = 0; i < gap->ga_len; ++i)
deleteFoldRecurse(&(((fold_T *)(gap->ga_data))[i].fd_nested));
ga_clear(gap);
}
/* foldMarkAdjust() {{{2 */
/*
* Update line numbers of folds for inserted/deleted lines.
*/
void
foldMarkAdjust(wp, line1, line2, amount, amount_after)
win_T *wp;
linenr_T line1;
linenr_T line2;
long amount;
long amount_after;
{
/* If deleting marks from line1 to line2, but not deleting all those
* lines, set line2 so that only deleted lines have their folds removed. */
if (amount == MAXLNUM && line2 >= line1 && line2 - line1 >= -amount_after)
line2 = line1 - amount_after - 1;
/* If appending a line in Insert mode, it should be included in the fold
* just above the line. */
if ((State & INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM)
--line1;
foldMarkAdjustRecurse(&wp->w_folds, line1, line2, amount, amount_after);
}
/* foldMarkAdjustRecurse() {{{2 */
static void
foldMarkAdjustRecurse(gap, line1, line2, amount, amount_after)
garray_T *gap;
linenr_T line1;
linenr_T line2;
long amount;
long amount_after;
{
fold_T *fp;
int i;
linenr_T last;
linenr_T top;
/* In Insert mode an inserted line at the top of a fold is considered part
* of the fold, otherwise it isn't. */
if ((State & INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM)
top = line1 + 1;
else
top = line1;
/* Find the fold containing or just below "line1". */
(void)foldFind(gap, line1, &fp);
/*
* Adjust all folds below "line1" that are affected.
*/
for (i = (int)(fp - (fold_T *)gap->ga_data); i < gap->ga_len; ++i, ++fp)
{
/*
* Check for these situations:
* 1 2 3
* 1 2 3
* line1 2 3 4 5
* 2 3 4 5
* 2 3 4 5
* line2 2 3 4 5
* 3 5 6
* 3 5 6
*/
last = fp->fd_top + fp->fd_len - 1; /* last line of fold */
/* 1. fold completely above line1: nothing to do */
if (last < line1)
continue;
/* 6. fold below line2: only adjust for amount_after */
if (fp->fd_top > line2)
{
if (amount_after == 0)
break;
fp->fd_top += amount_after;
}
else
{
if (fp->fd_top >= top && last <= line2)
{
/* 4. fold completely contained in range */
if (amount == MAXLNUM)
{
/* Deleting lines: delete the fold completely */
deleteFoldEntry(gap, i, TRUE);
--i; /* adjust index for deletion */
--fp;
}
else
fp->fd_top += amount;
}
else
{
if (fp->fd_top < top)
{
/* 2 or 3: need to correct nested folds too */
foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top,
line2 - fp->fd_top, amount, amount_after);
if (last <= line2)
{
/* 2. fold contains line1, line2 is below fold */
if (amount == MAXLNUM)
fp->fd_len = line1 - fp->fd_top;
else
fp->fd_len += amount;
}
else
{
/* 3. fold contains line1 and line2 */
fp->fd_len += amount_after;
}
}
else
{
/* 5. fold is below line1 and contains line2; need to
* correct nested folds too */
foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top,
line2 - fp->fd_top, amount,
amount_after + (fp->fd_top - top));
if (amount == MAXLNUM)
{
fp->fd_len -= line2 - fp->fd_top + 1;
fp->fd_top = line1;
}
else
{
fp->fd_len += amount_after - amount;
fp->fd_top += amount;
}
}
}
}
}
}
/* getDeepestNesting() {{{2 */
/*
* Get the lowest 'foldlevel' value that makes the deepest nested fold in the
* current window open.
*/
int
getDeepestNesting()
{
checkupdate(curwin);
return getDeepestNestingRecurse(&curwin->w_folds);
}
static int
getDeepestNestingRecurse(gap)
garray_T *gap;
{
int i;
int level;
int maxlevel = 0;
fold_T *fp;
fp = (fold_T *)gap->ga_data;
for (i = 0; i < gap->ga_len; ++i)
{
level = getDeepestNestingRecurse(&fp[i].fd_nested) + 1;
if (level > maxlevel)
maxlevel = level;
}
return maxlevel;
}
/* check_closed() {{{2 */
/*
* Check if a fold is closed and update the info needed to check nested folds.
*/
static int
check_closed(win, fp, use_levelp, level, maybe_smallp, lnum_off)
win_T *win;
fold_T *fp;
int *use_levelp; /* TRUE: outer fold had FD_LEVEL */
int level; /* folding depth */
int *maybe_smallp; /* TRUE: outer this had fd_small == MAYBE */
linenr_T lnum_off; /* line number offset for fp->fd_top */
{
int closed = FALSE;
/* Check if this fold is closed. If the flag is FD_LEVEL this
* fold and all folds it contains depend on 'foldlevel'. */
if (*use_levelp || fp->fd_flags == FD_LEVEL)
{
*use_levelp = TRUE;
if (level >= win->w_p_fdl)
closed = TRUE;
}
else if (fp->fd_flags == FD_CLOSED)
closed = TRUE;
/* Small fold isn't closed anyway. */
if (fp->fd_small == MAYBE)
*maybe_smallp = TRUE;
if (closed)
{
if (*maybe_smallp)
fp->fd_small = MAYBE;
checkSmall(win, fp, lnum_off);
if (fp->fd_small == TRUE)
closed = FALSE;
}
return closed;
}
/* checkSmall() {{{2 */
/*
* Update fd_small field of fold "fp".
*/
static void
checkSmall(wp, fp, lnum_off)
win_T *wp;
fold_T *fp;
linenr_T lnum_off; /* offset for fp->fd_top */
{
int count;
int n;
if (fp->fd_small == MAYBE)
{
/* Mark any nested folds to maybe-small */
setSmallMaybe(&fp->fd_nested);
if (fp->fd_len > curwin->w_p_fml)
fp->fd_small = FALSE;
else
{
count = 0;
for (n = 0; n < fp->fd_len; ++n)
{
count += plines_win_nofold(wp, fp->fd_top + lnum_off + n);
if (count > curwin->w_p_fml)
{
fp->fd_small = FALSE;
return;
}
}
fp->fd_small = TRUE;
}
}
}
/* setSmallMaybe() {{{2 */
/*
* Set small flags in "gap" to MAYBE.
*/
static void
setSmallMaybe(gap)
garray_T *gap;
{
int i;
fold_T *fp;
fp = (fold_T *)gap->ga_data;
for (i = 0; i < gap->ga_len; ++i)
fp[i].fd_small = MAYBE;
}
/* foldCreateMarkers() {{{2 */
/*
* Create a fold from line "start" to line "end" (inclusive) in the current
* window by adding markers.
*/
static void
foldCreateMarkers(start, end)
linenr_T start;
linenr_T end;
{
if (!curbuf->b_p_ma)
{
EMSG(_(e_modifiable));
return;
}
parseMarker(curwin);
foldAddMarker(start, curwin->w_p_fmr, foldstartmarkerlen);
foldAddMarker(end, foldendmarker, foldendmarkerlen);
/* Update both changes here, to avoid all folds after the start are
* changed when the start marker is inserted and the end isn't. */
changed_lines(start, (colnr_T)0, end, 0L);
}
/* foldAddMarker() {{{2 */
/*
* Add "marker[markerlen]" in 'commentstring' to line "lnum".
*/
static void
foldAddMarker(lnum, marker, markerlen)
linenr_T lnum;
char_u *marker;
int markerlen;
{
char_u *cms = curbuf->b_p_cms;
char_u *line;
int line_len;
char_u *newline;
char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s");
/* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */
line = ml_get(lnum);
line_len = (int)STRLEN(line);
if (u_save(lnum - 1, lnum + 1) == OK)
{
newline = alloc((unsigned)(line_len + markerlen + STRLEN(cms) + 1));
if (newline == NULL)
return;
STRCPY(newline, line);
if (p == NULL)
vim_strncpy(newline + line_len, marker, markerlen);
else
{
STRCPY(newline + line_len, cms);
STRNCPY(newline + line_len + (p - cms), marker, markerlen);
STRCPY(newline + line_len + (p - cms) + markerlen, p + 2);
}
ml_replace(lnum, newline, FALSE);
}
}
/* deleteFoldMarkers() {{{2 */
/*
* Delete the markers for a fold, causing it to be deleted.
*/
static void
deleteFoldMarkers(fp, recursive, lnum_off)
fold_T *fp;
int recursive;
linenr_T lnum_off; /* offset for fp->fd_top */
{
int i;
if (recursive)
for (i = 0; i < fp->fd_nested.ga_len; ++i)
deleteFoldMarkers((fold_T *)fp->fd_nested.ga_data + i, TRUE,
lnum_off + fp->fd_top);
foldDelMarker(fp->fd_top + lnum_off, curwin->w_p_fmr, foldstartmarkerlen);
foldDelMarker(fp->fd_top + lnum_off + fp->fd_len - 1,
foldendmarker, foldendmarkerlen);
}
/* foldDelMarker() {{{2 */
/*
* Delete marker "marker[markerlen]" at the end of line "lnum".
* Delete 'commentstring' if it matches.
* If the marker is not found, there is no error message. Could a missing
* close-marker.
*/
static void
foldDelMarker(lnum, marker, markerlen)
linenr_T lnum;
char_u *marker;
int markerlen;
{
char_u *line;
char_u *newline;
char_u *p;
int len;
char_u *cms = curbuf->b_p_cms;
char_u *cms2;
line = ml_get(lnum);
for (p = line; *p != NUL; ++p)
if (STRNCMP(p, marker, markerlen) == 0)
{
/* Found the marker, include a digit if it's there. */
len = markerlen;
if (VIM_ISDIGIT(p[len]))
++len;
if (*cms != NUL)
{
/* Also delete 'commentstring' if it matches. */
cms2 = (char_u *)strstr((char *)cms, "%s");
if (p - line >= cms2 - cms
&& STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0
&& STRNCMP(p + len, cms2 + 2, STRLEN(cms2 + 2)) == 0)
{
p -= cms2 - cms;
len += (int)STRLEN(cms) - 2;
}
}
if (u_save(lnum - 1, lnum + 1) == OK)
{
/* Make new line: text-before-marker + text-after-marker */
newline = alloc((unsigned)(STRLEN(line) - len + 1));
if (newline != NULL)
{
STRNCPY(newline, line, p - line);
STRCPY(newline + (p - line), p + len);
ml_replace(lnum, newline, FALSE);
}
}
break;
}
}
/* get_foldtext() {{{2 */
/*
* Return the text for a closed fold at line "lnum", with last line "lnume".
* When 'foldtext' isn't set puts the result in "buf[51]". Otherwise the
* result is in allocated memory.
*/
char_u *
get_foldtext(wp, lnum, lnume, foldinfo, buf)
win_T *wp;
linenr_T lnum, lnume;
foldinfo_T *foldinfo;
char_u *buf;
{
char_u *text = NULL;
#ifdef FEAT_EVAL
if (*wp->w_p_fdt != NUL)
{
char_u dashes[MAX_LEVEL + 2];
win_T *save_curwin;
int level;
char_u *p;
/* Set "v:foldstart" and "v:foldend". */
set_vim_var_nr(VV_FOLDSTART, lnum);
set_vim_var_nr(VV_FOLDEND, lnume);
/* Set "v:folddashes" to a string of "level" dashes. */
/* Set "v:foldlevel" to "level". */
level = foldinfo->fi_level;
if (level > (int)sizeof(dashes) - 1)
level = (int)sizeof(dashes) - 1;
vim_memset(dashes, '-', (size_t)level);
dashes[level] = NUL;
set_vim_var_string(VV_FOLDDASHES, dashes, -1);
set_vim_var_nr(VV_FOLDLEVEL, (long)level);
save_curwin = curwin;
curwin = wp;
curbuf = wp->w_buffer;
++emsg_off;
text = eval_to_string_safe(wp->w_p_fdt, NULL,
was_set_insecurely((char_u *)"foldtext", OPT_LOCAL));
--emsg_off;
curwin = save_curwin;
curbuf = curwin->w_buffer;
set_vim_var_string(VV_FOLDDASHES, NULL, -1);
if (text != NULL)
{
/* Replace unprintable characters, if there are any. But
* replace a TAB with a space. */
for (p = text; *p != NUL; ++p)
{
# ifdef FEAT_MBYTE
int len;
if (has_mbyte && (len = (*mb_ptr2len)(p)) > 1)
{
if (!vim_isprintc((*mb_ptr2char)(p)))
break;
p += len - 1;
}
else
# endif
if (*p == TAB)
*p = ' ';
else if (ptr2cells(p) > 1)
break;
}
if (*p != NUL)
{
p = transstr(text);
vim_free(text);
text = p;
}
}
}
if (text == NULL)
#endif
{
sprintf((char *)buf, _("+--%3ld lines folded "),
(long)(lnume - lnum + 1));
text = buf;
}
return text;
}
/* foldtext_cleanup() {{{2 */
/*
* Remove 'foldmarker' and 'commentstring' from "str" (in-place).
*/
void
foldtext_cleanup(str)
char_u *str;
{
char_u *cms_start; /* first part or the whole comment */
int cms_slen = 0; /* length of cms_start */
char_u *cms_end; /* last part of the comment or NULL */
int cms_elen = 0; /* length of cms_end */
char_u *s;
char_u *p;
int len;
int did1 = FALSE;
int did2 = FALSE;
/* Ignore leading and trailing white space in 'commentstring'. */
cms_start = skipwhite(curbuf->b_p_cms);
cms_slen = (int)STRLEN(cms_start);
while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1]))
--cms_slen;
/* locate "%s" in 'commentstring', use the part before and after it. */
cms_end = (char_u *)strstr((char *)cms_start, "%s");
if (cms_end != NULL)
{
cms_elen = cms_slen - (int)(cms_end - cms_start);
cms_slen = (int)(cms_end - cms_start);
/* exclude white space before "%s" */
while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1]))
--cms_slen;
/* skip "%s" and white space after it */
s = skipwhite(cms_end + 2);
cms_elen -= (int)(s - cms_end);
cms_end = s;
}
parseMarker(curwin);
for (s = str; *s != NUL; )
{
len = 0;
if (STRNCMP(s, curwin->w_p_fmr, foldstartmarkerlen) == 0)
len = foldstartmarkerlen;
else if (STRNCMP(s, foldendmarker, foldendmarkerlen) == 0)
len = foldendmarkerlen;
if (len > 0)
{
if (VIM_ISDIGIT(s[len]))
++len;
/* May remove 'commentstring' start. Useful when it's a double
* quote and we already removed a double quote. */
for (p = s; p > str && vim_iswhite(p[-1]); --p)
;
if (p >= str + cms_slen
&& STRNCMP(p - cms_slen, cms_start, cms_slen) == 0)
{
len += (int)(s - p) + cms_slen;
s = p - cms_slen;
}
}
else if (cms_end != NULL)
{
if (!did1 && cms_slen > 0 && STRNCMP(s, cms_start, cms_slen) == 0)
{
len = cms_slen;
did1 = TRUE;
}
else if (!did2 && cms_elen > 0
&& STRNCMP(s, cms_end, cms_elen) == 0)
{
len = cms_elen;
did2 = TRUE;
}
}
if (len != 0)
{
while (vim_iswhite(s[len]))
++len;
STRMOVE(s, s + len);
}
else
{
mb_ptr_adv(s);
}
}
}
/* Folding by indent, expr, marker and syntax. {{{1 */
/* Define "fline_T", passed to get fold level for a line. {{{2 */
typedef struct
{
win_T *wp; /* window */
linenr_T lnum; /* current line number */
linenr_T off; /* offset between lnum and real line number */
linenr_T lnum_save; /* line nr used by foldUpdateIEMSRecurse() */
int lvl; /* current level (-1 for undefined) */
int lvl_next; /* level used for next line */
int start; /* number of folds that are forced to start at
this line. */
int end; /* level of fold that is forced to end below
this line */
int had_end; /* level of fold that is forced to end above
this line (copy of "end" of prev. line) */
} fline_T;
/* Flag is set when redrawing is needed. */
static int fold_changed;
/* Function declarations. {{{2 */
static linenr_T foldUpdateIEMSRecurse __ARGS((garray_T *gap, int level, linenr_T startlnum, fline_T *flp, void (*getlevel)__ARGS((fline_T *)), linenr_T bot, int topflags));
static int foldInsert __ARGS((garray_T *gap, int i));
static void foldSplit __ARGS((garray_T *gap, int i, linenr_T top, linenr_T bot));
static void foldRemove __ARGS((garray_T *gap, linenr_T top, linenr_T bot));
static void foldMerge __ARGS((fold_T *fp1, garray_T *gap, fold_T *fp2));
static void foldlevelIndent __ARGS((fline_T *flp));
#ifdef FEAT_DIFF
static void foldlevelDiff __ARGS((fline_T *flp));
#endif
static void foldlevelExpr __ARGS((fline_T *flp));
static void foldlevelMarker __ARGS((fline_T *flp));
static void foldlevelSyntax __ARGS((fline_T *flp));
/* foldUpdateIEMS() {{{2 */
/*
* Update the folding for window "wp", at least from lines "top" to "bot".
* Return TRUE if any folds did change.
*/
static void
foldUpdateIEMS(wp, top, bot)
win_T *wp;
linenr_T top;
linenr_T bot;
{
linenr_T start;
linenr_T end;
fline_T fline;
void (*getlevel)__ARGS((fline_T *));
int level;
fold_T *fp;
/* Avoid problems when being called recursively. */
if (invalid_top != (linenr_T)0)
return;
if (wp->w_foldinvalid)
{
/* Need to update all folds. */
top = 1;
bot = wp->w_buffer->b_ml.ml_line_count;
wp->w_foldinvalid = FALSE;
/* Mark all folds a maybe-small. */
setSmallMaybe(&wp->w_folds);
}
#ifdef FEAT_DIFF
/* add the context for "diff" folding */
if (foldmethodIsDiff(wp))
{
if (top > diff_context)
top -= diff_context;
else
top = 1;
bot += diff_context;
}
#endif
/* When deleting lines at the end of the buffer "top" can be past the end
* of the buffer. */
if (top > wp->w_buffer->b_ml.ml_line_count)
top = wp->w_buffer->b_ml.ml_line_count;
fold_changed = FALSE;
fline.wp = wp;
fline.off = 0;
fline.lvl = 0;
fline.lvl_next = -1;
fline.start = 0;
fline.end = MAX_LEVEL + 1;
fline.had_end = MAX_LEVEL + 1;
invalid_top = top;
invalid_bot = bot;
if (foldmethodIsMarker(wp))
{
getlevel = foldlevelMarker;
/* Init marker variables to speed up foldlevelMarker(). */
parseMarker(wp);
/* Need to get the level of the line above top, it is used if there is
* no marker at the top. */
if (top > 1)
{
/* Get the fold level at top - 1. */
level = foldLevelWin(wp, top - 1);
/* The fold may end just above the top, check for that. */
fline.lnum = top - 1;
fline.lvl = level;
getlevel(&fline);
/* If a fold started here, we already had the level, if it stops
* here, we need to use lvl_next. Could also start and end a fold
* in the same line. */
if (fline.lvl > level)
fline.lvl = level - (fline.lvl - fline.lvl_next);
else
fline.lvl = fline.lvl_next;
}
fline.lnum = top;
getlevel(&fline);
}
else
{
fline.lnum = top;
if (foldmethodIsExpr(wp))
{
getlevel = foldlevelExpr;
/* start one line back, because a "<1" may indicate the end of a
* fold in the topline */
if (top > 1)
--fline.lnum;
}
else if (foldmethodIsSyntax(wp))
getlevel = foldlevelSyntax;
#ifdef FEAT_DIFF
else if (foldmethodIsDiff(wp))
getlevel = foldlevelDiff;
#endif
else
getlevel = foldlevelIndent;
/* Backup to a line for which the fold level is defined. Since it's
* always defined for line one, we will stop there. */
fline.lvl = -1;
for ( ; !got_int; --fline.lnum)
{
/* Reset lvl_next each time, because it will be set to a value for
* the next line, but we search backwards here. */
fline.lvl_next = -1;
getlevel(&fline);
if (fline.lvl >= 0)
break;
}
}
/*
* If folding is defined by the syntax, it is possible that a change in
* one line will cause all sub-folds of the current fold to change (e.g.,
* closing a C-style comment can cause folds in the subsequent lines to
* appear). To take that into account we should adjust the value of "bot"
* to point to the end of the current fold:
*/
if (foldlevelSyntax == getlevel)
{
garray_T *gap = &wp->w_folds;
fold_T *fpn = NULL;
int current_fdl = 0;
linenr_T fold_start_lnum = 0;
linenr_T lnum_rel = fline.lnum;
while (current_fdl < fline.lvl)
{
if (!foldFind(gap, lnum_rel, &fpn))
break;
++current_fdl;
fold_start_lnum += fpn->fd_top;
gap = &fpn->fd_nested;
lnum_rel -= fpn->fd_top;
}
if (fpn != NULL && current_fdl == fline.lvl)
{
linenr_T fold_end_lnum = fold_start_lnum + fpn->fd_len;
if (fold_end_lnum > bot)
bot = fold_end_lnum;
}
}
start = fline.lnum;
end = bot;
/* Do at least one line. */
if (start > end && end < wp->w_buffer->b_ml.ml_line_count)
end = start;
while (!got_int)
{
/* Always stop at the end of the file ("end" can be past the end of
* the file). */
if (fline.lnum > wp->w_buffer->b_ml.ml_line_count)
break;
if (fline.lnum > end)
{
/* For "marker", "expr" and "syntax" methods: If a change caused
* a fold to be removed, we need to continue at least until where
* it ended. */
if (getlevel != foldlevelMarker
&& getlevel != foldlevelSyntax
&& getlevel != foldlevelExpr)
break;
if ((start <= end
&& foldFind(&wp->w_folds, end, &fp)
&& fp->fd_top + fp->fd_len - 1 > end)
|| (fline.lvl == 0
&& foldFind(&wp->w_folds, fline.lnum, &fp)
&& fp->fd_top < fline.lnum))
end = fp->fd_top + fp->fd_len - 1;
else if (getlevel == foldlevelSyntax
&& foldLevelWin(wp, fline.lnum) != fline.lvl)
/* For "syntax" method: Compare the foldlevel that the syntax
* tells us to the foldlevel from the existing folds. If they
* don't match continue updating folds. */
end = fline.lnum;
else
break;
}
/* A level 1 fold starts at a line with foldlevel > 0. */
if (fline.lvl > 0)
{
invalid_top = fline.lnum;
invalid_bot = end;
end = foldUpdateIEMSRecurse(&wp->w_folds,
1, start, &fline, getlevel, end, FD_LEVEL);
start = fline.lnum;
}
else
{
if (fline.lnum == wp->w_buffer->b_ml.ml_line_count)
break;
++fline.lnum;
fline.lvl = fline.lvl_next;
getlevel(&fline);
}
}
/* There can't be any folds from start until end now. */
foldRemove(&wp->w_folds, start, end);
/* If some fold changed, need to redraw and position cursor. */
if (fold_changed && wp->w_p_fen)
changed_window_setting_win(wp);
/* If we updated folds past "bot", need to redraw more lines. Don't do
* this in other situations, the changed lines will be redrawn anyway and
* this method can cause the whole window to be updated. */
if (end != bot)
{
if (wp->w_redraw_top == 0 || wp->w_redraw_top > top)
wp->w_redraw_top = top;
if (wp->w_redraw_bot < end)
wp->w_redraw_bot = end;
}
invalid_top = (linenr_T)0;
}
/* foldUpdateIEMSRecurse() {{{2 */
/*
* Update a fold that starts at "flp->lnum". At this line there is always a
* valid foldlevel, and its level >= "level".
* "flp" is valid for "flp->lnum" when called and it's valid when returning.
* "flp->lnum" is set to the lnum just below the fold, if it ends before
* "bot", it's "bot" plus one if the fold continues and it's bigger when using
* the marker method and a text change made following folds to change.
* When returning, "flp->lnum_save" is the line number that was used to get
* the level when the level at "flp->lnum" is invalid.
* Remove any folds from "startlnum" up to here at this level.
* Recursively update nested folds.
* Below line "bot" there are no changes in the text.
* "flp->lnum", "flp->lnum_save" and "bot" are relative to the start of the
* outer fold.
* "flp->off" is the offset to the real line number in the buffer.
*
* All this would be a lot simpler if all folds in the range would be deleted
* and then created again. But we would lose all information about the
* folds, even when making changes that don't affect the folding (e.g. "vj~").
*
* Returns bot, which may have been increased for lines that also need to be
* updated as a result of a detected change in the fold.
*/
static linenr_T
foldUpdateIEMSRecurse(gap, level, startlnum, flp, getlevel, bot, topflags)
garray_T *gap;
int level;
linenr_T startlnum;
fline_T *flp;
void (*getlevel)__ARGS((fline_T *));
linenr_T bot;
int topflags; /* flags used by containing fold */
{
linenr_T ll;
fold_T *fp = NULL;
fold_T *fp2;
int lvl = level;
linenr_T startlnum2 = startlnum;
linenr_T firstlnum = flp->lnum; /* first lnum we got */
int i;
int finish = FALSE;
linenr_T linecount = flp->wp->w_buffer->b_ml.ml_line_count - flp->off;
int concat;
/*
* If using the marker method, the start line is not the start of a fold
* at the level we're dealing with and the level is non-zero, we must use
* the previous fold. But ignore a fold that starts at or below
* startlnum, it must be deleted.
*/
if (getlevel == foldlevelMarker && flp->start <= flp->lvl - level
&& flp->lvl > 0)
{
foldFind(gap, startlnum - 1, &fp);
if (fp >= ((fold_T *)gap->ga_data) + gap->ga_len
|| fp->fd_top >= startlnum)
fp = NULL;
}
/*
* Loop over all lines in this fold, or until "bot" is hit.
* Handle nested folds inside of this fold.
* "flp->lnum" is the current line. When finding the end of the fold, it
* is just below the end of the fold.
* "*flp" contains the level of the line "flp->lnum" or a following one if
* there are lines with an invalid fold level. "flp->lnum_save" is the
* line number that was used to get the fold level (below "flp->lnum" when
* it has an invalid fold level). When called the fold level is always
* valid, thus "flp->lnum_save" is equal to "flp->lnum".
*/
flp->lnum_save = flp->lnum;
while (!got_int)
{
/* Updating folds can be slow, check for CTRL-C. */
line_breakcheck();
/* Set "lvl" to the level of line "flp->lnum". When flp->start is set
* and after the first line of the fold, set the level to zero to
* force the fold to end. Do the same when had_end is set: Previous
* line was marked as end of a fold. */
lvl = flp->lvl;
if (lvl > MAX_LEVEL)
lvl = MAX_LEVEL;
if (flp->lnum > firstlnum
&& (level > lvl - flp->start || level >= flp->had_end))
lvl = 0;
if (flp->lnum > bot && !finish && fp != NULL)
{
/* For "marker" and "syntax" methods:
* - If a change caused a nested fold to be removed, we need to
* delete it and continue at least until where it ended.
* - If a change caused a nested fold to be created, or this fold
* to continue below its original end, need to finish this fold.
*/
if (getlevel != foldlevelMarker
&& getlevel != foldlevelExpr
&& getlevel != foldlevelSyntax)
break;
i = 0;
fp2 = fp;
if (lvl >= level)
{
/* Compute how deep the folds currently are, if it's deeper
* than "lvl" then some must be deleted, need to update
* at least one nested fold. */
ll = flp->lnum - fp->fd_top;
while (foldFind(&fp2->fd_nested, ll, &fp2))
{
++i;
ll -= fp2->fd_top;
}
}
if (lvl < level + i)
{
foldFind(&fp->fd_nested, flp->lnum - fp->fd_top, &fp2);
if (fp2 != NULL)
bot = fp2->fd_top + fp2->fd_len - 1 + fp->fd_top;
}
else if (fp->fd_top + fp->fd_len <= flp->lnum && lvl >= level)
finish = TRUE;
else
break;
}
/* At the start of the first nested fold and at the end of the current
* fold: check if existing folds at this level, before the current
* one, need to be deleted or truncated. */
if (fp == NULL
&& (lvl != level
|| flp->lnum_save >= bot
|| flp->start != 0
|| flp->had_end <= MAX_LEVEL
|| flp->lnum == linecount))
{
/*
* Remove or update folds that have lines between startlnum and
* firstlnum.
*/
while (!got_int)
{
/* set concat to 1 if it's allowed to concatenated this fold
* with a previous one that touches it. */
if (flp->start != 0 || flp->had_end <= MAX_LEVEL)
concat = 0;
else
concat = 1;
/* Find an existing fold to re-use. Preferably one that
* includes startlnum, otherwise one that ends just before
* startlnum or starts after it. */
if (foldFind(gap, startlnum, &fp)
|| (fp < ((fold_T *)gap->ga_data) + gap->ga_len
&& fp->fd_top <= firstlnum)
|| foldFind(gap, firstlnum - concat, &fp)
|| (fp < ((fold_T *)gap->ga_data) + gap->ga_len
&& ((lvl < level && fp->fd_top < flp->lnum)
|| (lvl >= level
&& fp->fd_top <= flp->lnum_save))))
{
if (fp->fd_top + fp->fd_len + concat > firstlnum)
{
/* Use existing fold for the new fold. If it starts
* before where we started looking, extend it. If it
* starts at another line, update nested folds to keep
* their position, compensating for the new fd_top. */
if (fp->fd_top >= startlnum && fp->fd_top != firstlnum)
{
if (fp->fd_top > firstlnum)
/* like lines are inserted */
foldMarkAdjustRecurse(&fp->fd_nested,
(linenr_T)0, (linenr_T)MAXLNUM,
(long)(fp->fd_top - firstlnum), 0L);
else
/* like lines are deleted */
foldMarkAdjustRecurse(&fp->fd_nested,
(linenr_T)0,
(long)(firstlnum - fp->fd_top - 1),
(linenr_T)MAXLNUM,
(long)(fp->fd_top - firstlnum));
fp->fd_len += fp->fd_top - firstlnum;
fp->fd_top = firstlnum;
fold_changed = TRUE;
}
else if (flp->start != 0 && lvl == level
&& fp->fd_top != firstlnum)
{
/* Existing fold that includes startlnum must stop
* if we find the start of a new fold at the same
* level. Split it. Delete contained folds at
* this point to split them too. */
foldRemove(&fp->fd_nested, flp->lnum - fp->fd_top,
flp->lnum - fp->fd_top);
i = (int)(fp - (fold_T *)gap->ga_data);
foldSplit(gap, i, flp->lnum, flp->lnum - 1);
fp = (fold_T *)gap->ga_data + i + 1;
/* If using the "marker" or "syntax" method, we
* need to continue until the end of the fold is
* found. */
if (getlevel == foldlevelMarker
|| getlevel == foldlevelExpr
|| getlevel == foldlevelSyntax)
finish = TRUE;
}
break;
}
if (fp->fd_top >= startlnum)
{
/* A fold that starts at or after startlnum and stops
* before the new fold must be deleted. Continue
* looking for the next one. */
deleteFoldEntry(gap,
(int)(fp - (fold_T *)gap->ga_data), TRUE);
}
else
{
/* A fold has some lines above startlnum, truncate it
* to stop just above startlnum. */
fp->fd_len = startlnum - fp->fd_top;
foldMarkAdjustRecurse(&fp->fd_nested,
(linenr_T)fp->fd_len, (linenr_T)MAXLNUM,
(linenr_T)MAXLNUM, 0L);
fold_changed = TRUE;
}
}
else
{
/* Insert new fold. Careful: ga_data may be NULL and it
* may change! */
i = (int)(fp - (fold_T *)gap->ga_data);
if (foldInsert(gap, i) != OK)
return bot;
fp = (fold_T *)gap->ga_data + i;
/* The new fold continues until bot, unless we find the
* end earlier. */
fp->fd_top = firstlnum;
fp->fd_len = bot - firstlnum + 1;
/* When the containing fold is open, the new fold is open.
* The new fold is closed if the fold above it is closed.
* The first fold depends on the containing fold. */
if (topflags == FD_OPEN)
{
flp->wp->w_fold_manual = TRUE;
fp->fd_flags = FD_OPEN;
}
else if (i <= 0)
{
fp->fd_flags = topflags;
if (topflags != FD_LEVEL)
flp->wp->w_fold_manual = TRUE;
}
else
fp->fd_flags = (fp - 1)->fd_flags;
fp->fd_small = MAYBE;
/* If using the "marker", "expr" or "syntax" method, we
* need to continue until the end of the fold is found. */
if (getlevel == foldlevelMarker
|| getlevel == foldlevelExpr
|| getlevel == foldlevelSyntax)
finish = TRUE;
fold_changed = TRUE;
break;
}
}
}
if (lvl < level || flp->lnum > linecount)
{
/*
* Found a line with a lower foldlevel, this fold ends just above
* "flp->lnum".
*/
break;
}
/*
* The fold includes the line "flp->lnum" and "flp->lnum_save".
* Check "fp" for safety.
*/
if (lvl > level && fp != NULL)
{
/*
* There is a nested fold, handle it recursively.
*/
/* At least do one line (can happen when finish is TRUE). */
if (bot < flp->lnum)
bot = flp->lnum;
/* Line numbers in the nested fold are relative to the start of
* this fold. */
flp->lnum = flp->lnum_save - fp->fd_top;
flp->off += fp->fd_top;
i = (int)(fp - (fold_T *)gap->ga_data);
bot = foldUpdateIEMSRecurse(&fp->fd_nested, level + 1,
startlnum2 - fp->fd_top, flp, getlevel,
bot - fp->fd_top, fp->fd_flags);
fp = (fold_T *)gap->ga_data + i;
flp->lnum += fp->fd_top;
flp->lnum_save += fp->fd_top;
flp->off -= fp->fd_top;
bot += fp->fd_top;
startlnum2 = flp->lnum;
/* This fold may end at the same line, don't incr. flp->lnum. */
}
else
{
/*
* Get the level of the next line, then continue the loop to check
* if it ends there.
* Skip over undefined lines, to find the foldlevel after it.
* For the last line in the file the foldlevel is always valid.
*/
flp->lnum = flp->lnum_save;
ll = flp->lnum + 1;
while (!got_int)
{
/* Make the previous level available to foldlevel(). */
prev_lnum = flp->lnum;
prev_lnum_lvl = flp->lvl;
if (++flp->lnum > linecount)
break;
flp->lvl = flp->lvl_next;
getlevel(flp);
if (flp->lvl >= 0 || flp->had_end <= MAX_LEVEL)
break;
}
prev_lnum = 0;
if (flp->lnum > linecount)
break;
/* leave flp->lnum_save to lnum of the line that was used to get
* the level, flp->lnum to the lnum of the next line. */
flp->lnum_save = flp->lnum;
flp->lnum = ll;
}
}
if (fp == NULL) /* only happens when got_int is set */
return bot;
/*
* Get here when:
* lvl < level: the folds ends just above "flp->lnum"
* lvl >= level: fold continues below "bot"
*/
/* Current fold at least extends until lnum. */
if (fp->fd_len < flp->lnum - fp->fd_top)
{
fp->fd_len = flp->lnum - fp->fd_top;
fp->fd_small = MAYBE;
fold_changed = TRUE;
}
/* Delete contained folds from the end of the last one found until where
* we stopped looking. */
foldRemove(&fp->fd_nested, startlnum2 - fp->fd_top,
flp->lnum - 1 - fp->fd_top);
if (lvl < level)
{
/* End of fold found, update the length when it got shorter. */
if (fp->fd_len != flp->lnum - fp->fd_top)
{
if (fp->fd_top + fp->fd_len > bot + 1)
{
/* fold continued below bot */
if (getlevel == foldlevelMarker
|| getlevel == foldlevelExpr
|| getlevel == foldlevelSyntax)
{
/* marker method: truncate the fold and make sure the
* previously included lines are processed again */
bot = fp->fd_top + fp->fd_len - 1;
fp->fd_len = flp->lnum - fp->fd_top;
}
else
{
/* indent or expr method: split fold to create a new one
* below bot */
i = (int)(fp - (fold_T *)gap->ga_data);
foldSplit(gap, i, flp->lnum, bot);
fp = (fold_T *)gap->ga_data + i;
}
}
else
fp->fd_len = flp->lnum - fp->fd_top;
fold_changed = TRUE;
}
}
/* delete following folds that end before the current line */
for (;;)
{
fp2 = fp + 1;
if (fp2 >= (fold_T *)gap->ga_data + gap->ga_len
|| fp2->fd_top > flp->lnum)
break;
if (fp2->fd_top + fp2->fd_len > flp->lnum)
{
if (fp2->fd_top < flp->lnum)
{
/* Make fold that includes lnum start at lnum. */
foldMarkAdjustRecurse(&fp2->fd_nested,
(linenr_T)0, (long)(flp->lnum - fp2->fd_top - 1),
(linenr_T)MAXLNUM, (long)(fp2->fd_top - flp->lnum));
fp2->fd_len -= flp->lnum - fp2->fd_top;
fp2->fd_top = flp->lnum;
fold_changed = TRUE;
}
if (lvl >= level)
{
/* merge new fold with existing fold that follows */
foldMerge(fp, gap, fp2);
}
break;
}
fold_changed = TRUE;
deleteFoldEntry(gap, (int)(fp2 - (fold_T *)gap->ga_data), TRUE);
}
/* Need to redraw the lines we inspected, which might be further down than
* was asked for. */
if (bot < flp->lnum - 1)
bot = flp->lnum - 1;
return bot;
}
/* foldInsert() {{{2 */
/*
* Insert a new fold in "gap" at position "i".
* Returns OK for success, FAIL for failure.
*/
static int
foldInsert(gap, i)
garray_T *gap;
int i;
{
fold_T *fp;
if (ga_grow(gap, 1) != OK)
return FAIL;
fp = (fold_T *)gap->ga_data + i;
if (i < gap->ga_len)
mch_memmove(fp + 1, fp, sizeof(fold_T) * (gap->ga_len - i));
++gap->ga_len;
ga_init2(&fp->fd_nested, (int)sizeof(fold_T), 10);
return OK;
}
/* foldSplit() {{{2 */
/*
* Split the "i"th fold in "gap", which starts before "top" and ends below
* "bot" in two pieces, one ending above "top" and the other starting below
* "bot".
* The caller must first have taken care of any nested folds from "top" to
* "bot"!
*/
static void
foldSplit(gap, i, top, bot)
garray_T *gap;
int i;
linenr_T top;
linenr_T bot;
{
fold_T *fp;
fold_T *fp2;
garray_T *gap1;
garray_T *gap2;
int idx;
int len;
/* The fold continues below bot, need to split it. */
if (foldInsert(gap, i + 1) == FAIL)
return;
fp = (fold_T *)gap->ga_data + i;
fp[1].fd_top = bot + 1;
fp[1].fd_len = fp->fd_len - (fp[1].fd_top - fp->fd_top);
fp[1].fd_flags = fp->fd_flags;
fp[1].fd_small = MAYBE;
fp->fd_small = MAYBE;
/* Move nested folds below bot to new fold. There can't be
* any between top and bot, they have been removed by the caller. */
gap1 = &fp->fd_nested;
gap2 = &fp[1].fd_nested;
(void)(foldFind(gap1, bot + 1 - fp->fd_top, &fp2));
len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2);
if (len > 0 && ga_grow(gap2, len) == OK)
{
for (idx = 0; idx < len; ++idx)
{
((fold_T *)gap2->ga_data)[idx] = fp2[idx];
((fold_T *)gap2->ga_data)[idx].fd_top
-= fp[1].fd_top - fp->fd_top;
}
gap2->ga_len = len;
gap1->ga_len -= len;
}
fp->fd_len = top - fp->fd_top;
fold_changed = TRUE;
}
/* foldRemove() {{{2 */
/*
* Remove folds within the range "top" to and including "bot".
* Check for these situations:
* 1 2 3
* 1 2 3
* top 2 3 4 5
* 2 3 4 5
* bot 2 3 4 5
* 3 5 6
* 3 5 6
*
* 1: not changed
* 2: truncate to stop above "top"
* 3: split in two parts, one stops above "top", other starts below "bot".
* 4: deleted
* 5: made to start below "bot".
* 6: not changed
*/
static void
foldRemove(gap, top, bot)
garray_T *gap;
linenr_T top;
linenr_T bot;
{
fold_T *fp = NULL;
if (bot < top)
return; /* nothing to do */
for (;;)
{
/* Find fold that includes top or a following one. */
if (foldFind(gap, top, &fp) && fp->fd_top < top)
{
/* 2: or 3: need to delete nested folds */
foldRemove(&fp->fd_nested, top - fp->fd_top, bot - fp->fd_top);
if (fp->fd_top + fp->fd_len > bot + 1)
{
/* 3: need to split it. */
foldSplit(gap, (int)(fp - (fold_T *)gap->ga_data), top, bot);
}
else
{
/* 2: truncate fold at "top". */
fp->fd_len = top - fp->fd_top;
}
fold_changed = TRUE;
continue;
}
if (fp >= (fold_T *)(gap->ga_data) + gap->ga_len
|| fp->fd_top > bot)
{
/* 6: Found a fold below bot, can stop looking. */
break;
}
if (fp->fd_top >= top)
{
/* Found an entry below top. */
fold_changed = TRUE;
if (fp->fd_top + fp->fd_len - 1 > bot)
{
/* 5: Make fold that includes bot start below bot. */
foldMarkAdjustRecurse(&fp->fd_nested,
(linenr_T)0, (long)(bot - fp->fd_top),
(linenr_T)MAXLNUM, (long)(fp->fd_top - bot - 1));
fp->fd_len -= bot - fp->fd_top + 1;
fp->fd_top = bot + 1;
break;
}
/* 4: Delete completely contained fold. */
deleteFoldEntry(gap, (int)(fp - (fold_T *)gap->ga_data), TRUE);
}
}
}
/* foldMerge() {{{2 */
/*
* Merge two adjacent folds (and the nested ones in them).
* This only works correctly when the folds are really adjacent! Thus "fp1"
* must end just above "fp2".
* The resulting fold is "fp1", nested folds are moved from "fp2" to "fp1".
* Fold entry "fp2" in "gap" is deleted.
*/
static void
foldMerge(fp1, gap, fp2)
fold_T *fp1;
garray_T *gap;
fold_T *fp2;
{
fold_T *fp3;
fold_T *fp4;
int idx;
garray_T *gap1 = &fp1->fd_nested;
garray_T *gap2 = &fp2->fd_nested;
/* If the last nested fold in fp1 touches the first nested fold in fp2,
* merge them recursively. */
if (foldFind(gap1, fp1->fd_len - 1L, &fp3) && foldFind(gap2, 0L, &fp4))
foldMerge(fp3, gap2, fp4);
/* Move nested folds in fp2 to the end of fp1. */
if (gap2->ga_len > 0 && ga_grow(gap1, gap2->ga_len) == OK)
{
for (idx = 0; idx < gap2->ga_len; ++idx)
{
((fold_T *)gap1->ga_data)[gap1->ga_len]
= ((fold_T *)gap2->ga_data)[idx];
((fold_T *)gap1->ga_data)[gap1->ga_len].fd_top += fp1->fd_len;
++gap1->ga_len;
}
gap2->ga_len = 0;
}
fp1->fd_len += fp2->fd_len;
deleteFoldEntry(gap, (int)(fp2 - (fold_T *)gap->ga_data), TRUE);
fold_changed = TRUE;
}
/* foldlevelIndent() {{{2 */
/*
* Low level function to get the foldlevel for the "indent" method.
* Doesn't use any caching.
* Returns a level of -1 if the foldlevel depends on surrounding lines.
*/
static void
foldlevelIndent(flp)
fline_T *flp;
{
char_u *s;
buf_T *buf;
linenr_T lnum = flp->lnum + flp->off;
buf = flp->wp->w_buffer;
s = skipwhite(ml_get_buf(buf, lnum, FALSE));
/* empty line or lines starting with a character in 'foldignore': level
* depends on surrounding lines */
if (*s == NUL || vim_strchr(flp->wp->w_p_fdi, *s) != NULL)
{
/* first and last line can't be undefined, use level 0 */
if (lnum == 1 || lnum == buf->b_ml.ml_line_count)
flp->lvl = 0;
else
flp->lvl = -1;
}
else
flp->lvl = get_indent_buf(buf, lnum) / buf->b_p_sw;
if (flp->lvl > flp->wp->w_p_fdn)
{
flp->lvl = flp->wp->w_p_fdn;
if (flp->lvl < 0)
flp->lvl = 0;
}
}
/* foldlevelDiff() {{{2 */
#ifdef FEAT_DIFF
/*
* Low level function to get the foldlevel for the "diff" method.
* Doesn't use any caching.
*/
static void
foldlevelDiff(flp)
fline_T *flp;
{
if (diff_infold(flp->wp, flp->lnum + flp->off))
flp->lvl = 1;
else
flp->lvl = 0;
}
#endif
/* foldlevelExpr() {{{2 */
/*
* Low level function to get the foldlevel for the "expr" method.
* Doesn't use any caching.
* Returns a level of -1 if the foldlevel depends on surrounding lines.
*/
static void
foldlevelExpr(flp)
fline_T *flp;
{
#ifndef FEAT_EVAL
flp->start = FALSE;
flp->lvl = 0;
#else
win_T *win;
int n;
int c;
linenr_T lnum = flp->lnum + flp->off;
int save_keytyped;
win = curwin;
curwin = flp->wp;
curbuf = flp->wp->w_buffer;
set_vim_var_nr(VV_LNUM, lnum);
flp->start = 0;
flp->had_end = flp->end;
flp->end = MAX_LEVEL + 1;
if (lnum <= 1)
flp->lvl = 0;
/* KeyTyped may be reset to 0 when calling a function which invokes
* do_cmdline(). To make 'foldopen' work correctly restore KeyTyped. */
save_keytyped = KeyTyped;
n = eval_foldexpr(flp->wp->w_p_fde, &c);
KeyTyped = save_keytyped;
switch (c)
{
/* "a1", "a2", .. : add to the fold level */
case 'a': if (flp->lvl >= 0)
{
flp->lvl += n;
flp->lvl_next = flp->lvl;
}
flp->start = n;
break;
/* "s1", "s2", .. : subtract from the fold level */
case 's': if (flp->lvl >= 0)
{
if (n > flp->lvl)
flp->lvl_next = 0;
else
flp->lvl_next = flp->lvl - n;
flp->end = flp->lvl_next + 1;
}
break;
/* ">1", ">2", .. : start a fold with a certain level */
case '>': flp->lvl = n;
flp->lvl_next = n;
flp->start = 1;
break;
/* "<1", "<2", .. : end a fold with a certain level */
case '<': flp->lvl_next = n - 1;
flp->end = n;
break;
/* "=": No change in level */
case '=': flp->lvl_next = flp->lvl;
break;
/* "-1", "0", "1", ..: set fold level */
default: if (n < 0)
/* Use the current level for the next line, so that "a1"
* will work there. */
flp->lvl_next = flp->lvl;
else
flp->lvl_next = n;
flp->lvl = n;
break;
}
/* If the level is unknown for the first or the last line in the file, use
* level 0. */
if (flp->lvl < 0)
{
if (lnum <= 1)
{
flp->lvl = 0;
flp->lvl_next = 0;
}
if (lnum == curbuf->b_ml.ml_line_count)
flp->lvl_next = 0;
}
curwin = win;
curbuf = curwin->w_buffer;
#endif
}
/* parseMarker() {{{2 */
/*
* Parse 'foldmarker' and set "foldendmarker", "foldstartmarkerlen" and
* "foldendmarkerlen".
* Relies on the option value to have been checked for correctness already.
*/
static void
parseMarker(wp)
win_T *wp;
{
foldendmarker = vim_strchr(wp->w_p_fmr, ',');
foldstartmarkerlen = (int)(foldendmarker++ - wp->w_p_fmr);
foldendmarkerlen = (int)STRLEN(foldendmarker);
}
/* foldlevelMarker() {{{2 */
/*
* Low level function to get the foldlevel for the "marker" method.
* "foldendmarker", "foldstartmarkerlen" and "foldendmarkerlen" must have been
* set before calling this.
* Requires that flp->lvl is set to the fold level of the previous line!
* Careful: This means you can't call this function twice on the same line.
* Doesn't use any caching.
* Sets flp->start when a start marker was found.
*/
static void
foldlevelMarker(flp)
fline_T *flp;
{
char_u *startmarker;
int cstart;
int cend;
int start_lvl = flp->lvl;
char_u *s;
int n;
/* cache a few values for speed */
startmarker = flp->wp->w_p_fmr;
cstart = *startmarker;
++startmarker;
cend = *foldendmarker;
/* Default: no start found, next level is same as current level */
flp->start = 0;
flp->lvl_next = flp->lvl;
s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, FALSE);
while (*s)
{
if (*s == cstart
&& STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0)
{
/* found startmarker: set flp->lvl */
s += foldstartmarkerlen;
if (VIM_ISDIGIT(*s))
{
n = atoi((char *)s);
if (n > 0)
{
flp->lvl = n;
flp->lvl_next = n;
if (n <= start_lvl)
flp->start = 1;
else
flp->start = n - start_lvl;
}
}
else
{
++flp->lvl;
++flp->lvl_next;
++flp->start;
}
}
else if (*s == cend
&& STRNCMP(s + 1, foldendmarker + 1, foldendmarkerlen - 1) == 0)
{
/* found endmarker: set flp->lvl_next */
s += foldendmarkerlen;
if (VIM_ISDIGIT(*s))
{
n = atoi((char *)s);
if (n > 0)
{
flp->lvl = n;
flp->lvl_next = n - 1;
/* never start a fold with an end marker */
if (flp->lvl_next > start_lvl)
flp->lvl_next = start_lvl;
}
}
else
--flp->lvl_next;
}
else
mb_ptr_adv(s);
}
/* The level can't go negative, must be missing a start marker. */
if (flp->lvl_next < 0)
flp->lvl_next = 0;
}
/* foldlevelSyntax() {{{2 */
/*
* Low level function to get the foldlevel for the "syntax" method.
* Doesn't use any caching.
*/
static void
foldlevelSyntax(flp)
fline_T *flp;
{
#ifndef FEAT_SYN_HL
flp->start = 0;
flp->lvl = 0;
#else
linenr_T lnum = flp->lnum + flp->off;
int n;
/* Use the maximum fold level at the start of this line and the next. */
flp->lvl = syn_get_foldlevel(flp->wp, lnum);
flp->start = 0;
if (lnum < flp->wp->w_buffer->b_ml.ml_line_count)
{
n = syn_get_foldlevel(flp->wp, lnum + 1);
if (n > flp->lvl)
{
flp->start = n - flp->lvl; /* fold(s) start here */
flp->lvl = n;
}
}
#endif
}
/* functions for storing the fold state in a View {{{1 */
/* put_folds() {{{2 */
#if defined(FEAT_SESSION) || defined(PROTO)
static int put_folds_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
static int put_foldopen_recurse __ARGS((FILE *fd, win_T *wp, garray_T *gap, linenr_T off));
static int put_fold_open_close __ARGS((FILE *fd, fold_T *fp, linenr_T off));
/*
* Write commands to "fd" to restore the manual folds in window "wp".
* Return FAIL if writing fails.
*/
int
put_folds(fd, wp)
FILE *fd;
win_T *wp;
{
if (foldmethodIsManual(wp))
{
if (put_line(fd, "silent! normal! zE") == FAIL
|| put_folds_recurse(fd, &wp->w_folds, (linenr_T)0) == FAIL)
return FAIL;
}
/* If some folds are manually opened/closed, need to restore that. */
if (wp->w_fold_manual)
return put_foldopen_recurse(fd, wp, &wp->w_folds, (linenr_T)0);
return OK;
}
/* put_folds_recurse() {{{2 */
/*
* Write commands to "fd" to recreate manually created folds.
* Returns FAIL when writing failed.
*/
static int
put_folds_recurse(fd, gap, off)
FILE *fd;
garray_T *gap;
linenr_T off;
{
int i;
fold_T *fp;
fp = (fold_T *)gap->ga_data;
for (i = 0; i < gap->ga_len; i++)
{
/* Do nested folds first, they will be created closed. */
if (put_folds_recurse(fd, &fp->fd_nested, off + fp->fd_top) == FAIL)
return FAIL;
if (fprintf(fd, "%ld,%ldfold", fp->fd_top + off,
fp->fd_top + off + fp->fd_len - 1) < 0
|| put_eol(fd) == FAIL)
return FAIL;
++fp;
}
return OK;
}
/* put_foldopen_recurse() {{{2 */
/*
* Write commands to "fd" to open and close manually opened/closed folds.
* Returns FAIL when writing failed.
*/
static int
put_foldopen_recurse(fd, wp, gap, off)
FILE *fd;
win_T *wp;
garray_T *gap;
linenr_T off;
{
int i;
int level;
fold_T *fp;
fp = (fold_T *)gap->ga_data;
for (i = 0; i < gap->ga_len; i++)
{
if (fp->fd_flags != FD_LEVEL)
{
if (fp->fd_nested.ga_len > 0)
{
/* open nested folds while this fold is open */
if (fprintf(fd, "%ld", fp->fd_top + off) < 0
|| put_eol(fd) == FAIL
|| put_line(fd, "normal zo") == FAIL)
return FAIL;
if (put_foldopen_recurse(fd, wp, &fp->fd_nested,
off + fp->fd_top)
== FAIL)
return FAIL;
/* close the parent when needed */
if (fp->fd_flags == FD_CLOSED)
{
if (put_fold_open_close(fd, fp, off) == FAIL)
return FAIL;
}
}
else
{
/* Open or close the leaf according to the window foldlevel.
* Do not close a leaf that is already closed, as it will close
* the parent. */
level = foldLevelWin(wp, off + fp->fd_top);
if ((fp->fd_flags == FD_CLOSED && wp->w_p_fdl >= level)
|| (fp->fd_flags != FD_CLOSED && wp->w_p_fdl < level))
if (put_fold_open_close(fd, fp, off) == FAIL)
return FAIL;
}
}
++fp;
}
return OK;
}
/* put_fold_open_close() {{{2 */
/*
* Write the open or close command to "fd".
* Returns FAIL when writing failed.
*/
static int
put_fold_open_close(fd, fp, off)
FILE *fd;
fold_T *fp;
linenr_T off;
{
if (fprintf(fd, "%ld", fp->fd_top + off) < 0
|| put_eol(fd) == FAIL
|| fprintf(fd, "normal z%c",
fp->fd_flags == FD_CLOSED ? 'c' : 'o') < 0
|| put_eol(fd) == FAIL)
return FAIL;
return OK;
}
#endif /* FEAT_SESSION */
/* }}}1 */
#endif /* defined(FEAT_FOLDING) || defined(PROTO) */
| zyz2011-vim | src/fold.c | C | gpl2 | 86,277 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* os_mac_conv.c: Code specifically for Mac string conversions.
*
* This code has been put in a separate file to avoid the conflicts that are
* caused by including both the X11 and Carbon header files.
*/
#define NO_X11_INCLUDES
#define BalloonEval int /* used in header files */
#include "vim.h"
#ifndef FEAT_GUI_MAC
# include <CoreServices/CoreServices.h>
#endif
#if defined(MACOS_CONVERT) || defined(PROTO)
# ifdef PROTO
/* A few dummy types to be able to generate function prototypes. */
typedef int UniChar;
typedef int *TECObjectRef;
typedef int CFStringRef;
# endif
static char_u *mac_utf16_to_utf8 __ARGS((UniChar *from, size_t fromLen, size_t *actualLen));
static UniChar *mac_utf8_to_utf16 __ARGS((char_u *from, size_t fromLen, size_t *actualLen));
/* Converter for composing decomposed HFS+ file paths */
static TECObjectRef gPathConverter;
/* Converter used by mac_utf16_to_utf8 */
static TECObjectRef gUTF16ToUTF8Converter;
/*
* A Mac version of string_convert_ext() for special cases.
*/
char_u *
mac_string_convert(ptr, len, lenp, fail_on_error, from_enc, to_enc, unconvlenp)
char_u *ptr;
int len;
int *lenp;
int fail_on_error;
int from_enc;
int to_enc;
int *unconvlenp;
{
char_u *retval, *d;
CFStringRef cfstr;
int buflen, in, out, l, i;
CFStringEncoding from;
CFStringEncoding to;
switch (from_enc)
{
case 'l': from = kCFStringEncodingISOLatin1; break;
case 'm': from = kCFStringEncodingMacRoman; break;
case 'u': from = kCFStringEncodingUTF8; break;
default: return NULL;
}
switch (to_enc)
{
case 'l': to = kCFStringEncodingISOLatin1; break;
case 'm': to = kCFStringEncodingMacRoman; break;
case 'u': to = kCFStringEncodingUTF8; break;
default: return NULL;
}
if (unconvlenp != NULL)
*unconvlenp = 0;
cfstr = CFStringCreateWithBytes(NULL, ptr, len, from, 0);
if (cfstr == NULL)
fprintf(stderr, "Encoding failed\n");
/* When conversion failed, try excluding bytes from the end, helps when
* there is an incomplete byte sequence. Only do up to 6 bytes to avoid
* looping a long time when there really is something unconvertible. */
while (cfstr == NULL && unconvlenp != NULL && len > 1 && *unconvlenp < 6)
{
--len;
++*unconvlenp;
cfstr = CFStringCreateWithBytes(NULL, ptr, len, from, 0);
}
if (cfstr == NULL)
return NULL;
if (to == kCFStringEncodingUTF8)
buflen = len * 6 + 1;
else
buflen = len + 1;
retval = alloc(buflen);
if (retval == NULL)
{
CFRelease(cfstr);
return NULL;
}
#if 0
CFRange convertRange = CFRangeMake(0, CFStringGetLength(cfstr));
/* Determine output buffer size */
CFStringGetBytes(cfstr, convertRange, to, NULL, FALSE, NULL, 0, (CFIndex *)&buflen);
retval = (buflen > 0) ? alloc(buflen) : NULL;
if (retval == NULL) {
CFRelease(cfstr);
return NULL;
}
if (lenp)
*lenp = buflen / sizeof(char_u);
if (!CFStringGetBytes(cfstr, convertRange, to, NULL, FALSE, retval, buflen, NULL))
#endif
if (!CFStringGetCString(cfstr, (char *)retval, buflen, to))
{
CFRelease(cfstr);
if (fail_on_error)
{
vim_free(retval);
return NULL;
}
fprintf(stderr, "Trying char-by-char conversion...\n");
/* conversion failed for the whole string, but maybe it will work
* for each character */
for (d = retval, in = 0, out = 0; in < len && out < buflen - 1;)
{
if (from == kCFStringEncodingUTF8)
l = utf_ptr2len(ptr + in);
else
l = 1;
cfstr = CFStringCreateWithBytes(NULL, ptr + in, l, from, 0);
if (cfstr == NULL)
{
*d++ = '?';
out++;
}
else
{
if (!CFStringGetCString(cfstr, (char *)d, buflen - out, to))
{
*d++ = '?';
out++;
}
else
{
i = STRLEN(d);
d += i;
out += i;
}
CFRelease(cfstr);
}
in += l;
}
*d = NUL;
if (lenp != NULL)
*lenp = out;
return retval;
}
CFRelease(cfstr);
if (lenp != NULL)
*lenp = STRLEN(retval);
return retval;
}
/*
* Conversion from Apple MacRoman char encoding to UTF-8 or latin1, using
* standard Carbon framework.
* Input: "ptr[*sizep]".
* "real_size" is the size of the buffer that "ptr" points to.
* output is in-place, "sizep" is adjusted.
* Returns OK or FAIL.
*/
int
macroman2enc(ptr, sizep, real_size)
char_u *ptr;
long *sizep;
long real_size;
{
CFStringRef cfstr;
CFRange r;
CFIndex len = *sizep;
/* MacRoman is an 8-bit encoding, no need to move bytes to
* conv_rest[]. */
cfstr = CFStringCreateWithBytes(NULL, ptr, len,
kCFStringEncodingMacRoman, 0);
/*
* If there is a conversion error, try using another
* conversion.
*/
if (cfstr == NULL)
return FAIL;
r.location = 0;
r.length = CFStringGetLength(cfstr);
if (r.length != CFStringGetBytes(cfstr, r,
(enc_utf8) ? kCFStringEncodingUTF8 : kCFStringEncodingISOLatin1,
0, /* no lossy conversion */
0, /* not external representation */
ptr + *sizep, real_size - *sizep, &len))
{
CFRelease(cfstr);
return FAIL;
}
CFRelease(cfstr);
mch_memmove(ptr, ptr + *sizep, len);
*sizep = len;
return OK;
}
/*
* Conversion from UTF-8 or latin1 to MacRoman.
* Input: "from[fromlen]"
* Output: "to[maxtolen]" length in "*tolenp"
* Unconverted rest in rest[*restlenp].
* Returns OK or FAIL.
*/
int
enc2macroman(from, fromlen, to, tolenp, maxtolen, rest, restlenp)
char_u *from;
size_t fromlen;
char_u *to;
int *tolenp;
int maxtolen;
char_u *rest;
int *restlenp;
{
CFStringRef cfstr;
CFRange r;
CFIndex l;
*restlenp = 0;
cfstr = CFStringCreateWithBytes(NULL, from, fromlen,
(enc_utf8) ? kCFStringEncodingUTF8 : kCFStringEncodingISOLatin1,
0);
while (cfstr == NULL && *restlenp < 3 && fromlen > 1)
{
rest[*restlenp++] = from[--fromlen];
cfstr = CFStringCreateWithBytes(NULL, from, fromlen,
(enc_utf8) ? kCFStringEncodingUTF8 : kCFStringEncodingISOLatin1,
0);
}
if (cfstr == NULL)
return FAIL;
r.location = 0;
r.length = CFStringGetLength(cfstr);
if (r.length != CFStringGetBytes(cfstr, r,
kCFStringEncodingMacRoman,
0, /* no lossy conversion */
0, /* not external representation (since vim
* handles this internally */
to, maxtolen, &l))
{
CFRelease(cfstr);
return FAIL;
}
CFRelease(cfstr);
*tolenp = l;
return OK;
}
/*
* Initializes text converters
*/
void
mac_conv_init()
{
TextEncoding utf8_encoding;
TextEncoding utf8_hfsplus_encoding;
TextEncoding utf8_canon_encoding;
TextEncoding utf16_encoding;
utf8_encoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
kTextEncodingDefaultVariant, kUnicodeUTF8Format);
utf8_hfsplus_encoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
kUnicodeHFSPlusCompVariant, kUnicodeUTF8Format);
utf8_canon_encoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
kUnicodeCanonicalCompVariant, kUnicodeUTF8Format);
utf16_encoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
kTextEncodingDefaultVariant, kUnicode16BitFormat);
if (TECCreateConverter(&gPathConverter, utf8_encoding,
utf8_hfsplus_encoding) != noErr)
gPathConverter = NULL;
if (TECCreateConverter(&gUTF16ToUTF8Converter, utf16_encoding,
utf8_canon_encoding) != noErr)
{
/* On pre-10.3, Unicode normalization is not available so
* fall back to non-normalizing converter */
if (TECCreateConverter(&gUTF16ToUTF8Converter, utf16_encoding,
utf8_encoding) != noErr)
gUTF16ToUTF8Converter = NULL;
}
}
/*
* Destroys text converters
*/
void
mac_conv_cleanup()
{
if (gUTF16ToUTF8Converter)
{
TECDisposeConverter(gUTF16ToUTF8Converter);
gUTF16ToUTF8Converter = NULL;
}
if (gPathConverter)
{
TECDisposeConverter(gPathConverter);
gPathConverter = NULL;
}
}
/*
* Conversion from UTF-16 UniChars to 'encoding'
* The function signature uses the real type of UniChar (as typedef'ed in
* CFBase.h) to avoid clashes with X11 header files in the .pro file
*/
char_u *
mac_utf16_to_enc(from, fromLen, actualLen)
unsigned short *from;
size_t fromLen;
size_t *actualLen;
{
/* Following code borrows somewhat from os_mswin.c */
vimconv_T conv;
size_t utf8_len;
char_u *utf8_str;
char_u *result = NULL;
/* Convert to utf-8 first, works better with iconv */
utf8_len = 0;
utf8_str = mac_utf16_to_utf8(from, fromLen, &utf8_len);
if (utf8_str)
{
/* We might be called before we have p_enc set up. */
conv.vc_type = CONV_NONE;
/* If encoding (p_enc) is any unicode, it is actually in utf-8 (vim
* internal unicode is always utf-8) so don't convert in such cases */
if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0)
convert_setup(&conv, (char_u *)"utf-8",
p_enc? p_enc: (char_u *)"macroman");
if (conv.vc_type == CONV_NONE)
{
/* p_enc is utf-8, so we're done. */
result = utf8_str;
}
else
{
result = string_convert(&conv, utf8_str, (int *)&utf8_len);
vim_free(utf8_str);
}
convert_setup(&conv, NULL, NULL);
if (actualLen)
*actualLen = utf8_len;
}
else if (actualLen)
*actualLen = 0;
return result;
}
/*
* Conversion from 'encoding' to UTF-16 UniChars
* The function return uses the real type of UniChar (as typedef'ed in
* CFBase.h) to avoid clashes with X11 header files in the .pro file
*/
unsigned short *
mac_enc_to_utf16(from, fromLen, actualLen)
char_u *from;
size_t fromLen;
size_t *actualLen;
{
/* Following code borrows somewhat from os_mswin.c */
vimconv_T conv;
size_t utf8_len;
char_u *utf8_str;
UniChar *result = NULL;
Boolean should_free_utf8 = FALSE;
do
{
/* Use MacRoman by default, we might be called before we have p_enc
* set up. Convert to utf-8 first, works better with iconv(). Does
* nothing if 'encoding' is "utf-8". */
conv.vc_type = CONV_NONE;
if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0 &&
convert_setup(&conv, p_enc ? p_enc : (char_u *)"macroman",
(char_u *)"utf-8") == FAIL)
break;
if (conv.vc_type != CONV_NONE)
{
utf8_len = fromLen;
utf8_str = string_convert(&conv, from, (int *)&utf8_len);
should_free_utf8 = TRUE;
}
else
{
utf8_str = from;
utf8_len = fromLen;
}
if (utf8_str == NULL)
break;
convert_setup(&conv, NULL, NULL);
result = mac_utf8_to_utf16(utf8_str, utf8_len, actualLen);
if (should_free_utf8)
vim_free(utf8_str);
return result;
}
while (0);
if (actualLen)
*actualLen = 0;
return result;
}
/*
* Converts from UTF-16 UniChars to CFString
* The void * return type is actually a CFStringRef
*/
void *
mac_enc_to_cfstring(from, fromLen)
char_u *from;
size_t fromLen;
{
UniChar *utf16_str;
size_t utf16_len;
CFStringRef result = NULL;
utf16_str = mac_enc_to_utf16(from, fromLen, &utf16_len);
if (utf16_str)
{
result = CFStringCreateWithCharacters(NULL, utf16_str, utf16_len/sizeof(UniChar));
vim_free(utf16_str);
}
return (void *)result;
}
/*
* Converts a decomposed HFS+ UTF-8 path to precomposed UTF-8
*/
char_u *
mac_precompose_path(decompPath, decompLen, precompLen)
char_u *decompPath;
size_t decompLen;
size_t *precompLen;
{
char_u *result = NULL;
size_t actualLen = 0;
if (gPathConverter)
{
result = alloc(decompLen);
if (result)
{
if (TECConvertText(gPathConverter, decompPath,
decompLen, &decompLen, result,
decompLen, &actualLen) != noErr)
{
vim_free(result);
result = NULL;
}
}
}
if (precompLen)
*precompLen = actualLen;
return result;
}
/*
* Converts from UTF-16 UniChars to precomposed UTF-8
*/
static char_u *
mac_utf16_to_utf8(from, fromLen, actualLen)
UniChar *from;
size_t fromLen;
size_t *actualLen;
{
ByteCount utf8_len;
ByteCount inputRead;
char_u *result;
if (gUTF16ToUTF8Converter)
{
result = alloc(fromLen * 6 + 1);
if (result && TECConvertText(gUTF16ToUTF8Converter, (ConstTextPtr)from,
fromLen, &inputRead, result,
(fromLen*6+1)*sizeof(char_u), &utf8_len) == noErr)
{
TECFlushText(gUTF16ToUTF8Converter, result, (fromLen*6+1)*sizeof(char_u), &inputRead);
utf8_len += inputRead;
}
else
{
vim_free(result);
result = NULL;
}
}
else
{
result = NULL;
}
if (actualLen)
*actualLen = result ? utf8_len : 0;
return result;
}
/*
* Converts from UTF-8 to UTF-16 UniChars
*/
static UniChar *
mac_utf8_to_utf16(from, fromLen, actualLen)
char_u *from;
size_t fromLen;
size_t *actualLen;
{
CFStringRef utf8_str;
CFRange convertRange;
UniChar *result = NULL;
utf8_str = CFStringCreateWithBytes(NULL, from, fromLen,
kCFStringEncodingUTF8, FALSE);
if (utf8_str == NULL) {
if (actualLen)
*actualLen = 0;
return NULL;
}
convertRange = CFRangeMake(0, CFStringGetLength(utf8_str));
result = (UniChar *)alloc(convertRange.length * sizeof(UniChar));
CFStringGetCharacters(utf8_str, convertRange, result);
CFRelease(utf8_str);
if (actualLen)
*actualLen = convertRange.length * sizeof(UniChar);
return result;
}
/*
* Sets LANG environment variable in Vim from Mac locale
*/
void
mac_lang_init() {
if (mch_getenv((char_u *)"LANG") == NULL)
{
char buf[20];
if (LocaleRefGetPartString(NULL,
kLocaleLanguageMask | kLocaleLanguageVariantMask |
kLocaleRegionMask | kLocaleRegionVariantMask,
sizeof buf, buf) == noErr && *buf)
{
vim_setenv((char_u *)"LANG", (char_u *)buf);
# ifdef HAVE_LOCALE_H
setlocale(LC_ALL, "");
# endif
}
}
}
#endif /* MACOS_CONVERT */
| zyz2011-vim | src/os_mac_conv.c | C | gpl2 | 14,189 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*/
/*
* DESCRIPTION:
* This module produces Global IME for Vim, on Windows with Internet
* Explorer 5.01 or higher. You need three files "dimm.idl", "dimm.h", and
* "dimm_i.c" when compile this module at your self. "dimm.h", and
* "dimm_i.c" are generated from "dimm.idl" by using MIDL.EXE as like
* "if_ole.h". You can get "dimm.idl" in MSDN web site. I got it below
* URL.
*
* WHAT IS THE GLOBAL IME?:
* Global IME makes capability input Chinese, Japanese, and Korean text into
* Vim buffer on any language version of Windows 98, Windows 95, and Windows
* NT 4.0. See below URL for detail of Global IME. You can also find
* various language version of Global IME at same place.
*
* RUNTIME REQUIREMENTS:
* - Internet Explorer 5.01 or higher.
* - Global IME (with language pack?).
* - Of course Vim for Windows.
*
* URLS:
* - Where you can probably get "dimm.idl".
* http://msdn.microsoft.com/downloads/samples/internet/libraries/ie5_lib/sample.asp
* - Global IME detailed information.
* http://www.microsoft.com/windows/ie/features/ime.asp
*/
#ifdef GLOBAL_IME
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <objbase.h>
extern "C" {
#include "vim.h"
}
#include "dimm.h"
#include "glbl_ime.h"
static IActiveIMMApp *pIApp = NULL;
static IActiveIMMMessagePumpOwner *pIMsg = NULL;
static HWND s_hWnd = NULL;
static BOOL s_bStatus = FALSE; /* for evacuate */
/*
* Initialize Global IME.
* "atom" must be return value of RegisterClass(Ex).
*/
void
global_ime_init(ATOM atom, HWND hWnd)
{
IUnknown *pI;
HRESULT hr;
if (pIApp != NULL || pIMsg != NULL)
return;
OleInitialize(NULL);
/*
* Get interface IUnknown
*/
hr = CoCreateInstance(CLSID_CActiveIMM, NULL, CLSCTX_SERVER,
IID_IUnknown, (void**)&pI);
if (FAILED(hr) || !pI)
return;
/*
* Get interface IActiveIMMApp
*/
hr = pI->QueryInterface(IID_IActiveIMMApp, (void**)&pIApp);
if (FAILED(hr))
pIApp = NULL;
/*
* Get interface IActiveIMMMessagePumpOwner
*/
hr = pI->QueryInterface(IID_IActiveIMMMessagePumpOwner, (void**)&pIMsg);
if (FAILED(hr))
pIMsg = NULL;
if (pIApp != NULL)
{
pIApp->Activate(TRUE);
pIApp->FilterClientWindows(&atom, 1);
}
if (pIMsg != NULL)
pIMsg->Start();
pI->Release();
s_hWnd = hWnd;
}
/*
* Reset and clear Global IME.
*/
void
global_ime_end()
{
if (pIApp != NULL)
{
IActiveIMMApp *p = pIApp;
pIApp = NULL;
p->FilterClientWindows(NULL, 0);
p->Deactivate();
p->Release();
}
if (pIMsg != NULL)
{
IActiveIMMMessagePumpOwner *p = pIMsg;
pIMsg = NULL;
p->End();
p->Release();
}
OleUninitialize();
}
/*
* Replacement for DefWindowProc().
*/
LRESULT WINAPI
global_ime_DefWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
LRESULT lResult;
if (pIApp == NULL || pIApp->OnDefWindowProc(hWnd, Msg,
wParam, lParam, &lResult) != S_OK)
{
#if defined(WIN3264) && defined(FEAT_MBYTE)
if (wide_WindowProc)
lResult = DefWindowProcW(hWnd, Msg, wParam, lParam);
else
#endif
lResult = DefWindowProc(hWnd, Msg, wParam, lParam);
}
return lResult;
}
/*
* Replace with TranslateMessage()
*/
BOOL WINAPI
global_ime_TranslateMessage(CONST MSG *lpMsg)
{
if (pIMsg == NULL || pIMsg->OnTranslateMessage(lpMsg) == S_FALSE)
return TranslateMessage(lpMsg);
return TRUE;
}
/*
* Set position of IME compotision window.
*
* You have to call this before starting composition. If once composition
* started, this can take no effect until that composition have finished. So
* you should handle WM_IME_STARTCOMPOSITION and call this function.
*/
void WINAPI
global_ime_set_position(POINT *pPoint)
{
HIMC hImc = NULL;
if (pIApp == NULL || pPoint == NULL)
return;
if (SUCCEEDED(pIApp->GetContext(s_hWnd, &hImc)))
{
COMPOSITIONFORM CompForm;
CompForm.dwStyle = CFS_POINT;
CompForm.ptCurrentPos = *pPoint;
pIApp->SetCompositionWindow(hImc, &CompForm);
pIApp->ReleaseContext(s_hWnd, hImc);
}
}
/*
* Set font to Global IME
*/
/* GIME_TEST */
void WINAPI
global_ime_set_font(LOGFONT *pFont)
{
HIMC hImc = NULL;
if (pIApp == NULL || pFont == NULL)
return;
if (SUCCEEDED(pIApp->GetContext(s_hWnd, &hImc)))
{
pIApp->SetCompositionFontA(hImc, pFont);
pIApp->ReleaseContext(s_hWnd, hImc);
}
}
#if 0
/*
* for IME control. Save current status of IME, and set force new-status to
* English (turn off).
*/
void WINAPI
global_ime_status_evacuate()
{
HIMC hImc;
if (pIApp != NULL && SUCCEEDED(pIApp->GetContext(s_hWnd, &hImc)))
{
s_bStatus = (pIApp->GetOpenStatus(hImc) == 0) ? TRUE : FALSE;
pIApp->SetOpenStatus(hImc, FALSE);
pIApp->ReleaseContext(s_hWnd, hImc);
}
}
/*
* for IME control. Change IME status to last saved one.
*/
void WINAPI
global_ime_status_restore()
{
HIMC hImc;
if (pIApp != NULL && SUCCEEDED(pIApp->GetContext(s_hWnd, &hImc)))
{
pIApp->SetOpenStatus(hImc, s_bStatus);
pIApp->ReleaseContext(s_hWnd, hImc);
}
}
#endif
void WINAPI
global_ime_set_status(int status)
{
HIMC hImc;
if (pIApp != NULL && SUCCEEDED(pIApp->GetContext(s_hWnd, &hImc)))
{
pIApp->SetOpenStatus(hImc, status ? TRUE : FALSE);
pIApp->ReleaseContext(s_hWnd, hImc);
}
}
int WINAPI
global_ime_get_status()
{
int status = 0;
HIMC hImc;
if (pIApp != NULL && SUCCEEDED(pIApp->GetContext(s_hWnd, &hImc)))
{
status = pIApp->GetOpenStatus(hImc) ? 1 : 0;
pIApp->ReleaseContext(s_hWnd, hImc);
}
return status;
}
#endif /* GLOBAL_IME */
| zyz2011-vim | src/glbl_ime.cpp | C++ | gpl2 | 5,837 |
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Public domain
errstatus=0
for file
do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d
do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp" 1>&2
mkdir "$pathcomp" || lasterr=$?
if test ! -d "$pathcomp"; then
errstatus=$lasterr
fi
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
# mkinstalldirs ends here
| zyz2011-vim | src/mkinstalldirs | Shell | gpl2 | 638 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* Code to handle tags and the tag stack
*/
#include "vim.h"
/*
* Structure to hold pointers to various items in a tag line.
*/
typedef struct tag_pointers
{
/* filled in by parse_tag_line(): */
char_u *tagname; /* start of tag name (skip "file:") */
char_u *tagname_end; /* char after tag name */
char_u *fname; /* first char of file name */
char_u *fname_end; /* char after file name */
char_u *command; /* first char of command */
/* filled in by parse_match(): */
char_u *command_end; /* first char after command */
char_u *tag_fname; /* file name of the tags file */
#ifdef FEAT_EMACS_TAGS
int is_etag; /* TRUE for emacs tag */
#endif
char_u *tagkind; /* "kind:" value */
char_u *tagkind_end; /* end of tagkind */
} tagptrs_T;
/*
* The matching tags are first stored in ga_match[]. In which one depends on
* the priority of the match.
* At the end, the matches from ga_match[] are concatenated, to make a list
* sorted on priority.
*/
#define MT_ST_CUR 0 /* static match in current file */
#define MT_GL_CUR 1 /* global match in current file */
#define MT_GL_OTH 2 /* global match in other file */
#define MT_ST_OTH 3 /* static match in other file */
#define MT_IC_ST_CUR 4 /* icase static match in current file */
#define MT_IC_GL_CUR 5 /* icase global match in current file */
#define MT_IC_GL_OTH 6 /* icase global match in other file */
#define MT_IC_ST_OTH 7 /* icase static match in other file */
#define MT_IC_OFF 4 /* add for icase match */
#define MT_RE_OFF 8 /* add for regexp match */
#define MT_MASK 7 /* mask for printing priority */
#define MT_COUNT 16
static char *mt_names[MT_COUNT/2] =
{"FSC", "F C", "F ", "FS ", " SC", " C", " ", " S "};
#define NOTAGFILE 99 /* return value for jumpto_tag */
static char_u *nofile_fname = NULL; /* fname for NOTAGFILE error */
static void taglen_advance __ARGS((int l));
static int jumpto_tag __ARGS((char_u *lbuf, int forceit, int keep_help));
#ifdef FEAT_EMACS_TAGS
static int parse_tag_line __ARGS((char_u *lbuf, int is_etag, tagptrs_T *tagp));
#else
static int parse_tag_line __ARGS((char_u *lbuf, tagptrs_T *tagp));
#endif
static int test_for_static __ARGS((tagptrs_T *));
static int parse_match __ARGS((char_u *lbuf, tagptrs_T *tagp));
static char_u *tag_full_fname __ARGS((tagptrs_T *tagp));
static char_u *expand_tag_fname __ARGS((char_u *fname, char_u *tag_fname, int expand));
#ifdef FEAT_EMACS_TAGS
static int test_for_current __ARGS((int, char_u *, char_u *, char_u *, char_u *));
#else
static int test_for_current __ARGS((char_u *, char_u *, char_u *, char_u *));
#endif
static int find_extra __ARGS((char_u **pp));
static char_u *bottommsg = (char_u *)N_("E555: at bottom of tag stack");
static char_u *topmsg = (char_u *)N_("E556: at top of tag stack");
static char_u *tagmatchname = NULL; /* name of last used tag */
/*
* We use ftello() here, if available. It returns off_t instead of long,
* which helps if long is 32 bit and off_t is 64 bit.
* We assume that when fseeko() is available then ftello() is too.
*/
#ifdef HAVE_FSEEKO
# define ftell ftello
#endif
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
/*
* Tag for preview window is remembered separately, to avoid messing up the
* normal tagstack.
*/
static taggy_T ptag_entry = {NULL, {INIT_POS_T(0, 0, 0), 0}, 0, 0};
#endif
/*
* Jump to tag; handling of tag commands and tag stack
*
* *tag != NUL: ":tag {tag}", jump to new tag, add to tag stack
*
* type == DT_TAG: ":tag [tag]", jump to newer position or same tag again
* type == DT_HELP: like DT_TAG, but don't use regexp.
* type == DT_POP: ":pop" or CTRL-T, jump to old position
* type == DT_NEXT: jump to next match of same tag
* type == DT_PREV: jump to previous match of same tag
* type == DT_FIRST: jump to first match of same tag
* type == DT_LAST: jump to last match of same tag
* type == DT_SELECT: ":tselect [tag]", select tag from a list of all matches
* type == DT_JUMP: ":tjump [tag]", jump to tag or select tag from a list
* type == DT_CSCOPE: use cscope to find the tag
* type == DT_LTAG: use location list for displaying tag matches
* type == DT_FREE: free cached matches
*
* for cscope, returns TRUE if we jumped to tag or aborted, FALSE otherwise
*/
int
do_tag(tag, type, count, forceit, verbose)
char_u *tag; /* tag (pattern) to jump to */
int type;
int count;
int forceit; /* :ta with ! */
int verbose; /* print "tag not found" message */
{
taggy_T *tagstack = curwin->w_tagstack;
int tagstackidx = curwin->w_tagstackidx;
int tagstacklen = curwin->w_tagstacklen;
int cur_match = 0;
int cur_fnum = curbuf->b_fnum;
int oldtagstackidx = tagstackidx;
int prevtagstackidx = tagstackidx;
int prev_num_matches;
int new_tag = FALSE;
int other_name;
int i, j, k;
int idx;
int ic;
char_u *p;
char_u *name;
int no_regexp = FALSE;
int error_cur_match = 0;
char_u *command_end;
int save_pos = FALSE;
fmark_T saved_fmark;
int taglen;
#ifdef FEAT_CSCOPE
int jumped_to_tag = FALSE;
#endif
tagptrs_T tagp, tagp2;
int new_num_matches;
char_u **new_matches;
int attr;
int use_tagstack;
int skip_msg = FALSE;
char_u *buf_ffname = curbuf->b_ffname; /* name to use for
priority computation */
/* remember the matches for the last used tag */
static int num_matches = 0;
static int max_num_matches = 0; /* limit used for match search */
static char_u **matches = NULL;
static int flags;
#ifdef EXITFREE
if (type == DT_FREE)
{
/* remove the list of matches */
FreeWild(num_matches, matches);
# ifdef FEAT_CSCOPE
cs_free_tags();
# endif
num_matches = 0;
return FALSE;
}
#endif
if (type == DT_HELP)
{
type = DT_TAG;
no_regexp = TRUE;
}
prev_num_matches = num_matches;
free_string_option(nofile_fname);
nofile_fname = NULL;
clearpos(&saved_fmark.mark); /* shutup gcc 4.0 */
saved_fmark.fnum = 0;
/*
* Don't add a tag to the tagstack if 'tagstack' has been reset.
*/
if ((!p_tgst && *tag != NUL))
{
use_tagstack = FALSE;
new_tag = TRUE;
}
else
{
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
use_tagstack = FALSE;
else
#endif
use_tagstack = TRUE;
/* new pattern, add to the tag stack */
if (*tag != NUL
&& (type == DT_TAG || type == DT_SELECT || type == DT_JUMP
#ifdef FEAT_QUICKFIX
|| type == DT_LTAG
#endif
#ifdef FEAT_CSCOPE
|| type == DT_CSCOPE
#endif
))
{
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
if (ptag_entry.tagname != NULL
&& STRCMP(ptag_entry.tagname, tag) == 0)
{
/* Jumping to same tag: keep the current match, so that
* the CursorHold autocommand example works. */
cur_match = ptag_entry.cur_match;
cur_fnum = ptag_entry.cur_fnum;
}
else
{
vim_free(ptag_entry.tagname);
if ((ptag_entry.tagname = vim_strsave(tag)) == NULL)
goto end_do_tag;
}
}
else
#endif
{
/*
* If the last used entry is not at the top, delete all tag
* stack entries above it.
*/
while (tagstackidx < tagstacklen)
vim_free(tagstack[--tagstacklen].tagname);
/* if the tagstack is full: remove oldest entry */
if (++tagstacklen > TAGSTACKSIZE)
{
tagstacklen = TAGSTACKSIZE;
vim_free(tagstack[0].tagname);
for (i = 1; i < tagstacklen; ++i)
tagstack[i - 1] = tagstack[i];
--tagstackidx;
}
/*
* put the tag name in the tag stack
*/
if ((tagstack[tagstackidx].tagname = vim_strsave(tag)) == NULL)
{
curwin->w_tagstacklen = tagstacklen - 1;
goto end_do_tag;
}
curwin->w_tagstacklen = tagstacklen;
save_pos = TRUE; /* save the cursor position below */
}
new_tag = TRUE;
}
else
{
if (
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
g_do_tagpreview != 0 ? ptag_entry.tagname == NULL :
#endif
tagstacklen == 0)
{
/* empty stack */
EMSG(_(e_tagstack));
goto end_do_tag;
}
if (type == DT_POP) /* go to older position */
{
#ifdef FEAT_FOLDING
int old_KeyTyped = KeyTyped;
#endif
if ((tagstackidx -= count) < 0)
{
EMSG(_(bottommsg));
if (tagstackidx + count == 0)
{
/* We did [num]^T from the bottom of the stack */
tagstackidx = 0;
goto end_do_tag;
}
/* We weren't at the bottom of the stack, so jump all the
* way to the bottom now.
*/
tagstackidx = 0;
}
else if (tagstackidx >= tagstacklen) /* count == 0? */
{
EMSG(_(topmsg));
goto end_do_tag;
}
/* Make a copy of the fmark, autocommands may invalidate the
* tagstack before it's used. */
saved_fmark = tagstack[tagstackidx].fmark;
if (saved_fmark.fnum != curbuf->b_fnum)
{
/*
* Jump to other file. If this fails (e.g. because the
* file was changed) keep original position in tag stack.
*/
if (buflist_getfile(saved_fmark.fnum, saved_fmark.mark.lnum,
GETF_SETMARK, forceit) == FAIL)
{
tagstackidx = oldtagstackidx; /* back to old posn */
goto end_do_tag;
}
/* An BufReadPost autocommand may jump to the '" mark, but
* we don't what that here. */
curwin->w_cursor.lnum = saved_fmark.mark.lnum;
}
else
{
setpcmark();
curwin->w_cursor.lnum = saved_fmark.mark.lnum;
}
curwin->w_cursor.col = saved_fmark.mark.col;
curwin->w_set_curswant = TRUE;
check_cursor();
#ifdef FEAT_FOLDING
if ((fdo_flags & FDO_TAG) && old_KeyTyped)
foldOpenCursor();
#endif
/* remove the old list of matches */
FreeWild(num_matches, matches);
#ifdef FEAT_CSCOPE
cs_free_tags();
#endif
num_matches = 0;
tag_freematch();
goto end_do_tag;
}
if (type == DT_TAG
#if defined(FEAT_QUICKFIX)
|| type == DT_LTAG
#endif
)
{
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
cur_match = ptag_entry.cur_match;
cur_fnum = ptag_entry.cur_fnum;
}
else
#endif
{
/* ":tag" (no argument): go to newer pattern */
save_pos = TRUE; /* save the cursor position below */
if ((tagstackidx += count - 1) >= tagstacklen)
{
/*
* Beyond the last one, just give an error message and
* go to the last one. Don't store the cursor
* position.
*/
tagstackidx = tagstacklen - 1;
EMSG(_(topmsg));
save_pos = FALSE;
}
else if (tagstackidx < 0) /* must have been count == 0 */
{
EMSG(_(bottommsg));
tagstackidx = 0;
goto end_do_tag;
}
cur_match = tagstack[tagstackidx].cur_match;
cur_fnum = tagstack[tagstackidx].cur_fnum;
}
new_tag = TRUE;
}
else /* go to other matching tag */
{
/* Save index for when selection is cancelled. */
prevtagstackidx = tagstackidx;
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
cur_match = ptag_entry.cur_match;
cur_fnum = ptag_entry.cur_fnum;
}
else
#endif
{
if (--tagstackidx < 0)
tagstackidx = 0;
cur_match = tagstack[tagstackidx].cur_match;
cur_fnum = tagstack[tagstackidx].cur_fnum;
}
switch (type)
{
case DT_FIRST: cur_match = count - 1; break;
case DT_SELECT:
case DT_JUMP:
#ifdef FEAT_CSCOPE
case DT_CSCOPE:
#endif
case DT_LAST: cur_match = MAXCOL - 1; break;
case DT_NEXT: cur_match += count; break;
case DT_PREV: cur_match -= count; break;
}
if (cur_match >= MAXCOL)
cur_match = MAXCOL - 1;
else if (cur_match < 0)
{
EMSG(_("E425: Cannot go before first matching tag"));
skip_msg = TRUE;
cur_match = 0;
cur_fnum = curbuf->b_fnum;
}
}
}
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
if (type != DT_SELECT && type != DT_JUMP)
{
ptag_entry.cur_match = cur_match;
ptag_entry.cur_fnum = cur_fnum;
}
}
else
#endif
{
/*
* For ":tag [arg]" or ":tselect" remember position before the jump.
*/
saved_fmark = tagstack[tagstackidx].fmark;
if (save_pos)
{
tagstack[tagstackidx].fmark.mark = curwin->w_cursor;
tagstack[tagstackidx].fmark.fnum = curbuf->b_fnum;
}
/* Curwin will change in the call to jumpto_tag() if ":stag" was
* used or an autocommand jumps to another window; store value of
* tagstackidx now. */
curwin->w_tagstackidx = tagstackidx;
if (type != DT_SELECT && type != DT_JUMP)
{
curwin->w_tagstack[tagstackidx].cur_match = cur_match;
curwin->w_tagstack[tagstackidx].cur_fnum = cur_fnum;
}
}
}
/* When not using the current buffer get the name of buffer "cur_fnum".
* Makes sure that the tag order doesn't change when using a remembered
* position for "cur_match". */
if (cur_fnum != curbuf->b_fnum)
{
buf_T *buf = buflist_findnr(cur_fnum);
if (buf != NULL)
buf_ffname = buf->b_ffname;
}
/*
* Repeat searching for tags, when a file has not been found.
*/
for (;;)
{
/*
* When desired match not found yet, try to find it (and others).
*/
if (use_tagstack)
name = tagstack[tagstackidx].tagname;
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
else if (g_do_tagpreview != 0)
name = ptag_entry.tagname;
#endif
else
name = tag;
other_name = (tagmatchname == NULL || STRCMP(tagmatchname, name) != 0);
if (new_tag
|| (cur_match >= num_matches && max_num_matches != MAXCOL)
|| other_name)
{
if (other_name)
{
vim_free(tagmatchname);
tagmatchname = vim_strsave(name);
}
/*
* If a count is supplied to the ":tag <name>" command, then
* jump to count'th matching tag.
*/
if (type == DT_TAG && *tag != NUL && count > 0)
cur_match = count - 1;
if (type == DT_SELECT || type == DT_JUMP
#if defined(FEAT_QUICKFIX)
|| type == DT_LTAG
#endif
)
cur_match = MAXCOL - 1;
max_num_matches = cur_match + 1;
/* when the argument starts with '/', use it as a regexp */
if (!no_regexp && *name == '/')
{
flags = TAG_REGEXP;
++name;
}
else
flags = TAG_NOIC;
#ifdef FEAT_CSCOPE
if (type == DT_CSCOPE)
flags = TAG_CSCOPE;
#endif
if (verbose)
flags |= TAG_VERBOSE;
if (find_tags(name, &new_num_matches, &new_matches, flags,
max_num_matches, buf_ffname) == OK
&& new_num_matches < max_num_matches)
max_num_matches = MAXCOL; /* If less than max_num_matches
found: all matches found. */
/* If there already were some matches for the same name, move them
* to the start. Avoids that the order changes when using
* ":tnext" and jumping to another file. */
if (!new_tag && !other_name)
{
/* Find the position of each old match in the new list. Need
* to use parse_match() to find the tag line. */
idx = 0;
for (j = 0; j < num_matches; ++j)
{
parse_match(matches[j], &tagp);
for (i = idx; i < new_num_matches; ++i)
{
parse_match(new_matches[i], &tagp2);
if (STRCMP(tagp.tagname, tagp2.tagname) == 0)
{
p = new_matches[i];
for (k = i; k > idx; --k)
new_matches[k] = new_matches[k - 1];
new_matches[idx++] = p;
break;
}
}
}
}
FreeWild(num_matches, matches);
num_matches = new_num_matches;
matches = new_matches;
}
if (num_matches <= 0)
{
if (verbose)
EMSG2(_("E426: tag not found: %s"), name);
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
g_do_tagpreview = 0;
#endif
}
else
{
int ask_for_selection = FALSE;
#ifdef FEAT_CSCOPE
if (type == DT_CSCOPE && num_matches > 1)
{
cs_print_tags();
ask_for_selection = TRUE;
}
else
#endif
if (type == DT_SELECT || (type == DT_JUMP && num_matches > 1))
{
/*
* List all the matching tags.
* Assume that the first match indicates how long the tags can
* be, and align the file names to that.
*/
parse_match(matches[0], &tagp);
taglen = (int)(tagp.tagname_end - tagp.tagname + 2);
if (taglen < 18)
taglen = 18;
if (taglen > Columns - 25)
taglen = MAXCOL;
if (msg_col == 0)
msg_didout = FALSE; /* overwrite previous message */
msg_start();
MSG_PUTS_ATTR(_(" # pri kind tag"), hl_attr(HLF_T));
msg_clr_eos();
taglen_advance(taglen);
MSG_PUTS_ATTR(_("file\n"), hl_attr(HLF_T));
for (i = 0; i < num_matches && !got_int; ++i)
{
parse_match(matches[i], &tagp);
if (!new_tag && (
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
(g_do_tagpreview != 0
&& i == ptag_entry.cur_match) ||
#endif
(use_tagstack
&& i == tagstack[tagstackidx].cur_match)))
*IObuff = '>';
else
*IObuff = ' ';
vim_snprintf((char *)IObuff + 1, IOSIZE - 1,
"%2d %s ", i + 1,
mt_names[matches[i][0] & MT_MASK]);
msg_puts(IObuff);
if (tagp.tagkind != NULL)
msg_outtrans_len(tagp.tagkind,
(int)(tagp.tagkind_end - tagp.tagkind));
msg_advance(13);
msg_outtrans_len_attr(tagp.tagname,
(int)(tagp.tagname_end - tagp.tagname),
hl_attr(HLF_T));
msg_putchar(' ');
taglen_advance(taglen);
/* Find out the actual file name. If it is long, truncate
* it and put "..." in the middle */
p = tag_full_fname(&tagp);
if (p != NULL)
{
msg_puts_long_attr(p, hl_attr(HLF_D));
vim_free(p);
}
if (msg_col > 0)
msg_putchar('\n');
if (got_int)
break;
msg_advance(15);
/* print any extra fields */
command_end = tagp.command_end;
if (command_end != NULL)
{
p = command_end + 3;
while (*p && *p != '\r' && *p != '\n')
{
while (*p == TAB)
++p;
/* skip "file:" without a value (static tag) */
if (STRNCMP(p, "file:", 5) == 0
&& vim_isspace(p[5]))
{
p += 5;
continue;
}
/* skip "kind:<kind>" and "<kind>" */
if (p == tagp.tagkind
|| (p + 5 == tagp.tagkind
&& STRNCMP(p, "kind:", 5) == 0))
{
p = tagp.tagkind_end;
continue;
}
/* print all other extra fields */
attr = hl_attr(HLF_CM);
while (*p && *p != '\r' && *p != '\n')
{
if (msg_col + ptr2cells(p) >= Columns)
{
msg_putchar('\n');
if (got_int)
break;
msg_advance(15);
}
p = msg_outtrans_one(p, attr);
if (*p == TAB)
{
msg_puts_attr((char_u *)" ", attr);
break;
}
if (*p == ':')
attr = 0;
}
}
if (msg_col > 15)
{
msg_putchar('\n');
if (got_int)
break;
msg_advance(15);
}
}
else
{
for (p = tagp.command;
*p && *p != '\r' && *p != '\n'; ++p)
;
command_end = p;
}
/*
* Put the info (in several lines) at column 15.
* Don't display "/^" and "?^".
*/
p = tagp.command;
if (*p == '/' || *p == '?')
{
++p;
if (*p == '^')
++p;
}
/* Remove leading whitespace from pattern */
while (p != command_end && vim_isspace(*p))
++p;
while (p != command_end)
{
if (msg_col + (*p == TAB ? 1 : ptr2cells(p)) > Columns)
msg_putchar('\n');
if (got_int)
break;
msg_advance(15);
/* skip backslash used for escaping command char */
if (*p == '\\' && *(p + 1) == *tagp.command)
++p;
if (*p == TAB)
{
msg_putchar(' ');
++p;
}
else
p = msg_outtrans_one(p, 0);
/* don't display the "$/;\"" and "$?;\"" */
if (p == command_end - 2 && *p == '$'
&& *(p + 1) == *tagp.command)
break;
/* don't display matching '/' or '?' */
if (p == command_end - 1 && *p == *tagp.command
&& (*p == '/' || *p == '?'))
break;
}
if (msg_col)
msg_putchar('\n');
ui_breakcheck();
}
if (got_int)
got_int = FALSE; /* only stop the listing */
ask_for_selection = TRUE;
}
#if defined(FEAT_QUICKFIX) && defined(FEAT_EVAL)
else if (type == DT_LTAG)
{
list_T *list;
char_u tag_name[128 + 1];
char_u *fname;
char_u *cmd;
/*
* Add the matching tags to the location list for the current
* window.
*/
fname = alloc(MAXPATHL + 1);
cmd = alloc(CMDBUFFSIZE + 1);
list = list_alloc();
if (list == NULL || fname == NULL || cmd == NULL)
{
vim_free(cmd);
vim_free(fname);
if (list != NULL)
list_free(list, TRUE);
goto end_do_tag;
}
for (i = 0; i < num_matches; ++i)
{
int len, cmd_len;
long lnum;
dict_T *dict;
parse_match(matches[i], &tagp);
/* Save the tag name */
len = (int)(tagp.tagname_end - tagp.tagname);
if (len > 128)
len = 128;
vim_strncpy(tag_name, tagp.tagname, len);
tag_name[len] = NUL;
/* Save the tag file name */
p = tag_full_fname(&tagp);
if (p == NULL)
continue;
vim_strncpy(fname, p, MAXPATHL);
vim_free(p);
/*
* Get the line number or the search pattern used to locate
* the tag.
*/
lnum = 0;
if (isdigit(*tagp.command))
/* Line number is used to locate the tag */
lnum = atol((char *)tagp.command);
else
{
char_u *cmd_start, *cmd_end;
/* Search pattern is used to locate the tag */
/* Locate the end of the command */
cmd_start = tagp.command;
cmd_end = tagp.command_end;
if (cmd_end == NULL)
{
for (p = tagp.command;
*p && *p != '\r' && *p != '\n'; ++p)
;
cmd_end = p;
}
/*
* Now, cmd_end points to the character after the
* command. Adjust it to point to the last
* character of the command.
*/
cmd_end--;
/*
* Skip the '/' and '?' characters at the
* beginning and end of the search pattern.
*/
if (*cmd_start == '/' || *cmd_start == '?')
cmd_start++;
if (*cmd_end == '/' || *cmd_end == '?')
cmd_end--;
len = 0;
cmd[0] = NUL;
/*
* If "^" is present in the tag search pattern, then
* copy it first.
*/
if (*cmd_start == '^')
{
STRCPY(cmd, "^");
cmd_start++;
len++;
}
/*
* Precede the tag pattern with \V to make it very
* nomagic.
*/
STRCAT(cmd, "\\V");
len += 2;
cmd_len = (int)(cmd_end - cmd_start + 1);
if (cmd_len > (CMDBUFFSIZE - 5))
cmd_len = CMDBUFFSIZE - 5;
STRNCAT(cmd, cmd_start, cmd_len);
len += cmd_len;
if (cmd[len - 1] == '$')
{
/*
* Replace '$' at the end of the search pattern
* with '\$'
*/
cmd[len - 1] = '\\';
cmd[len] = '$';
len++;
}
cmd[len] = NUL;
}
if ((dict = dict_alloc()) == NULL)
continue;
if (list_append_dict(list, dict) == FAIL)
{
vim_free(dict);
continue;
}
dict_add_nr_str(dict, "text", 0L, tag_name);
dict_add_nr_str(dict, "filename", 0L, fname);
dict_add_nr_str(dict, "lnum", lnum, NULL);
if (lnum == 0)
dict_add_nr_str(dict, "pattern", 0L, cmd);
}
vim_snprintf((char *)IObuff, IOSIZE, "ltag %s", tag);
set_errorlist(curwin, list, ' ', IObuff);
list_free(list, TRUE);
vim_free(fname);
vim_free(cmd);
cur_match = 0; /* Jump to the first tag */
}
#endif
if (ask_for_selection == TRUE)
{
/*
* Ask to select a tag from the list.
*/
i = prompt_for_number(NULL);
if (i <= 0 || i > num_matches || got_int)
{
/* no valid choice: don't change anything */
if (use_tagstack)
{
tagstack[tagstackidx].fmark = saved_fmark;
tagstackidx = prevtagstackidx;
}
#ifdef FEAT_CSCOPE
cs_free_tags();
jumped_to_tag = TRUE;
#endif
break;
}
cur_match = i - 1;
}
if (cur_match >= num_matches)
{
/* Avoid giving this error when a file wasn't found and we're
* looking for a match in another file, which wasn't found.
* There will be an EMSG("file doesn't exist") below then. */
if ((type == DT_NEXT || type == DT_FIRST)
&& nofile_fname == NULL)
{
if (num_matches == 1)
EMSG(_("E427: There is only one matching tag"));
else
EMSG(_("E428: Cannot go beyond last matching tag"));
skip_msg = TRUE;
}
cur_match = num_matches - 1;
}
if (use_tagstack)
{
tagstack[tagstackidx].cur_match = cur_match;
tagstack[tagstackidx].cur_fnum = cur_fnum;
++tagstackidx;
}
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
else if (g_do_tagpreview != 0)
{
ptag_entry.cur_match = cur_match;
ptag_entry.cur_fnum = cur_fnum;
}
#endif
/*
* Only when going to try the next match, report that the previous
* file didn't exist. Otherwise an EMSG() is given below.
*/
if (nofile_fname != NULL && error_cur_match != cur_match)
smsg((char_u *)_("File \"%s\" does not exist"), nofile_fname);
ic = (matches[cur_match][0] & MT_IC_OFF);
if (type != DT_SELECT && type != DT_JUMP
#ifdef FEAT_CSCOPE
&& type != DT_CSCOPE
#endif
&& (num_matches > 1 || ic)
&& !skip_msg)
{
/* Give an indication of the number of matching tags */
sprintf((char *)IObuff, _("tag %d of %d%s"),
cur_match + 1,
num_matches,
max_num_matches != MAXCOL ? _(" or more") : "");
if (ic)
STRCAT(IObuff, _(" Using tag with different case!"));
if ((num_matches > prev_num_matches || new_tag)
&& num_matches > 1)
{
if (ic)
msg_attr(IObuff, hl_attr(HLF_W));
else
msg(IObuff);
msg_scroll = TRUE; /* don't overwrite this message */
}
else
give_warning(IObuff, ic);
if (ic && !msg_scrolled && msg_silent == 0)
{
out_flush();
ui_delay(1000L, TRUE);
}
}
#ifdef FEAT_AUTOCMD
/* Let the SwapExists event know what tag we are jumping to. */
vim_snprintf((char *)IObuff, IOSIZE, ":ta %s\r", name);
set_vim_var_string(VV_SWAPCOMMAND, IObuff, -1);
#endif
/*
* Jump to the desired match.
*/
i = jumpto_tag(matches[cur_match], forceit, type != DT_CSCOPE);
#ifdef FEAT_AUTOCMD
set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
#endif
if (i == NOTAGFILE)
{
/* File not found: try again with another matching tag */
if ((type == DT_PREV && cur_match > 0)
|| ((type == DT_TAG || type == DT_NEXT
|| type == DT_FIRST)
&& (max_num_matches != MAXCOL
|| cur_match < num_matches - 1)))
{
error_cur_match = cur_match;
if (use_tagstack)
--tagstackidx;
if (type == DT_PREV)
--cur_match;
else
{
type = DT_NEXT;
++cur_match;
}
continue;
}
EMSG2(_("E429: File \"%s\" does not exist"), nofile_fname);
}
else
{
/* We may have jumped to another window, check that
* tagstackidx is still valid. */
if (use_tagstack && tagstackidx > curwin->w_tagstacklen)
tagstackidx = curwin->w_tagstackidx;
#ifdef FEAT_CSCOPE
jumped_to_tag = TRUE;
#endif
}
}
break;
}
end_do_tag:
/* Only store the new index when using the tagstack and it's valid. */
if (use_tagstack && tagstackidx <= curwin->w_tagstacklen)
curwin->w_tagstackidx = tagstackidx;
#ifdef FEAT_WINDOWS
postponed_split = 0; /* don't split next time */
#endif
#ifdef FEAT_CSCOPE
return jumped_to_tag;
#else
return FALSE;
#endif
}
/*
* Free cached tags.
*/
void
tag_freematch()
{
vim_free(tagmatchname);
tagmatchname = NULL;
}
static void
taglen_advance(l)
int l;
{
if (l == MAXCOL)
{
msg_putchar('\n');
msg_advance(24);
}
else
msg_advance(13 + l);
}
/*
* Print the tag stack
*/
void
do_tags(eap)
exarg_T *eap UNUSED;
{
int i;
char_u *name;
taggy_T *tagstack = curwin->w_tagstack;
int tagstackidx = curwin->w_tagstackidx;
int tagstacklen = curwin->w_tagstacklen;
/* Highlight title */
MSG_PUTS_TITLE(_("\n # TO tag FROM line in file/text"));
for (i = 0; i < tagstacklen; ++i)
{
if (tagstack[i].tagname != NULL)
{
name = fm_getname(&(tagstack[i].fmark), 30);
if (name == NULL) /* file name not available */
continue;
msg_putchar('\n');
sprintf((char *)IObuff, "%c%2d %2d %-15s %5ld ",
i == tagstackidx ? '>' : ' ',
i + 1,
tagstack[i].cur_match + 1,
tagstack[i].tagname,
tagstack[i].fmark.mark.lnum);
msg_outtrans(IObuff);
msg_outtrans_attr(name, tagstack[i].fmark.fnum == curbuf->b_fnum
? hl_attr(HLF_D) : 0);
vim_free(name);
}
out_flush(); /* show one line at a time */
}
if (tagstackidx == tagstacklen) /* idx at top of stack */
MSG_PUTS("\n>");
}
/* When not using a CR for line separator, use vim_fgets() to read tag lines.
* For the Mac use tag_fgets(). It can handle any line separator, but is much
* slower than vim_fgets().
*/
#ifndef USE_CR
# define tag_fgets vim_fgets
#endif
#ifdef FEAT_TAG_BINS
static int tag_strnicmp __ARGS((char_u *s1, char_u *s2, size_t len));
/*
* Compare two strings, for length "len", ignoring case the ASCII way.
* return 0 for match, < 0 for smaller, > 0 for bigger
* Make sure case is folded to uppercase in comparison (like for 'sort -f')
*/
static int
tag_strnicmp(s1, s2, len)
char_u *s1;
char_u *s2;
size_t len;
{
int i;
while (len > 0)
{
i = (int)TOUPPER_ASC(*s1) - (int)TOUPPER_ASC(*s2);
if (i != 0)
return i; /* this character different */
if (*s1 == NUL)
break; /* strings match until NUL */
++s1;
++s2;
--len;
}
return 0; /* strings match */
}
#endif
/*
* Structure to hold info about the tag pattern being used.
*/
typedef struct
{
char_u *pat; /* the pattern */
int len; /* length of pat[] */
char_u *head; /* start of pattern head */
int headlen; /* length of head[] */
regmatch_T regmatch; /* regexp program, may be NULL */
} pat_T;
static void prepare_pats __ARGS((pat_T *pats, int has_re));
/*
* Extract info from the tag search pattern "pats->pat".
*/
static void
prepare_pats(pats, has_re)
pat_T *pats;
int has_re;
{
pats->head = pats->pat;
pats->headlen = pats->len;
if (has_re)
{
/* When the pattern starts with '^' or "\\<", binary searching can be
* used (much faster). */
if (pats->pat[0] == '^')
pats->head = pats->pat + 1;
else if (pats->pat[0] == '\\' && pats->pat[1] == '<')
pats->head = pats->pat + 2;
if (pats->head == pats->pat)
pats->headlen = 0;
else
for (pats->headlen = 0; pats->head[pats->headlen] != NUL;
++pats->headlen)
if (vim_strchr((char_u *)(p_magic ? ".[~*\\$" : "\\$"),
pats->head[pats->headlen]) != NULL)
break;
if (p_tl != 0 && pats->headlen > p_tl) /* adjust for 'taglength' */
pats->headlen = p_tl;
}
if (has_re)
pats->regmatch.regprog = vim_regcomp(pats->pat, p_magic ? RE_MAGIC : 0);
else
pats->regmatch.regprog = NULL;
}
/*
* find_tags() - search for tags in tags files
*
* Return FAIL if search completely failed (*num_matches will be 0, *matchesp
* will be NULL), OK otherwise.
*
* There is a priority in which type of tag is recognized.
*
* 6. A static or global tag with a full matching tag for the current file.
* 5. A global tag with a full matching tag for another file.
* 4. A static tag with a full matching tag for another file.
* 3. A static or global tag with an ignore-case matching tag for the
* current file.
* 2. A global tag with an ignore-case matching tag for another file.
* 1. A static tag with an ignore-case matching tag for another file.
*
* Tags in an emacs-style tags file are always global.
*
* flags:
* TAG_HELP only search for help tags
* TAG_NAMES only return name of tag
* TAG_REGEXP use "pat" as a regexp
* TAG_NOIC don't always ignore case
* TAG_KEEP_LANG keep language
*/
int
find_tags(pat, num_matches, matchesp, flags, mincount, buf_ffname)
char_u *pat; /* pattern to search for */
int *num_matches; /* return: number of matches found */
char_u ***matchesp; /* return: array of matches found */
int flags;
int mincount; /* MAXCOL: find all matches
other: minimal number of matches */
char_u *buf_ffname; /* name of buffer for priority */
{
FILE *fp;
char_u *lbuf; /* line buffer */
int lbuf_size = LSIZE; /* length of lbuf */
char_u *tag_fname; /* name of tag file */
tagname_T tn; /* info for get_tagfname() */
int first_file; /* trying first tag file */
tagptrs_T tagp;
int did_open = FALSE; /* did open a tag file */
int stop_searching = FALSE; /* stop when match found or error */
int retval = FAIL; /* return value */
int is_static; /* current tag line is static */
int is_current; /* file name matches */
int eof = FALSE; /* found end-of-file */
char_u *p;
char_u *s;
int i;
#ifdef FEAT_TAG_BINS
int tag_file_sorted = NUL; /* !_TAG_FILE_SORTED value */
struct tag_search_info /* Binary search file offsets */
{
off_t low_offset; /* offset for first char of first line that
could match */
off_t high_offset; /* offset of char after last line that could
match */
off_t curr_offset; /* Current file offset in search range */
off_t curr_offset_used; /* curr_offset used when skipping back */
off_t match_offset; /* Where the binary search found a tag */
int low_char; /* first char at low_offset */
int high_char; /* first char at high_offset */
} search_info;
off_t filesize;
int tagcmp;
off_t offset;
int round;
#endif
enum
{
TS_START, /* at start of file */
TS_LINEAR /* linear searching forward, till EOF */
#ifdef FEAT_TAG_BINS
, TS_BINARY, /* binary searching */
TS_SKIP_BACK, /* skipping backwards */
TS_STEP_FORWARD /* stepping forwards */
#endif
} state; /* Current search state */
int cmplen;
int match; /* matches */
int match_no_ic = 0;/* matches with rm_ic == FALSE */
int match_re; /* match with regexp */
int matchoff = 0;
#ifdef FEAT_EMACS_TAGS
/*
* Stack for included emacs-tags file.
* It has a fixed size, to truncate cyclic includes. jw
*/
# define INCSTACK_SIZE 42
struct
{
FILE *fp;
char_u *etag_fname;
} incstack[INCSTACK_SIZE];
int incstack_idx = 0; /* index in incstack */
char_u *ebuf; /* additional buffer for etag fname */
int is_etag; /* current file is emaces style */
#endif
struct match_found
{
int len; /* nr of chars of match[] to be compared */
char_u match[1]; /* actually longer */
} *mfp, *mfp2;
garray_T ga_match[MT_COUNT];
int match_count = 0; /* number of matches found */
char_u **matches;
int mtt;
int help_save;
#ifdef FEAT_MULTI_LANG
int help_pri = 0;
char_u *help_lang_find = NULL; /* lang to be found */
char_u help_lang[3]; /* lang of current tags file */
char_u *saved_pat = NULL; /* copy of pat[] */
#endif
pat_T orgpat; /* holds unconverted pattern info */
#ifdef FEAT_MBYTE
vimconv_T vimconv;
#endif
#ifdef FEAT_TAG_BINS
int findall = (mincount == MAXCOL || mincount == TAG_MANY);
/* find all matching tags */
int sort_error = FALSE; /* tags file not sorted */
int linear; /* do a linear search */
int sortic = FALSE; /* tag file sorted in nocase */
#endif
int line_error = FALSE; /* syntax error */
int has_re = (flags & TAG_REGEXP); /* regexp used */
int help_only = (flags & TAG_HELP);
int name_only = (flags & TAG_NAMES);
int noic = (flags & TAG_NOIC);
int get_it_again = FALSE;
#ifdef FEAT_CSCOPE
int use_cscope = (flags & TAG_CSCOPE);
#endif
int verbose = (flags & TAG_VERBOSE);
help_save = curbuf->b_help;
orgpat.pat = pat;
#ifdef FEAT_MBYTE
vimconv.vc_type = CONV_NONE;
#endif
/*
* Allocate memory for the buffers that are used
*/
lbuf = alloc(lbuf_size);
tag_fname = alloc(MAXPATHL + 1);
#ifdef FEAT_EMACS_TAGS
ebuf = alloc(LSIZE);
#endif
for (mtt = 0; mtt < MT_COUNT; ++mtt)
ga_init2(&ga_match[mtt], (int)sizeof(struct match_found *), 100);
/* check for out of memory situation */
if (lbuf == NULL || tag_fname == NULL
#ifdef FEAT_EMACS_TAGS
|| ebuf == NULL
#endif
)
goto findtag_end;
#ifdef FEAT_CSCOPE
STRCPY(tag_fname, "from cscope"); /* for error messages */
#endif
/*
* Initialize a few variables
*/
if (help_only) /* want tags from help file */
curbuf->b_help = TRUE; /* will be restored later */
orgpat.len = (int)STRLEN(pat);
#ifdef FEAT_MULTI_LANG
if (curbuf->b_help)
{
/* When "@ab" is specified use only the "ab" language, otherwise
* search all languages. */
if (orgpat.len > 3 && pat[orgpat.len - 3] == '@'
&& ASCII_ISALPHA(pat[orgpat.len - 2])
&& ASCII_ISALPHA(pat[orgpat.len - 1]))
{
saved_pat = vim_strnsave(pat, orgpat.len - 3);
if (saved_pat != NULL)
{
help_lang_find = &pat[orgpat.len - 2];
orgpat.pat = saved_pat;
orgpat.len -= 3;
}
}
}
#endif
if (p_tl != 0 && orgpat.len > p_tl) /* adjust for 'taglength' */
orgpat.len = p_tl;
prepare_pats(&orgpat, has_re);
#ifdef FEAT_TAG_BINS
/* This is only to avoid a compiler warning for using search_info
* uninitialised. */
vim_memset(&search_info, 0, (size_t)1);
#endif
/*
* When finding a specified number of matches, first try with matching
* case, so binary search can be used, and try ignore-case matches in a
* second loop.
* When finding all matches, 'tagbsearch' is off, or there is no fixed
* string to look for, ignore case right away to avoid going though the
* tags files twice.
* When the tag file is case-fold sorted, it is either one or the other.
* Only ignore case when TAG_NOIC not used or 'ignorecase' set.
*/
#ifdef FEAT_TAG_BINS
orgpat.regmatch.rm_ic = ((p_ic || !noic)
&& (findall || orgpat.headlen == 0 || !p_tbs));
for (round = 1; round <= 2; ++round)
{
linear = (orgpat.headlen == 0 || !p_tbs || round == 2);
#else
orgpat.regmatch.rm_ic = (p_ic || !noic);
#endif
/*
* Try tag file names from tags option one by one.
*/
for (first_file = TRUE;
#ifdef FEAT_CSCOPE
use_cscope ||
#endif
get_tagfname(&tn, first_file, tag_fname) == OK;
first_file = FALSE)
{
/*
* A file that doesn't exist is silently ignored. Only when not a
* single file is found, an error message is given (further on).
*/
#ifdef FEAT_CSCOPE
if (use_cscope)
fp = NULL; /* avoid GCC warning */
else
#endif
{
#ifdef FEAT_MULTI_LANG
if (curbuf->b_help)
{
/* Prefer help tags according to 'helplang'. Put the
* two-letter language name in help_lang[]. */
i = (int)STRLEN(tag_fname);
if (i > 3 && tag_fname[i - 3] == '-')
STRCPY(help_lang, tag_fname + i - 2);
else
STRCPY(help_lang, "en");
/* When searching for a specific language skip tags files
* for other languages. */
if (help_lang_find != NULL
&& STRICMP(help_lang, help_lang_find) != 0)
continue;
/* For CTRL-] in a help file prefer a match with the same
* language. */
if ((flags & TAG_KEEP_LANG)
&& help_lang_find == NULL
&& curbuf->b_fname != NULL
&& (i = (int)STRLEN(curbuf->b_fname)) > 4
&& curbuf->b_fname[i - 1] == 'x'
&& curbuf->b_fname[i - 4] == '.'
&& STRNICMP(curbuf->b_fname + i - 3, help_lang, 2) == 0)
help_pri = 0;
else
{
help_pri = 1;
for (s = p_hlg; *s != NUL; ++s)
{
if (STRNICMP(s, help_lang, 2) == 0)
break;
++help_pri;
if ((s = vim_strchr(s, ',')) == NULL)
break;
}
if (s == NULL || *s == NUL)
{
/* Language not in 'helplang': use last, prefer English,
* unless found already. */
++help_pri;
if (STRICMP(help_lang, "en") != 0)
++help_pri;
}
}
}
#endif
if ((fp = mch_fopen((char *)tag_fname, "r")) == NULL)
continue;
if (p_verbose >= 5)
{
verbose_enter();
smsg((char_u *)_("Searching tags file %s"), tag_fname);
verbose_leave();
}
}
did_open = TRUE; /* remember that we found at least one file */
state = TS_START; /* we're at the start of the file */
#ifdef FEAT_EMACS_TAGS
is_etag = 0; /* default is: not emacs style */
#endif
/*
* Read and parse the lines in the file one by one
*/
for (;;)
{
line_breakcheck(); /* check for CTRL-C typed */
#ifdef FEAT_INS_EXPAND
if ((flags & TAG_INS_COMP)) /* Double brackets for gcc */
ins_compl_check_keys(30);
if (got_int || compl_interrupted)
#else
if (got_int)
#endif
{
stop_searching = TRUE;
break;
}
/* When mincount is TAG_MANY, stop when enough matches have been
* found (for completion). */
if (mincount == TAG_MANY && match_count >= TAG_MANY)
{
stop_searching = TRUE;
retval = OK;
break;
}
if (get_it_again)
goto line_read_in;
#ifdef FEAT_TAG_BINS
/*
* For binary search: compute the next offset to use.
*/
if (state == TS_BINARY)
{
offset = search_info.low_offset + ((search_info.high_offset
- search_info.low_offset) / 2);
if (offset == search_info.curr_offset)
break; /* End the binary search without a match. */
else
search_info.curr_offset = offset;
}
/*
* Skipping back (after a match during binary search).
*/
else if (state == TS_SKIP_BACK)
{
search_info.curr_offset -= LSIZE * 2;
if (search_info.curr_offset < 0)
{
search_info.curr_offset = 0;
rewind(fp);
state = TS_STEP_FORWARD;
}
}
/*
* When jumping around in the file, first read a line to find the
* start of the next line.
*/
if (state == TS_BINARY || state == TS_SKIP_BACK)
{
/* Adjust the search file offset to the correct position */
search_info.curr_offset_used = search_info.curr_offset;
#ifdef HAVE_FSEEKO
fseeko(fp, search_info.curr_offset, SEEK_SET);
#else
fseek(fp, (long)search_info.curr_offset, SEEK_SET);
#endif
eof = tag_fgets(lbuf, LSIZE, fp);
if (!eof && search_info.curr_offset != 0)
{
/* The explicit cast is to work around a bug in gcc 3.4.2
* (repeated below). */
search_info.curr_offset = ftell(fp);
if (search_info.curr_offset == search_info.high_offset)
{
/* oops, gone a bit too far; try from low offset */
#ifdef HAVE_FSEEKO
fseeko(fp, search_info.low_offset, SEEK_SET);
#else
fseek(fp, (long)search_info.low_offset, SEEK_SET);
#endif
search_info.curr_offset = search_info.low_offset;
}
eof = tag_fgets(lbuf, LSIZE, fp);
}
/* skip empty and blank lines */
while (!eof && vim_isblankline(lbuf))
{
search_info.curr_offset = ftell(fp);
eof = tag_fgets(lbuf, LSIZE, fp);
}
if (eof)
{
/* Hit end of file. Skip backwards. */
state = TS_SKIP_BACK;
search_info.match_offset = ftell(fp);
search_info.curr_offset = search_info.curr_offset_used;
continue;
}
}
/*
* Not jumping around in the file: Read the next line.
*/
else
#endif
{
/* skip empty and blank lines */
do
{
#ifdef FEAT_CSCOPE
if (use_cscope)
eof = cs_fgets(lbuf, LSIZE);
else
#endif
eof = tag_fgets(lbuf, LSIZE, fp);
} while (!eof && vim_isblankline(lbuf));
if (eof)
{
#ifdef FEAT_EMACS_TAGS
if (incstack_idx) /* this was an included file */
{
--incstack_idx;
fclose(fp); /* end of this file ... */
fp = incstack[incstack_idx].fp;
STRCPY(tag_fname, incstack[incstack_idx].etag_fname);
vim_free(incstack[incstack_idx].etag_fname);
is_etag = 1; /* (only etags can include) */
continue; /* ... continue with parent file */
}
else
#endif
break; /* end of file */
}
}
line_read_in:
#ifdef FEAT_MBYTE
if (vimconv.vc_type != CONV_NONE)
{
char_u *conv_line;
int len;
/* Convert every line. Converting the pattern from 'enc' to
* the tags file encoding doesn't work, because characters are
* not recognized. */
conv_line = string_convert(&vimconv, lbuf, NULL);
if (conv_line != NULL)
{
/* Copy or swap lbuf and conv_line. */
len = (int)STRLEN(conv_line) + 1;
if (len > lbuf_size)
{
vim_free(lbuf);
lbuf = conv_line;
lbuf_size = len;
}
else
{
STRCPY(lbuf, conv_line);
vim_free(conv_line);
}
}
}
#endif
#ifdef FEAT_EMACS_TAGS
/*
* Emacs tags line with CTRL-L: New file name on next line.
* The file name is followed by a ','.
*/
if (*lbuf == Ctrl_L) /* remember etag file name in ebuf */
{
is_etag = 1; /* in case at the start */
state = TS_LINEAR;
if (!tag_fgets(ebuf, LSIZE, fp))
{
for (p = ebuf; *p && *p != ','; p++)
;
*p = NUL;
/*
* atoi(p+1) is the number of bytes before the next ^L
* unless it is an include statement.
*/
if (STRNCMP(p + 1, "include", 7) == 0
&& incstack_idx < INCSTACK_SIZE)
{
/* Save current "fp" and "tag_fname" in the stack. */
if ((incstack[incstack_idx].etag_fname =
vim_strsave(tag_fname)) != NULL)
{
char_u *fullpath_ebuf;
incstack[incstack_idx].fp = fp;
fp = NULL;
/* Figure out "tag_fname" and "fp" to use for
* included file. */
fullpath_ebuf = expand_tag_fname(ebuf,
tag_fname, FALSE);
if (fullpath_ebuf != NULL)
{
fp = mch_fopen((char *)fullpath_ebuf, "r");
if (fp != NULL)
{
if (STRLEN(fullpath_ebuf) > LSIZE)
EMSG2(_("E430: Tag file path truncated for %s\n"), ebuf);
vim_strncpy(tag_fname, fullpath_ebuf,
MAXPATHL);
++incstack_idx;
is_etag = 0; /* we can include anything */
}
vim_free(fullpath_ebuf);
}
if (fp == NULL)
{
/* Can't open the included file, skip it and
* restore old value of "fp". */
fp = incstack[incstack_idx].fp;
vim_free(incstack[incstack_idx].etag_fname);
}
}
}
}
continue;
}
#endif
/*
* When still at the start of the file, check for Emacs tags file
* format, and for "not sorted" flag.
*/
if (state == TS_START)
{
if (STRNCMP(lbuf, "!_TAG_", 6) <= 0)
{
/*
* Read header line.
*/
#ifdef FEAT_TAG_BINS
if (STRNCMP(lbuf, "!_TAG_FILE_SORTED\t", 18) == 0)
tag_file_sorted = lbuf[18];
#endif
#ifdef FEAT_MBYTE
if (STRNCMP(lbuf, "!_TAG_FILE_ENCODING\t", 20) == 0)
{
/* Prepare to convert every line from the specified
* encoding to 'encoding'. */
for (p = lbuf + 20; *p > ' ' && *p < 127; ++p)
;
*p = NUL;
convert_setup(&vimconv, lbuf + 20, p_enc);
}
#endif
/* Read the next line. Unrecognized flags are ignored. */
continue;
}
/* Headers ends. */
#ifdef FEAT_TAG_BINS
/*
* When there is no tag head, or ignoring case, need to do a
* linear search.
* When no "!_TAG_" is found, default to binary search. If
* the tag file isn't sorted, the second loop will find it.
* When "!_TAG_FILE_SORTED" found: start binary search if
* flag set.
* For cscope, it's always linear.
*/
# ifdef FEAT_CSCOPE
if (linear || use_cscope)
# else
if (linear)
# endif
state = TS_LINEAR;
else if (tag_file_sorted == NUL)
state = TS_BINARY;
else if (tag_file_sorted == '1')
state = TS_BINARY;
else if (tag_file_sorted == '2')
{
state = TS_BINARY;
sortic = TRUE;
orgpat.regmatch.rm_ic = (p_ic || !noic);
}
else
state = TS_LINEAR;
if (state == TS_BINARY && orgpat.regmatch.rm_ic && !sortic)
{
/* Binary search won't work for ignoring case, use linear
* search. */
linear = TRUE;
state = TS_LINEAR;
}
#else
state = TS_LINEAR;
#endif
#ifdef FEAT_TAG_BINS
/*
* When starting a binary search, get the size of the file and
* compute the first offset.
*/
if (state == TS_BINARY)
{
/* Get the tag file size (don't use mch_fstat(), it's not
* portable). */
if ((filesize = lseek(fileno(fp),
(off_t)0L, SEEK_END)) <= 0)
state = TS_LINEAR;
else
{
lseek(fileno(fp), (off_t)0L, SEEK_SET);
/* Calculate the first read offset in the file. Start
* the search in the middle of the file. */
search_info.low_offset = 0;
search_info.low_char = 0;
search_info.high_offset = filesize;
search_info.curr_offset = 0;
search_info.high_char = 0xff;
}
continue;
}
#endif
}
/*
* Figure out where the different strings are in this line.
* For "normal" tags: Do a quick check if the tag matches.
* This speeds up tag searching a lot!
*/
if (orgpat.headlen
#ifdef FEAT_EMACS_TAGS
&& !is_etag
#endif
)
{
tagp.tagname = lbuf;
#ifdef FEAT_TAG_ANYWHITE
tagp.tagname_end = skiptowhite(lbuf);
if (*tagp.tagname_end == NUL)
#else
tagp.tagname_end = vim_strchr(lbuf, TAB);
if (tagp.tagname_end == NULL)
#endif
{
if (vim_strchr(lbuf, NL) == NULL)
{
/* Truncated line, ignore it. Has been reported for
* Mozilla JS with extremely long names. */
if (p_verbose >= 5)
{
verbose_enter();
MSG(_("Ignoring long line in tags file"));
verbose_leave();
}
#ifdef FEAT_TAG_BINS
if (state != TS_LINEAR)
{
/* Avoid getting stuck. */
linear = TRUE;
state = TS_LINEAR;
# ifdef HAVE_FSEEKO
fseeko(fp, search_info.low_offset, SEEK_SET);
# else
fseek(fp, (long)search_info.low_offset, SEEK_SET);
# endif
}
#endif
continue;
}
/* Corrupted tag line. */
line_error = TRUE;
break;
}
#ifdef FEAT_TAG_OLDSTATIC
/*
* Check for old style static tag: "file:tag file .."
*/
tagp.fname = NULL;
for (p = lbuf; p < tagp.tagname_end; ++p)
{
if (*p == ':')
{
if (tagp.fname == NULL)
#ifdef FEAT_TAG_ANYWHITE
tagp.fname = skipwhite(tagp.tagname_end);
#else
tagp.fname = tagp.tagname_end + 1;
#endif
if ( fnamencmp(lbuf, tagp.fname, p - lbuf) == 0
#ifdef FEAT_TAG_ANYWHITE
&& vim_iswhite(tagp.fname[p - lbuf])
#else
&& tagp.fname[p - lbuf] == TAB
#endif
)
{
/* found one */
tagp.tagname = p + 1;
break;
}
}
}
#endif
/*
* Skip this line if the length of the tag is different and
* there is no regexp, or the tag is too short.
*/
cmplen = (int)(tagp.tagname_end - tagp.tagname);
if (p_tl != 0 && cmplen > p_tl) /* adjust for 'taglength' */
cmplen = p_tl;
if (has_re && orgpat.headlen < cmplen)
cmplen = orgpat.headlen;
else if (state == TS_LINEAR && orgpat.headlen != cmplen)
continue;
#ifdef FEAT_TAG_BINS
if (state == TS_BINARY)
{
/*
* Simplistic check for unsorted tags file.
*/
i = (int)tagp.tagname[0];
if (sortic)
i = (int)TOUPPER_ASC(tagp.tagname[0]);
if (i < search_info.low_char || i > search_info.high_char)
sort_error = TRUE;
/*
* Compare the current tag with the searched tag.
*/
if (sortic)
tagcmp = tag_strnicmp(tagp.tagname, orgpat.head,
(size_t)cmplen);
else
tagcmp = STRNCMP(tagp.tagname, orgpat.head, cmplen);
/*
* A match with a shorter tag means to search forward.
* A match with a longer tag means to search backward.
*/
if (tagcmp == 0)
{
if (cmplen < orgpat.headlen)
tagcmp = -1;
else if (cmplen > orgpat.headlen)
tagcmp = 1;
}
if (tagcmp == 0)
{
/* We've located the tag, now skip back and search
* forward until the first matching tag is found.
*/
state = TS_SKIP_BACK;
search_info.match_offset = search_info.curr_offset;
continue;
}
if (tagcmp < 0)
{
search_info.curr_offset = ftell(fp);
if (search_info.curr_offset < search_info.high_offset)
{
search_info.low_offset = search_info.curr_offset;
if (sortic)
search_info.low_char =
TOUPPER_ASC(tagp.tagname[0]);
else
search_info.low_char = tagp.tagname[0];
continue;
}
}
if (tagcmp > 0
&& search_info.curr_offset != search_info.high_offset)
{
search_info.high_offset = search_info.curr_offset;
if (sortic)
search_info.high_char =
TOUPPER_ASC(tagp.tagname[0]);
else
search_info.high_char = tagp.tagname[0];
continue;
}
/* No match yet and are at the end of the binary search. */
break;
}
else if (state == TS_SKIP_BACK)
{
if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0)
state = TS_STEP_FORWARD;
else
/* Have to skip back more. Restore the curr_offset
* used, otherwise we get stuck at a long line. */
search_info.curr_offset = search_info.curr_offset_used;
continue;
}
else if (state == TS_STEP_FORWARD)
{
if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0)
{
if ((off_t)ftell(fp) > search_info.match_offset)
break; /* past last match */
else
continue; /* before first match */
}
}
else
#endif
/* skip this match if it can't match */
if (MB_STRNICMP(tagp.tagname, orgpat.head, cmplen) != 0)
continue;
/*
* Can be a matching tag, isolate the file name and command.
*/
#ifdef FEAT_TAG_OLDSTATIC
if (tagp.fname == NULL)
#endif
#ifdef FEAT_TAG_ANYWHITE
tagp.fname = skipwhite(tagp.tagname_end);
#else
tagp.fname = tagp.tagname_end + 1;
#endif
#ifdef FEAT_TAG_ANYWHITE
tagp.fname_end = skiptowhite(tagp.fname);
tagp.command = skipwhite(tagp.fname_end);
if (*tagp.command == NUL)
#else
tagp.fname_end = vim_strchr(tagp.fname, TAB);
tagp.command = tagp.fname_end + 1;
if (tagp.fname_end == NULL)
#endif
i = FAIL;
else
i = OK;
}
else
i = parse_tag_line(lbuf,
#ifdef FEAT_EMACS_TAGS
is_etag,
#endif
&tagp);
if (i == FAIL)
{
line_error = TRUE;
break;
}
#ifdef FEAT_EMACS_TAGS
if (is_etag)
tagp.fname = ebuf;
#endif
/*
* First try matching with the pattern literally (also when it is
* a regexp).
*/
cmplen = (int)(tagp.tagname_end - tagp.tagname);
if (p_tl != 0 && cmplen > p_tl) /* adjust for 'taglength' */
cmplen = p_tl;
/* if tag length does not match, don't try comparing */
if (orgpat.len != cmplen)
match = FALSE;
else
{
if (orgpat.regmatch.rm_ic)
{
match = (MB_STRNICMP(tagp.tagname, orgpat.pat, cmplen) == 0);
if (match)
match_no_ic = (STRNCMP(tagp.tagname, orgpat.pat,
cmplen) == 0);
}
else
match = (STRNCMP(tagp.tagname, orgpat.pat, cmplen) == 0);
}
/*
* Has a regexp: Also find tags matching regexp.
*/
match_re = FALSE;
if (!match && orgpat.regmatch.regprog != NULL)
{
int cc;
cc = *tagp.tagname_end;
*tagp.tagname_end = NUL;
match = vim_regexec(&orgpat.regmatch, tagp.tagname, (colnr_T)0);
if (match)
{
matchoff = (int)(orgpat.regmatch.startp[0] - tagp.tagname);
if (orgpat.regmatch.rm_ic)
{
orgpat.regmatch.rm_ic = FALSE;
match_no_ic = vim_regexec(&orgpat.regmatch, tagp.tagname,
(colnr_T)0);
orgpat.regmatch.rm_ic = TRUE;
}
}
*tagp.tagname_end = cc;
match_re = TRUE;
}
/*
* If a match is found, add it to ga_match[].
*/
if (match)
{
#ifdef FEAT_CSCOPE
if (use_cscope)
{
/* Don't change the ordering, always use the same table. */
mtt = MT_GL_OTH;
}
else
#endif
{
/* Decide in which array to store this match. */
is_current = test_for_current(
#ifdef FEAT_EMACS_TAGS
is_etag,
#endif
tagp.fname, tagp.fname_end, tag_fname,
buf_ffname);
#ifdef FEAT_EMACS_TAGS
is_static = FALSE;
if (!is_etag) /* emacs tags are never static */
#endif
{
#ifdef FEAT_TAG_OLDSTATIC
if (tagp.tagname != lbuf)
is_static = TRUE; /* detected static tag before */
else
#endif
is_static = test_for_static(&tagp);
}
/* decide in which of the sixteen tables to store this
* match */
if (is_static)
{
if (is_current)
mtt = MT_ST_CUR;
else
mtt = MT_ST_OTH;
}
else
{
if (is_current)
mtt = MT_GL_CUR;
else
mtt = MT_GL_OTH;
}
if (orgpat.regmatch.rm_ic && !match_no_ic)
mtt += MT_IC_OFF;
if (match_re)
mtt += MT_RE_OFF;
}
/*
* Add the found match in ga_match[mtt], avoiding duplicates.
* Store the info we need later, which depends on the kind of
* tags we are dealing with.
*/
if (ga_grow(&ga_match[mtt], 1) == OK)
{
int len;
if (help_only)
{
#ifdef FEAT_MULTI_LANG
# define ML_EXTRA 3
#else
# define ML_EXTRA 0
#endif
/*
* Append the help-heuristic number after the
* tagname, for sorting it later.
*/
*tagp.tagname_end = NUL;
len = (int)(tagp.tagname_end - tagp.tagname);
mfp = (struct match_found *)
alloc((int)sizeof(struct match_found) + len
+ 10 + ML_EXTRA);
if (mfp != NULL)
{
/* "len" includes the language and the NUL, but
* not the priority. */
mfp->len = len + ML_EXTRA + 1;
#define ML_HELP_LEN 6
p = mfp->match;
STRCPY(p, tagp.tagname);
#ifdef FEAT_MULTI_LANG
p[len] = '@';
STRCPY(p + len + 1, help_lang);
#endif
sprintf((char *)p + len + 1 + ML_EXTRA, "%06d",
help_heuristic(tagp.tagname,
match_re ? matchoff : 0, !match_no_ic)
#ifdef FEAT_MULTI_LANG
+ help_pri
#endif
);
}
*tagp.tagname_end = TAB;
}
else if (name_only)
{
if (get_it_again)
{
char_u *temp_end = tagp.command;
if (*temp_end == '/')
while (*temp_end && *temp_end != '\r'
&& *temp_end != '\n'
&& *temp_end != '$')
temp_end++;
if (tagp.command + 2 < temp_end)
{
len = (int)(temp_end - tagp.command - 2);
mfp = (struct match_found *)alloc(
(int)sizeof(struct match_found) + len);
if (mfp != NULL)
{
mfp->len = len + 1; /* include the NUL */
p = mfp->match;
vim_strncpy(p, tagp.command + 2, len);
}
}
else
mfp = NULL;
get_it_again = FALSE;
}
else
{
len = (int)(tagp.tagname_end - tagp.tagname);
mfp = (struct match_found *)alloc(
(int)sizeof(struct match_found) + len);
if (mfp != NULL)
{
mfp->len = len + 1; /* include the NUL */
p = mfp->match;
vim_strncpy(p, tagp.tagname, len);
}
/* if wanted, re-read line to get long form too */
if (State & INSERT)
get_it_again = p_sft;
}
}
else
{
/* Save the tag in a buffer.
* Emacs tag: <mtt><tag_fname><NUL><ebuf><NUL><lbuf>
* other tag: <mtt><tag_fname><NUL><NUL><lbuf>
* without Emacs tags: <mtt><tag_fname><NUL><lbuf>
*/
len = (int)STRLEN(tag_fname)
+ (int)STRLEN(lbuf) + 3;
#ifdef FEAT_EMACS_TAGS
if (is_etag)
len += (int)STRLEN(ebuf) + 1;
else
++len;
#endif
mfp = (struct match_found *)alloc(
(int)sizeof(struct match_found) + len);
if (mfp != NULL)
{
mfp->len = len;
p = mfp->match;
p[0] = mtt;
STRCPY(p + 1, tag_fname);
#ifdef BACKSLASH_IN_FILENAME
/* Ignore differences in slashes, avoid adding
* both path/file and path\file. */
slash_adjust(p + 1);
#endif
s = p + 1 + STRLEN(tag_fname) + 1;
#ifdef FEAT_EMACS_TAGS
if (is_etag)
{
STRCPY(s, ebuf);
s += STRLEN(ebuf) + 1;
}
else
*s++ = NUL;
#endif
STRCPY(s, lbuf);
}
}
if (mfp != NULL)
{
/*
* Don't add identical matches.
* This can take a lot of time when finding many
* matches, check for CTRL-C now and then.
* Add all cscope tags, because they are all listed.
*/
#ifdef FEAT_CSCOPE
if (use_cscope)
i = -1;
else
#endif
for (i = ga_match[mtt].ga_len; --i >= 0 && !got_int; )
{
mfp2 = ((struct match_found **)
(ga_match[mtt].ga_data))[i];
if (mfp2->len == mfp->len
&& vim_memcmp(mfp2->match, mfp->match,
(size_t)mfp->len) == 0)
break;
line_breakcheck();
}
if (i < 0)
{
((struct match_found **)(ga_match[mtt].ga_data))
[ga_match[mtt].ga_len++] = mfp;
++match_count;
}
else
vim_free(mfp);
}
}
else /* Out of memory! Just forget about the rest. */
{
retval = OK;
stop_searching = TRUE;
break;
}
}
#ifdef FEAT_CSCOPE
if (use_cscope && eof)
break;
#endif
} /* forever */
if (line_error)
{
EMSG2(_("E431: Format error in tags file \"%s\""), tag_fname);
#ifdef FEAT_CSCOPE
if (!use_cscope)
#endif
EMSGN(_("Before byte %ld"), (long)ftell(fp));
stop_searching = TRUE;
line_error = FALSE;
}
#ifdef FEAT_CSCOPE
if (!use_cscope)
#endif
fclose(fp);
#ifdef FEAT_EMACS_TAGS
while (incstack_idx)
{
--incstack_idx;
fclose(incstack[incstack_idx].fp);
vim_free(incstack[incstack_idx].etag_fname);
}
#endif
#ifdef FEAT_MBYTE
if (vimconv.vc_type != CONV_NONE)
convert_setup(&vimconv, NULL, NULL);
#endif
#ifdef FEAT_TAG_BINS
tag_file_sorted = NUL;
if (sort_error)
{
EMSG2(_("E432: Tags file not sorted: %s"), tag_fname);
sort_error = FALSE;
}
#endif
/*
* Stop searching if sufficient tags have been found.
*/
if (match_count >= mincount)
{
retval = OK;
stop_searching = TRUE;
}
#ifdef FEAT_CSCOPE
if (stop_searching || use_cscope)
#else
if (stop_searching)
#endif
break;
} /* end of for-each-file loop */
#ifdef FEAT_CSCOPE
if (!use_cscope)
#endif
tagname_free(&tn);
#ifdef FEAT_TAG_BINS
/* stop searching when already did a linear search, or when TAG_NOIC
* used, and 'ignorecase' not set or already did case-ignore search */
if (stop_searching || linear || (!p_ic && noic) || orgpat.regmatch.rm_ic)
break;
# ifdef FEAT_CSCOPE
if (use_cscope)
break;
# endif
orgpat.regmatch.rm_ic = TRUE; /* try another time while ignoring case */
}
#endif
if (!stop_searching)
{
if (!did_open && verbose) /* never opened any tags file */
EMSG(_("E433: No tags file"));
retval = OK; /* It's OK even when no tag found */
}
findtag_end:
vim_free(lbuf);
vim_free(orgpat.regmatch.regprog);
vim_free(tag_fname);
#ifdef FEAT_EMACS_TAGS
vim_free(ebuf);
#endif
/*
* Move the matches from the ga_match[] arrays into one list of
* matches. When retval == FAIL, free the matches.
*/
if (retval == FAIL)
match_count = 0;
if (match_count > 0)
matches = (char_u **)lalloc((long_u)(match_count * sizeof(char_u *)),
TRUE);
else
matches = NULL;
match_count = 0;
for (mtt = 0; mtt < MT_COUNT; ++mtt)
{
for (i = 0; i < ga_match[mtt].ga_len; ++i)
{
mfp = ((struct match_found **)(ga_match[mtt].ga_data))[i];
if (matches == NULL)
vim_free(mfp);
else
{
/* To avoid allocating memory again we turn the struct
* match_found into a string. For help the priority was not
* included in the length. */
mch_memmove(mfp, mfp->match,
(size_t)(mfp->len + (help_only ? ML_HELP_LEN : 0)));
matches[match_count++] = (char_u *)mfp;
}
}
ga_clear(&ga_match[mtt]);
}
*matchesp = matches;
*num_matches = match_count;
curbuf->b_help = help_save;
#ifdef FEAT_MULTI_LANG
vim_free(saved_pat);
#endif
return retval;
}
static garray_T tag_fnames = GA_EMPTY;
static void found_tagfile_cb __ARGS((char_u *fname, void *cookie));
/*
* Callback function for finding all "tags" and "tags-??" files in
* 'runtimepath' doc directories.
*/
static void
found_tagfile_cb(fname, cookie)
char_u *fname;
void *cookie UNUSED;
{
if (ga_grow(&tag_fnames, 1) == OK)
((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] =
vim_strsave(fname);
}
#if defined(EXITFREE) || defined(PROTO)
void
free_tag_stuff()
{
ga_clear_strings(&tag_fnames);
do_tag(NULL, DT_FREE, 0, 0, 0);
tag_freematch();
# if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
if (ptag_entry.tagname)
{
vim_free(ptag_entry.tagname);
ptag_entry.tagname = NULL;
}
# endif
}
#endif
/*
* Get the next name of a tag file from the tag file list.
* For help files, use "tags" file only.
*
* Return FAIL if no more tag file names, OK otherwise.
*/
int
get_tagfname(tnp, first, buf)
tagname_T *tnp; /* holds status info */
int first; /* TRUE when first file name is wanted */
char_u *buf; /* pointer to buffer of MAXPATHL chars */
{
char_u *fname = NULL;
char_u *r_ptr;
if (first)
vim_memset(tnp, 0, sizeof(tagname_T));
if (curbuf->b_help)
{
/*
* For help files it's done in a completely different way:
* Find "doc/tags" and "doc/tags-??" in all directories in
* 'runtimepath'.
*/
if (first)
{
ga_clear_strings(&tag_fnames);
ga_init2(&tag_fnames, (int)sizeof(char_u *), 10);
do_in_runtimepath((char_u *)
#ifdef FEAT_MULTI_LANG
# ifdef VMS
/* Functions decc$to_vms() and decc$translate_vms() crash
* on some VMS systems with wildcards "??". Seems ECO
* patches do fix the problem in C RTL, but we can't use
* an #ifdef for that. */
"doc/tags doc/tags-*"
# else
"doc/tags doc/tags-??"
# endif
#else
"doc/tags"
#endif
, TRUE, found_tagfile_cb, NULL);
}
if (tnp->tn_hf_idx >= tag_fnames.ga_len)
{
/* Not found in 'runtimepath', use 'helpfile', if it exists and
* wasn't used yet, replacing "help.txt" with "tags". */
if (tnp->tn_hf_idx > tag_fnames.ga_len || *p_hf == NUL)
return FAIL;
++tnp->tn_hf_idx;
STRCPY(buf, p_hf);
STRCPY(gettail(buf), "tags");
}
else
vim_strncpy(buf, ((char_u **)(tag_fnames.ga_data))[
tnp->tn_hf_idx++], MAXPATHL - 1);
return OK;
}
if (first)
{
/* Init. We make a copy of 'tags', because autocommands may change
* the value without notifying us. */
tnp->tn_tags = vim_strsave((*curbuf->b_p_tags != NUL)
? curbuf->b_p_tags : p_tags);
if (tnp->tn_tags == NULL)
return FAIL;
tnp->tn_np = tnp->tn_tags;
}
/*
* Loop until we have found a file name that can be used.
* There are two states:
* tnp->tn_did_filefind_init == FALSE: setup for next part in 'tags'.
* tnp->tn_did_filefind_init == TRUE: find next file in this part.
*/
for (;;)
{
if (tnp->tn_did_filefind_init)
{
fname = vim_findfile(tnp->tn_search_ctx);
if (fname != NULL)
break;
tnp->tn_did_filefind_init = FALSE;
}
else
{
char_u *filename = NULL;
/* Stop when used all parts of 'tags'. */
if (*tnp->tn_np == NUL)
{
vim_findfile_cleanup(tnp->tn_search_ctx);
tnp->tn_search_ctx = NULL;
return FAIL;
}
/*
* Copy next file name into buf.
*/
buf[0] = NUL;
(void)copy_option_part(&tnp->tn_np, buf, MAXPATHL - 1, " ,");
#ifdef FEAT_PATH_EXTRA
r_ptr = vim_findfile_stopdir(buf);
#else
r_ptr = NULL;
#endif
/* move the filename one char forward and truncate the
* filepath with a NUL */
filename = gettail(buf);
STRMOVE(filename + 1, filename);
*filename++ = NUL;
tnp->tn_search_ctx = vim_findfile_init(buf, filename,
r_ptr, 100,
FALSE, /* don't free visited list */
FINDFILE_FILE, /* we search for a file */
tnp->tn_search_ctx, TRUE, curbuf->b_ffname);
if (tnp->tn_search_ctx != NULL)
tnp->tn_did_filefind_init = TRUE;
}
}
STRCPY(buf, fname);
vim_free(fname);
return OK;
}
/*
* Free the contents of a tagname_T that was filled by get_tagfname().
*/
void
tagname_free(tnp)
tagname_T *tnp;
{
vim_free(tnp->tn_tags);
vim_findfile_cleanup(tnp->tn_search_ctx);
tnp->tn_search_ctx = NULL;
ga_clear_strings(&tag_fnames);
}
/*
* Parse one line from the tags file. Find start/end of tag name, start/end of
* file name and start of search pattern.
*
* If is_etag is TRUE, tagp->fname and tagp->fname_end are not set.
*
* Return FAIL if there is a format error in this line, OK otherwise.
*/
static int
parse_tag_line(lbuf,
#ifdef FEAT_EMACS_TAGS
is_etag,
#endif
tagp)
char_u *lbuf; /* line to be parsed */
#ifdef FEAT_EMACS_TAGS
int is_etag;
#endif
tagptrs_T *tagp;
{
char_u *p;
#ifdef FEAT_EMACS_TAGS
char_u *p_7f;
if (is_etag)
{
/*
* There are two formats for an emacs tag line:
* 1: struct EnvBase ^?EnvBase^A139,4627
* 2: #define ARPB_WILD_WORLD ^?153,5194
*/
p_7f = vim_strchr(lbuf, 0x7f);
if (p_7f == NULL)
{
etag_fail:
if (vim_strchr(lbuf, '\n') == NULL)
{
/* Truncated line. Ignore it. */
if (p_verbose >= 5)
{
verbose_enter();
MSG(_("Ignoring long line in tags file"));
verbose_leave();
}
tagp->command = lbuf;
tagp->tagname = lbuf;
tagp->tagname_end = lbuf;
return OK;
}
return FAIL;
}
/* Find ^A. If not found the line number is after the 0x7f */
p = vim_strchr(p_7f, Ctrl_A);
if (p == NULL)
p = p_7f + 1;
else
++p;
if (!VIM_ISDIGIT(*p)) /* check for start of line number */
goto etag_fail;
tagp->command = p;
if (p[-1] == Ctrl_A) /* first format: explicit tagname given */
{
tagp->tagname = p_7f + 1;
tagp->tagname_end = p - 1;
}
else /* second format: isolate tagname */
{
/* find end of tagname */
for (p = p_7f - 1; !vim_iswordc(*p); --p)
if (p == lbuf)
goto etag_fail;
tagp->tagname_end = p + 1;
while (p >= lbuf && vim_iswordc(*p))
--p;
tagp->tagname = p + 1;
}
}
else /* not an Emacs tag */
{
#endif
/* Isolate the tagname, from lbuf up to the first white */
tagp->tagname = lbuf;
#ifdef FEAT_TAG_ANYWHITE
p = skiptowhite(lbuf);
#else
p = vim_strchr(lbuf, TAB);
if (p == NULL)
return FAIL;
#endif
tagp->tagname_end = p;
/* Isolate file name, from first to second white space */
#ifdef FEAT_TAG_ANYWHITE
p = skipwhite(p);
#else
if (*p != NUL)
++p;
#endif
tagp->fname = p;
#ifdef FEAT_TAG_ANYWHITE
p = skiptowhite(p);
#else
p = vim_strchr(p, TAB);
if (p == NULL)
return FAIL;
#endif
tagp->fname_end = p;
/* find start of search command, after second white space */
#ifdef FEAT_TAG_ANYWHITE
p = skipwhite(p);
#else
if (*p != NUL)
++p;
#endif
if (*p == NUL)
return FAIL;
tagp->command = p;
#ifdef FEAT_EMACS_TAGS
}
#endif
return OK;
}
/*
* Check if tagname is a static tag
*
* Static tags produced by the older ctags program have the format:
* 'file:tag file /pattern'.
* This is only recognized when both occurrence of 'file' are the same, to
* avoid recognizing "string::string" or ":exit".
*
* Static tags produced by the new ctags program have the format:
* 'tag file /pattern/;"<Tab>file:' "
*
* Return TRUE if it is a static tag and adjust *tagname to the real tag.
* Return FALSE if it is not a static tag.
*/
static int
test_for_static(tagp)
tagptrs_T *tagp;
{
char_u *p;
#ifdef FEAT_TAG_OLDSTATIC
int len;
/*
* Check for old style static tag: "file:tag file .."
*/
len = (int)(tagp->fname_end - tagp->fname);
p = tagp->tagname + len;
if ( p < tagp->tagname_end
&& *p == ':'
&& fnamencmp(tagp->tagname, tagp->fname, len) == 0)
{
tagp->tagname = p + 1;
return TRUE;
}
#endif
/*
* Check for new style static tag ":...<Tab>file:[<Tab>...]"
*/
p = tagp->command;
while ((p = vim_strchr(p, '\t')) != NULL)
{
++p;
if (STRNCMP(p, "file:", 5) == 0)
return TRUE;
}
return FALSE;
}
/*
* Parse a line from a matching tag. Does not change the line itself.
*
* The line that we get looks like this:
* Emacs tag: <mtt><tag_fname><NUL><ebuf><NUL><lbuf>
* other tag: <mtt><tag_fname><NUL><NUL><lbuf>
* without Emacs tags: <mtt><tag_fname><NUL><lbuf>
*
* Return OK or FAIL.
*/
static int
parse_match(lbuf, tagp)
char_u *lbuf; /* input: matching line */
tagptrs_T *tagp; /* output: pointers into the line */
{
int retval;
char_u *p;
char_u *pc, *pt;
tagp->tag_fname = lbuf + 1;
lbuf += STRLEN(tagp->tag_fname) + 2;
#ifdef FEAT_EMACS_TAGS
if (*lbuf)
{
tagp->is_etag = TRUE;
tagp->fname = lbuf;
lbuf += STRLEN(lbuf);
tagp->fname_end = lbuf++;
}
else
{
tagp->is_etag = FALSE;
++lbuf;
}
#endif
/* Find search pattern and the file name for non-etags. */
retval = parse_tag_line(lbuf,
#ifdef FEAT_EMACS_TAGS
tagp->is_etag,
#endif
tagp);
tagp->tagkind = NULL;
tagp->command_end = NULL;
if (retval == OK)
{
/* Try to find a kind field: "kind:<kind>" or just "<kind>"*/
p = tagp->command;
if (find_extra(&p) == OK)
{
tagp->command_end = p;
p += 2; /* skip ";\"" */
if (*p++ == TAB)
while (ASCII_ISALPHA(*p))
{
if (STRNCMP(p, "kind:", 5) == 0)
{
tagp->tagkind = p + 5;
break;
}
pc = vim_strchr(p, ':');
pt = vim_strchr(p, '\t');
if (pc == NULL || (pt != NULL && pc > pt))
{
tagp->tagkind = p;
break;
}
if (pt == NULL)
break;
p = pt + 1;
}
}
if (tagp->tagkind != NULL)
{
for (p = tagp->tagkind;
*p && *p != '\t' && *p != '\r' && *p != '\n'; ++p)
;
tagp->tagkind_end = p;
}
}
return retval;
}
/*
* Find out the actual file name of a tag. Concatenate the tags file name
* with the matching tag file name.
* Returns an allocated string or NULL (out of memory).
*/
static char_u *
tag_full_fname(tagp)
tagptrs_T *tagp;
{
char_u *fullname;
int c;
#ifdef FEAT_EMACS_TAGS
if (tagp->is_etag)
c = 0; /* to shut up GCC */
else
#endif
{
c = *tagp->fname_end;
*tagp->fname_end = NUL;
}
fullname = expand_tag_fname(tagp->fname, tagp->tag_fname, FALSE);
#ifdef FEAT_EMACS_TAGS
if (!tagp->is_etag)
#endif
*tagp->fname_end = c;
return fullname;
}
/*
* Jump to a tag that has been found in one of the tag files
*
* returns OK for success, NOTAGFILE when file not found, FAIL otherwise.
*/
static int
jumpto_tag(lbuf, forceit, keep_help)
char_u *lbuf; /* line from the tags file for this tag */
int forceit; /* :ta with ! */
int keep_help; /* keep help flag (FALSE for cscope) */
{
int save_secure;
int save_magic;
int save_p_ws, save_p_scs, save_p_ic;
linenr_T save_lnum;
int csave = 0;
char_u *str;
char_u *pbuf; /* search pattern buffer */
char_u *pbuf_end;
char_u *tofree_fname = NULL;
char_u *fname;
tagptrs_T tagp;
int retval = FAIL;
int getfile_result;
int search_options;
#ifdef FEAT_SEARCH_EXTRA
int save_no_hlsearch;
#endif
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
win_T *curwin_save = NULL;
#endif
char_u *full_fname = NULL;
#ifdef FEAT_FOLDING
int old_KeyTyped = KeyTyped; /* getting the file may reset it */
#endif
pbuf = alloc(LSIZE);
/* parse the match line into the tagp structure */
if (pbuf == NULL || parse_match(lbuf, &tagp) == FAIL)
{
tagp.fname_end = NULL;
goto erret;
}
/* truncate the file name, so it can be used as a string */
csave = *tagp.fname_end;
*tagp.fname_end = NUL;
fname = tagp.fname;
/* copy the command to pbuf[], remove trailing CR/NL */
str = tagp.command;
for (pbuf_end = pbuf; *str && *str != '\n' && *str != '\r'; )
{
#ifdef FEAT_EMACS_TAGS
if (tagp.is_etag && *str == ',')/* stop at ',' after line number */
break;
#endif
*pbuf_end++ = *str++;
}
*pbuf_end = NUL;
#ifdef FEAT_EMACS_TAGS
if (!tagp.is_etag)
#endif
{
/*
* Remove the "<Tab>fieldname:value" stuff; we don't need it here.
*/
str = pbuf;
if (find_extra(&str) == OK)
{
pbuf_end = str;
*pbuf_end = NUL;
}
}
/*
* Expand file name, when needed (for environment variables).
* If 'tagrelative' option set, may change file name.
*/
fname = expand_tag_fname(fname, tagp.tag_fname, TRUE);
if (fname == NULL)
goto erret;
tofree_fname = fname; /* free() it later */
/*
* Check if the file with the tag exists before abandoning the current
* file. Also accept a file name for which there is a matching BufReadCmd
* autocommand event (e.g., http://sys/file).
*/
if (mch_getperm(fname) < 0
#ifdef FEAT_AUTOCMD
&& !has_autocmd(EVENT_BUFREADCMD, fname, NULL)
#endif
)
{
retval = NOTAGFILE;
vim_free(nofile_fname);
nofile_fname = vim_strsave(fname);
if (nofile_fname == NULL)
nofile_fname = empty_option;
goto erret;
}
++RedrawingDisabled;
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
postponed_split = 0; /* don't split again below */
curwin_save = curwin; /* Save current window */
/*
* If we are reusing a window, we may change dir when
* entering it (autocommands) so turn the tag filename
* into a fullpath
*/
if (!curwin->w_p_pvw)
{
full_fname = FullName_save(fname, FALSE);
fname = full_fname;
/*
* Make the preview window the current window.
* Open a preview window when needed.
*/
prepare_tagpreview(TRUE);
}
}
/* If it was a CTRL-W CTRL-] command split window now. For ":tab tag"
* open a new tab page. */
if (postponed_split || cmdmod.tab != 0)
{
win_split(postponed_split > 0 ? postponed_split : 0,
postponed_split_flags);
RESET_BINDING(curwin);
}
#endif
if (keep_help)
{
/* A :ta from a help file will keep the b_help flag set. For ":ptag"
* we need to use the flag from the window where we came from. */
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
keep_help_flag = curwin_save->w_buffer->b_help;
else
#endif
keep_help_flag = curbuf->b_help;
}
getfile_result = getfile(0, fname, NULL, TRUE, (linenr_T)0, forceit);
keep_help_flag = FALSE;
if (getfile_result <= 0) /* got to the right file */
{
curwin->w_set_curswant = TRUE;
#ifdef FEAT_WINDOWS
postponed_split = 0;
#endif
save_secure = secure;
secure = 1;
#ifdef HAVE_SANDBOX
++sandbox;
#endif
save_magic = p_magic;
p_magic = FALSE; /* always execute with 'nomagic' */
#ifdef FEAT_SEARCH_EXTRA
/* Save value of no_hlsearch, jumping to a tag is not a real search */
save_no_hlsearch = no_hlsearch;
#endif
/*
* If 'cpoptions' contains 't', store the search pattern for the "n"
* command. If 'cpoptions' does not contain 't', the search pattern
* is not stored.
*/
if (vim_strchr(p_cpo, CPO_TAGPAT) != NULL)
search_options = 0;
else
search_options = SEARCH_KEEP;
/*
* If the command is a search, try here.
*
* Reset 'smartcase' for the search, since the search pattern was not
* typed by the user.
* Only use do_search() when there is a full search command, without
* anything following.
*/
str = pbuf;
if (pbuf[0] == '/' || pbuf[0] == '?')
str = skip_regexp(pbuf + 1, pbuf[0], FALSE, NULL) + 1;
if (str > pbuf_end - 1) /* search command with nothing following */
{
save_p_ws = p_ws;
save_p_ic = p_ic;
save_p_scs = p_scs;
p_ws = TRUE; /* need 'wrapscan' for backward searches */
p_ic = FALSE; /* don't ignore case now */
p_scs = FALSE;
#if 0 /* disabled for now */
#ifdef FEAT_CMDHIST
/* put pattern in search history */
add_to_history(HIST_SEARCH, pbuf + 1, TRUE, pbuf[0]);
#endif
#endif
save_lnum = curwin->w_cursor.lnum;
curwin->w_cursor.lnum = 0; /* start search before first line */
if (do_search(NULL, pbuf[0], pbuf + 1, (long)1,
search_options, NULL))
retval = OK;
else
{
int found = 1;
int cc;
/*
* try again, ignore case now
*/
p_ic = TRUE;
if (!do_search(NULL, pbuf[0], pbuf + 1, (long)1,
search_options, NULL))
{
/*
* Failed to find pattern, take a guess: "^func ("
*/
found = 2;
(void)test_for_static(&tagp);
cc = *tagp.tagname_end;
*tagp.tagname_end = NUL;
sprintf((char *)pbuf, "^%s\\s\\*(", tagp.tagname);
if (!do_search(NULL, '/', pbuf, (long)1,
search_options, NULL))
{
/* Guess again: "^char * \<func (" */
sprintf((char *)pbuf, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(",
tagp.tagname);
if (!do_search(NULL, '/', pbuf, (long)1,
search_options, NULL))
found = 0;
}
*tagp.tagname_end = cc;
}
if (found == 0)
{
EMSG(_("E434: Can't find tag pattern"));
curwin->w_cursor.lnum = save_lnum;
}
else
{
/*
* Only give a message when really guessed, not when 'ic'
* is set and match found while ignoring case.
*/
if (found == 2 || !save_p_ic)
{
MSG(_("E435: Couldn't find tag, just guessing!"));
if (!msg_scrolled && msg_silent == 0)
{
out_flush();
ui_delay(1000L, TRUE);
}
}
retval = OK;
}
}
p_ws = save_p_ws;
p_ic = save_p_ic;
p_scs = save_p_scs;
/* A search command may have positioned the cursor beyond the end
* of the line. May need to correct that here. */
check_cursor();
}
else
{
curwin->w_cursor.lnum = 1; /* start command in line 1 */
do_cmdline_cmd(pbuf);
retval = OK;
}
/*
* When the command has done something that is not allowed make sure
* the error message can be seen.
*/
if (secure == 2)
wait_return(TRUE);
secure = save_secure;
p_magic = save_magic;
#ifdef HAVE_SANDBOX
--sandbox;
#endif
#ifdef FEAT_SEARCH_EXTRA
/* restore no_hlsearch when keeping the old search pattern */
if (search_options)
no_hlsearch = save_no_hlsearch;
#endif
/* Return OK if jumped to another file (at least we found the file!). */
if (getfile_result == -1)
retval = OK;
if (retval == OK)
{
/*
* For a help buffer: Put the cursor line at the top of the window,
* the help subject will be below it.
*/
if (curbuf->b_help)
set_topline(curwin, curwin->w_cursor.lnum);
#ifdef FEAT_FOLDING
if ((fdo_flags & FDO_TAG) && old_KeyTyped)
foldOpenCursor();
#endif
}
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0
&& curwin != curwin_save && win_valid(curwin_save))
{
/* Return cursor to where we were */
validate_cursor();
redraw_later(VALID);
win_enter(curwin_save, TRUE);
}
#endif
--RedrawingDisabled;
}
else
{
--RedrawingDisabled;
#ifdef FEAT_WINDOWS
if (postponed_split) /* close the window */
{
win_close(curwin, FALSE);
postponed_split = 0;
}
#endif
}
erret:
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
g_do_tagpreview = 0; /* For next time */
#endif
if (tagp.fname_end != NULL)
*tagp.fname_end = csave;
vim_free(pbuf);
vim_free(tofree_fname);
vim_free(full_fname);
return retval;
}
/*
* If "expand" is TRUE, expand wildcards in fname.
* If 'tagrelative' option set, change fname (name of file containing tag)
* according to tag_fname (name of tag file containing fname).
* Returns a pointer to allocated memory (or NULL when out of memory).
*/
static char_u *
expand_tag_fname(fname, tag_fname, expand)
char_u *fname;
char_u *tag_fname;
int expand;
{
char_u *p;
char_u *retval;
char_u *expanded_fname = NULL;
expand_T xpc;
/*
* Expand file name (for environment variables) when needed.
*/
if (expand && mch_has_wildcard(fname))
{
ExpandInit(&xpc);
xpc.xp_context = EXPAND_FILES;
expanded_fname = ExpandOne(&xpc, (char_u *)fname, NULL,
WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE);
if (expanded_fname != NULL)
fname = expanded_fname;
}
if ((p_tr || curbuf->b_help)
&& !vim_isAbsName(fname)
&& (p = gettail(tag_fname)) != tag_fname)
{
retval = alloc(MAXPATHL);
if (retval != NULL)
{
STRCPY(retval, tag_fname);
vim_strncpy(retval + (p - tag_fname), fname,
MAXPATHL - (p - tag_fname) - 1);
/*
* Translate names like "src/a/../b/file.c" into "src/b/file.c".
*/
simplify_filename(retval);
}
}
else
retval = vim_strsave(fname);
vim_free(expanded_fname);
return retval;
}
/*
* Converts a file name into a canonical form. It simplifies a file name into
* its simplest form by stripping out unneeded components, if any. The
* resulting file name is simplified in place and will either be the same
* length as that supplied, or shorter.
*/
void
simplify_filename(filename)
char_u *filename;
{
#ifndef AMIGA /* Amiga doesn't have "..", it uses "/" */
int components = 0;
char_u *p, *tail, *start;
int stripping_disabled = FALSE;
int relative = TRUE;
p = filename;
#ifdef BACKSLASH_IN_FILENAME
if (p[1] == ':') /* skip "x:" */
p += 2;
#endif
if (vim_ispathsep(*p))
{
relative = FALSE;
do
++p;
while (vim_ispathsep(*p));
}
start = p; /* remember start after "c:/" or "/" or "///" */
do
{
/* At this point "p" is pointing to the char following a single "/"
* or "p" is at the "start" of the (absolute or relative) path name. */
#ifdef VMS
/* VMS allows device:[path] - don't strip the [ in directory */
if ((*p == '[' || *p == '<') && p > filename && p[-1] == ':')
{
/* :[ or :< composition: vms directory component */
++components;
p = getnextcomp(p + 1);
}
/* allow remote calls as host"user passwd"::device:[path] */
else if (p[0] == ':' && p[1] == ':' && p > filename && p[-1] == '"' )
{
/* ":: composition: vms host/passwd component */
++components;
p = getnextcomp(p + 2);
}
else
#endif
if (vim_ispathsep(*p))
STRMOVE(p, p + 1); /* remove duplicate "/" */
else if (p[0] == '.' && (vim_ispathsep(p[1]) || p[1] == NUL))
{
if (p == start && relative)
p += 1 + (p[1] != NUL); /* keep single "." or leading "./" */
else
{
/* Strip "./" or ".///". If we are at the end of the file name
* and there is no trailing path separator, either strip "/." if
* we are after "start", or strip "." if we are at the beginning
* of an absolute path name . */
tail = p + 1;
if (p[1] != NUL)
while (vim_ispathsep(*tail))
mb_ptr_adv(tail);
else if (p > start)
--p; /* strip preceding path separator */
STRMOVE(p, tail);
}
}
else if (p[0] == '.' && p[1] == '.' &&
(vim_ispathsep(p[2]) || p[2] == NUL))
{
/* Skip to after ".." or "../" or "..///". */
tail = p + 2;
while (vim_ispathsep(*tail))
mb_ptr_adv(tail);
if (components > 0) /* strip one preceding component */
{
int do_strip = FALSE;
char_u saved_char;
struct stat st;
/* Don't strip for an erroneous file name. */
if (!stripping_disabled)
{
/* If the preceding component does not exist in the file
* system, we strip it. On Unix, we don't accept a symbolic
* link that refers to a non-existent file. */
saved_char = p[-1];
p[-1] = NUL;
#ifdef UNIX
if (mch_lstat((char *)filename, &st) < 0)
#else
if (mch_stat((char *)filename, &st) < 0)
#endif
do_strip = TRUE;
p[-1] = saved_char;
--p;
/* Skip back to after previous '/'. */
while (p > start && !after_pathsep(start, p))
mb_ptr_back(start, p);
if (!do_strip)
{
/* If the component exists in the file system, check
* that stripping it won't change the meaning of the
* file name. First get information about the
* unstripped file name. This may fail if the component
* to strip is not a searchable directory (but a regular
* file, for instance), since the trailing "/.." cannot
* be applied then. We don't strip it then since we
* don't want to replace an erroneous file name by
* a valid one, and we disable stripping of later
* components. */
saved_char = *tail;
*tail = NUL;
if (mch_stat((char *)filename, &st) >= 0)
do_strip = TRUE;
else
stripping_disabled = TRUE;
*tail = saved_char;
#ifdef UNIX
if (do_strip)
{
struct stat new_st;
/* On Unix, the check for the unstripped file name
* above works also for a symbolic link pointing to
* a searchable directory. But then the parent of
* the directory pointed to by the link must be the
* same as the stripped file name. (The latter
* exists in the file system since it is the
* component's parent directory.) */
if (p == start && relative)
(void)mch_stat(".", &new_st);
else
{
saved_char = *p;
*p = NUL;
(void)mch_stat((char *)filename, &new_st);
*p = saved_char;
}
if (new_st.st_ino != st.st_ino ||
new_st.st_dev != st.st_dev)
{
do_strip = FALSE;
/* We don't disable stripping of later
* components since the unstripped path name is
* still valid. */
}
}
#endif
}
}
if (!do_strip)
{
/* Skip the ".." or "../" and reset the counter for the
* components that might be stripped later on. */
p = tail;
components = 0;
}
else
{
/* Strip previous component. If the result would get empty
* and there is no trailing path separator, leave a single
* "." instead. If we are at the end of the file name and
* there is no trailing path separator and a preceding
* component is left after stripping, strip its trailing
* path separator as well. */
if (p == start && relative && tail[-1] == '.')
{
*p++ = '.';
*p = NUL;
}
else
{
if (p > start && tail[-1] == '.')
--p;
STRMOVE(p, tail); /* strip previous component */
}
--components;
}
}
else if (p == start && !relative) /* leading "/.." or "/../" */
STRMOVE(p, tail); /* strip ".." or "../" */
else
{
if (p == start + 2 && p[-2] == '.') /* leading "./../" */
{
STRMOVE(p - 2, p); /* strip leading "./" */
tail -= 2;
}
p = tail; /* skip to char after ".." or "../" */
}
}
else
{
++components; /* simple path component */
p = getnextcomp(p);
}
} while (*p != NUL);
#endif /* !AMIGA */
}
/*
* Check if we have a tag for the buffer with name "buf_ffname".
* This is a bit slow, because of the full path compare in fullpathcmp().
* Return TRUE if tag for file "fname" if tag file "tag_fname" is for current
* file.
*/
static int
#ifdef FEAT_EMACS_TAGS
test_for_current(is_etag, fname, fname_end, tag_fname, buf_ffname)
int is_etag;
#else
test_for_current(fname, fname_end, tag_fname, buf_ffname)
#endif
char_u *fname;
char_u *fname_end;
char_u *tag_fname;
char_u *buf_ffname;
{
int c;
int retval = FALSE;
char_u *fullname;
if (buf_ffname != NULL) /* if the buffer has a name */
{
#ifdef FEAT_EMACS_TAGS
if (is_etag)
c = 0; /* to shut up GCC */
else
#endif
{
c = *fname_end;
*fname_end = NUL;
}
fullname = expand_tag_fname(fname, tag_fname, TRUE);
if (fullname != NULL)
{
retval = (fullpathcmp(fullname, buf_ffname, TRUE) & FPC_SAME);
vim_free(fullname);
}
#ifdef FEAT_EMACS_TAGS
if (!is_etag)
#endif
*fname_end = c;
}
return retval;
}
/*
* Find the end of the tagaddress.
* Return OK if ";\"" is following, FAIL otherwise.
*/
static int
find_extra(pp)
char_u **pp;
{
char_u *str = *pp;
/* Repeat for addresses separated with ';' */
for (;;)
{
if (VIM_ISDIGIT(*str))
str = skipdigits(str);
else if (*str == '/' || *str == '?')
{
str = skip_regexp(str + 1, *str, FALSE, NULL);
if (*str != **pp)
str = NULL;
else
++str;
}
else
str = NULL;
if (str == NULL || *str != ';'
|| !(VIM_ISDIGIT(str[1]) || str[1] == '/' || str[1] == '?'))
break;
++str; /* skip ';' */
}
if (str != NULL && STRNCMP(str, ";\"", 2) == 0)
{
*pp = str;
return OK;
}
return FAIL;
}
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
int
expand_tags(tagnames, pat, num_file, file)
int tagnames; /* expand tag names */
char_u *pat;
int *num_file;
char_u ***file;
{
int i;
int c;
int tagnmflag;
char_u tagnm[100];
tagptrs_T t_p;
int ret;
if (tagnames)
tagnmflag = TAG_NAMES;
else
tagnmflag = 0;
if (pat[0] == '/')
ret = find_tags(pat + 1, num_file, file,
TAG_REGEXP | tagnmflag | TAG_VERBOSE,
TAG_MANY, curbuf->b_ffname);
else
ret = find_tags(pat, num_file, file,
TAG_REGEXP | tagnmflag | TAG_VERBOSE | TAG_NOIC,
TAG_MANY, curbuf->b_ffname);
if (ret == OK && !tagnames)
{
/* Reorganize the tags for display and matching as strings of:
* "<tagname>\0<kind>\0<filename>\0"
*/
for (i = 0; i < *num_file; i++)
{
parse_match((*file)[i], &t_p);
c = (int)(t_p.tagname_end - t_p.tagname);
mch_memmove(tagnm, t_p.tagname, (size_t)c);
tagnm[c++] = 0;
tagnm[c++] = (t_p.tagkind != NULL && *t_p.tagkind)
? *t_p.tagkind : 'f';
tagnm[c++] = 0;
mch_memmove((*file)[i] + c, t_p.fname, t_p.fname_end - t_p.fname);
(*file)[i][c + (t_p.fname_end - t_p.fname)] = 0;
mch_memmove((*file)[i], tagnm, (size_t)c);
}
}
return ret;
}
#endif
#if defined(FEAT_EVAL) || defined(PROTO)
static int add_tag_field __ARGS((dict_T *dict, char *field_name, char_u *start, char_u *end));
/*
* Add a tag field to the dictionary "dict".
* Return OK or FAIL.
*/
static int
add_tag_field(dict, field_name, start, end)
dict_T *dict;
char *field_name;
char_u *start; /* start of the value */
char_u *end; /* after the value; can be NULL */
{
char_u *buf;
int len = 0;
int retval;
/* check that the field name doesn't exist yet */
if (dict_find(dict, (char_u *)field_name, -1) != NULL)
{
if (p_verbose > 0)
{
verbose_enter();
smsg((char_u *)_("Duplicate field name: %s"), field_name);
verbose_leave();
}
return FAIL;
}
buf = alloc(MAXPATHL);
if (buf == NULL)
return FAIL;
if (start != NULL)
{
if (end == NULL)
{
end = start + STRLEN(start);
while (end > start && (end[-1] == '\r' || end[-1] == '\n'))
--end;
}
len = (int)(end - start);
if (len > MAXPATHL - 1)
len = MAXPATHL - 1;
vim_strncpy(buf, start, len);
}
buf[len] = NUL;
retval = dict_add_nr_str(dict, field_name, 0L, buf);
vim_free(buf);
return retval;
}
/*
* Add the tags matching the specified pattern to the list "list"
* as a dictionary
*/
int
get_tags(list, pat)
list_T *list;
char_u *pat;
{
int num_matches, i, ret;
char_u **matches, *p;
char_u *full_fname;
dict_T *dict;
tagptrs_T tp;
long is_static;
ret = find_tags(pat, &num_matches, &matches,
TAG_REGEXP | TAG_NOIC, (int)MAXCOL, NULL);
if (ret == OK && num_matches > 0)
{
for (i = 0; i < num_matches; ++i)
{
parse_match(matches[i], &tp);
is_static = test_for_static(&tp);
/* Skip pseudo-tag lines. */
if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0)
continue;
if ((dict = dict_alloc()) == NULL)
ret = FAIL;
if (list_append_dict(list, dict) == FAIL)
ret = FAIL;
full_fname = tag_full_fname(&tp);
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
|| add_tag_field(dict, "filename", full_fname,
NULL) == FAIL
|| add_tag_field(dict, "cmd", tp.command,
tp.command_end) == FAIL
|| add_tag_field(dict, "kind", tp.tagkind,
tp.tagkind_end) == FAIL
|| dict_add_nr_str(dict, "static", is_static, NULL) == FAIL)
ret = FAIL;
vim_free(full_fname);
if (tp.command_end != NULL)
{
for (p = tp.command_end + 3;
*p != NUL && *p != '\n' && *p != '\r'; ++p)
{
if (p == tp.tagkind || (p + 5 == tp.tagkind
&& STRNCMP(p, "kind:", 5) == 0))
/* skip "kind:<kind>" and "<kind>" */
p = tp.tagkind_end - 1;
else if (STRNCMP(p, "file:", 5) == 0)
/* skip "file:" (static tag) */
p += 4;
else if (!vim_iswhite(*p))
{
char_u *s, *n;
int len;
/* Add extra field as a dict entry. Fields are
* separated by Tabs. */
n = p;
while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':')
++p;
len = (int)(p - n);
if (*p == ':' && len > 0)
{
s = ++p;
while (*p != NUL && *p >= ' ')
++p;
n[len] = NUL;
if (add_tag_field(dict, (char *)n, s, p) == FAIL)
ret = FAIL;
n[len] = ':';
}
else
/* Skip field without colon. */
while (*p != NUL && *p >= ' ')
++p;
if (*p == NUL)
break;
}
}
}
vim_free(matches[i]);
}
vim_free(matches);
}
return ret;
}
#endif
| zyz2011-vim | src/tag.c | C | gpl2 | 97,803 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* move.c: Functions for moving the cursor and scrolling text.
*
* There are two ways to move the cursor:
* 1. Move the cursor directly, the text is scrolled to keep the cursor in the
* window.
* 2. Scroll the text, the cursor is moved into the text visible in the
* window.
* The 'scrolloff' option makes this a bit complicated.
*/
#include "vim.h"
static void comp_botline __ARGS((win_T *wp));
static int scrolljump_value __ARGS((void));
static int check_top_offset __ARGS((void));
static void curs_rows __ARGS((win_T *wp, int do_botline));
static void validate_botline_win __ARGS((win_T *wp));
static void validate_cheight __ARGS((void));
typedef struct
{
linenr_T lnum; /* line number */
#ifdef FEAT_DIFF
int fill; /* filler lines */
#endif
int height; /* height of added line */
} lineoff_T;
static void topline_back __ARGS((lineoff_T *lp));
static void botline_forw __ARGS((lineoff_T *lp));
#ifdef FEAT_DIFF
static void botline_topline __ARGS((lineoff_T *lp));
static void topline_botline __ARGS((lineoff_T *lp));
static void max_topfill __ARGS((void));
#endif
/*
* Compute wp->w_botline for the current wp->w_topline. Can be called after
* wp->w_topline changed.
*/
static void
comp_botline(wp)
win_T *wp;
{
int n;
linenr_T lnum;
int done;
#ifdef FEAT_FOLDING
linenr_T last;
int folded;
#endif
/*
* If w_cline_row is valid, start there.
* Otherwise have to start at w_topline.
*/
check_cursor_moved(wp);
if (wp->w_valid & VALID_CROW)
{
lnum = wp->w_cursor.lnum;
done = wp->w_cline_row;
}
else
{
lnum = wp->w_topline;
done = 0;
}
for ( ; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum)
{
#ifdef FEAT_FOLDING
last = lnum;
folded = FALSE;
if (hasFoldingWin(wp, lnum, NULL, &last, TRUE, NULL))
{
n = 1;
folded = TRUE;
}
else
#endif
#ifdef FEAT_DIFF
if (lnum == wp->w_topline)
n = plines_win_nofill(wp, lnum, TRUE) + wp->w_topfill;
else
#endif
n = plines_win(wp, lnum, TRUE);
if (
#ifdef FEAT_FOLDING
lnum <= wp->w_cursor.lnum && last >= wp->w_cursor.lnum
#else
lnum == wp->w_cursor.lnum
#endif
)
{
wp->w_cline_row = done;
wp->w_cline_height = n;
#ifdef FEAT_FOLDING
wp->w_cline_folded = folded;
#endif
wp->w_valid |= (VALID_CROW|VALID_CHEIGHT);
}
if (done + n > wp->w_height)
break;
done += n;
#ifdef FEAT_FOLDING
lnum = last;
#endif
}
/* wp->w_botline is the line that is just below the window */
wp->w_botline = lnum;
wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
set_empty_rows(wp, done);
}
/*
* Update curwin->w_topline and redraw if necessary.
* Used to update the screen before printing a message.
*/
void
update_topline_redraw()
{
update_topline();
if (must_redraw)
update_screen(0);
}
/*
* Update curwin->w_topline to move the cursor onto the screen.
*/
void
update_topline()
{
long line_count;
int halfheight;
int n;
linenr_T old_topline;
#ifdef FEAT_DIFF
int old_topfill;
#endif
#ifdef FEAT_FOLDING
linenr_T lnum;
#endif
int check_topline = FALSE;
int check_botline = FALSE;
#ifdef FEAT_MOUSE
int save_so = p_so;
#endif
if (!screen_valid(TRUE))
return;
check_cursor_moved(curwin);
if (curwin->w_valid & VALID_TOPLINE)
return;
#ifdef FEAT_MOUSE
/* When dragging with the mouse, don't scroll that quickly */
if (mouse_dragging > 0)
p_so = mouse_dragging - 1;
#endif
old_topline = curwin->w_topline;
#ifdef FEAT_DIFF
old_topfill = curwin->w_topfill;
#endif
/*
* If the buffer is empty, always set topline to 1.
*/
if (bufempty()) /* special case - file is empty */
{
if (curwin->w_topline != 1)
redraw_later(NOT_VALID);
curwin->w_topline = 1;
curwin->w_botline = 2;
curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
#ifdef FEAT_SCROLLBIND
curwin->w_scbind_pos = 1;
#endif
}
/*
* If the cursor is above or near the top of the window, scroll the window
* to show the line the cursor is in, with 'scrolloff' context.
*/
else
{
if (curwin->w_topline > 1)
{
/* If the cursor is above topline, scrolling is always needed.
* If the cursor is far below topline and there is no folding,
* scrolling down is never needed. */
if (curwin->w_cursor.lnum < curwin->w_topline)
check_topline = TRUE;
else if (check_top_offset())
check_topline = TRUE;
}
#ifdef FEAT_DIFF
/* Check if there are more filler lines than allowed. */
if (!check_topline && curwin->w_topfill > diff_check_fill(curwin,
curwin->w_topline))
check_topline = TRUE;
#endif
if (check_topline)
{
halfheight = curwin->w_height / 2 - 1;
if (halfheight < 2)
halfheight = 2;
#ifdef FEAT_FOLDING
if (hasAnyFolding(curwin))
{
/* Count the number of logical lines between the cursor and
* topline + p_so (approximation of how much will be
* scrolled). */
n = 0;
for (lnum = curwin->w_cursor.lnum;
lnum < curwin->w_topline + p_so; ++lnum)
{
++n;
/* stop at end of file or when we know we are far off */
if (lnum >= curbuf->b_ml.ml_line_count || n >= halfheight)
break;
(void)hasFolding(lnum, NULL, &lnum);
}
}
else
#endif
n = curwin->w_topline + p_so - curwin->w_cursor.lnum;
/* If we weren't very close to begin with, we scroll to put the
* cursor in the middle of the window. Otherwise put the cursor
* near the top of the window. */
if (n >= halfheight)
scroll_cursor_halfway(FALSE);
else
{
scroll_cursor_top(scrolljump_value(), FALSE);
check_botline = TRUE;
}
}
else
{
#ifdef FEAT_FOLDING
/* Make sure topline is the first line of a fold. */
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
#endif
check_botline = TRUE;
}
}
/*
* If the cursor is below the bottom of the window, scroll the window
* to put the cursor on the window.
* When w_botline is invalid, recompute it first, to avoid a redraw later.
* If w_botline was approximated, we might need a redraw later in a few
* cases, but we don't want to spend (a lot of) time recomputing w_botline
* for every small change.
*/
if (check_botline)
{
if (!(curwin->w_valid & VALID_BOTLINE_AP))
validate_botline();
if (curwin->w_botline <= curbuf->b_ml.ml_line_count)
{
if (curwin->w_cursor.lnum < curwin->w_botline)
{
if (((long)curwin->w_cursor.lnum
>= (long)curwin->w_botline - p_so
#ifdef FEAT_FOLDING
|| hasAnyFolding(curwin)
#endif
))
{
lineoff_T loff;
/* Cursor is (a few lines) above botline, check if there are
* 'scrolloff' window lines below the cursor. If not, need to
* scroll. */
n = curwin->w_empty_rows;
loff.lnum = curwin->w_cursor.lnum;
#ifdef FEAT_FOLDING
/* In a fold go to its last line. */
(void)hasFolding(loff.lnum, NULL, &loff.lnum);
#endif
#ifdef FEAT_DIFF
loff.fill = 0;
n += curwin->w_filler_rows;
#endif
loff.height = 0;
while (loff.lnum < curwin->w_botline
#ifdef FEAT_DIFF
&& (loff.lnum + 1 < curwin->w_botline || loff.fill == 0)
#endif
)
{
n += loff.height;
if (n >= p_so)
break;
botline_forw(&loff);
}
if (n >= p_so)
/* sufficient context, no need to scroll */
check_botline = FALSE;
}
else
/* sufficient context, no need to scroll */
check_botline = FALSE;
}
if (check_botline)
{
#ifdef FEAT_FOLDING
if (hasAnyFolding(curwin))
{
/* Count the number of logical lines between the cursor and
* botline - p_so (approximation of how much will be
* scrolled). */
line_count = 0;
for (lnum = curwin->w_cursor.lnum;
lnum >= curwin->w_botline - p_so; --lnum)
{
++line_count;
/* stop at end of file or when we know we are far off */
if (lnum <= 0 || line_count > curwin->w_height + 1)
break;
(void)hasFolding(lnum, &lnum, NULL);
}
}
else
#endif
line_count = curwin->w_cursor.lnum - curwin->w_botline
+ 1 + p_so;
if (line_count <= curwin->w_height + 1)
scroll_cursor_bot(scrolljump_value(), FALSE);
else
scroll_cursor_halfway(FALSE);
}
}
}
curwin->w_valid |= VALID_TOPLINE;
/*
* Need to redraw when topline changed.
*/
if (curwin->w_topline != old_topline
#ifdef FEAT_DIFF
|| curwin->w_topfill != old_topfill
#endif
)
{
dollar_vcol = -1;
if (curwin->w_skipcol != 0)
{
curwin->w_skipcol = 0;
redraw_later(NOT_VALID);
}
else
redraw_later(VALID);
/* May need to set w_skipcol when cursor in w_topline. */
if (curwin->w_cursor.lnum == curwin->w_topline)
validate_cursor();
}
#ifdef FEAT_MOUSE
p_so = save_so;
#endif
}
/*
* Return the scrolljump value to use for the current window.
* When 'scrolljump' is positive use it as-is.
* When 'scrolljump' is negative use it as a percentage of the window height.
*/
static int
scrolljump_value()
{
if (p_sj >= 0)
return (int)p_sj;
return (curwin->w_height * -p_sj) / 100;
}
/*
* Return TRUE when there are not 'scrolloff' lines above the cursor for the
* current window.
*/
static int
check_top_offset()
{
lineoff_T loff;
int n;
if (curwin->w_cursor.lnum < curwin->w_topline + p_so
#ifdef FEAT_FOLDING
|| hasAnyFolding(curwin)
#endif
)
{
loff.lnum = curwin->w_cursor.lnum;
#ifdef FEAT_DIFF
loff.fill = 0;
n = curwin->w_topfill; /* always have this context */
#else
n = 0;
#endif
/* Count the visible screen lines above the cursor line. */
while (n < p_so)
{
topline_back(&loff);
/* Stop when included a line above the window. */
if (loff.lnum < curwin->w_topline
#ifdef FEAT_DIFF
|| (loff.lnum == curwin->w_topline && loff.fill > 0)
#endif
)
break;
n += loff.height;
}
if (n < p_so)
return TRUE;
}
return FALSE;
}
void
update_curswant()
{
if (curwin->w_set_curswant)
{
validate_virtcol();
curwin->w_curswant = curwin->w_virtcol;
curwin->w_set_curswant = FALSE;
}
}
/*
* Check if the cursor has moved. Set the w_valid flag accordingly.
*/
void
check_cursor_moved(wp)
win_T *wp;
{
if (wp->w_cursor.lnum != wp->w_valid_cursor.lnum)
{
wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL
|VALID_CHEIGHT|VALID_CROW|VALID_TOPLINE);
wp->w_valid_cursor = wp->w_cursor;
wp->w_valid_leftcol = wp->w_leftcol;
}
else if (wp->w_cursor.col != wp->w_valid_cursor.col
|| wp->w_leftcol != wp->w_valid_leftcol
#ifdef FEAT_VIRTUALEDIT
|| wp->w_cursor.coladd != wp->w_valid_cursor.coladd
#endif
)
{
wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
wp->w_valid_cursor.col = wp->w_cursor.col;
wp->w_valid_leftcol = wp->w_leftcol;
#ifdef FEAT_VIRTUALEDIT
wp->w_valid_cursor.coladd = wp->w_cursor.coladd;
#endif
}
}
/*
* Call this function when some window settings have changed, which require
* the cursor position, botline and topline to be recomputed and the window to
* be redrawn. E.g, when changing the 'wrap' option or folding.
*/
void
changed_window_setting()
{
changed_window_setting_win(curwin);
}
void
changed_window_setting_win(wp)
win_T *wp;
{
wp->w_lines_valid = 0;
changed_line_abv_curs_win(wp);
wp->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP|VALID_TOPLINE);
redraw_win_later(wp, NOT_VALID);
}
/*
* Set wp->w_topline to a certain number.
*/
void
set_topline(wp, lnum)
win_T *wp;
linenr_T lnum;
{
#ifdef FEAT_FOLDING
/* go to first of folded lines */
(void)hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL);
#endif
/* Approximate the value of w_botline */
wp->w_botline += lnum - wp->w_topline;
wp->w_topline = lnum;
#ifdef FEAT_AUTOCMD
wp->w_topline_was_set = TRUE;
#endif
#ifdef FEAT_DIFF
wp->w_topfill = 0;
#endif
wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_TOPLINE);
/* Don't set VALID_TOPLINE here, 'scrolloff' needs to be checked. */
redraw_later(VALID);
}
/*
* Call this function when the length of the cursor line (in screen
* characters) has changed, and the change is before the cursor.
* Need to take care of w_botline separately!
*/
void
changed_cline_bef_curs()
{
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL
|VALID_CHEIGHT|VALID_TOPLINE);
}
void
changed_cline_bef_curs_win(wp)
win_T *wp;
{
wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL
|VALID_CHEIGHT|VALID_TOPLINE);
}
/*
* Call this function when the length of a line (in screen characters) above
* the cursor have changed.
* Need to take care of w_botline separately!
*/
void
changed_line_abv_curs()
{
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW
|VALID_CHEIGHT|VALID_TOPLINE);
}
void
changed_line_abv_curs_win(wp)
win_T *wp;
{
wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW
|VALID_CHEIGHT|VALID_TOPLINE);
}
/*
* Make sure the value of curwin->w_botline is valid.
*/
void
validate_botline()
{
if (!(curwin->w_valid & VALID_BOTLINE))
comp_botline(curwin);
}
/*
* Make sure the value of wp->w_botline is valid.
*/
static void
validate_botline_win(wp)
win_T *wp;
{
if (!(wp->w_valid & VALID_BOTLINE))
comp_botline(wp);
}
/*
* Mark curwin->w_botline as invalid (because of some change in the buffer).
*/
void
invalidate_botline()
{
curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP);
}
void
invalidate_botline_win(wp)
win_T *wp;
{
wp->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP);
}
void
approximate_botline_win(wp)
win_T *wp;
{
wp->w_valid &= ~VALID_BOTLINE;
}
/*
* Return TRUE if curwin->w_wrow and curwin->w_wcol are valid.
*/
int
cursor_valid()
{
check_cursor_moved(curwin);
return ((curwin->w_valid & (VALID_WROW|VALID_WCOL)) ==
(VALID_WROW|VALID_WCOL));
}
/*
* Validate cursor position. Makes sure w_wrow and w_wcol are valid.
* w_topline must be valid, you may need to call update_topline() first!
*/
void
validate_cursor()
{
check_cursor_moved(curwin);
if ((curwin->w_valid & (VALID_WCOL|VALID_WROW)) != (VALID_WCOL|VALID_WROW))
curs_columns(TRUE);
}
#if defined(FEAT_GUI) || defined(PROTO)
/*
* validate w_cline_row.
*/
void
validate_cline_row()
{
/*
* First make sure that w_topline is valid (after moving the cursor).
*/
update_topline();
check_cursor_moved(curwin);
if (!(curwin->w_valid & VALID_CROW))
curs_rows(curwin, FALSE);
}
#endif
/*
* Compute wp->w_cline_row and wp->w_cline_height, based on the current value
* of wp->w_topline.
*
* Returns OK when cursor is in the window, FAIL when it isn't.
*/
static void
curs_rows(wp, do_botline)
win_T *wp;
int do_botline; /* also compute w_botline */
{
linenr_T lnum;
int i;
int all_invalid;
int valid;
#ifdef FEAT_FOLDING
long fold_count;
#endif
/* Check if wp->w_lines[].wl_size is invalid */
all_invalid = (!redrawing()
|| wp->w_lines_valid == 0
|| wp->w_lines[0].wl_lnum > wp->w_topline);
i = 0;
wp->w_cline_row = 0;
for (lnum = wp->w_topline; lnum < wp->w_cursor.lnum; ++i)
{
valid = FALSE;
if (!all_invalid && i < wp->w_lines_valid)
{
if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid)
continue; /* skip changed or deleted lines */
if (wp->w_lines[i].wl_lnum == lnum)
{
#ifdef FEAT_FOLDING
/* Check for newly inserted lines below this row, in which
* case we need to check for folded lines. */
if (!wp->w_buffer->b_mod_set
|| wp->w_lines[i].wl_lastlnum < wp->w_cursor.lnum
|| wp->w_buffer->b_mod_top
> wp->w_lines[i].wl_lastlnum + 1)
#endif
valid = TRUE;
}
else if (wp->w_lines[i].wl_lnum > lnum)
--i; /* hold at inserted lines */
}
if (valid
#ifdef FEAT_DIFF
&& (lnum != wp->w_topline || !wp->w_p_diff)
#endif
)
{
#ifdef FEAT_FOLDING
lnum = wp->w_lines[i].wl_lastlnum + 1;
/* Cursor inside folded lines, don't count this row */
if (lnum > wp->w_cursor.lnum)
break;
#else
++lnum;
#endif
wp->w_cline_row += wp->w_lines[i].wl_size;
}
else
{
#ifdef FEAT_FOLDING
fold_count = foldedCount(wp, lnum, NULL);
if (fold_count)
{
lnum += fold_count;
if (lnum > wp->w_cursor.lnum)
break;
++wp->w_cline_row;
}
else
#endif
#ifdef FEAT_DIFF
if (lnum == wp->w_topline)
wp->w_cline_row += plines_win_nofill(wp, lnum++, TRUE)
+ wp->w_topfill;
else
#endif
wp->w_cline_row += plines_win(wp, lnum++, TRUE);
}
}
check_cursor_moved(wp);
if (!(wp->w_valid & VALID_CHEIGHT))
{
if (all_invalid
|| i == wp->w_lines_valid
|| (i < wp->w_lines_valid
&& (!wp->w_lines[i].wl_valid
|| wp->w_lines[i].wl_lnum != wp->w_cursor.lnum)))
{
#ifdef FEAT_DIFF
if (wp->w_cursor.lnum == wp->w_topline)
wp->w_cline_height = plines_win_nofill(wp, wp->w_cursor.lnum,
TRUE) + wp->w_topfill;
else
#endif
wp->w_cline_height = plines_win(wp, wp->w_cursor.lnum, TRUE);
#ifdef FEAT_FOLDING
wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum,
NULL, NULL, TRUE, NULL);
#endif
}
else if (i > wp->w_lines_valid)
{
/* a line that is too long to fit on the last screen line */
wp->w_cline_height = 0;
#ifdef FEAT_FOLDING
wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum,
NULL, NULL, TRUE, NULL);
#endif
}
else
{
wp->w_cline_height = wp->w_lines[i].wl_size;
#ifdef FEAT_FOLDING
wp->w_cline_folded = wp->w_lines[i].wl_folded;
#endif
}
}
wp->w_valid |= VALID_CROW|VALID_CHEIGHT;
/* validate botline too, if update_screen doesn't do it */
if (do_botline && all_invalid)
validate_botline_win(wp);
}
/*
* Validate curwin->w_virtcol only.
*/
void
validate_virtcol()
{
validate_virtcol_win(curwin);
}
/*
* Validate wp->w_virtcol only.
*/
void
validate_virtcol_win(wp)
win_T *wp;
{
check_cursor_moved(wp);
if (!(wp->w_valid & VALID_VIRTCOL))
{
getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
wp->w_valid |= VALID_VIRTCOL;
#ifdef FEAT_SYN_HL
if (wp->w_p_cuc
# ifdef FEAT_INS_EXPAND
&& !pum_visible()
# endif
)
redraw_win_later(wp, SOME_VALID);
#endif
}
}
/*
* Validate curwin->w_cline_height only.
*/
static void
validate_cheight()
{
check_cursor_moved(curwin);
if (!(curwin->w_valid & VALID_CHEIGHT))
{
#ifdef FEAT_DIFF
if (curwin->w_cursor.lnum == curwin->w_topline)
curwin->w_cline_height = plines_nofill(curwin->w_cursor.lnum)
+ curwin->w_topfill;
else
#endif
curwin->w_cline_height = plines(curwin->w_cursor.lnum);
#ifdef FEAT_FOLDING
curwin->w_cline_folded = hasFolding(curwin->w_cursor.lnum, NULL, NULL);
#endif
curwin->w_valid |= VALID_CHEIGHT;
}
}
/*
* Validate w_wcol and w_virtcol only.
*/
void
validate_cursor_col()
{
colnr_T off;
colnr_T col;
int width;
validate_virtcol();
if (!(curwin->w_valid & VALID_WCOL))
{
col = curwin->w_virtcol;
off = curwin_col_off();
col += off;
width = W_WIDTH(curwin) - off + curwin_col_off2();
/* long line wrapping, adjust curwin->w_wrow */
if (curwin->w_p_wrap
&& col >= (colnr_T)W_WIDTH(curwin)
&& width > 0)
/* use same formula as what is used in curs_columns() */
col -= ((col - W_WIDTH(curwin)) / width + 1) * width;
if (col > (int)curwin->w_leftcol)
col -= curwin->w_leftcol;
else
col = 0;
curwin->w_wcol = col;
curwin->w_valid |= VALID_WCOL;
}
}
/*
* Compute offset of a window, occupied by absolute or relative line number,
* fold column and sign column (these don't move when scrolling horizontally).
*/
int
win_col_off(wp)
win_T *wp;
{
return (((wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) + 1 : 0)
#ifdef FEAT_CMDWIN
+ (cmdwin_type == 0 || wp != curwin ? 0 : 1)
#endif
#ifdef FEAT_FOLDING
+ wp->w_p_fdc
#endif
#ifdef FEAT_SIGNS
+ (
# ifdef FEAT_NETBEANS_INTG
/* show glyph gutter in netbeans */
netbeans_active() ||
# endif
wp->w_buffer->b_signlist != NULL ? 2 : 0)
#endif
);
}
int
curwin_col_off()
{
return win_col_off(curwin);
}
/*
* Return the difference in column offset for the second screen line of a
* wrapped line. It's 8 if 'number' or 'relativenumber' is on and 'n' is in
* 'cpoptions'.
*/
int
win_col_off2(wp)
win_T *wp;
{
if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL)
return number_width(wp) + 1;
return 0;
}
int
curwin_col_off2()
{
return win_col_off2(curwin);
}
/*
* compute curwin->w_wcol and curwin->w_virtcol.
* Also updates curwin->w_wrow and curwin->w_cline_row.
* Also updates curwin->w_leftcol.
*/
void
curs_columns(may_scroll)
int may_scroll; /* when TRUE, may scroll horizontally */
{
int diff;
int extra; /* offset for first screen line */
int off_left, off_right;
int n;
int p_lines;
int width = 0;
int textwidth;
int new_leftcol;
colnr_T startcol;
colnr_T endcol;
colnr_T prev_skipcol;
/*
* First make sure that w_topline is valid (after moving the cursor).
*/
update_topline();
/*
* Next make sure that w_cline_row is valid.
*/
if (!(curwin->w_valid & VALID_CROW))
curs_rows(curwin, FALSE);
/*
* Compute the number of virtual columns.
*/
#ifdef FEAT_FOLDING
if (curwin->w_cline_folded)
/* In a folded line the cursor is always in the first column */
startcol = curwin->w_virtcol = endcol = curwin->w_leftcol;
else
#endif
getvvcol(curwin, &curwin->w_cursor,
&startcol, &(curwin->w_virtcol), &endcol);
/* remove '$' from change command when cursor moves onto it */
if (startcol > dollar_vcol)
dollar_vcol = -1;
extra = curwin_col_off();
curwin->w_wcol = curwin->w_virtcol + extra;
endcol += extra;
/*
* Now compute w_wrow, counting screen lines from w_cline_row.
*/
curwin->w_wrow = curwin->w_cline_row;
textwidth = W_WIDTH(curwin) - extra;
if (textwidth <= 0)
{
/* No room for text, put cursor in last char of window. */
curwin->w_wcol = W_WIDTH(curwin) - 1;
curwin->w_wrow = curwin->w_height - 1;
}
else if (curwin->w_p_wrap
#ifdef FEAT_VERTSPLIT
&& curwin->w_width != 0
#endif
)
{
width = textwidth + curwin_col_off2();
/* long line wrapping, adjust curwin->w_wrow */
if (curwin->w_wcol >= W_WIDTH(curwin))
{
/* this same formula is used in validate_cursor_col() */
n = (curwin->w_wcol - W_WIDTH(curwin)) / width + 1;
curwin->w_wcol -= n * width;
curwin->w_wrow += n;
#ifdef FEAT_LINEBREAK
/* When cursor wraps to first char of next line in Insert
* mode, the 'showbreak' string isn't shown, backup to first
* column */
if (*p_sbr && *ml_get_cursor() == NUL
&& curwin->w_wcol == (int)vim_strsize(p_sbr))
curwin->w_wcol = 0;
#endif
}
}
/* No line wrapping: compute curwin->w_leftcol if scrolling is on and line
* is not folded.
* If scrolling is off, curwin->w_leftcol is assumed to be 0 */
else if (may_scroll
#ifdef FEAT_FOLDING
&& !curwin->w_cline_folded
#endif
)
{
/*
* If Cursor is left of the screen, scroll rightwards.
* If Cursor is right of the screen, scroll leftwards
* If we get closer to the edge than 'sidescrolloff', scroll a little
* extra
*/
off_left = (int)startcol - (int)curwin->w_leftcol - p_siso;
off_right = (int)endcol - (int)(curwin->w_leftcol + W_WIDTH(curwin)
- p_siso) + 1;
if (off_left < 0 || off_right > 0)
{
if (off_left < 0)
diff = -off_left;
else
diff = off_right;
/* When far off or not enough room on either side, put cursor in
* middle of window. */
if (p_ss == 0 || diff >= textwidth / 2 || off_right >= off_left)
new_leftcol = curwin->w_wcol - extra - textwidth / 2;
else
{
if (diff < p_ss)
diff = p_ss;
if (off_left < 0)
new_leftcol = curwin->w_leftcol - diff;
else
new_leftcol = curwin->w_leftcol + diff;
}
if (new_leftcol < 0)
new_leftcol = 0;
if (new_leftcol != (int)curwin->w_leftcol)
{
curwin->w_leftcol = new_leftcol;
/* screen has to be redrawn with new curwin->w_leftcol */
redraw_later(NOT_VALID);
}
}
curwin->w_wcol -= curwin->w_leftcol;
}
else if (curwin->w_wcol > (int)curwin->w_leftcol)
curwin->w_wcol -= curwin->w_leftcol;
else
curwin->w_wcol = 0;
#ifdef FEAT_DIFF
/* Skip over filler lines. At the top use w_topfill, there
* may be some filler lines above the window. */
if (curwin->w_cursor.lnum == curwin->w_topline)
curwin->w_wrow += curwin->w_topfill;
else
curwin->w_wrow += diff_check_fill(curwin, curwin->w_cursor.lnum);
#endif
prev_skipcol = curwin->w_skipcol;
p_lines = 0;
if ((curwin->w_wrow >= curwin->w_height
|| ((prev_skipcol > 0
|| curwin->w_wrow + p_so >= curwin->w_height)
&& (p_lines =
#ifdef FEAT_DIFF
plines_win_nofill
#else
plines_win
#endif
(curwin, curwin->w_cursor.lnum, FALSE))
- 1 >= curwin->w_height))
&& curwin->w_height != 0
&& curwin->w_cursor.lnum == curwin->w_topline
&& width > 0
#ifdef FEAT_VERTSPLIT
&& curwin->w_width != 0
#endif
)
{
/* Cursor past end of screen. Happens with a single line that does
* not fit on screen. Find a skipcol to show the text around the
* cursor. Avoid scrolling all the time. compute value of "extra":
* 1: Less than "p_so" lines above
* 2: Less than "p_so" lines below
* 3: both of them */
extra = 0;
if (curwin->w_skipcol + p_so * width > curwin->w_virtcol)
extra = 1;
/* Compute last display line of the buffer line that we want at the
* bottom of the window. */
if (p_lines == 0)
p_lines = plines_win(curwin, curwin->w_cursor.lnum, FALSE);
--p_lines;
if (p_lines > curwin->w_wrow + p_so)
n = curwin->w_wrow + p_so;
else
n = p_lines;
if ((colnr_T)n >= curwin->w_height + curwin->w_skipcol / width)
extra += 2;
if (extra == 3 || p_lines < p_so * 2)
{
/* not enough room for 'scrolloff', put cursor in the middle */
n = curwin->w_virtcol / width;
if (n > curwin->w_height / 2)
n -= curwin->w_height / 2;
else
n = 0;
/* don't skip more than necessary */
if (n > p_lines - curwin->w_height + 1)
n = p_lines - curwin->w_height + 1;
curwin->w_skipcol = n * width;
}
else if (extra == 1)
{
/* less then 'scrolloff' lines above, decrease skipcol */
extra = (curwin->w_skipcol + p_so * width - curwin->w_virtcol
+ width - 1) / width;
if (extra > 0)
{
if ((colnr_T)(extra * width) > curwin->w_skipcol)
extra = curwin->w_skipcol / width;
curwin->w_skipcol -= extra * width;
}
}
else if (extra == 2)
{
/* less then 'scrolloff' lines below, increase skipcol */
endcol = (n - curwin->w_height + 1) * width;
while (endcol > curwin->w_virtcol)
endcol -= width;
if (endcol > curwin->w_skipcol)
curwin->w_skipcol = endcol;
}
curwin->w_wrow -= curwin->w_skipcol / width;
if (curwin->w_wrow >= curwin->w_height)
{
/* small window, make sure cursor is in it */
extra = curwin->w_wrow - curwin->w_height + 1;
curwin->w_skipcol += extra * width;
curwin->w_wrow -= extra;
}
extra = ((int)prev_skipcol - (int)curwin->w_skipcol) / width;
if (extra > 0)
win_ins_lines(curwin, 0, extra, FALSE, FALSE);
else if (extra < 0)
win_del_lines(curwin, 0, -extra, FALSE, FALSE);
}
else
curwin->w_skipcol = 0;
if (prev_skipcol != curwin->w_skipcol)
redraw_later(NOT_VALID);
/* Redraw when w_row changes and 'relativenumber' is set */
if (((curwin->w_valid & VALID_WROW) == 0 && (curwin->w_p_rnu
#ifdef FEAT_SYN_HL
/* or when w_row changes and 'cursorline' is set. */
|| curwin->w_p_cul
#endif
))
#ifdef FEAT_SYN_HL
/* or when w_virtcol changes and 'cursorcolumn' is set */
|| (curwin->w_p_cuc && (curwin->w_valid & VALID_VIRTCOL) == 0)
#endif
)
# ifdef FEAT_INS_EXPAND
if (!pum_visible())
# endif
redraw_later(SOME_VALID);
curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
}
/*
* Scroll the current window down by "line_count" logical lines. "CTRL-Y"
*/
void
scrolldown(line_count, byfold)
long line_count;
int byfold UNUSED; /* TRUE: count a closed fold as one line */
{
long done = 0; /* total # of physical lines done */
int wrow;
int moved = FALSE;
#ifdef FEAT_FOLDING
linenr_T first;
/* Make sure w_topline is at the first of a sequence of folded lines. */
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
#endif
validate_cursor(); /* w_wrow needs to be valid */
while (line_count-- > 0)
{
#ifdef FEAT_DIFF
if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)
&& curwin->w_topfill < curwin->w_height - 1)
{
++curwin->w_topfill;
++done;
}
else
#endif
{
if (curwin->w_topline == 1)
break;
--curwin->w_topline;
#ifdef FEAT_DIFF
curwin->w_topfill = 0;
#endif
#ifdef FEAT_FOLDING
/* A sequence of folded lines only counts for one logical line */
if (hasFolding(curwin->w_topline, &first, NULL))
{
++done;
if (!byfold)
line_count -= curwin->w_topline - first - 1;
curwin->w_botline -= curwin->w_topline - first;
curwin->w_topline = first;
}
else
#endif
#ifdef FEAT_DIFF
done += plines_nofill(curwin->w_topline);
#else
done += plines(curwin->w_topline);
#endif
}
--curwin->w_botline; /* approximate w_botline */
invalidate_botline();
}
curwin->w_wrow += done; /* keep w_wrow updated */
curwin->w_cline_row += done; /* keep w_cline_row updated */
#ifdef FEAT_DIFF
if (curwin->w_cursor.lnum == curwin->w_topline)
curwin->w_cline_row = 0;
check_topfill(curwin, TRUE);
#endif
/*
* Compute the row number of the last row of the cursor line
* and move the cursor onto the displayed part of the window.
*/
wrow = curwin->w_wrow;
if (curwin->w_p_wrap
#ifdef FEAT_VERTSPLIT
&& curwin->w_width != 0
#endif
)
{
validate_virtcol();
validate_cheight();
wrow += curwin->w_cline_height - 1 -
curwin->w_virtcol / W_WIDTH(curwin);
}
while (wrow >= curwin->w_height && curwin->w_cursor.lnum > 1)
{
#ifdef FEAT_FOLDING
if (hasFolding(curwin->w_cursor.lnum, &first, NULL))
{
--wrow;
if (first == 1)
curwin->w_cursor.lnum = 1;
else
curwin->w_cursor.lnum = first - 1;
}
else
#endif
wrow -= plines(curwin->w_cursor.lnum--);
curwin->w_valid &=
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
moved = TRUE;
}
if (moved)
{
#ifdef FEAT_FOLDING
/* Move cursor to first line of closed fold. */
foldAdjustCursor();
#endif
coladvance(curwin->w_curswant);
}
}
/*
* Scroll the current window up by "line_count" logical lines. "CTRL-E"
*/
void
scrollup(line_count, byfold)
long line_count;
int byfold UNUSED; /* TRUE: count a closed fold as one line */
{
#if defined(FEAT_FOLDING) || defined(FEAT_DIFF)
linenr_T lnum;
if (
# ifdef FEAT_FOLDING
(byfold && hasAnyFolding(curwin))
# ifdef FEAT_DIFF
||
# endif
# endif
# ifdef FEAT_DIFF
curwin->w_p_diff
# endif
)
{
/* count each sequence of folded lines as one logical line */
lnum = curwin->w_topline;
while (line_count--)
{
# ifdef FEAT_DIFF
if (curwin->w_topfill > 0)
--curwin->w_topfill;
else
# endif
{
# ifdef FEAT_FOLDING
if (byfold)
(void)hasFolding(lnum, NULL, &lnum);
# endif
if (lnum >= curbuf->b_ml.ml_line_count)
break;
++lnum;
# ifdef FEAT_DIFF
curwin->w_topfill = diff_check_fill(curwin, lnum);
# endif
}
}
/* approximate w_botline */
curwin->w_botline += lnum - curwin->w_topline;
curwin->w_topline = lnum;
}
else
#endif
{
curwin->w_topline += line_count;
curwin->w_botline += line_count; /* approximate w_botline */
}
if (curwin->w_topline > curbuf->b_ml.ml_line_count)
curwin->w_topline = curbuf->b_ml.ml_line_count;
if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1)
curwin->w_botline = curbuf->b_ml.ml_line_count + 1;
#ifdef FEAT_DIFF
check_topfill(curwin, FALSE);
#endif
#ifdef FEAT_FOLDING
if (hasAnyFolding(curwin))
/* Make sure w_topline is at the first of a sequence of folded lines. */
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
#endif
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
if (curwin->w_cursor.lnum < curwin->w_topline)
{
curwin->w_cursor.lnum = curwin->w_topline;
curwin->w_valid &=
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
coladvance(curwin->w_curswant);
}
}
#ifdef FEAT_DIFF
/*
* Don't end up with too many filler lines in the window.
*/
void
check_topfill(wp, down)
win_T *wp;
int down; /* when TRUE scroll down when not enough space */
{
int n;
if (wp->w_topfill > 0)
{
n = plines_win_nofill(wp, wp->w_topline, TRUE);
if (wp->w_topfill + n > wp->w_height)
{
if (down && wp->w_topline > 1)
{
--wp->w_topline;
wp->w_topfill = 0;
}
else
{
wp->w_topfill = wp->w_height - n;
if (wp->w_topfill < 0)
wp->w_topfill = 0;
}
}
}
}
/*
* Use as many filler lines as possible for w_topline. Make sure w_topline
* is still visible.
*/
static void
max_topfill()
{
int n;
n = plines_nofill(curwin->w_topline);
if (n >= curwin->w_height)
curwin->w_topfill = 0;
else
{
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
if (curwin->w_topfill + n > curwin->w_height)
curwin->w_topfill = curwin->w_height - n;
}
}
#endif
#if defined(FEAT_INS_EXPAND) || defined(PROTO)
/*
* Scroll the screen one line down, but don't do it if it would move the
* cursor off the screen.
*/
void
scrolldown_clamp()
{
int end_row;
#ifdef FEAT_DIFF
int can_fill = (curwin->w_topfill
< diff_check_fill(curwin, curwin->w_topline));
#endif
if (curwin->w_topline <= 1
#ifdef FEAT_DIFF
&& !can_fill
#endif
)
return;
validate_cursor(); /* w_wrow needs to be valid */
/*
* Compute the row number of the last row of the cursor line
* and make sure it doesn't go off the screen. Make sure the cursor
* doesn't go past 'scrolloff' lines from the screen end.
*/
end_row = curwin->w_wrow;
#ifdef FEAT_DIFF
if (can_fill)
++end_row;
else
end_row += plines_nofill(curwin->w_topline - 1);
#else
end_row += plines(curwin->w_topline - 1);
#endif
if (curwin->w_p_wrap
#ifdef FEAT_VERTSPLIT
&& curwin->w_width != 0
#endif
)
{
validate_cheight();
validate_virtcol();
end_row += curwin->w_cline_height - 1 -
curwin->w_virtcol / W_WIDTH(curwin);
}
if (end_row < curwin->w_height - p_so)
{
#ifdef FEAT_DIFF
if (can_fill)
{
++curwin->w_topfill;
check_topfill(curwin, TRUE);
}
else
{
--curwin->w_topline;
curwin->w_topfill = 0;
}
#else
--curwin->w_topline;
#endif
#ifdef FEAT_FOLDING
hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
#endif
--curwin->w_botline; /* approximate w_botline */
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
}
}
/*
* Scroll the screen one line up, but don't do it if it would move the cursor
* off the screen.
*/
void
scrollup_clamp()
{
int start_row;
if (curwin->w_topline == curbuf->b_ml.ml_line_count
#ifdef FEAT_DIFF
&& curwin->w_topfill == 0
#endif
)
return;
validate_cursor(); /* w_wrow needs to be valid */
/*
* Compute the row number of the first row of the cursor line
* and make sure it doesn't go off the screen. Make sure the cursor
* doesn't go before 'scrolloff' lines from the screen start.
*/
#ifdef FEAT_DIFF
start_row = curwin->w_wrow - plines_nofill(curwin->w_topline)
- curwin->w_topfill;
#else
start_row = curwin->w_wrow - plines(curwin->w_topline);
#endif
if (curwin->w_p_wrap
#ifdef FEAT_VERTSPLIT
&& curwin->w_width != 0
#endif
)
{
validate_virtcol();
start_row -= curwin->w_virtcol / W_WIDTH(curwin);
}
if (start_row >= p_so)
{
#ifdef FEAT_DIFF
if (curwin->w_topfill > 0)
--curwin->w_topfill;
else
#endif
{
#ifdef FEAT_FOLDING
(void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline);
#endif
++curwin->w_topline;
}
++curwin->w_botline; /* approximate w_botline */
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
}
}
#endif /* FEAT_INS_EXPAND */
/*
* Add one line above "lp->lnum". This can be a filler line, a closed fold or
* a (wrapped) text line. Uses and sets "lp->fill".
* Returns the height of the added line in "lp->height".
* Lines above the first one are incredibly high: MAXCOL.
*/
static void
topline_back(lp)
lineoff_T *lp;
{
#ifdef FEAT_DIFF
if (lp->fill < diff_check_fill(curwin, lp->lnum))
{
/* Add a filler line. */
++lp->fill;
lp->height = 1;
}
else
#endif
{
--lp->lnum;
#ifdef FEAT_DIFF
lp->fill = 0;
#endif
if (lp->lnum < 1)
lp->height = MAXCOL;
else
#ifdef FEAT_FOLDING
if (hasFolding(lp->lnum, &lp->lnum, NULL))
/* Add a closed fold */
lp->height = 1;
else
#endif
{
#ifdef FEAT_DIFF
lp->height = plines_nofill(lp->lnum);
#else
lp->height = plines(lp->lnum);
#endif
}
}
}
/*
* Add one line below "lp->lnum". This can be a filler line, a closed fold or
* a (wrapped) text line. Uses and sets "lp->fill".
* Returns the height of the added line in "lp->height".
* Lines below the last one are incredibly high.
*/
static void
botline_forw(lp)
lineoff_T *lp;
{
#ifdef FEAT_DIFF
if (lp->fill < diff_check_fill(curwin, lp->lnum + 1))
{
/* Add a filler line. */
++lp->fill;
lp->height = 1;
}
else
#endif
{
++lp->lnum;
#ifdef FEAT_DIFF
lp->fill = 0;
#endif
if (lp->lnum > curbuf->b_ml.ml_line_count)
lp->height = MAXCOL;
else
#ifdef FEAT_FOLDING
if (hasFolding(lp->lnum, NULL, &lp->lnum))
/* Add a closed fold */
lp->height = 1;
else
#endif
{
#ifdef FEAT_DIFF
lp->height = plines_nofill(lp->lnum);
#else
lp->height = plines(lp->lnum);
#endif
}
}
}
#ifdef FEAT_DIFF
/*
* Switch from including filler lines below lp->lnum to including filler
* lines above loff.lnum + 1. This keeps pointing to the same line.
* When there are no filler lines nothing changes.
*/
static void
botline_topline(lp)
lineoff_T *lp;
{
if (lp->fill > 0)
{
++lp->lnum;
lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1;
}
}
/*
* Switch from including filler lines above lp->lnum to including filler
* lines below loff.lnum - 1. This keeps pointing to the same line.
* When there are no filler lines nothing changes.
*/
static void
topline_botline(lp)
lineoff_T *lp;
{
if (lp->fill > 0)
{
lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1;
--lp->lnum;
}
}
#endif
/*
* Recompute topline to put the cursor at the top of the window.
* Scroll at least "min_scroll" lines.
* If "always" is TRUE, always set topline (for "zt").
*/
void
scroll_cursor_top(min_scroll, always)
int min_scroll;
int always;
{
int scrolled = 0;
int extra = 0;
int used;
int i;
linenr_T top; /* just above displayed lines */
linenr_T bot; /* just below displayed lines */
linenr_T old_topline = curwin->w_topline;
#ifdef FEAT_DIFF
linenr_T old_topfill = curwin->w_topfill;
#endif
linenr_T new_topline;
int off = p_so;
#ifdef FEAT_MOUSE
if (mouse_dragging > 0)
off = mouse_dragging - 1;
#endif
/*
* Decrease topline until:
* - it has become 1
* - (part of) the cursor line is moved off the screen or
* - moved at least 'scrolljump' lines and
* - at least 'scrolloff' lines above and below the cursor
*/
validate_cheight();
used = curwin->w_cline_height;
if (curwin->w_cursor.lnum < curwin->w_topline)
scrolled = used;
#ifdef FEAT_FOLDING
if (hasFolding(curwin->w_cursor.lnum, &top, &bot))
{
--top;
++bot;
}
else
#endif
{
top = curwin->w_cursor.lnum - 1;
bot = curwin->w_cursor.lnum + 1;
}
new_topline = top + 1;
#ifdef FEAT_DIFF
/* count filler lines of the cursor window as context */
i = diff_check_fill(curwin, curwin->w_cursor.lnum);
used += i;
extra += i;
#endif
/*
* Check if the lines from "top" to "bot" fit in the window. If they do,
* set new_topline and advance "top" and "bot" to include more lines.
*/
while (top > 0)
{
#ifdef FEAT_FOLDING
if (hasFolding(top, &top, NULL))
/* count one logical line for a sequence of folded lines */
i = 1;
else
#endif
i = plines(top);
used += i;
if (extra + i <= off && bot < curbuf->b_ml.ml_line_count)
{
#ifdef FEAT_FOLDING
if (hasFolding(bot, NULL, &bot))
/* count one logical line for a sequence of folded lines */
++used;
else
#endif
used += plines(bot);
}
if (used > curwin->w_height)
break;
if (top < curwin->w_topline)
scrolled += i;
/*
* If scrolling is needed, scroll at least 'sj' lines.
*/
if ((new_topline >= curwin->w_topline || scrolled > min_scroll)
&& extra >= off)
break;
extra += i;
new_topline = top;
--top;
++bot;
}
/*
* If we don't have enough space, put cursor in the middle.
* This makes sure we get the same position when using "k" and "j"
* in a small window.
*/
if (used > curwin->w_height)
scroll_cursor_halfway(FALSE);
else
{
/*
* If "always" is FALSE, only adjust topline to a lower value, higher
* value may happen with wrapping lines
*/
if (new_topline < curwin->w_topline || always)
curwin->w_topline = new_topline;
if (curwin->w_topline > curwin->w_cursor.lnum)
curwin->w_topline = curwin->w_cursor.lnum;
#ifdef FEAT_DIFF
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
if (curwin->w_topfill > 0 && extra > off)
{
curwin->w_topfill -= extra - off;
if (curwin->w_topfill < 0)
curwin->w_topfill = 0;
}
check_topfill(curwin, FALSE);
#endif
if (curwin->w_topline != old_topline
#ifdef FEAT_DIFF
|| curwin->w_topfill != old_topfill
#endif
)
curwin->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
curwin->w_valid |= VALID_TOPLINE;
}
}
/*
* Set w_empty_rows and w_filler_rows for window "wp", having used up "used"
* screen lines for text lines.
*/
void
set_empty_rows(wp, used)
win_T *wp;
int used;
{
#ifdef FEAT_DIFF
wp->w_filler_rows = 0;
#endif
if (used == 0)
wp->w_empty_rows = 0; /* single line that doesn't fit */
else
{
wp->w_empty_rows = wp->w_height - used;
#ifdef FEAT_DIFF
if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count)
{
wp->w_filler_rows = diff_check_fill(wp, wp->w_botline);
if (wp->w_empty_rows > wp->w_filler_rows)
wp->w_empty_rows -= wp->w_filler_rows;
else
{
wp->w_filler_rows = wp->w_empty_rows;
wp->w_empty_rows = 0;
}
}
#endif
}
}
/*
* Recompute topline to put the cursor at the bottom of the window.
* Scroll at least "min_scroll" lines.
* If "set_topbot" is TRUE, set topline and botline first (for "zb").
* This is messy stuff!!!
*/
void
scroll_cursor_bot(min_scroll, set_topbot)
int min_scroll;
int set_topbot;
{
int used;
int scrolled = 0;
int extra = 0;
int i;
linenr_T line_count;
linenr_T old_topline = curwin->w_topline;
lineoff_T loff;
lineoff_T boff;
#ifdef FEAT_DIFF
int old_topfill = curwin->w_topfill;
int fill_below_window;
#endif
linenr_T old_botline = curwin->w_botline;
linenr_T old_valid = curwin->w_valid;
int old_empty_rows = curwin->w_empty_rows;
linenr_T cln; /* Cursor Line Number */
cln = curwin->w_cursor.lnum;
if (set_topbot)
{
used = 0;
curwin->w_botline = cln + 1;
#ifdef FEAT_DIFF
loff.fill = 0;
#endif
for (curwin->w_topline = curwin->w_botline;
curwin->w_topline > 1;
curwin->w_topline = loff.lnum)
{
loff.lnum = curwin->w_topline;
topline_back(&loff);
if (loff.height == MAXCOL || used + loff.height > curwin->w_height)
break;
used += loff.height;
#ifdef FEAT_DIFF
curwin->w_topfill = loff.fill;
#endif
}
set_empty_rows(curwin, used);
curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
if (curwin->w_topline != old_topline
#ifdef FEAT_DIFF
|| curwin->w_topfill != old_topfill
#endif
)
curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
}
else
validate_botline();
/* The lines of the cursor line itself are always used. */
#ifdef FEAT_DIFF
used = plines_nofill(cln);
#else
validate_cheight();
used = curwin->w_cline_height;
#endif
/* If the cursor is below botline, we will at least scroll by the height
* of the cursor line. Correct for empty lines, which are really part of
* botline. */
if (cln >= curwin->w_botline)
{
scrolled = used;
if (cln == curwin->w_botline)
scrolled -= curwin->w_empty_rows;
}
/*
* Stop counting lines to scroll when
* - hitting start of the file
* - scrolled nothing or at least 'sj' lines
* - at least 'so' lines below the cursor
* - lines between botline and cursor have been counted
*/
#ifdef FEAT_FOLDING
if (!hasFolding(curwin->w_cursor.lnum, &loff.lnum, &boff.lnum))
#endif
{
loff.lnum = cln;
boff.lnum = cln;
}
#ifdef FEAT_DIFF
loff.fill = 0;
boff.fill = 0;
fill_below_window = diff_check_fill(curwin, curwin->w_botline)
- curwin->w_filler_rows;
#endif
while (loff.lnum > 1)
{
/* Stop when scrolled nothing or at least "min_scroll", found "extra"
* context for 'scrolloff' and counted all lines below the window. */
if ((((scrolled <= 0 || scrolled >= min_scroll)
&& extra >= (
#ifdef FEAT_MOUSE
mouse_dragging > 0 ? mouse_dragging - 1 :
#endif
p_so))
|| boff.lnum + 1 > curbuf->b_ml.ml_line_count)
&& loff.lnum <= curwin->w_botline
#ifdef FEAT_DIFF
&& (loff.lnum < curwin->w_botline
|| loff.fill >= fill_below_window)
#endif
)
break;
/* Add one line above */
topline_back(&loff);
if (loff.height == MAXCOL)
used = MAXCOL;
else
used += loff.height;
if (used > curwin->w_height)
break;
if (loff.lnum >= curwin->w_botline
#ifdef FEAT_DIFF
&& (loff.lnum > curwin->w_botline
|| loff.fill <= fill_below_window)
#endif
)
{
/* Count screen lines that are below the window. */
scrolled += loff.height;
if (loff.lnum == curwin->w_botline
#ifdef FEAT_DIFF
&& boff.fill == 0
#endif
)
scrolled -= curwin->w_empty_rows;
}
if (boff.lnum < curbuf->b_ml.ml_line_count)
{
/* Add one line below */
botline_forw(&boff);
used += boff.height;
if (used > curwin->w_height)
break;
if (extra < (
#ifdef FEAT_MOUSE
mouse_dragging > 0 ? mouse_dragging - 1 :
#endif
p_so) || scrolled < min_scroll)
{
extra += boff.height;
if (boff.lnum >= curwin->w_botline
#ifdef FEAT_DIFF
|| (boff.lnum + 1 == curwin->w_botline
&& boff.fill > curwin->w_filler_rows)
#endif
)
{
/* Count screen lines that are below the window. */
scrolled += boff.height;
if (boff.lnum == curwin->w_botline
#ifdef FEAT_DIFF
&& boff.fill == 0
#endif
)
scrolled -= curwin->w_empty_rows;
}
}
}
}
/* curwin->w_empty_rows is larger, no need to scroll */
if (scrolled <= 0)
line_count = 0;
/* more than a screenfull, don't scroll but redraw */
else if (used > curwin->w_height)
line_count = used;
/* scroll minimal number of lines */
else
{
line_count = 0;
#ifdef FEAT_DIFF
boff.fill = curwin->w_topfill;
#endif
boff.lnum = curwin->w_topline - 1;
for (i = 0; i < scrolled && boff.lnum < curwin->w_botline; )
{
botline_forw(&boff);
i += boff.height;
++line_count;
}
if (i < scrolled) /* below curwin->w_botline, don't scroll */
line_count = 9999;
}
/*
* Scroll up if the cursor is off the bottom of the screen a bit.
* Otherwise put it at 1/2 of the screen.
*/
if (line_count >= curwin->w_height && line_count > min_scroll)
scroll_cursor_halfway(FALSE);
else
scrollup(line_count, TRUE);
/*
* If topline didn't change we need to restore w_botline and w_empty_rows
* (we changed them).
* If topline did change, update_screen() will set botline.
*/
if (curwin->w_topline == old_topline && set_topbot)
{
curwin->w_botline = old_botline;
curwin->w_empty_rows = old_empty_rows;
curwin->w_valid = old_valid;
}
curwin->w_valid |= VALID_TOPLINE;
}
/*
* Recompute topline to put the cursor halfway the window
* If "atend" is TRUE, also put it halfway at the end of the file.
*/
void
scroll_cursor_halfway(atend)
int atend;
{
int above = 0;
linenr_T topline;
#ifdef FEAT_DIFF
int topfill = 0;
#endif
int below = 0;
int used;
lineoff_T loff;
lineoff_T boff;
loff.lnum = boff.lnum = curwin->w_cursor.lnum;
#ifdef FEAT_FOLDING
(void)hasFolding(loff.lnum, &loff.lnum, &boff.lnum);
#endif
#ifdef FEAT_DIFF
used = plines_nofill(loff.lnum);
loff.fill = 0;
boff.fill = 0;
#else
used = plines(loff.lnum);
#endif
topline = loff.lnum;
while (topline > 1)
{
if (below <= above) /* add a line below the cursor first */
{
if (boff.lnum < curbuf->b_ml.ml_line_count)
{
botline_forw(&boff);
used += boff.height;
if (used > curwin->w_height)
break;
below += boff.height;
}
else
{
++below; /* count a "~" line */
if (atend)
++used;
}
}
if (below > above) /* add a line above the cursor */
{
topline_back(&loff);
if (loff.height == MAXCOL)
used = MAXCOL;
else
used += loff.height;
if (used > curwin->w_height)
break;
above += loff.height;
topline = loff.lnum;
#ifdef FEAT_DIFF
topfill = loff.fill;
#endif
}
}
#ifdef FEAT_FOLDING
if (!hasFolding(topline, &curwin->w_topline, NULL))
#endif
curwin->w_topline = topline;
#ifdef FEAT_DIFF
curwin->w_topfill = topfill;
check_topfill(curwin, FALSE);
#endif
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
curwin->w_valid |= VALID_TOPLINE;
}
/*
* Correct the cursor position so that it is in a part of the screen at least
* 'so' lines from the top and bottom, if possible.
* If not possible, put it at the same position as scroll_cursor_halfway().
* When called topline must be valid!
*/
void
cursor_correct()
{
int above = 0; /* screen lines above topline */
linenr_T topline;
int below = 0; /* screen lines below botline */
linenr_T botline;
int above_wanted, below_wanted;
linenr_T cln; /* Cursor Line Number */
int max_off;
/*
* How many lines we would like to have above/below the cursor depends on
* whether the first/last line of the file is on screen.
*/
above_wanted = p_so;
below_wanted = p_so;
#ifdef FEAT_MOUSE
if (mouse_dragging > 0)
{
above_wanted = mouse_dragging - 1;
below_wanted = mouse_dragging - 1;
}
#endif
if (curwin->w_topline == 1)
{
above_wanted = 0;
max_off = curwin->w_height / 2;
if (below_wanted > max_off)
below_wanted = max_off;
}
validate_botline();
if (curwin->w_botline == curbuf->b_ml.ml_line_count + 1
#ifdef FEAT_MOUSE
&& mouse_dragging == 0
#endif
)
{
below_wanted = 0;
max_off = (curwin->w_height - 1) / 2;
if (above_wanted > max_off)
above_wanted = max_off;
}
/*
* If there are sufficient file-lines above and below the cursor, we can
* return now.
*/
cln = curwin->w_cursor.lnum;
if (cln >= curwin->w_topline + above_wanted
&& cln < curwin->w_botline - below_wanted
#ifdef FEAT_FOLDING
&& !hasAnyFolding(curwin)
#endif
)
return;
/*
* Narrow down the area where the cursor can be put by taking lines from
* the top and the bottom until:
* - the desired context lines are found
* - the lines from the top is past the lines from the bottom
*/
topline = curwin->w_topline;
botline = curwin->w_botline - 1;
#ifdef FEAT_DIFF
/* count filler lines as context */
above = curwin->w_topfill;
below = curwin->w_filler_rows;
#endif
while ((above < above_wanted || below < below_wanted) && topline < botline)
{
if (below < below_wanted && (below <= above || above >= above_wanted))
{
#ifdef FEAT_FOLDING
if (hasFolding(botline, &botline, NULL))
++below;
else
#endif
below += plines(botline);
--botline;
}
if (above < above_wanted && (above < below || below >= below_wanted))
{
#ifdef FEAT_FOLDING
if (hasFolding(topline, NULL, &topline))
++above;
else
#endif
#ifndef FEAT_DIFF
above += plines(topline);
#else
above += plines_nofill(topline);
/* Count filler lines below this line as context. */
if (topline < botline)
above += diff_check_fill(curwin, topline + 1);
#endif
++topline;
}
}
if (topline == botline || botline == 0)
curwin->w_cursor.lnum = topline;
else if (topline > botline)
curwin->w_cursor.lnum = botline;
else
{
if (cln < topline && curwin->w_topline > 1)
{
curwin->w_cursor.lnum = topline;
curwin->w_valid &=
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW);
}
if (cln > botline && curwin->w_botline <= curbuf->b_ml.ml_line_count)
{
curwin->w_cursor.lnum = botline;
curwin->w_valid &=
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW);
}
}
curwin->w_valid |= VALID_TOPLINE;
}
static void get_scroll_overlap __ARGS((lineoff_T *lp, int dir));
/*
* move screen 'count' pages up or down and update screen
*
* return FAIL for failure, OK otherwise
*/
int
onepage(dir, count)
int dir;
long count;
{
long n;
int retval = OK;
lineoff_T loff;
linenr_T old_topline = curwin->w_topline;
if (curbuf->b_ml.ml_line_count == 1) /* nothing to do */
{
beep_flush();
return FAIL;
}
for ( ; count > 0; --count)
{
validate_botline();
/*
* It's an error to move a page up when the first line is already on
* the screen. It's an error to move a page down when the last line
* is on the screen and the topline is 'scrolloff' lines from the
* last line.
*/
if (dir == FORWARD
? ((curwin->w_topline >= curbuf->b_ml.ml_line_count - p_so)
&& curwin->w_botline > curbuf->b_ml.ml_line_count)
: (curwin->w_topline == 1
#ifdef FEAT_DIFF
&& curwin->w_topfill ==
diff_check_fill(curwin, curwin->w_topline)
#endif
))
{
beep_flush();
retval = FAIL;
break;
}
#ifdef FEAT_DIFF
loff.fill = 0;
#endif
if (dir == FORWARD)
{
if (firstwin == lastwin && p_window > 0 && p_window < Rows - 1)
{
/* Vi compatible scrolling */
if (p_window <= 2)
++curwin->w_topline;
else
curwin->w_topline += p_window - 2;
if (curwin->w_topline > curbuf->b_ml.ml_line_count)
curwin->w_topline = curbuf->b_ml.ml_line_count;
curwin->w_cursor.lnum = curwin->w_topline;
}
else if (curwin->w_botline > curbuf->b_ml.ml_line_count)
{
/* at end of file */
curwin->w_topline = curbuf->b_ml.ml_line_count;
#ifdef FEAT_DIFF
curwin->w_topfill = 0;
#endif
curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
}
else
{
/* For the overlap, start with the line just below the window
* and go upwards. */
loff.lnum = curwin->w_botline;
#ifdef FEAT_DIFF
loff.fill = diff_check_fill(curwin, loff.lnum)
- curwin->w_filler_rows;
#endif
get_scroll_overlap(&loff, -1);
curwin->w_topline = loff.lnum;
#ifdef FEAT_DIFF
curwin->w_topfill = loff.fill;
check_topfill(curwin, FALSE);
#endif
curwin->w_cursor.lnum = curwin->w_topline;
curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW|
VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
}
}
else /* dir == BACKWARDS */
{
#ifdef FEAT_DIFF
if (curwin->w_topline == 1)
{
/* Include max number of filler lines */
max_topfill();
continue;
}
#endif
if (firstwin == lastwin && p_window > 0 && p_window < Rows - 1)
{
/* Vi compatible scrolling (sort of) */
if (p_window <= 2)
--curwin->w_topline;
else
curwin->w_topline -= p_window - 2;
if (curwin->w_topline < 1)
curwin->w_topline = 1;
curwin->w_cursor.lnum = curwin->w_topline + p_window - 1;
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
continue;
}
/* Find the line at the top of the window that is going to be the
* line at the bottom of the window. Make sure this results in
* the same line as before doing CTRL-F. */
loff.lnum = curwin->w_topline - 1;
#ifdef FEAT_DIFF
loff.fill = diff_check_fill(curwin, loff.lnum + 1)
- curwin->w_topfill;
#endif
get_scroll_overlap(&loff, 1);
if (loff.lnum >= curbuf->b_ml.ml_line_count)
{
loff.lnum = curbuf->b_ml.ml_line_count;
#ifdef FEAT_DIFF
loff.fill = 0;
}
else
{
botline_topline(&loff);
#endif
}
curwin->w_cursor.lnum = loff.lnum;
/* Find the line just above the new topline to get the right line
* at the bottom of the window. */
n = 0;
while (n <= curwin->w_height && loff.lnum >= 1)
{
topline_back(&loff);
if (loff.height == MAXCOL)
n = MAXCOL;
else
n += loff.height;
}
if (loff.lnum < 1) /* at begin of file */
{
curwin->w_topline = 1;
#ifdef FEAT_DIFF
max_topfill();
#endif
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
}
else
{
/* Go two lines forward again. */
#ifdef FEAT_DIFF
topline_botline(&loff);
#endif
botline_forw(&loff);
botline_forw(&loff);
#ifdef FEAT_DIFF
botline_topline(&loff);
#endif
#ifdef FEAT_FOLDING
/* We're at the wrong end of a fold now. */
(void)hasFolding(loff.lnum, &loff.lnum, NULL);
#endif
/* Always scroll at least one line. Avoid getting stuck on
* very long lines. */
if (loff.lnum >= curwin->w_topline
#ifdef FEAT_DIFF
&& (loff.lnum > curwin->w_topline
|| loff.fill >= curwin->w_topfill)
#endif
)
{
#ifdef FEAT_DIFF
/* First try using the maximum number of filler lines. If
* that's not enough, backup one line. */
loff.fill = curwin->w_topfill;
if (curwin->w_topfill < diff_check_fill(curwin,
curwin->w_topline))
max_topfill();
if (curwin->w_topfill == loff.fill)
#endif
{
--curwin->w_topline;
#ifdef FEAT_DIFF
curwin->w_topfill = 0;
#endif
}
comp_botline(curwin);
curwin->w_cursor.lnum = curwin->w_botline - 1;
curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|
VALID_WROW|VALID_CROW);
}
else
{
curwin->w_topline = loff.lnum;
#ifdef FEAT_DIFF
curwin->w_topfill = loff.fill;
check_topfill(curwin, FALSE);
#endif
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
}
}
}
}
#ifdef FEAT_FOLDING
foldAdjustCursor();
#endif
cursor_correct();
if (retval == OK)
beginline(BL_SOL | BL_FIX);
curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL);
/*
* Avoid the screen jumping up and down when 'scrolloff' is non-zero.
* But make sure we scroll at least one line (happens with mix of long
* wrapping lines and non-wrapping line).
*/
if (retval == OK && dir == FORWARD && check_top_offset())
{
scroll_cursor_top(1, FALSE);
if (curwin->w_topline <= old_topline
&& old_topline < curbuf->b_ml.ml_line_count)
{
curwin->w_topline = old_topline + 1;
#ifdef FEAT_FOLDING
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
#endif
}
}
redraw_later(VALID);
return retval;
}
/*
* Decide how much overlap to use for page-up or page-down scrolling.
* This is symmetric, so that doing both keeps the same lines displayed.
* Three lines are examined:
*
* before CTRL-F after CTRL-F / before CTRL-B
* etc. l1
* l1 last but one line ------------
* l2 last text line l2 top text line
* ------------- l3 second text line
* l3 etc.
*/
static void
get_scroll_overlap(lp, dir)
lineoff_T *lp;
int dir;
{
int h1, h2, h3, h4;
int min_height = curwin->w_height - 2;
lineoff_T loff0, loff1, loff2;
#ifdef FEAT_DIFF
if (lp->fill > 0)
lp->height = 1;
else
lp->height = plines_nofill(lp->lnum);
#else
lp->height = plines(lp->lnum);
#endif
h1 = lp->height;
if (h1 > min_height)
return; /* no overlap */
loff0 = *lp;
if (dir > 0)
botline_forw(lp);
else
topline_back(lp);
h2 = lp->height;
if (h2 + h1 > min_height)
{
*lp = loff0; /* no overlap */
return;
}
loff1 = *lp;
if (dir > 0)
botline_forw(lp);
else
topline_back(lp);
h3 = lp->height;
if (h3 + h2 > min_height)
{
*lp = loff0; /* no overlap */
return;
}
loff2 = *lp;
if (dir > 0)
botline_forw(lp);
else
topline_back(lp);
h4 = lp->height;
if (h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height)
*lp = loff1; /* 1 line overlap */
else
*lp = loff2; /* 2 lines overlap */
return;
}
/* #define KEEP_SCREEN_LINE */
/*
* Scroll 'scroll' lines up or down.
*/
void
halfpage(flag, Prenum)
int flag;
linenr_T Prenum;
{
long scrolled = 0;
int i;
int n;
int room;
if (Prenum)
curwin->w_p_scr = (Prenum > curwin->w_height) ?
curwin->w_height : Prenum;
n = (curwin->w_p_scr <= curwin->w_height) ?
curwin->w_p_scr : curwin->w_height;
validate_botline();
room = curwin->w_empty_rows;
#ifdef FEAT_DIFF
room += curwin->w_filler_rows;
#endif
if (flag)
{
/*
* scroll the text up
*/
while (n > 0 && curwin->w_botline <= curbuf->b_ml.ml_line_count)
{
#ifdef FEAT_DIFF
if (curwin->w_topfill > 0)
{
i = 1;
if (--n < 0 && scrolled > 0)
break;
--curwin->w_topfill;
}
else
#endif
{
#ifdef FEAT_DIFF
i = plines_nofill(curwin->w_topline);
#else
i = plines(curwin->w_topline);
#endif
n -= i;
if (n < 0 && scrolled > 0)
break;
#ifdef FEAT_FOLDING
(void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline);
#endif
++curwin->w_topline;
#ifdef FEAT_DIFF
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
#endif
#ifndef KEEP_SCREEN_LINE
if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
{
++curwin->w_cursor.lnum;
curwin->w_valid &=
~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL);
}
#endif
}
curwin->w_valid &= ~(VALID_CROW|VALID_WROW);
scrolled += i;
/*
* Correct w_botline for changed w_topline.
* Won't work when there are filler lines.
*/
#ifdef FEAT_DIFF
if (curwin->w_p_diff)
curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP);
else
#endif
{
room += i;
do
{
i = plines(curwin->w_botline);
if (i > room)
break;
#ifdef FEAT_FOLDING
(void)hasFolding(curwin->w_botline, NULL,
&curwin->w_botline);
#endif
++curwin->w_botline;
room -= i;
} while (curwin->w_botline <= curbuf->b_ml.ml_line_count);
}
}
#ifndef KEEP_SCREEN_LINE
/*
* When hit bottom of the file: move cursor down.
*/
if (n > 0)
{
# ifdef FEAT_FOLDING
if (hasAnyFolding(curwin))
{
while (--n >= 0
&& curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
{
(void)hasFolding(curwin->w_cursor.lnum, NULL,
&curwin->w_cursor.lnum);
++curwin->w_cursor.lnum;
}
}
else
# endif
curwin->w_cursor.lnum += n;
check_cursor_lnum();
}
#else
/* try to put the cursor in the same screen line */
while ((curwin->w_cursor.lnum < curwin->w_topline || scrolled > 0)
&& curwin->w_cursor.lnum < curwin->w_botline - 1)
{
scrolled -= plines(curwin->w_cursor.lnum);
if (scrolled < 0 && curwin->w_cursor.lnum >= curwin->w_topline)
break;
# ifdef FEAT_FOLDING
(void)hasFolding(curwin->w_cursor.lnum, NULL,
&curwin->w_cursor.lnum);
# endif
++curwin->w_cursor.lnum;
}
#endif
}
else
{
/*
* scroll the text down
*/
while (n > 0 && curwin->w_topline > 1)
{
#ifdef FEAT_DIFF
if (curwin->w_topfill < diff_check_fill(curwin, curwin->w_topline))
{
i = 1;
if (--n < 0 && scrolled > 0)
break;
++curwin->w_topfill;
}
else
#endif
{
#ifdef FEAT_DIFF
i = plines_nofill(curwin->w_topline - 1);
#else
i = plines(curwin->w_topline - 1);
#endif
n -= i;
if (n < 0 && scrolled > 0)
break;
--curwin->w_topline;
#ifdef FEAT_FOLDING
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
#endif
#ifdef FEAT_DIFF
curwin->w_topfill = 0;
#endif
}
curwin->w_valid &= ~(VALID_CROW|VALID_WROW|
VALID_BOTLINE|VALID_BOTLINE_AP);
scrolled += i;
#ifndef KEEP_SCREEN_LINE
if (curwin->w_cursor.lnum > 1)
{
--curwin->w_cursor.lnum;
curwin->w_valid &= ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL);
}
#endif
}
#ifndef KEEP_SCREEN_LINE
/*
* When hit top of the file: move cursor up.
*/
if (n > 0)
{
if (curwin->w_cursor.lnum <= (linenr_T)n)
curwin->w_cursor.lnum = 1;
else
# ifdef FEAT_FOLDING
if (hasAnyFolding(curwin))
{
while (--n >= 0 && curwin->w_cursor.lnum > 1)
{
--curwin->w_cursor.lnum;
(void)hasFolding(curwin->w_cursor.lnum,
&curwin->w_cursor.lnum, NULL);
}
}
else
# endif
curwin->w_cursor.lnum -= n;
}
#else
/* try to put the cursor in the same screen line */
scrolled += n; /* move cursor when topline is 1 */
while (curwin->w_cursor.lnum > curwin->w_topline
&& (scrolled > 0 || curwin->w_cursor.lnum >= curwin->w_botline))
{
scrolled -= plines(curwin->w_cursor.lnum - 1);
if (scrolled < 0 && curwin->w_cursor.lnum < curwin->w_botline)
break;
--curwin->w_cursor.lnum;
# ifdef FEAT_FOLDING
foldAdjustCursor();
# endif
}
#endif
}
# ifdef FEAT_FOLDING
/* Move cursor to first line of closed fold. */
foldAdjustCursor();
# endif
#ifdef FEAT_DIFF
check_topfill(curwin, !flag);
#endif
cursor_correct();
beginline(BL_SOL | BL_FIX);
redraw_later(VALID);
}
#if defined(FEAT_CURSORBIND) || defined(PROTO)
void
do_check_cursorbind()
{
linenr_T line = curwin->w_cursor.lnum;
colnr_T col = curwin->w_cursor.col;
# ifdef FEAT_VIRTUALEDIT
colnr_T coladd = curwin->w_cursor.coladd;
# endif
colnr_T curswant = curwin->w_curswant;
int set_curswant = curwin->w_set_curswant;
win_T *old_curwin = curwin;
buf_T *old_curbuf = curbuf;
int restart_edit_save;
# ifdef FEAT_VISUAL
int old_VIsual_select = VIsual_select;
int old_VIsual_active = VIsual_active;
# endif
/*
* loop through the cursorbound windows
*/
# ifdef FEAT_VISUAL
VIsual_select = VIsual_active = 0;
# endif
for (curwin = firstwin; curwin; curwin = curwin->w_next)
{
curbuf = curwin->w_buffer;
/* skip original window and windows with 'noscrollbind' */
if (curwin != old_curwin && curwin->w_p_crb)
{
# ifdef FEAT_DIFF
if (curwin->w_p_diff)
curwin->w_cursor.lnum
= diff_get_corresponding_line(old_curbuf,
line,
curbuf,
curwin->w_cursor.lnum);
else
# endif
curwin->w_cursor.lnum = line;
curwin->w_cursor.col = col;
# ifdef FEAT_VIRTUALEDIT
curwin->w_cursor.coladd = coladd;
# endif
curwin->w_curswant = curswant;
curwin->w_set_curswant = set_curswant;
/* Make sure the cursor is in a valid position. Temporarily set
* "restart_edit" to allow the cursor to be beyond the EOL. */
restart_edit_save = restart_edit;
restart_edit = TRUE;
check_cursor();
restart_edit = restart_edit_save;
# ifdef FEAT_MBYTE
/* Correct cursor for multi-byte character. */
if (has_mbyte)
mb_adjust_cursor();
# endif
redraw_later(VALID);
/* Only scroll when 'scrollbind' hasn't done this. */
if (!curwin->w_p_scb)
update_topline();
# ifdef FEAT_WINDOWS
curwin->w_redr_status = TRUE;
# endif
}
}
/*
* reset current-window
*/
# ifdef FEAT_VISUAL
VIsual_select = old_VIsual_select;
VIsual_active = old_VIsual_active;
# endif
curwin = old_curwin;
curbuf = old_curbuf;
}
#endif /* FEAT_CURSORBIND */
| zyz2011-vim | src/move.c | C | gpl2 | 69,081 |
# vim: set ft=make :
# Makefile for VIM on the Amiga, using SAS/Lattice C 6.0 to 6.58
#
# Do NOT use the peephole optimizer with a version before 6.56!
# It messes up all kinds of things:
# For 6.0 and 6.1, expand_env() will not work correctly.
# For 6.2 and 6.3 the call to free_line in u_freeentry is wrong.
# The "read.me" file for version 6.56 includes a remark about a fix for the
# peephole optimizer. Everything before 6.56 will probably fail.
#
# You should use Manx Aztec C whenever possible, because it has been tested.
#
# The prototypes from Manx and SAS are incompatible. If the prototypes
# were generated by Manx, first do "touch *.c; make proto" before "make".
# The prototypes generated on Unix work for both.
#
# Note: Not all dependencies are included. This was done to avoid having
# to compile everything when a global variable or function is added.
#>>>>> choose options:
### See feature.h for a list of optionals.
### Any other defines can be included here.
# NO_ARP Don't include ARP functions
# SASC=658 Sas/C version number
# NEWSASC fixes a bug in the syntax highlighting?
DEFINES = DEF=NO_ARP DEF=NEWSASC DEF="SASC=658"
#>>>>> if HAVE_TGETENT is defined termlib.o has to be used
#TERMLIB = termlib.o
TERMLIB =
#>>>>> choose NODEBUG for normal compiling, the other for debugging and
# profiling
# don't switch on debugging when generating proto files, it crashes the
# compiler.
DBG = NODEBUG
#DBG = DBG=SF
#>>>>> choose NOOPTPEEP for 6.0 to 6.3, NOOPT for debugging
# with version 6.56 and later you can probably use OPT
OPTIMIZE = OPT
#OPTIMIZE = NOOPTPEEP
#OPTIMIZE = NOOPT
# for 6.58 you can use the line below, but be warned it takes a loooonnnggg time
#OPTIMIZE=OPT OPTIMIZERSCHEDULER OPTIMIZERTIME NoOPTIMIZERALIAS \
OptimizerComplexity=10 OptimizerDepth=10 OptimizerRecurDepth=10 \
OptimizerInLocal OPTPEEP
#generate code for your processor - 68060 will work for 040's as well.
CPU=68000
#CPU=68020
#CPU=68030
#CPU=68040
#CPU=68060
#Error reporting - rexx or console
ERROR = ERRORCONSOLE ERRORSOURCE ERRORHIGHLIGHT
#ERROR = ERRORREXX ERRORCONSOLE ERRORSOURCE ERRORHIGHLIGHT
#memory types, if you have fast use it :->,
# ANY = will work on all machines
# FAST = this is the best option, for speed
#MEMORYTYPE=FAST
MEMORYTYPE=ANY
#MEMSIZE - this is for compile time only for speed of compilation
#MEMSIZE=HUGE
MEMSIZE=LARGE
#MEMSIZE=SMALL
#>>>>> end of choices
###########################################################################
CC = sc
GST = vim.gst
COPTS = SINT SCODE SDATA
SHELL = csh
DEL = $(SHELL) -c rm -f
# ignore error messages for uninitialized variables, they are mostly not correct
CFLAGS = NOLINK $(DBG) CPU=$(CPU) NOSTACKCHECK DEF=AMIGA CODE=FAR idir=proto ignore=317
CFLAGS2 = $(OPTIMIZE) $(ERROR) GSTIMMEDIATE GST=$(GST)
CFLAGS3 = $(COPTS) STRINGMERGE MEMSIZE=$(MEMSIZE)
CFLAGS4 = $(DEFINES) DATAMEMORY=$(MEMORYTYPE)
PROPT = DEF=PROTO GPROTO GPPARM MAXIMUMERRORS=999 GENPROTOSTATICS GENPROTOPARAMETERS
SRC = \
blowfish.c \
buffer.c \
charset.c \
diff.c \
digraph.c \
edit.c \
eval.c \
ex_cmds.c \
ex_cmds2.c \
ex_docmd.c \
ex_eval.c \
ex_getln.c \
fileio.c \
fold.c \
getchar.c \
hardcopy.c \
hashtab.c \
main.c \
mark.c \
memfile.c \
memline.c \
menu.c \
message.c \
misc1.c \
misc2.c \
move.c \
mbyte.c \
normal.c \
ops.c \
option.c \
os_amiga.c \
popupmnu.c \
quickfix.c \
regexp.c \
screen.c \
search.c \
sha256.c \
spell.c \
syntax.c \
tag.c \
term.c \
ui.c \
undo.c \
window.c \
version.c
OBJ = \
blowfish.o \
buffer.o \
charset.o \
diff.o \
digraph.o \
edit.o \
eval.o \
ex_cmds.o \
ex_cmds2.o \
ex_docmd.o \
ex_eval.o \
ex_getln.o \
fileio.o \
fold.o \
getchar.o \
hardcopy.o \
hashtab.o \
main.o \
mark.o \
memfile.o \
memline.o \
menu.o \
message.o \
misc1.o \
misc2.o \
move.o \
mbyte.o \
normal.o \
ops.o \
option.o \
os_amiga.o \
popupmnu.o \
quickfix.o \
regexp.o \
screen.o \
search.o \
sha256.o \
spell.o \
syntax.o \
tag.o \
term.o \
ui.o \
undo.o \
window.o \
$(TERMLIB)
PRO = \
proto/blowfish.pro \
proto/buffer.pro \
proto/charset.pro \
proto/diff.pro \
proto/digraph.pro \
proto/edit.pro \
proto/eval.pro \
proto/ex_cmds.pro \
proto/ex_cmds2.pro \
proto/ex_docmd.pro \
proto/ex_eval.pro \
proto/ex_getln.pro \
proto/fileio.pro \
proto/fold.pro \
proto/getchar.pro \
proto/hardcopy.pro \
proto/hashtab.pro \
proto/main.pro \
proto/mark.pro \
proto/memfile.pro \
proto/memline.pro \
proto/menu.pro \
proto/message.pro \
proto/misc1.pro \
proto/misc2.pro \
proto/move.pro \
proto/mbyte.pro \
proto/normal.pro \
proto/ops.pro \
proto/option.pro \
proto/os_amiga.pro \
proto/popupmnu.pro \
proto/quickfix.pro \
proto/regexp.pro \
proto/screen.pro \
proto/search.pro \
proto/sha256.pro \
proto/spell.pro \
proto/syntax.pro \
proto/tag.pro \
proto/term.pro \
proto/termlib.pro \
proto/ui.pro \
proto/undo.pro \
proto/window.pro
all: proto Vim
Vim: scoptions $(OBJ) version.c version.h
$(CC) $(CFLAGS) version.c
$(CC) LINK $(COPTS) $(OBJ) version.o $(DBG) PNAME=Vim
debug: scoptions $(OBJ) version.c version.h
$(CC) $(CFLAGS) version.c
$(CC) LINK $(COPTS) $(OBJ) version.o $(DBG) PNAME=Vim
proto: $(GST) $(PRO)
tags:
spat ctags $(SRC) *.h
# csh -c ctags $(SRC) *.h
# can't use delete here, too many file names
clean:
$(DEL) *.o Vim $(GST)
# generate GlobalSymbolTable, which speeds up the compile time.
#
# A preprocessing stage is used to work arounda bug in the GST generator, in
# that it does not handle nested makefiles properly in this stage.
# Ignore error message for not producing any code (105).
$(GST): scoptions vim.h keymap.h macros.h ascii.h term.h structs.h
$(CC) $(CFLAGS) PREPROCESSORONLY vim.h objectname pre.h
$(CC) MGST=$(GST) pre.h ignore=105
$(DEL) pre.h
# generate an options file, because SAS/C smake can't handle the amiga command
# line can handle the lengths that this makefile will impose on the shell.
# (Manx's make can do this).
scoptions: Make_sas.mak
@echo "Generating - $@ ..."
@echo $(CFLAGS) > scoptions
@echo $(CFLAGS1) >> scoptions
@echo $(CFLAGS2) >> scoptions
@echo $(CFLAGS3) >> scoptions
@echo $(CFLAGS4) >> scoptions
@echo $(COPTS) >>scoptions
@echo done
###########################################################################
$(OBJ): $(GST) vim.h
$(PRO): $(GST) vim.h
.c.o:
$(CC) $(CFLAGS) $*.c
.c.pro:
$(CC) $(CFLAGS) GPFILE=proto/$*.pro $(PROPT) $*.c
# dependancies
blowfish.o: blowfish.c
proto/blowfish.pro: blowfish.c
buffer.o: buffer.c
proto/buffer.pro: buffer.c
charset.o: charset.c
proto/charset.pro: charset.c
diff.o: diff.c
proto/diff.pro: diff.c
digraph.o: digraph.c
proto/digraph.pro: digraph.c
edit.o: edit.c
proto/edit.pro: edit.c
eval.o: eval.c
proto/eval.pro: eval.c
ex_cmds.o: ex_cmds.c
proto/ex_cmds.pro: ex_cmds.c
ex_cmds2.o: ex_cmds2.c
proto/ex_cmds2.pro: ex_cmds2.c
ex_docmd.o: ex_docmd.c ex_cmds.h
proto/ex_docmd.pro: ex_docmd.c ex_cmds.h
ex_eval.o: ex_eval.c ex_cmds.h
proto/ex_eval.pro: ex_eval.c ex_cmds.h
ex_getln.o: ex_getln.c
proto/ex_getln.pro: ex_getln.c
fileio.o: fileio.c
proto/fileio.pro: fileio.c
fold.o: fold.c
proto/fold.pro: fold.c
getchar.o: getchar.c
proto/getchar.pro: getchar.c
hardcopy.o: hardcopy.c
proto/hardcopy.pro: hardcopy.c
hashtab.o: hashtab.c
proto/hashtab.pro: hashtab.c
main.o: main.c
proto/main.pro: main.c
mark.o: mark.c
proto/mark.pro: mark.c
memfile.o: memfile.c
proto/memfile.pro: memfile.c
memline.o: memline.c
proto/memline.pro: memline.c
menu.o: menu.c
proto/menu.pro: menu.c
message.o: message.c
proto/message.pro: message.c
misc1.o: misc1.c
proto/misc1.pro: misc1.c
misc2.o: misc2.c
proto/misc2.pro: misc2.c
move.o: move.c
proto/move.pro: move.c
mbyte.o: mbyte.c
proto/mbyte.pro: mbyte.c
normal.o: normal.c
proto/normal.pro: normal.c
ops.o: ops.c
proto/ops.pro: ops.c
option.o: option.c
proto/option.pro: option.c
os_amiga.o: os_amiga.c
proto/os_amiga.pro: os_amiga.c
popupmnu.o: popupmnu.c
proto/popupmnu.pro: popupmnu.c
quickfix.o: quickfix.c
proto/quickfix.pro: quickfix.c
regexp.o: regexp.c
proto/regexp.pro: regexp.c
screen.o: screen.c
proto/screen.pro: screen.c
search.o: search.c
proto/search.pro: search.c
sha256.o: sha256.c
proto/sha256.pro: sha256.c
spell.o: spell.c
proto/spell.pro: spell.c
syntax.o: syntax.c
proto/syntax.pro: syntax.c
tag.o: tag.c
proto/tag.pro: tag.c
term.o: term.c
proto/term.pro: term.c
termlib.o: termlib.c
proto/termlib.pro: termlib.c
ui.o: ui.c
proto/ui.pro: ui.c
undo.o: undo.c
proto/undo.pro: undo.c
window.o: window.c
| zyz2011-vim | src/Make_sas.mak | Makefile | gpl2 | 8,604 |
# Makefile for VIM on Win32, using 'EGCS/mingw32 1.1.2'.
# Info at http://www.mingw.org
# Also requires 'GNU make 3.77', which you can get through a link
# to 'JanJaap's page from the above page.
# Get missing libraries from http://gnuwin32.sf.net.
#
# Tested on Win32 NT 4 and Win95.
#
# To make everything, just 'make -f Make_ming.mak'
# To make just e.g. gvim.exe, 'make -f Make_ming.mak gvim.exe'
# After a run, you can 'make -f Make_ming.mak clean' to clean up
#
# NOTE: Sometimes 'GNU Make' will stop after building vimrun.exe -- I think
# it's just run out of memory or something. Run again, and it will continue
# with 'xxd'.
#
# "make upx" makes *compressed* versions of the 32 bit GUI and console EXEs,
# using the excellent UPX compressor:
# http://upx.sourceforge.net/
# "make mpress" uses the MPRESS compressor for 32- and 64-bit EXEs:
# http://www.matcode.com/mpress.htm
#
# Maintained by Ron Aaron <ronaharon@yahoo.com>
# updated 2003 Jan 20
#>>>>> choose options:
# set to yes for a debug build
DEBUG=no
# set to SIZE for size, SPEED for speed, MAXSPEED for maximum optimization
OPTIMIZE=MAXSPEED
# set to yes to make gvim, no for vim
GUI=yes
# FEATURES=[TINY | SMALL | NORMAL | BIG | HUGE]
# set to TINY to make minimal version (few features)
FEATURES=BIG
# set to one of i386, i486, i586, i686 as the minimum target processor
ARCH=i386
# set to yes to cross-compile from unix; no=native Windows
CROSS=no
# set to path to iconv.h and libiconv.a to enable using 'iconv.dll'
#ICONV="."
ICONV=yes
GETTEXT=yes
# set to yes to include multibyte support
MBYTE=yes
# set to yes to include IME support
IME=yes
DYNAMIC_IME=yes
# set to yes to enable writing a postscript file with :hardcopy
POSTSCRIPT=no
# set to yes to enable OLE support
OLE=no
# Set the default $(WINVER) to make it work with pre-Win2k
ifndef WINVER
WINVER = 0x0400
endif
# Set to yes to enable Cscope support
CSCOPE=yes
# Set to yes to enable Netbeans support
NETBEANS=$(GUI)
# Link against the shared version of libstdc++ by default. Set
# STATIC_STDCPLUS to "yes" to link against static version instead.
ifndef STATIC_STDCPLUS
STATIC_STDCPLUS=no
endif
# If the user doesn't want gettext, undefine it.
ifeq (no, $(GETTEXT))
GETTEXT=
endif
# Added by E.F. Amatria <eferna1@platea.ptic.mec.es> 2001 Feb 23
# Uncomment the first line and one of the following three if you want Native Language
# Support. You'll need gnu_gettext.win32, a MINGW32 Windows PORT of gettext by
# Franco Bez <franco.bez@gmx.de>. It may be found at
# http://home.a-city.de/franco.bez/gettext/gettext_win32_en.html
# Tested with mingw32 with GCC-2.95.2 on Win98
# Updated 2001 Jun 9
#GETTEXT=c:/gettext.win32.msvcrt
#STATIC_GETTEXT=USE_STATIC_GETTEXT
#DYNAMIC_GETTEXT=USE_GETTEXT_DLL
#DYNAMIC_GETTEXT=USE_SAFE_GETTEXT_DLL
SAFE_GETTEXT_DLL_OBJ = $(GETTEXT)/src/safe_gettext_dll/safe_gettext_dll.o
# Alternatively, if you uncomment the two following lines, you get a "safe" version
# without linking the safe_gettext_dll.o object file.
#DYNAMIC_GETTEXT=DYNAMIC_GETTEXT
#GETTEXT_DYNAMIC=gnu_gettext.dll
INTLPATH=$(GETTEXT)/lib/mingw32
INTLLIB=gnu_gettext
# If you are using gettext-0.10.35 from http://sourceforge.net/projects/gettext
# or gettext-0.10.37 from http://sourceforge.net/projects/mingwrep/
# uncomment the following, but I can't build a static version with them, ?-(|
#GETTEXT=c:/gettext-0.10.37-20010430
#STATIC_GETTEXT=USE_STATIC_GETTEXT
#DYNAMIC_GETTEXT=DYNAMIC_GETTEXT
#INTLPATH=$(GETTEXT)/lib
#INTLLIB=intl
# uncomment 'PERL' if you want a perl-enabled version
#PERL=C:/perl
ifdef PERL
ifndef PERL_VER
PERL_VER=56
endif
ifndef DYNAMIC_PERL
DYNAMIC_PERL=yes
endif
# on Linux, for cross-compile, it's here:
#PERLLIB=/home/ron/ActivePerl/lib
# on NT, it's here:
PERLLIB=$(PERL)/lib
PERLLIBS=$(PERLLIB)/Core
XSUBPPTRY=$(PERLLIB)/ExtUtils/xsubpp
XSUBPP_EXISTS=$(shell perl -e "print 1 unless -e '$(XSUBPPTRY)'")
ifeq "$(XSUBPP_EXISTS)" ""
XSUBPP=perl $(XSUBPPTRY)
else
XSUBPP=xsubpp
endif
endif
# uncomment 'LUA' if you want a Lua-enabled version
#LUA=/usr/local
ifdef LUA
ifndef DYNAMIC_LUA
DYNAMIC_LUA=yes
endif
ifndef LUA_VER
LUA_VER=51
endif
ifeq (no,$(DYNAMIC_LUA))
LUA_LIB = -L$(LUA)/lib -llua
endif
endif
# uncomment 'MZSCHEME' if you want a MzScheme-enabled version
#MZSCHEME=d:/plt
ifdef MZSCHEME
ifndef DYNAMIC_MZSCHEME
DYNAMIC_MZSCHEME=yes
endif
ifndef MZSCHEME_VER
MZSCHEME_VER=205_000
endif
ifndef MZSCHEME_PRECISE_GC
MZSCHEME_PRECISE_GC=no
endif
# for version 4.x we need to generate byte-code for Scheme base
ifndef MZSCHEME_GENERATE_BASE
MZSCHEME_GENERATE_BASE=no
endif
ifndef MZSCHEME_USE_RACKET
MZSCHEME_MAIN_LIB=mzsch
else
MZSCHEME_MAIN_LIB=racket
endif
ifeq (no,$(DYNAMIC_MZSCHEME))
ifeq (yes,$(MZSCHEME_PRECISE_GC))
MZSCHEME_LIB=-l$(MZSCHEME_MAIN_LIB)$(MZSCHEME_VER)
else
MZSCHEME_LIB = -l$(MZSCHEME_MAIN_LIB)$(MZSCHEME_VER) -lmzgc$(MZSCHEME_VER)
endif
# the modern MinGW can dynamically link to dlls directly.
# point MZSCHEME_DLLS to where you put libmzschXXXXXXX.dll and libgcXXXXXXX.dll
ifndef MZSCHEME_DLLS
MZSCHEME_DLLS=$(MZSCHEME)
endif
MZSCHEME_LIBDIR=-L$(MZSCHEME_DLLS) -L$(MZSCHEME_DLLS)\lib
endif
endif
# Python support -- works with the ActiveState python 2.0 release (and others
# too, probably)
#
# uncomment 'PYTHON' to make python-enabled version
# Put the path to the python distro here. If cross compiling from Linux, you
# will also need to convert the header files to unix instead of dos format:
# for fil in *.h ; do vim -e -c 'set ff=unix|w|q' $fil
# and also, you will need to make a mingw32 'libpython20.a' to link with:
# cd $PYTHON/libs
# pexports python20.dll > python20.def
# dlltool -d python20.def -l libpython20.a
# on my Linux box, I put the Python stuff here:
#PYTHON=/home/ron/ActivePython-2.0.0-202/src/Core
# on my NT box, it's here:
#PYTHON=c:/python20
ifdef PYTHON
ifndef DYNAMIC_PYTHON
DYNAMIC_PYTHON=yes
endif
ifndef PYTHON_VER
PYTHON_VER=22
endif
ifeq (no,$(DYNAMIC_PYTHON))
PYTHONLIB=-L$(PYTHON)/libs -lpython$(PYTHON_VER)
endif
# my include files are in 'win32inc' on Linux, and 'include' in the standard
# NT distro (ActiveState)
ifeq ($(CROSS),no)
PYTHONINC=-I $(PYTHON)/include
else
PYTHONINC=-I $(PYTHON)/win32inc
endif
endif
#PYTHON3: See comment for Python 2 above
ifdef PYTHON3
ifndef DYNAMIC_PYTHON3
DYNAMIC_PYTHON3=yes
endif
ifndef PYTHON3_VER
PYTHON3_VER=31
endif
ifeq (no,$(DYNAMIC_PYTHON3))
PYTHON3LIB=-L$(PYTHON3)/libs -lPYTHON$(PYTHON3_VER)
endif
ifeq ($(CROSS),no)
PYTHON3INC=-I $(PYTHON3)/include
else
PYTHON3INC=-I $(PYTHON3)/win32inc
endif
endif
# TCL interface:
# TCL=[Path to TCL directory]
# DYNAMIC_TCL=yes (to load the TCL DLL dynamically)
# TCL_VER=[TCL version, eg 83, 84] (default is 83)
#TCL=c:/tcl
ifdef TCL
ifndef DYNAMIC_TCL
DYNAMIC_TCL=yes
endif
ifndef TCL_VER
TCL_VER = 83
endif
TCLINC += -I$(TCL)/include
endif
# Ruby interface:
# RUBY=[Path to Ruby directory]
# DYNAMIC_RUBY=yes (to load the Ruby DLL dynamically)
# RUBY_VER=[Ruby version, eg 16, 17] (default is 16)
# RUBY_VER_LONG=[Ruby version, eg 1.6, 1.7] (default is 1.6)
# You must set RUBY_VER_LONG when change RUBY_VER.
#RUBY=c:/ruby
ifdef RUBY
ifndef DYNAMIC_RUBY
DYNAMIC_RUBY=yes
endif
# Set default value
ifndef RUBY_VER
RUBY_VER = 16
endif
ifndef RUBY_VER_LONG
RUBY_VER_LONG = 1.6
endif
ifndef RUBY_PLATFORM
ifeq ($(RUBY_VER), 16)
RUBY_PLATFORM = i586-mswin32
else
ifneq ($(wildcard $(RUBY)/lib/ruby/$(RUBY_VER_LONG)/i386-mingw32),)
RUBY_PLATFORM = i386-mingw32
else
RUBY_PLATFORM = i386-mswin32
endif
endif
endif
ifndef RUBY_INSTALL_NAME
ifeq ($(RUBY_VER), 16)
RUBY_INSTALL_NAME = mswin32-ruby$(RUBY_VER)
else
RUBY_INSTALL_NAME = msvcrt-ruby$(RUBY_VER)
endif
endif
RUBYINC =-I $(RUBY)/lib/ruby/$(RUBY_VER_LONG)/$(RUBY_PLATFORM) -I $(RUBY)/include/ruby-$(RUBY_VER_LONG) -I $(RUBY)/include/ruby-$(RUBY_VER_LONG)/$(RUBY_PLATFORM)
ifeq (no, $(DYNAMIC_RUBY))
RUBYLIB = -L$(RUBY)/lib -l$(RUBY_INSTALL_NAME)
endif
endif # RUBY
# See feature.h for a list of options.
# Any other defines can be included here.
DEF_GUI=-DFEAT_GUI_W32 -DFEAT_CLIPBOARD
DEFINES=-DWIN32 -DWINVER=$(WINVER) -D_WIN32_WINNT=$(WINVER) \
-DHAVE_PATHDEF -DFEAT_$(FEATURES)
ifeq ($(CROSS),yes)
# cross-compiler prefix:
CROSS_COMPILE = i586-pc-mingw32msvc-
DEL = rm
MKDIR = mkdir -p
DIRSLASH = /
else
# normal (Windows) compilation:
CROSS_COMPILE =
ifneq (sh.exe, $(SHELL))
DEL = rm
MKDIR = mkdir -p
DIRSLASH = /
else
DEL = del
MKDIR = mkdir
DIRSLASH = \\
endif
endif
CC := $(CROSS_COMPILE)gcc
WINDRES := $(CROSS_COMPILE)windres
WINDRES_CC = $(CC)
#>>>>> end of choices
###########################################################################
CFLAGS = -Iproto $(DEFINES) -pipe -w -march=$(ARCH) -Wall
WINDRES_FLAGS = --preprocessor="$(WINDRES_CC) -E -xc" -DRC_INVOKED
ifdef GETTEXT
DEFINES += -DHAVE_GETTEXT -DHAVE_LOCALE_H
GETTEXTINCLUDE = $(GETTEXT)/include
GETTEXTLIB = $(INTLPATH)
ifeq (yes, $(GETTEXT))
DEFINES += -DDYNAMIC_GETTEXT
else
ifdef DYNAMIC_GETTEXT
DEFINES += -D$(DYNAMIC_GETTEXT)
ifdef GETTEXT_DYNAMIC
DEFINES += -DGETTEXT_DYNAMIC -DGETTEXT_DLL=\"$(GETTEXT_DYNAMIC)\"
endif
endif
endif
endif
ifdef PERL
CFLAGS += -I$(PERLLIBS) -DFEAT_PERL -L$(PERLLIBS)
ifeq (yes, $(DYNAMIC_PERL))
CFLAGS += -DDYNAMIC_PERL -DDYNAMIC_PERL_DLL=\"perl$(PERL_VER).dll\"
endif
endif
ifdef LUA
CFLAGS += -I$(LUA)/include -DFEAT_LUA
ifeq (yes, $(DYNAMIC_LUA))
CFLAGS += -DDYNAMIC_LUA -DDYNAMIC_LUA_DLL=\"lua$(LUA_VER).dll\"
endif
endif
ifdef MZSCHEME
CFLAGS += -I$(MZSCHEME)/include -DFEAT_MZSCHEME -DMZSCHEME_COLLECTS=\"$(MZSCHEME)/collects\"
ifeq (yes, $(DYNAMIC_MZSCHEME))
CFLAGS += -DDYNAMIC_MZSCHEME -DDYNAMIC_MZSCH_DLL=\"lib$(MZSCHEME_MAIN_LIB)$(MZSCHEME_VER).dll\" -DDYNAMIC_MZGC_DLL=\"libmzgc$(MZSCHEME_VER).dll\"
endif
endif
ifdef RUBY
CFLAGS += -DFEAT_RUBY $(RUBYINC)
ifeq (yes, $(DYNAMIC_RUBY))
CFLAGS += -DDYNAMIC_RUBY -DDYNAMIC_RUBY_DLL=\"$(RUBY_INSTALL_NAME).dll\"
CFLAGS += -DDYNAMIC_RUBY_VER=$(RUBY_VER)
endif
endif
ifdef PYTHON
CFLAGS += -DFEAT_PYTHON
ifeq (yes, $(DYNAMIC_PYTHON))
CFLAGS += -DDYNAMIC_PYTHON
endif
endif
ifdef PYTHON3
CFLAGS += -DFEAT_PYTHON3
ifeq (yes, $(DYNAMIC_PYTHON3))
CFLAGS += -DDYNAMIC_PYTHON3
endif
endif
ifdef TCL
CFLAGS += -DFEAT_TCL $(TCLINC)
ifeq (yes, $(DYNAMIC_TCL))
CFLAGS += -DDYNAMIC_TCL -DDYNAMIC_TCL_DLL=\"tcl$(TCL_VER).dll\"
endif
endif
ifeq ($(POSTSCRIPT),yes)
DEFINES += -DMSWINPS
endif
ifeq (yes, $(OLE))
DEFINES += -DFEAT_OLE
endif
ifeq ($(CSCOPE),yes)
DEFINES += -DFEAT_CSCOPE
endif
ifeq ($(NETBEANS),yes)
# Only allow NETBEANS for a GUI build.
ifeq (yes, $(GUI))
DEFINES += -DFEAT_NETBEANS_INTG
ifeq ($(NBDEBUG), yes)
DEFINES += -DNBDEBUG
NBDEBUG_INCL = nbdebug.h
NBDEBUG_SRC = nbdebug.c
endif
endif
endif
ifdef XPM
# Only allow XPM for a GUI build.
ifeq (yes, $(GUI))
CFLAGS += -DFEAT_XPM_W32 -I $(XPM)/include
endif
endif
ifeq ($(DEBUG),yes)
CFLAGS += -g -fstack-check
DEBUG_SUFFIX=d
else
ifeq ($(OPTIMIZE), SIZE)
CFLAGS += -Os
else
ifeq ($(OPTIMIZE), MAXSPEED)
CFLAGS += -O3
CFLAGS += -fomit-frame-pointer -freg-struct-return
else # SPEED
CFLAGS += -O2
endif
endif
CFLAGS += -s
endif
LIB = -lkernel32 -luser32 -lgdi32 -ladvapi32 -lcomdlg32 -lcomctl32 -lversion
GUIOBJ = $(OUTDIR)/gui.o $(OUTDIR)/gui_w32.o $(OUTDIR)/gui_beval.o $(OUTDIR)/os_w32exe.o
OBJ = \
$(OUTDIR)/blowfish.o \
$(OUTDIR)/buffer.o \
$(OUTDIR)/charset.o \
$(OUTDIR)/diff.o \
$(OUTDIR)/digraph.o \
$(OUTDIR)/edit.o \
$(OUTDIR)/eval.o \
$(OUTDIR)/ex_cmds.o \
$(OUTDIR)/ex_cmds2.o \
$(OUTDIR)/ex_docmd.o \
$(OUTDIR)/ex_eval.o \
$(OUTDIR)/ex_getln.o \
$(OUTDIR)/fileio.o \
$(OUTDIR)/fold.o \
$(OUTDIR)/getchar.o \
$(OUTDIR)/hardcopy.o \
$(OUTDIR)/hashtab.o \
$(OUTDIR)/main.o \
$(OUTDIR)/mark.o \
$(OUTDIR)/memfile.o \
$(OUTDIR)/memline.o \
$(OUTDIR)/menu.o \
$(OUTDIR)/message.o \
$(OUTDIR)/misc1.o \
$(OUTDIR)/misc2.o \
$(OUTDIR)/move.o \
$(OUTDIR)/mbyte.o \
$(OUTDIR)/normal.o \
$(OUTDIR)/ops.o \
$(OUTDIR)/option.o \
$(OUTDIR)/os_win32.o \
$(OUTDIR)/os_mswin.o \
$(OUTDIR)/pathdef.o \
$(OUTDIR)/popupmnu.o \
$(OUTDIR)/quickfix.o \
$(OUTDIR)/regexp.o \
$(OUTDIR)/screen.o \
$(OUTDIR)/search.o \
$(OUTDIR)/sha256.o \
$(OUTDIR)/spell.o \
$(OUTDIR)/syntax.o \
$(OUTDIR)/tag.o \
$(OUTDIR)/term.o \
$(OUTDIR)/ui.o \
$(OUTDIR)/undo.o \
$(OUTDIR)/version.o \
$(OUTDIR)/vimrc.o \
$(OUTDIR)/window.o
ifdef PERL
OBJ += $(OUTDIR)/if_perl.o
endif
ifdef LUA
OBJ += $(OUTDIR)/if_lua.o
endif
ifdef MZSCHEME
OBJ += $(OUTDIR)/if_mzsch.o
MZSCHEME_INCL = if_mzsch.h
ifeq (yes,$(MZSCHEME_GENERATE_BASE))
CFLAGS += -DINCLUDE_MZSCHEME_BASE
MZ_EXTRA_DEP += mzscheme_base.c
endif
ifeq (yes,$(MZSCHEME_PRECISE_GC))
CFLAGS += -DMZ_PRECISE_GC
endif
endif
ifdef PYTHON
OBJ += $(OUTDIR)/if_python.o
endif
ifdef PYTHON3
OBJ += $(OUTDIR)/if_python3.o
endif
ifdef RUBY
OBJ += $(OUTDIR)/if_ruby.o
endif
ifdef TCL
OBJ += $(OUTDIR)/if_tcl.o
endif
ifeq ($(CSCOPE),yes)
OBJ += $(OUTDIR)/if_cscope.o
endif
ifeq ($(NETBEANS),yes)
# Only allow NETBEANS for a GUI build.
ifeq (yes, $(GUI))
OBJ += $(OUTDIR)/netbeans.o
LIB += -lwsock32
endif
endif
ifdef XPM
# Only allow XPM for a GUI build.
ifeq (yes, $(GUI))
OBJ += $(OUTDIR)/xpm_w32.o
# You'll need libXpm.a from http://gnuwin32.sf.net
LIB += -L $(XPM)/lib -lXpm
endif
endif
ifdef MZSCHEME
MZSCHEME_SUFFIX = Z
endif
ifeq ($(GUI),yes)
TARGET := gvim$(DEBUG_SUFFIX).exe
DEFINES += $(DEF_GUI)
OBJ += $(GUIOBJ)
LFLAGS += -mwindows
OUTDIR = gobj$(DEBUG_SUFFIX)$(MZSCHEME_SUFFIX)
else
TARGET := vim$(DEBUG_SUFFIX).exe
OUTDIR = obj$(DEBUG_SUFFIX)$(MZSCHEME_SUFFIX)
endif
ifdef GETTEXT
ifneq (yes, $(GETTEXT))
CFLAGS += -I$(GETTEXTINCLUDE)
ifndef STATIC_GETTEXT
LIB += -L$(GETTEXTLIB) -l$(INTLLIB)
ifeq (USE_SAFE_GETTEXT_DLL, $(DYNAMIC_GETTEXT))
OBJ+=$(SAFE_GETTEXT_DLL_OBJ)
endif
else
LIB += -L$(GETTEXTLIB) -lintl
endif
endif
endif
ifdef PERL
ifeq (no, $(DYNAMIC_PERL))
LIB += -lperl$(PERL_VER)
endif
endif
ifdef TCL
LIB += -L$(TCL)/lib
ifeq (yes, $(DYNAMIC_TCL))
LIB += -ltclstub$(TCL_VER)
else
LIB += -ltcl$(TCL_VER)
endif
endif
ifeq (yes, $(OLE))
LIB += -loleaut32
OBJ += $(OUTDIR)/if_ole.o
ifeq (yes, $(STATIC_STDCPLUS))
LIB += -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
else
LIB += -lstdc++
endif
endif
ifeq (yes, $(MBYTE))
DEFINES += -DFEAT_MBYTE
endif
ifeq (yes, $(IME))
DEFINES += -DFEAT_MBYTE_IME
ifeq (yes, $(DYNAMIC_IME))
DEFINES += -DDYNAMIC_IME
else
LIB += -limm32
endif
endif
ifdef ICONV
ifneq (yes, $(ICONV))
LIB += -L$(ICONV)
CFLAGS += -I$(ICONV)
endif
DEFINES+=-DDYNAMIC_ICONV
endif
all: $(TARGET) vimrun.exe xxd/xxd.exe install.exe uninstal.exe GvimExt/gvimext.dll
vimrun.exe: vimrun.c
$(CC) $(CFLAGS) -o vimrun.exe vimrun.c $(LIB)
install.exe: dosinst.c
$(CC) $(CFLAGS) -o install.exe dosinst.c $(LIB) -lole32 -luuid
uninstal.exe: uninstal.c
$(CC) $(CFLAGS) -o uninstal.exe uninstal.c $(LIB)
$(TARGET): $(OUTDIR) $(OBJ)
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $(OBJ) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB)
upx: exes
upx gvim.exe
upx vim.exe
mpress: exes
mpress gvim.exe
mpress vim.exe
xxd/xxd.exe: xxd/xxd.c
$(MAKE) -C xxd -f Make_ming.mak CC=$(CC)
GvimExt/gvimext.dll: GvimExt/gvimext.cpp GvimExt/gvimext.rc GvimExt/gvimext.h
$(MAKE) -C GvimExt -f Make_ming.mak CROSS=$(CROSS) CROSS_COMPILE=$(CROSS_COMPILE)
clean:
-$(DEL) $(OUTDIR)$(DIRSLASH)*.o
-$(DEL) $(OUTDIR)$(DIRSLASH)*.res
-rmdir $(OUTDIR)
-$(DEL) *.exe
-$(DEL) pathdef.c
ifdef PERL
-$(DEL) if_perl.c
endif
ifdef MZSCHEME
-$(DEL) mzscheme_base.c
endif
$(MAKE) -C GvimExt -f Make_ming.mak clean
$(MAKE) -C xxd -f Make_ming.mak clean
###########################################################################
INCL = vim.h feature.h os_win32.h os_dos.h ascii.h keymap.h term.h macros.h \
structs.h regexp.h option.h ex_cmds.h proto.h globals.h farsi.h \
gui.h
$(OUTDIR)/if_python.o : if_python.c $(INCL)
$(CC) -c $(CFLAGS) $(PYTHONINC) -DDYNAMIC_PYTHON_DLL=\"python$(PYTHON_VER).dll\" $< -o $@
$(OUTDIR)/if_python3.o : if_python3.c $(INCL)
$(CC) -c $(CFLAGS) $(PYTHON3INC) -DDYNAMIC_PYTHON3_DLL=\"PYTHON$(PYTHON3_VER).dll\" $< -o $@
$(OUTDIR)/%.o : %.c $(INCL)
$(CC) -c $(CFLAGS) $< -o $@
$(OUTDIR)/vimrc.o: vim.rc version.h gui_w32_rc.h
$(WINDRES) $(WINDRES_FLAGS) $(DEFINES) \
--input-format=rc --output-format=coff -i vim.rc -o $@
$(OUTDIR):
$(MKDIR) $(OUTDIR)
$(OUTDIR)/ex_docmd.o: ex_docmd.c $(INCL) ex_cmds.h
$(CC) -c $(CFLAGS) ex_docmd.c -o $(OUTDIR)/ex_docmd.o
$(OUTDIR)/ex_eval.o: ex_eval.c $(INCL) ex_cmds.h
$(CC) -c $(CFLAGS) ex_eval.c -o $(OUTDIR)/ex_eval.o
$(OUTDIR)/if_cscope.o: if_cscope.c $(INCL) if_cscope.h
$(CC) -c $(CFLAGS) if_cscope.c -o $(OUTDIR)/if_cscope.o
# Remove -D__IID_DEFINED__ for newer versions of the w32api
$(OUTDIR)/if_ole.o: if_ole.cpp $(INCL)
$(CC) $(CFLAGS) -c -o $(OUTDIR)/if_ole.o if_ole.cpp
$(OUTDIR)/if_ruby.o: if_ruby.c $(INCL)
ifeq (16, $(RUBY))
$(CC) $(CFLAGS) -U_WIN32 -c -o $(OUTDIR)/if_ruby.o if_ruby.c
endif
if_perl.c: if_perl.xs typemap
$(XSUBPP) -prototypes -typemap \
$(PERLLIB)/ExtUtils/typemap if_perl.xs > $@
$(OUTDIR)/netbeans.o: netbeans.c $(INCL) $(NBDEBUG_INCL) $(NBDEBUG_SRC)
$(CC) -c $(CFLAGS) netbeans.c -o $(OUTDIR)/netbeans.o
$(OUTDIR)/if_mzsch.o: if_mzsch.c $(INCL) if_mzsch.h $(MZ_EXTRA_DEP)
$(CC) -c $(CFLAGS) if_mzsch.c -o $(OUTDIR)/if_mzsch.o
mzscheme_base.c:
$(MZSCHEME)/mzc --c-mods mzscheme_base.c ++lib scheme/base
pathdef.c: $(INCL)
ifneq (sh.exe, $(SHELL))
@echo creating pathdef.c
@echo '/* pathdef.c */' > pathdef.c
@echo '#include "vim.h"' >> pathdef.c
@echo 'char_u *default_vim_dir = (char_u *)"$(VIMRCLOC)";' >> pathdef.c
@echo 'char_u *default_vimruntime_dir = (char_u *)"$(VIMRUNTIMEDIR)";' >> pathdef.c
@echo 'char_u *all_cflags = (char_u *)"$(CC) $(CFLAGS)";' >> pathdef.c
@echo 'char_u *all_lflags = (char_u *)"$(CC) $(CFLAGS) $(LFLAGS) -o $(TARGET) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB)";' >> pathdef.c
@echo 'char_u *compiled_user = (char_u *)"$(USERNAME)";' >> pathdef.c
@echo 'char_u *compiled_sys = (char_u *)"$(USERDOMAIN)";' >> pathdef.c
else
@echo creating pathdef.c
@echo /* pathdef.c */ > pathdef.c
@echo #include "vim.h" >> pathdef.c
@echo char_u *default_vim_dir = (char_u *)"$(VIMRCLOC)"; >> pathdef.c
@echo char_u *default_vimruntime_dir = (char_u *)"$(VIMRUNTIMEDIR)"; >> pathdef.c
@echo char_u *all_cflags = (char_u *)"$(CC) $(CFLAGS)"; >> pathdef.c
@echo char_u *all_lflags = (char_u *)"$(CC) $(CFLAGS) $(LFLAGS) -o $(TARGET) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB)"; >> pathdef.c
@echo char_u *compiled_user = (char_u *)"$(USERNAME)"; >> pathdef.c
@echo char_u *compiled_sys = (char_u *)"$(USERDOMAIN)"; >> pathdef.c
endif
| zyz2011-vim | src/Make_ming.mak | Makefile | gpl2 | 18,655 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
* Netbeans integration by David Weatherford
* Adopted for Win32 by Sergey Khorev
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*/
/*
* Implements client side of org.netbeans.modules.emacs editor
* integration protocol. Be careful! The protocol uses offsets
* which are *between* characters, whereas vim uses line number
* and column number which are *on* characters.
* See ":help netbeans-protocol" for explanation.
*
* The Netbeans messages are received and queued in the gui event loop, or in
* the select loop when Vim runs in a terminal. These messages are processed
* by netbeans_parse_messages() which is invoked in the idle loop when Vim is
* waiting for user input. The function netbeans_parse_messages() is also
* called from the ":sleep" command, to allow the execution of test cases that
* may not invoke the idle loop.
*/
#include "vim.h"
#if defined(FEAT_NETBEANS_INTG) || defined(PROTO)
/* TODO: when should this not be defined? */
#define INET_SOCKETS
/* Note: when making changes here also adjust configure.in. */
#ifdef WIN32
# ifdef DEBUG
# include <tchar.h> /* for _T definition for TRACEn macros */
# endif
/* WinSock API is separated from C API, thus we can't use read(), write(),
* errno... */
# define SOCK_ERRNO errno = WSAGetLastError()
# undef ECONNREFUSED
# define ECONNREFUSED WSAECONNREFUSED
# ifdef EINTR
# undef EINTR
# endif
# define EINTR WSAEINTR
# define sock_write(sd, buf, len) send(sd, buf, len, 0)
# define sock_read(sd, buf, len) recv(sd, buf, len, 0)
# define sock_close(sd) closesocket(sd)
# define sleep(t) Sleep(t*1000) /* WinAPI Sleep() accepts milliseconds */
#else
# ifdef INET_SOCKETS
# include <netdb.h>
# include <netinet/in.h>
# else
# include <sys/un.h>
# endif
# include <sys/socket.h>
# ifdef HAVE_LIBGEN_H
# include <libgen.h>
# endif
# define SOCK_ERRNO
# define sock_write(sd, buf, len) write(sd, buf, len)
# define sock_read(sd, buf, len) read(sd, buf, len)
# define sock_close(sd) close(sd)
#endif
#include "version.h"
#define GUARDED 10000 /* typenr for "guarded" annotation */
#define GUARDEDOFFSET 1000000 /* base for "guarded" sign id's */
#define MAX_COLOR_LENGTH 32 /* max length of color name in defineAnnoType */
/* The first implementation (working only with Netbeans) returned "1.1". The
* protocol implemented here also supports A-A-P. */
static char *ExtEdProtocolVersion = "2.5";
static long pos2off __ARGS((buf_T *, pos_T *));
static pos_T *off2pos __ARGS((buf_T *, long));
static pos_T *get_off_or_lnum __ARGS((buf_T *buf, char_u **argp));
static long get_buf_size __ARGS((buf_T *));
static int netbeans_keystring __ARGS((char_u *keystr));
static void postpone_keycommand __ARGS((char_u *keystr));
static void special_keys __ARGS((char_u *args));
static int netbeans_connect __ARGS((char *, int));
static int getConnInfo __ARGS((char *file, char **host, char **port, char **password));
static void nb_init_graphics __ARGS((void));
static void coloncmd __ARGS((char *cmd, ...));
static void nb_set_curbuf __ARGS((buf_T *buf));
#ifdef FEAT_GUI_X11
static void messageFromNetbeans __ARGS((XtPointer, int *, XtInputId *));
#endif
#ifdef FEAT_GUI_GTK
static void messageFromNetbeans __ARGS((gpointer, gint, GdkInputCondition));
#endif
static void nb_parse_cmd __ARGS((char_u *));
static int nb_do_cmd __ARGS((int, char_u *, int, int, char_u *));
static void nb_send __ARGS((char *buf, char *fun));
static void nb_free __ARGS((void));
/* TRUE when netbeans is running with a GUI. */
#ifdef FEAT_GUI
# define NB_HAS_GUI (gui.in_use || gui.starting)
#endif
#ifdef WIN64
typedef __int64 NBSOCK;
#else
typedef int NBSOCK;
#endif
static NBSOCK nbsock = -1; /* socket fd for Netbeans connection */
#define NETBEANS_OPEN (nbsock != -1)
#ifdef FEAT_GUI_X11
static XtInputId inputHandler = (XtInputId)NULL; /* Cookie for input */
#endif
#ifdef FEAT_GUI_GTK
static gint inputHandler = 0; /* Cookie for input */
#endif
#ifdef FEAT_GUI_W32
static int inputHandler = -1; /* simply ret.value of WSAAsyncSelect() */
extern HWND s_hwnd; /* Gvim's Window handle */
#endif
static int r_cmdno; /* current command number for reply */
static int dosetvisible = FALSE;
/*
* Include the debugging code if wanted.
*/
#ifdef NBDEBUG
# include "nbdebug.c"
#endif
static int needupdate = 0;
static int inAtomic = 0;
/*
* Close the socket and remove the input handlers.
*/
static void
nb_close_socket(void)
{
#ifdef FEAT_GUI_X11
if (inputHandler != (XtInputId)NULL)
{
XtRemoveInput(inputHandler);
inputHandler = (XtInputId)NULL;
}
#else
# ifdef FEAT_GUI_GTK
if (inputHandler != 0)
{
gdk_input_remove(inputHandler);
inputHandler = 0;
}
# else
# ifdef FEAT_GUI_W32
if (inputHandler == 0)
{
WSAAsyncSelect(nbsock, s_hwnd, 0, 0);
inputHandler = -1;
}
# endif
# endif
#endif
sock_close(nbsock);
nbsock = -1;
}
/*
* Close the connection and cleanup.
* May be called when nb_close_socket() was called earlier.
*/
static void
netbeans_close(void)
{
if (NETBEANS_OPEN)
{
netbeans_send_disconnect();
nb_close_socket();
}
#ifdef FEAT_BEVAL
bevalServers &= ~BEVAL_NETBEANS;
#endif
needupdate = 0;
inAtomic = 0;
nb_free();
/* remove all signs and update the screen after gutter removal */
coloncmd(":sign unplace *");
changed_window_setting();
update_screen(CLEAR);
setcursor();
cursor_on();
out_flush();
#ifdef FEAT_GUI
if (gui.in_use)
{
gui_update_cursor(TRUE, FALSE);
gui_mch_flush();
}
#endif
}
#define NB_DEF_HOST "localhost"
#define NB_DEF_ADDR "3219"
#define NB_DEF_PASS "changeme"
static int
netbeans_connect(char *params, int doabort)
{
#ifdef INET_SOCKETS
struct sockaddr_in server;
struct hostent * host;
# ifdef FEAT_GUI_W32
u_short port;
# else
int port;
# endif
#else
struct sockaddr_un server;
#endif
int sd;
char buf[32];
char *hostname = NULL;
char *address = NULL;
char *password = NULL;
char *fname;
char *arg = NULL;
if (*params == '=')
{
/* "=fname": Read info from specified file. */
if (getConnInfo(params + 1, &hostname, &address, &password)
== FAIL)
return FAIL;
}
else
{
if (*params == ':')
/* ":<host>:<addr>:<password>": get info from argument */
arg = params + 1;
if (arg == NULL && (fname = getenv("__NETBEANS_CONINFO")) != NULL)
{
/* "": get info from file specified in environment */
if (getConnInfo(fname, &hostname, &address, &password) == FAIL)
return FAIL;
}
else
{
if (arg != NULL)
{
/* ":<host>:<addr>:<password>": get info from argument */
hostname = arg;
address = strchr(hostname, ':');
if (address != NULL)
{
*address++ = '\0';
password = strchr(address, ':');
if (password != NULL)
*password++ = '\0';
}
}
/* Get the missing values from the environment. */
if (hostname == NULL || *hostname == '\0')
hostname = getenv("__NETBEANS_HOST");
if (address == NULL)
address = getenv("__NETBEANS_SOCKET");
if (password == NULL)
password = getenv("__NETBEANS_VIM_PASSWORD");
/* Move values to allocated memory. */
if (hostname != NULL)
hostname = (char *)vim_strsave((char_u *)hostname);
if (address != NULL)
address = (char *)vim_strsave((char_u *)address);
if (password != NULL)
password = (char *)vim_strsave((char_u *)password);
}
}
/* Use the default when a value is missing. */
if (hostname == NULL || *hostname == '\0')
{
vim_free(hostname);
hostname = (char *)vim_strsave((char_u *)NB_DEF_HOST);
}
if (address == NULL || *address == '\0')
{
vim_free(address);
address = (char *)vim_strsave((char_u *)NB_DEF_ADDR);
}
if (password == NULL || *password == '\0')
{
vim_free(password);
password = (char *)vim_strsave((char_u *)NB_DEF_PASS);
}
if (hostname == NULL || address == NULL || password == NULL)
goto theend; /* out of memory */
#ifdef FEAT_GUI_W32
netbeans_init_winsock();
#endif
#ifdef INET_SOCKETS
port = atoi(address);
if ((sd = (NBSOCK)socket(AF_INET, SOCK_STREAM, 0)) == (NBSOCK)-1)
{
nbdebug(("error in socket() in netbeans_connect()\n"));
PERROR("socket() in netbeans_connect()");
goto theend;
}
/* Get the server internet address and put into addr structure */
/* fill in the socket address structure and connect to server */
vim_memset((char *)&server, '\0', sizeof(server));
server.sin_family = AF_INET;
server.sin_port = htons(port);
if ((host = gethostbyname(hostname)) == NULL)
{
nbdebug(("error in gethostbyname() in netbeans_connect()\n"));
PERROR("gethostbyname() in netbeans_connect()");
sock_close(sd);
goto theend;
}
memcpy((char *)&server.sin_addr, host->h_addr, host->h_length);
#else
if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
{
nbdebug(("error in socket() in netbeans_connect()\n"));
PERROR("socket() in netbeans_connect()");
goto theend;
}
server.sun_family = AF_UNIX;
strcpy(server.sun_path, address);
#endif
/* Connect to server */
if (connect(sd, (struct sockaddr *)&server, sizeof(server)))
{
SOCK_ERRNO;
nbdebug(("netbeans_connect: Connect failed with errno %d\n", errno));
if (errno == ECONNREFUSED)
{
sock_close(sd);
#ifdef INET_SOCKETS
if ((sd = (NBSOCK)socket(AF_INET, SOCK_STREAM, 0)) == (NBSOCK)-1)
{
SOCK_ERRNO;
nbdebug(("socket()#2 in netbeans_connect()\n"));
PERROR("socket()#2 in netbeans_connect()");
goto theend;
}
#else
if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
{
SOCK_ERRNO;
nbdebug(("socket()#2 in netbeans_connect()\n"));
PERROR("socket()#2 in netbeans_connect()");
goto theend;
}
#endif
if (connect(sd, (struct sockaddr *)&server, sizeof(server)))
{
int retries = 36;
int success = FALSE;
SOCK_ERRNO;
while (retries-- && ((errno == ECONNREFUSED)
|| (errno == EINTR)))
{
nbdebug(("retrying...\n"));
mch_delay(3000L, TRUE);
ui_breakcheck();
if (got_int)
{
errno = EINTR;
break;
}
if (connect(sd, (struct sockaddr *)&server,
sizeof(server)) == 0)
{
success = TRUE;
break;
}
SOCK_ERRNO;
}
if (!success)
{
/* Get here when the server can't be found. */
nbdebug(("Cannot connect to Netbeans #2\n"));
PERROR(_("Cannot connect to Netbeans #2"));
sock_close(sd);
if (doabort)
getout(1);
goto theend;
}
}
}
else
{
nbdebug(("Cannot connect to Netbeans\n"));
PERROR(_("Cannot connect to Netbeans"));
sock_close(sd);
if (doabort)
getout(1);
goto theend;
}
}
nbsock = sd;
vim_snprintf(buf, sizeof(buf), "AUTH %s\n", password);
nb_send(buf, "netbeans_connect");
sprintf(buf, "0:version=0 \"%s\"\n", ExtEdProtocolVersion);
nb_send(buf, "externaleditor_version");
theend:
vim_free(hostname);
vim_free(address);
vim_free(password);
return NETBEANS_OPEN ? OK : FAIL;
}
/*
* Obtain the NetBeans hostname, port address and password from a file.
* Return the strings in allocated memory.
* Return FAIL if the file could not be read, OK otherwise (no matter what it
* contains).
*/
static int
getConnInfo(char *file, char **host, char **port, char **auth)
{
FILE *fp;
char_u buf[BUFSIZ];
char_u *lp;
char_u *nlp;
#ifdef UNIX
struct stat st;
/*
* For Unix only accept the file when it's not accessible by others.
* The open will then fail if we don't own the file.
*/
if (mch_stat(file, &st) == 0 && (st.st_mode & 0077) != 0)
{
nbdebug(("Wrong access mode for NetBeans connection info file: \"%s\"\n",
file));
EMSG2(_("E668: Wrong access mode for NetBeans connection info file: \"%s\""),
file);
return FAIL;
}
#endif
fp = mch_fopen(file, "r");
if (fp == NULL)
{
nbdebug(("Cannot open NetBeans connection info file\n"));
PERROR("E660: Cannot open NetBeans connection info file");
return FAIL;
}
/* Read the file. There should be one of each parameter */
while ((lp = (char_u *)fgets((char *)buf, BUFSIZ, fp)) != NULL)
{
if ((nlp = vim_strchr(lp, '\n')) != NULL)
*nlp = 0; /* strip off the trailing newline */
if (STRNCMP(lp, "host=", 5) == 0)
{
vim_free(*host);
*host = (char *)vim_strsave(&buf[5]);
}
else if (STRNCMP(lp, "port=", 5) == 0)
{
vim_free(*port);
*port = (char *)vim_strsave(&buf[5]);
}
else if (STRNCMP(lp, "auth=", 5) == 0)
{
vim_free(*auth);
*auth = (char *)vim_strsave(&buf[5]);
}
}
fclose(fp);
return OK;
}
struct keyqueue
{
char_u *keystr;
struct keyqueue *next;
struct keyqueue *prev;
};
typedef struct keyqueue keyQ_T;
static keyQ_T keyHead; /* dummy node, header for circular queue */
/*
* Queue up key commands sent from netbeans.
* We store the string, because it may depend on the global mod_mask and
* :nbkey doesn't have a key number.
*/
static void
postpone_keycommand(char_u *keystr)
{
keyQ_T *node;
node = (keyQ_T *)alloc(sizeof(keyQ_T));
if (node == NULL)
return; /* out of memory, drop the key */
if (keyHead.next == NULL) /* initialize circular queue */
{
keyHead.next = &keyHead;
keyHead.prev = &keyHead;
}
/* insert node at tail of queue */
node->next = &keyHead;
node->prev = keyHead.prev;
keyHead.prev->next = node;
keyHead.prev = node;
node->keystr = vim_strsave(keystr);
}
/*
* Handle any queued-up NetBeans keycommands to be send.
*/
static void
handle_key_queue(void)
{
int postponed = FALSE;
while (!postponed && keyHead.next && keyHead.next != &keyHead)
{
/* first, unlink the node */
keyQ_T *node = keyHead.next;
keyHead.next = node->next;
node->next->prev = node->prev;
/* Now, send the keycommand. This may cause it to be postponed again
* and change keyHead. */
if (node->keystr != NULL)
postponed = !netbeans_keystring(node->keystr);
vim_free(node->keystr);
/* Finally, dispose of the node */
vim_free(node);
}
}
struct cmdqueue
{
char_u *buffer;
struct cmdqueue *next;
struct cmdqueue *prev;
};
typedef struct cmdqueue queue_T;
static queue_T head; /* dummy node, header for circular queue */
/*
* Put the buffer on the work queue; possibly save it to a file as well.
*/
static void
save(char_u *buf, int len)
{
queue_T *node;
node = (queue_T *)alloc(sizeof(queue_T));
if (node == NULL)
return; /* out of memory */
node->buffer = alloc(len + 1);
if (node->buffer == NULL)
{
vim_free(node);
return; /* out of memory */
}
mch_memmove(node->buffer, buf, (size_t)len);
node->buffer[len] = NUL;
if (head.next == NULL) /* initialize circular queue */
{
head.next = &head;
head.prev = &head;
}
/* insert node at tail of queue */
node->next = &head;
node->prev = head.prev;
head.prev->next = node;
head.prev = node;
#ifdef NBDEBUG
{
static int outfd = -2;
/* possibly write buffer out to a file */
if (outfd == -3)
return;
if (outfd == -2)
{
char *file = getenv("__NETBEANS_SAVE");
if (file == NULL)
outfd = -3;
else
outfd = mch_open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
}
if (outfd >= 0)
write(outfd, buf, len);
}
#endif
}
/*
* While there's still a command in the work queue, parse and execute it.
*/
void
netbeans_parse_messages(void)
{
char_u *p;
queue_T *node;
int own_node;
while (head.next != NULL && head.next != &head)
{
node = head.next;
/* Locate the first line in the first buffer. */
p = vim_strchr(node->buffer, '\n');
if (p == NULL)
{
/* Command isn't complete. If there is no following buffer,
* return (wait for more). If there is another buffer following,
* prepend the text to that buffer and delete this one. */
if (node->next == &head)
return;
p = alloc((unsigned)(STRLEN(node->buffer)
+ STRLEN(node->next->buffer) + 1));
if (p == NULL)
return; /* out of memory */
STRCPY(p, node->buffer);
STRCAT(p, node->next->buffer);
vim_free(node->next->buffer);
node->next->buffer = p;
/* dispose of the node and buffer */
head.next = node->next;
node->next->prev = node->prev;
vim_free(node->buffer);
vim_free(node);
}
else
{
/* There is a complete command at the start of the buffer.
* Terminate it with a NUL. When no more text is following unlink
* the buffer. Do this before executing, because new buffers can
* be added while busy handling the command. */
*p++ = NUL;
if (*p == NUL)
{
own_node = TRUE;
head.next = node->next;
node->next->prev = node->prev;
}
else
own_node = FALSE;
/* now, parse and execute the commands */
nb_parse_cmd(node->buffer);
if (own_node)
{
/* buffer finished, dispose of the node and buffer */
vim_free(node->buffer);
vim_free(node);
}
/* Check that "head" wasn't changed under our fingers, e.g. when a
* DETACH command was handled. */
else if (head.next == node)
{
/* more follows, move to the start */
STRMOVE(node->buffer, p);
}
}
}
}
/* Buffer size for reading incoming messages. */
#define MAXMSGSIZE 4096
/*
* Read a command from netbeans.
*/
#ifdef FEAT_GUI_X11
static void
messageFromNetbeans(XtPointer clientData UNUSED,
int *unused1 UNUSED,
XtInputId *unused2 UNUSED)
{
netbeans_read();
}
#endif
#ifdef FEAT_GUI_GTK
static void
messageFromNetbeans(gpointer clientData UNUSED,
gint unused1 UNUSED,
GdkInputCondition unused2 UNUSED)
{
netbeans_read();
}
#endif
#define DETACH_MSG "DETACH\n"
void
netbeans_read()
{
static char_u *buf = NULL;
int len = 0;
int readlen = 0;
#ifdef HAVE_SELECT
struct timeval tval;
fd_set rfds;
#else
# ifdef HAVE_POLL
struct pollfd fds;
# endif
#endif
if (!NETBEANS_OPEN)
{
nbdebug(("messageFromNetbeans() called without a socket\n"));
return;
}
/* Allocate a buffer to read into. */
if (buf == NULL)
{
buf = alloc(MAXMSGSIZE);
if (buf == NULL)
return; /* out of memory! */
}
/* Keep on reading for as long as there is something to read.
* Use select() or poll() to avoid blocking on a message that is exactly
* MAXMSGSIZE long. */
for (;;)
{
#ifdef HAVE_SELECT
FD_ZERO(&rfds);
FD_SET(nbsock, &rfds);
tval.tv_sec = 0;
tval.tv_usec = 0;
if (select(nbsock + 1, &rfds, NULL, NULL, &tval) <= 0)
break;
#else
# ifdef HAVE_POLL
fds.fd = nbsock;
fds.events = POLLIN;
if (poll(&fds, 1, 0) <= 0)
break;
# endif
#endif
len = sock_read(nbsock, buf, MAXMSGSIZE);
if (len <= 0)
break; /* error or nothing more to read */
/* Store the read message in the queue. */
save(buf, len);
readlen += len;
if (len < MAXMSGSIZE)
break; /* did read everything that's available */
}
/* Reading a socket disconnection (readlen == 0), or a socket error. */
if (readlen <= 0)
{
/* Queue a "DETACH" netbeans message in the command queue in order to
* terminate the netbeans session later. Do not end the session here
* directly as we may be running in the context of a call to
* netbeans_parse_messages():
* netbeans_parse_messages
* -> autocmd triggered while processing the netbeans cmd
* -> ui_breakcheck
* -> gui event loop or select loop
* -> netbeans_read()
*/
save((char_u *)DETACH_MSG, (int)strlen(DETACH_MSG));
nb_close_socket();
if (len < 0)
{
nbdebug(("read from Netbeans socket\n"));
PERROR(_("read from Netbeans socket"));
}
}
#if defined(NB_HAS_GUI) && defined(FEAT_GUI_GTK)
if (NB_HAS_GUI && gtk_main_level() > 0)
gtk_main_quit();
#endif
}
/*
* Handle one NUL terminated command.
*
* format of a command from netbeans:
*
* 6:setTitle!84 "a.c"
*
* bufno
* colon
* cmd
* !
* cmdno
* args
*
* for function calls, the ! is replaced by a /
*/
static void
nb_parse_cmd(char_u *cmd)
{
char *verb;
char *q;
int bufno;
int isfunc = -1;
if (STRCMP(cmd, "DISCONNECT") == 0)
{
/* We assume the server knows that we can safely exit! */
/* Disconnect before exiting, Motif hangs in a Select error
* message otherwise. */
netbeans_close();
getout(0);
/* NOTREACHED */
}
if (STRCMP(cmd, "DETACH") == 0)
{
/* The IDE is breaking the connection. */
netbeans_close();
return;
}
bufno = strtol((char *)cmd, &verb, 10);
if (*verb != ':')
{
nbdebug((" missing colon: %s\n", cmd));
EMSG2("E627: missing colon: %s", cmd);
return;
}
++verb; /* skip colon */
for (q = verb; *q; q++)
{
if (*q == '!')
{
*q++ = NUL;
isfunc = 0;
break;
}
else if (*q == '/')
{
*q++ = NUL;
isfunc = 1;
break;
}
}
if (isfunc < 0)
{
nbdebug((" missing ! or / in: %s\n", cmd));
EMSG2("E628: missing ! or / in: %s", cmd);
return;
}
r_cmdno = strtol(q, &q, 10);
q = (char *)skipwhite((char_u *)q);
if (nb_do_cmd(bufno, (char_u *)verb, isfunc, r_cmdno, (char_u *)q) == FAIL)
{
#ifdef NBDEBUG
/*
* This happens because the ExtEd can send a command or 2 after
* doing a stopDocumentListen command. It doesn't harm anything
* so I'm disabling it except for debugging.
*/
nbdebug(("nb_parse_cmd: Command error for \"%s\"\n", cmd));
EMSG("E629: bad return from nb_do_cmd");
#endif
}
}
struct nbbuf_struct
{
buf_T *bufp;
unsigned int fireChanges:1;
unsigned int initDone:1;
unsigned int insertDone:1;
unsigned int modified:1;
int nbbuf_number;
char *displayname;
int *signmap;
short_u signmaplen;
short_u signmapused;
};
typedef struct nbbuf_struct nbbuf_T;
static nbbuf_T *buf_list = NULL;
static int buf_list_size = 0; /* size of buf_list */
static int buf_list_used = 0; /* nr of entries in buf_list actually in use */
static char **globalsignmap = NULL;
static int globalsignmaplen = 0;
static int globalsignmapused = 0;
static int mapsigntype __ARGS((nbbuf_T *, int localsigntype));
static void addsigntype __ARGS((nbbuf_T *, int localsigntype, char_u *typeName,
char_u *tooltip, char_u *glyphfile,
char_u *fg, char_u *bg));
static void print_read_msg __ARGS((nbbuf_T *buf));
static void print_save_msg __ARGS((nbbuf_T *buf, off_t nchars));
static int curPCtype = -1;
/*
* Free netbeans resources.
*/
static void
nb_free()
{
keyQ_T *key_node = keyHead.next;
queue_T *cmd_node = head.next;
nbbuf_T buf;
int i;
/* free the netbeans buffer list */
for (i = 0; i < buf_list_used; i++)
{
buf = buf_list[i];
vim_free(buf.displayname);
vim_free(buf.signmap);
if (buf.bufp != NULL)
{
buf.bufp->b_netbeans_file = FALSE;
buf.bufp->b_was_netbeans_file = FALSE;
}
}
vim_free(buf_list);
buf_list = NULL;
buf_list_size = 0;
buf_list_used = 0;
/* free the queued key commands */
while(key_node != NULL && key_node != &keyHead)
{
keyQ_T *next = key_node->next;
vim_free(key_node->keystr);
vim_free(key_node);
if (next == &keyHead)
{
keyHead.next = &keyHead;
keyHead.prev = &keyHead;
break;
}
key_node = next;
}
/* free the queued netbeans commands */
while(cmd_node != NULL && cmd_node != &head)
{
queue_T *next = cmd_node->next;
vim_free(cmd_node->buffer);
vim_free(cmd_node);
if (next == &head)
{
head.next = &head;
head.prev = &head;
break;
}
cmd_node = next;
}
}
/*
* Get the Netbeans buffer number for the specified buffer.
*/
static int
nb_getbufno(buf_T *bufp)
{
int i;
for (i = 0; i < buf_list_used; i++)
if (buf_list[i].bufp == bufp)
return i;
return -1;
}
/*
* Is this a NetBeans-owned buffer?
*/
int
isNetbeansBuffer(buf_T *bufp)
{
return NETBEANS_OPEN && bufp->b_netbeans_file;
}
/*
* NetBeans and Vim have different undo models. In Vim, the file isn't
* changed if changes are undone via the undo command. In NetBeans, once
* a change has been made the file is marked as modified until saved. It
* doesn't matter if the change was undone.
*
* So this function is for the corner case where Vim thinks a buffer is
* unmodified but NetBeans thinks it IS modified.
*/
int
isNetbeansModified(buf_T *bufp)
{
if (isNetbeansBuffer(bufp))
{
int bufno = nb_getbufno(bufp);
if (bufno > 0)
return buf_list[bufno].modified;
else
return FALSE;
}
else
return FALSE;
}
/*
* Given a Netbeans buffer number, return the netbeans buffer.
* Returns NULL for 0 or a negative number. A 0 bufno means a
* non-buffer related command has been sent.
*/
static nbbuf_T *
nb_get_buf(int bufno)
{
/* find or create a buffer with the given number */
int incr;
if (bufno <= 0)
return NULL;
if (!buf_list)
{
/* initialize */
buf_list = (nbbuf_T *)alloc_clear(100 * sizeof(nbbuf_T));
buf_list_size = 100;
}
if (bufno >= buf_list_used) /* new */
{
if (bufno >= buf_list_size) /* grow list */
{
incr = bufno - buf_list_size + 90;
buf_list_size += incr;
buf_list = (nbbuf_T *)vim_realloc(
buf_list, buf_list_size * sizeof(nbbuf_T));
vim_memset(buf_list + buf_list_size - incr, 0,
incr * sizeof(nbbuf_T));
}
while (buf_list_used <= bufno)
{
/* Default is to fire text changes. */
buf_list[buf_list_used].fireChanges = 1;
++buf_list_used;
}
}
return buf_list + bufno;
}
/*
* Return the number of buffers that are modified.
*/
static int
count_changed_buffers(void)
{
buf_T *bufp;
int n;
n = 0;
for (bufp = firstbuf; bufp != NULL; bufp = bufp->b_next)
if (bufp->b_changed)
++n;
return n;
}
/*
* End the netbeans session.
*/
void
netbeans_end(void)
{
int i;
static char buf[128];
if (!NETBEANS_OPEN)
return;
for (i = 0; i < buf_list_used; i++)
{
if (!buf_list[i].bufp)
continue;
if (netbeansForcedQuit)
{
/* mark as unmodified so NetBeans won't put up dialog on "killed" */
sprintf(buf, "%d:unmodified=%d\n", i, r_cmdno);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_end");
}
sprintf(buf, "%d:killed=%d\n", i, r_cmdno);
nbdebug(("EVT: %s", buf));
/* nb_send(buf, "netbeans_end"); avoid "write failed" messages */
ignored = sock_write(nbsock, buf, (int)STRLEN(buf));
}
}
/*
* Send a message to netbeans.
*/
static void
nb_send(char *buf, char *fun)
{
/* Avoid giving pages full of error messages when the other side has
* exited, only mention the first error until the connection works again. */
static int did_error = FALSE;
if (!NETBEANS_OPEN)
{
if (!did_error)
{
nbdebug((" %s(): write while not connected\n", fun));
EMSG2("E630: %s(): write while not connected", fun);
}
did_error = TRUE;
}
else if (sock_write(nbsock, buf, (int)STRLEN(buf)) != (int)STRLEN(buf))
{
if (!did_error)
{
nbdebug((" %s(): write failed\n", fun));
EMSG2("E631: %s(): write failed", fun);
}
did_error = TRUE;
}
else
did_error = FALSE;
}
/*
* Some input received from netbeans requires a response. This function
* handles a response with no information (except the command number).
*/
static void
nb_reply_nil(int cmdno)
{
char reply[32];
nbdebug(("REP %d: <none>\n", cmdno));
/* Avoid printing an annoying error message. */
if (!NETBEANS_OPEN)
return;
sprintf(reply, "%d\n", cmdno);
nb_send(reply, "nb_reply_nil");
}
/*
* Send a response with text.
* "result" must have been quoted already (using nb_quote()).
*/
static void
nb_reply_text(int cmdno, char_u *result)
{
char_u *reply;
nbdebug(("REP %d: %s\n", cmdno, (char *)result));
reply = alloc((unsigned)STRLEN(result) + 32);
sprintf((char *)reply, "%d %s\n", cmdno, (char *)result);
nb_send((char *)reply, "nb_reply_text");
vim_free(reply);
}
/*
* Send a response with a number result code.
*/
static void
nb_reply_nr(int cmdno, long result)
{
char reply[32];
nbdebug(("REP %d: %ld\n", cmdno, result));
sprintf(reply, "%d %ld\n", cmdno, result);
nb_send(reply, "nb_reply_nr");
}
/*
* Encode newline, ret, backslash, double quote for transmission to NetBeans.
*/
static char_u *
nb_quote(char_u *txt)
{
char_u *buf = alloc((unsigned)(2 * STRLEN(txt) + 1));
char_u *p = txt;
char_u *q = buf;
if (buf == NULL)
return NULL;
for (; *p; p++)
{
switch (*p)
{
case '\"':
case '\\':
*q++ = '\\'; *q++ = *p; break;
/* case '\t': */
/* *q++ = '\\'; *q++ = 't'; break; */
case '\n':
*q++ = '\\'; *q++ = 'n'; break;
case '\r':
*q++ = '\\'; *q++ = 'r'; break;
default:
*q++ = *p;
break;
}
}
*q = '\0';
return buf;
}
/*
* Remove top level double quotes; convert backslashed chars.
* Returns an allocated string (NULL for failure).
* If "endp" is not NULL it is set to the character after the terminating
* quote.
*/
static char *
nb_unquote(char_u *p, char_u **endp)
{
char *result = 0;
char *q;
int done = 0;
/* result is never longer than input */
result = (char *)alloc_clear((unsigned)STRLEN(p) + 1);
if (result == NULL)
return NULL;
if (*p++ != '"')
{
nbdebug(("nb_unquote called with string that doesn't start with a quote!: %s\n",
p));
result[0] = NUL;
return result;
}
for (q = result; !done && *p != NUL;)
{
switch (*p)
{
case '"':
/*
* Unbackslashed dquote marks the end, if first char was dquote.
*/
done = 1;
break;
case '\\':
++p;
switch (*p)
{
case '\\': *q++ = '\\'; break;
case 'n': *q++ = '\n'; break;
case 't': *q++ = '\t'; break;
case 'r': *q++ = '\r'; break;
case '"': *q++ = '"'; break;
case NUL: --p; break;
/* default: skip over illegal chars */
}
++p;
break;
default:
*q++ = *p++;
}
}
if (endp != NULL)
*endp = p;
return result;
}
/*
* Remove from "first" byte to "last" byte (inclusive), at line "lnum" of the
* current buffer. Remove to end of line when "last" is MAXCOL.
*/
static void
nb_partialremove(linenr_T lnum, colnr_T first, colnr_T last)
{
char_u *oldtext, *newtext;
int oldlen;
int lastbyte = last;
oldtext = ml_get(lnum);
oldlen = (int)STRLEN(oldtext);
if (first >= (colnr_T)oldlen || oldlen == 0) /* just in case */
return;
if (lastbyte >= oldlen)
lastbyte = oldlen - 1;
newtext = alloc(oldlen - (int)(lastbyte - first));
if (newtext != NULL)
{
mch_memmove(newtext, oldtext, first);
STRMOVE(newtext + first, oldtext + lastbyte + 1);
nbdebug((" NEW LINE %d: %s\n", lnum, newtext));
ml_replace(lnum, newtext, FALSE);
}
}
/*
* Replace the "first" line with the concatenation of the "first" and
* the "other" line. The "other" line is not removed.
*/
static void
nb_joinlines(linenr_T first, linenr_T other)
{
int len_first, len_other;
char_u *p;
len_first = (int)STRLEN(ml_get(first));
len_other = (int)STRLEN(ml_get(other));
p = alloc((unsigned)(len_first + len_other + 1));
if (p != NULL)
{
mch_memmove(p, ml_get(first), len_first);
mch_memmove(p + len_first, ml_get(other), len_other + 1);
ml_replace(first, p, FALSE);
}
}
#define SKIP_STOP 2
#define streq(a,b) (strcmp(a,b) == 0)
/*
* Do the actual processing of a single netbeans command or function.
* The difference between a command and function is that a function
* gets a response (it's required) but a command does not.
* For arguments see comment for nb_parse_cmd().
*/
static int
nb_do_cmd(
int bufno,
char_u *cmd,
int func,
int cmdno,
char_u *args) /* points to space before arguments or NUL */
{
int do_update = 0;
long off = 0;
nbbuf_T *buf = nb_get_buf(bufno);
static int skip = 0;
int retval = OK;
char *cp; /* for when a char pointer is needed */
nbdebug(("%s %d: (%d) %s %s\n", (func) ? "FUN" : "CMD", cmdno, bufno, cmd,
STRCMP(cmd, "insert") == 0 ? "<text>" : (char *)args));
if (func)
{
/* =====================================================================*/
if (streq((char *)cmd, "getModified"))
{
if (buf == NULL || buf->bufp == NULL)
/* Return the number of buffers that are modified. */
nb_reply_nr(cmdno, (long)count_changed_buffers());
else
/* Return whether the buffer is modified. */
nb_reply_nr(cmdno, (long)(buf->bufp->b_changed
|| isNetbeansModified(buf->bufp)));
/* =====================================================================*/
}
else if (streq((char *)cmd, "saveAndExit"))
{
/* Note: this will exit Vim if successful. */
coloncmd(":confirm qall");
/* We didn't exit: return the number of changed buffers. */
nb_reply_nr(cmdno, (long)count_changed_buffers());
/* =====================================================================*/
}
else if (streq((char *)cmd, "getCursor"))
{
char_u text[200];
/* Note: nb_getbufno() may return -1. This indicates the IDE
* didn't assign a number to the current buffer in response to a
* fileOpened event. */
sprintf((char *)text, "%d %ld %d %ld",
nb_getbufno(curbuf),
(long)curwin->w_cursor.lnum,
(int)curwin->w_cursor.col,
pos2off(curbuf, &curwin->w_cursor));
nb_reply_text(cmdno, text);
/* =====================================================================*/
}
else if (streq((char *)cmd, "getAnno"))
{
long linenum = 0;
#ifdef FEAT_SIGNS
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" Invalid buffer identifier in getAnno\n"));
EMSG("E652: Invalid buffer identifier in getAnno");
retval = FAIL;
}
else
{
int serNum;
cp = (char *)args;
serNum = strtol(cp, &cp, 10);
/* If the sign isn't found linenum will be zero. */
linenum = (long)buf_findsign(buf->bufp, serNum);
}
#endif
nb_reply_nr(cmdno, linenum);
/* =====================================================================*/
}
else if (streq((char *)cmd, "getLength"))
{
long len = 0;
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in getLength\n"));
EMSG("E632: invalid buffer identifier in getLength");
retval = FAIL;
}
else
{
len = get_buf_size(buf->bufp);
}
nb_reply_nr(cmdno, len);
/* =====================================================================*/
}
else if (streq((char *)cmd, "getText"))
{
long len;
linenr_T nlines;
char_u *text = NULL;
linenr_T lno = 1;
char_u *p;
char_u *line;
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in getText\n"));
EMSG("E633: invalid buffer identifier in getText");
retval = FAIL;
}
else
{
len = get_buf_size(buf->bufp);
nlines = buf->bufp->b_ml.ml_line_count;
text = alloc((unsigned)((len > 0)
? ((len + nlines) * 2) : 4));
if (text == NULL)
{
nbdebug((" nb_do_cmd: getText has null text field\n"));
retval = FAIL;
}
else
{
p = text;
*p++ = '\"';
for (; lno <= nlines ; lno++)
{
line = nb_quote(ml_get_buf(buf->bufp, lno, FALSE));
if (line != NULL)
{
STRCPY(p, line);
p += STRLEN(line);
*p++ = '\\';
*p++ = 'n';
vim_free(line);
}
}
*p++ = '\"';
*p = '\0';
}
}
if (text == NULL)
nb_reply_text(cmdno, (char_u *)"");
else
{
nb_reply_text(cmdno, text);
vim_free(text);
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "remove"))
{
long count;
pos_T first, last;
pos_T *pos;
pos_T *next;
linenr_T del_from_lnum, del_to_lnum; /* lines to be deleted as a whole */
int oldFire = netbeansFireChanges;
int oldSuppress = netbeansSuppressNoLines;
int wasChanged;
if (skip >= SKIP_STOP)
{
nbdebug((" Skipping %s command\n", (char *) cmd));
nb_reply_nil(cmdno);
return OK;
}
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in remove\n"));
EMSG("E634: invalid buffer identifier in remove");
retval = FAIL;
}
else
{
netbeansFireChanges = FALSE;
netbeansSuppressNoLines = TRUE;
nb_set_curbuf(buf->bufp);
wasChanged = buf->bufp->b_changed;
cp = (char *)args;
off = strtol(cp, &cp, 10);
count = strtol(cp, &cp, 10);
args = (char_u *)cp;
/* delete "count" chars, starting at "off" */
pos = off2pos(buf->bufp, off);
if (!pos)
{
nbdebug((" !bad position\n"));
nb_reply_text(cmdno, (char_u *)"!bad position");
netbeansFireChanges = oldFire;
netbeansSuppressNoLines = oldSuppress;
return FAIL;
}
first = *pos;
nbdebug((" FIRST POS: line %d, col %d\n",
first.lnum, first.col));
pos = off2pos(buf->bufp, off+count-1);
if (!pos)
{
nbdebug((" !bad count\n"));
nb_reply_text(cmdno, (char_u *)"!bad count");
netbeansFireChanges = oldFire;
netbeansSuppressNoLines = oldSuppress;
return FAIL;
}
last = *pos;
nbdebug((" LAST POS: line %d, col %d\n",
last.lnum, last.col));
del_from_lnum = first.lnum;
del_to_lnum = last.lnum;
do_update = 1;
/* Get the position of the first byte after the deleted
* section. "next" is NULL when deleting to the end of the
* file. */
next = off2pos(buf->bufp, off + count);
/* Remove part of the first line. */
if (first.col != 0
|| (next != NULL && first.lnum == next->lnum))
{
if (first.lnum != last.lnum
|| (next != NULL && first.lnum != next->lnum))
{
/* remove to the end of the first line */
nb_partialremove(first.lnum, first.col,
(colnr_T)MAXCOL);
if (first.lnum == last.lnum)
{
/* Partial line to remove includes the end of
* line. Join the line with the next one, have
* the next line deleted below. */
nb_joinlines(first.lnum, next->lnum);
del_to_lnum = next->lnum;
}
}
else
{
/* remove within one line */
nb_partialremove(first.lnum, first.col, last.col);
}
++del_from_lnum; /* don't delete the first line */
}
/* Remove part of the last line. */
if (first.lnum != last.lnum && next != NULL
&& next->col != 0 && last.lnum == next->lnum)
{
nb_partialremove(last.lnum, 0, last.col);
if (del_from_lnum > first.lnum)
{
/* Join end of last line to start of first line; last
* line is deleted below. */
nb_joinlines(first.lnum, last.lnum);
}
else
/* First line is deleted as a whole, keep the last
* line. */
--del_to_lnum;
}
/* First is partial line; last line to remove includes
* the end of line; join first line to line following last
* line; line following last line is deleted below. */
if (first.lnum != last.lnum && del_from_lnum > first.lnum
&& next != NULL && last.lnum != next->lnum)
{
nb_joinlines(first.lnum, next->lnum);
del_to_lnum = next->lnum;
}
/* Delete whole lines if there are any. */
if (del_to_lnum >= del_from_lnum)
{
int i;
/* delete signs from the lines being deleted */
for (i = del_from_lnum; i <= del_to_lnum; i++)
{
int id = buf_findsign_id(buf->bufp, (linenr_T)i);
if (id > 0)
{
nbdebug((" Deleting sign %d on line %d\n",
id, i));
buf_delsign(buf->bufp, id);
}
else
{
nbdebug((" No sign on line %d\n", i));
}
}
nbdebug((" Deleting lines %d through %d\n",
del_from_lnum, del_to_lnum));
curwin->w_cursor.lnum = del_from_lnum;
curwin->w_cursor.col = 0;
del_lines(del_to_lnum - del_from_lnum + 1, FALSE);
}
/* Leave cursor at first deleted byte. */
curwin->w_cursor = first;
check_cursor_lnum();
buf->bufp->b_changed = wasChanged; /* logically unchanged */
netbeansFireChanges = oldFire;
netbeansSuppressNoLines = oldSuppress;
u_blockfree(buf->bufp);
u_clearall(buf->bufp);
}
nb_reply_nil(cmdno);
/* =====================================================================*/
}
else if (streq((char *)cmd, "insert"))
{
char_u *to_free;
if (skip >= SKIP_STOP)
{
nbdebug((" Skipping %s command\n", (char *) cmd));
nb_reply_nil(cmdno);
return OK;
}
/* get offset */
cp = (char *)args;
off = strtol(cp, &cp, 10);
args = (char_u *)cp;
/* get text to be inserted */
args = skipwhite(args);
args = to_free = (char_u *)nb_unquote(args, NULL);
/*
nbdebug((" CHUNK[%d]: %d bytes at offset %d\n",
buf->bufp->b_ml.ml_line_count, STRLEN(args), off));
*/
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in insert\n"));
EMSG("E635: invalid buffer identifier in insert");
retval = FAIL;
}
else if (args != NULL)
{
int ff_detected = EOL_UNKNOWN;
int buf_was_empty = (buf->bufp->b_ml.ml_flags & ML_EMPTY);
size_t len = 0;
int added = 0;
int oldFire = netbeansFireChanges;
int old_b_changed;
char_u *nlp;
linenr_T lnum;
linenr_T lnum_start;
pos_T *pos;
netbeansFireChanges = 0;
/* Jump to the buffer where we insert. After this "curbuf"
* can be used. */
nb_set_curbuf(buf->bufp);
old_b_changed = curbuf->b_changed;
/* Convert the specified character offset into a lnum/col
* position. */
pos = off2pos(curbuf, off);
if (pos != NULL)
{
if (pos->lnum <= 0)
lnum_start = 1;
else
lnum_start = pos->lnum;
}
else
{
/* If the given position is not found, assume we want
* the end of the file. See setLocAndSize HACK. */
if (buf_was_empty)
lnum_start = 1; /* above empty line */
else
lnum_start = curbuf->b_ml.ml_line_count + 1;
}
/* "lnum" is the line where we insert: either append to it or
* insert a new line above it. */
lnum = lnum_start;
/* Loop over the "\n" separated lines of the argument. */
do_update = 1;
while (*args != NUL)
{
nlp = vim_strchr(args, '\n');
if (nlp == NULL)
{
/* Incomplete line, probably truncated. Next "insert"
* command should append to this one. */
len = STRLEN(args);
}
else
{
len = nlp - args;
/*
* We need to detect EOL style, because the commands
* use a character offset.
*/
if (nlp > args && nlp[-1] == '\r')
{
ff_detected = EOL_DOS;
--len;
}
else
ff_detected = EOL_UNIX;
}
args[len] = NUL;
if (lnum == lnum_start
&& ((pos != NULL && pos->col > 0)
|| (lnum == 1 && buf_was_empty)))
{
char_u *oldline = ml_get(lnum);
char_u *newline;
/* Insert halfway a line. */
newline = alloc_check(
(unsigned)(STRLEN(oldline) + len + 1));
if (newline != NULL)
{
mch_memmove(newline, oldline, (size_t)pos->col);
newline[pos->col] = NUL;
STRCAT(newline, args);
STRCAT(newline, oldline + pos->col);
ml_replace(lnum, newline, FALSE);
}
}
else
{
/* Append a new line. Not that we always do this,
* also when the text doesn't end in a "\n". */
ml_append((linenr_T)(lnum - 1), args,
(colnr_T)(len + 1), FALSE);
++added;
}
if (nlp == NULL)
break;
++lnum;
args = nlp + 1;
}
/* Adjust the marks below the inserted lines. */
appended_lines_mark(lnum_start - 1, (long)added);
/*
* When starting with an empty buffer set the fileformat.
* This is just guessing...
*/
if (buf_was_empty)
{
if (ff_detected == EOL_UNKNOWN)
#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
ff_detected = EOL_DOS;
#else
ff_detected = EOL_UNIX;
#endif
set_fileformat(ff_detected, OPT_LOCAL);
curbuf->b_start_ffc = *curbuf->b_p_ff;
}
/*
* XXX - GRP - Is the next line right? If I've inserted
* text the buffer has been updated but not written. Will
* netbeans guarantee to write it? Even if I do a :q! ?
*/
curbuf->b_changed = old_b_changed; /* logically unchanged */
netbeansFireChanges = oldFire;
/* Undo info is invalid now... */
u_blockfree(curbuf);
u_clearall(curbuf);
}
vim_free(to_free);
nb_reply_nil(cmdno); /* or !error */
}
else
{
nbdebug(("UNIMPLEMENTED FUNCTION: %s\n", cmd));
nb_reply_nil(cmdno);
retval = FAIL;
}
}
else /* Not a function; no reply required. */
{
/* =====================================================================*/
if (streq((char *)cmd, "create"))
{
/* Create a buffer without a name. */
if (buf == NULL)
{
nbdebug((" invalid buffer identifier in create\n"));
EMSG("E636: invalid buffer identifier in create");
return FAIL;
}
vim_free(buf->displayname);
buf->displayname = NULL;
netbeansReadFile = 0; /* don't try to open disk file */
do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF, curwin);
netbeansReadFile = 1;
buf->bufp = curbuf;
maketitle();
buf->insertDone = FALSE;
#if defined(FEAT_MENU) && defined(FEAT_GUI)
if (gui.in_use)
gui_update_menus(0);
#endif
/* =====================================================================*/
}
else if (streq((char *)cmd, "insertDone"))
{
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in insertDone\n"));
}
else
{
buf->bufp->b_start_eol = *args == 'T';
buf->insertDone = TRUE;
args += 2;
buf->bufp->b_p_ro = *args == 'T';
print_read_msg(buf);
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "saveDone"))
{
long savedChars = atol((char *)args);
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in saveDone\n"));
}
else
print_save_msg(buf, savedChars);
/* =====================================================================*/
}
else if (streq((char *)cmd, "startDocumentListen"))
{
if (buf == NULL)
{
nbdebug((" invalid buffer identifier in startDocumentListen\n"));
EMSG("E637: invalid buffer identifier in startDocumentListen");
return FAIL;
}
buf->fireChanges = 1;
/* =====================================================================*/
}
else if (streq((char *)cmd, "stopDocumentListen"))
{
if (buf == NULL)
{
nbdebug((" invalid buffer identifier in stopDocumentListen\n"));
EMSG("E638: invalid buffer identifier in stopDocumentListen");
return FAIL;
}
buf->fireChanges = 0;
if (buf->bufp != NULL && buf->bufp->b_was_netbeans_file)
{
if (!buf->bufp->b_netbeans_file)
{
nbdebug(("E658: NetBeans connection lost for buffer %ld\n", buf->bufp->b_fnum));
EMSGN(_("E658: NetBeans connection lost for buffer %ld"),
buf->bufp->b_fnum);
}
else
{
/* NetBeans uses stopDocumentListen when it stops editing
* a file. It then expects the buffer in Vim to
* disappear. */
do_bufdel(DOBUF_DEL, (char_u *)"", 1,
buf->bufp->b_fnum, buf->bufp->b_fnum, TRUE);
vim_memset(buf, 0, sizeof(nbbuf_T));
}
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "setTitle"))
{
if (buf == NULL)
{
nbdebug((" invalid buffer identifier in setTitle\n"));
EMSG("E639: invalid buffer identifier in setTitle");
return FAIL;
}
vim_free(buf->displayname);
buf->displayname = nb_unquote(args, NULL);
/* =====================================================================*/
}
else if (streq((char *)cmd, "initDone"))
{
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in initDone\n"));
EMSG("E640: invalid buffer identifier in initDone");
return FAIL;
}
do_update = 1;
buf->initDone = TRUE;
nb_set_curbuf(buf->bufp);
#if defined(FEAT_AUTOCMD)
apply_autocmds(EVENT_BUFREADPOST, 0, 0, FALSE, buf->bufp);
#endif
/* handle any postponed key commands */
handle_key_queue();
/* =====================================================================*/
}
else if (streq((char *)cmd, "setBufferNumber")
|| streq((char *)cmd, "putBufferNumber"))
{
char_u *path;
buf_T *bufp;
if (buf == NULL)
{
nbdebug((" invalid buffer identifier in setBufferNumber\n"));
EMSG("E641: invalid buffer identifier in setBufferNumber");
return FAIL;
}
path = (char_u *)nb_unquote(args, NULL);
if (path == NULL)
return FAIL;
bufp = buflist_findname(path);
vim_free(path);
if (bufp == NULL)
{
nbdebug((" File %s not found in setBufferNumber\n", args));
EMSG2("E642: File %s not found in setBufferNumber", args);
return FAIL;
}
buf->bufp = bufp;
buf->nbbuf_number = bufp->b_fnum;
/* "setBufferNumber" has the side effect of jumping to the buffer
* (don't know why!). Don't do that for "putBufferNumber". */
if (*cmd != 'p')
coloncmd(":buffer %d", bufp->b_fnum);
else
{
buf->initDone = TRUE;
/* handle any postponed key commands */
handle_key_queue();
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "setFullName"))
{
if (buf == NULL)
{
nbdebug((" invalid buffer identifier in setFullName\n"));
EMSG("E643: invalid buffer identifier in setFullName");
return FAIL;
}
vim_free(buf->displayname);
buf->displayname = nb_unquote(args, NULL);
netbeansReadFile = 0; /* don't try to open disk file */
do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE,
ECMD_HIDE + ECMD_OLDBUF, curwin);
netbeansReadFile = 1;
buf->bufp = curbuf;
maketitle();
#if defined(FEAT_MENU) && defined(FEAT_GUI)
if (gui.in_use)
gui_update_menus(0);
#endif
/* =====================================================================*/
}
else if (streq((char *)cmd, "editFile"))
{
if (buf == NULL)
{
nbdebug((" invalid buffer identifier in editFile\n"));
EMSG("E644: invalid buffer identifier in editFile");
return FAIL;
}
/* Edit a file: like create + setFullName + read the file. */
vim_free(buf->displayname);
buf->displayname = nb_unquote(args, NULL);
do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE,
ECMD_HIDE + ECMD_OLDBUF, curwin);
buf->bufp = curbuf;
buf->initDone = TRUE;
do_update = 1;
#if defined(FEAT_TITLE)
maketitle();
#endif
#if defined(FEAT_MENU) && defined(FEAT_GUI)
if (gui.in_use)
gui_update_menus(0);
#endif
/* =====================================================================*/
}
else if (streq((char *)cmd, "setVisible"))
{
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in setVisible\n"));
/* This message was commented out, probably because it can
* happen when shutting down. */
if (p_verbose > 0)
EMSG("E645: invalid buffer identifier in setVisible");
return FAIL;
}
if (streq((char *)args, "T") && buf->bufp != curbuf)
{
exarg_T exarg;
exarg.cmd = (char_u *)"goto";
exarg.forceit = FALSE;
dosetvisible = TRUE;
goto_buffer(&exarg, DOBUF_FIRST, FORWARD, buf->bufp->b_fnum);
do_update = 1;
dosetvisible = FALSE;
#ifdef FEAT_GUI
/* Side effect!!!. */
if (gui.in_use)
gui_mch_set_foreground();
#endif
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "raise"))
{
#ifdef FEAT_GUI
/* Bring gvim to the foreground. */
if (gui.in_use)
gui_mch_set_foreground();
#endif
/* =====================================================================*/
}
else if (streq((char *)cmd, "setModified"))
{
int prev_b_changed;
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in setModified\n"));
/* This message was commented out, probably because it can
* happen when shutting down. */
if (p_verbose > 0)
EMSG("E646: invalid buffer identifier in setModified");
return FAIL;
}
prev_b_changed = buf->bufp->b_changed;
if (streq((char *)args, "T"))
buf->bufp->b_changed = TRUE;
else
{
struct stat st;
/* Assume NetBeans stored the file. Reset the timestamp to
* avoid "file changed" warnings. */
if (buf->bufp->b_ffname != NULL
&& mch_stat((char *)buf->bufp->b_ffname, &st) >= 0)
buf_store_time(buf->bufp, &st, buf->bufp->b_ffname);
buf->bufp->b_changed = FALSE;
}
buf->modified = buf->bufp->b_changed;
if (prev_b_changed != buf->bufp->b_changed)
{
#ifdef FEAT_WINDOWS
check_status(buf->bufp);
redraw_tabline = TRUE;
#endif
#ifdef FEAT_TITLE
maketitle();
#endif
update_screen(0);
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "setModtime"))
{
if (buf == NULL || buf->bufp == NULL)
nbdebug((" invalid buffer identifier in setModtime\n"));
else
buf->bufp->b_mtime = atoi((char *)args);
/* =====================================================================*/
}
else if (streq((char *)cmd, "setReadOnly"))
{
if (buf == NULL || buf->bufp == NULL)
nbdebug((" invalid buffer identifier in setReadOnly\n"));
else if (streq((char *)args, "T"))
buf->bufp->b_p_ro = TRUE;
else
buf->bufp->b_p_ro = FALSE;
/* =====================================================================*/
}
else if (streq((char *)cmd, "setMark"))
{
/* not yet */
/* =====================================================================*/
}
else if (streq((char *)cmd, "showBalloon"))
{
#if defined(FEAT_BEVAL)
static char *text = NULL;
/*
* Set up the Balloon Expression Evaluation area.
* Ignore 'ballooneval' here.
* The text pointer must remain valid for a while.
*/
if (balloonEval != NULL)
{
vim_free(text);
text = nb_unquote(args, NULL);
if (text != NULL)
gui_mch_post_balloon(balloonEval, (char_u *)text);
}
#endif
/* =====================================================================*/
}
else if (streq((char *)cmd, "setDot"))
{
pos_T *pos;
#ifdef NBDEBUG
char_u *s;
#endif
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in setDot\n"));
EMSG("E647: invalid buffer identifier in setDot");
return FAIL;
}
nb_set_curbuf(buf->bufp);
#ifdef FEAT_VISUAL
/* Don't want Visual mode now. */
if (VIsual_active)
end_visual_mode();
#endif
#ifdef NBDEBUG
s = args;
#endif
pos = get_off_or_lnum(buf->bufp, &args);
if (pos)
{
curwin->w_cursor = *pos;
check_cursor();
#ifdef FEAT_FOLDING
foldOpenCursor();
#endif
}
else
{
nbdebug((" BAD POSITION in setDot: %s\n", s));
}
/* gui_update_cursor(TRUE, FALSE); */
/* update_curbuf(NOT_VALID); */
update_topline(); /* scroll to show the line */
update_screen(VALID);
setcursor();
cursor_on();
out_flush();
#ifdef FEAT_GUI
if (gui.in_use)
{
gui_update_cursor(TRUE, FALSE);
gui_mch_flush();
}
#endif
/* Quit a hit-return or more prompt. */
if (State == HITRETURN || State == ASKMORE)
{
#ifdef FEAT_GUI_GTK
if (gui.in_use && gtk_main_level() > 0)
gtk_main_quit();
#endif
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "close"))
{
#ifdef NBDEBUG
char *name = "<NONE>";
#endif
if (buf == NULL)
{
nbdebug((" invalid buffer identifier in close\n"));
EMSG("E648: invalid buffer identifier in close");
return FAIL;
}
#ifdef NBDEBUG
if (buf->displayname != NULL)
name = buf->displayname;
#endif
if (buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in close\n"));
/* This message was commented out, probably because it can
* happen when shutting down. */
if (p_verbose > 0)
EMSG("E649: invalid buffer identifier in close");
}
nbdebug((" CLOSE %d: %s\n", bufno, name));
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
if (buf->bufp != NULL)
do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD,
buf->bufp->b_fnum, TRUE);
buf->bufp = NULL;
buf->initDone = FALSE;
do_update = 1;
/* =====================================================================*/
}
else if (streq((char *)cmd, "setStyle")) /* obsolete... */
{
nbdebug((" setStyle is obsolete!\n"));
/* =====================================================================*/
}
else if (streq((char *)cmd, "setExitDelay"))
{
/* Only used in version 2.1. */
/* =====================================================================*/
}
else if (streq((char *)cmd, "defineAnnoType"))
{
#ifdef FEAT_SIGNS
int typeNum;
char_u *typeName;
char_u *tooltip;
char_u *p;
char_u *glyphFile;
int parse_error = FALSE;
char_u *fg;
char_u *bg;
if (buf == NULL)
{
nbdebug((" invalid buffer identifier in defineAnnoType\n"));
EMSG("E650: invalid buffer identifier in defineAnnoType");
return FAIL;
}
cp = (char *)args;
typeNum = strtol(cp, &cp, 10);
args = (char_u *)cp;
args = skipwhite(args);
typeName = (char_u *)nb_unquote(args, &args);
args = skipwhite(args + 1);
tooltip = (char_u *)nb_unquote(args, &args);
args = skipwhite(args + 1);
p = (char_u *)nb_unquote(args, &args);
glyphFile = vim_strsave_escaped(p, escape_chars);
vim_free(p);
args = skipwhite(args + 1);
p = skiptowhite(args);
if (*p != NUL)
{
*p = NUL;
p = skipwhite(p + 1);
}
fg = vim_strsave(args);
bg = vim_strsave(p);
if (STRLEN(fg) > MAX_COLOR_LENGTH || STRLEN(bg) > MAX_COLOR_LENGTH)
{
EMSG("E532: highlighting color name too long in defineAnnoType");
vim_free(typeName);
parse_error = TRUE;
}
else if (typeName != NULL && tooltip != NULL && glyphFile != NULL)
addsigntype(buf, typeNum, typeName, tooltip, glyphFile, fg, bg);
else
vim_free(typeName);
/* don't free typeName; it's used directly in addsigntype() */
vim_free(fg);
vim_free(bg);
vim_free(tooltip);
vim_free(glyphFile);
if (parse_error)
return FAIL;
#endif
/* =====================================================================*/
}
else if (streq((char *)cmd, "addAnno"))
{
#ifdef FEAT_SIGNS
int serNum;
int localTypeNum;
int typeNum;
pos_T *pos;
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in addAnno\n"));
EMSG("E651: invalid buffer identifier in addAnno");
return FAIL;
}
do_update = 1;
cp = (char *)args;
serNum = strtol(cp, &cp, 10);
/* Get the typenr specific for this buffer and convert it to
* the global typenumber, as used for the sign name. */
localTypeNum = strtol(cp, &cp, 10);
args = (char_u *)cp;
typeNum = mapsigntype(buf, localTypeNum);
pos = get_off_or_lnum(buf->bufp, &args);
cp = (char *)args;
ignored = (int)strtol(cp, &cp, 10);
args = (char_u *)cp;
# ifdef NBDEBUG
if (ignored != -1)
{
nbdebug((" partial line annotation -- Not Yet Implemented!\n"));
}
# endif
if (serNum >= GUARDEDOFFSET)
{
nbdebug((" too many annotations! ignoring...\n"));
return FAIL;
}
if (pos)
{
coloncmd(":sign place %d line=%ld name=%d buffer=%d",
serNum, pos->lnum, typeNum, buf->bufp->b_fnum);
if (typeNum == curPCtype)
coloncmd(":sign jump %d buffer=%d", serNum,
buf->bufp->b_fnum);
}
#endif
/* =====================================================================*/
}
else if (streq((char *)cmd, "removeAnno"))
{
#ifdef FEAT_SIGNS
int serNum;
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in removeAnno\n"));
return FAIL;
}
do_update = 1;
cp = (char *)args;
serNum = strtol(cp, &cp, 10);
args = (char_u *)cp;
coloncmd(":sign unplace %d buffer=%d",
serNum, buf->bufp->b_fnum);
redraw_buf_later(buf->bufp, NOT_VALID);
#endif
/* =====================================================================*/
}
else if (streq((char *)cmd, "moveAnnoToFront"))
{
#ifdef FEAT_SIGNS
nbdebug((" moveAnnoToFront: Not Yet Implemented!\n"));
#endif
/* =====================================================================*/
}
else if (streq((char *)cmd, "guard") || streq((char *)cmd, "unguard"))
{
int len;
pos_T first;
pos_T last;
pos_T *pos;
int un = (cmd[0] == 'u');
static int guardId = GUARDEDOFFSET;
if (skip >= SKIP_STOP)
{
nbdebug((" Skipping %s command\n", (char *) cmd));
return OK;
}
nb_init_graphics();
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in %s command\n", cmd));
return FAIL;
}
nb_set_curbuf(buf->bufp);
cp = (char *)args;
off = strtol(cp, &cp, 10);
len = strtol(cp, NULL, 10);
args = (char_u *)cp;
pos = off2pos(buf->bufp, off);
do_update = 1;
if (!pos)
nbdebug((" no such start pos in %s, %ld\n", cmd, off));
else
{
first = *pos;
pos = off2pos(buf->bufp, off + len - 1);
if (pos != NULL && pos->col == 0)
{
/*
* In Java Swing the offset is a position between 2
* characters. If col == 0 then we really want the
* previous line as the end.
*/
pos = off2pos(buf->bufp, off + len - 2);
}
if (!pos)
nbdebug((" no such end pos in %s, %ld\n",
cmd, off + len - 1));
else
{
long lnum;
last = *pos;
/* set highlight for region */
nbdebug((" %sGUARD %ld,%d to %ld,%d\n", (un) ? "UN" : "",
first.lnum, first.col,
last.lnum, last.col));
#ifdef FEAT_SIGNS
for (lnum = first.lnum; lnum <= last.lnum; lnum++)
{
if (un)
{
/* never used */
}
else
{
if (buf_findsigntype_id(buf->bufp, lnum,
GUARDED) == 0)
{
coloncmd(
":sign place %d line=%ld name=%d buffer=%d",
guardId++, lnum, GUARDED,
buf->bufp->b_fnum);
}
}
}
#endif
redraw_buf_later(buf->bufp, NOT_VALID);
}
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "startAtomic"))
{
inAtomic = 1;
/* =====================================================================*/
}
else if (streq((char *)cmd, "endAtomic"))
{
inAtomic = 0;
if (needupdate)
{
do_update = 1;
needupdate = 0;
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "save"))
{
/*
* NOTE - This command is obsolete wrt NetBeans. Its left in
* only for historical reasons.
*/
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in %s command\n", cmd));
return FAIL;
}
/* the following is taken from ex_cmds.c (do_wqall function) */
if (bufIsChanged(buf->bufp))
{
/* Only write if the buffer can be written. */
if (p_write
&& !buf->bufp->b_p_ro
&& buf->bufp->b_ffname != NULL
#ifdef FEAT_QUICKFIX
&& !bt_dontwrite(buf->bufp)
#endif
)
{
buf_write_all(buf->bufp, FALSE);
#ifdef FEAT_AUTOCMD
/* an autocommand may have deleted the buffer */
if (!buf_valid(buf->bufp))
buf->bufp = NULL;
#endif
}
}
else
{
nbdebug((" Buffer has no changes!\n"));
}
/* =====================================================================*/
}
else if (streq((char *)cmd, "netbeansBuffer"))
{
if (buf == NULL || buf->bufp == NULL)
{
nbdebug((" invalid buffer identifier in %s command\n", cmd));
return FAIL;
}
if (*args == 'T')
{
buf->bufp->b_netbeans_file = TRUE;
buf->bufp->b_was_netbeans_file = TRUE;
}
else
buf->bufp->b_netbeans_file = FALSE;
/* =====================================================================*/
}
else if (streq((char *)cmd, "specialKeys"))
{
special_keys(args);
/* =====================================================================*/
}
else if (streq((char *)cmd, "actionMenuItem"))
{
/* not used yet */
/* =====================================================================*/
}
else if (streq((char *)cmd, "version"))
{
/* not used yet */
}
else
{
nbdebug(("Unrecognised command: %s\n", cmd));
}
/*
* Unrecognized command is ignored.
*/
}
if (inAtomic && do_update)
{
needupdate = 1;
do_update = 0;
}
/*
* Is this needed? I moved the netbeans_Xt_connect() later during startup
* and it may no longer be necessary. If its not needed then needupdate
* and do_update can also be removed.
*/
if (buf != NULL && buf->initDone && do_update)
{
update_screen(NOT_VALID);
setcursor();
cursor_on();
out_flush();
#ifdef FEAT_GUI
if (gui.in_use)
{
gui_update_cursor(TRUE, FALSE);
gui_mch_flush();
}
#endif
/* Quit a hit-return or more prompt. */
if (State == HITRETURN || State == ASKMORE)
{
#ifdef FEAT_GUI_GTK
if (gui.in_use && gtk_main_level() > 0)
gtk_main_quit();
#endif
}
}
return retval;
}
/*
* If "buf" is not the current buffer try changing to a window that edits this
* buffer. If there is no such window then close the current buffer and set
* the current buffer as "buf".
*/
static void
nb_set_curbuf(buf_T *buf)
{
if (curbuf != buf && buf_jump_open_win(buf) == NULL)
set_curbuf(buf, DOBUF_GOTO);
}
/*
* Process a vim colon command.
*/
static void
coloncmd(char *cmd, ...)
{
char buf[1024];
va_list ap;
va_start(ap, cmd);
vim_vsnprintf(buf, sizeof(buf), cmd, ap, NULL);
va_end(ap);
nbdebug((" COLONCMD %s\n", buf));
/* ALT_INPUT_LOCK_ON; */
do_cmdline((char_u *)buf, NULL, NULL, DOCMD_NOWAIT | DOCMD_KEYTYPED);
/* ALT_INPUT_LOCK_OFF; */
setcursor(); /* restore the cursor position */
out_flush(); /* make sure output has been written */
#ifdef FEAT_GUI
if (gui.in_use)
{
gui_update_cursor(TRUE, FALSE);
gui_mch_flush();
}
#endif
}
/*
* Parse the specialKeys argument and issue the appropriate map commands.
*/
static void
special_keys(char_u *args)
{
char *save_str = nb_unquote(args, NULL);
char *tok = strtok(save_str, " ");
char *sep;
char keybuf[64];
char cmdbuf[256];
while (tok != NULL)
{
int i = 0;
if ((sep = strchr(tok, '-')) != NULL)
{
*sep = NUL;
while (*tok)
{
switch (*tok)
{
case 'A':
case 'M':
case 'C':
case 'S':
keybuf[i++] = *tok;
keybuf[i++] = '-';
break;
}
tok++;
}
tok++;
}
strcpy(&keybuf[i], tok);
vim_snprintf(cmdbuf, sizeof(cmdbuf),
"<silent><%s> :nbkey %s<CR>", keybuf, keybuf);
do_map(0, (char_u *)cmdbuf, NORMAL, FALSE);
tok = strtok(NULL, " ");
}
vim_free(save_str);
}
void
ex_nbclose(eap)
exarg_T *eap UNUSED;
{
netbeans_close();
}
void
ex_nbkey(eap)
exarg_T *eap;
{
(void)netbeans_keystring(eap->arg);
}
void
ex_nbstart(eap)
exarg_T *eap;
{
#ifdef FEAT_GUI
# if !defined(FEAT_GUI_X11) && !defined(FEAT_GUI_GTK) \
&& !defined(FEAT_GUI_W32)
if (gui.in_use)
{
EMSG(_("E838: netbeans is not supported with this GUI"));
return;
}
# endif
#endif
netbeans_open((char *)eap->arg, FALSE);
}
/*
* Initialize highlights and signs for use by netbeans (mostly obsolete)
*/
static void
nb_init_graphics(void)
{
static int did_init = FALSE;
if (!did_init)
{
coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"
" ctermbg=LightCyan ctermfg=Black");
coloncmd(":sign define %d linehl=NBGuarded", GUARDED);
did_init = TRUE;
}
}
/*
* Convert key to netbeans name. This uses the global "mod_mask".
*/
static void
netbeans_keyname(int key, char *buf)
{
char *name = 0;
char namebuf[2];
int ctrl = 0;
int shift = 0;
int alt = 0;
if (mod_mask & MOD_MASK_CTRL)
ctrl = 1;
if (mod_mask & MOD_MASK_SHIFT)
shift = 1;
if (mod_mask & MOD_MASK_ALT)
alt = 1;
switch (key)
{
case K_F1: name = "F1"; break;
case K_S_F1: name = "F1"; shift = 1; break;
case K_F2: name = "F2"; break;
case K_S_F2: name = "F2"; shift = 1; break;
case K_F3: name = "F3"; break;
case K_S_F3: name = "F3"; shift = 1; break;
case K_F4: name = "F4"; break;
case K_S_F4: name = "F4"; shift = 1; break;
case K_F5: name = "F5"; break;
case K_S_F5: name = "F5"; shift = 1; break;
case K_F6: name = "F6"; break;
case K_S_F6: name = "F6"; shift = 1; break;
case K_F7: name = "F7"; break;
case K_S_F7: name = "F7"; shift = 1; break;
case K_F8: name = "F8"; break;
case K_S_F8: name = "F8"; shift = 1; break;
case K_F9: name = "F9"; break;
case K_S_F9: name = "F9"; shift = 1; break;
case K_F10: name = "F10"; break;
case K_S_F10: name = "F10"; shift = 1; break;
case K_F11: name = "F11"; break;
case K_S_F11: name = "F11"; shift = 1; break;
case K_F12: name = "F12"; break;
case K_S_F12: name = "F12"; shift = 1; break;
default:
if (key >= ' ' && key <= '~')
{
/* Allow ASCII characters. */
name = namebuf;
namebuf[0] = key;
namebuf[1] = NUL;
}
else
name = "X";
break;
}
buf[0] = '\0';
if (ctrl)
strcat(buf, "C");
if (shift)
strcat(buf, "S");
if (alt)
strcat(buf, "M"); /* META */
if (ctrl || shift || alt)
strcat(buf, "-");
strcat(buf, name);
}
#if defined(FEAT_BEVAL) || defined(PROTO)
/*
* Function to be called for balloon evaluation. Grabs the text under the
* cursor and sends it to the debugger for evaluation. The debugger should
* respond with a showBalloon command when there is a useful result.
*/
void
netbeans_beval_cb(
BalloonEval *beval,
int state UNUSED)
{
win_T *wp;
char_u *text;
linenr_T lnum;
int col;
char *buf;
char_u *p;
/* Don't do anything when 'ballooneval' is off, messages scrolled the
* windows up or we have no connection. */
if (!p_beval || msg_scrolled > 0 || !NETBEANS_OPEN)
return;
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK)
{
/* Send debugger request. Only when the text is of reasonable
* length. */
if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
{
buf = (char *)alloc(MAXPATHL * 2 + 25);
if (buf != NULL)
{
p = nb_quote(text);
if (p != NULL)
{
vim_snprintf(buf, MAXPATHL * 2 + 25,
"0:balloonText=%d \"%s\"\n", r_cmdno, p);
vim_free(p);
}
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_beval_cb");
vim_free(buf);
}
}
vim_free(text);
}
}
#endif
/*
* Return TRUE when the netbeans connection is closed.
*/
int
netbeans_active(void)
{
return NETBEANS_OPEN;
}
/*
* Return netbeans file descriptor.
*/
int
netbeans_filedesc(void)
{
return nbsock;
}
#if defined(FEAT_GUI) || defined(PROTO)
/*
* Register our file descriptor with the gui event handling system.
*/
void
netbeans_gui_register(void)
{
if (!NB_HAS_GUI || !NETBEANS_OPEN)
return;
# ifdef FEAT_GUI_X11
/* tell notifier we are interested in being called
* when there is input on the editor connection socket
*/
if (inputHandler == (XtInputId)NULL)
inputHandler = XtAppAddInput((XtAppContext)app_context, nbsock,
(XtPointer)(XtInputReadMask + XtInputExceptMask),
messageFromNetbeans, NULL);
# else
# ifdef FEAT_GUI_GTK
/*
* Tell gdk we are interested in being called when there
* is input on the editor connection socket
*/
if (inputHandler == 0)
inputHandler = gdk_input_add((gint)nbsock, (GdkInputCondition)
((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION),
messageFromNetbeans, NULL);
# else
# ifdef FEAT_GUI_W32
/*
* Tell Windows we are interested in receiving message when there
* is input on the editor connection socket
*/
if (inputHandler == -1)
inputHandler = WSAAsyncSelect(nbsock, s_hwnd, WM_NETBEANS, FD_READ);
# endif
# endif
# endif
# ifdef FEAT_BEVAL
bevalServers |= BEVAL_NETBEANS;
# endif
}
#endif
/*
* Tell netbeans that the window was opened, ready for commands.
*/
void
netbeans_open(char *params, int doabort)
{
char *cmd = "0:startupDone=0\n";
if (NETBEANS_OPEN)
{
EMSG(_("E511: netbeans already connected"));
return;
}
if (netbeans_connect(params, doabort) != OK)
return;
#ifdef FEAT_GUI
netbeans_gui_register();
#endif
nbdebug(("EVT: %s", cmd));
nb_send(cmd, "netbeans_startup_done");
/* update the screen after having added the gutter */
changed_window_setting();
update_screen(CLEAR);
setcursor();
cursor_on();
out_flush();
#ifdef FEAT_GUI
if (gui.in_use)
{
gui_update_cursor(TRUE, FALSE);
gui_mch_flush();
}
#endif
}
/*
* Tell netbeans that we're exiting. This should be called right
* before calling exit.
*/
void
netbeans_send_disconnect()
{
char buf[128];
if (NETBEANS_OPEN)
{
sprintf(buf, "0:disconnect=%d\n", r_cmdno);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_disconnect");
}
}
#if defined(FEAT_GUI_X11) || defined(FEAT_GUI_W32) || defined(PROTO)
/*
* Tell netbeans that the window was moved or resized.
*/
void
netbeans_frame_moved(int new_x, int new_y)
{
char buf[128];
if (!NETBEANS_OPEN)
return;
sprintf(buf, "0:geometry=%d %d %d %d %d\n",
r_cmdno, (int)Columns, (int)Rows, new_x, new_y);
/*nbdebug(("EVT: %s", buf)); happens too many times during a move */
nb_send(buf, "netbeans_frame_moved");
}
#endif
/*
* Tell netbeans the user opened or activated a file.
*/
void
netbeans_file_activated(buf_T *bufp)
{
int bufno = nb_getbufno(bufp);
nbbuf_T *bp = nb_get_buf(bufno);
char buffer[2*MAXPATHL];
char_u *q;
if (!NETBEANS_OPEN || !bufp->b_netbeans_file || dosetvisible)
return;
q = nb_quote(bufp->b_ffname);
if (q == NULL || bp == NULL)
return;
vim_snprintf(buffer, sizeof(buffer), "%d:fileOpened=%d \"%s\" %s %s\n",
bufno,
bufno,
(char *)q,
"T", /* open in NetBeans */
"F"); /* modified */
vim_free(q);
nbdebug(("EVT: %s", buffer));
nb_send(buffer, "netbeans_file_opened");
}
/*
* Tell netbeans the user opened a file.
*/
void
netbeans_file_opened(buf_T *bufp)
{
int bufno = nb_getbufno(bufp);
char buffer[2*MAXPATHL];
char_u *q;
nbbuf_T *bp = nb_get_buf(nb_getbufno(bufp));
int bnum;
if (!NETBEANS_OPEN)
return;
q = nb_quote(bufp->b_ffname);
if (q == NULL)
return;
if (bp != NULL)
bnum = bufno;
else
bnum = 0;
vim_snprintf(buffer, sizeof(buffer), "%d:fileOpened=%d \"%s\" %s %s\n",
bnum,
0,
(char *)q,
"T", /* open in NetBeans */
"F"); /* modified */
vim_free(q);
nbdebug(("EVT: %s", buffer));
nb_send(buffer, "netbeans_file_opened");
if (p_acd && vim_chdirfile(bufp->b_ffname) == OK)
shorten_fnames(TRUE);
}
/*
* Tell netbeans that a file was deleted or wiped out.
*/
void
netbeans_file_killed(buf_T *bufp)
{
int bufno = nb_getbufno(bufp);
nbbuf_T *nbbuf = nb_get_buf(bufno);
char buffer[2*MAXPATHL];
if (!NETBEANS_OPEN || bufno == -1)
return;
nbdebug(("netbeans_file_killed:\n"));
nbdebug((" Killing bufno: %d", bufno));
sprintf(buffer, "%d:killed=%d\n", bufno, r_cmdno);
nbdebug(("EVT: %s", buffer));
nb_send(buffer, "netbeans_file_killed");
if (nbbuf != NULL)
nbbuf->bufp = NULL;
}
/*
* Get a pointer to the Netbeans buffer for Vim buffer "bufp".
* Return NULL if there is no such buffer or changes are not to be reported.
* Otherwise store the buffer number in "*bufnop".
*/
static nbbuf_T *
nb_bufp2nbbuf_fire(buf_T *bufp, int *bufnop)
{
int bufno;
nbbuf_T *nbbuf;
if (!NETBEANS_OPEN || !netbeansFireChanges)
return NULL; /* changes are not reported at all */
bufno = nb_getbufno(bufp);
if (bufno <= 0)
return NULL; /* file is not known to NetBeans */
nbbuf = nb_get_buf(bufno);
if (nbbuf != NULL && !nbbuf->fireChanges)
return NULL; /* changes in this buffer are not reported */
*bufnop = bufno;
return nbbuf;
}
/*
* Tell netbeans the user inserted some text.
*/
void
netbeans_inserted(
buf_T *bufp,
linenr_T linenr,
colnr_T col,
char_u *txt,
int newlen)
{
char_u *buf;
int bufno;
nbbuf_T *nbbuf;
pos_T pos;
long off;
char_u *p;
char_u *newtxt;
if (!NETBEANS_OPEN)
return;
nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
if (nbbuf == NULL)
return;
/* Don't mark as modified for initial read */
if (nbbuf->insertDone)
nbbuf->modified = 1;
pos.lnum = linenr;
pos.col = col;
off = pos2off(bufp, &pos);
/* send the "insert" EVT */
newtxt = alloc(newlen + 1);
vim_strncpy(newtxt, txt, newlen);
p = nb_quote(newtxt);
if (p != NULL)
{
buf = alloc(128 + 2*newlen);
sprintf((char *)buf, "%d:insert=%d %ld \"%s\"\n",
bufno, r_cmdno, off, p);
nbdebug(("EVT: %s", buf));
nb_send((char *)buf, "netbeans_inserted");
vim_free(p);
vim_free(buf);
}
vim_free(newtxt);
}
/*
* Tell netbeans some bytes have been removed.
*/
void
netbeans_removed(
buf_T *bufp,
linenr_T linenr,
colnr_T col,
long len)
{
char_u buf[128];
int bufno;
nbbuf_T *nbbuf;
pos_T pos;
long off;
if (!NETBEANS_OPEN)
return;
nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
if (nbbuf == NULL)
return;
if (len < 0)
{
nbdebug(("Negative len %ld in netbeans_removed()!\n", len));
return;
}
nbbuf->modified = 1;
pos.lnum = linenr;
pos.col = col;
off = pos2off(bufp, &pos);
sprintf((char *)buf, "%d:remove=%d %ld %ld\n", bufno, r_cmdno, off, len);
nbdebug(("EVT: %s", buf));
nb_send((char *)buf, "netbeans_removed");
}
/*
* Send netbeans an unmodified command.
*/
void
netbeans_unmodified(buf_T *bufp UNUSED)
{
/* This is a no-op, because NetBeans considers a buffer modified
* even when all changes have been undone. */
}
/*
* Send a button release event back to netbeans. Its up to netbeans
* to decide what to do (if anything) with this event.
*/
void
netbeans_button_release(int button)
{
char buf[128];
int bufno;
if (!NETBEANS_OPEN)
return;
bufno = nb_getbufno(curbuf);
if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
{
int col = mouse_col - W_WINCOL(curwin)
- ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
long off = pos2off(curbuf, &curwin->w_cursor);
/* sync the cursor position */
sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_button_release[newDotAndMark]");
sprintf(buf, "%d:buttonRelease=%d %d %ld %d\n", bufno, r_cmdno,
button, (long)curwin->w_cursor.lnum, col);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_button_release");
}
}
/*
* Send a keypress event back to netbeans. This usually simulates some
* kind of function key press. This function operates on a key code.
* Return TRUE when the key was sent, FALSE when the command has been
* postponed.
*/
int
netbeans_keycommand(int key)
{
char keyName[60];
netbeans_keyname(key, keyName);
return netbeans_keystring((char_u *)keyName);
}
/*
* Send a keypress event back to netbeans. This usually simulates some
* kind of function key press. This function operates on a key string.
* Return TRUE when the key was sent, FALSE when the command has been
* postponed.
*/
static int
netbeans_keystring(char_u *keyName)
{
char buf[2*MAXPATHL];
int bufno = nb_getbufno(curbuf);
long off;
char_u *q;
if (!NETBEANS_OPEN)
return TRUE;
if (bufno == -1)
{
nbdebug(("got keycommand for non-NetBeans buffer, opening...\n"));
q = curbuf->b_ffname == NULL ? (char_u *)""
: nb_quote(curbuf->b_ffname);
if (q == NULL)
return TRUE;
vim_snprintf(buf, sizeof(buf), "0:fileOpened=%d \"%s\" %s %s\n", 0,
q,
"T", /* open in NetBeans */
"F"); /* modified */
if (curbuf->b_ffname != NULL)
vim_free(q);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_keycommand");
postpone_keycommand(keyName);
return FALSE;
}
/* sync the cursor position */
off = pos2off(curbuf, &curwin->w_cursor);
sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_keycommand");
/* To work on Win32 you must apply patch to ExtEditor module
* from ExtEdCaret.java.diff - make EVT_newDotAndMark handler
* more synchronous
*/
/* now send keyCommand event */
vim_snprintf(buf, sizeof(buf), "%d:keyCommand=%d \"%s\"\n",
bufno, r_cmdno, keyName);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_keycommand");
/* New: do both at once and include the lnum/col. */
vim_snprintf(buf, sizeof(buf), "%d:keyAtPos=%d \"%s\" %ld %ld/%ld\n",
bufno, r_cmdno, keyName,
off, (long)curwin->w_cursor.lnum, (long)curwin->w_cursor.col);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_keycommand");
return TRUE;
}
/*
* Send a save event to netbeans.
*/
void
netbeans_save_buffer(buf_T *bufp)
{
char_u buf[64];
int bufno;
nbbuf_T *nbbuf;
if (!NETBEANS_OPEN)
return;
nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
if (nbbuf == NULL)
return;
nbbuf->modified = 0;
sprintf((char *)buf, "%d:save=%d\n", bufno, r_cmdno);
nbdebug(("EVT: %s", buf));
nb_send((char *)buf, "netbeans_save_buffer");
}
/*
* Send remove command to netbeans (this command has been turned off).
*/
void
netbeans_deleted_all_lines(buf_T *bufp)
{
char_u buf[64];
int bufno;
nbbuf_T *nbbuf;
if (!NETBEANS_OPEN)
return;
nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
if (nbbuf == NULL)
return;
/* Don't mark as modified for initial read */
if (nbbuf->insertDone)
nbbuf->modified = 1;
sprintf((char *)buf, "%d:remove=%d 0 -1\n", bufno, r_cmdno);
nbdebug(("EVT(suppressed): %s", buf));
/* nb_send(buf, "netbeans_deleted_all_lines"); */
}
/*
* See if the lines are guarded. The top and bot parameters are from
* u_savecommon(), these are the line above the change and the line below the
* change.
*/
int
netbeans_is_guarded(linenr_T top, linenr_T bot)
{
signlist_T *p;
int lnum;
if (!NETBEANS_OPEN)
return FALSE;
for (p = curbuf->b_signlist; p != NULL; p = p->next)
if (p->id >= GUARDEDOFFSET)
for (lnum = top + 1; lnum < bot; lnum++)
if (lnum == p->lnum)
return TRUE;
return FALSE;
}
#if defined(FEAT_GUI_X11) || defined(PROTO)
/*
* We have multiple signs to draw at the same location. Draw the
* multi-sign indicator instead. This is the Motif version.
*/
void
netbeans_draw_multisign_indicator(int row)
{
int i;
int y;
int x;
if (!NETBEANS_OPEN)
return;
x = 0;
y = row * gui.char_height + 2;
for (i = 0; i < gui.char_height - 3; i++)
XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y++);
XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+0, y);
XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y);
XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+4, y++);
XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+1, y);
XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y);
XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+3, y++);
XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y);
}
#endif /* FEAT_GUI_X11 */
#if defined(FEAT_GUI_GTK) && !defined(PROTO)
/*
* We have multiple signs to draw at the same location. Draw the
* multi-sign indicator instead. This is the GTK/Gnome version.
*/
void
netbeans_draw_multisign_indicator(int row)
{
int i;
int y;
int x;
GdkDrawable *drawable = gui.drawarea->window;
if (!NETBEANS_OPEN)
return;
x = 0;
y = row * gui.char_height + 2;
for (i = 0; i < gui.char_height - 3; i++)
gdk_draw_point(drawable, gui.text_gc, x+2, y++);
gdk_draw_point(drawable, gui.text_gc, x+0, y);
gdk_draw_point(drawable, gui.text_gc, x+2, y);
gdk_draw_point(drawable, gui.text_gc, x+4, y++);
gdk_draw_point(drawable, gui.text_gc, x+1, y);
gdk_draw_point(drawable, gui.text_gc, x+2, y);
gdk_draw_point(drawable, gui.text_gc, x+3, y++);
gdk_draw_point(drawable, gui.text_gc, x+2, y);
}
#endif /* FEAT_GUI_GTK */
/*
* If the mouse is clicked in the gutter of a line with multiple
* annotations, cycle through the set of signs.
*/
void
netbeans_gutter_click(linenr_T lnum)
{
signlist_T *p;
if (!NETBEANS_OPEN)
return;
for (p = curbuf->b_signlist; p != NULL; p = p->next)
{
if (p->lnum == lnum && p->next && p->next->lnum == lnum)
{
signlist_T *tail;
/* remove "p" from list, reinsert it at the tail of the sublist */
if (p->prev)
p->prev->next = p->next;
else
curbuf->b_signlist = p->next;
p->next->prev = p->prev;
/* now find end of sublist and insert p */
for (tail = p->next;
tail->next && tail->next->lnum == lnum
&& tail->next->id < GUARDEDOFFSET;
tail = tail->next)
;
/* tail now points to last entry with same lnum (except
* that "guarded" annotations are always last) */
p->next = tail->next;
if (tail->next)
tail->next->prev = p;
p->prev = tail;
tail->next = p;
update_debug_sign(curbuf, lnum);
break;
}
}
}
/*
* Add a sign of the requested type at the requested location.
*
* Reverse engineering:
* Apparently an annotation is defined the first time it is used in a buffer.
* When the same annotation is used in two buffers, the second time we do not
* need to define a new sign name but reuse the existing one. But since the
* ID number used in the second buffer starts counting at one again, a mapping
* is made from the ID specifically for the buffer to the global sign name
* (which is a number).
*
* globalsignmap[] stores the signs that have been defined globally.
* buf->signmapused[] maps buffer-local annotation IDs to an index in
* globalsignmap[].
*/
static void
addsigntype(
nbbuf_T *buf,
int typeNum,
char_u *typeName,
char_u *tooltip UNUSED,
char_u *glyphFile,
char_u *fg,
char_u *bg)
{
int i, j;
int use_fg = (*fg && STRCMP(fg, "none") != 0);
int use_bg = (*bg && STRCMP(bg, "none") != 0);
for (i = 0; i < globalsignmapused; i++)
if (STRCMP(typeName, globalsignmap[i]) == 0)
break;
if (i == globalsignmapused) /* not found; add it to global map */
{
nbdebug(("DEFINEANNOTYPE(%d,%s,%s,%s,%s,%s)\n",
typeNum, typeName, tooltip, glyphFile, fg, bg));
if (use_fg || use_bg)
{
char fgbuf[2 * (8 + MAX_COLOR_LENGTH) + 1];
char bgbuf[2 * (8 + MAX_COLOR_LENGTH) + 1];
char *ptr;
int value;
value = strtol((char *)fg, &ptr, 10);
if (ptr != (char *)fg)
sprintf(fgbuf, "guifg=#%06x", value & 0xFFFFFF);
else
sprintf(fgbuf, "guifg=%s ctermfg=%s", fg, fg);
value = strtol((char *)bg, &ptr, 10);
if (ptr != (char *)bg)
sprintf(bgbuf, "guibg=#%06x", value & 0xFFFFFF);
else
sprintf(bgbuf, "guibg=%s ctermbg=%s", bg, bg);
coloncmd(":highlight NB_%s %s %s", typeName, (use_fg) ? fgbuf : "",
(use_bg) ? bgbuf : "");
if (*glyphFile == NUL)
/* no glyph, line highlighting only */
coloncmd(":sign define %d linehl=NB_%s", i + 1, typeName);
else if (vim_strsize(glyphFile) <= 2)
/* one- or two-character glyph name, use as text glyph with
* texthl */
coloncmd(":sign define %d text=%s texthl=NB_%s", i + 1,
glyphFile, typeName);
else
/* glyph, line highlighting */
coloncmd(":sign define %d icon=%s linehl=NB_%s", i + 1,
glyphFile, typeName);
}
else
/* glyph, no line highlighting */
coloncmd(":sign define %d icon=%s", i + 1, glyphFile);
if (STRCMP(typeName,"CurrentPC") == 0)
curPCtype = typeNum;
if (globalsignmapused == globalsignmaplen)
{
if (globalsignmaplen == 0) /* first allocation */
{
globalsignmaplen = 20;
globalsignmap = (char **)alloc_clear(globalsignmaplen*sizeof(char *));
}
else /* grow it */
{
int incr;
int oldlen = globalsignmaplen;
globalsignmaplen *= 2;
incr = globalsignmaplen - oldlen;
globalsignmap = (char **)vim_realloc(globalsignmap,
globalsignmaplen * sizeof(char *));
vim_memset(globalsignmap + oldlen, 0, incr * sizeof(char *));
}
}
globalsignmap[i] = (char *)typeName;
globalsignmapused = i + 1;
}
/* check local map; should *not* be found! */
for (j = 0; j < buf->signmapused; j++)
if (buf->signmap[j] == i + 1)
return;
/* add to local map */
if (buf->signmapused == buf->signmaplen)
{
if (buf->signmaplen == 0) /* first allocation */
{
buf->signmaplen = 5;
buf->signmap = (int *)alloc_clear(buf->signmaplen * sizeof(int));
}
else /* grow it */
{
int incr;
int oldlen = buf->signmaplen;
buf->signmaplen *= 2;
incr = buf->signmaplen - oldlen;
buf->signmap = (int *)vim_realloc(buf->signmap,
buf->signmaplen * sizeof(int));
vim_memset(buf->signmap + oldlen, 0, incr * sizeof(int));
}
}
buf->signmap[buf->signmapused++] = i + 1;
}
/*
* See if we have the requested sign type in the buffer.
*/
static int
mapsigntype(nbbuf_T *buf, int localsigntype)
{
if (--localsigntype >= 0 && localsigntype < buf->signmapused)
return buf->signmap[localsigntype];
return 0;
}
/*
* Compute length of buffer, don't print anything.
*/
static long
get_buf_size(buf_T *bufp)
{
linenr_T lnum;
long char_count = 0;
int eol_size;
long last_check = 100000L;
if (bufp->b_ml.ml_flags & ML_EMPTY)
return 0;
else
{
if (get_fileformat(bufp) == EOL_DOS)
eol_size = 2;
else
eol_size = 1;
for (lnum = 1; lnum <= bufp->b_ml.ml_line_count; ++lnum)
{
char_count += (long)STRLEN(ml_get_buf(bufp, lnum, FALSE))
+ eol_size;
/* Check for a CTRL-C every 100000 characters */
if (char_count > last_check)
{
ui_breakcheck();
if (got_int)
return char_count;
last_check = char_count + 100000L;
}
}
/* Correction for when last line doesn't have an EOL. */
if (!bufp->b_p_eol && bufp->b_p_bin)
char_count -= eol_size;
}
return char_count;
}
/*
* Convert character offset to lnum,col
*/
static pos_T *
off2pos(buf_T *buf, long offset)
{
linenr_T lnum;
static pos_T pos;
pos.lnum = 0;
pos.col = 0;
#ifdef FEAT_VIRTUALEDIT
pos.coladd = 0;
#endif
if (!(buf->b_ml.ml_flags & ML_EMPTY))
{
if ((lnum = ml_find_line_or_offset(buf, (linenr_T)0, &offset)) < 0)
return NULL;
pos.lnum = lnum;
pos.col = offset;
}
return &pos;
}
/*
* Convert an argument in the form "1234" to an offset and compute the
* lnum/col from it. Convert an argument in the form "123/12" directly to a
* lnum/col.
* "argp" is advanced to after the argument.
* Return a pointer to the position, NULL if something is wrong.
*/
static pos_T *
get_off_or_lnum(buf_T *buf, char_u **argp)
{
static pos_T mypos;
long off;
off = strtol((char *)*argp, (char **)argp, 10);
if (**argp == '/')
{
mypos.lnum = (linenr_T)off;
++*argp;
mypos.col = strtol((char *)*argp, (char **)argp, 10);
#ifdef FEAT_VIRTUALEDIT
mypos.coladd = 0;
#endif
return &mypos;
}
return off2pos(buf, off);
}
/*
* Convert (lnum,col) to byte offset in the file.
*/
static long
pos2off(buf_T *buf, pos_T *pos)
{
long offset = 0;
if (!(buf->b_ml.ml_flags & ML_EMPTY))
{
if ((offset = ml_find_line_or_offset(buf, pos->lnum, 0)) < 0)
return 0;
offset += pos->col;
}
return offset;
}
/*
* This message is printed after NetBeans opens a new file. Its
* similar to the message readfile() uses, but since NetBeans
* doesn't normally call readfile, we do our own.
*/
static void
print_read_msg(buf)
nbbuf_T *buf;
{
int lnum = buf->bufp->b_ml.ml_line_count;
off_t nchars = buf->bufp->b_orig_size;
char_u c;
msg_add_fname(buf->bufp, buf->bufp->b_ffname);
c = FALSE;
if (buf->bufp->b_p_ro)
{
STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]"));
c = TRUE;
}
if (!buf->bufp->b_start_eol)
{
STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]")
: _("[Incomplete last line]"));
c = TRUE;
}
msg_add_lines(c, (long)lnum, nchars);
/* Now display it */
vim_free(keep_msg);
keep_msg = NULL;
msg_scrolled_ign = TRUE;
msg_trunc_attr(IObuff, FALSE, 0);
msg_scrolled_ign = FALSE;
}
/*
* Print a message after NetBeans writes the file. This message should be
* identical to the standard message a non-netbeans user would see when
* writing a file.
*/
static void
print_save_msg(buf, nchars)
nbbuf_T *buf;
off_t nchars;
{
char_u c;
char_u *p;
if (nchars >= 0)
{
/* put fname in IObuff with quotes */
msg_add_fname(buf->bufp, buf->bufp->b_ffname);
c = FALSE;
msg_add_lines(c, buf->bufp->b_ml.ml_line_count,
buf->bufp->b_orig_size);
vim_free(keep_msg);
keep_msg = NULL;
msg_scrolled_ign = TRUE;
p = msg_trunc_attr(IObuff, FALSE, 0);
if ((msg_scrolled && !need_wait_return) || !buf->initDone)
{
/* Need to repeat the message after redrawing when:
* - When reading from stdin (the screen will be cleared next).
* - When restart_edit is set (otherwise there will be a delay
* before redrawing).
* - When the screen was scrolled but there is no wait-return
* prompt. */
set_keep_msg(p, 0);
}
msg_scrolled_ign = FALSE;
/* add_to_input_buf((char_u *)"\f", 1); */
}
else
{
char_u msgbuf[IOSIZE];
vim_snprintf((char *)msgbuf, IOSIZE,
_("E505: %s is read-only (add ! to override)"), IObuff);
nbdebug((" %s\n", msgbuf));
emsg(msgbuf);
}
}
#endif /* defined(FEAT_NETBEANS_INTG) */
| zyz2011-vim | src/netbeans.c | C | gpl2 | 95,078 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* Porting to GTK+ was done by:
*
* (C) 1998,1999,2000 by Marcin Dalecki <martin@dalecki.de>
*
* With GREAT support and continuous encouragements by Andy Kahn and of
* course Bram Moolenaar!
*
* Support for GTK+ 2 was added by:
*
* (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca>
* Daniel Elstner <daniel.elstner@gmx.net>
*
* Best supporting actor (He helped somewhat, aesthetically speaking):
* Maxime Romano <verbophobe@hotmail.com>
*/
#ifdef FEAT_GUI_GTK
# include "gui_gtk_f.h"
#endif
/* GTK defines MAX and MIN, but some system header files as well. Undefine
* them and don't use them. */
#ifdef MIN
# undef MIN
#endif
#ifdef MAX
# undef MAX
#endif
#include "vim.h"
#ifdef FEAT_GUI_GNOME
/* Gnome redefines _() and N_(). Grrr... */
# ifdef _
# undef _
# endif
# ifdef N_
# undef N_
# endif
# ifdef textdomain
# undef textdomain
# endif
# ifdef bindtextdomain
# undef bindtextdomain
# endif
# ifdef bind_textdomain_codeset
# undef bind_textdomain_codeset
# endif
# if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS)
# define ENABLE_NLS /* so the texts in the dialog boxes are translated */
# endif
# include <gnome.h>
#endif
#ifdef FEAT_GUI_GTK
# include <gdk/gdkkeysyms.h>
# include <gdk/gdk.h>
# ifdef WIN3264
# include <gdk/gdkwin32.h>
# else
# include <gdk/gdkx.h>
# endif
# include <gtk/gtk.h>
#else
/* define these items to be able to generate prototypes without GTK */
typedef int GtkWidget;
# define gpointer int
# define guint8 int
# define GdkPixmap int
# define GdkBitmap int
# define GtkIconFactory int
# define GtkToolbar int
# define GtkAdjustment int
# define gboolean int
# define GdkEventKey int
# define CancelData int
#endif
static void entry_activate_cb(GtkWidget *widget, gpointer data);
static void entry_changed_cb(GtkWidget *entry, GtkWidget *dialog);
static void find_replace_cb(GtkWidget *widget, gpointer data);
#if defined(FEAT_BROWSE) || defined(PROTO)
static void recent_func_log_func(
const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data);
#endif
#if defined(FEAT_TOOLBAR)
/*
* Table from BuiltIn## icon indices to GTK+ stock IDs. Order must exactly
* match toolbar_names[] in menu.c! All stock icons including the "vim-*"
* ones can be overridden in your gtkrc file.
*/
static const char * const menu_stock_ids[] =
{
/* 00 */ GTK_STOCK_NEW,
/* 01 */ GTK_STOCK_OPEN,
/* 02 */ GTK_STOCK_SAVE,
/* 03 */ GTK_STOCK_UNDO,
/* 04 */ GTK_STOCK_REDO,
/* 05 */ GTK_STOCK_CUT,
/* 06 */ GTK_STOCK_COPY,
/* 07 */ GTK_STOCK_PASTE,
/* 08 */ GTK_STOCK_PRINT,
/* 09 */ GTK_STOCK_HELP,
/* 10 */ GTK_STOCK_FIND,
/* 11 */ "vim-save-all",
/* 12 */ "vim-session-save",
/* 13 */ "vim-session-new",
/* 14 */ "vim-session-load",
/* 15 */ GTK_STOCK_EXECUTE,
/* 16 */ GTK_STOCK_FIND_AND_REPLACE,
/* 17 */ GTK_STOCK_CLOSE, /* FIXME: fuzzy */
/* 18 */ "vim-window-maximize",
/* 19 */ "vim-window-minimize",
/* 20 */ "vim-window-split",
/* 21 */ "vim-shell",
/* 22 */ GTK_STOCK_GO_BACK,
/* 23 */ GTK_STOCK_GO_FORWARD,
/* 24 */ "vim-find-help",
/* 25 */ GTK_STOCK_CONVERT,
/* 26 */ GTK_STOCK_JUMP_TO,
/* 27 */ "vim-build-tags",
/* 28 */ "vim-window-split-vertical",
/* 29 */ "vim-window-maximize-width",
/* 30 */ "vim-window-minimize-width",
/* 31 */ GTK_STOCK_QUIT
};
static void
add_stock_icon(GtkIconFactory *factory,
const char *stock_id,
const guint8 *inline_data,
int data_length)
{
GdkPixbuf *pixbuf;
GtkIconSet *icon_set;
pixbuf = gdk_pixbuf_new_from_inline(data_length, inline_data, FALSE, NULL);
icon_set = gtk_icon_set_new_from_pixbuf(pixbuf);
gtk_icon_factory_add(factory, stock_id, icon_set);
gtk_icon_set_unref(icon_set);
g_object_unref(pixbuf);
}
static int
lookup_menu_iconfile(char_u *iconfile, char_u *dest)
{
expand_env(iconfile, dest, MAXPATHL);
if (mch_isFullName(dest))
{
return vim_fexists(dest);
}
else
{
static const char suffixes[][4] = {"png", "xpm", "bmp"};
char_u buf[MAXPATHL];
unsigned int i;
for (i = 0; i < G_N_ELEMENTS(suffixes); ++i)
if (gui_find_bitmap(dest, buf, (char *)suffixes[i]) == OK)
{
STRCPY(dest, buf);
return TRUE;
}
return FALSE;
}
}
static GtkWidget *
load_menu_iconfile(char_u *name, GtkIconSize icon_size)
{
GtkWidget *image = NULL;
GtkIconSet *icon_set;
GtkIconSource *icon_source;
/*
* Rather than loading the icon directly into a GtkImage, create
* a new GtkIconSet and put it in there. This way we can easily
* scale the toolbar icons on the fly when needed.
*/
icon_set = gtk_icon_set_new();
icon_source = gtk_icon_source_new();
gtk_icon_source_set_filename(icon_source, (const char *)name);
gtk_icon_set_add_source(icon_set, icon_source);
image = gtk_image_new_from_icon_set(icon_set, icon_size);
gtk_icon_source_free(icon_source);
gtk_icon_set_unref(icon_set);
return image;
}
static GtkWidget *
create_menu_icon(vimmenu_T *menu, GtkIconSize icon_size)
{
GtkWidget *image = NULL;
char_u buf[MAXPATHL];
/* First use a specified "icon=" argument. */
if (menu->iconfile != NULL && lookup_menu_iconfile(menu->iconfile, buf))
image = load_menu_iconfile(buf, icon_size);
/* If not found and not builtin specified try using the menu name. */
if (image == NULL && !menu->icon_builtin
&& lookup_menu_iconfile(menu->name, buf))
image = load_menu_iconfile(buf, icon_size);
/* Still not found? Then use a builtin icon, a blank one as fallback. */
if (image == NULL)
{
const char *stock_id;
const int n_ids = G_N_ELEMENTS(menu_stock_ids);
if (menu->iconidx >= 0 && menu->iconidx < n_ids)
stock_id = menu_stock_ids[menu->iconidx];
else
stock_id = GTK_STOCK_MISSING_IMAGE;
image = gtk_image_new_from_stock(stock_id, icon_size);
}
return image;
}
static gint
toolbar_button_focus_in_event(GtkWidget *widget UNUSED,
GdkEventFocus *event UNUSED,
gpointer data UNUSED)
{
/* When we're in a GtkPlug, we don't have window focus events, only widget
* focus. To emulate stand-alone gvim, if a button gets focus (e.g.,
* <Tab> into GtkPlug) immediately pass it to mainwin. */
if (gtk_socket_id != 0)
gtk_widget_grab_focus(gui.drawarea);
return TRUE;
}
#endif /* FEAT_TOOLBAR */
#if defined(FEAT_TOOLBAR) || defined(PROTO)
void
gui_gtk_register_stock_icons(void)
{
# include "../pixmaps/stock_icons.h"
GtkIconFactory *factory;
factory = gtk_icon_factory_new();
# define ADD_ICON(Name, Data) add_stock_icon(factory, Name, Data, (int)sizeof(Data))
ADD_ICON("vim-build-tags", stock_vim_build_tags);
ADD_ICON("vim-find-help", stock_vim_find_help);
ADD_ICON("vim-save-all", stock_vim_save_all);
ADD_ICON("vim-session-load", stock_vim_session_load);
ADD_ICON("vim-session-new", stock_vim_session_new);
ADD_ICON("vim-session-save", stock_vim_session_save);
ADD_ICON("vim-shell", stock_vim_shell);
ADD_ICON("vim-window-maximize", stock_vim_window_maximize);
ADD_ICON("vim-window-maximize-width", stock_vim_window_maximize_width);
ADD_ICON("vim-window-minimize", stock_vim_window_minimize);
ADD_ICON("vim-window-minimize-width", stock_vim_window_minimize_width);
ADD_ICON("vim-window-split", stock_vim_window_split);
ADD_ICON("vim-window-split-vertical", stock_vim_window_split_vertical);
# undef ADD_ICON
gtk_icon_factory_add_default(factory);
g_object_unref(factory);
}
#endif /* FEAT_TOOLBAR */
#if defined(FEAT_MENU) || defined(PROTO)
/*
* Translate Vim's mnemonic tagging to GTK+ style and convert to UTF-8
* if necessary. The caller must vim_free() the returned string.
*
* Input Output
* _ __
* && &
* & _ stripped if use_mnemonic == FALSE
* <Tab> end of menu label text
*/
static char_u *
translate_mnemonic_tag(char_u *name, int use_mnemonic)
{
char_u *buf;
char_u *psrc;
char_u *pdest;
int n_underscores = 0;
name = CONVERT_TO_UTF8(name);
if (name == NULL)
return NULL;
for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc)
if (*psrc == '_')
++n_underscores;
buf = alloc((unsigned)(psrc - name + n_underscores + 1));
if (buf != NULL)
{
pdest = buf;
for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc)
{
if (*psrc == '_')
{
*pdest++ = '_';
*pdest++ = '_';
}
else if (*psrc != '&')
{
*pdest++ = *psrc;
}
else if (*(psrc + 1) == '&')
{
*pdest++ = *psrc++;
}
else if (use_mnemonic)
{
*pdest++ = '_';
}
}
*pdest = NUL;
}
CONVERT_TO_UTF8_FREE(name);
return buf;
}
static void
menu_item_new(vimmenu_T *menu, GtkWidget *parent_widget)
{
GtkWidget *box;
char_u *text;
int use_mnemonic;
/* It would be neat to have image menu items, but that would require major
* changes to Vim's menu system. Not to mention that all the translations
* had to be updated. */
menu->id = gtk_menu_item_new();
box = gtk_hbox_new(FALSE, 20);
use_mnemonic = (p_wak[0] != 'n' || !GTK_IS_MENU_BAR(parent_widget));
text = translate_mnemonic_tag(menu->name, use_mnemonic);
menu->label = gtk_label_new_with_mnemonic((const char *)text);
vim_free(text);
gtk_box_pack_start(GTK_BOX(box), menu->label, FALSE, FALSE, 0);
if (menu->actext != NULL && menu->actext[0] != NUL)
{
text = CONVERT_TO_UTF8(menu->actext);
gtk_box_pack_end(GTK_BOX(box),
gtk_label_new((const char *)text),
FALSE, FALSE, 0);
CONVERT_TO_UTF8_FREE(text);
}
gtk_container_add(GTK_CONTAINER(menu->id), box);
gtk_widget_show_all(menu->id);
}
void
gui_mch_add_menu(vimmenu_T *menu, int idx)
{
vimmenu_T *parent;
GtkWidget *parent_widget;
if (menu->name[0] == ']' || menu_is_popup(menu->name))
{
menu->submenu_id = gtk_menu_new();
return;
}
parent = menu->parent;
if ((parent != NULL && parent->submenu_id == NULL)
|| !menu_is_menubar(menu->name))
return;
parent_widget = (parent != NULL) ? parent->submenu_id : gui.menubar;
menu_item_new(menu, parent_widget);
/* since the tearoff should always appear first, increment idx */
if (parent != NULL && !menu_is_popup(parent->name))
++idx;
gtk_menu_shell_insert(GTK_MENU_SHELL(parent_widget), menu->id, idx);
menu->submenu_id = gtk_menu_new();
gtk_menu_set_accel_group(GTK_MENU(menu->submenu_id), gui.accel_group);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu->id), menu->submenu_id);
menu->tearoff_handle = gtk_tearoff_menu_item_new();
if (vim_strchr(p_go, GO_TEAROFF) != NULL)
gtk_widget_show(menu->tearoff_handle);
gtk_menu_prepend(GTK_MENU(menu->submenu_id), menu->tearoff_handle);
}
static void
menu_item_activate(GtkWidget *widget UNUSED, gpointer data)
{
gui_menu_cb((vimmenu_T *)data);
}
void
gui_mch_add_menu_item(vimmenu_T *menu, int idx)
{
vimmenu_T *parent;
parent = menu->parent;
# ifdef FEAT_TOOLBAR
if (menu_is_toolbar(parent->name))
{
GtkToolbar *toolbar;
toolbar = GTK_TOOLBAR(gui.toolbar);
menu->submenu_id = NULL;
if (menu_is_separator(menu->name))
{
gtk_toolbar_insert_space(toolbar, idx);
menu->id = NULL;
}
else
{
char_u *text;
char_u *tooltip;
text = CONVERT_TO_UTF8(menu->dname);
tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
if (tooltip != NULL && !utf_valid_string(tooltip, NULL))
/* Invalid text, can happen when 'encoding' is changed. Avoid
* a nasty GTK error message, skip the tooltip. */
CONVERT_TO_UTF8_FREE(tooltip);
menu->id = gtk_toolbar_insert_item(
toolbar,
(const char *)text,
(const char *)tooltip,
NULL,
create_menu_icon(menu, gtk_toolbar_get_icon_size(toolbar)),
G_CALLBACK(&menu_item_activate),
menu,
idx);
if (gtk_socket_id != 0)
gtk_signal_connect(GTK_OBJECT(menu->id), "focus_in_event",
GTK_SIGNAL_FUNC(toolbar_button_focus_in_event), NULL);
CONVERT_TO_UTF8_FREE(text);
CONVERT_TO_UTF8_FREE(tooltip);
}
}
else
# endif /* FEAT_TOOLBAR */
{
/* No parent, must be a non-menubar menu */
if (parent == NULL || parent->submenu_id == NULL)
return;
/* Make place for the possible tearoff handle item. Not in the popup
* menu, it doesn't have a tearoff item. */
if (!menu_is_popup(parent->name))
++idx;
if (menu_is_separator(menu->name))
{
/* Separator: Just add it */
menu->id = gtk_menu_item_new();
gtk_widget_set_sensitive(menu->id, FALSE);
gtk_widget_show(menu->id);
gtk_menu_insert(GTK_MENU(parent->submenu_id), menu->id, idx);
return;
}
/* Add textual menu item. */
menu_item_new(menu, parent->submenu_id);
gtk_widget_show(menu->id);
gtk_menu_insert(GTK_MENU(parent->submenu_id), menu->id, idx);
if (menu->id != NULL)
gtk_signal_connect(GTK_OBJECT(menu->id), "activate",
GTK_SIGNAL_FUNC(menu_item_activate), menu);
}
}
#endif /* FEAT_MENU */
void
gui_mch_set_text_area_pos(int x, int y, int w, int h)
{
gtk_form_move_resize(GTK_FORM(gui.formwin), gui.drawarea, x, y, w, h);
}
#if defined(FEAT_MENU) || defined(PROTO)
/*
* Enable or disable accelerators for the toplevel menus.
*/
void
gui_gtk_set_mnemonics(int enable)
{
vimmenu_T *menu;
char_u *name;
for (menu = root_menu; menu != NULL; menu = menu->next)
{
if (menu->id == NULL)
continue;
name = translate_mnemonic_tag(menu->name, enable);
gtk_label_set_text_with_mnemonic(GTK_LABEL(menu->label),
(const char *)name);
vim_free(name);
}
}
static void
recurse_tearoffs(vimmenu_T *menu, int val)
{
for (; menu != NULL; menu = menu->next)
{
if (menu->submenu_id != NULL && menu->tearoff_handle != NULL
&& menu->name[0] != ']' && !menu_is_popup(menu->name))
{
if (val)
gtk_widget_show(menu->tearoff_handle);
else
gtk_widget_hide(menu->tearoff_handle);
}
recurse_tearoffs(menu->children, val);
}
}
void
gui_mch_toggle_tearoffs(int enable)
{
recurse_tearoffs(root_menu, enable);
}
#endif /* FEAT_MENU */
#if defined(FEAT_TOOLBAR)
static int
get_menu_position(vimmenu_T *menu)
{
vimmenu_T *node;
int idx = 0;
for (node = menu->parent->children; node != menu; node = node->next)
{
g_return_val_if_fail(node != NULL, -1);
++idx;
}
return idx;
}
#endif /* FEAT_TOOLBAR */
#if defined(FEAT_TOOLBAR) || defined(PROTO)
void
gui_mch_menu_set_tip(vimmenu_T *menu)
{
if (menu->id != NULL && menu->parent != NULL
&& gui.toolbar != NULL && menu_is_toolbar(menu->parent->name))
{
char_u *tooltip;
tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
if (tooltip == NULL || utf_valid_string(tooltip, NULL))
/* Only set the tooltip when it's valid utf-8. */
gtk_tooltips_set_tip(GTK_TOOLBAR(gui.toolbar)->tooltips,
menu->id, (const char *)tooltip, NULL);
CONVERT_TO_UTF8_FREE(tooltip);
}
}
#endif /* FEAT_TOOLBAR */
#if defined(FEAT_MENU) || defined(PROTO)
/*
* Destroy the machine specific menu widget.
*/
void
gui_mch_destroy_menu(vimmenu_T *menu)
{
# ifdef FEAT_TOOLBAR
if (menu->parent != NULL && menu_is_toolbar(menu->parent->name))
{
if (menu_is_separator(menu->name))
gtk_toolbar_remove_space(GTK_TOOLBAR(gui.toolbar),
get_menu_position(menu));
else if (menu->id != NULL)
gtk_widget_destroy(menu->id);
}
else
# endif /* FEAT_TOOLBAR */
{
if (menu->submenu_id != NULL)
gtk_widget_destroy(menu->submenu_id);
if (menu->id != NULL)
gtk_widget_destroy(menu->id);
}
menu->submenu_id = NULL;
menu->id = NULL;
}
#endif /* FEAT_MENU */
/*
* Scrollbar stuff.
*/
void
gui_mch_set_scrollbar_thumb(scrollbar_T *sb, long val, long size, long max)
{
if (sb->id != NULL)
{
GtkAdjustment *adjustment;
adjustment = gtk_range_get_adjustment(GTK_RANGE(sb->id));
adjustment->lower = 0.0;
adjustment->value = val;
adjustment->upper = max + 1;
adjustment->page_size = size;
adjustment->page_increment = size < 3L ? 1L : size - 2L;
adjustment->step_increment = 1.0;
g_signal_handler_block(GTK_OBJECT(adjustment),
(gulong)sb->handler_id);
gtk_adjustment_changed(adjustment);
g_signal_handler_unblock(GTK_OBJECT(adjustment),
(gulong)sb->handler_id);
}
}
void
gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h)
{
if (sb->id != NULL)
gtk_form_move_resize(GTK_FORM(gui.formwin), sb->id, x, y, w, h);
}
/*
* Take action upon scrollbar dragging.
*/
static void
adjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
{
scrollbar_T *sb;
long value;
int dragging = FALSE;
#ifdef FEAT_XIM
/* cancel any preediting */
if (im_is_preediting())
xim_reset();
#endif
sb = gui_find_scrollbar((long)data);
value = (long)adjustment->value;
/*
* The dragging argument must be right for the scrollbar to work with
* closed folds. This isn't documented, hopefully this will keep on
* working in later GTK versions.
*
* FIXME: Well, it doesn't work in GTK2. :)
* HACK: Get the mouse pointer position, if it appears to be on an arrow
* button set "dragging" to FALSE. This assumes square buttons!
*/
if (sb != NULL)
{
dragging = TRUE;
if (sb->wp != NULL)
{
int x;
int y;
GdkModifierType state;
int width;
int height;
/* vertical scrollbar: need to set "dragging" properly in case
* there are closed folds. */
gdk_window_get_pointer(sb->id->window, &x, &y, &state);
gdk_window_get_size(sb->id->window, &width, &height);
if (x >= 0 && x < width && y >= 0 && y < height)
{
if (y < width)
{
/* up arrow: move one (closed fold) line up */
dragging = FALSE;
value = sb->wp->w_topline - 2;
}
else if (y > height - width)
{
/* down arrow: move one (closed fold) line down */
dragging = FALSE;
value = sb->wp->w_topline;
}
}
}
}
gui_drag_scrollbar(sb, value, dragging);
}
/* SBAR_VERT or SBAR_HORIZ */
void
gui_mch_create_scrollbar(scrollbar_T *sb, int orient)
{
if (orient == SBAR_HORIZ)
sb->id = gtk_hscrollbar_new(NULL);
else if (orient == SBAR_VERT)
sb->id = gtk_vscrollbar_new(NULL);
if (sb->id != NULL)
{
GtkAdjustment *adjustment;
GTK_WIDGET_UNSET_FLAGS(sb->id, GTK_CAN_FOCUS);
gtk_form_put(GTK_FORM(gui.formwin), sb->id, 0, 0);
adjustment = gtk_range_get_adjustment(GTK_RANGE(sb->id));
sb->handler_id = gtk_signal_connect(
GTK_OBJECT(adjustment), "value_changed",
GTK_SIGNAL_FUNC(adjustment_value_changed),
GINT_TO_POINTER(sb->ident));
gui_mch_update();
}
}
#if defined(FEAT_WINDOWS) || defined(PROTO)
void
gui_mch_destroy_scrollbar(scrollbar_T *sb)
{
if (sb->id != NULL)
{
gtk_widget_destroy(sb->id);
sb->id = NULL;
}
gui_mch_update();
}
#endif
#if defined(FEAT_BROWSE) || defined(PROTO)
/*
* Implementation of the file selector related stuff
*/
#if GTK_CHECK_VERSION(2,4,0)
# define USE_FILE_CHOOSER
#endif
#ifndef USE_FILE_CHOOSER
static void
browse_ok_cb(GtkWidget *widget UNUSED, gpointer cbdata)
{
gui_T *vw = (gui_T *)cbdata;
if (vw->browse_fname != NULL)
g_free(vw->browse_fname);
vw->browse_fname = (char_u *)g_strdup(gtk_file_selection_get_filename(
GTK_FILE_SELECTION(vw->filedlg)));
gtk_widget_hide(vw->filedlg);
}
static void
browse_cancel_cb(GtkWidget *widget UNUSED, gpointer cbdata)
{
gui_T *vw = (gui_T *)cbdata;
if (vw->browse_fname != NULL)
{
g_free(vw->browse_fname);
vw->browse_fname = NULL;
}
gtk_widget_hide(vw->filedlg);
}
static gboolean
browse_destroy_cb(GtkWidget *widget UNUSED)
{
if (gui.browse_fname != NULL)
{
g_free(gui.browse_fname);
gui.browse_fname = NULL;
}
gui.filedlg = NULL;
gtk_main_quit();
return FALSE;
}
#endif
/*
* Put up a file requester.
* Returns the selected name in allocated memory, or NULL for Cancel.
* saving, select file to write
* title title for the window
* dflt default name
* ext not used (extension added)
* initdir initial directory, NULL for current dir
* filter not used (file name filter)
*/
char_u *
gui_mch_browse(int saving UNUSED,
char_u *title,
char_u *dflt,
char_u *ext UNUSED,
char_u *initdir,
char_u *filter UNUSED)
{
#ifdef USE_FILE_CHOOSER
GtkWidget *fc;
#endif
char_u dirbuf[MAXPATHL];
guint log_handler;
const gchar *domain = "Gtk";
title = CONVERT_TO_UTF8(title);
/* GTK has a bug, it only works with an absolute path. */
if (initdir == NULL || *initdir == NUL)
mch_dirname(dirbuf, MAXPATHL);
else if (vim_FullName(initdir, dirbuf, MAXPATHL - 2, FALSE) == FAIL)
dirbuf[0] = NUL;
/* Always need a trailing slash for a directory. */
add_pathsep(dirbuf);
/* If our pointer is currently hidden, then we should show it. */
gui_mch_mousehide(FALSE);
/* Hack: The GTK file dialog warns when it can't access a new file, this
* makes it shut up. http://bugzilla.gnome.org/show_bug.cgi?id=664587 */
log_handler = g_log_set_handler(domain, G_LOG_LEVEL_WARNING,
recent_func_log_func, NULL);
#ifdef USE_FILE_CHOOSER
/* We create the dialog each time, so that the button text can be "Open"
* or "Save" according to the action. */
fc = gtk_file_chooser_dialog_new((const gchar *)title,
GTK_WINDOW(gui.mainwin),
saving ? GTK_FILE_CHOOSER_ACTION_SAVE
: GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc),
(const gchar *)dirbuf);
if (saving && dflt != NULL && *dflt != NUL)
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), (char *)dflt);
gui.browse_fname = NULL;
if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT)
{
char *filename;
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fc));
gui.browse_fname = (char_u *)g_strdup(filename);
g_free(filename);
}
gtk_widget_destroy(GTK_WIDGET(fc));
#else
if (gui.filedlg == NULL)
{
GtkFileSelection *fs; /* shortcut */
gui.filedlg = gtk_file_selection_new((const gchar *)title);
gtk_window_set_modal(GTK_WINDOW(gui.filedlg), TRUE);
gtk_window_set_transient_for(GTK_WINDOW(gui.filedlg),
GTK_WINDOW(gui.mainwin));
fs = GTK_FILE_SELECTION(gui.filedlg);
gtk_container_border_width(GTK_CONTAINER(fs), 4);
gtk_signal_connect(GTK_OBJECT(fs->ok_button),
"clicked", GTK_SIGNAL_FUNC(browse_ok_cb), &gui);
gtk_signal_connect(GTK_OBJECT(fs->cancel_button),
"clicked", GTK_SIGNAL_FUNC(browse_cancel_cb), &gui);
/* gtk_signal_connect() doesn't work for destroy, it causes a hang */
gtk_signal_connect_object(GTK_OBJECT(gui.filedlg),
"destroy", GTK_SIGNAL_FUNC(browse_destroy_cb),
GTK_OBJECT(gui.filedlg));
}
else
gtk_window_set_title(GTK_WINDOW(gui.filedlg), (const gchar *)title);
/* Concatenate "initdir" and "dflt". */
if (dflt != NULL && *dflt != NUL
&& STRLEN(dirbuf) + 2 + STRLEN(dflt) < MAXPATHL)
STRCAT(dirbuf, dflt);
gtk_file_selection_set_filename(GTK_FILE_SELECTION(gui.filedlg),
(const gchar *)dirbuf);
gtk_widget_show(gui.filedlg);
gtk_main();
#endif
g_log_remove_handler(domain, log_handler);
CONVERT_TO_UTF8_FREE(title);
if (gui.browse_fname == NULL)
return NULL;
/* shorten the file name if possible */
return vim_strsave(shorten_fname1(gui.browse_fname));
}
/*
* Put up a directory selector
* Returns the selected name in allocated memory, or NULL for Cancel.
* title title for the window
* dflt default name
* initdir initial directory, NULL for current dir
*/
char_u *
gui_mch_browsedir(
char_u *title,
char_u *initdir)
{
# if defined(GTK_FILE_CHOOSER) /* Only in GTK 2.4 and later. */
char_u dirbuf[MAXPATHL];
char_u *p;
GtkWidget *dirdlg; /* file selection dialog */
char_u *dirname = NULL;
title = CONVERT_TO_UTF8(title);
dirdlg = gtk_file_chooser_dialog_new(
(const gchar *)title,
GTK_WINDOW(gui.mainwin),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
CONVERT_TO_UTF8_FREE(title);
/* if our pointer is currently hidden, then we should show it. */
gui_mch_mousehide(FALSE);
/* GTK appears to insist on an absolute path. */
if (initdir == NULL || *initdir == NUL
|| vim_FullName(initdir, dirbuf, MAXPATHL - 10, FALSE) == FAIL)
mch_dirname(dirbuf, MAXPATHL - 10);
/* Always need a trailing slash for a directory.
* Also add a dummy file name, so that we get to the directory. */
add_pathsep(dirbuf);
STRCAT(dirbuf, "@zd(*&1|");
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dirdlg),
(const gchar *)dirbuf);
/* Run the dialog. */
if (gtk_dialog_run(GTK_DIALOG(dirdlg)) == GTK_RESPONSE_ACCEPT)
dirname = (char_u *)gtk_file_chooser_get_filename(
GTK_FILE_CHOOSER(dirdlg));
gtk_widget_destroy(dirdlg);
if (dirname == NULL)
return NULL;
/* shorten the file name if possible */
p = vim_strsave(shorten_fname1(dirname));
g_free(dirname);
return p;
# else
/* For GTK 2.2 and earlier: fall back to ordinary file selector. */
return gui_mch_browse(0, title, NULL, NULL, initdir, NULL);
# endif
}
#endif /* FEAT_BROWSE */
#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
static GtkWidget *
create_message_dialog(int type, char_u *title, char_u *message)
{
GtkWidget *dialog;
GtkMessageType message_type;
switch (type)
{
case VIM_ERROR: message_type = GTK_MESSAGE_ERROR; break;
case VIM_WARNING: message_type = GTK_MESSAGE_WARNING; break;
case VIM_QUESTION: message_type = GTK_MESSAGE_QUESTION; break;
default: message_type = GTK_MESSAGE_INFO; break;
}
message = CONVERT_TO_UTF8(message);
dialog = gtk_message_dialog_new(GTK_WINDOW(gui.mainwin),
GTK_DIALOG_DESTROY_WITH_PARENT,
message_type,
GTK_BUTTONS_NONE,
"%s", (const char *)message);
CONVERT_TO_UTF8_FREE(message);
if (title != NULL)
{
title = CONVERT_TO_UTF8(title);
gtk_window_set_title(GTK_WINDOW(dialog), (const char *)title);
CONVERT_TO_UTF8_FREE(title);
}
else if (type == VIM_GENERIC)
{
gtk_window_set_title(GTK_WINDOW(dialog), "VIM");
}
return dialog;
}
/*
* Split up button_string into individual button labels by inserting
* NUL bytes. Also replace the Vim-style mnemonic accelerator prefix
* '&' with '_'. button_string must point to allocated memory!
* Return an allocated array of pointers into button_string.
*/
static char **
split_button_string(char_u *button_string, int *n_buttons)
{
char **array;
char_u *p;
unsigned int count = 1;
for (p = button_string; *p != NUL; ++p)
if (*p == DLG_BUTTON_SEP)
++count;
array = (char **)alloc((count + 1) * sizeof(char *));
count = 0;
if (array != NULL)
{
array[count++] = (char *)button_string;
for (p = button_string; *p != NUL; )
{
if (*p == DLG_BUTTON_SEP)
{
*p++ = NUL;
array[count++] = (char *)p;
}
else if (*p == DLG_HOTKEY_CHAR)
*p++ = '_';
else
mb_ptr_adv(p);
}
array[count] = NULL; /* currently not relied upon, but doesn't hurt */
}
*n_buttons = count;
return array;
}
static char **
split_button_translation(const char *message)
{
char **buttons = NULL;
char_u *str;
int n_buttons = 0;
int n_expected = 1;
for (str = (char_u *)message; *str != NUL; ++str)
if (*str == DLG_BUTTON_SEP)
++n_expected;
str = (char_u *)_(message);
if (str != NULL)
{
if (output_conv.vc_type != CONV_NONE)
str = string_convert(&output_conv, str, NULL);
else
str = vim_strsave(str);
if (str != NULL)
buttons = split_button_string(str, &n_buttons);
}
/*
* Uh-oh... this should never ever happen. But we don't wanna crash
* if the translation is broken, thus fall back to the untranslated
* buttons string in case of emergency.
*/
if (buttons == NULL || n_buttons != n_expected)
{
vim_free(buttons);
vim_free(str);
buttons = NULL;
str = vim_strsave((char_u *)message);
if (str != NULL)
buttons = split_button_string(str, &n_buttons);
if (buttons == NULL)
vim_free(str);
}
return buttons;
}
static int
button_equal(const char *a, const char *b)
{
while (*a != '\0' && *b != '\0')
{
if (*a == '_' && *++a == '\0')
break;
if (*b == '_' && *++b == '\0')
break;
if (g_unichar_tolower(g_utf8_get_char(a))
!= g_unichar_tolower(g_utf8_get_char(b)))
return FALSE;
a = g_utf8_next_char(a);
b = g_utf8_next_char(b);
}
return (*a == '\0' && *b == '\0');
}
static void
dialog_add_buttons(GtkDialog *dialog, char_u *button_string)
{
char **ok;
char **ync; /* "yes no cancel" */
char **buttons;
int n_buttons = 0;
int idx;
button_string = vim_strsave(button_string); /* must be writable */
if (button_string == NULL)
return;
/* Check 'v' flag in 'guioptions': vertical button placement. */
if (vim_strchr(p_go, GO_VERTICAL) != NULL)
{
GtkWidget *vbutton_box;
vbutton_box = gtk_vbutton_box_new();
gtk_widget_show(vbutton_box);
gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->vbox),
vbutton_box, TRUE, FALSE, 0);
/* Overrule the "action_area" value, hopefully this works... */
GTK_DIALOG(dialog)->action_area = vbutton_box;
}
/*
* Yes this is ugly, I don't particularly like it either. But doing it
* this way has the compelling advantage that translations need not to
* be touched at all. See below what 'ok' and 'ync' are used for.
*/
ok = split_button_translation(N_("&Ok"));
ync = split_button_translation(N_("&Yes\n&No\n&Cancel"));
buttons = split_button_string(button_string, &n_buttons);
/*
* Yes, the buttons are in reversed order to match the GNOME 2 desktop
* environment. Don't hit me -- it's all about consistency.
* Well, apparently somebody changed his mind: with GTK 2.2.4 it works the
* other way around...
*/
for (idx = 1; idx <= n_buttons; ++idx)
{
char *label;
char_u *label8;
label = buttons[idx - 1];
/*
* Perform some guesswork to find appropriate stock items for the
* buttons. We have to compare with a sample of the translated
* button string to get things right. Yes, this is hackish :/
*
* But even the common button labels aren't necessarily translated,
* since anyone can create their own dialogs using Vim functions.
* Thus we have to check for those too.
*/
if (ok != NULL && ync != NULL) /* almost impossible to fail */
{
if (button_equal(label, ok[0])) label = GTK_STOCK_OK;
else if (button_equal(label, ync[0])) label = GTK_STOCK_YES;
else if (button_equal(label, ync[1])) label = GTK_STOCK_NO;
else if (button_equal(label, ync[2])) label = GTK_STOCK_CANCEL;
else if (button_equal(label, "Ok")) label = GTK_STOCK_OK;
else if (button_equal(label, "Yes")) label = GTK_STOCK_YES;
else if (button_equal(label, "No")) label = GTK_STOCK_NO;
else if (button_equal(label, "Cancel")) label = GTK_STOCK_CANCEL;
}
label8 = CONVERT_TO_UTF8((char_u *)label);
gtk_dialog_add_button(dialog, (const gchar *)label8, idx);
CONVERT_TO_UTF8_FREE(label8);
}
if (ok != NULL)
vim_free(*ok);
if (ync != NULL)
vim_free(*ync);
vim_free(ok);
vim_free(ync);
vim_free(buttons);
vim_free(button_string);
}
/*
* Allow mnemonic accelerators to be activated without pressing <Alt>.
* I'm not sure if it's a wise idea to do this. However, the old GTK+ 1.2
* GUI used to work this way, and I consider the impact on UI consistency
* low enough to justify implementing this as a special Vim feature.
*/
typedef struct _DialogInfo
{
int ignore_enter; /* no default button, ignore "Enter" */
int noalt; /* accept accelerators without Alt */
GtkDialog *dialog; /* Widget of the dialog */
} DialogInfo;
static gboolean
dialog_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
DialogInfo *di = (DialogInfo *)data;
/* Ignore hitting Enter (or Space) when there is no default button. */
if (di->ignore_enter && (event->keyval == GDK_Return
|| event->keyval == ' '))
return TRUE;
else /* A different key was pressed, return to normal behavior */
di->ignore_enter = FALSE;
/* Close the dialog when hitting "Esc". */
if (event->keyval == GDK_Escape)
{
gtk_dialog_response(di->dialog, GTK_RESPONSE_REJECT);
return TRUE;
}
if (di->noalt
&& (event->state & gtk_accelerator_get_default_mod_mask()) == 0)
{
return gtk_window_mnemonic_activate(
GTK_WINDOW(widget), event->keyval,
gtk_window_get_mnemonic_modifier(GTK_WINDOW(widget)));
}
return FALSE; /* continue emission */
}
int
gui_mch_dialog(int type, /* type of dialog */
char_u *title, /* title of dialog */
char_u *message, /* message text */
char_u *buttons, /* names of buttons */
int def_but, /* default button */
char_u *textfield, /* text for textfield or NULL */
int ex_cmd UNUSED)
{
GtkWidget *dialog;
GtkWidget *entry = NULL;
char_u *text;
int response;
DialogInfo dialoginfo;
dialog = create_message_dialog(type, title, message);
dialoginfo.dialog = GTK_DIALOG(dialog);
dialog_add_buttons(GTK_DIALOG(dialog), buttons);
if (textfield != NULL)
{
GtkWidget *alignment;
entry = gtk_entry_new();
gtk_widget_show(entry);
/* Make Enter work like pressing OK. */
gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
text = CONVERT_TO_UTF8(textfield);
gtk_entry_set_text(GTK_ENTRY(entry), (const char *)text);
CONVERT_TO_UTF8_FREE(text);
alignment = gtk_alignment_new((float)0.5, (float)0.5,
(float)1.0, (float)1.0);
gtk_container_add(GTK_CONTAINER(alignment), entry);
gtk_container_set_border_width(GTK_CONTAINER(alignment), 5);
gtk_widget_show(alignment);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
alignment, TRUE, FALSE, 0);
dialoginfo.noalt = FALSE;
}
else
dialoginfo.noalt = TRUE;
/* Allow activation of mnemonic accelerators without pressing <Alt> when
* there is no textfield. Handle pressing Esc. */
g_signal_connect(G_OBJECT(dialog), "key_press_event",
G_CALLBACK(&dialog_key_press_event_cb), &dialoginfo);
if (def_but > 0)
{
gtk_dialog_set_default_response(GTK_DIALOG(dialog), def_but);
dialoginfo.ignore_enter = FALSE;
}
else
/* No default button, ignore pressing Enter. */
dialoginfo.ignore_enter = TRUE;
/* Show the mouse pointer if it's currently hidden. */
gui_mch_mousehide(FALSE);
response = gtk_dialog_run(GTK_DIALOG(dialog));
/* GTK_RESPONSE_NONE means the dialog was programmatically destroyed. */
if (response != GTK_RESPONSE_NONE)
{
if (response == GTK_RESPONSE_ACCEPT) /* Enter pressed */
response = def_but;
if (textfield != NULL)
{
text = (char_u *)gtk_entry_get_text(GTK_ENTRY(entry));
text = CONVERT_FROM_UTF8(text);
vim_strncpy(textfield, text, IOSIZE - 1);
CONVERT_FROM_UTF8_FREE(text);
}
gtk_widget_destroy(dialog);
}
return response > 0 ? response : 0;
}
#endif /* FEAT_GUI_DIALOG */
#if defined(FEAT_MENU) || defined(PROTO)
void
gui_mch_show_popupmenu(vimmenu_T *menu)
{
# if defined(FEAT_XIM)
/*
* Append a submenu for selecting an input method. This is
* currently the only way to switch input methods at runtime.
*/
if (xic != NULL && g_object_get_data(G_OBJECT(menu->submenu_id),
"vim-has-im-menu") == NULL)
{
GtkWidget *menuitem;
GtkWidget *submenu;
char_u *name;
menuitem = gtk_separator_menu_item_new();
gtk_widget_show(menuitem);
gtk_menu_shell_append(GTK_MENU_SHELL(menu->submenu_id), menuitem);
name = (char_u *)_("Input _Methods");
name = CONVERT_TO_UTF8(name);
menuitem = gtk_menu_item_new_with_mnemonic((const char *)name);
CONVERT_TO_UTF8_FREE(name);
gtk_widget_show(menuitem);
submenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
gtk_menu_shell_append(GTK_MENU_SHELL(menu->submenu_id), menuitem);
gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(xic),
GTK_MENU_SHELL(submenu));
g_object_set_data(G_OBJECT(menu->submenu_id),
"vim-has-im-menu", GINT_TO_POINTER(TRUE));
}
# endif /* FEAT_XIM */
gtk_menu_popup(GTK_MENU(menu->submenu_id),
NULL, NULL,
(GtkMenuPositionFunc)NULL, NULL,
3U, gui.event_time);
}
/* Ugly global variable to pass "mouse_pos" flag from gui_make_popup() to
* popup_menu_position_func(). */
static int popup_mouse_pos;
/*
* Menu position callback; used by gui_make_popup() to place the menu
* at the current text cursor position.
*
* Note: The push_in output argument seems to affect scrolling of huge
* menus that don't fit on the screen. Leave it at the default for now.
*/
static void
popup_menu_position_func(GtkMenu *menu UNUSED,
gint *x, gint *y,
gboolean *push_in UNUSED,
gpointer user_data UNUSED)
{
gdk_window_get_origin(gui.drawarea->window, x, y);
if (popup_mouse_pos)
{
int mx, my;
gui_mch_getmouse(&mx, &my);
*x += mx;
*y += my;
}
else if (curwin != NULL && gui.drawarea != NULL && gui.drawarea->window != NULL)
{
/* Find the cursor position in the current window */
*x += FILL_X(W_WINCOL(curwin) + curwin->w_wcol + 1) + 1;
*y += FILL_Y(W_WINROW(curwin) + curwin->w_wrow + 1) + 1;
}
}
void
gui_make_popup(char_u *path_name, int mouse_pos)
{
vimmenu_T *menu;
popup_mouse_pos = mouse_pos;
menu = gui_find_menu(path_name);
if (menu != NULL && menu->submenu_id != NULL)
{
gtk_menu_popup(GTK_MENU(menu->submenu_id),
NULL, NULL,
&popup_menu_position_func, NULL,
0U, (guint32)GDK_CURRENT_TIME);
}
}
#endif /* FEAT_MENU */
/*
* We don't create it twice.
*/
typedef struct _SharedFindReplace
{
GtkWidget *dialog; /* the main dialog widget */
GtkWidget *wword; /* 'Whole word only' check button */
GtkWidget *mcase; /* 'Match case' check button */
GtkWidget *up; /* search direction 'Up' radio button */
GtkWidget *down; /* search direction 'Down' radio button */
GtkWidget *what; /* 'Find what' entry text widget */
GtkWidget *with; /* 'Replace with' entry text widget */
GtkWidget *find; /* 'Find Next' action button */
GtkWidget *replace; /* 'Replace With' action button */
GtkWidget *all; /* 'Replace All' action button */
} SharedFindReplace;
static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
static int
find_key_press_event(
GtkWidget *widget UNUSED,
GdkEventKey *event,
SharedFindReplace *frdp)
{
/* If the user is holding one of the key modifiers we will just bail out,
* thus preserving the possibility of normal focus traversal.
*/
if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))
return FALSE;
/* the Escape key synthesizes a cancellation action */
if (event->keyval == GDK_Escape)
{
gtk_widget_hide(frdp->dialog);
return TRUE;
}
/* It would be delightful if it where possible to do search history
* operations on the K_UP and K_DOWN keys here.
*/
return FALSE;
}
static GtkWidget *
create_image_button(const char *stock_id, const char *label)
{
char_u *text;
GtkWidget *box;
GtkWidget *alignment;
GtkWidget *button;
text = CONVERT_TO_UTF8((char_u *)label);
box = gtk_hbox_new(FALSE, 3);
gtk_box_pack_start(GTK_BOX(box),
gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON),
FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box),
gtk_label_new((const char *)text),
FALSE, FALSE, 0);
CONVERT_TO_UTF8_FREE(text);
alignment = gtk_alignment_new((float)0.5, (float)0.5,
(float)0.0, (float)0.0);
gtk_container_add(GTK_CONTAINER(alignment), box);
gtk_widget_show_all(alignment);
button = gtk_button_new();
gtk_container_add(GTK_CONTAINER(button), alignment);
return button;
}
/*
* This is currently only used by find_replace_dialog_create(), and
* I'd really like to keep it at that. In other words: don't spread
* this nasty hack all over the code. Think twice.
*/
static const char *
convert_localized_message(char_u **buffer, const char *message)
{
if (output_conv.vc_type == CONV_NONE)
return message;
vim_free(*buffer);
*buffer = string_convert(&output_conv, (char_u *)message, NULL);
return (const char *)*buffer;
}
static void
find_replace_dialog_create(char_u *arg, int do_replace)
{
GtkWidget *hbox; /* main top down box */
GtkWidget *actionarea;
GtkWidget *table;
GtkWidget *tmp;
GtkWidget *vbox;
gboolean sensitive;
SharedFindReplace *frdp;
char_u *entry_text;
int wword = FALSE;
int mcase = !p_ic;
char_u *conv_buffer = NULL;
# define CONV(message) convert_localized_message(&conv_buffer, (message))
frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
/* Get the search string to use. */
entry_text = get_find_dialog_text(arg, &wword, &mcase);
if (entry_text != NULL && output_conv.vc_type != CONV_NONE)
{
char_u *old_text = entry_text;
entry_text = string_convert(&output_conv, entry_text, NULL);
vim_free(old_text);
}
/*
* If the dialog already exists, just raise it.
*/
if (frdp->dialog)
{
if (entry_text != NULL)
{
gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword),
(gboolean)wword);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase),
(gboolean)mcase);
}
gtk_window_present(GTK_WINDOW(frdp->dialog));
vim_free(entry_text);
return;
}
frdp->dialog = gtk_dialog_new();
gtk_dialog_set_has_separator(GTK_DIALOG(frdp->dialog), FALSE);
gtk_window_set_transient_for(GTK_WINDOW(frdp->dialog), GTK_WINDOW(gui.mainwin));
gtk_window_set_destroy_with_parent(GTK_WINDOW(frdp->dialog), TRUE);
if (do_replace)
{
gtk_window_set_title(GTK_WINDOW(frdp->dialog),
CONV(_("VIM - Search and Replace...")));
}
else
{
gtk_window_set_title(GTK_WINDOW(frdp->dialog),
CONV(_("VIM - Search...")));
}
hbox = gtk_hbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 10);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(frdp->dialog)->vbox), hbox);
if (do_replace)
table = gtk_table_new(1024, 4, FALSE);
else
table = gtk_table_new(1024, 3, FALSE);
gtk_box_pack_start(GTK_BOX(hbox), table, TRUE, TRUE, 0);
gtk_container_border_width(GTK_CONTAINER(table), 4);
tmp = gtk_label_new(CONV(_("Find what:")));
gtk_misc_set_alignment(GTK_MISC(tmp), (gfloat)0.0, (gfloat)0.5);
gtk_table_attach(GTK_TABLE(table), tmp, 0, 1, 0, 1,
GTK_FILL, GTK_EXPAND, 2, 2);
frdp->what = gtk_entry_new();
sensitive = (entry_text != NULL && entry_text[0] != NUL);
if (entry_text != NULL)
gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text);
gtk_signal_connect(GTK_OBJECT(frdp->what), "changed",
GTK_SIGNAL_FUNC(entry_changed_cb), frdp->dialog);
gtk_signal_connect_after(GTK_OBJECT(frdp->what), "key_press_event",
GTK_SIGNAL_FUNC(find_key_press_event),
(gpointer) frdp);
gtk_table_attach(GTK_TABLE(table), frdp->what, 1, 1024, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND, 2, 2);
if (do_replace)
{
tmp = gtk_label_new(CONV(_("Replace with:")));
gtk_misc_set_alignment(GTK_MISC(tmp), (gfloat)0.0, (gfloat)0.5);
gtk_table_attach(GTK_TABLE(table), tmp, 0, 1, 1, 2,
GTK_FILL, GTK_EXPAND, 2, 2);
frdp->with = gtk_entry_new();
gtk_signal_connect(GTK_OBJECT(frdp->with), "activate",
GTK_SIGNAL_FUNC(find_replace_cb),
GINT_TO_POINTER(FRD_R_FINDNEXT));
gtk_signal_connect_after(GTK_OBJECT(frdp->with), "key_press_event",
GTK_SIGNAL_FUNC(find_key_press_event),
(gpointer) frdp);
gtk_table_attach(GTK_TABLE(table), frdp->with, 1, 1024, 1, 2,
GTK_EXPAND | GTK_FILL, GTK_EXPAND, 2, 2);
/*
* Make the entry activation only change the input focus onto the
* with item.
*/
gtk_signal_connect(GTK_OBJECT(frdp->what), "activate",
GTK_SIGNAL_FUNC(entry_activate_cb), frdp->with);
}
else
{
/*
* Make the entry activation do the search.
*/
gtk_signal_connect(GTK_OBJECT(frdp->what), "activate",
GTK_SIGNAL_FUNC(find_replace_cb),
GINT_TO_POINTER(FRD_FINDNEXT));
}
/* whole word only button */
frdp->wword = gtk_check_button_new_with_label(CONV(_("Match whole word only")));
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword),
(gboolean)wword);
if (do_replace)
gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 2, 3,
GTK_FILL, GTK_EXPAND, 2, 2);
else
gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 1, 2,
GTK_FILL, GTK_EXPAND, 2, 2);
/* match case button */
frdp->mcase = gtk_check_button_new_with_label(CONV(_("Match case")));
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase),
(gboolean)mcase);
if (do_replace)
gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 3, 4,
GTK_FILL, GTK_EXPAND, 2, 2);
else
gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 2, 3,
GTK_FILL, GTK_EXPAND, 2, 2);
tmp = gtk_frame_new(CONV(_("Direction")));
if (do_replace)
gtk_table_attach(GTK_TABLE(table), tmp, 1023, 1024, 2, 4,
GTK_FILL, GTK_FILL, 2, 2);
else
gtk_table_attach(GTK_TABLE(table), tmp, 1023, 1024, 1, 3,
GTK_FILL, GTK_FILL, 2, 2);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_border_width(GTK_CONTAINER(vbox), 0);
gtk_container_add(GTK_CONTAINER(tmp), vbox);
/* 'Up' and 'Down' buttons */
frdp->up = gtk_radio_button_new_with_label(NULL, CONV(_("Up")));
gtk_box_pack_start(GTK_BOX(vbox), frdp->up, TRUE, TRUE, 0);
frdp->down = gtk_radio_button_new_with_label(
gtk_radio_button_group(GTK_RADIO_BUTTON(frdp->up)),
CONV(_("Down")));
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->down), TRUE);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
gtk_box_pack_start(GTK_BOX(vbox), frdp->down, TRUE, TRUE, 0);
/* vbox to hold the action buttons */
actionarea = gtk_vbutton_box_new();
gtk_container_border_width(GTK_CONTAINER(actionarea), 2);
gtk_box_pack_end(GTK_BOX(hbox), actionarea, FALSE, FALSE, 0);
/* 'Find Next' button */
frdp->find = create_image_button(GTK_STOCK_FIND, _("Find Next"));
gtk_widget_set_sensitive(frdp->find, sensitive);
gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked",
GTK_SIGNAL_FUNC(find_replace_cb),
(do_replace) ? GINT_TO_POINTER(FRD_R_FINDNEXT)
: GINT_TO_POINTER(FRD_FINDNEXT));
GTK_WIDGET_SET_FLAGS(frdp->find, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(actionarea), frdp->find, FALSE, FALSE, 0);
gtk_widget_grab_default(frdp->find);
if (do_replace)
{
/* 'Replace' button */
frdp->replace = create_image_button(GTK_STOCK_CONVERT, _("Replace"));
gtk_widget_set_sensitive(frdp->replace, sensitive);
GTK_WIDGET_SET_FLAGS(frdp->replace, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(actionarea), frdp->replace, FALSE, FALSE, 0);
gtk_signal_connect(GTK_OBJECT(frdp->replace), "clicked",
GTK_SIGNAL_FUNC(find_replace_cb),
GINT_TO_POINTER(FRD_REPLACE));
/* 'Replace All' button */
frdp->all = create_image_button(GTK_STOCK_CONVERT, _("Replace All"));
gtk_widget_set_sensitive(frdp->all, sensitive);
GTK_WIDGET_SET_FLAGS(frdp->all, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(actionarea), frdp->all, FALSE, FALSE, 0);
gtk_signal_connect(GTK_OBJECT(frdp->all), "clicked",
GTK_SIGNAL_FUNC(find_replace_cb),
GINT_TO_POINTER(FRD_REPLACEALL));
}
/* 'Cancel' button */
tmp = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
GTK_WIDGET_SET_FLAGS(tmp, GTK_CAN_DEFAULT);
gtk_box_pack_end(GTK_BOX(actionarea), tmp, FALSE, FALSE, 0);
gtk_signal_connect_object(GTK_OBJECT(tmp),
"clicked", GTK_SIGNAL_FUNC(gtk_widget_hide),
GTK_OBJECT(frdp->dialog));
gtk_signal_connect_object(GTK_OBJECT(frdp->dialog),
"delete_event", GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
GTK_OBJECT(frdp->dialog));
tmp = gtk_vseparator_new();
gtk_box_pack_end(GTK_BOX(hbox), tmp, FALSE, FALSE, 10);
/* Suppress automatic show of the unused action area */
gtk_widget_hide(GTK_DIALOG(frdp->dialog)->action_area);
gtk_widget_show_all(hbox);
gtk_widget_show(frdp->dialog);
vim_free(entry_text);
vim_free(conv_buffer);
#undef CONV
}
void
gui_mch_find_dialog(exarg_T *eap)
{
if (gui.in_use)
find_replace_dialog_create(eap->arg, FALSE);
}
void
gui_mch_replace_dialog(exarg_T *eap)
{
if (gui.in_use)
find_replace_dialog_create(eap->arg, TRUE);
}
/*
* Callback for actions of the find and replace dialogs
*/
static void
find_replace_cb(GtkWidget *widget UNUSED, gpointer data)
{
int flags;
char_u *find_text;
char_u *repl_text;
gboolean direction_down;
SharedFindReplace *sfr;
flags = (int)(long)data; /* avoid a lint warning here */
/* Get the search/replace strings from the dialog */
if (flags == FRD_FINDNEXT)
{
repl_text = NULL;
sfr = &find_widgets;
}
else
{
repl_text = (char_u *)gtk_entry_get_text(GTK_ENTRY(repl_widgets.with));
sfr = &repl_widgets;
}
find_text = (char_u *)gtk_entry_get_text(GTK_ENTRY(sfr->what));
direction_down = GTK_TOGGLE_BUTTON(sfr->down)->active;
if (GTK_TOGGLE_BUTTON(sfr->wword)->active)
flags |= FRD_WHOLE_WORD;
if (GTK_TOGGLE_BUTTON(sfr->mcase)->active)
flags |= FRD_MATCH_CASE;
repl_text = CONVERT_FROM_UTF8(repl_text);
find_text = CONVERT_FROM_UTF8(find_text);
gui_do_findrepl(flags, find_text, repl_text, direction_down);
CONVERT_FROM_UTF8_FREE(repl_text);
CONVERT_FROM_UTF8_FREE(find_text);
}
/* our usual callback function */
static void
entry_activate_cb(GtkWidget *widget UNUSED, gpointer data)
{
gtk_widget_grab_focus(GTK_WIDGET(data));
}
/*
* Syncing the find/replace dialogs on the fly is utterly useless crack,
* and causes nothing but problems. Please tell me a use case for which
* you'd need both a find dialog and a find/replace one at the same time,
* without being able to actually use them separately since they're syncing
* all the time. I don't think it's worthwhile to fix this nonsense,
* particularly evil incarnation of braindeadness, whatever; I'd much rather
* see it extinguished from this planet. Thanks for listening. Sorry.
*/
static void
entry_changed_cb(GtkWidget * entry, GtkWidget * dialog)
{
const gchar *entry_text;
gboolean nonempty;
entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
if (!entry_text)
return; /* shouldn't happen */
nonempty = (entry_text[0] != '\0');
if (dialog == find_widgets.dialog)
{
gtk_widget_set_sensitive(find_widgets.find, nonempty);
}
if (dialog == repl_widgets.dialog)
{
gtk_widget_set_sensitive(repl_widgets.find, nonempty);
gtk_widget_set_sensitive(repl_widgets.replace, nonempty);
gtk_widget_set_sensitive(repl_widgets.all, nonempty);
}
}
/*
* ":helpfind"
*/
void
ex_helpfind(eap)
exarg_T *eap UNUSED;
{
/* This will fail when menus are not loaded. Well, it's only for
* backwards compatibility anyway. */
do_cmdline_cmd((char_u *)"emenu ToolBar.FindHelp");
}
#if defined(FEAT_BROWSE) || defined(PROTO)
static void
recent_func_log_func(const gchar *log_domain UNUSED,
GLogLevelFlags log_level UNUSED,
const gchar *message UNUSED,
gpointer user_data UNUSED)
{
/* We just want to suppress the warnings. */
/* http://bugzilla.gnome.org/show_bug.cgi?id=664587 */
}
#endif
| zyz2011-vim | src/gui_gtk.c | C | gpl2 | 53,162 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*
* File MOTIF_REDEFINES.H originally delivers together with
* OpenVMS Porting Library
* http://www.openvms.compaq.com/openvms/products/ips/porting.html
*
* This file has been modified for Vim development.
* Original file contains just defines that GTK for OpenVMS uses,
* but not all functions that DECW library has. Therefore it has been expanded
* with necessary defines for Vim on OpenVMS with GTK GUI.
*
* Zoltan Arpadffy <arpadffy@polarhome.com>
*/
/*
*************************************************************************
* *
* Copyright 2000 Compaq Computer Corporation *
* *
* COMPAQ Registered in U.S. Patent and Trademark Office. *
* *
*************************************************************************
* IMPORTANT: Carefully read the License Terms below before *
* proceeding. By use of these materials you agree to these terms. *
* If you do not agree to these terms, you may not use this software or *
* the accompanying documentation. *
*************************************************************************
* LICENSE TERMS *
* 1. GRANT *
* Compaq Computer Corporation ("COMPAQ") grants you the right to use, *
* modify, and distribute the following source code (the "Software") *
* on any number of computers. You may use the Software as part of *
* creating a software program or product intended for commercial or *
* non-commercial distribution in machine-readable source code, binary, *
* or executable formats. You may distribute the Software as *
* machine-readable source code provided this license is not removed *
* from the Software and any modifications are conspicuously indicated. *
* 2. COPYRIGHT *
* The Software is owned by COMPAQ and its suppliers and is protected by *
* copyright laws and international treaties. Your use of the Software *
* and associated documentation is subject to the applicable copyright *
* laws and the express rights and restrictions of these terms. *
* 3. RESTRICTIONS *
* You may not remove any copyright, trademark, or other proprietary *
* notices from the Software or the associated documentation. *
* You are responsible for compliance with all applicable export or *
* re-export control laws and regulations if you export the Software. *
* This license is governed by and is to be construed under the laws *
* of the State of Texas. *
* *
* DISCLAIMER OF WARRANTY AND LIABILITY *
* Compaq shall not be liable for technical or editorial errors or *
* omissions contained herein. The information contained herein is *
* subject to change without notice. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. *
* THE ENTIRE RISK ARISING OUT OF THE USE OF THIS SOFTWARE REMAINS WITH *
* RECIPIENT. IN NO EVENT SHALL COMPAQ BE LIABLE FOR ANY DIRECT, *
* CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE OR OTHER DAMAGES *
* WHATSOEVER (INCLUDING WITHOUT LIMITATION DAMAGES FOR LOSS OF BUSINESS *
* PROFITS, BUSINESS INTERRUPTION, OR LOSS OF BUSINESS INFORMATION), *
* EVEN IF COMPAQ HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES *
* AND WHETHER IN AN ACTION OF CONTRACT OR TORT INCLUDING NEGLIGENCE. *
* *
* If you have any questions concerning this license, please contact: *
* Compaq Computer Corporation, Software Business Practices, ZKO1-2/D22, *
* 110 Spit Brook Road, Nashua, NH. 03062-2698. *
* *
*************************************************************************
*/
/* INTRINSIC.H omits proto if XtFree is defined */
/* VMS_BEGIN_C_PLUS_PLUS */
extern void XtFree(char*);
extern void XTFREE(char*);
/* VMS_END_C_PLUS_PLUS */
#define _XRegisterFilterByType _XREGISTERFILTERBYTYPE
#define XAllocClassHint XALLOCCLASSHINT
#define XAllocColor XALLOCCOLOR
#define XAllocColorCells XALLOCCOLORCELLS
#define XAllocSizeHints XALLOCSIZEHINTS
#define XAllocWMHints XALLOCWMHINTS
#define XAutoRepeatOff XAUTOREPEATOFF
#define XAutoRepeatOn XAUTOREPEATON
#define XBaseFontNameListOfFontSet XBASEFONTNAMELISTOFFONTSET
#define XBell XBELL
#define XBitmapPad XBITMAPPAD
#define XChangeActivePointerGrab XCHANGEACTIVEPOINTERGRAB
#define XChangeGC XCHANGEGC
#define XChangeProperty XCHANGEPROPERTY
#define XChangeWindowAttributes XCHANGEWINDOWATTRIBUTES
#define XCheckIfEvent XCHECKIFEVENT
#define XCheckMaskEvent XCHECKMASKEVENT
#define XCheckTypedEvent XCHECKTYPEDEVENT
#define XCheckTypedWindowEvent XCHECKTYPEDWINDOWEVENT
#define XCheckWindowEvent XCHECKWINDOWEVENT
#define XClearArea XCLEARAREA
#define XClearWindow XCLEARWINDOW
#define XClipBox XCLIPBOX
#define XCloseDisplay XCLOSEDISPLAY
#define XCloseIM XCLOSEIM
#define XConfigureWindow XCONFIGUREWINDOW
#define XConvertSelection XCONVERTSELECTION
#define XCopyArea XCOPYAREA
#define XCopyGC XCOPYGC
#define XCopyPlane XCOPYPLANE
#define XCreateBitmapFromData XCREATEBITMAPFROMDATA
#define XCreateColormap XCREATECOLORMAP
#define XCreateFontCursor XCREATEFONTCURSOR
#define XCreateFontSet XCREATEFONTSET
#define XCreateGC XCREATEGC
#define XCreateIC XCREATEIC
#define XCreateImage XCREATEIMAGE
#define XCreatePixmap XCREATEPIXMAP
#define XCreatePixmapCursor XCREATEPIXMAPCURSOR
#define XCreatePixmapFromBitmapData XCREATEPIXMAPFROMBITMAPDATA
#define XCreateRegion XCREATEREGION
#define XCreateSimpleWindow XCREATESIMPLEWINDOW
#define XCreateWindow XCREATEWINDOW
#define XDefaultRootWindow XDEFAULTROOTWINDOW
#define XDefaultScreenOfDisplay XDEFAULTSCREENOFDISPLAY
#define XDefineCursor XDEFINECURSOR
#define XDeleteProperty XDELETEPROPERTY
#define XDestroyIC XDESTROYIC
#define XDestroyRegion XDESTROYREGION
#define XDestroyWindow XDESTROYWINDOW
#define XDisplayName XDISPLAYNAME
#define XDisplayOfScreen XDISPLAYOFSCREEN
#define XDisplayString XDISPLAYSTRING
#define XDrawArc XDRAWARC
#define XDrawImageString XDRAWIMAGESTRING
#define XDrawImageString16 XDRAWIMAGESTRING16
#define XDrawLine XDRAWLINE
#define XDrawLines XDRAWLINES
#define XDrawPoint XDRAWPOINT
#define XDrawPoints XDRAWPOINTS
#define XDrawRectangle XDRAWRECTANGLE
#define XDrawSegments XDRAWSEGMENTS
#define XDrawString XDRAWSTRING
#define XDrawString16 XDRAWSTRING16
#define XEmptyRegion XEMPTYREGION
#define XEqualRegion XEQUALREGION
#define XEventsQueued XEVENTSQUEUED
#define XExtentsOfFontSet XEXTENTSOFFONTSET
#define XFetchBuffer XFETCHBUFFER
#define XFillArc XFILLARC
#define XFillPolygon XFILLPOLYGON
#define XFillRectangle XFILLRECTANGLE
#define XFillRectangles XFILLRECTANGLES
#define XFilterEvent XFILTEREVENT
#define XFlush XFLUSH
#define XFontsOfFontSet XFONTSOFFONTSET
#define XFree XFREE
#define XFreeColormap XFREECOLORMAP
#define XFreeColors XFREECOLORS
#define XFreeCursor XFREECURSOR
#define XFreeFont XFREEFONT
#define XFreeFontInfo XFREEFONTINFO
#define XFreeFontNames XFREEFONTNAMES
#define XFreeFontSet XFREEFONTSET
#define XFreeGC XFREEGC
#define XFreeModifiermap XFREEMODIFIERMAP
#define XFreePixmap XFREEPIXMAP
#define XFreeStringList XFREESTRINGLIST
#define XGetAtomName XGETATOMNAME
#define XGetDefault XGETDEFAULT
#define XGetErrorDatabaseText XGETERRORDATABASETEXT
#define XGetErrorText XGETERRORTEXT
#define XGetFontProperty XGETFONTPROPERTY
#define XGetGCValues XGETGCVALUES
#define XGetGeometry XGETGEOMETRY
#define XGetIconSizes XGETICONSIZES
#define XGetICValues XGETICVALUES
#define XGetIMValues XGETIMVALUES
#define XGetImage XGETIMAGE
#define XGetKeyboardControl XGETKEYBOARDCONTROL
#define XGetModifierMapping XGETMODIFIERMAPPING
#define XGetMotionEvents XGETMOTIONEVENTS
#define XGetNormalHints XGETNORMALHINTS
#define XGetSelectionOwner XGETSELECTIONOWNER
#define XGetSubImage XGETSUBIMAGE
#define XGetVisualInfo XGETVISUALINFO
#define XGetWMColormapWindows XGETWMCOLORMAPWINDOWS
#define XGetWMIconName XGETWMICONNAME
#define XGetWMProtocols XGETWMPROTOCOLS
#define XGetWMHints XGETWMHINTS
#define XGetWMName XGETWMNAME
#define XGetWMNormalHints XGETWMNORMALHINTS
#define XGetWindowAttributes XGETWINDOWATTRIBUTES
#define XGetWindowProperty XGETWINDOWPROPERTY
#define XGrabKeyboard XGRABKEYBOARD
#define XGrabPointer XGRABPOINTER
#define XGrabServer XGRABSERVER
#define XHeightOfScreen XHEIGHTOFSCREEN
#define XIconifyWindow XICONIFYWINDOW
#define XIfEvent XIFEVENT
#define XInternAtom XINTERNATOM
#define XIntersectRegion XINTERSECTREGION
#define XKeycodeToKeysym XKEYCODETOKEYSYM
#define XKeysymToKeycode XKEYSYMTOKEYCODE
#define XKeysymToString XKEYSYMTOSTRING
#define XListFonts XLISTFONTS
#define XListFontsWithInfo XLISTFONTSWITHINFO
#define XListPixmapFormats XLISTPIXMAPFORMATS
#define XListProperties XLISTPROPERTIES
#define XLoadQueryFont XLOADQUERYFONT
#define XLookupString XLOOKUPSTRING
#define XLowerWindow XLOWERWINDOW
#define XMapRaised XMAPRAISED
#define XMapWindow XMAPWINDOW
#define XMatchVisualInfo XMATCHVISUALINFO
#define XMoveResizeWindow XMOVERESIZEWINDOW
#define XMoveWindow XMOVEWINDOW
#define XNextEvent XNEXTEVENT
#define XOffsetRegion XOFFSETREGION
#define XOpenDisplay XOPENDISPLAY
#define XOpenIM XOPENIM
#define XParseColor XPARSECOLOR
#define XParseGeometry XPARSEGEOMETRY
#define XPeekEvent XPEEKEVENT
#define XPending XPENDING
#define XPointInRegion XPOINTINREGION
#define XPolygonRegion XPOLYGONREGION
#define XPutBackEvent XPUTBACKEVENT
#define XPutImage XPUTIMAGE
#define XRootWindow XROOTWINDOW
#define XQueryColor XQUERYCOLOR
#define XQueryColors XQUERYCOLORS
#define XQueryExtension XQUERYEXTENSION
#define XQueryPointer XQUERYPOINTER
#define XQueryTree XQUERYTREE
#define XRaiseWindow XRAISEWINDOW
#define XReconfigureWMWindow XRECONFIGUREWMWINDOW
#define XRectInRegion XRECTINREGION
#define XRefreshKeyboardMapping XREFRESHKEYBOARDMAPPING
#define XReparentWindow XREPARENTWINDOW
#define XResizeWindow XRESIZEWINDOW
#define XRestackWindows XRESTACKWINDOWS
#define XRootWindowOfScreen XROOTWINDOWOFSCREEN
#define XScreenNumberOfScreen XSCREENNUMBEROFSCREEN
#define XSelectAsyncEvent XSELECTASYNCEVENT
#define XSelectAsyncInput XSELECTASYNCINPUT
#define XSelectInput XSELECTINPUT
#define XSendEvent XSENDEVENT
#define XServerVendor XSERVERVENDOR
#define XSetBackground XSETBACKGROUND
#define XSetClassHint XSETCLASSHINT
#define XSetClipMask XSETCLIPMASK
#define XSetClipOrigin XSETCLIPORIGIN
#define XSetClipRectangles XSETCLIPRECTANGLES
#define XSetCloseDownMode XSETCLOSEDOWNMODE
#define XSetCommand XSETCOMMAND
#define XSetDashes XSETDASHES
#define XSetErrorHandler XSETERRORHANDLER
#define XSetFillStyle XSETFILLSTYLE
#define XSetFont XSETFONT
#define XSetForeground XSETFOREGROUND
#define XSetFunction XSETFUNCTION
#define XSetGraphicsExposures XSETGRAPHICSEXPOSURES
#define XSetICFocus XSETICFOCUS
#define XSetICValues XSETICVALUES
#define XSetIOErrorHandler XSETIOERRORHANDLER
#define XSetInputFocus XSETINPUTFOCUS
#define XSetLineAttributes XSETLINEATTRIBUTES
#define XSetLocaleModifiers XSETLOCALEMODIFIERS
#define XSetNormalHints XSETNORMALHINTS
#define XSetRegion XSETREGION
#define XSetSelectionOwner XSETSELECTIONOWNER
#define XSetStipple XSETSTIPPLE
#define XSetSubwindowMode XSETSUBWINDOWMODE
#define XSetTSOrigin XSETTSORIGIN
#define XSetTile XSETTILE
#define XSetTransientForHint XSETTRANSIENTFORHINT
#define XSetWMColormapWindows XSETWMCOLORMAPWINDOWS
#define XSetWMHints XSETWMHINTS
#define XSetWMIconName XSETWMICONNAME
#define XSetWMName XSETWMNAME
#define XSetWMNormalHints XSETWMNORMALHINTS
#define XSetWMProperties XSETWMPROPERTIES
#define XSetWMProtocols XSETWMPROTOCOLS
#define XSetWindowBackground XSETWINDOWBACKGROUND
#define XSetWindowBackgroundPixmap XSETWINDOWBACKGROUNDPIXMAP
#define XSetWindowColormap XSETWINDOWCOLORMAP
#define XShapeCombineMask XSHAPECOMBINEMASK
#define XShapeCombineRectangles XSHAPECOMBINERECTANGLES
#define XShapeGetRectangles XSHAPEGETRECTANGLES
#define XShrinkRegion XSHRINKREGION
#define XStoreBuffer XSTOREBUFFER
#define XStoreColor XSTORECOLOR
#define XStoreColors XSTORECOLORS
#define XStoreName XSTORENAME
#define XStringToKeysym XSTRINGTOKEYSYM
#define XSubtractRegion XSUBTRACTREGION
#define XSupportsLocale XSUPPORTSLOCALE
#define XSync XSYNC
#define XSynchronize XSYNCHRONIZE
#define XTextExtents XTEXTEXTENTS
#define XTextExtents16 XTEXTEXTENTS16
#define XTextWidth XTEXTWIDTH
#define XTextWidth16 XTEXTWIDTH16
#define XTranslateCoordinates XTRANSLATECOORDINATES
#define XUndefineCursor XUNDEFINECURSOR
#define XUngrabKeyboard XUNGRABKEYBOARD
#define XUngrabPointer XUNGRABPOINTER
#define XUngrabServer XUNGRABSERVER
#define XUnionRectWithRegion XUNIONRECTWITHREGION
#define XUnionRegion XUNIONREGION
#define XUnmapWindow XUNMAPWINDOW
#define _XUnregisterFilter _XUNREGISTERFILTER
#define XUnsetICFocus XUNSETICFOCUS
#define XVaCreateNestedList XVACREATENESTEDLIST
#define XVisualIDFromVisual XVISUALIDFROMVISUAL
#define XWarpPointer XWARPPOINTER
#define XWidthOfScreen XWIDTHOFSCREEN
#define XWindowEvent XWINDOWEVENT
#define XWithdrawWindow XWITHDRAWWINDOW
#define XXorRegion XXORREGION
#define XmAddProtocolCallback XMADDPROTOCOLCALLBACK
#define XmAddProtocols XMADDPROTOCOLS
#define XmChangeColor XMCHANGECOLOR
#define XmClipboardCopy XMCLIPBOARDCOPY
#define XmClipboardEndCopy XMCLIPBOARDENDCOPY
#define XmClipboardInquireLength XMCLIPBOARDINQUIRELENGTH
#define XmClipboardLock XMCLIPBOARDLOCK
#define XmClipboardRetrieve XMCLIPBOARDRETRIEVE
#define XmClipboardStartCopy XMCLIPBOARDSTARTCOPY
#define XmClipboardUnlock XMCLIPBOARDUNLOCK
#define XmCreateArrowButton XMCREATEARROWBUTTON
#define XmCreateArrowButtonGadget XMCREATEARROWBUTTONGADGET
#define XmCreateCascadeButton XMCREATECASCADEBUTTON
#define XmCreateDialogShell XMCREATEDIALOGSHELL
#define XmCreateDragIcon XMCREATEDRAGICON
#define XmCreateDrawingArea XMCREATEDRAWINGAREA
#define XmCreateDrawnButton XMCREATEDRAWNBUTTON
#define XmCreateFileSelectionBox XMCREATEFILESELECTIONBOX
#define XmCreateFileSelectionDialog XMCREATEFILESELECTIONDIALOG
#define XmCreateForm XMCREATEFORM
#define XmCreateFormDialog XMCREATEFORMDIALOG
#define XmCreateFrame XMCREATEFRAME
#define XmCreateInformationDialog XMCREATEINFORMATIONDIALOG
#define XmCreateLabelGadget XMCREATELABELGADGET
#define XmCreateMainWindow XMCREATEMAINWINDOW
#define XmCreateMenuBar XMCREATEMENUBAR
#define XmCreateMessageBox XMCREATEMESSAGEBOX
#define XmCreateMessageDialog XMCREATEMESSAGEDIALOG
#define XmCreateOptionMenu XMCREATEOPTIONMENU
#define XmCreatePanedWindow XMCREATEPANEDWINDOW
#define XmCreatePopupMenu XMCREATEPOPUPMENU
#define XmCreatePromptDialog XMCREATEPROMPTDIALOG
#define XmCreatePulldownMenu XMCREATEPULLDOWNMENU
#define XmCreatePushButton XMCREATEPUSHBUTTON
#define XmCreatePushButtonGadget XMCREATEPUSHBUTTONGADGET
#define XmCreateQuestionDialog XMCREATEQUESTIONDIALOG
#define XmCreateRadioBox XMCREATERADIOBOX
#define XmCreateRowColumn XMCREATEROWCOLUMN
#define XmCreateScale XMCREATESCALE
#define XmCreateScrollBar XMCREATESCROLLBAR
#define XmCreateScrolledList XMCREATESCROLLEDLIST
#define XmCreateScrolledText XMCREATESCROLLEDTEXT
#define XmCreateScrolledWindow XMCREATESCROLLEDWINDOW
#define XmCreateSelectionDialog XMCREATESELECTIONDIALOG
#define XmCreateSeparator XMCREATESEPARATOR
#define XmCreateSeparatorGadget XMCREATESEPARATORGADGET
#define XmCreateTemplateDialog XMCREATETEMPLATEDIALOG
#define XmCreateText XMCREATETEXT
#define XmCreateTextField XMCREATETEXTFIELD
#define XmCreateToggleButton XMCREATETOGGLEBUTTON
#define XmCreateToggleButtonGadget XMCREATETOGGLEBUTTONGADGET
#define XmDragStart XMDRAGSTART
#define XmDropSiteRegister XMDROPSITEREGISTER
#define XmDropSiteUnregister XMDROPSITEUNREGISTER
#define XmDropSiteUpdate XMDROPSITEUPDATE
#define XmDropTransferStart XMDROPTRANSFERSTART
#define XmFileSelectionBoxGetChild XMFILESELECTIONBOXGETCHILD
#define XmFileSelectionDoSearch XMFILESELECTIONDOSEARCH
#define XmFontListAppendEntry XMFONTLISTAPPENDENTRY
#define XmFontListCopy XMFONTLISTCOPY
#define XmFontListCreate XMFONTLISTCREATE
#define XmFontListEntryCreate XMFONTLISTENTRYCREATE
#define XmFontListEntryFree XMFONTLISTENTRYFREE
#define XmFontListEntryGetFont XMFONTLISTENTRYGETFONT
#define XmFontListEntryGetTag XMFONTLISTENTRYGETTAG
#define XmFontListEntryLoad XMFONTLISTENTRYLOAD
#define XmFontListFree XMFONTLISTFREE
#define XmFontListFreeFontContext XMFONTLISTFREEFONTCONTEXT
#define XmFontListGetNextFont XMFONTLISTGETNEXTFONT
#define XmFontListInitFontContext XMFONTLISTINITFONTCONTEXT
#define XmFontListNextEntry XMFONTLISTNEXTENTRY
#define XmGetColors XMGETCOLORS
#define XmGetFocusWidget XMGETFOCUSWIDGET
#define XmGetMenuCursor XMGETMENUCURSOR
#define XmGetPixmapByDepth XMGETPIXMAPBYDEPTH
#define XmGetTearOffControl XMGETTEAROFFCONTROL
#define XmGetXmDisplay XMGETXMDISPLAY
#define XmImMbLookupString XMIMMBLOOKUPSTRING
#define XmImRegister XMIMREGISTER
#define XmImSetFocusValues XMIMSETFOCUSVALUES
#define XmImSetValues XMIMSETVALUES
#define XmImUnregister XMIMUNREGISTER
#define XmImUnsetFocus XMIMUNSETFOCUS
#define XmInternAtom XMINTERNATOM
#define XmIsMotifWMRunning XMISMOTIFWMRUNNING
#define XmListAddItem XMLISTADDITEM
#define XmListAddItemUnselected XMLISTADDITEMUNSELECTED
#define XmListAddItemsUnselected XMLISTADDITEMSUNSELECTED
#define XmListDeleteAllItems XMLISTDELETEALLITEMS
#define XmListDeleteItemsPos XMLISTDELETEITEMSPOS
#define XmListDeletePos XMLISTDELETEPOS
#define XmListDeselectAllItems XMLISTDESELECTALLITEMS
#define XmListDeselectPos XMLISTDESELECTPOS
#define XmListGetKbdItemPos XMLISTGETKBDITEMPOS
#define XmListGetMatchPos XMLISTGETMATCHPOS
#define XmListGetSelectedPos XMLISTGETSELECTEDPOS
#define XmListPosSelected XMLISTPOSSELECTED
#define XmListSelectItem XMLISTSELECTITEM
#define XmListSelectPos XMLISTSELECTPOS
#define XmListSetBottomPos XMLISTSETBOTTOMPOS
#define XmListSetItem XMLISTSETITEM
#define XmListSetKbdItemPos XMLISTSETKBDITEMPOS
#define XmListSetPos XMLISTSETPOS
#define XmMainWindowSetAreas XMMAINWINDOWSETAREAS
#define XmMenuPosition XMMENUPOSITION
#define XmMessageBoxGetChild XMMESSAGEBOXGETCHILD
#define XmOptionButtonGadget XMOPTIONBUTTONGADGET
#define XmOptionLabelGadget XMOPTIONLABELGADGET
#define XmProcessTraversal XMPROCESSTRAVERSAL
#define XmQmotif XMQMOTIF
#define XmRemoveProtocolCallback XMREMOVEPROTOCOLCALLBACK
#define XmRepTypeGetId XMREPTYPEGETID
#define XmRepTypeGetRecord XMREPTYPEGETRECORD
#define XmRepTypeRegister XMREPTYPEREGISTER
#define XmRepTypeValidValue XMREPTYPEVALIDVALUE
#define XmScrollBarSetValues XMSCROLLBARSETVALUES
#define XmScrolledWindowSetAreas XMSCROLLEDWINDOWSETAREAS
#define XmSelectionBoxGetChild XMSELECTIONBOXGETCHILD
#define XmStringByteCompare XMSTRINGBYTECOMPARE
#define XmStringCompare XMSTRINGCOMPARE
#define XmStringConcat XMSTRINGCONCAT
#define XmStringCopy XMSTRINGCOPY
#define XmStringCreate XMSTRINGCREATE
#define XmStringCreateLocalized XMSTRINGCREATELOCALIZED
#define XmStringCreateLtoR XMSTRINGCREATELTOR
#define XmStringCreateSimple XMSTRINGCREATESIMPLE
#define XmStringDraw XMSTRINGDRAW
#define XmStringDrawUnderline XMSTRINGDRAWUNDERLINE
#define XmStringExtent XMSTRINGEXTENT
#define XmStringFree XMSTRINGFREE
#define XmStringFreeContext XMSTRINGFREECONTEXT
#define XmStringGetLtoR XMSTRINGGETLTOR
#define XmStringGetNextComponent XMSTRINGGETNEXTCOMPONENT
#define XmStringGetNextSegment XMSTRINGGETNEXTSEGMENT
#define XmStringInitContext XMSTRINGINITCONTEXT
#define XmStringLength XMSTRINGLENGTH
#define XmStringLtoRCreate XMSTRINGLTORCREATE
#define XmStringNConcat XMSTRINGNCONCAT
#define XmStringSegmentCreate XMSTRINGSEGMENTCREATE
#define XmStringWidth XMSTRINGWIDTH
#define XmTextClearSelection XMTEXTCLEARSELECTION
#define XmTextFieldGetEditable XMTEXTFIELDGETEDITABLE
#define XmTextFieldGetInsertionPosition XMTEXTFIELDGETINSERTIONPOSITION
#define XmTextFieldGetLastPosition XMTEXTFIELDGETLASTPOSITION
#define XmTextFieldGetSelection XMTEXTFIELDGETSELECTION
#define XmTextFieldGetString XMTEXTFIELDGETSTRING
#define XmTextFieldInsert XMTEXTFIELDINSERT
#define XmTextFieldRemove XMTEXTFIELDREMOVE
#define XmTextFieldSetSelection XMTEXTFIELDSETSELECTION
#define XmTextFieldSetString XMTEXTFIELDSETSTRING
#define XmTextGetCursorPosition XMTEXTGETCURSORPOSITION
#define XmTextGetInsertionPosition XMTEXTGETINSERTIONPOSITION
#define XmTextGetLastPosition XMTEXTGETLASTPOSITION
#define XmTextGetMaxLength XMTEXTGETMAXLENGTH
#define XmTextGetSelection XMTEXTGETSELECTION
#define XmTextGetSelectionPosition XMTEXTGETSELECTIONPOSITION
#define XmTextGetString XMTEXTGETSTRING
#define XmTextInsert XMTEXTINSERT
#define XmTextRemove XMTEXTREMOVE
#define XmTextReplace XMTEXTREPLACE
#define XmTextSetCursorPosition XMTEXTSETCURSORPOSITION
#define XmTextSetHighlight XMTEXTSETHIGHLIGHT
#define XmTextSetInsertionPosition XMTEXTSETINSERTIONPOSITION
#define XmTextSetSelection XMTEXTSETSELECTION
#define XmTextSetString XMTEXTSETSTRING
#define XmToggleButtonGadgetGetState XMTOGGLEBUTTONGADGETGETSTATE
#define XmToggleButtonGadgetSetState XMTOGGLEBUTTONGADGETSETSTATE
#define XmToggleButtonGetState XMTOGGLEBUTTONGETSTATE
#define XmToggleButtonSetState XMTOGGLEBUTTONSETSTATE
#define XmUpdateDisplay XMUPDATEDISPLAY
#define XmVaCreateSimpleRadioBox XMVACREATESIMPLERADIOBOX
#define XmbDrawString XMBDRAWSTRING
#define XmbLookupString XMBLOOKUPSTRING
#define XmbResetIC XMBRESETIC
#define XmbSetWMProperties XMBSETWMPROPERTIES
#define XmbTextEscapement XMBTEXTESCAPEMENT
#define XmbTextExtents XMBTEXTEXTENTS
#define XmbTextListToTextProperty XMBTEXTLISTTOTEXTPROPERTY
#define XmbTextPropertyToTextList XMBTEXTPROPERTYTOTEXTLIST
#define XmuClientWindow XMUCLIENTWINDOW
#define XmuPrintDefaultErrorMessage XMUPRINTDEFAULTERRORMESSAGE
#define XrmGetDatabase XRMGETDATABASE
#define XrmGetResource XRMGETRESOURCE
#define XrmPutStringResource XRMPUTSTRINGRESOURCE
#define XrmQuarkToString XRMQUARKTOSTRING
#define XrmStringToQuark XRMSTRINGTOQUARK
#define XtAddCallback XTADDCALLBACK
#define XtAddCallbacks XTADDCALLBACKS
#define XtAddEventHandler XTADDEVENTHANDLER
#define XtAddGrab XTADDGRAB
#define XtAllocateGC XTALLOCATEGC
#define XtAppAddActions XTAPPADDACTIONS
#define XtAppAddInput XTAPPADDINPUT
#define XtAppAddTimeOut XTAPPADDTIMEOUT
#define XtAppCreateShell XTAPPCREATESHELL
#define XtAppInitialize XTAPPINITIALIZE
#define XtAppNextEvent XTAPPNEXTEVENT
#define XtAppPeekEvent XTAPPPEEKEVENT
#define XtAppPending XTAPPPENDING
#define XtAppProcessEvent XTAPPPROCESSEVENT
#define XtAppSetErrorHandler XTAPPSETERRORHANDLER
#define XtAppSetFallbackResources XTAPPSETFALLBACKRESOURCES
#define XtAppSetWarningHandler XTAPPSETWARNINGHANDLER
#define XtAppSetWarningMsgHandler XTAPPSETWARNINGMSGHANDLER
#define XtAppWarning XTAPPWARNING
#define XtCallActionProc XTCALLACTIONPROC
#define XtCallCallbackList XTCALLCALLBACKLIST
#define XtCallCallbacks XTCALLCALLBACKS
#define XtConfigureWidget XTCONFIGUREWIDGET
#define XtConvertAndStore XTCONVERTANDSTORE
#define XtCreateApplicationContext XTCREATEAPPLICATIONCONTEXT
#define XtCreateManagedWidget XTCREATEMANAGEDWIDGET
#define XtCreatePopupShell XTCREATEPOPUPSHELL
#define XtCreateWidget XTCREATEWIDGET
#define XtDatabase XTDATABASE
#define XtDestroyWidget XTDESTROYWIDGET
#define XtDisownSelection XTDISOWNSELECTION
#define XtDispatchEvent XTDISPATCHEVENT
#define XtDisplayOfObject XTDISPLAYOFOBJECT
#define XtDisplayStringConvWarning XTDISPLAYSTRINGCONVWARNING
#define XtDisplayToApplicationContext XTDISPLAYTOAPPLICATIONCONTEXT
#define XtFree XTFREE
#define XtGetActionKeysym XTGETACTIONKEYSYM
#define XtGetActionList XTGETACTIONLIST
#define XtGetApplicationNameAndClass XTGETAPPLICATIONNAMEANDCLASS
#define XtGetApplicationResources XTGETAPPLICATIONRESOURCES
#define XtGetGC XTGETGC
#define XtGetMultiClickTime XTGETMULTICLICKTIME
#define XtGetSelectionValue XTGETSELECTIONVALUE
#define XtGetSelectionValues XTGETSELECTIONVALUES
#define XtGetSubresources XTGETSUBRESOURCES
#define XtGetValues XTGETVALUES
#define XtGrabKeyboard XTGRABKEYBOARD
#define XtGrabPointer XTGRABPOINTER
#define XtHasCallbacks XTHASCALLBACKS
#define XtInitializeWidgetClass XTINITIALIZEWIDGETCLASS
#define XtInsertEventHandler XTINSERTEVENTHANDLER
#define XtIsManaged XTISMANAGED
#define XtIsObject XTISOBJECT
#define XtIsSensitive XTISSENSITIVE
#define XtIsSubclass XTISSUBCLASS
#define XtLastTimestampProcessed XTLASTTIMESTAMPPROCESSED
#define XtMakeGeometryRequest XTMAKEGEOMETRYREQUEST
#define XtMakeResizeRequest XTMAKERESIZEREQUEST
#define XtMalloc XTMALLOC
#define XtManageChild XTMANAGECHILD
#define XtManageChildren XTMANAGECHILDREN
#define XtMergeArgLists XTMERGEARGLISTS
#define XtMoveWidget XTMOVEWIDGET
#define XtName XTNAME
#define XtNameToWidget XTNAMETOWIDGET
#define XtOpenDisplay XTOPENDISPLAY
#define XtOverrideTranslations XTOVERRIDETRANSLATIONS
#define XtOwnSelection XTOWNSELECTION
#define XtParent XTPARENT
#define XtParseTranslationTable XTPARSETRANSLATIONTABLE
#define XtPopdown XTPOPDOWN
#define XtPopup XTPOPUP
#define XtQueryGeometry XTQUERYGEOMETRY
#define XtRealizeWidget XTREALIZEWIDGET
#define XtRealloc XTREALLOC
#define XtReleaseGC XTRELEASEGC
#define XtRemoveAllCallbacks XTREMOVEALLCALLBACKS
#define XtRemoveCallback XTREMOVECALLBACK
#define XtRemoveEventHandler XTREMOVEEVENTHANDLER
#define XtRemoveGrab XTREMOVEGRAB
#define XtRemoveInput XTREMOVEINPUT
#define XtRemoveTimeOut XTREMOVETIMEOUT
#define XtResizeWidget XTRESIZEWIDGET
#define XtResolvePathname XTRESOLVEPATHNAME
#define XtSetKeyboardFocus XTSETKEYBOARDFOCUS
#define XtSetMappedWhenManaged XTSETMAPPEDWHENMANAGED
#define XtSetSensitive XTSETSENSITIVE
#define XtSetTypeConverter XTSETTYPECONVERTER
#define XtSetValues XTSETVALUES
#define XtShellStrings XTSHELLSTRINGS
#define XtStrings XTSTRINGS
#define XtToolkitInitialize XTTOOLKITINITIALIZE
#define XtTranslateCoords XTTRANSLATECOORDS
#define XtTranslateKeycode XTTRANSLATEKEYCODE
#define XtUngrabKeyboard XTUNGRABKEYBOARD
#define XtUngrabPointer XTUNGRABPOINTER
#define XtUnmanageChild XTUNMANAGECHILD
#define XtUnmanageChildren XTUNMANAGECHILDREN
#define XtUnrealizeWidget XTUNREALIZEWIDGET
#define XtVaAppCreateShell XTVAAPPCREATESHELL
#define XtVaCreateManagedWidget XTVACREATEMANAGEDWIDGET
#define XtVaCreatePopupShell XTVACREATEPOPUPSHELL
#define XtVaCreateWidget XTVACREATEWIDGET
#define XtVaGetValues XTVAGETVALUES
#define XtVaSetValues XTVASETVALUES
#define XtWarning XTWARNING
#define XtWidgetToApplicationContext XTWIDGETTOAPPLICATIONCONTEXT
#define XtWindow XTWINDOW
#define XtWindowOfObject XTWINDOWOFOBJECT
#define XtWindowToWidget XTWINDOWTOWIDGET
#define XwcDrawString XWCDRAWSTRING
#define XwcFreeStringList XWCFREESTRINGLIST
#define XwcTextEscapement XWCTEXTESCAPEMENT
#define XwcTextExtents XWCTEXTEXTENTS
#define XwcTextListToTextProperty XWCTEXTLISTTOTEXTPROPERTY
#define XwcTextPropertyToTextList XWCTEXTPROPERTYTOTEXTLIST
#define _XmBottomShadowColorDefault _XMBOTTOMSHADOWCOLORDEFAULT
#define _XmClearBorder _XMCLEARBORDER
#define _XmConfigureObject _XMCONFIGUREOBJECT
#define _XmDestroyParentCallback _XMDESTROYPARENTCALLBACK
#define _XmDrawArrow _XMDRAWARROW
#define _XmDrawShadows _XMDRAWSHADOWS
#define _XmFontListGetDefaultFont _XMFONTLISTGETDEFAULTFONT
#define _XmFromHorizontalPixels _XMFROMHORIZONTALPIXELS
#define _XmFromVerticalPixels _XMFROMVERTICALPIXELS
#define _XmGetClassExtensionPtr _XMGETCLASSEXTENSIONPTR
#define _XmGetDefaultFontList _XMGETDEFAULTFONTLIST
#define _XmGetTextualDragIcon _XMGETTEXTUALDRAGICON
#define _XmGetWidgetExtData _XMGETWIDGETEXTDATA
#define _XmGrabKeyboard _XMGRABKEYBOARD
#define _XmGrabPointer _XMGRABPOINTER
#define _XmInheritClass _XMINHERITCLASS
#define _XmInputInGadget _XMINPUTINGADGET
#define _XmMakeGeometryRequest _XMMAKEGEOMETRYREQUEST
#define _XmMenuPopDown _XMMENUPOPDOWN
#define _XmMoveObject _XMMOVEOBJECT
#define _XmNavigChangeManaged _XMNAVIGCHANGEMANAGED
#define _XmOSBuildFileList _XMOSBUILDFILELIST
#define _XmOSFileCompare _XMOSFILECOMPARE
#define _XmOSFindPatternPart _XMOSFINDPATTERNPART
#define _XmOSQualifyFileSpec _XMOSQUALIFYFILESPEC
#define _XmPostPopupMenu _XMPOSTPOPUPMENU
#define _XmPrimitiveEnter _XMPRIMITIVEENTER
#define _XmPrimitiveLeave _XMPRIMITIVELEAVE
#define _XmRedisplayGadgets _XMREDISPLAYGADGETS
#define _XmShellIsExclusive _XMSHELLISEXCLUSIVE
#define _XmStringDraw _XMSTRINGDRAW
#define _XmStringGetTextConcat _XMSTRINGGETTEXTCONCAT
#define _XmStrings _XMSTRINGS
#define _XmToHorizontalPixels _XMTOHORIZONTALPIXELS
#define _XmToVerticalPixels _XMTOVERTICALPIXELS
#define _XmTopShadowColorDefault _XMTOPSHADOWCOLORDEFAULT
#define _Xm_fastPtr _XM_FASTPTR
#define _XtCheckSubclassFlag _XTCHECKSUBCLASSFLAG
#define _XtInherit _XTINHERIT
#define _XtInheritTranslations _XTINHERITTRANSLATIONS
#define applicationShellWidgetClass APPLICATIONSHELLWIDGETCLASS
#define compositeWidgetClass COMPOSITEWIDGETCLASS
#define overrideShellWidgetClass OVERRIDESHELLWIDGETCLASS
#define shellWidgetClass SHELLWIDGETCLASS
#define topLevelShellClassRec TOPLEVELSHELLCLASSREC
#define topLevelShellWidgetClass TOPLEVELSHELLWIDGETCLASS
#define transientShellWidgetClass TRANSIENTSHELLWIDGETCLASS
#define vendorShellClassRec VENDORSHELLCLASSREC
#define vendorShellWidgetClass VENDORSHELLWIDGETCLASS
#define wmShellWidgetClass WMSHELLWIDGETCLASS
#define xmArrowButtonWidgetClass XMARROWBUTTONWIDGETCLASS
#define xmCascadeButtonClassRec XMCASCADEBUTTONCLASSREC
#define xmCascadeButtonGadgetClass XMCASCADEBUTTONGADGETCLASS
#define xmCascadeButtonWidgetClass XMCASCADEBUTTONWIDGETCLASS
#define xmDialogShellWidgetClass XMDIALOGSHELLWIDGETCLASS
#define xmDrawingAreaWidgetClass XMDRAWINGAREAWIDGETCLASS
#define xmDrawnButtonWidgetClass XMDRAWNBUTTONWIDGETCLASS
#define xmFileSelectionBoxWidgetClass XMFILESELECTIONBOXWIDGETCLASS
#define xmFormWidgetClass XMFORMWIDGETCLASS
#define xmFrameWidgetClass XMFRAMEWIDGETCLASS
#define xmGadgetClass XMGADGETCLASS
#define xmLabelGadgetClass XMLABELGADGETCLASS
#define xmLabelWidgetClass XMLABELWIDGETCLASS
#define xmListWidgetClass XMLISTWIDGETCLASS
#define xmMainWindowWidgetClass XMMAINWINDOWWIDGETCLASS
#define xmManagerClassRec XMMANAGERCLASSREC
#define xmManagerWidgetClass XMMANAGERWIDGETCLASS
#define xmMenuShellWidgetClass XMMENUSHELLWIDGETCLASS
#define xmMessageBoxWidgetClass XMMESSAGEBOXWIDGETCLASS
#define xmPrimitiveClassRec XMPRIMITIVECLASSREC
#define xmPrimitiveWidgetClass XMPRIMITIVEWIDGETCLASS
#define xmPushButtonClassRec XMPUSHBUTTONCLASSREC
#define xmPushButtonGadgetClass XMPUSHBUTTONGADGETCLASS
#define xmPushButtonWidgetClass XMPUSHBUTTONWIDGETCLASS
#define xmRowColumnWidgetClass XMROWCOLUMNWIDGETCLASS
#define xmSashWidgetClass XMSASHWIDGETCLASS
#define xmScrollBarWidgetClass XMSCROLLBARWIDGETCLASS
#define xmScrolledWindowClassRec XMSCROLLEDWINDOWCLASSREC
#define xmScrolledWindowWidgetClass XMSCROLLEDWINDOWWIDGETCLASS
#define xmSeparatorGadgetClass XMSEPARATORGADGETCLASS
#define xmSeparatorWidgetClass XMSEPARATORWIDGETCLASS
#define xmTextFieldWidgetClass XMTEXTFIELDWIDGETCLASS
#define xmTextWidgetClass XMTEXTWIDGETCLASS
#define xmToggleButtonGadgetClass XMTOGGLEBUTTONGADGETCLASS
#define xmToggleButtonWidgetClass XMTOGGLEBUTTONWIDGETCLASS
/*
** XtRegisterDrawable and XtUnregisterDrawable don't exist until R6.
** So we have to fake it for R5 and earlier. It would be real nice to
** include X11.h here and then test for R6 by checking
** XlibSpecificationRelease. But including X11.h defines the symbol "None"
** and there's Mozilla code in gfx/src/gtk that defines an enum element
** named None. So for now hard code this is R5....
*/
#ifndef VMS_X11R6
/* R5 or earlier */
#define _XtRegisterWindow _XTREGISTERWINDOW
#define _XtUnregisterWindow _XTUNREGISTERWINDOW
/* original code is fixed so we don't need this now */
#if 0
#define XtRegisterDrawable(display,drawable,widget) \
{ extern void _XtRegisterWindow(Window,Widget); \
_XtRegisterWindow(drawable,widget); \
}
#define XtUnregisterDrawable(display,drawable) \
{ extern void _XtUnregisterWindow(Window,Widget); \
_XtUnregisterWindow(drawable,XtWindowToWidget(display,drawable)); \
}
#endif
#else
/* R6 or later */
#define XtRegisterDrawable XTREGISTERDRAWABLE
#define XtUnregisterDrawable XTUNREGISTERDRAWABLE
#endif
| zyz2011-vim | src/gui_gtk_vms.h | C | gpl2 | 32,016 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*/
/*
* Amiga Machine-dependent things
*/
#define CASE_INSENSITIVE_FILENAME /* ignore case when comparing file names */
#define SPACE_IN_FILENAME
#define USE_FNAME_CASE /* adjust case of file names */
#define USE_TERM_CONSOLE
#define HAVE_AVAIL_MEM
#ifndef HAVE_CONFIG_H
# if defined(AZTEC_C) || defined(__amigaos4__)
# define HAVE_STAT_H
# endif
# ifdef __amigaos4__
# define HAVE_STDARG_H
# endif
# define HAVE_STDLIB_H
# define HAVE_STRING_H
# define HAVE_FCNTL_H
# define HAVE_STRCSPN
# define HAVE_STRICMP
# define HAVE_STRNICMP
# define HAVE_STRFTIME /* guessed */
# define HAVE_SETENV
# define HAVE_MEMSET
# define HAVE_QSORT
# if defined(__DATE__) && defined(__TIME__)
# define HAVE_DATE_TIME
# endif
#endif /* HAVE_CONFIG_H */
#ifndef DFLT_ERRORFILE
# define DFLT_ERRORFILE "AztecC.Err" /* Should this change? */
#endif
#ifndef DFLT_RUNTIMEPATH
# define DFLT_RUNTIMEPATH "home:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,home:vimfiles/after"
#endif
#ifndef BASENAMELEN
# define BASENAMELEN 26 /* Amiga */
#endif
#ifndef TEMPNAME
# define TEMPNAME "t:v?XXXXXX"
# define TEMPNAMELEN 12
#endif
#include <exec/types.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
/* Currently, all Amiga compilers except AZTEC C have these... */
#ifndef AZTEC_C
# include <proto/exec.h>
# include <proto/dos.h>
# include <proto/intuition.h>
#endif
#define FNAME_ILLEGAL ";*?`#%" /* illegal characters in a file name */
/*
* Manx doesn't have off_t, define it here.
*/
#ifdef AZTEC_C
typedef long off_t;
#endif
#ifdef LATTICE
# define USE_TMPNAM /* use tmpnam() instead of mktemp() */
#endif
#ifdef __GNUC__
# include <sys/stat.h>
# include <unistd.h>
#endif
/*
* arpbase.h must be included before functions.h
*/
#ifdef FEAT_ARP
# include <libraries/arpbase.h>
#endif
/*
* This won't be needed if you have a version of Lattice 4.01 without broken
* break signal handling.
*/
#include <signal.h>
/*
* Names for the EXRC, HELP and temporary files.
* Some of these may have been defined in the makefile.
*/
#ifndef SYS_VIMRC_FILE
# define SYS_VIMRC_FILE "$VIM/vimrc"
#endif
#ifndef SYS_GVIMRC_FILE
# define SYS_GVIMRC_FILE "$VIM/gvimrc"
#endif
#ifndef SYS_MENU_FILE
# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
#endif
#ifndef DFLT_HELPFILE
# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
#endif
#ifndef FILETYPE_FILE
# define FILETYPE_FILE "filetype.vim"
#endif
#ifndef FTPLUGIN_FILE
# define FTPLUGIN_FILE "ftplugin.vim"
#endif
#ifndef INDENT_FILE
# define INDENT_FILE "indent.vim"
#endif
#ifndef FTOFF_FILE
# define FTOFF_FILE "ftoff.vim"
#endif
#ifndef FTPLUGOF_FILE
# define FTPLUGOF_FILE "ftplugof.vim"
#endif
#ifndef INDOFF_FILE
# define INDOFF_FILE "indoff.vim"
#endif
#ifndef SYNTAX_FNAME
# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
#endif
#ifndef USR_EXRC_FILE
# define USR_EXRC_FILE "s:.exrc"
#endif
#ifndef USR_EXRC_FILE2
# define USR_EXRC_FILE2 "home:.exrc"
#endif
#ifndef USR_VIMRC_FILE
# define USR_VIMRC_FILE "s:.vimrc"
#endif
#ifndef USR_VIMRC_FILE2
# define USR_VIMRC_FILE2 "home:.vimrc"
#endif
#ifndef USR_VIMRC_FILE3
# define USR_VIMRC_FILE3 "$VIM/.vimrc"
#endif
#ifndef EVIM_FILE
# define EVIM_FILE "$VIMRUNTIME/evim.vim"
#endif
#ifndef USR_GVIMRC_FILE
# define USR_GVIMRC_FILE "s:.gvimrc"
#endif
#ifndef USR_GVIMRC_FILE2
# define USR_GVIMRC_FILE2 "home:.gvimrc"
#endif
#ifndef USR_GVIMRC_FILE3
# define USR_GVIMRC_FILE3 "$VIM/.gvimrc"
#endif
#ifdef FEAT_VIMINFO
# ifndef VIMINFO_FILE
# define VIMINFO_FILE "s:.viminfo"
# endif
#endif /* FEAT_VIMINFO */
#ifndef EXRC_FILE
# define EXRC_FILE ".exrc"
#endif
#ifndef VIMRC_FILE
# define VIMRC_FILE ".vimrc"
#endif
#ifndef GVIMRC_FILE
# define GVIMRC_FILE ".gvimrc"
#endif
#ifndef DFLT_BDIR
# define DFLT_BDIR ".,t:" /* default for 'backupdir' */
#endif
#ifndef DFLT_DIR
# define DFLT_DIR ".,t:" /* default for 'directory' */
#endif
#ifndef DFLT_VDIR
# define DFLT_VDIR "$VIM/vimfiles/view" /* default for 'viewdir' */
#endif
#ifndef DFLT_MAXMEM
# define DFLT_MAXMEM 256 /* use up to 256Kbyte for buffer */
#endif
#ifndef DFLT_MAXMEMTOT
# define DFLT_MAXMEMTOT 0 /* decide in set_init */
#endif
#if defined(SASC)
int setenv(const char *, const char *);
#endif
#define mch_remove(x) remove((char *)(x))
#define mch_rename(src, dst) rename(src, dst)
#define mch_chdir(s) chdir(s)
#define vim_mkdir(x, y) mch_mkdir(x)
| zyz2011-vim | src/os_amiga.h | C | gpl2 | 4,573 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*/
/*
* Definitions of various common control characters.
* For EBCDIC we have to use different values.
*/
#ifndef EBCDIC
/* IF_EB(ASCII_constant, EBCDIC_constant) */
#define IF_EB(a, b) a
#define CharOrd(x) ((x) < 'a' ? (x) - 'A' : (x) - 'a')
#define CharOrdLow(x) ((x) - 'a')
#define CharOrdUp(x) ((x) - 'A')
#define ROT13(c, a) (((((c) - (a)) + 13) % 26) + (a))
#define NUL '\000'
#define BELL '\007'
#define BS '\010'
#define TAB '\011'
#define NL '\012'
#define NL_STR (char_u *)"\012"
#define FF '\014'
#define CAR '\015' /* CR is used by Mac OS X */
#define ESC '\033'
#define ESC_STR (char_u *)"\033"
#define ESC_STR_nc "\033"
#define DEL 0x7f
#define DEL_STR (char_u *)"\177"
#define CSI 0x9b /* Control Sequence Introducer */
#define CSI_STR "\233"
#define DCS 0x90 /* Device Control String */
#define STERM 0x9c /* String Terminator */
#define POUND 0xA3
#define Ctrl_chr(x) (TOUPPER_ASC(x) ^ 0x40) /* '?' -> DEL, '@' -> ^@, etc. */
#define Meta(x) ((x) | 0x80)
#define CTRL_F_STR "\006"
#define CTRL_H_STR "\010"
#define CTRL_V_STR "\026"
#define Ctrl_AT 0 /* @ */
#define Ctrl_A 1
#define Ctrl_B 2
#define Ctrl_C 3
#define Ctrl_D 4
#define Ctrl_E 5
#define Ctrl_F 6
#define Ctrl_G 7
#define Ctrl_H 8
#define Ctrl_I 9
#define Ctrl_J 10
#define Ctrl_K 11
#define Ctrl_L 12
#define Ctrl_M 13
#define Ctrl_N 14
#define Ctrl_O 15
#define Ctrl_P 16
#define Ctrl_Q 17
#define Ctrl_R 18
#define Ctrl_S 19
#define Ctrl_T 20
#define Ctrl_U 21
#define Ctrl_V 22
#define Ctrl_W 23
#define Ctrl_X 24
#define Ctrl_Y 25
#define Ctrl_Z 26
/* CTRL- [ Left Square Bracket == ESC*/
#define Ctrl_BSL 28 /* \ BackSLash */
#define Ctrl_RSB 29 /* ] Right Square Bracket */
#define Ctrl_HAT 30 /* ^ */
#define Ctrl__ 31
#else
/* EBCDIC */
/* IF_EB(ASCII_constant, EBCDIC_constant) */
#define IF_EB(a, b) b
/*
* Finding the position in the alphabet is not straightforward in EBCDIC.
* There are gaps in the code table.
* 'a' + 1 == 'b', but: 'i' + 7 == 'j' and 'r' + 8 == 's'
*/
#define CharOrd__(c) ((c) < ('j' - 'a') ? (c) : ((c) < ('s' - 'a') ? (c) - 7 : (c) - 7 - 8))
#define CharOrdLow(x) (CharOrd__((x) - 'a'))
#define CharOrdUp(x) (CharOrd__((x) - 'A'))
#define CharOrd(x) (isupper(x) ? CharOrdUp(x) : CharOrdLow(x))
#define EBCDIC_CHAR_ADD_(x) ((x) < 0?'a':(x)>25?'z':"abcdefghijklmnopqrstuvwxyz"[x])
#define EBCDIC_CHAR_ADD(c,s) (isupper(c) ? toupper(EBCDIC_CHAR_ADD_(CharOrdUp(c)+(s))) : EBCDIC_CHAR_ADD_(CharOrdLow(c)+(s)))
#define R13_(c) ("abcdefghijklmnopqrstuvwxyz"[((c) + 13) % 26])
#define ROT13(c, a) (isupper(c) ? toupper(R13_(CharOrdUp(c))) : R13_(CharOrdLow(c)))
#define NUL '\000'
#define BELL '\x2f'
#define BS '\x16'
#define TAB '\x05'
#define NL '\x15'
#define NL_STR (char_u *)"\x15"
#define FF '\x0C'
#define CAR '\x0D'
#define ESC '\x27'
#define ESC_STR (char_u *)"\x27"
#define ESC_STR_nc "\x27"
#define DEL 0x07
#define DEL_STR (char_u *)"\007"
/* TODO: EBCDIC Code page dependent (here 1047) */
#define CSI 0x9b /* Control Sequence Introducer */
#define CSI_STR "\233"
#define DCS 0x90 /* Device Control String */
#define STERM 0x9c /* String Terminator */
#define POUND 0xB1
#define CTRL_F_STR "\056"
#define CTRL_H_STR "\026"
#define CTRL_V_STR "\062"
#define Ctrl_AT 0x00 /* @ */
#define Ctrl_A 0x01
#define Ctrl_B 0x02
#define Ctrl_C 0x03
#define Ctrl_D 0x37
#define Ctrl_E 0x2D
#define Ctrl_F 0x2E
#define Ctrl_G 0x2F
#define Ctrl_H 0x16
#define Ctrl_I 0x05
#define Ctrl_J 0x15
#define Ctrl_K 0x0B
#define Ctrl_L 0x0C
#define Ctrl_M 0x0D
#define Ctrl_N 0x0E
#define Ctrl_O 0x0F
#define Ctrl_P 0x10
#define Ctrl_Q 0x11
#define Ctrl_R 0x12
#define Ctrl_S 0x13
#define Ctrl_T 0x3C
#define Ctrl_U 0x3D
#define Ctrl_V 0x32
#define Ctrl_W 0x26
#define Ctrl_X 0x18
#define Ctrl_Y 0x19
#define Ctrl_Z 0x3F
/* CTRL- [ Left Square Bracket == ESC*/
#define Ctrl_RSB 0x1D /* ] Right Square Bracket */
#define Ctrl_BSL 0x1C /* \ BackSLash */
#define Ctrl_HAT 0x1E /* ^ */
#define Ctrl__ 0x1F
#define Ctrl_chr(x) (CtrlTable[(x)])
extern char CtrlTable[];
#define CtrlChar(x) ((x < ' ') ? CtrlCharTable[(x)] : 0)
extern char CtrlCharTable[];
#define MetaChar(x) ((x < ' ') ? MetaCharTable[(x)] : 0)
extern char MetaCharTable[];
#endif /* defined EBCDIC */
/*
* Character that separates dir names in a path.
* For MS-DOS, WIN32 and OS/2 we use a backslash. A slash mostly works
* fine, but there are places where it doesn't (e.g. in a command name).
* For Acorn we use a dot.
*/
#ifdef BACKSLASH_IN_FILENAME
# define PATHSEP psepc
# define PATHSEPSTR pseps
#else
# define PATHSEP '/'
# define PATHSEPSTR "/"
#endif
| zyz2011-vim | src/ascii.h | C | gpl2 | 4,886 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
* Visual Workshop integration by Gordon Prieur
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*/
/*
THIS IS AN UNSTABLE INTERFACE! It is unsupported and will likely
change in future releases, possibly breaking compatibility!
*/
#ifndef _INTEGRATION_H
#define _INTEGRATION_H
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Enable NoHands test support functions. Define this only if you want to
compile in support in the editor such that it can be run under
the WorkShop test suite. */
#ifndef NOHANDS_SUPPORT_FUNCTIONS
#define NOHANDS_SUPPORT_FUNCTIONS
#endif
/* This header file has three parts.
* 1. Functions you need to implement; these are called by the integration
* library
* 2. Functions you need to call when certain events happen in the editor;
* these are implemented by the integration library
* 3. Utility functions provided by the integration library; these make
* task 1 a bit easier.
*/
/*
* The following functions need to be implemented by the editor
* integration code (and will be editor-specific). Please see the
* sample workshop.c file for comments explaining what each functions
* needs to do, what the arguments mean, etc.
*/
/*
* This string is recognized by eserve and should be all lower case.
* This is how the editor detects that it is talking to NEdit instead
* of Vim, for example, when the connection is initiated from the editor.
* Examples: "nedit", "gvim"
*/
char *workshop_get_editor_name();
/*
* Version number of the editor.
* This number is communicated along with the protocol
* version to the application.
* Examples: "5.0.2", "19.3"
*/
char *workshop_get_editor_version();
/* Goto a given line in a given file */
void workshop_goto_line(char *filename, int lineno);
/* Set mark in a given file */
void workshop_set_mark(char *filename, int lineno, int markId, int type);
/* Change mark type (for example from current-pc to pc-and-breakpoint) */
void workshop_change_mark_type(char *filename, int markId, int type);
/*
* Goto the given mark in a file (e.g. show it).
* If message is not null, display it in the footer.
*/
void workshop_goto_mark(char *filename, int markId, char *message);
/* Delete mark */
void workshop_delete_mark(char *filename, int markId);
/* Begin/end pair of messages indicating that a series of _set_mark and
* _delete_mark messages will be sent. This can/should be used to suppress gui
* redraws between the begin and end messages. For example, if you switch
* to a headerfile that has a class breakpoint set, there may be hundreds
* of marks that need to be added. You don't want to refresh the gui for each
* added sign, you want to wait until the final end message.
*/
void workshop_mark_batch_begin();
void workshop_mark_batch_end();
/* Load a given file into the WorkShop buffer. "frameid" is a token string
* that identifies which frame the file would like to be loaded into. This
* will usually be null, in which case you should use the default frame.
* However, if frameid is not null, you need to find a frame that has this
* frameid, and replace the file in that frame. Finally, if the frameid is
* one you haven't seen before, you should create a new frame for this file.
* Note that "frameid" is a string value, not just an opaque pointer, so
* you should use strcmp rather than == when testing for equality.
*/
void workshop_load_file(char *filename, int line, char *frameid);
/* Reload the WorkShop buffer */
void workshop_reload_file(char *filename, int line);
/* Show the given file */
void workshop_show_file(char *filename);
/* Front the given file */
void workshop_front_file(char *filename);
/* Save the given file */
void workshop_save_file(char *filename);
/* Save all WorkShop edited files. You can ask user about modified files
* and skip saving any files the user doesn't want to save.
* This function is typically called when the user issues a build, a fix,
* etc. (and also if you select "Save All" from the File menu :-)
*/
void workshop_save_files();
/* Show a message in all footers.
Severity currently is not defined. */
void workshop_footer_message(char *message, int severity);
/* Minimize all windows */
void workshop_minimize();
/* Maximize all windows */
void workshop_maximize();
/*
* Create a new mark type, assign it a given index, a given textbackground
* color, and a given left-margin sign (where sign is a filename to an
* .xpm file)
*/
void workshop_add_mark_type(int idx, char *colorspec, char *sign);
/* Get mark line number */
int workshop_get_mark_lineno(char *filename, int markId);
/* Exit editor; save confirmation dialogs are okay */
void workshop_quit();
/* Set an editor option.
* For example, name="syntax",value="on" would enable syntax highlighting.
* The currently defined options are:
* lineno {on,off} show line numbers
* syntax {on,off} highlight syntax
* parentheses {on,off} show matching parentheses
* The following options are interpreted by the library for you (so you
* will never see the message. However, the implementation requires you
* to provide certain callbacks, like restore hotkeys or save all files.
* These are documented separately).
* workshopkeys {on,off} set workshop hotkeys
* savefiles {on,off} save all files before issuing a build
* balloon {on,off} enable/disable balloon evaluate
*
* IGNORE an option if you do not recognize it.
*/
void workshop_set_option(char *name, char *value);
/*
* (See workshop_add_frame first.) This function notifies the editor
* that the frame for the given window (indicated by "frame", which
* was supplied by the editor in workshop_add_frame) has been created.
* This can happen much later than the workshop_add_frame message, since
* often a window is created on editor startup, while the frame description
* is passed over from eserve much later, when the connection is complete.
* This gives the editor a chance to kick its GUI to show the frame
* properly; typically you'll unmanage and remanage the parent widget to
* force a geometry recalculation.
*/
void workshop_reconfigure_frame(void *frame);
/* Are there any moved marks? If so, call workshop_move_mark on
* each of them now. This is how eserve can find out if for example
* breakpoints have moved when a program has been recompiled and
* reloaded into dbx.
*/
void workshop_moved_marks(char *filename);
/* A button in the toolbar has been pushed. "frame" is provided
* which should let you determine which toolbar had a button pushed
* (you supplied this clientData when you created a toolbar). From
* this you should be able to figure out which file the operation
* applies to, and for that window the cursor line and column,
* selection begin line and column, selection end line and column,
* selection text and selection text length. The column numbers are
* currently unused but implement it anyway in case we decide to use
* them in the future.
* Note that frame can be NULL. In this case, you should pick
* a default window to translate coordinates for (ideally, the
* last window the user has operated on.) This will be the case when
* the user clicks on a Custom Button programmed to take the current
* line number as an argument. Here it's ambiguous which buffer
* to use, so you need to pick one.
* (Interface consideration: Perhaps we instead should add smarts
* into the library such that we remember which frame pointer
* we last noticed (e.g. last call to get_positions, or perhaps
* last add_frame) and then pass that instead? For example, we could
* have all workshop operations return the clientData when passed
* the filename (or add a filename-to-clientData converter?) and then
* remember the last filename/clientData used.
*/
int workshop_get_positions(void *frame,
char **filename,
int *curLine,
int *curCol,
int *selStartLine,
int *selStartCol,
int *selEndLine,
int *selEndCol,
int *selLength,
char **selection);
/* The following function should return the height of a character
* in the text display. This is used to pick out a suitable size
* for the signs to match the text (currently available in three
* sizes). If you just return 0, WorkShop will use the default
* sign size. (Use XmStringExtent on character "A" to get the height.)
*/
int workshop_get_font_height(void);
/* The following function requests that you register the given
* hotkey as a keyboard accelerator for all frames. Whenever the
* hotkey is pressed, you should invoke workshop_hotkey_pressed
* and pass the current frame pointer as an argument as well as
* the clientData pointer passed in to this function.
* The remove function unregisters the hotkey.
*/
void workshop_register_hotkey(Modifiers modifiers, KeySym keysym,
void *clientData);
void workshop_unregister_hotkey(Modifiers modifiers, KeySym keysym,
void *clientData);
/*
*
* The following functions notify eserve of important editor events,
* such as files being modified, files being saved, etc. You must
* sprinkle your editor code with calls to these. For example, whenever
* a file is modified (well, when its read-only status changes to modified),
* call workshop_file_modified().
*
*/
/* Connect with eserve. Add this call after you editor initialization
* is done, right before entering the event loop or blocking on input.
* This will set up a socket connection with eserve.
*/
void workshop_connect(XtAppContext context);
/* A file has been opened. */
void workshop_file_opened(char *filename, int readOnly);
/* A file has been saved. Despite its name, eserve also uses this
* message to mean a file has been reverted or unmodified.
*/
void workshop_file_saved(char *filename);
#if 0
/* A file has been closed */
void workshop_file_closed(char *filename);
#endif
/* Like workshop_file_closed, but also inform eserve what line the
cursor was on when you left the file. That way eserve can put you
back where you left off when you return to this file. */
void workshop_file_closed_lineno(char *filename, int line);
#if 0
/* A file has been modified */
void workshop_file_modified(char *filename);
/*
* A mark has been moved. Only call this as a response to
* a workshop_moved_marks request call.
*/
void workshop_move_mark(char *filename, int markId, int newLineno);
#endif
/* Tell the integration library about a new frame being added.
* Supply a form for the toolbar, a label for the footer, and an
* XmPulldown menu for the WorkShop menu to attach to. Top and bottom
* are the widgets above and below the toolbar form widget, if
* any. Call this function when you create a new window. It returns a
* void *, a handle which you should keep and return when you delete
* the window with workshop_delete_toolbar. The "footer" argument
* points to a Label widget that is going to be used as a status
* message area, and "menu" (if any) points to an Menu widget that
* should contain a WorkShop menu. Clientdata is a pointer which is
* only used by the editor. It will typically be a pointer to the
* window object that the toolbar is placed in. If you have multiple
* windows, you need to use this pointer to figure out which window
* (and thus corresponding buffer) the user has clicked on to respond
* to the workshop_get_positions message.
* Each frame's clientData ("frame") should be unique.
*/
void *workshop_add_frame(void *frame, Widget form,
Widget top, Widget bottom, Widget footer,
Widget menu);
/* Delete a window/frame. Call this when an editor window is being deleted. */
void workshop_delete_frame(void *handle);
/* Add a balloon evaluate text area. "frame" is used the same way
* as in workshop_add_frame. This call is not part of workshop_add_frame because
* a frame can have multiple tooltip areas (typically, an editor frame that
* is split showing multiple buffers will have a separate tooltip area for
* each text widget. Each such area is called a "window" (consistent with
* XEmacs terminology). Separate these by the window argument if necessary.
* You will need to implement workshop_get_balloon_text such that it uses
* these two arguments to derive the file, line etc. for the tip.
* Call the remove function if you delete this area such that the integration
* library can update itself. You must call workshop_add_frame before you
* call add_balloon_eval_area, and you must pass the same frame pointer.
*/
void workshop_add_balloon_eval_area(void *frame, void *window, Widget widget);
void workshop_remove_balloon_eval_area(void *frame, void *window, Widget widget);
/* For a given mouse position inside the balloon area (passed as x,y),
* return the balloon text to be evaluated. There are two scenarios:
* If the position is inside the selection, return the selection
* string. Else, return the full line (or possibly the full line up
* to the last semicolon (that's TBD), along with an index pointing to
* where which character the mouse is over.
* If we have the selection-scenario, set mouseIndex to -1 to indicate
* that no autoexpansion should occur but that the selection should
* be evaluated as is.
*
* XXX Does dbx need more information here, like the filename and line
* number in order to determine the correct language and scope to be
* used during evaluation?? Or should it just work like the p= button
* (where the current scope and language is used, even if you are
* pointing at a different file with a different scope) ?
*/
int workshop_get_balloon_text(Position x, Position y,
void *frame,
void *window,
char **filename,
int *line,
char **text,
int *mouseIndex);
/* Window size and location
* WorkShop will attempt to restore the size and location of a single
* editor frame. For vi, this window is designated as the "reusable" one.
* You can implement your own scheme for determining which window you
* want to associate with WorkShop. Whenever the size and location of
* this window is changed, call the following function to notify eserve.
* Like workshop_invoked, this can be called before the workshop_connect()
* call.
*/
void workshop_frame_moved(int new_x, int new_y, int new_w, int new_h);
Boolean workshop_get_width_height(int *, int *);
#if 0
Boolean workshop_get_rows_cols(int *, int *);
#endif
/* This function should be invoked when you press a hotkey
* set up by workshop_register_hotkey. Pass the clientData
* to it that was given to you with workshop_register_hotkey.
*/
void workshop_hotkey_pressed(void *frame, void *clientData);
/*
* Utility functions
* These provide convenience functions to simplify implementing some
* of the above functions.
*
*/
#if 0
/* Were we invoked by WorkShop? This function can be used early during startup
* if you want to do things differently if the editor is started standalone
* or in WorkShop mode. For example, in standalone mode you may not want to
* add a footer/message area or a sign gutter.
*/
int workshop_invoked(void);
#endif
/* Minimize (iconify) the given shell */
void workshop_minimize_shell(Widget shell);
/* Maximize (deiconify) the given shell */
void workshop_maximize_shell(Widget shell);
/* Called by frame.cc -- editor shouldn't call this directly.
* Perhaps we need an integrationP.h file ? */
void workshop_perform_verb(char *verb, void *clientData);
void workshop_send_message(char *buf);
#ifdef NOHANDS_SUPPORT_FUNCTIONS
/* The following functions are needed to run the WorkShop testsuite
* with this editor. You don't need to implement these unless you
* intend for your editor to be run by Workshop's testsuite.
* getcursorrow should return the number of lines from the top of
* the window the cursor is; similarly for getcursorcol.
*/
char *workshop_test_getcurrentfile();
int workshop_test_getcursorrow();
int workshop_test_getcursorcol();
char *workshop_test_getcursorrowtext();
char *workshop_test_getselectedtext();
#endif
/*
* Struct used to set/unset the sensitivity of verbs.
*/
typedef struct {
char *verb;
Boolean sense;
} VerbSense;
#ifdef __cplusplus
}
#endif
#endif /* _INTEGRATION_H */
| zyz2011-vim | src/integration.h | C | gpl2 | 16,426 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
#include "vim.h"
#ifdef FEAT_LINEBREAK
static int win_chartabsize __ARGS((win_T *wp, char_u *p, colnr_T col));
#endif
#ifdef FEAT_MBYTE
# if defined(HAVE_WCHAR_H)
# include <wchar.h> /* for towupper() and towlower() */
# endif
static int win_nolbr_chartabsize __ARGS((win_T *wp, char_u *s, colnr_T col, int *headp));
#endif
static unsigned nr2hex __ARGS((unsigned c));
static int chartab_initialized = FALSE;
/* b_chartab[] is an array of 32 bytes, each bit representing one of the
* characters 0-255. */
#define SET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> 3] |= (1 << ((c) & 0x7))
#define RESET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7))
#define GET_CHARTAB(buf, c) ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7)))
/*
* Fill chartab[]. Also fills curbuf->b_chartab[] with flags for keyword
* characters for current buffer.
*
* Depends on the option settings 'iskeyword', 'isident', 'isfname',
* 'isprint' and 'encoding'.
*
* The index in chartab[] depends on 'encoding':
* - For non-multi-byte index with the byte (same as the character).
* - For DBCS index with the first byte.
* - For UTF-8 index with the character (when first byte is up to 0x80 it is
* the same as the character, if the first byte is 0x80 and above it depends
* on further bytes).
*
* The contents of chartab[]:
* - The lower two bits, masked by CT_CELL_MASK, give the number of display
* cells the character occupies (1 or 2). Not valid for UTF-8 above 0x80.
* - CT_PRINT_CHAR bit is set when the character is printable (no need to
* translate the character before displaying it). Note that only DBCS
* characters can have 2 display cells and still be printable.
* - CT_FNAME_CHAR bit is set when the character can be in a file name.
* - CT_ID_CHAR bit is set when the character can be in an identifier.
*
* Return FAIL if 'iskeyword', 'isident', 'isfname' or 'isprint' option has an
* error, OK otherwise.
*/
int
init_chartab()
{
return buf_init_chartab(curbuf, TRUE);
}
int
buf_init_chartab(buf, global)
buf_T *buf;
int global; /* FALSE: only set buf->b_chartab[] */
{
int c;
int c2;
char_u *p;
int i;
int tilde;
int do_isalpha;
if (global)
{
/*
* Set the default size for printable characters:
* From <Space> to '~' is 1 (printable), others are 2 (not printable).
* This also inits all 'isident' and 'isfname' flags to FALSE.
*
* EBCDIC: all chars below ' ' are not printable, all others are
* printable.
*/
c = 0;
while (c < ' ')
chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2;
#ifdef EBCDIC
while (c < 255)
#else
while (c <= '~')
#endif
chartab[c++] = 1 + CT_PRINT_CHAR;
#ifdef FEAT_FKMAP
if (p_altkeymap)
{
while (c < YE)
chartab[c++] = 1 + CT_PRINT_CHAR;
}
#endif
while (c < 256)
{
#ifdef FEAT_MBYTE
/* UTF-8: bytes 0xa0 - 0xff are printable (latin1) */
if (enc_utf8 && c >= 0xa0)
chartab[c++] = CT_PRINT_CHAR + 1;
/* euc-jp characters starting with 0x8e are single width */
else if (enc_dbcs == DBCS_JPNU && c == 0x8e)
chartab[c++] = CT_PRINT_CHAR + 1;
/* other double-byte chars can be printable AND double-width */
else if (enc_dbcs != 0 && MB_BYTE2LEN(c) == 2)
chartab[c++] = CT_PRINT_CHAR + 2;
else
#endif
/* the rest is unprintable by default */
chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2;
}
#ifdef FEAT_MBYTE
/* Assume that every multi-byte char is a filename character. */
for (c = 1; c < 256; ++c)
if ((enc_dbcs != 0 && MB_BYTE2LEN(c) > 1)
|| (enc_dbcs == DBCS_JPNU && c == 0x8e)
|| (enc_utf8 && c >= 0xa0))
chartab[c] |= CT_FNAME_CHAR;
#endif
}
/*
* Init word char flags all to FALSE
*/
vim_memset(buf->b_chartab, 0, (size_t)32);
#ifdef FEAT_MBYTE
if (enc_dbcs != 0)
for (c = 0; c < 256; ++c)
{
/* double-byte characters are probably word characters */
if (MB_BYTE2LEN(c) == 2)
SET_CHARTAB(buf, c);
}
#endif
#ifdef FEAT_LISP
/*
* In lisp mode the '-' character is included in keywords.
*/
if (buf->b_p_lisp)
SET_CHARTAB(buf, '-');
#endif
/* Walk through the 'isident', 'iskeyword', 'isfname' and 'isprint'
* options Each option is a list of characters, character numbers or
* ranges, separated by commas, e.g.: "200-210,x,#-178,-"
*/
for (i = global ? 0 : 3; i <= 3; ++i)
{
if (i == 0)
p = p_isi; /* first round: 'isident' */
else if (i == 1)
p = p_isp; /* second round: 'isprint' */
else if (i == 2)
p = p_isf; /* third round: 'isfname' */
else /* i == 3 */
p = buf->b_p_isk; /* fourth round: 'iskeyword' */
while (*p)
{
tilde = FALSE;
do_isalpha = FALSE;
if (*p == '^' && p[1] != NUL)
{
tilde = TRUE;
++p;
}
if (VIM_ISDIGIT(*p))
c = getdigits(&p);
else
#ifdef FEAT_MBYTE
if (has_mbyte)
c = mb_ptr2char_adv(&p);
else
#endif
c = *p++;
c2 = -1;
if (*p == '-' && p[1] != NUL)
{
++p;
if (VIM_ISDIGIT(*p))
c2 = getdigits(&p);
else
#ifdef FEAT_MBYTE
if (has_mbyte)
c2 = mb_ptr2char_adv(&p);
else
#endif
c2 = *p++;
}
if (c <= 0 || c >= 256 || (c2 < c && c2 != -1) || c2 >= 256
|| !(*p == NUL || *p == ','))
return FAIL;
if (c2 == -1) /* not a range */
{
/*
* A single '@' (not "@-@"):
* Decide on letters being ID/printable/keyword chars with
* standard function isalpha(). This takes care of locale for
* single-byte characters).
*/
if (c == '@')
{
do_isalpha = TRUE;
c = 1;
c2 = 255;
}
else
c2 = c;
}
while (c <= c2)
{
/* Use the MB_ functions here, because isalpha() doesn't
* work properly when 'encoding' is "latin1" and the locale is
* "C". */
if (!do_isalpha || MB_ISLOWER(c) || MB_ISUPPER(c)
#ifdef FEAT_FKMAP
|| (p_altkeymap && (F_isalpha(c) || F_isdigit(c)))
#endif
)
{
if (i == 0) /* (re)set ID flag */
{
if (tilde)
chartab[c] &= ~CT_ID_CHAR;
else
chartab[c] |= CT_ID_CHAR;
}
else if (i == 1) /* (re)set printable */
{
if ((c < ' '
#ifndef EBCDIC
|| c > '~'
#endif
#ifdef FEAT_FKMAP
|| (p_altkeymap
&& (F_isalpha(c) || F_isdigit(c)))
#endif
)
#ifdef FEAT_MBYTE
/* For double-byte we keep the cell width, so
* that we can detect it from the first byte. */
&& !(enc_dbcs && MB_BYTE2LEN(c) == 2)
#endif
)
{
if (tilde)
{
chartab[c] = (chartab[c] & ~CT_CELL_MASK)
+ ((dy_flags & DY_UHEX) ? 4 : 2);
chartab[c] &= ~CT_PRINT_CHAR;
}
else
{
chartab[c] = (chartab[c] & ~CT_CELL_MASK) + 1;
chartab[c] |= CT_PRINT_CHAR;
}
}
}
else if (i == 2) /* (re)set fname flag */
{
if (tilde)
chartab[c] &= ~CT_FNAME_CHAR;
else
chartab[c] |= CT_FNAME_CHAR;
}
else /* i == 3 */ /* (re)set keyword flag */
{
if (tilde)
RESET_CHARTAB(buf, c);
else
SET_CHARTAB(buf, c);
}
}
++c;
}
p = skip_to_option_part(p);
}
}
chartab_initialized = TRUE;
return OK;
}
/*
* Translate any special characters in buf[bufsize] in-place.
* The result is a string with only printable characters, but if there is not
* enough room, not all characters will be translated.
*/
void
trans_characters(buf, bufsize)
char_u *buf;
int bufsize;
{
int len; /* length of string needing translation */
int room; /* room in buffer after string */
char_u *trs; /* translated character */
int trs_len; /* length of trs[] */
len = (int)STRLEN(buf);
room = bufsize - len;
while (*buf != 0)
{
# ifdef FEAT_MBYTE
/* Assume a multi-byte character doesn't need translation. */
if (has_mbyte && (trs_len = (*mb_ptr2len)(buf)) > 1)
len -= trs_len;
else
# endif
{
trs = transchar_byte(*buf);
trs_len = (int)STRLEN(trs);
if (trs_len > 1)
{
room -= trs_len - 1;
if (room <= 0)
return;
mch_memmove(buf + trs_len, buf + 1, (size_t)len);
}
mch_memmove(buf, trs, (size_t)trs_len);
--len;
}
buf += trs_len;
}
}
#if defined(FEAT_EVAL) || defined(FEAT_TITLE) || defined(FEAT_INS_EXPAND) \
|| defined(PROTO)
/*
* Translate a string into allocated memory, replacing special chars with
* printable chars. Returns NULL when out of memory.
*/
char_u *
transstr(s)
char_u *s;
{
char_u *res;
char_u *p;
#ifdef FEAT_MBYTE
int l, len, c;
char_u hexbuf[11];
#endif
#ifdef FEAT_MBYTE
if (has_mbyte)
{
/* Compute the length of the result, taking account of unprintable
* multi-byte characters. */
len = 0;
p = s;
while (*p != NUL)
{
if ((l = (*mb_ptr2len)(p)) > 1)
{
c = (*mb_ptr2char)(p);
p += l;
if (vim_isprintc(c))
len += l;
else
{
transchar_hex(hexbuf, c);
len += (int)STRLEN(hexbuf);
}
}
else
{
l = byte2cells(*p++);
if (l > 0)
len += l;
else
len += 4; /* illegal byte sequence */
}
}
res = alloc((unsigned)(len + 1));
}
else
#endif
res = alloc((unsigned)(vim_strsize(s) + 1));
if (res != NULL)
{
*res = NUL;
p = s;
while (*p != NUL)
{
#ifdef FEAT_MBYTE
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
{
c = (*mb_ptr2char)(p);
if (vim_isprintc(c))
STRNCAT(res, p, l); /* append printable multi-byte char */
else
transchar_hex(res + STRLEN(res), c);
p += l;
}
else
#endif
STRCAT(res, transchar_byte(*p++));
}
}
return res;
}
#endif
#if defined(FEAT_SYN_HL) || defined(FEAT_INS_EXPAND) || defined(PROTO)
/*
* Convert the string "str[orglen]" to do ignore-case comparing. Uses the
* current locale.
* When "buf" is NULL returns an allocated string (NULL for out-of-memory).
* Otherwise puts the result in "buf[buflen]".
*/
char_u *
str_foldcase(str, orglen, buf, buflen)
char_u *str;
int orglen;
char_u *buf;
int buflen;
{
garray_T ga;
int i;
int len = orglen;
#define GA_CHAR(i) ((char_u *)ga.ga_data)[i]
#define GA_PTR(i) ((char_u *)ga.ga_data + i)
#define STR_CHAR(i) (buf == NULL ? GA_CHAR(i) : buf[i])
#define STR_PTR(i) (buf == NULL ? GA_PTR(i) : buf + i)
/* Copy "str" into "buf" or allocated memory, unmodified. */
if (buf == NULL)
{
ga_init2(&ga, 1, 10);
if (ga_grow(&ga, len + 1) == FAIL)
return NULL;
mch_memmove(ga.ga_data, str, (size_t)len);
ga.ga_len = len;
}
else
{
if (len >= buflen) /* Ugly! */
len = buflen - 1;
mch_memmove(buf, str, (size_t)len);
}
if (buf == NULL)
GA_CHAR(len) = NUL;
else
buf[len] = NUL;
/* Make each character lower case. */
i = 0;
while (STR_CHAR(i) != NUL)
{
#ifdef FEAT_MBYTE
if (enc_utf8 || (has_mbyte && MB_BYTE2LEN(STR_CHAR(i)) > 1))
{
if (enc_utf8)
{
int c = utf_ptr2char(STR_PTR(i));
int olen = utf_ptr2len(STR_PTR(i));
int lc = utf_tolower(c);
/* Only replace the character when it is not an invalid
* sequence (ASCII character or more than one byte) and
* utf_tolower() doesn't return the original character. */
if ((c < 0x80 || olen > 1) && c != lc)
{
int nlen = utf_char2len(lc);
/* If the byte length changes need to shift the following
* characters forward or backward. */
if (olen != nlen)
{
if (nlen > olen)
{
if (buf == NULL
? ga_grow(&ga, nlen - olen + 1) == FAIL
: len + nlen - olen >= buflen)
{
/* out of memory, keep old char */
lc = c;
nlen = olen;
}
}
if (olen != nlen)
{
if (buf == NULL)
{
STRMOVE(GA_PTR(i) + nlen, GA_PTR(i) + olen);
ga.ga_len += nlen - olen;
}
else
{
STRMOVE(buf + i + nlen, buf + i + olen);
len += nlen - olen;
}
}
}
(void)utf_char2bytes(lc, STR_PTR(i));
}
}
/* skip to next multi-byte char */
i += (*mb_ptr2len)(STR_PTR(i));
}
else
#endif
{
if (buf == NULL)
GA_CHAR(i) = TOLOWER_LOC(GA_CHAR(i));
else
buf[i] = TOLOWER_LOC(buf[i]);
++i;
}
}
if (buf == NULL)
return (char_u *)ga.ga_data;
return buf;
}
#endif
/*
* Catch 22: chartab[] can't be initialized before the options are
* initialized, and initializing options may cause transchar() to be called!
* When chartab_initialized == FALSE don't use chartab[].
* Does NOT work for multi-byte characters, c must be <= 255.
* Also doesn't work for the first byte of a multi-byte, "c" must be a
* character!
*/
static char_u transchar_buf[7];
char_u *
transchar(c)
int c;
{
int i;
i = 0;
if (IS_SPECIAL(c)) /* special key code, display as ~@ char */
{
transchar_buf[0] = '~';
transchar_buf[1] = '@';
i = 2;
c = K_SECOND(c);
}
if ((!chartab_initialized && (
#ifdef EBCDIC
(c >= 64 && c < 255)
#else
(c >= ' ' && c <= '~')
#endif
#ifdef FEAT_FKMAP
|| F_ischar(c)
#endif
)) || (c < 256 && vim_isprintc_strict(c)))
{
/* printable character */
transchar_buf[i] = c;
transchar_buf[i + 1] = NUL;
}
else
transchar_nonprint(transchar_buf + i, c);
return transchar_buf;
}
#if defined(FEAT_MBYTE) || defined(PROTO)
/*
* Like transchar(), but called with a byte instead of a character. Checks
* for an illegal UTF-8 byte.
*/
char_u *
transchar_byte(c)
int c;
{
if (enc_utf8 && c >= 0x80)
{
transchar_nonprint(transchar_buf, c);
return transchar_buf;
}
return transchar(c);
}
#endif
/*
* Convert non-printable character to two or more printable characters in
* "buf[]". "buf" needs to be able to hold five bytes.
* Does NOT work for multi-byte characters, c must be <= 255.
*/
void
transchar_nonprint(buf, c)
char_u *buf;
int c;
{
if (c == NL)
c = NUL; /* we use newline in place of a NUL */
else if (c == CAR && get_fileformat(curbuf) == EOL_MAC)
c = NL; /* we use CR in place of NL in this case */
if (dy_flags & DY_UHEX) /* 'display' has "uhex" */
transchar_hex(buf, c);
#ifdef EBCDIC
/* For EBCDIC only the characters 0-63 and 255 are not printable */
else if (CtrlChar(c) != 0 || c == DEL)
#else
else if (c <= 0x7f) /* 0x00 - 0x1f and 0x7f */
#endif
{
buf[0] = '^';
#ifdef EBCDIC
if (c == DEL)
buf[1] = '?'; /* DEL displayed as ^? */
else
buf[1] = CtrlChar(c);
#else
buf[1] = c ^ 0x40; /* DEL displayed as ^? */
#endif
buf[2] = NUL;
}
#ifdef FEAT_MBYTE
else if (enc_utf8 && c >= 0x80)
{
transchar_hex(buf, c);
}
#endif
#ifndef EBCDIC
else if (c >= ' ' + 0x80 && c <= '~' + 0x80) /* 0xa0 - 0xfe */
{
buf[0] = '|';
buf[1] = c - 0x80;
buf[2] = NUL;
}
#else
else if (c < 64)
{
buf[0] = '~';
buf[1] = MetaChar(c);
buf[2] = NUL;
}
#endif
else /* 0x80 - 0x9f and 0xff */
{
/*
* TODO: EBCDIC I don't know what to do with this chars, so I display
* them as '~?' for now
*/
buf[0] = '~';
#ifdef EBCDIC
buf[1] = '?'; /* 0xff displayed as ~? */
#else
buf[1] = (c - 0x80) ^ 0x40; /* 0xff displayed as ~? */
#endif
buf[2] = NUL;
}
}
void
transchar_hex(buf, c)
char_u *buf;
int c;
{
int i = 0;
buf[0] = '<';
#ifdef FEAT_MBYTE
if (c > 255)
{
buf[++i] = nr2hex((unsigned)c >> 12);
buf[++i] = nr2hex((unsigned)c >> 8);
}
#endif
buf[++i] = nr2hex((unsigned)c >> 4);
buf[++i] = nr2hex((unsigned)c);
buf[++i] = '>';
buf[++i] = NUL;
}
/*
* Convert the lower 4 bits of byte "c" to its hex character.
* Lower case letters are used to avoid the confusion of <F1> being 0xf1 or
* function key 1.
*/
static unsigned
nr2hex(c)
unsigned c;
{
if ((c & 0xf) <= 9)
return (c & 0xf) + '0';
return (c & 0xf) - 10 + 'a';
}
/*
* Return number of display cells occupied by byte "b".
* Caller must make sure 0 <= b <= 255.
* For multi-byte mode "b" must be the first byte of a character.
* A TAB is counted as two cells: "^I".
* For UTF-8 mode this will return 0 for bytes >= 0x80, because the number of
* cells depends on further bytes.
*/
int
byte2cells(b)
int b;
{
#ifdef FEAT_MBYTE
if (enc_utf8 && b >= 0x80)
return 0;
#endif
return (chartab[b] & CT_CELL_MASK);
}
/*
* Return number of display cells occupied by character "c".
* "c" can be a special key (negative number) in which case 3 or 4 is returned.
* A TAB is counted as two cells: "^I" or four: "<09>".
*/
int
char2cells(c)
int c;
{
if (IS_SPECIAL(c))
return char2cells(K_SECOND(c)) + 2;
#ifdef FEAT_MBYTE
if (c >= 0x80)
{
/* UTF-8: above 0x80 need to check the value */
if (enc_utf8)
return utf_char2cells(c);
/* DBCS: double-byte means double-width, except for euc-jp with first
* byte 0x8e */
if (enc_dbcs != 0 && c >= 0x100)
{
if (enc_dbcs == DBCS_JPNU && ((unsigned)c >> 8) == 0x8e)
return 1;
return 2;
}
}
#endif
return (chartab[c & 0xff] & CT_CELL_MASK);
}
/*
* Return number of display cells occupied by character at "*p".
* A TAB is counted as two cells: "^I" or four: "<09>".
*/
int
ptr2cells(p)
char_u *p;
{
#ifdef FEAT_MBYTE
/* For UTF-8 we need to look at more bytes if the first byte is >= 0x80. */
if (enc_utf8 && *p >= 0x80)
return utf_ptr2cells(p);
/* For DBCS we can tell the cell count from the first byte. */
#endif
return (chartab[*p] & CT_CELL_MASK);
}
/*
* Return the number of character cells string "s" will take on the screen,
* counting TABs as two characters: "^I".
*/
int
vim_strsize(s)
char_u *s;
{
return vim_strnsize(s, (int)MAXCOL);
}
/*
* Return the number of character cells string "s[len]" will take on the
* screen, counting TABs as two characters: "^I".
*/
int
vim_strnsize(s, len)
char_u *s;
int len;
{
int size = 0;
while (*s != NUL && --len >= 0)
{
#ifdef FEAT_MBYTE
if (has_mbyte)
{
int l = (*mb_ptr2len)(s);
size += ptr2cells(s);
s += l;
len -= l - 1;
}
else
#endif
size += byte2cells(*s++);
}
return size;
}
/*
* Return the number of characters 'c' will take on the screen, taking
* into account the size of a tab.
* Use a define to make it fast, this is used very often!!!
* Also see getvcol() below.
*/
#define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \
if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) \
{ \
int ts; \
ts = (buf)->b_p_ts; \
return (int)(ts - (col % ts)); \
} \
else \
return ptr2cells(p);
#if defined(FEAT_VREPLACE) || defined(FEAT_EX_EXTRA) || defined(FEAT_GUI) \
|| defined(FEAT_VIRTUALEDIT) || defined(PROTO)
int
chartabsize(p, col)
char_u *p;
colnr_T col;
{
RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, p, col)
}
#endif
#ifdef FEAT_LINEBREAK
static int
win_chartabsize(wp, p, col)
win_T *wp;
char_u *p;
colnr_T col;
{
RET_WIN_BUF_CHARTABSIZE(wp, wp->w_buffer, p, col)
}
#endif
/*
* Return the number of characters the string 's' will take on the screen,
* taking into account the size of a tab.
*/
int
linetabsize(s)
char_u *s;
{
return linetabsize_col(0, s);
}
/*
* Like linetabsize(), but starting at column "startcol".
*/
int
linetabsize_col(startcol, s)
int startcol;
char_u *s;
{
colnr_T col = startcol;
while (*s != NUL)
col += lbr_chartabsize_adv(&s, col);
return (int)col;
}
/*
* Like linetabsize(), but for a given window instead of the current one.
*/
int
win_linetabsize(wp, p, len)
win_T *wp;
char_u *p;
colnr_T len;
{
colnr_T col = 0;
char_u *s;
for (s = p; *s != NUL && (len == MAXCOL || s < p + len); mb_ptr_adv(s))
col += win_lbr_chartabsize(wp, s, col, NULL);
return (int)col;
}
/*
* Return TRUE if 'c' is a normal identifier character:
* Letters and characters from the 'isident' option.
*/
int
vim_isIDc(c)
int c;
{
return (c > 0 && c < 0x100 && (chartab[c] & CT_ID_CHAR));
}
/*
* return TRUE if 'c' is a keyword character: Letters and characters from
* 'iskeyword' option for current buffer.
* For multi-byte characters mb_get_class() is used (builtin rules).
*/
int
vim_iswordc(c)
int c;
{
#ifdef FEAT_MBYTE
if (c >= 0x100)
{
if (enc_dbcs != 0)
return dbcs_class((unsigned)c >> 8, (unsigned)(c & 0xff)) >= 2;
if (enc_utf8)
return utf_class(c) >= 2;
}
#endif
return (c > 0 && c < 0x100 && GET_CHARTAB(curbuf, c) != 0);
}
/*
* Just like vim_iswordc() but uses a pointer to the (multi-byte) character.
*/
int
vim_iswordp(p)
char_u *p;
{
#ifdef FEAT_MBYTE
if (has_mbyte && MB_BYTE2LEN(*p) > 1)
return mb_get_class(p) >= 2;
#endif
return GET_CHARTAB(curbuf, *p) != 0;
}
#if defined(FEAT_SYN_HL) || defined(PROTO)
int
vim_iswordc_buf(p, buf)
char_u *p;
buf_T *buf;
{
# ifdef FEAT_MBYTE
if (has_mbyte && MB_BYTE2LEN(*p) > 1)
return mb_get_class(p) >= 2;
# endif
return (GET_CHARTAB(buf, *p) != 0);
}
#endif
/*
* return TRUE if 'c' is a valid file-name character
* Assume characters above 0x100 are valid (multi-byte).
*/
int
vim_isfilec(c)
int c;
{
return (c >= 0x100 || (c > 0 && (chartab[c] & CT_FNAME_CHAR)));
}
/*
* return TRUE if 'c' is a valid file-name character or a wildcard character
* Assume characters above 0x100 are valid (multi-byte).
* Explicitly interpret ']' as a wildcard character as mch_has_wildcard("]")
* returns false.
*/
int
vim_isfilec_or_wc(c)
int c;
{
char_u buf[2];
buf[0] = (char_u)c;
buf[1] = NUL;
return vim_isfilec(c) || c == ']' || mch_has_wildcard(buf);
}
/*
* return TRUE if 'c' is a printable character
* Assume characters above 0x100 are printable (multi-byte), except for
* Unicode.
*/
int
vim_isprintc(c)
int c;
{
#ifdef FEAT_MBYTE
if (enc_utf8 && c >= 0x100)
return utf_printable(c);
#endif
return (c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR)));
}
/*
* Strict version of vim_isprintc(c), don't return TRUE if "c" is the head
* byte of a double-byte character.
*/
int
vim_isprintc_strict(c)
int c;
{
#ifdef FEAT_MBYTE
if (enc_dbcs != 0 && c < 0x100 && MB_BYTE2LEN(c) > 1)
return FALSE;
if (enc_utf8 && c >= 0x100)
return utf_printable(c);
#endif
return (c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR)));
}
/*
* like chartabsize(), but also check for line breaks on the screen
*/
int
lbr_chartabsize(s, col)
unsigned char *s;
colnr_T col;
{
#ifdef FEAT_LINEBREAK
if (!curwin->w_p_lbr && *p_sbr == NUL)
{
#endif
#ifdef FEAT_MBYTE
if (curwin->w_p_wrap)
return win_nolbr_chartabsize(curwin, s, col, NULL);
#endif
RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, s, col)
#ifdef FEAT_LINEBREAK
}
return win_lbr_chartabsize(curwin, s, col, NULL);
#endif
}
/*
* Call lbr_chartabsize() and advance the pointer.
*/
int
lbr_chartabsize_adv(s, col)
char_u **s;
colnr_T col;
{
int retval;
retval = lbr_chartabsize(*s, col);
mb_ptr_adv(*s);
return retval;
}
/*
* This function is used very often, keep it fast!!!!
*
* If "headp" not NULL, set *headp to the size of what we for 'showbreak'
* string at start of line. Warning: *headp is only set if it's a non-zero
* value, init to 0 before calling.
*/
int
win_lbr_chartabsize(wp, s, col, headp)
win_T *wp;
char_u *s;
colnr_T col;
int *headp UNUSED;
{
#ifdef FEAT_LINEBREAK
int c;
int size;
colnr_T col2;
colnr_T colmax;
int added;
# ifdef FEAT_MBYTE
int mb_added = 0;
# else
# define mb_added 0
# endif
int numberextra;
char_u *ps;
int tab_corr = (*s == TAB);
int n;
/*
* No 'linebreak' and 'showbreak': return quickly.
*/
if (!wp->w_p_lbr && *p_sbr == NUL)
#endif
{
#ifdef FEAT_MBYTE
if (wp->w_p_wrap)
return win_nolbr_chartabsize(wp, s, col, headp);
#endif
RET_WIN_BUF_CHARTABSIZE(wp, wp->w_buffer, s, col)
}
#ifdef FEAT_LINEBREAK
/*
* First get normal size, without 'linebreak'
*/
size = win_chartabsize(wp, s, col);
c = *s;
/*
* If 'linebreak' set check at a blank before a non-blank if the line
* needs a break here
*/
if (wp->w_p_lbr
&& vim_isbreak(c)
&& !vim_isbreak(s[1])
&& !wp->w_p_list
&& wp->w_p_wrap
# ifdef FEAT_VERTSPLIT
&& wp->w_width != 0
# endif
)
{
/*
* Count all characters from first non-blank after a blank up to next
* non-blank after a blank.
*/
numberextra = win_col_off(wp);
col2 = col;
colmax = (colnr_T)(W_WIDTH(wp) - numberextra);
if (col >= colmax)
{
n = colmax + win_col_off2(wp);
if (n > 0)
colmax += (((col - colmax) / n) + 1) * n;
}
for (;;)
{
ps = s;
mb_ptr_adv(s);
c = *s;
if (!(c != NUL
&& (vim_isbreak(c)
|| (!vim_isbreak(c)
&& (col2 == col || !vim_isbreak(*ps))))))
break;
col2 += win_chartabsize(wp, s, col2);
if (col2 >= colmax) /* doesn't fit */
{
size = colmax - col;
tab_corr = FALSE;
break;
}
}
}
# ifdef FEAT_MBYTE
else if (has_mbyte && size == 2 && MB_BYTE2LEN(*s) > 1
&& wp->w_p_wrap && in_win_border(wp, col))
{
++size; /* Count the ">" in the last column. */
mb_added = 1;
}
# endif
/*
* May have to add something for 'showbreak' string at start of line
* Set *headp to the size of what we add.
*/
added = 0;
if (*p_sbr != NUL && wp->w_p_wrap && col != 0)
{
numberextra = win_col_off(wp);
col += numberextra + mb_added;
if (col >= (colnr_T)W_WIDTH(wp))
{
col -= W_WIDTH(wp);
numberextra = W_WIDTH(wp) - (numberextra - win_col_off2(wp));
if (numberextra > 0)
col = col % numberextra;
}
if (col == 0 || col + size > (colnr_T)W_WIDTH(wp))
{
added = vim_strsize(p_sbr);
if (tab_corr)
size += (added / wp->w_buffer->b_p_ts) * wp->w_buffer->b_p_ts;
else
size += added;
if (col != 0)
added = 0;
}
}
if (headp != NULL)
*headp = added + mb_added;
return size;
#endif
}
#if defined(FEAT_MBYTE) || defined(PROTO)
/*
* Like win_lbr_chartabsize(), except that we know 'linebreak' is off and
* 'wrap' is on. This means we need to check for a double-byte character that
* doesn't fit at the end of the screen line.
*/
static int
win_nolbr_chartabsize(wp, s, col, headp)
win_T *wp;
char_u *s;
colnr_T col;
int *headp;
{
int n;
if (*s == TAB && (!wp->w_p_list || lcs_tab1))
{
n = wp->w_buffer->b_p_ts;
return (int)(n - (col % n));
}
n = ptr2cells(s);
/* Add one cell for a double-width character in the last column of the
* window, displayed with a ">". */
if (n == 2 && MB_BYTE2LEN(*s) > 1 && in_win_border(wp, col))
{
if (headp != NULL)
*headp = 1;
return 3;
}
return n;
}
/*
* Return TRUE if virtual column "vcol" is in the rightmost column of window
* "wp".
*/
int
in_win_border(wp, vcol)
win_T *wp;
colnr_T vcol;
{
int width1; /* width of first line (after line number) */
int width2; /* width of further lines */
#ifdef FEAT_VERTSPLIT
if (wp->w_width == 0) /* there is no border */
return FALSE;
#endif
width1 = W_WIDTH(wp) - win_col_off(wp);
if ((int)vcol < width1 - 1)
return FALSE;
if ((int)vcol == width1 - 1)
return TRUE;
width2 = width1 + win_col_off2(wp);
if (width2 <= 0)
return FALSE;
return ((vcol - width1) % width2 == width2 - 1);
}
#endif /* FEAT_MBYTE */
/*
* Get virtual column number of pos.
* start: on the first position of this character (TAB, ctrl)
* cursor: where the cursor is on this character (first char, except for TAB)
* end: on the last position of this character (TAB, ctrl)
*
* This is used very often, keep it fast!
*/
void
getvcol(wp, pos, start, cursor, end)
win_T *wp;
pos_T *pos;
colnr_T *start;
colnr_T *cursor;
colnr_T *end;
{
colnr_T vcol;
char_u *ptr; /* points to current char */
char_u *posptr; /* points to char at pos->col */
int incr;
int head;
int ts = wp->w_buffer->b_p_ts;
int c;
vcol = 0;
ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
if (pos->col == MAXCOL)
posptr = NULL; /* continue until the NUL */
else
posptr = ptr + pos->col;
/*
* This function is used very often, do some speed optimizations.
* When 'list', 'linebreak' and 'showbreak' are not set use a simple loop.
* Also use this when 'list' is set but tabs take their normal size.
*/
if ((!wp->w_p_list || lcs_tab1 != NUL)
#ifdef FEAT_LINEBREAK
&& !wp->w_p_lbr && *p_sbr == NUL
#endif
)
{
#ifndef FEAT_MBYTE
head = 0;
#endif
for (;;)
{
#ifdef FEAT_MBYTE
head = 0;
#endif
c = *ptr;
/* make sure we don't go past the end of the line */
if (c == NUL)
{
incr = 1; /* NUL at end of line only takes one column */
break;
}
/* A tab gets expanded, depending on the current column */
if (c == TAB)
incr = ts - (vcol % ts);
else
{
#ifdef FEAT_MBYTE
if (has_mbyte)
{
/* For utf-8, if the byte is >= 0x80, need to look at
* further bytes to find the cell width. */
if (enc_utf8 && c >= 0x80)
incr = utf_ptr2cells(ptr);
else
incr = CHARSIZE(c);
/* If a double-cell char doesn't fit at the end of a line
* it wraps to the next line, it's like this char is three
* cells wide. */
if (incr == 2 && wp->w_p_wrap && MB_BYTE2LEN(*ptr) > 1
&& in_win_border(wp, vcol))
{
++incr;
head = 1;
}
}
else
#endif
incr = CHARSIZE(c);
}
if (posptr != NULL && ptr >= posptr) /* character at pos->col */
break;
vcol += incr;
mb_ptr_adv(ptr);
}
}
else
{
for (;;)
{
/* A tab gets expanded, depending on the current column */
head = 0;
incr = win_lbr_chartabsize(wp, ptr, vcol, &head);
/* make sure we don't go past the end of the line */
if (*ptr == NUL)
{
incr = 1; /* NUL at end of line only takes one column */
break;
}
if (posptr != NULL && ptr >= posptr) /* character at pos->col */
break;
vcol += incr;
mb_ptr_adv(ptr);
}
}
if (start != NULL)
*start = vcol + head;
if (end != NULL)
*end = vcol + incr - 1;
if (cursor != NULL)
{
if (*ptr == TAB
&& (State & NORMAL)
&& !wp->w_p_list
&& !virtual_active()
#ifdef FEAT_VISUAL
&& !(VIsual_active
&& (*p_sel == 'e' || ltoreq(*pos, VIsual)))
#endif
)
*cursor = vcol + incr - 1; /* cursor at end */
else
*cursor = vcol + head; /* cursor at start */
}
}
/*
* Get virtual cursor column in the current window, pretending 'list' is off.
*/
colnr_T
getvcol_nolist(posp)
pos_T *posp;
{
int list_save = curwin->w_p_list;
colnr_T vcol;
curwin->w_p_list = FALSE;
getvcol(curwin, posp, NULL, &vcol, NULL);
curwin->w_p_list = list_save;
return vcol;
}
#if defined(FEAT_VIRTUALEDIT) || defined(PROTO)
/*
* Get virtual column in virtual mode.
*/
void
getvvcol(wp, pos, start, cursor, end)
win_T *wp;
pos_T *pos;
colnr_T *start;
colnr_T *cursor;
colnr_T *end;
{
colnr_T col;
colnr_T coladd;
colnr_T endadd;
# ifdef FEAT_MBYTE
char_u *ptr;
# endif
if (virtual_active())
{
/* For virtual mode, only want one value */
getvcol(wp, pos, &col, NULL, NULL);
coladd = pos->coladd;
endadd = 0;
# ifdef FEAT_MBYTE
/* Cannot put the cursor on part of a wide character. */
ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
if (pos->col < (colnr_T)STRLEN(ptr))
{
int c = (*mb_ptr2char)(ptr + pos->col);
if (c != TAB && vim_isprintc(c))
{
endadd = (colnr_T)(char2cells(c) - 1);
if (coladd > endadd) /* past end of line */
endadd = 0;
else
coladd = 0;
}
}
# endif
col += coladd;
if (start != NULL)
*start = col;
if (cursor != NULL)
*cursor = col;
if (end != NULL)
*end = col + endadd;
}
else
getvcol(wp, pos, start, cursor, end);
}
#endif
#if defined(FEAT_VISUAL) || defined(PROTO)
/*
* Get the leftmost and rightmost virtual column of pos1 and pos2.
* Used for Visual block mode.
*/
void
getvcols(wp, pos1, pos2, left, right)
win_T *wp;
pos_T *pos1, *pos2;
colnr_T *left, *right;
{
colnr_T from1, from2, to1, to2;
if (ltp(pos1, pos2))
{
getvvcol(wp, pos1, &from1, NULL, &to1);
getvvcol(wp, pos2, &from2, NULL, &to2);
}
else
{
getvvcol(wp, pos2, &from1, NULL, &to1);
getvvcol(wp, pos1, &from2, NULL, &to2);
}
if (from2 < from1)
*left = from2;
else
*left = from1;
if (to2 > to1)
{
if (*p_sel == 'e' && from2 - 1 >= to1)
*right = from2 - 1;
else
*right = to2;
}
else
*right = to1;
}
#endif
/*
* skipwhite: skip over ' ' and '\t'.
*/
char_u *
skipwhite(q)
char_u *q;
{
char_u *p = q;
while (vim_iswhite(*p)) /* skip to next non-white */
++p;
return p;
}
/*
* skip over digits
*/
char_u *
skipdigits(q)
char_u *q;
{
char_u *p = q;
while (VIM_ISDIGIT(*p)) /* skip to next non-digit */
++p;
return p;
}
#if defined(FEAT_SYN_HL) || defined(FEAT_SPELL) || defined(PROTO)
/*
* skip over digits and hex characters
*/
char_u *
skiphex(q)
char_u *q;
{
char_u *p = q;
while (vim_isxdigit(*p)) /* skip to next non-digit */
++p;
return p;
}
#endif
#if defined(FEAT_EX_EXTRA) || defined(PROTO)
/*
* skip to digit (or NUL after the string)
*/
char_u *
skiptodigit(q)
char_u *q;
{
char_u *p = q;
while (*p != NUL && !VIM_ISDIGIT(*p)) /* skip to next digit */
++p;
return p;
}
/*
* skip to hex character (or NUL after the string)
*/
char_u *
skiptohex(q)
char_u *q;
{
char_u *p = q;
while (*p != NUL && !vim_isxdigit(*p)) /* skip to next digit */
++p;
return p;
}
#endif
/*
* Variant of isdigit() that can handle characters > 0x100.
* We don't use isdigit() here, because on some systems it also considers
* superscript 1 to be a digit.
* Use the VIM_ISDIGIT() macro for simple arguments.
*/
int
vim_isdigit(c)
int c;
{
return (c >= '0' && c <= '9');
}
/*
* Variant of isxdigit() that can handle characters > 0x100.
* We don't use isxdigit() here, because on some systems it also considers
* superscript 1 to be a digit.
*/
int
vim_isxdigit(c)
int c;
{
return (c >= '0' && c <= '9')
|| (c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F');
}
#if defined(FEAT_MBYTE) || defined(PROTO)
/*
* Vim's own character class functions. These exist because many library
* islower()/toupper() etc. do not work properly: they crash when used with
* invalid values or can't handle latin1 when the locale is C.
* Speed is most important here.
*/
#define LATIN1LOWER 'l'
#define LATIN1UPPER 'U'
static char_u latin1flags[257] = " UUUUUUUUUUUUUUUUUUUUUUUUUU llllllllllllllllllllllllll UUUUUUUUUUUUUUUUUUUUUUU UUUUUUUllllllllllllllllllllllll llllllll";
static char_u latin1upper[257] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xf7\xd8\xd9\xda\xdb\xdc\xdd\xde\xff";
static char_u latin1lower[257] = " !\"#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xd7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff";
int
vim_islower(c)
int c;
{
if (c <= '@')
return FALSE;
if (c >= 0x80)
{
if (enc_utf8)
return utf_islower(c);
if (c >= 0x100)
{
#ifdef HAVE_ISWLOWER
if (has_mbyte)
return iswlower(c);
#endif
/* islower() can't handle these chars and may crash */
return FALSE;
}
if (enc_latin1like)
return (latin1flags[c] & LATIN1LOWER) == LATIN1LOWER;
}
return islower(c);
}
int
vim_isupper(c)
int c;
{
if (c <= '@')
return FALSE;
if (c >= 0x80)
{
if (enc_utf8)
return utf_isupper(c);
if (c >= 0x100)
{
#ifdef HAVE_ISWUPPER
if (has_mbyte)
return iswupper(c);
#endif
/* islower() can't handle these chars and may crash */
return FALSE;
}
if (enc_latin1like)
return (latin1flags[c] & LATIN1UPPER) == LATIN1UPPER;
}
return isupper(c);
}
int
vim_toupper(c)
int c;
{
if (c <= '@')
return c;
if (c >= 0x80)
{
if (enc_utf8)
return utf_toupper(c);
if (c >= 0x100)
{
#ifdef HAVE_TOWUPPER
if (has_mbyte)
return towupper(c);
#endif
/* toupper() can't handle these chars and may crash */
return c;
}
if (enc_latin1like)
return latin1upper[c];
}
return TOUPPER_LOC(c);
}
int
vim_tolower(c)
int c;
{
if (c <= '@')
return c;
if (c >= 0x80)
{
if (enc_utf8)
return utf_tolower(c);
if (c >= 0x100)
{
#ifdef HAVE_TOWLOWER
if (has_mbyte)
return towlower(c);
#endif
/* tolower() can't handle these chars and may crash */
return c;
}
if (enc_latin1like)
return latin1lower[c];
}
return TOLOWER_LOC(c);
}
#endif
/*
* skiptowhite: skip over text until ' ' or '\t' or NUL.
*/
char_u *
skiptowhite(p)
char_u *p;
{
while (*p != ' ' && *p != '\t' && *p != NUL)
++p;
return p;
}
#if defined(FEAT_LISTCMDS) || defined(FEAT_SIGNS) || defined(FEAT_SNIFF) \
|| defined(PROTO)
/*
* skiptowhite_esc: Like skiptowhite(), but also skip escaped chars
*/
char_u *
skiptowhite_esc(p)
char_u *p;
{
while (*p != ' ' && *p != '\t' && *p != NUL)
{
if ((*p == '\\' || *p == Ctrl_V) && *(p + 1) != NUL)
++p;
++p;
}
return p;
}
#endif
/*
* Getdigits: Get a number from a string and skip over it.
* Note: the argument is a pointer to a char_u pointer!
*/
long
getdigits(pp)
char_u **pp;
{
char_u *p;
long retval;
p = *pp;
retval = atol((char *)p);
if (*p == '-') /* skip negative sign */
++p;
p = skipdigits(p); /* skip to next non-digit */
*pp = p;
return retval;
}
/*
* Return TRUE if "lbuf" is empty or only contains blanks.
*/
int
vim_isblankline(lbuf)
char_u *lbuf;
{
char_u *p;
p = skipwhite(lbuf);
return (*p == NUL || *p == '\r' || *p == '\n');
}
/*
* Convert a string into a long and/or unsigned long, taking care of
* hexadecimal and octal numbers. Accepts a '-' sign.
* If "hexp" is not NULL, returns a flag to indicate the type of the number:
* 0 decimal
* '0' octal
* 'X' hex
* 'x' hex
* If "len" is not NULL, the length of the number in characters is returned.
* If "nptr" is not NULL, the signed result is returned in it.
* If "unptr" is not NULL, the unsigned result is returned in it.
* If "dooct" is non-zero recognize octal numbers, when > 1 always assume
* octal number.
* If "dohex" is non-zero recognize hex numbers, when > 1 always assume
* hex number.
*/
void
vim_str2nr(start, hexp, len, dooct, dohex, nptr, unptr)
char_u *start;
int *hexp; /* return: type of number 0 = decimal, 'x'
or 'X' is hex, '0' = octal */
int *len; /* return: detected length of number */
int dooct; /* recognize octal number */
int dohex; /* recognize hex number */
long *nptr; /* return: signed result */
unsigned long *unptr; /* return: unsigned result */
{
char_u *ptr = start;
int hex = 0; /* default is decimal */
int negative = FALSE;
unsigned long un = 0;
int n;
if (ptr[0] == '-')
{
negative = TRUE;
++ptr;
}
/* Recognize hex and octal. */
if (ptr[0] == '0' && ptr[1] != '8' && ptr[1] != '9')
{
hex = ptr[1];
if (dohex && (hex == 'X' || hex == 'x') && vim_isxdigit(ptr[2]))
ptr += 2; /* hexadecimal */
else
{
hex = 0; /* default is decimal */
if (dooct)
{
/* Don't interpret "0", "08" or "0129" as octal. */
for (n = 1; VIM_ISDIGIT(ptr[n]); ++n)
{
if (ptr[n] > '7')
{
hex = 0; /* can't be octal */
break;
}
if (ptr[n] >= '0')
hex = '0'; /* assume octal */
}
}
}
}
/*
* Do the string-to-numeric conversion "manually" to avoid sscanf quirks.
*/
if (hex == '0' || dooct > 1)
{
/* octal */
while ('0' <= *ptr && *ptr <= '7')
{
un = 8 * un + (unsigned long)(*ptr - '0');
++ptr;
}
}
else if (hex != 0 || dohex > 1)
{
/* hex */
while (vim_isxdigit(*ptr))
{
un = 16 * un + (unsigned long)hex2nr(*ptr);
++ptr;
}
}
else
{
/* decimal */
while (VIM_ISDIGIT(*ptr))
{
un = 10 * un + (unsigned long)(*ptr - '0');
++ptr;
}
}
if (hexp != NULL)
*hexp = hex;
if (len != NULL)
*len = (int)(ptr - start);
if (nptr != NULL)
{
if (negative) /* account for leading '-' for decimal numbers */
*nptr = -(long)un;
else
*nptr = (long)un;
}
if (unptr != NULL)
*unptr = un;
}
/*
* Return the value of a single hex character.
* Only valid when the argument is '0' - '9', 'A' - 'F' or 'a' - 'f'.
*/
int
hex2nr(c)
int c;
{
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return c - '0';
}
#if defined(FEAT_TERMRESPONSE) \
|| (defined(FEAT_GUI_GTK) && defined(FEAT_WINDOWS)) || defined(PROTO)
/*
* Convert two hex characters to a byte.
* Return -1 if one of the characters is not hex.
*/
int
hexhex2nr(p)
char_u *p;
{
if (!vim_isxdigit(p[0]) || !vim_isxdigit(p[1]))
return -1;
return (hex2nr(p[0]) << 4) + hex2nr(p[1]);
}
#endif
/*
* Return TRUE if "str" starts with a backslash that should be removed.
* For MS-DOS, WIN32 and OS/2 this is only done when the character after the
* backslash is not a normal file name character.
* '$' is a valid file name character, we don't remove the backslash before
* it. This means it is not possible to use an environment variable after a
* backslash. "C:\$VIM\doc" is taken literally, only "$VIM\doc" works.
* Although "\ name" is valid, the backslash in "Program\ files" must be
* removed. Assume a file name doesn't start with a space.
* For multi-byte names, never remove a backslash before a non-ascii
* character, assume that all multi-byte characters are valid file name
* characters.
*/
int
rem_backslash(str)
char_u *str;
{
#ifdef BACKSLASH_IN_FILENAME
return (str[0] == '\\'
# ifdef FEAT_MBYTE
&& str[1] < 0x80
# endif
&& (str[1] == ' '
|| (str[1] != NUL
&& str[1] != '*'
&& str[1] != '?'
&& !vim_isfilec(str[1]))));
#else
return (str[0] == '\\' && str[1] != NUL);
#endif
}
/*
* Halve the number of backslashes in a file name argument.
* For MS-DOS we only do this if the character after the backslash
* is not a normal file character.
*/
void
backslash_halve(p)
char_u *p;
{
for ( ; *p; ++p)
if (rem_backslash(p))
STRMOVE(p, p + 1);
}
/*
* backslash_halve() plus save the result in allocated memory.
*/
char_u *
backslash_halve_save(p)
char_u *p;
{
char_u *res;
res = vim_strsave(p);
if (res == NULL)
return p;
backslash_halve(res);
return res;
}
#if (defined(EBCDIC) && defined(FEAT_POSTSCRIPT)) || defined(PROTO)
/*
* Table for EBCDIC to ASCII conversion unashamedly taken from xxd.c!
* The first 64 entries have been added to map control characters defined in
* ascii.h
*/
static char_u ebcdic2ascii_tab[256] =
{
0000, 0001, 0002, 0003, 0004, 0011, 0006, 0177,
0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017,
0020, 0021, 0022, 0023, 0024, 0012, 0010, 0027,
0030, 0031, 0032, 0033, 0033, 0035, 0036, 0037,
0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047,
0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057,
0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077,
0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246,
0247, 0250, 0325, 0056, 0074, 0050, 0053, 0174,
0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
0260, 0261, 0041, 0044, 0052, 0051, 0073, 0176,
0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267,
0270, 0271, 0313, 0054, 0045, 0137, 0076, 0077,
0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301,
0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042,
0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147,
0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311,
0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160,
0161, 0162, 0136, 0314, 0315, 0316, 0317, 0320,
0321, 0345, 0163, 0164, 0165, 0166, 0167, 0170,
0171, 0172, 0322, 0323, 0324, 0133, 0326, 0327,
0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
0340, 0341, 0342, 0343, 0344, 0135, 0346, 0347,
0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355,
0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120,
0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363,
0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130,
0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371,
0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377
};
/*
* Convert a buffer worth of characters from EBCDIC to ASCII. Only useful if
* wanting 7-bit ASCII characters out the other end.
*/
void
ebcdic2ascii(buffer, len)
char_u *buffer;
int len;
{
int i;
for (i = 0; i < len; i++)
buffer[i] = ebcdic2ascii_tab[buffer[i]];
}
#endif
| zyz2011-vim | src/charset.c | C | gpl2 | 46,798 |
/* vi:set ts=8 sts=4 sw=4: */
/*
* MODIFIED ATHENA SCROLLBAR (USING ARROWHEADS AT ENDS OF TRAVEL)
* Modifications Copyright 1992 by Mitch Trachtenberg
* Rights, permissions, and disclaimer of warranty are as in the DEC and MIT
* notice below.
* $XConsortium: Scrollbar.c,v 1.72 94/04/17 20:12:40 kaleb Exp $
*/
/*
* Modified for Vim by Bill Foster and Bram Moolenaar
*/
/*
Copyright (c) 1987, 1988, 1994 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X
CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from the X Consortium.
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided that
the above copyright notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting documentation, and that
the name of Digital not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL
BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* ScrollBar.c */
/* created by weissman, Mon Jul 7 13:20:03 1986 */
/* converted by swick, Thu Aug 27 1987 */
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/XawInit.h>
#include "vim.h"
#include "gui_at_sb.h"
#include <X11/Xmu/Drawing.h>
/* Private definitions. */
static char defaultTranslations[] =
"<Btn1Down>: NotifyScroll()\n\
<Btn2Down>: MoveThumb() NotifyThumb()\n\
<Btn3Down>: NotifyScroll()\n\
<Btn4Down>: ScrollOneLineUp()\n\
Shift<Btn4Down>: ScrollPageUp()\n\
<Btn5Down>: ScrollOneLineDown()\n\
Shift<Btn5Down>: ScrollPageDown()\n\
<Btn1Motion>: HandleThumb()\n\
<Btn3Motion>: HandleThumb()\n\
<Btn2Motion>: MoveThumb() NotifyThumb()\n\
<BtnUp>: EndScroll()";
static float floatZero = 0.0;
#define Offset(field) XtOffsetOf(ScrollbarRec, field)
static XtResource resources[] =
{
{XtNlength, XtCLength, XtRDimension, sizeof(Dimension),
Offset(scrollbar.length), XtRImmediate, (XtPointer) 1},
{XtNthickness, XtCThickness, XtRDimension, sizeof(Dimension),
Offset(scrollbar.thickness), XtRImmediate, (XtPointer) 14},
{XtNorientation, XtCOrientation, XtROrientation, sizeof(XtOrientation),
Offset(scrollbar.orientation), XtRImmediate, (XtPointer) XtorientVertical},
{XtNscrollProc, XtCCallback, XtRCallback, sizeof(XtPointer),
Offset(scrollbar.scrollProc), XtRCallback, NULL},
{XtNthumbProc, XtCCallback, XtRCallback, sizeof(XtPointer),
Offset(scrollbar.thumbProc), XtRCallback, NULL},
{XtNjumpProc, XtCCallback, XtRCallback, sizeof(XtPointer),
Offset(scrollbar.jumpProc), XtRCallback, NULL},
{XtNthumb, XtCThumb, XtRBitmap, sizeof(Pixmap),
Offset(scrollbar.thumb), XtRImmediate, (XtPointer) XtUnspecifiedPixmap},
{XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
Offset(scrollbar.foreground), XtRString, XtDefaultForeground},
{XtNshown, XtCShown, XtRFloat, sizeof(float),
Offset(scrollbar.shown), XtRFloat, (XtPointer)&floatZero},
{XtNtopOfThumb, XtCTopOfThumb, XtRFloat, sizeof(float),
Offset(scrollbar.top), XtRFloat, (XtPointer)&floatZero},
{XtNmaxOfThumb, XtCMaxOfThumb, XtRFloat, sizeof(float),
Offset(scrollbar.max), XtRFloat, (XtPointer)&floatZero},
{XtNminimumThumb, XtCMinimumThumb, XtRDimension, sizeof(Dimension),
Offset(scrollbar.min_thumb), XtRImmediate, (XtPointer) 7},
{XtNshadowWidth, XtCShadowWidth, XtRDimension, sizeof(Dimension),
Offset(scrollbar.shadow_width), XtRImmediate, (XtPointer) 1},
{XtNtopShadowPixel, XtCTopShadowPixel, XtRPixel, sizeof(Pixel),
Offset(scrollbar.top_shadow_pixel), XtRString, XtDefaultBackground},
{XtNbottomShadowPixel, XtCBottomShadowPixel, XtRPixel, sizeof(Pixel),
Offset(scrollbar.bot_shadow_pixel), XtRString, XtDefaultForeground},
{XtNlimitThumb, XtCLimitThumb, XtRBool, sizeof(Bool),
Offset(scrollbar.limit_thumb), XtRImmediate, (XtPointer)0}
};
#undef Offset
static void ClassInitialize __ARGS((void));
static void Initialize __ARGS((Widget, Widget, ArgList, Cardinal *));
static void Destroy __ARGS((Widget));
static void Realize __ARGS((Widget, Mask *, XSetWindowAttributes *));
static void Resize __ARGS((Widget));
static void Redisplay __ARGS((Widget, XEvent *, Region));
static Boolean SetValues __ARGS((Widget, Widget, Widget, ArgList, Cardinal *));
static void HandleThumb __ARGS((Widget, XEvent *, String *, Cardinal *));
static void MoveThumb __ARGS((Widget, XEvent *, String *, Cardinal *));
static void NotifyThumb __ARGS((Widget, XEvent *, String *, Cardinal *));
static void NotifyScroll __ARGS((Widget, XEvent *, String *, Cardinal *));
static void EndScroll __ARGS((Widget, XEvent *, String *, Cardinal *));
static void ScrollOneLineUp __ARGS((Widget, XEvent *, String *, Cardinal *));
static void ScrollOneLineDown __ARGS((Widget, XEvent *, String *, Cardinal *));
static void ScrollPageUp __ARGS((Widget, XEvent *, String *, Cardinal *));
static void ScrollPageDown __ARGS((Widget, XEvent *, String *, Cardinal *));
static void ScrollSome __ARGS((Widget w, XEvent *event, int call_data));
static void _Xaw3dDrawShadows __ARGS((Widget, XEvent *, Region, int));
static void AllocTopShadowGC __ARGS((Widget));
static void AllocBotShadowGC __ARGS((Widget));
static XtActionsRec actions[] =
{
{"HandleThumb", HandleThumb},
{"MoveThumb", MoveThumb},
{"NotifyThumb", NotifyThumb},
{"NotifyScroll", NotifyScroll},
{"EndScroll", EndScroll},
{"ScrollOneLineUp", ScrollOneLineUp},
{"ScrollOneLineDown", ScrollOneLineDown},
{"ScrollPageUp", ScrollPageUp},
{"ScrollPageDown", ScrollPageDown}
};
ScrollbarClassRec vim_scrollbarClassRec =
{
{ /* core fields */
/* superclass */ (WidgetClass) &simpleClassRec,
/* class_name */ "Scrollbar",
/* size */ sizeof(ScrollbarRec),
/* class_initialize */ ClassInitialize,
/* class_part_init */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ Realize,
/* actions */ actions,
/* num_actions */ XtNumber(actions),
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure*/ TRUE,
/* compress_enterleave*/ TRUE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ defaultTranslations,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator*/ XtInheritDisplayAccelerator,
/* extension */ NULL
},
{ /* simple fields */
/* change_sensitive */ XtInheritChangeSensitive,
#ifndef OLDXAW
/* extension */ NULL
#endif
},
{ /* scrollbar fields */
/* empty */ 0
}
};
WidgetClass vim_scrollbarWidgetClass = (WidgetClass)&vim_scrollbarClassRec;
#define NoButton -1
#define PICKLENGTH(widget, x, y) \
((widget->scrollbar.orientation == XtorientHorizontal) ? (x) : (y))
#define AT_MIN(x,y) ((x) < (y) ? (x) : (y))
#define AT_MAX(x,y) ((x) > (y) ? (x) : (y))
#define LINE_DELAY 300
#define PAGE_DELAY 300
#define LINE_REPEAT 50
#define PAGE_REPEAT 250
static void
ClassInitialize()
{
XawInitializeWidgetSet();
XtAddConverter( XtRString, XtROrientation, XmuCvtStringToOrientation,
(XtConvertArgList)NULL, (Cardinal)0 );
}
#define MARGIN(sbw) (sbw)->scrollbar.thickness + (sbw)->scrollbar.shadow_width
static void
FillArea(sbw, top, bottom, fill, draw_shadow)
ScrollbarWidget sbw;
Position top, bottom;
int fill;
int draw_shadow;
{
int tlen = bottom - top; /* length of thumb in pixels */
int sw, margin, floor;
int lx, ly, lw, lh;
if (bottom <= 0 || bottom <= top)
return;
sw = sbw->scrollbar.shadow_width;
if (sw < 0)
sw = 0;
margin = MARGIN (sbw);
floor = sbw->scrollbar.length - margin + 2;
if (sbw->scrollbar.orientation == XtorientHorizontal)
{
lx = ((top < margin) ? margin : top);
ly = sw;
lw = (((top + tlen) > floor) ? floor - top : tlen);
lh = sbw->core.height - 2 * sw;
}
else
{
lx = sw;
ly = ((top < margin) ? margin : top);
lw = sbw->core.width - 2 * sw;
lh = (((top + tlen) > floor) ? floor - top : tlen);
}
if (lh <= 0 || lw <= 0)
return;
if (draw_shadow)
{
if (!(sbw->scrollbar.orientation == XtorientHorizontal))
{
/* Top border */
XDrawLine (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.top_shadow_GC,
lx, ly, lx + lw - 1, ly);
/* Bottom border */
XDrawLine (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.bot_shadow_GC,
lx, ly + lh - 1, lx + lw - 1, ly + lh - 1);
}
else
{
/* Left border */
XDrawLine (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.top_shadow_GC,
lx, ly, lx, ly + lh - 1);
/* Right border */
XDrawLine (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.bot_shadow_GC,
lx + lw - 1, ly, lx + lw - 1, ly + lh - 1);
}
return;
}
if (fill)
{
XFillRectangle(XtDisplay((Widget) sbw), XtWindow((Widget) sbw),
sbw->scrollbar.gc,
lx, ly, (unsigned int) lw, (unsigned int) lh);
if (!(sbw->scrollbar.orientation == XtorientHorizontal))
{
/* Left border */
XDrawLine(XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.top_shadow_GC,
lx, ly, lx, ly + lh - 1);
/* Right border */
XDrawLine(XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.bot_shadow_GC,
lx + lw - 1, ly, lx + lw - 1, ly + lh - 1);
}
else
{
/* Top border */
XDrawLine(XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.top_shadow_GC,
lx, ly, lx + lw - 1, ly);
/* Bottom border */
XDrawLine(XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.bot_shadow_GC,
lx, ly + lh - 1, lx + lw - 1, ly + lh - 1);
}
}
else
{
XClearArea(XtDisplay((Widget) sbw), XtWindow((Widget) sbw),
lx, ly, (unsigned int) lw, (unsigned int) lh, FALSE);
}
}
/* Paint the thumb in the area specified by sbw->top and
sbw->shown. The old area is erased. The painting and
erasing is done cleverly so that no flickering will occur.
*/
static void
PaintThumb(sbw)
ScrollbarWidget sbw;
{
Position oldtop, oldbot, newtop, newbot;
Dimension margin, tzl;
margin = MARGIN (sbw);
tzl = sbw->scrollbar.length - 2 * margin;
newtop = margin + (int)(tzl * sbw->scrollbar.top);
newbot = newtop + (int)(tzl * sbw->scrollbar.shown) + 1;
if (newbot < newtop + (int)sbw->scrollbar.min_thumb)
newbot = newtop + sbw->scrollbar.min_thumb;
oldtop = sbw->scrollbar.topLoc;
oldbot = oldtop + sbw->scrollbar.shownLength;
sbw->scrollbar.topLoc = newtop;
sbw->scrollbar.shownLength = newbot - newtop;
if (XtIsRealized ((Widget) sbw))
{
if (newtop < oldtop)
FillArea(sbw, newtop, AT_MIN(newbot, oldtop+1),1,0);
if (newtop > oldtop)
FillArea(sbw, oldtop, AT_MIN(newtop, oldbot ),0,0);
if (newbot < oldbot)
FillArea(sbw, AT_MAX(newbot, oldtop), oldbot, 0,0);
if (newbot > oldbot)
FillArea(sbw, AT_MAX(newtop, oldbot-1), newbot, 1,0);
/* Only draw the missing shadows */
FillArea(sbw, newtop, newbot, 0, 1);
}
}
static void
PaintArrows(sbw)
ScrollbarWidget sbw;
{
XPoint point[6];
Dimension thickness = sbw->scrollbar.thickness - 1;
Dimension size;
Dimension off;
if (XtIsRealized((Widget) sbw))
{
if ((int)thickness * 2 > (int)sbw->scrollbar.length)
{
size = sbw->scrollbar.length / 2;
off = (int)(thickness - size) / 2;
}
else
{
size = thickness;
off = 0;
}
point[0].x = off + sbw->scrollbar.shadow_width;
point[0].y = size;
point[1].x = thickness - off - sbw->scrollbar.shadow_width;
point[1].y = size;
point[2].x = thickness / 2;
point[2].y = sbw->scrollbar.shadow_width;
point[3].x = off + sbw->scrollbar.shadow_width;
point[3].y = sbw->scrollbar.length - size;
point[4].x = thickness - off - sbw->scrollbar.shadow_width;
point[4].y = sbw->scrollbar.length - size;
point[5].x = thickness / 2;
point[5].y = sbw->scrollbar.length - sbw->scrollbar.shadow_width - 1;
/* horizontal arrows require that x and y coordinates be swapped */
if (sbw->scrollbar.orientation == XtorientHorizontal)
{
int n;
int swap;
for (n = 0; n < 6; n++)
{
swap = point[n].x;
point[n].x = point[n].y;
point[n].y = swap;
}
}
/* draw the up/left arrow */
XFillPolygon (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.gc,
point, 3,
Convex, CoordModeOrigin);
XDrawLines (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.bot_shadow_GC,
point, 3,
CoordModeOrigin);
XDrawLine (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.top_shadow_GC,
point[0].x, point[0].y,
point[2].x, point[2].y);
/* draw the down/right arrow */
XFillPolygon (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.gc,
point+3, 3,
Convex, CoordModeOrigin);
XDrawLine (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.top_shadow_GC,
point[3].x, point[3].y,
point[4].x, point[4].y);
XDrawLine (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.top_shadow_GC,
point[3].x, point[3].y,
point[5].x, point[5].y);
XDrawLine (XtDisplay ((Widget) sbw), XtWindow ((Widget) sbw),
sbw->scrollbar.bot_shadow_GC,
point[4].x, point[4].y,
point[5].x, point[5].y);
}
}
static void
Destroy(w)
Widget w;
{
ScrollbarWidget sbw = (ScrollbarWidget) w;
if (sbw->scrollbar.timer_id != (XtIntervalId) 0)
XtRemoveTimeOut (sbw->scrollbar.timer_id);
XtReleaseGC(w, sbw->scrollbar.gc);
XtReleaseGC(w, sbw->scrollbar.top_shadow_GC);
XtReleaseGC(w, sbw->scrollbar.bot_shadow_GC);
}
static void
CreateGC(w)
Widget w;
{
ScrollbarWidget sbw = (ScrollbarWidget) w;
XGCValues gcValues;
XtGCMask mask;
unsigned int depth = 1;
if (sbw->scrollbar.thumb == XtUnspecifiedPixmap)
{
sbw->scrollbar.thumb = XmuCreateStippledPixmap (XtScreen(w),
(Pixel) 1, (Pixel) 0, depth);
}
else if (sbw->scrollbar.thumb != None)
{
Window root;
int x, y;
unsigned int width, height, bw;
if (XGetGeometry (XtDisplay(w), sbw->scrollbar.thumb, &root, &x, &y,
&width, &height, &bw, &depth) == 0)
EMSG(_("Scrollbar Widget: Could not get geometry of thumb pixmap."));
}
gcValues.foreground = sbw->scrollbar.foreground;
gcValues.background = sbw->core.background_pixel;
mask = GCForeground | GCBackground;
if (sbw->scrollbar.thumb != None)
{
gcValues.fill_style = FillSolid;
mask |= GCFillStyle;
}
/* the creation should be non-caching, because */
/* we now set and clear clip masks on the gc returned */
sbw->scrollbar.gc = XtGetGC (w, mask, &gcValues);
}
static void
SetDimensions(sbw)
ScrollbarWidget sbw;
{
if (sbw->scrollbar.orientation == XtorientVertical)
{
sbw->scrollbar.length = sbw->core.height;
sbw->scrollbar.thickness = sbw->core.width;
}
else
{
sbw->scrollbar.length = sbw->core.width;
sbw->scrollbar.thickness = sbw->core.height;
}
}
static void
Initialize(request, new, args, num_args)
Widget request UNUSED; /* what the client asked for */
Widget new; /* what we're going to give him */
ArgList args UNUSED;
Cardinal *num_args UNUSED;
{
ScrollbarWidget sbw = (ScrollbarWidget) new;
CreateGC(new);
AllocTopShadowGC(new);
AllocBotShadowGC(new);
if (sbw->core.width == 0)
sbw->core.width = (sbw->scrollbar.orientation == XtorientVertical)
? sbw->scrollbar.thickness : sbw->scrollbar.length;
if (sbw->core.height == 0)
sbw->core.height = (sbw->scrollbar.orientation == XtorientHorizontal)
? sbw->scrollbar.thickness : sbw->scrollbar.length;
SetDimensions(sbw);
sbw->scrollbar.scroll_mode = SMODE_NONE;
sbw->scrollbar.timer_id = (XtIntervalId)0;
sbw->scrollbar.topLoc = 0;
sbw->scrollbar.shownLength = sbw->scrollbar.min_thumb;
}
static void
Realize(w, valueMask, attributes)
Widget w;
Mask *valueMask;
XSetWindowAttributes *attributes;
{
/* The Simple widget actually stuffs the value in the valuemask. */
(*vim_scrollbarWidgetClass->core_class.superclass->core_class.realize)
(w, valueMask, attributes);
}
static Boolean
SetValues(current, request, desired, args, num_args)
Widget current; /* what I am */
Widget request UNUSED; /* what he wants me to be */
Widget desired; /* what I will become */
ArgList args UNUSED;
Cardinal *num_args UNUSED;
{
ScrollbarWidget sbw = (ScrollbarWidget) current;
ScrollbarWidget dsbw = (ScrollbarWidget) desired;
Boolean redraw = FALSE;
/*
* If these values are outside the acceptable range ignore them...
*/
if (dsbw->scrollbar.top < 0.0 || dsbw->scrollbar.top > 1.0)
dsbw->scrollbar.top = sbw->scrollbar.top;
if (dsbw->scrollbar.shown < 0.0 || dsbw->scrollbar.shown > 1.0)
dsbw->scrollbar.shown = sbw->scrollbar.shown;
/*
* Change colors and stuff...
*/
if (XtIsRealized(desired))
{
if (sbw->scrollbar.foreground != dsbw->scrollbar.foreground ||
sbw->core.background_pixel != dsbw->core.background_pixel ||
sbw->scrollbar.thumb != dsbw->scrollbar.thumb)
{
XtReleaseGC(desired, sbw->scrollbar.gc);
CreateGC (desired);
redraw = TRUE;
}
if (sbw->scrollbar.top != dsbw->scrollbar.top ||
sbw->scrollbar.shown != dsbw->scrollbar.shown)
redraw = TRUE;
}
return redraw;
}
static void
Resize(w)
Widget w;
{
/* ForgetGravity has taken care of background, but thumb may
* have to move as a result of the new size. */
SetDimensions ((ScrollbarWidget) w);
Redisplay(w, (XEvent*) NULL, (Region)NULL);
}
static void
Redisplay(w, event, region)
Widget w;
XEvent *event;
Region region;
{
ScrollbarWidget sbw = (ScrollbarWidget) w;
int x, y;
unsigned int width, height;
_Xaw3dDrawShadows(w, event, region, FALSE);
if (sbw->scrollbar.orientation == XtorientHorizontal)
{
x = sbw->scrollbar.topLoc;
y = 1;
width = sbw->scrollbar.shownLength;
height = sbw->core.height - 2;
}
else
{
x = 1;
y = sbw->scrollbar.topLoc;
width = sbw->core.width - 2;
height = sbw->scrollbar.shownLength;
}
if (region == NULL ||
XRectInRegion (region, x, y, width, height) != RectangleOut)
{
/* Forces entire thumb to be painted. */
sbw->scrollbar.topLoc = -(sbw->scrollbar.length + 1);
PaintThumb (sbw);
}
/* we'd like to be region aware here!!!! */
PaintArrows(sbw);
}
static Boolean
CompareEvents(oldEvent, newEvent)
XEvent *oldEvent, *newEvent;
{
#define Check(field) if (newEvent->field != oldEvent->field) return False;
Check(xany.display);
Check(xany.type);
Check(xany.window);
switch (newEvent->type)
{
case MotionNotify:
Check(xmotion.state);
break;
case ButtonPress:
case ButtonRelease:
Check(xbutton.state);
Check(xbutton.button);
break;
case KeyPress:
case KeyRelease:
Check(xkey.state);
Check(xkey.keycode);
break;
case EnterNotify:
case LeaveNotify:
Check(xcrossing.mode);
Check(xcrossing.detail);
Check(xcrossing.state);
break;
}
#undef Check
return True;
}
struct EventData
{
XEvent *oldEvent;
int count;
};
static Bool
PeekNotifyEvent(dpy, event, args)
Display *dpy;
XEvent *event;
char *args;
{
struct EventData *eventData = (struct EventData*)args;
return ((++eventData->count == QLength(dpy)) /* since PeekIf blocks */
|| CompareEvents(event, eventData->oldEvent));
}
static Boolean
LookAhead(w, event)
Widget w;
XEvent *event;
{
XEvent newEvent;
struct EventData eventData;
if (QLength (XtDisplay (w)) == 0)
return False;
eventData.count = 0;
eventData.oldEvent = event;
XPeekIfEvent (XtDisplay (w), &newEvent, PeekNotifyEvent, (char*)&eventData);
return CompareEvents (event, &newEvent);
}
static void
ExtractPosition(event, x, y, state)
XEvent *event;
Position *x, *y; /* RETURN */
unsigned int *state; /* RETURN */
{
switch (event->type)
{
case MotionNotify:
*x = event->xmotion.x;
*y = event->xmotion.y;
if (state != NULL)
*state = event->xmotion.state;
break;
case ButtonPress:
case ButtonRelease:
*x = event->xbutton.x;
*y = event->xbutton.y;
if (state != NULL)
*state = event->xbutton.state;
break;
case KeyPress:
case KeyRelease:
*x = event->xkey.x;
*y = event->xkey.y;
if (state != NULL)
*state = event->xkey.state;
break;
case EnterNotify:
case LeaveNotify:
*x = event->xcrossing.x;
*y = event->xcrossing.y;
if (state != NULL)
*state = event->xcrossing.state;
break;
default:
*x = 0; *y = 0;
if (state != NULL)
*state = 0;
}
}
static void
HandleThumb(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Position x, y, loc;
ScrollbarWidget sbw = (ScrollbarWidget) w;
ExtractPosition(event, &x, &y, (unsigned int *)NULL);
loc = PICKLENGTH(sbw, x, y);
/* if the motion event puts the pointer in thumb, call Move and Notify */
/* also call Move and Notify if we're already in continuous scroll mode */
if (sbw->scrollbar.scroll_mode == SMODE_CONT ||
(loc >= sbw->scrollbar.topLoc &&
loc <= sbw->scrollbar.topLoc + (int)sbw->scrollbar.shownLength))
{
XtCallActionProc(w, "MoveThumb", event, params, *num_params);
XtCallActionProc(w, "NotifyThumb", event, params, *num_params);
}
}
static void
RepeatNotify(client_data, idp)
XtPointer client_data;
XtIntervalId *idp UNUSED;
{
ScrollbarWidget sbw = (ScrollbarWidget) client_data;
int call_data;
char mode = sbw->scrollbar.scroll_mode;
unsigned long rep;
if (mode == SMODE_NONE || mode == SMODE_CONT)
{
sbw->scrollbar.timer_id = (XtIntervalId)0;
return;
}
if (mode == SMODE_LINE_DOWN || mode == SMODE_LINE_UP)
{
call_data = ONE_LINE_DATA;
rep = LINE_REPEAT;
}
else
{
call_data = ONE_PAGE_DATA;
rep = PAGE_REPEAT;
}
if (mode == SMODE_PAGE_UP || mode == SMODE_LINE_UP)
call_data = -call_data;
XtCallCallbacks((Widget)sbw, XtNscrollProc, (XtPointer)(long_u)call_data);
sbw->scrollbar.timer_id =
XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)sbw),
rep,
RepeatNotify,
client_data);
}
/*
* Same as above, but for floating numbers.
*/
static float
FloatInRange(num, small, big)
float num, small, big;
{
return (num < small) ? small : ((num > big) ? big : num);
}
static void
ScrollOneLineUp(w, event, params, num_params)
Widget w;
XEvent *event;
String *params UNUSED;
Cardinal *num_params UNUSED;
{
ScrollSome(w, event, -ONE_LINE_DATA);
}
static void
ScrollOneLineDown(w, event, params, num_params)
Widget w;
XEvent *event;
String *params UNUSED;
Cardinal *num_params UNUSED;
{
ScrollSome(w, event, ONE_LINE_DATA);
}
static void
ScrollPageDown(w, event, params, num_params)
Widget w;
XEvent *event;
String *params UNUSED;
Cardinal *num_params UNUSED;
{
ScrollSome(w, event, ONE_PAGE_DATA);
}
static void
ScrollPageUp(w, event, params, num_params)
Widget w;
XEvent *event;
String *params UNUSED;
Cardinal *num_params UNUSED;
{
ScrollSome(w, event, -ONE_PAGE_DATA);
}
static void
ScrollSome(w, event, call_data)
Widget w;
XEvent *event;
int call_data;
{
ScrollbarWidget sbw = (ScrollbarWidget) w;
if (sbw->scrollbar.scroll_mode == SMODE_CONT) /* if scroll continuous */
return;
if (LookAhead(w, event))
return;
sbw->scrollbar.scroll_mode = SMODE_LINE_UP;
XtCallCallbacks(w, XtNscrollProc, (XtPointer)(long_u)call_data);
}
static void
NotifyScroll(w, event, params, num_params)
Widget w;
XEvent *event;
String *params UNUSED;
Cardinal *num_params UNUSED;
{
ScrollbarWidget sbw = (ScrollbarWidget) w;
Position x, y, loc;
Dimension arrow_size;
unsigned long delay = 0;
int call_data = 0;
unsigned int state;
if (sbw->scrollbar.scroll_mode == SMODE_CONT) /* if scroll continuous */
return;
if (LookAhead (w, event))
return;
ExtractPosition(event, &x, &y, &state);
loc = PICKLENGTH(sbw, x, y);
if ((int)sbw->scrollbar.thickness * 2 > (int)sbw->scrollbar.length)
arrow_size = sbw->scrollbar.length / 2;
else
arrow_size = sbw->scrollbar.thickness;
/*
* handle CTRL modifier
*/
if (state & ControlMask)
{
if (loc > sbw->scrollbar.topLoc + (Position)sbw->scrollbar.shownLength)
call_data = END_PAGE_DATA;
else
call_data = -END_PAGE_DATA;
sbw->scrollbar.scroll_mode = SMODE_NONE;
}
/*
* handle first arrow zone
*/
else if (loc < (Position)arrow_size)
{
call_data = -ONE_LINE_DATA;
sbw->scrollbar.scroll_mode = SMODE_LINE_UP;
delay = LINE_DELAY;
}
/*
* handle last arrow zone
*/
else if (loc > (Position)(sbw->scrollbar.length - arrow_size))
{
call_data = ONE_LINE_DATA;
sbw->scrollbar.scroll_mode = SMODE_LINE_DOWN;
delay = LINE_DELAY;
}
/*
* handle zone "above" the thumb
*/
else if (loc < sbw->scrollbar.topLoc)
{
call_data = -ONE_PAGE_DATA;
sbw->scrollbar.scroll_mode = SMODE_PAGE_UP;
delay = PAGE_DELAY;
}
/*
* handle zone "below" the thumb
*/
else if (loc > sbw->scrollbar.topLoc + (Position)sbw->scrollbar.shownLength)
{
call_data = ONE_PAGE_DATA;
sbw->scrollbar.scroll_mode = SMODE_PAGE_DOWN;
delay = PAGE_DELAY;
}
if (call_data)
XtCallCallbacks(w, XtNscrollProc, (XtPointer)(long_u)call_data);
/* establish autoscroll */
if (delay)
sbw->scrollbar.timer_id =
XtAppAddTimeOut(XtWidgetToApplicationContext(w),
delay, RepeatNotify, (XtPointer)w);
}
static void
EndScroll(w, event, params, num_params)
Widget w;
XEvent *event UNUSED;
String *params UNUSED;
Cardinal *num_params UNUSED;
{
ScrollbarWidget sbw = (ScrollbarWidget) w;
sbw->scrollbar.scroll_mode = SMODE_NONE;
/* no need to remove any autoscroll timeout; it will no-op */
/* because the scroll_mode is SMODE_NONE */
/* but be sure to remove timeout in destroy proc */
}
static float
FractionLoc(sbw, x, y)
ScrollbarWidget sbw;
int x, y;
{
int margin;
float height, width;
margin = MARGIN(sbw);
x -= margin;
y -= margin;
height = (float)sbw->core.height - 2 * margin;
width = (float)sbw->core.width - 2 * margin;
return PICKLENGTH(sbw, x / width, y / height);
}
static void
MoveThumb(w, event, params, num_params)
Widget w;
XEvent *event;
String *params UNUSED;
Cardinal *num_params UNUSED;
{
ScrollbarWidget sbw = (ScrollbarWidget)w;
Position x, y;
float top;
char old_mode = sbw->scrollbar.scroll_mode;
sbw->scrollbar.scroll_mode = SMODE_CONT; /* indicate continuous scroll */
if (LookAhead(w, event))
return;
if (!event->xmotion.same_screen)
return;
ExtractPosition(event, &x, &y, (unsigned int *)NULL);
top = FractionLoc(sbw, x, y);
if (old_mode != SMODE_CONT) /* start dragging: set offset */
{
if (event->xbutton.button == Button2)
sbw->scrollbar.scroll_off = sbw->scrollbar.shown / 2.;
else
sbw->scrollbar.scroll_off = top - sbw->scrollbar.top;
}
top -= sbw->scrollbar.scroll_off;
if (sbw->scrollbar.limit_thumb)
top = FloatInRange(top, 0.0,
sbw->scrollbar.max - sbw->scrollbar.shown + 0.000001);
else
top = FloatInRange(top, 0.0, sbw->scrollbar.max);
sbw->scrollbar.top = top;
PaintThumb(sbw);
XFlush(XtDisplay(w)); /* re-draw it before Notifying */
}
static void
NotifyThumb(w, event, params, num_params)
Widget w;
XEvent *event;
String *params UNUSED;
Cardinal *num_params UNUSED;
{
ScrollbarWidget sbw = (ScrollbarWidget)w;
/* Use a union to avoid a warning for the weird conversion from float to
* XtPointer. Comes from Xaw/Scrollbar.c. */
union {
XtPointer xtp;
float xtf;
} xtpf;
if (LookAhead(w, event))
return;
/* thumbProc is not pretty, but is necessary for backwards
compatibility on those architectures for which it work{s,ed};
the intent is to pass a (truncated) float by value. */
xtpf.xtf = sbw->scrollbar.top;
XtCallCallbacks(w, XtNthumbProc, xtpf.xtp);
XtCallCallbacks(w, XtNjumpProc, (XtPointer)&sbw->scrollbar.top);
}
static void
AllocTopShadowGC(w)
Widget w;
{
ScrollbarWidget sbw = (ScrollbarWidget) w;
XtGCMask valuemask;
XGCValues myXGCV;
valuemask = GCForeground;
myXGCV.foreground = sbw->scrollbar.top_shadow_pixel;
sbw->scrollbar.top_shadow_GC = XtGetGC(w, valuemask, &myXGCV);
}
static void
AllocBotShadowGC(w)
Widget w;
{
ScrollbarWidget sbw = (ScrollbarWidget) w;
XtGCMask valuemask;
XGCValues myXGCV;
valuemask = GCForeground;
myXGCV.foreground = sbw->scrollbar.bot_shadow_pixel;
sbw->scrollbar.bot_shadow_GC = XtGetGC(w, valuemask, &myXGCV);
}
static void
_Xaw3dDrawShadows(gw, event, region, out)
Widget gw;
XEvent *event UNUSED;
Region region;
int out;
{
XPoint pt[6];
ScrollbarWidget sbw = (ScrollbarWidget) gw;
Dimension s = sbw->scrollbar.shadow_width;
/*
* draw the shadows using the core part width and height,
* and the scrollbar part shadow_width.
*
* no point to do anything if the shadow_width is 0 or the
* widget has not been realized.
*/
if (s > 0 && XtIsRealized(gw))
{
Dimension h = sbw->core.height;
Dimension w = sbw->core.width;
Dimension wms = w - s;
Dimension hms = h - s;
Display *dpy = XtDisplay (gw);
Window win = XtWindow (gw);
GC top, bot;
if (out)
{
top = sbw->scrollbar.top_shadow_GC;
bot = sbw->scrollbar.bot_shadow_GC;
}
else
{
top = sbw->scrollbar.bot_shadow_GC;
bot = sbw->scrollbar.top_shadow_GC;
}
/* top-left shadow */
if ((region == NULL) ||
(XRectInRegion (region, 0, 0, w, s) != RectangleOut) ||
(XRectInRegion (region, 0, 0, s, h) != RectangleOut))
{
pt[0].x = 0; pt[0].y = h;
pt[1].x = pt[1].y = 0;
pt[2].x = w; pt[2].y = 0;
pt[3].x = wms; pt[3].y = s;
pt[4].x = pt[4].y = s;
pt[5].x = s; pt[5].y = hms;
XFillPolygon (dpy, win, top, pt, 6, Complex, CoordModeOrigin);
}
/* bottom-right shadow */
if ((region == NULL) ||
(XRectInRegion (region, 0, hms, w, s) != RectangleOut) ||
(XRectInRegion (region, wms, 0, s, h) != RectangleOut))
{
pt[0].x = 0; pt[0].y = h;
pt[1].x = w; pt[1].y = h;
pt[2].x = w; pt[2].y = 0;
pt[3].x = wms; pt[3].y = s;
pt[4].x = wms; pt[4].y = hms;
pt[5].x = s; pt[5].y = hms;
XFillPolygon (dpy, win, bot, pt, 6, Complex, CoordModeOrigin);
}
}
}
/*
* Set the scroll bar to the given location.
*/
void
vim_XawScrollbarSetThumb(w, top, shown, max)
Widget w;
double top, shown, max;
{
ScrollbarWidget sbw = (ScrollbarWidget) w;
if (sbw->scrollbar.scroll_mode == SMODE_CONT) /* if still thumbing */
return;
sbw->scrollbar.max = (max > 1.0) ? 1.0 :
(max >= 0.0) ? max : sbw->scrollbar.max;
sbw->scrollbar.top = (top > sbw->scrollbar.max) ? sbw->scrollbar.max :
(top >= 0.0) ? top : sbw->scrollbar.top;
sbw->scrollbar.shown = (shown > 1.0) ? 1.0 :
(shown >= 0.0) ? shown : sbw->scrollbar.shown;
PaintThumb(sbw);
}
| zyz2011-vim | src/gui_at_sb.c | C | gpl2 | 33,918 |
#! /bin/sh
#
# link.sh -- try linking Vim with different sets of libraries, finding the
# minimal set for fastest startup. The problem is that configure adds a few
# libraries when they exist, but this doesn't mean they are needed for Vim.
#
# Author: Bram Moolenaar
# Last change: 2010 Nov 03
# License: Public domain
#
# Warning: This fails miserably if the linker doesn't return an error code!
#
# Otherwise this script is fail-safe, falling back to the original full link
# command if anything fails.
echo "$LINK " >link.cmd
exit_value=0
if test "$LINK_AS_NEEDED" = yes; then
echo "link.sh: \$LINK_AS_NEEDED set to 'yes': invoking linker directly."
cat link.cmd
if sh link.cmd; then
exit_value=0
echo "link.sh: Linked fine"
else
exit_value=$?
echo "link.sh: Linking failed"
fi
else
if test -f auto/link.sed; then
#
# If auto/link.sed already exists, use it. We assume a previous run of
# link.sh has found the correct set of libraries.
#
echo "link.sh: The file 'auto/link.sed' exists, which is going to be used now."
echo "link.sh: If linking fails, try deleting the auto/link.sed file."
echo "link.sh: If this fails too, try creating an empty auto/link.sed file."
else
# If linking works with the full link command, try removing some libraries,
# that are known not to be needed on at least one system.
# Remove auto/pathdef.c if there is a new link command and compile it again.
# There is a loop to remove libraries that appear several times.
#
# Notes:
# - Can't remove Xext; It links fine but will give an error when running gvim
# with Motif.
# - Don't remove the last -lm: On HP-UX Vim links OK but crashes when the GTK
# GUI is started, because the "floor" symbol could not be resolved.
#
cat link.cmd
if sh link.cmd; then
touch auto/link.sed
cp link.cmd linkit.sh
for libname in SM ICE nsl dnet dnet_stub inet socket dir elf iconv Xt Xmu Xp Xpm X11 Xdmcp x w perl dl pthread thread readline m crypt attr; do
cont=yes
while test -n "$cont"; do
if grep "l$libname " linkit.sh >/dev/null; then
if test ! -f link1.sed; then
echo "link.sh: OK, linking works, let's try omitting a few libraries."
echo "link.sh: See auto/link.log for details."
rm -f auto/link.log
fi
echo "s/-l$libname *//" >link1.sed
sed -f auto/link.sed <link.cmd >linkit2.sh
sed -f link1.sed <linkit2.sh >linkit.sh
# keep the last -lm
if test $libname != "m" || grep "lm " linkit.sh >/dev/null; then
echo "link.sh: Trying to omit the $libname library..."
cat linkit.sh >>auto/link.log
# Redirect this link output, it may contain error messages which
# should be ignored.
if sh linkit.sh >>auto/link.log 2>&1; then
echo "link.sh: Vim doesn't need the $libname library!"
cat link1.sed >>auto/link.sed
rm -f auto/pathdef.c
else
echo "link.sh: Vim DOES need the $libname library."
cont=
cp link.cmd linkit.sh
fi
else
cont=
cp link.cmd linkit.sh
fi
else
cont=
cp link.cmd linkit.sh
fi
done
done
if test ! -f auto/pathdef.c; then
$MAKE objects/pathdef.o
fi
if test ! -f link1.sed; then
echo "link.sh: Linked fine, no libraries can be omitted"
touch link3.sed
fi
else
exit_value=$?
fi
fi
#
# Now do the real linking.
#
if test -s auto/link.sed; then
echo "link.sh: Using auto/link.sed file to omit a few libraries"
sed -f auto/link.sed <link.cmd >linkit.sh
cat linkit.sh
if sh linkit.sh; then
exit_value=0
echo "link.sh: Linked fine with a few libraries omitted"
else
exit_value=$?
echo "link.sh: Linking failed, making auto/link.sed empty and trying again"
mv -f auto/link.sed link2.sed
touch auto/link.sed
rm -f auto/pathdef.c
$MAKE objects/pathdef.o
fi
fi
if test -f auto/link.sed -a ! -s auto/link.sed -a ! -f link3.sed; then
echo "link.sh: Using unmodified link command"
cat link.cmd
if sh link.cmd; then
exit_value=0
echo "link.sh: Linked OK"
else
exit_value=$?
if test -f link2.sed; then
echo "link.sh: Linking doesn't work at all, removing auto/link.sed"
rm -f auto/link.sed
fi
fi
fi
fi
#
# cleanup
#
rm -f link.cmd linkit.sh link1.sed link2.sed link3.sed linkit2.sh
#
# return an error code if something went wrong
#
exit $exit_value
# vim:set sw=2 et:
| zyz2011-vim | src/link.sh | Shell | gpl2 | 4,620 |
#
# Makefile for VIM, using MorphOS SDK (gcc 2.95.3)
#
CFLAGS = -c \
-pipe \
-O2 \
-Wall \
\
-DNO_ARP \
-DUSE_TMPNAM \
\
-I proto \
\
-noixemul
PRG = Vim
LIBS = -noixemul -s
CC = gcc
LD = gcc
OBJDUMP = objdump
RM = rm
.c.o:
${CC} ${CFLAGS} $< -o $@
SRC = blowfish.c \
buffer.c \
charset.c \
diff.c \
digraph.c \
edit.c \
eval.c \
ex_cmds.c \
ex_cmds2.c \
ex_docmd.c \
ex_eval.c \
ex_getln.c \
fileio.c \
fold.c \
getchar.c \
hardcopy.c \
hashtab.c \
main.c \
mark.c \
mbyte.c \
memfile.c \
memline.c \
menu.c \
message.c \
misc1.c \
misc2.c \
move.c \
normal.c \
ops.c \
option.c \
os_amiga.c \
popupmnu.c \
quickfix.c \
regexp.c \
screen.c \
search.c \
sha256.c \
spell.c \
syntax.c \
tag.c \
term.c \
ui.c \
undo.c \
version.c \
window.c \
OBJ = $(SRC:.c=.o)
$(PRG): $(OBJ)
${LD} -o $(PRG) $(OBJ) $(LIBS)
dump: $(PRG)
$(OBJDUMP) --reloc --disassemble-all $(PRG) > $(PRG).s
clean:
$(RM) -fv $(OBJ) $(PRG) $(PRG).s
| zyz2011-vim | src/Make_morph.mak | Makefile | gpl2 | 1,288 |
#
# Makefile for Vim on OpenVMS
#
# Maintainer: Zoltan Arpadffy <arpadffy@polarhome.com>
# Last change: 2008 Aug 16
#
# This has script been tested on VMS 6.2 to 8.2 on DEC Alpha, VAX and IA64
# with MMS and MMK
#
# The following could be built:
# vim.exe: standard (terminal, GUI/Motif, GUI/GTK)
# dvim.exe: debug
#
# Edit the lines in the Configuration section below for fine tuning.
#
# To build: mms/descrip=Make_vms.mms /ignore=warning
# To clean up: mms/descrip=Make_vms.mms clean
#
# Hints and detailed description could be found in INSTALLVMS.TXT file.
#
######################################################################
# Configuration section.
######################################################################
# VMS version
# Uncomment if you use VMS version 6.2 or older
# OLD_VMS = YES
# Compiler selection.
# Comment out if you use the VAXC compiler
DECC = YES
# Build model selection
# TINY - Almost no features enabled, not even multiple windows
# SMALL - Few features enabled, as basic as possible
# NORMAL - A default selection of features enabled
# BIG - Many features enabled, as rich as possible. (default)
# HUGE - All possible featues enabled.
# Please select one of these alternatives above.
MODEL = HUGE
# GUI or terminal mode executable.
# Comment out if you want just the character terminal mode only.
# GUI with Motif
# GUI = YES
# GUI with GTK
# If you have GTK installed you might want to enable this option.
# NOTE: you will need to properly define GTK_DIR below
# GTK = YES
# GUI/Motif with XPM
# If you have XPM installed you might want to build Motif version with toolbar
# XPM = YES
# Comment out if you want the compiler version with :ver command.
# NOTE: This part can make some complications if you're using some
# predefined symbols/flags for your compiler. If does, just leave behind
# the comment varialbe CCVER.
CCVER = YES
# Uncomment if want a debug version. Resulting executable is DVIM.EXE
# Development purpose only! Normally, it should not be defined. !!!
# DEBUG = YES
# Languages support for Perl, Python, TCL etc.
# If you don't need it really, leave them behind the comment.
# You will need related libraries, include files etc.
# VIM_TCL = YES
# VIM_PERL = YES
# VIM_PYTHON = YES
# VIM_RUBY = YES
# VIM_SNIFF = YES
# X Input Method. For entering special languages like chinese and
# Japanese. Please define just one: VIM_XIM or VIM_HANGULIN
# If you don't need it really, leave it behind the comment.
# VIM_XIM = YES
# Internal Hangul input method. GUI only.
# If you don't need it really, leave it behind the comment.
# VIM_HANGULIN = YES
# Allow any white space to separate the fields in a tags file
# When not defined, only a TAB is allowed.
# VIM_TAG_ANYWHITE = YES
# Allow FEATURE_MZSCHEME
# VIM_MZSCHEME = YES
######################################################################
# Directory, library and include files configuration section.
# Normally you need not to change anything below. !
# These may need to be defined if things are not in standard locations
#
# You can find some explanation in INSTALLVMS.TXT
######################################################################
# Compiler setup
.IFDEF MMSVAX
.IFDEF DECC # VAX with DECC
CC_DEF = cc # /decc # some system requires this switch but when it is not required /ver might fail
PREFIX = /prefix=all
.ELSE # VAX with VAXC
CC_DEF = cc
PREFIX =
CCVER =
.ENDIF
.ELSE # AXP wixh DECC
CC_DEF = cc
PREFIX = /prefix=all
.ENDIF
LD_DEF = link
C_INC = [.proto]
.IFDEF OLD_VMS
VMS_DEF = ,"OLD_VMS"
.ENDIF
.IFDEF DEBUG
DEBUG_DEF = ,"DEBUG"
TARGET = dvim.exe
CFLAGS = /debug/noopt$(PREFIX)
LDFLAGS = /debug
.ELSE
TARGET = vim.exe
CFLAGS = /opt$(PREFIX)
LDFLAGS =
.ENDIF
# Predefined VIM directories
# Please, use $VIM and $VIMRUNTIME logicals instead
VIMLOC = ""
VIMRUN = ""
CONFIG_H = os_vms_conf.h
# GTK or XPM but not both
.IFDEF GTK
.IFDEF GUI
.ELSE
GUI = YES
.ENDIF
.IFDEF XPM
XPM = ""
.ENDIF
.ENDIF
.IFDEF XPM
.IFDEF GUI
.ELSE
GUI = YES
.ENDIF
.IFDEF GTK
GTK = ""
.ENDIF
.ENDIF
.IFDEF GUI
# X/Motif/GTK executable (also works in terminal mode )
.IFDEF GTK
# NOTE: you need to set up your GTK_DIR (GTK root directory), because it is
# unique on every system - logicals are not accepted
# please note: directory should end with . in order to /trans=conc work
# This value for GTK_DIR is an example.
GTK_DIR = $1$DGA104:[USERS.ZAY.WORK.GTK1210.]
DEFS = "HAVE_CONFIG_H","FEAT_GUI_GTK"
LIBS = ,OS_VMS_GTK.OPT/OPT
GUI_FLAG = /name=(as_is,short)/float=ieee/ieee=denorm
GUI_SRC = gui.c gui_gtk.c gui_gtk_f.c gui_gtk_x11.c gui_beval.c pty.c
GUI_OBJ = gui.obj gui_gtk.obj gui_gtk_f.obj gui_gtk_x11.obj gui_beval.obj pty.obj
GUI_INC = ,"/gtk_root/gtk","/gtk_root/glib"
# GUI_INC_VER is used just for :ver information
# this string should escape from C and DCL in the same time
GUI_INC_VER= ,\""/gtk_root/gtk\"",\""/gtk_root/glib\""
.ELSE
MOTIF = YES
.IFDEF XPM
DEFS = "HAVE_CONFIG_H","FEAT_GUI_MOTIF","HAVE_XPM"
.ELSE
DEFS = "HAVE_CONFIG_H","FEAT_GUI_MOTIF"
.ENDIF
LIBS = ,OS_VMS_MOTIF.OPT/OPT
GUI_FLAG =
GUI_SRC = gui.c gui_motif.c gui_x11.c gui_beval.c gui_xmdlg.c gui_xmebw.c
GUI_OBJ = gui.obj gui_motif.obj gui_x11.obj gui_beval.obj gui_xmdlg.obj gui_xmebw.obj
GUI_INC =
.ENDIF
# You need to define these variables if you do not have DECW files
# at standard location
GUI_INC_DIR = ,decw$include:
# GUI_LIB_DIR = ,sys$library:
.ELSE
# Character terminal only executable
DEFS = "HAVE_CONFIG_H"
LIBS =
.ENDIF
.IFDEF VIM_PERL
# Perl related setup.
PERL = perl
PERL_DEF = ,"FEAT_PERL"
PERL_SRC = if_perlsfio.c if_perl.xs
PERL_OBJ = if_perlsfio.obj if_perl.obj
PERL_LIB = ,OS_VMS_PERL.OPT/OPT
PERL_INC = ,dka0:[perlbuild.perl.lib.vms_axp.5_6_1.core]
.ENDIF
.IFDEF VIM_PYTHON
# Python related setup.
PYTHON_DEF = ,"FEAT_PYTHON"
PYTHON_SRC = if_python.c
PYTHON_OBJ = if_python.obj
PYTHON_LIB = ,OS_VMS_PYTHON.OPT/OPT
PYTHON_INC = ,PYTHON_INCLUDE
.ENDIF
.IFDEF VIM_TCL
# TCL related setup.
TCL_DEF = ,"FEAT_TCL"
TCL_SRC = if_tcl.c
TCL_OBJ = if_tcl.obj
TCL_LIB = ,OS_VMS_TCL.OPT/OPT
TCL_INC = ,dka0:[tcl80.generic]
.ENDIF
.IFDEF VIM_SNIFF
# SNIFF related setup.
SNIFF_DEF = ,"FEAT_SNIFF"
SNIFF_SRC = if_sniff.c
SNIFF_OBJ = if_sniff.obj
SNIFF_LIB =
SNIFF_INC =
.ENDIF
.IFDEF VIM_RUBY
# RUBY related setup.
RUBY_DEF = ,"FEAT_RUBY"
RUBY_SRC = if_ruby.c
RUBY_OBJ = if_ruby.obj
RUBY_LIB = ,OS_VMS_RUBY.OPT/OPT
RUBY_INC =
.ENDIF
.IFDEF VIM_XIM
# XIM related setup.
.IFDEF GUI
XIM_DEF = ,"FEAT_XIM"
.ENDIF
.ENDIF
.IFDEF VIM_HANGULIN
# HANGULIN related setup.
.IFDEF GUI
HANGULIN_DEF = ,"FEAT_HANGULIN"
HANGULIN_SRC = hangulin.c
HANGULIN_OBJ = hangulin.obj
.ENDIF
.ENDIF
.IFDEF VIM_TAG_ANYWHITE
# TAG_ANYWHITE related setup.
TAG_DEF = ,"FEAT_TAG_ANYWHITE"
.ENDIF
.IFDEF VIM_MZSCHEME
# MZSCHEME related setup
MZSCH_DEF = ,"FEAT_MZSCHEME"
MZSCH_SRC = if_mzsch.c
MZSCH_OBJ = if_mzsch.obj
.ENDIF
######################################################################
# End of configuration section.
# Please, do not change anything below without programming experience.
######################################################################
MODEL_DEF = "FEAT_$(MODEL)",
# These go into pathdef.c
VIMUSER = "''F$EDIT(F$GETJPI(" ","USERNAME"),"TRIM")'"
VIMHOST = "''F$TRNLNM("SYS$NODE")'''F$TRNLNM("UCX$INET_HOST")'.''F$TRNLNM("UCX$INET_DOMAIN")'"
.SUFFIXES : .obj .c
ALL_CFLAGS = /def=($(MODEL_DEF)$(DEFS)$(VMS_DEF)$(DEBUG_DEF)$(PERL_DEF)$(PYTHON_DEF) -
$(TCL_DEF)$(SNIFF_DEF)$(RUBY_DEF)$(XIM_DEF)$(HANGULIN_DEF)$(TAG_DEF)$(MZSCH_DEF)) -
$(CFLAGS)$(GUI_FLAG) -
/include=($(C_INC)$(GUI_INC_DIR)$(GUI_INC)$(PERL_INC)$(PYTHON_INC)$(TCL_INC))
# CFLAGS displayed in :ver information
# It is specially formated for correct display of unix like includes
# as $(GUI_INC) - replaced with $(GUI_INC_VER)
# Otherwise should not be any other difference.
ALL_CFLAGS_VER = /def=($(MODEL_DEF)$(DEFS)$(VMS_DEF)$(DEBUG_DEF)$(PERL_DEF)$(PYTHON_DEF) -
$(TCL_DEF)$(SNIFF_DEF)$(RUBY_DEF)$(XIM_DEF)$(HANGULIN_DEF)$(TAG_DEF)$(MZSCH_DEF)) -
$(CFLAGS)$(GUI_FLAG) -
/include=($(C_INC)$(GUI_INC_DIR)$(GUI_INC_VER)$(PERL_INC)$(PYTHON_INC)$(TCL_INC))
ALL_LIBS = $(LIBS) $(GUI_LIB_DIR) $(GUI_LIB) \
$(PERL_LIB) $(PYTHON_LIB) $(TCL_LIB) $(SNIFF_LIB) $(RUBY_LIB)
SRC = blowfish.c buffer.c charset.c diff.c digraph.c edit.c eval.c ex_cmds.c ex_cmds2.c \
ex_docmd.c ex_eval.c ex_getln.c if_xcmdsrv.c fileio.c fold.c getchar.c \
hardcopy.c hashtab.c main.c mark.c menu.c mbyte.c memfile.c memline.c message.c misc1.c \
misc2.c move.c normal.c ops.c option.c popupmnu.c quickfix.c regexp.c search.c sha256.c\
spell.c syntax.c tag.c term.c termlib.c ui.c undo.c version.c screen.c \
window.c os_unix.c os_vms.c pathdef.c \
$(GUI_SRC) $(PERL_SRC) $(PYTHON_SRC) $(TCL_SRC) $(SNIFF_SRC) \
$(RUBY_SRC) $(HANGULIN_SRC) $(MZSCH_SRC)
OBJ = blowfish.obj buffer.obj charset.obj diff.obj digraph.obj edit.obj eval.obj \
ex_cmds.obj ex_cmds2.obj ex_docmd.obj ex_eval.obj ex_getln.obj \
if_xcmdsrv.obj fileio.obj fold.obj getchar.obj hardcopy.obj hashtab.obj main.obj mark.obj \
menu.obj memfile.obj memline.obj message.obj misc1.obj misc2.obj \
move.obj mbyte.obj normal.obj ops.obj option.obj popupmnu.obj quickfix.obj \
regexp.obj search.obj sha256.obj spell.obj syntax.obj tag.obj term.obj termlib.obj \
ui.obj undo.obj screen.obj version.obj window.obj os_unix.obj \
os_vms.obj pathdef.obj if_mzsch.obj\
$(GUI_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(TCL_OBJ) $(SNIFF_OBJ) \
$(RUBY_OBJ) $(HANGULIN_OBJ) $(MZSCH_OBJ)
# Default target is making the executable
all : [.auto]config.h mmk_compat motif_env gtk_env perl_env python_env tcl_env ruby_env $(TARGET)
! $@
[.auto]config.h : $(CONFIG_H)
copy/nolog $(CONFIG_H) [.auto]config.h
mmk_compat :
-@ open/write pd pathdef.c
-@ write pd "/* Empty file to satisfy MMK depend. */"
-@ write pd "/* It will be overwritten later on... */"
-@ close pd
clean :
-@ if "''F$SEARCH("*.exe")'" .NES. "" then delete/noconfirm/nolog *.exe;*
-@ if "''F$SEARCH("*.obj")'" .NES. "" then delete/noconfirm/nolog *.obj;*
-@ if "''F$SEARCH("[.auto]config.h")'" .NES. "" then delete/noconfirm/nolog [.auto]config.h;*
-@ if "''F$SEARCH("pathdef.c")'" .NES. "" then delete/noconfirm/nolog pathdef.c;*
-@ if "''F$SEARCH("if_perl.c")'" .NES. "" then delete/noconfirm/nolog if_perl.c;*
-@ if "''F$SEARCH("*.opt")'" .NES. "" then delete/noconfirm/nolog *.opt;*
# Link the target
$(TARGET) : $(OBJ)
$(LD_DEF) $(LDFLAGS) /exe=$(TARGET) $+ $(ALL_LIBS)
.c.obj :
$(CC_DEF) $(ALL_CFLAGS) $<
pathdef.c : check_ccver $(CONFIG_H)
-@ write sys$output "creating PATHDEF.C file."
-@ open/write pd pathdef.c
-@ write pd "/* pathdef.c -- DO NOT EDIT! */"
-@ write pd "/* This file is automatically created by MAKE_VMS.MMS"
-@ write pd " * Change the file MAKE_VMS.MMS Only. */"
-@ write pd "typedef unsigned char char_u;"
-@ write pd "char_u *default_vim_dir = (char_u *)"$(VIMLOC)";"
-@ write pd "char_u *default_vimruntime_dir = (char_u *)"$(VIMRUN)";"
-@ write pd "char_u *all_cflags = (char_u *)""$(CC_DEF)$(ALL_CFLAGS_VER)"";"
-@ write pd "char_u *all_lflags = (char_u *)""$(LD_DEF)$(LDFLAGS) /exe=$(TARGET) *.OBJ $(ALL_LIBS)"";"
-@ write pd "char_u *compiler_version = (char_u *) ""''CC_VER'"";"
-@ write pd "char_u *compiled_user = (char_u *) "$(VIMUSER)";"
-@ write pd "char_u *compiled_sys = (char_u *) "$(VIMHOST)";"
-@ write pd "char_u *compiled_arch = (char_u *) ""$(MMSARCH_NAME)"";"
-@ close pd
if_perl.c : if_perl.xs
-@ $(PERL) PERL_ROOT:[LIB.ExtUtils]xsubpp -prototypes -typemap -
PERL_ROOT:[LIB.ExtUtils]typemap if_perl.xs >> $@
make_vms.mms :
-@ write sys$output "The name of the makefile MUST be <MAKE_VMS.MMS> !!!"
.IFDEF CCVER
# This part can make some complications if you're using some predefined
# symbols/flags for your compiler. If does, just comment out CCVER variable
check_ccver :
-@ define sys$output cc_ver.tmp
-@ $(CC_DEF)/version
-@ deassign sys$output
-@ open/read file cc_ver.tmp
-@ read file CC_VER
-@ close file
-@ delete/noconfirm/nolog cc_ver.tmp.*
.ELSE
check_ccver :
-@ !
.ENDIF
.IFDEF MOTIF
motif_env :
.IFDEF XPM
-@ write sys$output "using DECW/Motif/XPM environment."
.ELSE
-@ write sys$output "using DECW/Motif environment."
.ENDIF
-@ write sys$output "creating OS_VMS_MOTIF.OPT file."
-@ open/write opt_file OS_VMS_MOTIF.OPT
-@ write opt_file "sys$share:decw$xmlibshr12.exe/share,-"
-@ write opt_file "sys$share:decw$xtlibshrr5.exe/share,-"
-@ write opt_file "sys$share:decw$xlibshr.exe/share"
-@ close opt_file
.ELSE
motif_env :
-@ !
.ENDIF
.IFDEF GTK
gtk_env :
-@ write sys$output "using GTK environment:"
-@ define/nolog gtk_root /trans=conc $(GTK_DIR)
-@ show logical gtk_root
-@ write sys$output " include path: "$(GUI_INC)""
-@ write sys$output "creating OS_VMS_GTK.OPT file."
-@ open/write opt_file OS_VMS_GTK.OPT
-@ write opt_file "gtk_root:[glib]libglib.exe /share,-"
-@ write opt_file "gtk_root:[glib.gmodule]libgmodule.exe /share,-"
-@ write opt_file "gtk_root:[gtk.gdk]libgdk.exe /share,-"
-@ write opt_file "gtk_root:[gtk.gtk]libgtk.exe /share,-"
-@ write opt_file "sys$share:decw$xmlibshr12.exe/share,-"
-@ write opt_file "sys$share:decw$xtlibshrr5.exe/share,-"
-@ write opt_file "sys$share:decw$xlibshr.exe/share"
-@ close opt_file
.ELSE
gtk_env :
-@ !
.ENDIF
.IFDEF VIM_PERL
perl_env :
-@ write sys$output "using PERL environment:"
-@ show logical PERLSHR
-@ write sys$output " include path: ""$(PERL_INC)"""
-@ show symbol perl
-@ open/write pd if_perl.c
-@ write pd "/* Empty file to satisfy MMK depend. */"
-@ write pd "/* It will be overwritten later on... */"
-@ close pd
-@ write sys$output "creating OS_VMS_PERL.OPT file."
-@ open/write opt_file OS_VMS_PERL.OPT
-@ write opt_file "PERLSHR /share"
-@ close opt_file
.ELSE
perl_env :
-@ !
.ENDIF
.IFDEF VIM_PYTHON
python_env :
-@ write sys$output "using PYTHON environment:"
-@ show logical PYTHON_INCLUDE
-@ show logical PYTHON_OLB
-@ write sys$output "creating OS_VMS_PYTHON.OPT file."
-@ open/write opt_file OS_VMS_PYTHON.OPT
-@ write opt_file "PYTHON_OLB:PYTHON.OLB /share"
-@ close opt_file
.ELSE
python_env :
-@ !
.ENDIF
.IFDEF VIM_TCL
tcl_env :
-@ write sys$output "using TCL environment:"
-@ show logical TCLSHR
-@ write sys$output " include path: ""$(TCL_INC)"""
-@ write sys$output "creating OS_VMS_TCL.OPT file."
-@ open/write opt_file OS_VMS_TCL.OPT
-@ write opt_file "TCLSHR /share"
-@ close opt_file
.ELSE
tcl_env :
-@ !
.ENDIF
.IFDEF VIM_RUBY
ruby_env :
-@ write sys$output "using RUBY environment:"
-@ write sys$output " include path: ""$(RUBY_INC)"""
-@ write sys$output "creating OS_VMS_RUBY.OPT file."
-@ open/write opt_file OS_VMS_RUBY.OPT
-@ write opt_file "RUBYSHR /share"
-@ close opt_file
.ELSE
ruby_env :
-@ !
.ENDIF
buffer.obj : buffer.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
charset.obj : charset.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
diff.obj : diff.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
digraph.obj : digraph.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
edit.obj : edit.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
eval.obj : eval.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h version.h
ex_cmds.obj : ex_cmds.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
ex_cmds2.obj : ex_cmds2.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
ex_docmd.obj : ex_docmd.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
ex_eval.obj : ex_eval.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
ex_getln.obj : ex_getln.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
fileio.obj : fileio.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
fold.obj : fold.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
getchar.obj : getchar.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
hardcopy.obj : hardcopy.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
hashtab.obj : hashtab.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
if_cscope.obj : if_cscope.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h if_cscope.h
if_xcmdsrv.obj : if_xcmdsrv.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
if_mzsch.obj : if_mzsch.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h [.proto]gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h if_mzsch.h
main.obj : main.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h farsi.c arabic.c
mark.obj : mark.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
memfile.obj : memfile.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
memline.obj : memline.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
menu.obj : menu.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
message.obj : message.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
misc1.obj : misc1.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h version.h
misc2.obj : misc2.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
move.obj : move.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
mbyte.obj : mbyte.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
normal.obj : normal.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
ops.obj : ops.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
option.obj : option.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
os_unix.obj : os_unix.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h os_unixx.h
os_vms.obj : os_vms.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h os_unixx.h
pathdef.obj : pathdef.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
popupmnu.obj : popupmnu.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
quickfix.obj : quickfix.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
regexp.obj : regexp.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
screen.obj : screen.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
search.obj : search.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
spell.obj : spell.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
syntax.obj : syntax.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
tag.obj : tag.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
term.obj : term.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
termlib.obj : termlib.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
ui.obj : ui.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
undo.obj : undo.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
version.obj : version.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
window.obj : window.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
gui.obj : gui.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
gui_gtk.obj : gui_gtk.c gui_gtk_f.h vim.h [.auto]config.h feature.h \
os_unix.h ascii.h keymap.h term.h macros.h structs.h \
regexp.h gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h \
proto.h globals.h farsi.h arabic.h [-.pixmaps]stock_icons.h
gui_gtk_f.obj : gui_gtk_f.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_gtk_f.h
gui_motif.obj : gui_motif.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h [-.pixmaps]alert.xpm [-.pixmaps]error.xpm \
[-.pixmaps]generic.xpm [-.pixmaps]info.xpm [-.pixmaps]quest.xpm
gui_athena.obj : gui_athena.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_at_sb.h
gui_gtk_x11.obj : gui_gtk_x11.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_gtk_f.h [-.runtime]vim32x32.xpm \
[-.runtime]vim16x16.xpm [-.runtime]vim48x48.xpm
gui_x11.obj : gui_x11.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h [-.runtime]vim32x32.xpm \
[-.runtime]vim16x16.xpm [-.runtime]vim48x48.xpm [-.pixmaps]tb_new.xpm \
[-.pixmaps]tb_open.xpm [-.pixmaps]tb_close.xpm [-.pixmaps]tb_save.xpm \
[-.pixmaps]tb_print.xpm [-.pixmaps]tb_cut.xpm [-.pixmaps]tb_copy.xpm \
[-.pixmaps]tb_paste.xpm [-.pixmaps]tb_find.xpm \
[-.pixmaps]tb_find_next.xpm [-.pixmaps]tb_find_prev.xpm \
[-.pixmaps]tb_find_help.xpm [-.pixmaps]tb_exit.xpm \
[-.pixmaps]tb_undo.xpm [-.pixmaps]tb_redo.xpm [-.pixmaps]tb_help.xpm \
[-.pixmaps]tb_macro.xpm [-.pixmaps]tb_make.xpm \
[-.pixmaps]tb_save_all.xpm [-.pixmaps]tb_jump.xpm \
[-.pixmaps]tb_ctags.xpm [-.pixmaps]tb_load_session.xpm \
[-.pixmaps]tb_save_session.xpm [-.pixmaps]tb_new_session.xpm \
[-.pixmaps]tb_blank.xpm [-.pixmaps]tb_maximize.xpm \
[-.pixmaps]tb_split.xpm [-.pixmaps]tb_minimize.xpm \
[-.pixmaps]tb_shell.xpm [-.pixmaps]tb_replace.xpm \
[-.pixmaps]tb_vsplit.xpm [-.pixmaps]tb_maxwidth.xpm \
[-.pixmaps]tb_minwidth.xpm
gui_at_sb.obj : gui_at_sb.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_at_sb.h
gui_at_fs.obj : gui_at_fs.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_at_sb.h
pty.obj : pty.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
arabic.h
hangulin.obj : hangulin.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
if_perl.obj : [.auto]if_perl.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
if_perlsfio.obj : if_perlsfio.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
if_python.obj : if_python.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
if_tcl.obj : if_tcl.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
if_ruby.obj : if_ruby.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
if_sniff.obj : if_sniff.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h os_unixx.h
gui_beval.obj : gui_beval.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h
workshop.obj : workshop.c [.auto]config.h integration.h vim.h feature.h \
os_unix.h ascii.h keymap.h term.h macros.h structs.h \
regexp.h gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h \
proto.h globals.h farsi.h arabic.h version.h workshop.h
wsdebug.obj : wsdebug.c
integration.obj : integration.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h integration.h
netbeans.obj : netbeans.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
gui_xmdlg.obj : gui_xmdlg.c
gui_xmebw.obj : gui_xmebw.c
| zyz2011-vim | src/Make_vms.mms | Module Management System | gpl2 | 31,798 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
* BeBox port Copyright 1997 by Olaf Seibert.
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* os_beos.c Additional stuff for BeOS (rest is in os_unix.c)
*/
#include <float.h>
#include <termios.h>
#include <kernel/OS.h>
#include "vim.h"
#if USE_THREAD_FOR_INPUT_WITH_TIMEOUT
#ifdef PROTO /* making prototypes on Unix */
#define sem_id int
#define thread_id int
#endif
char_u charbuf;
signed char charcount;
sem_id character_present;
sem_id character_wanted;
thread_id read_thread_id;
#define TRY_ABORT 0 /* This code does not work so turn it off. */
#if TRY_ABORT
static void
mostly_ignore(int sig)
{
}
#endif
static long
read_thread(void *dummy)
{
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
#if TRY_ABORT
signal(SIGUSR1, mostly_ignore);
#endif
for (;;) {
if (acquire_sem(character_wanted) != B_NO_ERROR)
break;
charcount = read(read_cmd_fd, &charbuf, 1);
release_sem(character_present);
}
return 0;
}
void
beos_cleanup_read_thread(void)
{
if (character_present > 0)
delete_sem(character_present);
character_present = 0;
if (read_thread_id > 0)
kill_thread(read_thread_id);
read_thread_id = 0;
}
#endif
/*
* select() emulation. Hopefully, in DR9 there will be something
* useful supplied by the system. ... Alas, not. Not in AAPR, nor
* in PR or even PR2... R3 then maybe? I don't think so!
*/
int
beos_select(int nbits,
struct fd_set *rbits,
struct fd_set *wbits,
struct fd_set *ebits,
struct timeval *timeout)
{
bigtime_t tmo;
if (nbits == 0) {
/* select is purely being used for delay */
snooze(timeout->tv_sec * 1e6 + timeout->tv_usec);
return 0;
}
#if 0
/*
* This does not seem to work either. Reads here are not supposed to
* block indefinitely, yet they do. This is most annoying.
*/
if (FD_ISSET(0, rbits)) {
char cbuf[1];
int count;
struct termios told;
struct termios tnew;
tcgetattr(0, &told);
tnew = told;
tnew.c_lflag &= ~ICANON;
tnew.c_cc[VMIN] = 0;
tnew.c_cc[VTIME] = timeout->tv_sec * 10 + timeout->tv_usec / 100000;
tcsetattr(0, TCSANOW, &tnew);
count = read(0, &cbuf, sizeof(cbuf));
tcsetattr(0, TCSANOW, &told);
if (count > 0) {
add_to_input_buf(&cbuf[0], count);
return 1;
}
return 0;
}
#endif
#if USE_THREAD_FOR_INPUT_WITH_TIMEOUT
/*
* Check if the operation is really on stdin...
*/
if (FD_ISSET(read_cmd_fd, rbits))
{
int acquired;
/*
* Is this the first time through?
* Then start up the thread and initialise the semaphores.
*/
if (character_present == 0) {
character_present = create_sem(0, "vim character_present");
character_wanted = create_sem(1, "vim character_wanted");
read_thread_id = spawn_thread(read_thread, "vim async read",
B_NORMAL_PRIORITY, NULL);
atexit(beos_cleanup_read_thread);
resume_thread(read_thread_id);
}
/* timeout == NULL means "indefinitely" */
if (timeout) {
tmo = timeout->tv_sec * 1e6 + timeout->tv_usec;
/* 0 means "don't wait, which is impossible to do exactly. */
if (tmo == 0)
tmo = 1.0;
}
#if TRY_ABORT
release_sem(character_wanted);
#endif
if (timeout)
acquired = acquire_sem_etc(character_present, 1, B_TIMEOUT, tmo);
else
acquired = acquire_sem(character_present);
if (acquired == B_NO_ERROR) {
if (charcount > 0) {
add_to_input_buf(&charbuf, 1);
#if !TRY_ABORT
release_sem(character_wanted);
#endif
return 1;
} else {
#if !TRY_ABORT
release_sem(character_wanted);
#endif
return 0;
}
}
#if TRY_ABORT
else {
/*
* Timeout occurred. Break the read() call by sending
* a signal. Problem: it may be just read()ing it now.
* Therefore we still have to finish the handshake with
* the thread and maybe remember the character.
*/
kill(read_thread_id, SIGUSR1);
/*
* If some other error occurred, don't hang now.
* (We will most likely hang later anyway...)
*/
if (acquired == B_TIMED_OUT)
acquire_sem(character_present);
if (charcount > 0) {
add_to_input_buf(&charbuf, 1);
return 1;
}
return 0;
}
#endif
}
#endif
return 0;
}
| zyz2011-vim | src/os_beos.c | C | gpl2 | 4,433 |
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
* VMS port by Henk Elbers
* VMS deport by Zoltan Arpadffy
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
#include "vim.h"
typedef struct
{
char class;
char type;
short width;
union
{
struct
{
char _basic[3];
char length;
} y;
int basic;
} x;
int extended;
} TT_MODE;
typedef struct
{
short buflen;
short itemcode;
char *bufadrs;
int *retlen;
} ITEM;
typedef struct
{
ITEM equ;
int nul;
} ITMLST1;
typedef struct
{
ITEM index;
ITEM string;
int nul;
} ITMLST2;
static TT_MODE orgmode;
static short iochan; /* TTY I/O channel */
static short iosb[4]; /* IO status block */
static int vms_match_num = 0;
static int vms_match_free = 0;
static char_u **vms_fmatch = NULL;
static char *Fspec_Rms; /* rms file spec, passed implicitly between routines */
static TT_MODE get_tty __ARGS((void));
static void set_tty __ARGS((int row, int col));
#define EXPL_ALLOC_INC 64
#define EQN(S1,S2,LN) (strncmp(S1,S2,LN) == 0)
#define SKIP_FOLLOWING_SLASHES(Str) while (Str[1] == '/') ++Str
/*
* vul_desc vult een descriptor met een string en de lengte
* hier van.
*/
static void
vul_desc(DESC *des, char *str)
{
des->dsc$b_dtype = DSC$K_DTYPE_T;
des->dsc$b_class = DSC$K_CLASS_S;
des->dsc$a_pointer = str;
des->dsc$w_length = str ? strlen(str) : 0;
}
/*
* vul_item vult een item met een aantal waarden
*/
static void
vul_item(ITEM *itm, short len, short cod, char *adr, int *ret)
{
itm->buflen = len;
itm->itemcode = cod;
itm->bufadrs = adr;
itm->retlen = ret;
}
void
mch_settmode(int tmode)
{
int status;
if ( tmode == TMODE_RAW )
set_tty(0, 0);
else{
switch (orgmode.width)
{
case 132: OUT_STR_NF((char_u *)"\033[?3h\033>"); break;
case 80: OUT_STR_NF((char_u *)"\033[?3l\033>"); break;
default: break;
}
out_flush();
status = sys$qiow(0, iochan, IO$_SETMODE, iosb, 0, 0,
&orgmode, sizeof(TT_MODE), 0,0,0,0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
return;
(void)sys$dassgn(iochan);
iochan = 0;
}
}
static void
set_tty(int row, int col)
{
int status;
TT_MODE newmode; /* New TTY mode bits */
static short first_time = TRUE;
if (first_time)
{
orgmode = get_tty();
first_time = FALSE;
}
newmode = get_tty();
if (col)
newmode.width = col;
if (row)
newmode.x.y.length = row;
newmode.x.basic |= (TT$M_NOECHO | TT$M_HOSTSYNC);
newmode.x.basic &= ~TT$M_TTSYNC;
newmode.extended |= TT2$M_PASTHRU;
status = sys$qiow(0, iochan, IO$_SETMODE, iosb, 0, 0,
&newmode, sizeof(newmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
return;
}
static TT_MODE
get_tty(void)
{
static $DESCRIPTOR(odsc,"SYS$OUTPUT"); /* output descriptor */
int status;
TT_MODE tt_mode;
if (!iochan)
status = sys$assign(&odsc,&iochan,0,0);
status = sys$qiow(0, iochan, IO$_SENSEMODE, iosb, 0, 0,
&tt_mode, sizeof(tt_mode), 0, 0, 0, 0);
if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
{
tt_mode.width = 0;
tt_mode.type = 0;
tt_mode.class = 0;
tt_mode.x.basic = 0;
tt_mode.x.y.length = 0;
tt_mode.extended = 0;
}
return(tt_mode);
}
/*
* Get the current window size in Rows and Columns.
*/
int
mch_get_shellsize(void)
{
TT_MODE tmode;
tmode = get_tty(); /* get size from VMS */
Columns = tmode.width;
Rows = tmode.x.y.length;
return OK;
}
/*
* Try to set the window size to Rows and new_Columns.
*/
void
mch_set_shellsize(void)
{
set_tty(Rows, Columns);
switch (Columns)
{
case 132: OUT_STR_NF((char_u *)"\033[?3h\033>"); break;
case 80: OUT_STR_NF((char_u *)"\033[?3l\033>"); break;
default: break;
}
out_flush();
screen_start();
}
char_u *
mch_getenv(char_u *lognam)
{
DESC d_file_dev, d_lognam ;
static char buffer[LNM$C_NAMLENGTH+1];
char_u *cp = NULL;
unsigned long attrib;
int lengte = 0, dum = 0, idx = 0;
ITMLST2 itmlst;
char *sbuf = NULL;
vul_desc(&d_lognam, (char *)lognam);
vul_desc(&d_file_dev, "LNM$FILE_DEV");
attrib = LNM$M_CASE_BLIND;
vul_item(&itmlst.index, sizeof(int), LNM$_INDEX, (char *)&idx, &dum);
vul_item(&itmlst.string, LNM$C_NAMLENGTH, LNM$_STRING, buffer, &lengte);
itmlst.nul = 0;
if (sys$trnlnm(&attrib, &d_file_dev, &d_lognam, NULL,&itmlst) == SS$_NORMAL)
{
buffer[lengte] = '\0';
if (cp = (char_u *)alloc((unsigned)(lengte+1)))
strcpy((char *)cp, buffer);
return(cp);
}
else if ((sbuf = getenv((char *)lognam)))
{
lengte = strlen(sbuf) + 1;
cp = (char_u *)alloc((size_t)lengte);
if (cp)
strcpy((char *)cp, sbuf);
return cp;
}
else
return(NULL);
}
/*
* mch_setenv VMS version of setenv()
*/
int
mch_setenv(char *var, char *value, int x)
{
int res, dum;
long attrib = 0L;
char acmode = PSL$C_SUPER; /* needs SYSNAM privilege */
DESC tabnam, lognam;
ITMLST1 itmlst;
vul_desc(&tabnam, "LNM$JOB");
vul_desc(&lognam, var);
vul_item(&itmlst.equ, value ? strlen(value) : 0, value ? LNM$_STRING : 0,
value, &dum);
itmlst.nul = 0;
res = sys$crelnm(&attrib, &tabnam, &lognam, &acmode, &itmlst);
return((res == 1) ? 0 : -1);
}
int
vms_sys(char *cmd, char *out, char *inp)
{
DESC cdsc, odsc, idsc;
long status;
if (cmd)
vul_desc(&cdsc, cmd);
if (out)
vul_desc(&odsc, out);
if (inp)
vul_desc(&idsc, inp);
lib$spawn(cmd ? &cdsc : NULL, /* command string */
inp ? &idsc : NULL, /* input file */
out ? &odsc : NULL, /* output file */
0, 0, 0, &status, 0, 0, 0, 0, 0, 0);
return status;
}
/*
* Convert VMS system() or lib$spawn() return code to Unix-like exit value.
*/
int
vms_sys_status(int status)
{
if (status != SS$_NORMAL && (status & STS$M_SUCCESS) == 0)
return status; /* Command failed. */
return 0;
}
/*
* vms_read()
* function for low level char input
*
* Returns: input length
*/
int
vms_read(char *inbuf, size_t nbytes)
{
int status, function, len;
TT_MODE tt_mode;
ITEM itmlst[2]; /* terminates on everything */
static long trm_mask[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
/* whatever happened earlier we need an iochan here */
if (!iochan)
tt_mode = get_tty();
/* important: clean the inbuf */
memset(inbuf, 0, nbytes);
/* set up the itemlist for the first read */
vul_item(&itmlst[0], 0, TRM$_MODIFIERS,
(char *)( TRM$M_TM_NOECHO | TRM$M_TM_NOEDIT |
TRM$M_TM_NOFILTR | TRM$M_TM_TRMNOECHO |
TRM$M_TM_NORECALL) , 0);
vul_item(&itmlst[1], sizeof(trm_mask), TRM$_TERM, (char *)&trm_mask, 0);
/* wait forever for a char */
function = (IO$_READLBLK | IO$M_EXTEND);
status = sys$qiow(0, iochan, function, &iosb, 0, 0,
inbuf, nbytes-1, 0, 0, &itmlst, sizeof(itmlst));
len = strlen(inbuf); /* how many chars we got? */
/* read immediately the rest in the IO queue */
function = (IO$_READLBLK | IO$M_TIMED | IO$M_ESCAPE | IO$M_NOECHO | IO$M_NOFILTR);
status = sys$qiow(0, iochan, function, &iosb, 0, 0,
inbuf+len, nbytes-1-len, 0, 0, 0, 0);
len = strlen(inbuf); /* return the total length */
return len;
}
/*
* vms_wproc() is called for each matching filename by decc$to_vms().
* We want to save each match for later retrieval.
*
* Returns: 1 - continue finding matches
* 0 - stop trying to find any further matches
*/
static int
vms_wproc(char *name, int val)
{
int i;
int nlen;
static int vms_match_alloced = 0;
if (val != DECC$K_FILE) /* Directories and foreign non VMS files are not
counting */
return 1;
if (vms_match_num == 0) {
/* first time through, setup some things */
if (NULL == vms_fmatch) {
vms_fmatch = (char_u **)alloc(EXPL_ALLOC_INC * sizeof(char *));
if (!vms_fmatch)
return 0;
vms_match_alloced = EXPL_ALLOC_INC;
vms_match_free = EXPL_ALLOC_INC;
}
else {
/* re-use existing space */
vms_match_free = vms_match_alloced;
}
}
vms_remove_version(name);
/* convert filename to lowercase */
nlen = strlen(name);
for (i = 0; i < nlen; i++)
name[i] = TOLOWER_ASC(name[i]);
/* if name already exists, don't add it */
for (i = 0; i<vms_match_num; i++) {
if (0 == STRCMP((char_u *)name,vms_fmatch[i]))
return 1;
}
if (--vms_match_free == 0) {
/* add more space to store matches */
vms_match_alloced += EXPL_ALLOC_INC;
vms_fmatch = (char_u **)vim_realloc(vms_fmatch,
sizeof(char **) * vms_match_alloced);
if (!vms_fmatch)
return 0;
vms_match_free = EXPL_ALLOC_INC;
}
vms_fmatch[vms_match_num] = vim_strsave((char_u *)name);
++vms_match_num;
return 1;
}
/*
* mch_expand_wildcards this code does wild-card pattern
* matching NOT using the shell
*
* return OK for success, FAIL for error (you may lose some
* memory) and put an error message in *file.
*
* num_pat number of input patterns
* pat array of pointers to input patterns
* num_file pointer to number of matched file names
* file pointer to array of pointers to matched file names
*
*/
int
mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, int flags)
{
int i, cnt = 0;
char_u buf[MAXPATHL];
int dir;
int files_alloced, files_free;
*num_file = 0; /* default: no files found */
files_alloced = EXPL_ALLOC_INC;
files_free = EXPL_ALLOC_INC;
*file = (char_u **) alloc(sizeof(char_u **) * files_alloced);
if (*file == NULL)
{
*num_file = 0;
return FAIL;
}
for (i = 0; i < num_pat; i++)
{
/* expand environment var or home dir */
if (vim_strchr(pat[i],'$') || vim_strchr(pat[i],'~'))
expand_env(pat[i],buf,MAXPATHL);
else
STRCPY(buf,pat[i]);
vms_match_num = 0; /* reset collection counter */
cnt = decc$to_vms(decc$translate_vms(vms_fixfilename(buf)), vms_wproc, 1, 0);
/* allow wild, no dir */
if (cnt > 0)
cnt = vms_match_num;
if (cnt < 1)
continue;
for (i = 0; i < cnt; i++)
{
/* files should exist if expanding interactively */
if (!(flags & EW_NOTFOUND) && mch_getperm(vms_fmatch[i]) < 0)
continue;
/* do not include directories */
dir = (mch_isdir(vms_fmatch[i]));
if (( dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE)))
continue;
/* Skip files that are not executable if we check for that. */
if (!dir && (flags & EW_EXEC) && !mch_can_exe(vms_fmatch[i]))
continue;
/* allocate memory for pointers */
if (--files_free < 1)
{
files_alloced += EXPL_ALLOC_INC;
*file = (char_u **)vim_realloc(*file,
sizeof(char_u **) * files_alloced);
if (*file == NULL)
{
*file = (char_u **)"";
*num_file = 0;
return(FAIL);
}
files_free = EXPL_ALLOC_INC;
}
(*file)[*num_file++] = vms_fmatch[i];
}
}
return OK;
}
int
mch_expandpath(garray_T *gap, char_u *path, int flags)
{
int i,cnt = 0;
vms_match_num = 0;
cnt = decc$to_vms(decc$translate_vms(vms_fixfilename(path)), vms_wproc, 1, 0);
/* allow wild, no dir */
if (cnt > 0)
cnt = vms_match_num;
for (i = 0; i < cnt; i++)
{
if (mch_getperm(vms_fmatch[i]) >= 0) /* add existing file */
addfile(gap, vms_fmatch[i], flags);
}
return cnt;
}
/*
* attempt to translate a mixed unix-vms file specification to pure vms
*/
static void
vms_unix_mixed_filespec(char *in, char *out)
{
char *lastcolon;
char *end_of_dir;
char ch;
int len;
/* copy vms filename portion up to last colon
* (node and/or disk)
*/
lastcolon = strrchr(in, ':'); /* find last colon */
if (lastcolon != NULL) {
len = lastcolon - in + 1;
strncpy(out, in, len);
out += len;
in += len;
}
end_of_dir = NULL; /* default: no directory */
/* start of directory portion */
ch = *in;
if ((ch == '[') || (ch == '/') || (ch == '<')) { /* start of directory(s) ? */
ch = '[';
SKIP_FOLLOWING_SLASHES(in);
} else if (EQN(in, "../", 3)) { /* Unix parent directory? */
*out++ = '[';
*out++ = '-';
end_of_dir = out;
ch = '.';
in += 2;
SKIP_FOLLOWING_SLASHES(in);
} else { /* not a special character */
while (EQN(in, "./", 2)) { /* Ignore Unix "current dir" */
in += 2;
SKIP_FOLLOWING_SLASHES(in);
}
if (strchr(in, '/') == NULL) { /* any more Unix directories ? */
strcpy(out, in); /* No - get rest of the spec */
return;
} else {
*out++ = '['; /* Yes, denote a Vms subdirectory */
ch = '.';
--in;
}
}
/* if we get here, there is a directory part of the filename */
/* initialize output file spec */
*out++ = ch;
++in;
while (*in != '\0') {
ch = *in;
if ((ch == ']') || (ch == '/') || (ch == '>') ) { /* end of (sub)directory ? */
end_of_dir = out;
ch = '.';
SKIP_FOLLOWING_SLASHES(in);
}
else if (EQN(in, "../", 3)) { /* Unix parent directory? */
*out++ = '-';
end_of_dir = out;
ch = '.';
in += 2;
SKIP_FOLLOWING_SLASHES(in);
}
else {
while (EQN(in, "./", 2)) { /* Ignore Unix "current dir" */
end_of_dir = out;
in += 2;
SKIP_FOLLOWING_SLASHES(in);
ch = *in;
}
}
/* Place next character into output file spec */
*out++ = ch;
++in;
}
*out = '\0'; /* Terminate output file spec */
if (end_of_dir != NULL) /* Terminate directory portion */
*end_of_dir = ']';
}
/*
* for decc$to_vms in vms_fixfilename
*/
static int
vms_fspec_proc(char *fil, int val)
{
strcpy(Fspec_Rms,fil);
return(1);
}
/*
* change unix and mixed filenames to VMS
*/
void *
vms_fixfilename(void *instring)
{
static char *buf = NULL;
static size_t buflen = 0;
size_t len;
/* get a big-enough buffer */
len = strlen(instring) + 1;
if (len > buflen)
{
buflen = len + 128;
if (buf)
buf = (char *)vim_realloc(buf, buflen);
else
buf = (char *)alloc(buflen * sizeof(char));
}
#ifdef DEBUG
char *tmpbuf = NULL;
tmpbuf = (char *)alloc(buflen * sizeof(char));
strcpy(tmpbuf, instring);
#endif
Fspec_Rms = buf; /* for decc$to_vms */
if (strchr(instring,'/') == NULL)
/* It is already a VMS file spec */
strcpy(buf, instring);
else if (strchr(instring,'"') == NULL) /* password in the path? */
{
/* Seems it is a regular file, let guess that it is pure Unix fspec */
if (decc$to_vms(instring, vms_fspec_proc, 0, 0) <= 0)
/* No... it must be mixed */
vms_unix_mixed_filespec(instring, buf);
}
else
/* we have a password in the path */
/* decc$ functions can not handle */
/* this is our only hope to resolv */
vms_unix_mixed_filespec(instring, buf);
return buf;
}
/*
* Remove version number from file name
* we need it in some special cases as:
* creating swap file name and writing new file
*/
void
vms_remove_version(void * fname)
{
char_u *cp;
char_u *fp;
if ((cp = vim_strchr( fname, ';')) != NULL) /* remove version */
*cp = '\0';
else if ((cp = vim_strrchr( fname, '.')) != NULL )
{
if ((fp = vim_strrchr( fname, ']')) != NULL ) {;}
else if ((fp = vim_strrchr( fname, '>')) != NULL ) {;}
else fp = fname;
while ( *fp != '\0' && fp < cp )
if ( *fp++ == '.' )
*cp = '\0';
}
return ;
}
| zyz2011-vim | src/os_vms.c | C | gpl2 | 15,721 |