comparison src/ex_getln.c @ 7819:f86adafb28d4 v7.4.1206

commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 30 15:52:46 2016 +0100 patch 7.4.1206 Problem: Using old style function declarations. Solution: Change to new style function declarations. (script by Hirohito Higashi)
author Christian Brabandt <cb@256bit.org>
date Sat, 30 Jan 2016 16:00:06 +0100
parents 1a5d34492798
children 10f17a228661
comparison
equal deleted inserted replaced
7818:19dfb097d82d 7819:f86adafb28d4
154 * 154 *
155 * Return pointer to allocated string if there is a commandline, NULL 155 * Return pointer to allocated string if there is a commandline, NULL
156 * otherwise. 156 * otherwise.
157 */ 157 */
158 char_u * 158 char_u *
159 getcmdline(firstc, count, indent) 159 getcmdline(
160 int firstc; 160 int firstc,
161 long count UNUSED; /* only used for incremental search */ 161 long count UNUSED, /* only used for incremental search */
162 int indent; /* indent for inside conditionals */ 162 int indent) /* indent for inside conditionals */
163 { 163 {
164 int c; 164 int c;
165 int i; 165 int i;
166 int j; 166 int j;
167 int gotesc = FALSE; /* TRUE when <ESC> just typed */ 167 int gotesc = FALSE; /* TRUE when <ESC> just typed */
1986 * This is prepared to be called recursively from getcmdline() (e.g. by 1986 * This is prepared to be called recursively from getcmdline() (e.g. by
1987 * f_input() when evaluating an expression from CTRL-R =). 1987 * f_input() when evaluating an expression from CTRL-R =).
1988 * Returns the command line in allocated memory, or NULL. 1988 * Returns the command line in allocated memory, or NULL.
1989 */ 1989 */
1990 char_u * 1990 char_u *
1991 getcmdline_prompt(firstc, prompt, attr, xp_context, xp_arg) 1991 getcmdline_prompt(
1992 int firstc; 1992 int firstc,
1993 char_u *prompt; /* command line prompt */ 1993 char_u *prompt, /* command line prompt */
1994 int attr; /* attributes for prompt */ 1994 int attr, /* attributes for prompt */
1995 int xp_context; /* type of expansion */ 1995 int xp_context, /* type of expansion */
1996 char_u *xp_arg; /* user-defined expansion argument */ 1996 char_u *xp_arg) /* user-defined expansion argument */
1997 { 1997 {
1998 char_u *s; 1998 char_u *s;
1999 struct cmdline_info save_ccline; 1999 struct cmdline_info save_ccline;
2000 int msg_col_save = msg_col; 2000 int msg_col_save = msg_col;
2001 2001
2024 * Return TRUE when the text must not be changed and we can't switch to 2024 * Return TRUE when the text must not be changed and we can't switch to
2025 * another window or buffer. Used when editing the command line, evaluating 2025 * another window or buffer. Used when editing the command line, evaluating
2026 * 'balloonexpr', etc. 2026 * 'balloonexpr', etc.
2027 */ 2027 */
2028 int 2028 int
2029 text_locked() 2029 text_locked(void)
2030 { 2030 {
2031 #ifdef FEAT_CMDWIN 2031 #ifdef FEAT_CMDWIN
2032 if (cmdwin_type != 0) 2032 if (cmdwin_type != 0)
2033 return TRUE; 2033 return TRUE;
2034 #endif 2034 #endif
2038 /* 2038 /*
2039 * Give an error message for a command that isn't allowed while the cmdline 2039 * Give an error message for a command that isn't allowed while the cmdline
2040 * window is open or editing the cmdline in another way. 2040 * window is open or editing the cmdline in another way.
2041 */ 2041 */
2042 void 2042 void
2043 text_locked_msg() 2043 text_locked_msg(void)
2044 { 2044 {
2045 #ifdef FEAT_CMDWIN 2045 #ifdef FEAT_CMDWIN
2046 if (cmdwin_type != 0) 2046 if (cmdwin_type != 0)
2047 EMSG(_(e_cmdwin)); 2047 EMSG(_(e_cmdwin));
2048 else 2048 else
2054 /* 2054 /*
2055 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is 2055 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is
2056 * and give an error message. 2056 * and give an error message.
2057 */ 2057 */
2058 int 2058 int
2059 curbuf_locked() 2059 curbuf_locked(void)
2060 { 2060 {
2061 if (curbuf_lock > 0) 2061 if (curbuf_lock > 0)
2062 { 2062 {
2063 EMSG(_("E788: Not allowed to edit another buffer now")); 2063 EMSG(_("E788: Not allowed to edit another buffer now"));
2064 return TRUE; 2064 return TRUE;
2069 /* 2069 /*
2070 * Check if "allbuf_lock" is set and return TRUE when it is and give an error 2070 * Check if "allbuf_lock" is set and return TRUE when it is and give an error
2071 * message. 2071 * message.
2072 */ 2072 */
2073 int 2073 int
2074 allbuf_locked() 2074 allbuf_locked(void)
2075 { 2075 {
2076 if (allbuf_lock > 0) 2076 if (allbuf_lock > 0)
2077 { 2077 {
2078 EMSG(_("E811: Not allowed to change buffer information now")); 2078 EMSG(_("E811: Not allowed to change buffer information now"));
2079 return TRUE; 2079 return TRUE;
2081 return FALSE; 2081 return FALSE;
2082 } 2082 }
2083 #endif 2083 #endif
2084 2084
2085 static int 2085 static int
2086 cmdline_charsize(idx) 2086 cmdline_charsize(int idx)
2087 int idx;
2088 { 2087 {
2089 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) 2088 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
2090 if (cmdline_star > 0) /* showing '*', always 1 position */ 2089 if (cmdline_star > 0) /* showing '*', always 1 position */
2091 return 1; 2090 return 1;
2092 #endif 2091 #endif
2096 /* 2095 /*
2097 * Compute the offset of the cursor on the command line for the prompt and 2096 * Compute the offset of the cursor on the command line for the prompt and
2098 * indent. 2097 * indent.
2099 */ 2098 */
2100 static void 2099 static void
2101 set_cmdspos() 2100 set_cmdspos(void)
2102 { 2101 {
2103 if (ccline.cmdfirstc != NUL) 2102 if (ccline.cmdfirstc != NUL)
2104 ccline.cmdspos = 1 + ccline.cmdindent; 2103 ccline.cmdspos = 1 + ccline.cmdindent;
2105 else 2104 else
2106 ccline.cmdspos = 0 + ccline.cmdindent; 2105 ccline.cmdspos = 0 + ccline.cmdindent;
2108 2107
2109 /* 2108 /*
2110 * Compute the screen position for the cursor on the command line. 2109 * Compute the screen position for the cursor on the command line.
2111 */ 2110 */
2112 static void 2111 static void
2113 set_cmdspos_cursor() 2112 set_cmdspos_cursor(void)
2114 { 2113 {
2115 int i, m, c; 2114 int i, m, c;
2116 2115
2117 set_cmdspos(); 2116 set_cmdspos();
2118 if (KeyTyped) 2117 if (KeyTyped)
2149 /* 2148 /*
2150 * Check if the character at "idx", which is "cells" wide, is a multi-byte 2149 * Check if the character at "idx", which is "cells" wide, is a multi-byte
2151 * character that doesn't fit, so that a ">" must be displayed. 2150 * character that doesn't fit, so that a ">" must be displayed.
2152 */ 2151 */
2153 static void 2152 static void
2154 correct_cmdspos(idx, cells) 2153 correct_cmdspos(int idx, int cells)
2155 int idx;
2156 int cells;
2157 { 2154 {
2158 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 2155 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1
2159 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 2156 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1
2160 && ccline.cmdspos % Columns + cells > Columns) 2157 && ccline.cmdspos % Columns + cells > Columns)
2161 ccline.cmdspos++; 2158 ccline.cmdspos++;
2164 2161
2165 /* 2162 /*
2166 * Get an Ex command line for the ":" command. 2163 * Get an Ex command line for the ":" command.
2167 */ 2164 */
2168 char_u * 2165 char_u *
2169 getexline(c, cookie, indent) 2166 getexline(
2170 int c; /* normally ':', NUL for ":append" */ 2167 int c, /* normally ':', NUL for ":append" */
2171 void *cookie UNUSED; 2168 void *cookie UNUSED,
2172 int indent; /* indent for inside conditionals */ 2169 int indent) /* indent for inside conditionals */
2173 { 2170 {
2174 /* When executing a register, remove ':' that's in front of each line. */ 2171 /* When executing a register, remove ':' that's in front of each line. */
2175 if (exec_from_reg && vpeekc() == ':') 2172 if (exec_from_reg && vpeekc() == ':')
2176 (void)vgetc(); 2173 (void)vgetc();
2177 return getcmdline(c, 1L, indent); 2174 return getcmdline(c, 1L, indent);
2182 * In Ex mode we only use the OS supplied line editing features and no 2179 * In Ex mode we only use the OS supplied line editing features and no
2183 * mappings or abbreviations. 2180 * mappings or abbreviations.
2184 * Returns a string in allocated memory or NULL. 2181 * Returns a string in allocated memory or NULL.
2185 */ 2182 */
2186 char_u * 2183 char_u *
2187 getexmodeline(promptc, cookie, indent) 2184 getexmodeline(
2188 int promptc; /* normally ':', NUL for ":append" and '?' for 2185 int promptc, /* normally ':', NUL for ":append" and '?' for
2189 :s prompt */ 2186 :s prompt */
2190 void *cookie UNUSED; 2187 void *cookie UNUSED,
2191 int indent; /* indent for inside conditionals */ 2188 int indent) /* indent for inside conditionals */
2192 { 2189 {
2193 garray_T line_ga; 2190 garray_T line_ga;
2194 char_u *pend; 2191 char_u *pend;
2195 int startcol = 0; 2192 int startcol = 0;
2196 int c1 = 0; 2193 int c1 = 0;
2471 || defined(FEAT_MOUSESHAPE) || defined(PROTO) 2468 || defined(FEAT_MOUSESHAPE) || defined(PROTO)
2472 /* 2469 /*
2473 * Return TRUE if ccline.overstrike is on. 2470 * Return TRUE if ccline.overstrike is on.
2474 */ 2471 */
2475 int 2472 int
2476 cmdline_overstrike() 2473 cmdline_overstrike(void)
2477 { 2474 {
2478 return ccline.overstrike; 2475 return ccline.overstrike;
2479 } 2476 }
2480 2477
2481 /* 2478 /*
2482 * Return TRUE if the cursor is at the end of the cmdline. 2479 * Return TRUE if the cursor is at the end of the cmdline.
2483 */ 2480 */
2484 int 2481 int
2485 cmdline_at_end() 2482 cmdline_at_end(void)
2486 { 2483 {
2487 return (ccline.cmdpos >= ccline.cmdlen); 2484 return (ccline.cmdpos >= ccline.cmdlen);
2488 } 2485 }
2489 #endif 2486 #endif
2490 2487
2492 /* 2489 /*
2493 * Return the virtual column number at the current cursor position. 2490 * Return the virtual column number at the current cursor position.
2494 * This is used by the IM code to obtain the start of the preedit string. 2491 * This is used by the IM code to obtain the start of the preedit string.
2495 */ 2492 */
2496 colnr_T 2493 colnr_T
2497 cmdline_getvcol_cursor() 2494 cmdline_getvcol_cursor(void)
2498 { 2495 {
2499 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) 2496 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen)
2500 return MAXCOL; 2497 return MAXCOL;
2501 2498
2502 # ifdef FEAT_MBYTE 2499 # ifdef FEAT_MBYTE
2520 /* 2517 /*
2521 * If part of the command line is an IM preedit string, redraw it with 2518 * If part of the command line is an IM preedit string, redraw it with
2522 * IM feedback attributes. The cursor position is restored after drawing. 2519 * IM feedback attributes. The cursor position is restored after drawing.
2523 */ 2520 */
2524 static void 2521 static void
2525 redrawcmd_preedit() 2522 redrawcmd_preedit(void)
2526 { 2523 {
2527 if ((State & CMDLINE) 2524 if ((State & CMDLINE)
2528 && xic != NULL 2525 && xic != NULL
2529 /* && im_get_status() doesn't work when using SCIM */ 2526 /* && im_get_status() doesn't work when using SCIM */
2530 && !p_imdisable 2527 && !p_imdisable
2592 * Allocate a new command line buffer. 2589 * Allocate a new command line buffer.
2593 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. 2590 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen.
2594 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. 2591 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen.
2595 */ 2592 */
2596 static void 2593 static void
2597 alloc_cmdbuff(len) 2594 alloc_cmdbuff(int len)
2598 int len;
2599 { 2595 {
2600 /* 2596 /*
2601 * give some extra space to avoid having to allocate all the time 2597 * give some extra space to avoid having to allocate all the time
2602 */ 2598 */
2603 if (len < 80) 2599 if (len < 80)
2612 /* 2608 /*
2613 * Re-allocate the command line to length len + something extra. 2609 * Re-allocate the command line to length len + something extra.
2614 * return FAIL for failure, OK otherwise 2610 * return FAIL for failure, OK otherwise
2615 */ 2611 */
2616 static int 2612 static int
2617 realloc_cmdbuff(len) 2613 realloc_cmdbuff(int len)
2618 int len;
2619 { 2614 {
2620 char_u *p; 2615 char_u *p;
2621 2616
2622 if (len < ccline.cmdbufflen) 2617 if (len < ccline.cmdbufflen)
2623 return OK; /* no need to resize */ 2618 return OK; /* no need to resize */
2654 #if defined(FEAT_ARABIC) || defined(PROTO) 2649 #if defined(FEAT_ARABIC) || defined(PROTO)
2655 static char_u *arshape_buf = NULL; 2650 static char_u *arshape_buf = NULL;
2656 2651
2657 # if defined(EXITFREE) || defined(PROTO) 2652 # if defined(EXITFREE) || defined(PROTO)
2658 void 2653 void
2659 free_cmdline_buf() 2654 free_cmdline_buf(void)
2660 { 2655 {
2661 vim_free(arshape_buf); 2656 vim_free(arshape_buf);
2662 } 2657 }
2663 # endif 2658 # endif
2664 #endif 2659 #endif
2666 /* 2661 /*
2667 * Draw part of the cmdline at the current cursor position. But draw stars 2662 * Draw part of the cmdline at the current cursor position. But draw stars
2668 * when cmdline_star is TRUE. 2663 * when cmdline_star is TRUE.
2669 */ 2664 */
2670 static void 2665 static void
2671 draw_cmdline(start, len) 2666 draw_cmdline(int start, int len)
2672 int start;
2673 int len;
2674 { 2667 {
2675 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) 2668 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
2676 int i; 2669 int i;
2677 2670
2678 if (cmdline_star > 0) 2671 if (cmdline_star > 0)
2789 * Put a character on the command line. Shifts the following text to the 2782 * Put a character on the command line. Shifts the following text to the
2790 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. 2783 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc.
2791 * "c" must be printable (fit in one display cell)! 2784 * "c" must be printable (fit in one display cell)!
2792 */ 2785 */
2793 void 2786 void
2794 putcmdline(c, shift) 2787 putcmdline(int c, int shift)
2795 int c;
2796 int shift;
2797 { 2788 {
2798 if (cmd_silent) 2789 if (cmd_silent)
2799 return; 2790 return;
2800 msg_no_more = TRUE; 2791 msg_no_more = TRUE;
2801 msg_putchar(c); 2792 msg_putchar(c);
2807 2798
2808 /* 2799 /*
2809 * Undo a putcmdline(c, FALSE). 2800 * Undo a putcmdline(c, FALSE).
2810 */ 2801 */
2811 void 2802 void
2812 unputcmdline() 2803 unputcmdline(void)
2813 { 2804 {
2814 if (cmd_silent) 2805 if (cmd_silent)
2815 return; 2806 return;
2816 msg_no_more = TRUE; 2807 msg_no_more = TRUE;
2817 if (ccline.cmdlen == ccline.cmdpos) 2808 if (ccline.cmdlen == ccline.cmdpos)
2834 * part will be redrawn, otherwise it will not. If this function is called 2825 * part will be redrawn, otherwise it will not. If this function is called
2835 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be 2826 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be
2836 * called afterwards. 2827 * called afterwards.
2837 */ 2828 */
2838 int 2829 int
2839 put_on_cmdline(str, len, redraw) 2830 put_on_cmdline(char_u *str, int len, int redraw)
2840 char_u *str;
2841 int len;
2842 int redraw;
2843 { 2831 {
2844 int retval; 2832 int retval;
2845 int i; 2833 int i;
2846 int m; 2834 int m;
2847 int c; 2835 int c;
3007 * Save ccline, because obtaining the "=" register may execute "normal :cmd" 2995 * Save ccline, because obtaining the "=" register may execute "normal :cmd"
3008 * and overwrite it. But get_cmdline_str() may need it, thus make it 2996 * and overwrite it. But get_cmdline_str() may need it, thus make it
3009 * available globally in prev_ccline. 2997 * available globally in prev_ccline.
3010 */ 2998 */
3011 static void 2999 static void
3012 save_cmdline(ccp) 3000 save_cmdline(struct cmdline_info *ccp)
3013 struct cmdline_info *ccp;
3014 { 3001 {
3015 if (!prev_ccline_used) 3002 if (!prev_ccline_used)
3016 { 3003 {
3017 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); 3004 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info));
3018 prev_ccline_used = TRUE; 3005 prev_ccline_used = TRUE;
3026 3013
3027 /* 3014 /*
3028 * Restore ccline after it has been saved with save_cmdline(). 3015 * Restore ccline after it has been saved with save_cmdline().
3029 */ 3016 */
3030 static void 3017 static void
3031 restore_cmdline(ccp) 3018 restore_cmdline(struct cmdline_info *ccp)
3032 struct cmdline_info *ccp;
3033 { 3019 {
3034 ccline = prev_ccline; 3020 ccline = prev_ccline;
3035 prev_ccline = *ccp; 3021 prev_ccline = *ccp;
3036 } 3022 }
3037 3023
3040 * Save the command line into allocated memory. Returns a pointer to be 3026 * Save the command line into allocated memory. Returns a pointer to be
3041 * passed to restore_cmdline_alloc() later. 3027 * passed to restore_cmdline_alloc() later.
3042 * Returns NULL when failed. 3028 * Returns NULL when failed.
3043 */ 3029 */
3044 char_u * 3030 char_u *
3045 save_cmdline_alloc() 3031 save_cmdline_alloc(void)
3046 { 3032 {
3047 struct cmdline_info *p; 3033 struct cmdline_info *p;
3048 3034
3049 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); 3035 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info));
3050 if (p != NULL) 3036 if (p != NULL)
3054 3040
3055 /* 3041 /*
3056 * Restore the command line from the return value of save_cmdline_alloc(). 3042 * Restore the command line from the return value of save_cmdline_alloc().
3057 */ 3043 */
3058 void 3044 void
3059 restore_cmdline_alloc(p) 3045 restore_cmdline_alloc(char_u *p)
3060 char_u *p;
3061 { 3046 {
3062 if (p != NULL) 3047 if (p != NULL)
3063 { 3048 {
3064 restore_cmdline((struct cmdline_info *)p); 3049 restore_cmdline((struct cmdline_info *)p);
3065 vim_free(p); 3050 vim_free(p);
3074 * register contents will be interpreted as commands. 3059 * register contents will be interpreted as commands.
3075 * 3060 *
3076 * Return FAIL for failure, OK otherwise. 3061 * Return FAIL for failure, OK otherwise.
3077 */ 3062 */
3078 static int 3063 static int
3079 cmdline_paste(regname, literally, remcr) 3064 cmdline_paste(
3080 int regname; 3065 int regname,
3081 int literally; /* Insert text literally instead of "as typed" */ 3066 int literally, /* Insert text literally instead of "as typed" */
3082 int remcr; /* remove trailing CR */ 3067 int remcr) /* remove trailing CR */
3083 { 3068 {
3084 long i; 3069 long i;
3085 char_u *arg; 3070 char_u *arg;
3086 char_u *p; 3071 char_u *p;
3087 int allocated; 3072 int allocated;
3163 * When "literally" is TRUE, insert literally. 3148 * When "literally" is TRUE, insert literally.
3164 * When "literally" is FALSE, insert as typed, but don't leave the command 3149 * When "literally" is FALSE, insert as typed, but don't leave the command
3165 * line. 3150 * line.
3166 */ 3151 */
3167 void 3152 void
3168 cmdline_paste_str(s, literally) 3153 cmdline_paste_str(char_u *s, int literally)
3169 char_u *s;
3170 int literally;
3171 { 3154 {
3172 int c, cv; 3155 int c, cv;
3173 3156
3174 if (literally) 3157 if (literally)
3175 put_on_cmdline(s, -1, TRUE); 3158 put_on_cmdline(s, -1, TRUE);
3200 /* 3183 /*
3201 * Delete characters on the command line, from "from" to the current 3184 * Delete characters on the command line, from "from" to the current
3202 * position. 3185 * position.
3203 */ 3186 */
3204 static void 3187 static void
3205 cmdline_del(from) 3188 cmdline_del(int from)
3206 int from;
3207 { 3189 {
3208 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, 3190 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos,
3209 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); 3191 (size_t)(ccline.cmdlen - ccline.cmdpos + 1));
3210 ccline.cmdlen -= ccline.cmdpos - from; 3192 ccline.cmdlen -= ccline.cmdpos - from;
3211 ccline.cmdpos = from; 3193 ccline.cmdpos = from;
3215 /* 3197 /*
3216 * this function is called when the screen size changes and with incremental 3198 * this function is called when the screen size changes and with incremental
3217 * search 3199 * search
3218 */ 3200 */
3219 void 3201 void
3220 redrawcmdline() 3202 redrawcmdline(void)
3221 { 3203 {
3222 if (cmd_silent) 3204 if (cmd_silent)
3223 return; 3205 return;
3224 need_wait_return = FALSE; 3206 need_wait_return = FALSE;
3225 compute_cmdrow(); 3207 compute_cmdrow();
3226 redrawcmd(); 3208 redrawcmd();
3227 cursorcmd(); 3209 cursorcmd();
3228 } 3210 }
3229 3211
3230 static void 3212 static void
3231 redrawcmdprompt() 3213 redrawcmdprompt(void)
3232 { 3214 {
3233 int i; 3215 int i;
3234 3216
3235 if (cmd_silent) 3217 if (cmd_silent)
3236 return; 3218 return;
3251 3233
3252 /* 3234 /*
3253 * Redraw what is currently on the command line. 3235 * Redraw what is currently on the command line.
3254 */ 3236 */
3255 void 3237 void
3256 redrawcmd() 3238 redrawcmd(void)
3257 { 3239 {
3258 if (cmd_silent) 3240 if (cmd_silent)
3259 return; 3241 return;
3260 3242
3261 /* when 'incsearch' is set there may be no command line while redrawing */ 3243 /* when 'incsearch' is set there may be no command line while redrawing */
3287 * in cmdline mode */ 3269 * in cmdline mode */
3288 skip_redraw = FALSE; 3270 skip_redraw = FALSE;
3289 } 3271 }
3290 3272
3291 void 3273 void
3292 compute_cmdrow() 3274 compute_cmdrow(void)
3293 { 3275 {
3294 if (exmode_active || msg_scrolled != 0) 3276 if (exmode_active || msg_scrolled != 0)
3295 cmdline_row = Rows - 1; 3277 cmdline_row = Rows - 1;
3296 else 3278 else
3297 cmdline_row = W_WINROW(lastwin) + lastwin->w_height 3279 cmdline_row = W_WINROW(lastwin) + lastwin->w_height
3298 + W_STATUS_HEIGHT(lastwin); 3280 + W_STATUS_HEIGHT(lastwin);
3299 } 3281 }
3300 3282
3301 static void 3283 static void
3302 cursorcmd() 3284 cursorcmd(void)
3303 { 3285 {
3304 if (cmd_silent) 3286 if (cmd_silent)
3305 return; 3287 return;
3306 3288
3307 #ifdef FEAT_RIGHTLEFT 3289 #ifdef FEAT_RIGHTLEFT
3329 mch_update_cursor(); 3311 mch_update_cursor();
3330 #endif 3312 #endif
3331 } 3313 }
3332 3314
3333 void 3315 void
3334 gotocmdline(clr) 3316 gotocmdline(int clr)
3335 int clr;
3336 { 3317 {
3337 msg_start(); 3318 msg_start();
3338 #ifdef FEAT_RIGHTLEFT 3319 #ifdef FEAT_RIGHTLEFT
3339 if (cmdmsg_rl) 3320 if (cmdmsg_rl)
3340 msg_col = Columns - 1; 3321 msg_col = Columns - 1;
3351 * Called when the non-id character "c" has been entered. 3332 * Called when the non-id character "c" has been entered.
3352 * When an abbreviation is recognized it is removed from the text with 3333 * When an abbreviation is recognized it is removed from the text with
3353 * backspaces and the replacement string is inserted, followed by "c". 3334 * backspaces and the replacement string is inserted, followed by "c".
3354 */ 3335 */
3355 static int 3336 static int
3356 ccheck_abbr(c) 3337 ccheck_abbr(int c)
3357 int c;
3358 { 3338 {
3359 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ 3339 if (p_paste || no_abbr) /* no abbreviations or in paste mode */
3360 return FALSE; 3340 return FALSE;
3361 3341
3362 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, 0); 3342 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, 0);
3365 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) 3345 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
3366 static int 3346 static int
3367 #ifdef __BORLANDC__ 3347 #ifdef __BORLANDC__
3368 _RTLENTRYF 3348 _RTLENTRYF
3369 #endif 3349 #endif
3370 sort_func_compare(s1, s2) 3350 sort_func_compare(const void *s1, const void *s2)
3371 const void *s1;
3372 const void *s2;
3373 { 3351 {
3374 char_u *p1 = *(char_u **)s1; 3352 char_u *p1 = *(char_u **)s1;
3375 char_u *p2 = *(char_u **)s2; 3353 char_u *p2 = *(char_u **)s2;
3376 3354
3377 if (*p1 != '<' && *p2 == '<') return -1; 3355 if (*p1 != '<' && *p2 == '<') return -1;
3385 * completion of anything, return OK if it is (even if there are no matches). 3363 * completion of anything, return OK if it is (even if there are no matches).
3386 * For the caller, this means that the character is just passed through like a 3364 * For the caller, this means that the character is just passed through like a
3387 * normal character (instead of being expanded). This allows :s/^I^D etc. 3365 * normal character (instead of being expanded). This allows :s/^I^D etc.
3388 */ 3366 */
3389 static int 3367 static int
3390 nextwild(xp, type, options, escape) 3368 nextwild(
3391 expand_T *xp; 3369 expand_T *xp,
3392 int type; 3370 int type,
3393 int options; /* extra options for ExpandOne() */ 3371 int options, /* extra options for ExpandOne() */
3394 int escape; /* if TRUE, escape the returned matches */ 3372 int escape) /* if TRUE, escape the returned matches */
3395 { 3373 {
3396 int i, j; 3374 int i, j;
3397 char_u *p1; 3375 char_u *p1;
3398 char_u *p2; 3376 char_u *p2;
3399 int difflen; 3377 int difflen;
3538 * options = WILD_ICASE: ignore case for files 3516 * options = WILD_ICASE: ignore case for files
3539 * 3517 *
3540 * The variables xp->xp_context and xp->xp_backslash must have been set! 3518 * The variables xp->xp_context and xp->xp_backslash must have been set!
3541 */ 3519 */
3542 char_u * 3520 char_u *
3543 ExpandOne(xp, str, orig, options, mode) 3521 ExpandOne(
3544 expand_T *xp; 3522 expand_T *xp,
3545 char_u *str; 3523 char_u *str,
3546 char_u *orig; /* allocated copy of original of expanded string */ 3524 char_u *orig, /* allocated copy of original of expanded string */
3547 int options; 3525 int options,
3548 int mode; 3526 int mode)
3549 { 3527 {
3550 char_u *ss = NULL; 3528 char_u *ss = NULL;
3551 static int findex; 3529 static int findex;
3552 static char_u *orig_save = NULL; /* kept value of orig */ 3530 static char_u *orig_save = NULL; /* kept value of orig */
3553 int orig_saved = FALSE; 3531 int orig_saved = FALSE;
3769 3747
3770 /* 3748 /*
3771 * Prepare an expand structure for use. 3749 * Prepare an expand structure for use.
3772 */ 3750 */
3773 void 3751 void
3774 ExpandInit(xp) 3752 ExpandInit(expand_T *xp)
3775 expand_T *xp;
3776 { 3753 {
3777 xp->xp_pattern = NULL; 3754 xp->xp_pattern = NULL;
3778 xp->xp_pattern_len = 0; 3755 xp->xp_pattern_len = 0;
3779 xp->xp_backslash = XP_BS_NONE; 3756 xp->xp_backslash = XP_BS_NONE;
3780 #ifndef BACKSLASH_IN_FILENAME 3757 #ifndef BACKSLASH_IN_FILENAME
3790 3767
3791 /* 3768 /*
3792 * Cleanup an expand structure after use. 3769 * Cleanup an expand structure after use.
3793 */ 3770 */
3794 void 3771 void
3795 ExpandCleanup(xp) 3772 ExpandCleanup(expand_T *xp)
3796 expand_T *xp;
3797 { 3773 {
3798 if (xp->xp_numfiles >= 0) 3774 if (xp->xp_numfiles >= 0)
3799 { 3775 {
3800 FreeWild(xp->xp_numfiles, xp->xp_files); 3776 FreeWild(xp->xp_numfiles, xp->xp_files);
3801 xp->xp_numfiles = -1; 3777 xp->xp_numfiles = -1;
3802 } 3778 }
3803 } 3779 }
3804 3780
3805 void 3781 void
3806 ExpandEscape(xp, str, numfiles, files, options) 3782 ExpandEscape(
3807 expand_T *xp; 3783 expand_T *xp,
3808 char_u *str; 3784 char_u *str,
3809 int numfiles; 3785 int numfiles,
3810 char_u **files; 3786 char_u **files,
3811 int options; 3787 int options)
3812 { 3788 {
3813 int i; 3789 int i;
3814 char_u *p; 3790 char_u *p;
3815 3791
3816 /* 3792 /*
3897 * Escape special characters in "fname" for when used as a file name argument 3873 * Escape special characters in "fname" for when used as a file name argument
3898 * after a Vim command, or, when "shell" is non-zero, a shell command. 3874 * after a Vim command, or, when "shell" is non-zero, a shell command.
3899 * Returns the result in allocated memory. 3875 * Returns the result in allocated memory.
3900 */ 3876 */
3901 char_u * 3877 char_u *
3902 vim_strsave_fnameescape(fname, shell) 3878 vim_strsave_fnameescape(char_u *fname, int shell)
3903 char_u *fname;
3904 int shell;
3905 { 3879 {
3906 char_u *p; 3880 char_u *p;
3907 #ifdef BACKSLASH_IN_FILENAME 3881 #ifdef BACKSLASH_IN_FILENAME
3908 char_u buf[20]; 3882 char_u buf[20];
3909 int j = 0; 3883 int j = 0;
3938 3912
3939 /* 3913 /*
3940 * Put a backslash before the file name in "pp", which is in allocated memory. 3914 * Put a backslash before the file name in "pp", which is in allocated memory.
3941 */ 3915 */
3942 static void 3916 static void
3943 escape_fname(pp) 3917 escape_fname(char_u **pp)
3944 char_u **pp;
3945 { 3918 {
3946 char_u *p; 3919 char_u *p;
3947 3920
3948 p = alloc((unsigned)(STRLEN(*pp) + 2)); 3921 p = alloc((unsigned)(STRLEN(*pp) + 2));
3949 if (p != NULL) 3922 if (p != NULL)
3958 /* 3931 /*
3959 * For each file name in files[num_files]: 3932 * For each file name in files[num_files]:
3960 * If 'orig_pat' starts with "~/", replace the home directory with "~". 3933 * If 'orig_pat' starts with "~/", replace the home directory with "~".
3961 */ 3934 */
3962 void 3935 void
3963 tilde_replace(orig_pat, num_files, files) 3936 tilde_replace(
3964 char_u *orig_pat; 3937 char_u *orig_pat,
3965 int num_files; 3938 int num_files,
3966 char_u **files; 3939 char_u **files)
3967 { 3940 {
3968 int i; 3941 int i;
3969 char_u *p; 3942 char_u *p;
3970 3943
3971 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) 3944 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1]))
3986 * Show all matches for completion on the command line. 3959 * Show all matches for completion on the command line.
3987 * Returns EXPAND_NOTHING when the character that triggered expansion should 3960 * Returns EXPAND_NOTHING when the character that triggered expansion should
3988 * be inserted like a normal character. 3961 * be inserted like a normal character.
3989 */ 3962 */
3990 static int 3963 static int
3991 showmatches(xp, wildmenu) 3964 showmatches(expand_T *xp, int wildmenu UNUSED)
3992 expand_T *xp;
3993 int wildmenu UNUSED;
3994 { 3965 {
3995 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) 3966 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m])
3996 int num_files; 3967 int num_files;
3997 char_u **files_found; 3968 char_u **files_found;
3998 int i, j, k; 3969 int i, j, k;
4170 /* 4141 /*
4171 * Private gettail for showmatches() (and win_redr_status_matches()): 4142 * Private gettail for showmatches() (and win_redr_status_matches()):
4172 * Find tail of file name path, but ignore trailing "/". 4143 * Find tail of file name path, but ignore trailing "/".
4173 */ 4144 */
4174 char_u * 4145 char_u *
4175 sm_gettail(s) 4146 sm_gettail(char_u *s)
4176 char_u *s;
4177 { 4147 {
4178 char_u *p; 4148 char_u *p;
4179 char_u *t = s; 4149 char_u *t = s;
4180 int had_sep = FALSE; 4150 int had_sep = FALSE;
4181 4151
4201 * Return TRUE if we only need to show the tail of completion matches. 4171 * Return TRUE if we only need to show the tail of completion matches.
4202 * When not completing file names or there is a wildcard in the path FALSE is 4172 * When not completing file names or there is a wildcard in the path FALSE is
4203 * returned. 4173 * returned.
4204 */ 4174 */
4205 static int 4175 static int
4206 expand_showtail(xp) 4176 expand_showtail(expand_T *xp)
4207 expand_T *xp;
4208 { 4177 {
4209 char_u *s; 4178 char_u *s;
4210 char_u *end; 4179 char_u *end;
4211 4180
4212 /* When not completing file names a "/" may mean something different. */ 4181 /* When not completing file names a "/" may mean something different. */
4237 * Copy "fname[len]" into allocated memory and add a '*' at the end. 4206 * Copy "fname[len]" into allocated memory and add a '*' at the end.
4238 * When expanding other names: The string will be used with regcomp(). Copy 4207 * When expanding other names: The string will be used with regcomp(). Copy
4239 * the name into allocated memory and prepend "^". 4208 * the name into allocated memory and prepend "^".
4240 */ 4209 */
4241 char_u * 4210 char_u *
4242 addstar(fname, len, context) 4211 addstar(
4243 char_u *fname; 4212 char_u *fname,
4244 int len; 4213 int len,
4245 int context; /* EXPAND_FILES etc. */ 4214 int context) /* EXPAND_FILES etc. */
4246 { 4215 {
4247 char_u *retval; 4216 char_u *retval;
4248 int i, j; 4217 int i, j;
4249 int new_len; 4218 int new_len;
4250 char_u *tail; 4219 char_u *tail;
4406 * names in expressions, eg :while s^I 4375 * names in expressions, eg :while s^I
4407 * EXPAND_ENV_VARS Complete environment variable names 4376 * EXPAND_ENV_VARS Complete environment variable names
4408 * EXPAND_USER Complete user names 4377 * EXPAND_USER Complete user names
4409 */ 4378 */
4410 static void 4379 static void
4411 set_expand_context(xp) 4380 set_expand_context(expand_T *xp)
4412 expand_T *xp;
4413 { 4381 {
4414 /* only expansion for ':', '>' and '=' command-lines */ 4382 /* only expansion for ':', '>' and '=' command-lines */
4415 if (ccline.cmdfirstc != ':' 4383 if (ccline.cmdfirstc != ':'
4416 #ifdef FEAT_EVAL 4384 #ifdef FEAT_EVAL
4417 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' 4385 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '='
4424 } 4392 }
4425 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos); 4393 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos);
4426 } 4394 }
4427 4395
4428 void 4396 void
4429 set_cmd_context(xp, str, len, col) 4397 set_cmd_context(
4430 expand_T *xp; 4398 expand_T *xp,
4431 char_u *str; /* start of command line */ 4399 char_u *str, /* start of command line */
4432 int len; /* length of command line (excl. NUL) */ 4400 int len, /* length of command line (excl. NUL) */
4433 int col; /* position of cursor */ 4401 int col) /* position of cursor */
4434 { 4402 {
4435 int old_char = NUL; 4403 int old_char = NUL;
4436 char_u *nextcomm; 4404 char_u *nextcomm;
4437 4405
4438 /* 4406 /*
4483 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the 4451 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the
4484 * key that triggered expansion literally. 4452 * key that triggered expansion literally.
4485 * Returns EXPAND_OK otherwise. 4453 * Returns EXPAND_OK otherwise.
4486 */ 4454 */
4487 int 4455 int
4488 expand_cmdline(xp, str, col, matchcount, matches) 4456 expand_cmdline(
4489 expand_T *xp; 4457 expand_T *xp,
4490 char_u *str; /* start of command line */ 4458 char_u *str, /* start of command line */
4491 int col; /* position of cursor */ 4459 int col, /* position of cursor */
4492 int *matchcount; /* return: nr of matches */ 4460 int *matchcount, /* return: nr of matches */
4493 char_u ***matches; /* return: array of pointers to matches */ 4461 char_u ***matches) /* return: array of pointers to matches */
4494 { 4462 {
4495 char_u *file_str = NULL; 4463 char_u *file_str = NULL;
4496 int options = WILD_ADD_SLASH|WILD_SILENT; 4464 int options = WILD_ADD_SLASH|WILD_SILENT;
4497 4465
4498 if (xp->xp_context == EXPAND_UNSUCCESSFUL) 4466 if (xp->xp_context == EXPAND_UNSUCCESSFUL)
4531 * Cleanup matches for help tags: remove "@en" if "en" is the only language. 4499 * Cleanup matches for help tags: remove "@en" if "en" is the only language.
4532 */ 4500 */
4533 static void cleanup_help_tags(int num_file, char_u **file); 4501 static void cleanup_help_tags(int num_file, char_u **file);
4534 4502
4535 static void 4503 static void
4536 cleanup_help_tags(num_file, file) 4504 cleanup_help_tags(int num_file, char_u **file)
4537 int num_file;
4538 char_u **file;
4539 { 4505 {
4540 int i, j; 4506 int i, j;
4541 int len; 4507 int len;
4542 4508
4543 for (i = 0; i < num_file; ++i) 4509 for (i = 0; i < num_file; ++i)
4561 4527
4562 /* 4528 /*
4563 * Do the expansion based on xp->xp_context and "pat". 4529 * Do the expansion based on xp->xp_context and "pat".
4564 */ 4530 */
4565 static int 4531 static int
4566 ExpandFromContext(xp, pat, num_file, file, options) 4532 ExpandFromContext(
4567 expand_T *xp; 4533 expand_T *xp,
4568 char_u *pat; 4534 char_u *pat,
4569 int *num_file; 4535 int *num_file,
4570 char_u ***file; 4536 char_u ***file,
4571 int options; /* EW_ flags */ 4537 int options) /* EW_ flags */
4572 { 4538 {
4573 #ifdef FEAT_CMDL_COMPL 4539 #ifdef FEAT_CMDL_COMPL
4574 regmatch_T regmatch; 4540 regmatch_T regmatch;
4575 #endif 4541 #endif
4576 int ret; 4542 int ret;
4797 * program. Matching strings are copied into an array, which is returned. 4763 * program. Matching strings are copied into an array, which is returned.
4798 * 4764 *
4799 * Returns OK when no problems encountered, FAIL for error (out of memory). 4765 * Returns OK when no problems encountered, FAIL for error (out of memory).
4800 */ 4766 */
4801 int 4767 int
4802 ExpandGeneric(xp, regmatch, num_file, file, func, escaped) 4768 ExpandGeneric(
4803 expand_T *xp; 4769 expand_T *xp,
4804 regmatch_T *regmatch; 4770 regmatch_T *regmatch,
4805 int *num_file; 4771 int *num_file,
4806 char_u ***file; 4772 char_u ***file,
4807 char_u *((*func)(expand_T *, int)); 4773 char_u *((*func)(expand_T *, int)),
4808 /* returns a string from the list */ 4774 /* returns a string from the list */
4809 int escaped; 4775 int escaped)
4810 { 4776 {
4811 int i; 4777 int i;
4812 int count = 0; 4778 int count = 0;
4813 int round; 4779 int round;
4814 char_u *str; 4780 char_u *str;
4889 /* 4855 /*
4890 * Complete a shell command. 4856 * Complete a shell command.
4891 * Returns FAIL or OK; 4857 * Returns FAIL or OK;
4892 */ 4858 */
4893 static int 4859 static int
4894 expand_shellcmd(filepat, num_file, file, flagsarg) 4860 expand_shellcmd(
4895 char_u *filepat; /* pattern to match with command names */ 4861 char_u *filepat, /* pattern to match with command names */
4896 int *num_file; /* return: number of matches */ 4862 int *num_file, /* return: number of matches */
4897 char_u ***file; /* return: array with matches */ 4863 char_u ***file, /* return: array with matches */
4898 int flagsarg; /* EW_ flags */ 4864 int flagsarg) /* EW_ flags */
4899 { 4865 {
4900 char_u *pat; 4866 char_u *pat;
4901 int i; 4867 int i;
4902 char_u *path; 4868 char_u *path;
4903 int mustfree = FALSE; 4869 int mustfree = FALSE;
5014 /* 4980 /*
5015 * Call "user_expand_func()" to invoke a user defined VimL function and return 4981 * Call "user_expand_func()" to invoke a user defined VimL function and return
5016 * the result (either a string or a List). 4982 * the result (either a string or a List).
5017 */ 4983 */
5018 static void * 4984 static void *
5019 call_user_expand_func(user_expand_func, xp, num_file, file) 4985 call_user_expand_func(
5020 void *(*user_expand_func)(char_u *, int, char_u **, int); 4986 void *(*user_expand_func)(char_u *, int, char_u **, int),
5021 expand_T *xp; 4987 expand_T *xp,
5022 int *num_file; 4988 int *num_file,
5023 char_u ***file; 4989 char_u ***file)
5024 { 4990 {
5025 int keep = 0; 4991 int keep = 0;
5026 char_u num[50]; 4992 char_u num[50];
5027 char_u *args[3]; 4993 char_u *args[3];
5028 int save_current_SID = current_SID; 4994 int save_current_SID = current_SID;
5064 5030
5065 /* 5031 /*
5066 * Expand names with a function defined by the user. 5032 * Expand names with a function defined by the user.
5067 */ 5033 */
5068 static int 5034 static int
5069 ExpandUserDefined(xp, regmatch, num_file, file) 5035 ExpandUserDefined(
5070 expand_T *xp; 5036 expand_T *xp,
5071 regmatch_T *regmatch; 5037 regmatch_T *regmatch,
5072 int *num_file; 5038 int *num_file,
5073 char_u ***file; 5039 char_u ***file)
5074 { 5040 {
5075 char_u *retstr; 5041 char_u *retstr;
5076 char_u *s; 5042 char_u *s;
5077 char_u *e; 5043 char_u *e;
5078 char_u keep; 5044 char_u keep;
5117 5083
5118 /* 5084 /*
5119 * Expand names with a list returned by a function defined by the user. 5085 * Expand names with a list returned by a function defined by the user.
5120 */ 5086 */
5121 static int 5087 static int
5122 ExpandUserList(xp, num_file, file) 5088 ExpandUserList(
5123 expand_T *xp; 5089 expand_T *xp,
5124 int *num_file; 5090 int *num_file,
5125 char_u ***file; 5091 char_u ***file)
5126 { 5092 {
5127 list_T *retlist; 5093 list_T *retlist;
5128 listitem_T *li; 5094 listitem_T *li;
5129 garray_T ga; 5095 garray_T ga;
5130 5096
5158 * Expand color scheme, compiler or filetype names: 5124 * Expand color scheme, compiler or filetype names:
5159 * 'runtimepath'/{dirnames}/{pat}.vim 5125 * 'runtimepath'/{dirnames}/{pat}.vim
5160 * "dirnames" is an array with one or more directory names. 5126 * "dirnames" is an array with one or more directory names.
5161 */ 5127 */
5162 static int 5128 static int
5163 ExpandRTDir(pat, num_file, file, dirnames) 5129 ExpandRTDir(
5164 char_u *pat; 5130 char_u *pat,
5165 int *num_file; 5131 int *num_file,
5166 char_u ***file; 5132 char_u ***file,
5167 char *dirnames[]; 5133 char *dirnames[])
5168 { 5134 {
5169 char_u *s; 5135 char_u *s;
5170 char_u *e; 5136 char_u *e;
5171 char_u *match; 5137 char_u *match;
5172 garray_T ga; 5138 garray_T ga;
5226 /* 5192 /*
5227 * Expand "file" for all comma-separated directories in "path". 5193 * Expand "file" for all comma-separated directories in "path".
5228 * Adds the matches to "ga". Caller must init "ga". 5194 * Adds the matches to "ga". Caller must init "ga".
5229 */ 5195 */
5230 void 5196 void
5231 globpath(path, file, ga, expand_options) 5197 globpath(
5232 char_u *path; 5198 char_u *path,
5233 char_u *file; 5199 char_u *file,
5234 garray_T *ga; 5200 garray_T *ga,
5235 int expand_options; 5201 int expand_options)
5236 { 5202 {
5237 expand_T xpc; 5203 expand_T xpc;
5238 char_u *buf; 5204 char_u *buf;
5239 int i; 5205 int i;
5240 int num_p; 5206 int num_p;
5296 5262
5297 /* 5263 /*
5298 * Translate a history character to the associated type number. 5264 * Translate a history character to the associated type number.
5299 */ 5265 */
5300 static int 5266 static int
5301 hist_char2type(c) 5267 hist_char2type(int c)
5302 int c;
5303 { 5268 {
5304 if (c == ':') 5269 if (c == ':')
5305 return HIST_CMD; 5270 return HIST_CMD;
5306 if (c == '=') 5271 if (c == '=')
5307 return HIST_EXPR; 5272 return HIST_EXPR;
5332 /* 5297 /*
5333 * Function given to ExpandGeneric() to obtain the possible first 5298 * Function given to ExpandGeneric() to obtain the possible first
5334 * arguments of the ":history command. 5299 * arguments of the ":history command.
5335 */ 5300 */
5336 static char_u * 5301 static char_u *
5337 get_history_arg(xp, idx) 5302 get_history_arg(expand_T *xp UNUSED, int idx)
5338 expand_T *xp UNUSED;
5339 int idx;
5340 { 5303 {
5341 static char_u compl[2] = { NUL, NUL }; 5304 static char_u compl[2] = { NUL, NUL };
5342 char *short_names = ":=@>?/"; 5305 char *short_names = ":=@>?/";
5343 int short_names_count = (int)STRLEN(short_names); 5306 int short_names_count = (int)STRLEN(short_names);
5344 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; 5307 int history_name_count = sizeof(history_names) / sizeof(char *) - 1;
5359 /* 5322 /*
5360 * init_history() - Initialize the command line history. 5323 * init_history() - Initialize the command line history.
5361 * Also used to re-allocate the history when the size changes. 5324 * Also used to re-allocate the history when the size changes.
5362 */ 5325 */
5363 void 5326 void
5364 init_history() 5327 init_history(void)
5365 { 5328 {
5366 int newlen; /* new length of history table */ 5329 int newlen; /* new length of history table */
5367 histentry_T *temp; 5330 histentry_T *temp;
5368 int i; 5331 int i;
5369 int j; 5332 int j;
5437 hislen = newlen; 5400 hislen = newlen;
5438 } 5401 }
5439 } 5402 }
5440 5403
5441 static void 5404 static void
5442 clear_hist_entry(hisptr) 5405 clear_hist_entry(histentry_T *hisptr)
5443 histentry_T *hisptr;
5444 { 5406 {
5445 hisptr->hisnum = 0; 5407 hisptr->hisnum = 0;
5446 hisptr->viminfo = FALSE; 5408 hisptr->viminfo = FALSE;
5447 hisptr->hisstr = NULL; 5409 hisptr->hisstr = NULL;
5448 } 5410 }
5450 /* 5412 /*
5451 * Check if command line 'str' is already in history. 5413 * Check if command line 'str' is already in history.
5452 * If 'move_to_front' is TRUE, matching entry is moved to end of history. 5414 * If 'move_to_front' is TRUE, matching entry is moved to end of history.
5453 */ 5415 */
5454 static int 5416 static int
5455 in_history(type, str, move_to_front, sep, writing) 5417 in_history(
5456 int type; 5418 int type,
5457 char_u *str; 5419 char_u *str,
5458 int move_to_front; /* Move the entry to the front if it exists */ 5420 int move_to_front, /* Move the entry to the front if it exists */
5459 int sep; 5421 int sep,
5460 int writing; /* ignore entries read from viminfo */ 5422 int writing) /* ignore entries read from viminfo */
5461 { 5423 {
5462 int i; 5424 int i;
5463 int last_i = -1; 5425 int last_i = -1;
5464 char_u *p; 5426 char_u *p;
5465 5427
5509 * Convert history name (from table above) to its HIST_ equivalent. 5471 * Convert history name (from table above) to its HIST_ equivalent.
5510 * When "name" is empty, return "cmd" history. 5472 * When "name" is empty, return "cmd" history.
5511 * Returns -1 for unknown history name. 5473 * Returns -1 for unknown history name.
5512 */ 5474 */
5513 int 5475 int
5514 get_histtype(name) 5476 get_histtype(char_u *name)
5515 char_u *name;
5516 { 5477 {
5517 int i; 5478 int i;
5518 int len = (int)STRLEN(name); 5479 int len = (int)STRLEN(name);
5519 5480
5520 /* No argument: use current history. */ 5481 /* No argument: use current history. */
5537 * Add the given string to the given history. If the string is already in the 5498 * Add the given string to the given history. If the string is already in the
5538 * history then it is moved to the front. "histype" may be one of he HIST_ 5499 * history then it is moved to the front. "histype" may be one of he HIST_
5539 * values. 5500 * values.
5540 */ 5501 */
5541 void 5502 void
5542 add_to_history(histype, new_entry, in_map, sep) 5503 add_to_history(
5543 int histype; 5504 int histype,
5544 char_u *new_entry; 5505 char_u *new_entry,
5545 int in_map; /* consider maptick when inside a mapping */ 5506 int in_map, /* consider maptick when inside a mapping */
5546 int sep; /* separator character used (search hist) */ 5507 int sep) /* separator character used (search hist) */
5547 { 5508 {
5548 histentry_T *hisptr; 5509 histentry_T *hisptr;
5549 int len; 5510 int len;
5550 5511
5551 if (hislen == 0) /* no history */ 5512 if (hislen == 0) /* no history */
5598 /* 5559 /*
5599 * Get identifier of newest history entry. 5560 * Get identifier of newest history entry.
5600 * "histype" may be one of the HIST_ values. 5561 * "histype" may be one of the HIST_ values.
5601 */ 5562 */
5602 int 5563 int
5603 get_history_idx(histype) 5564 get_history_idx(int histype)
5604 int histype;
5605 { 5565 {
5606 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT 5566 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT
5607 || hisidx[histype] < 0) 5567 || hisidx[histype] < 0)
5608 return -1; 5568 return -1;
5609 5569
5615 /* 5575 /*
5616 * Get pointer to the command line info to use. cmdline_paste() may clear 5576 * Get pointer to the command line info to use. cmdline_paste() may clear
5617 * ccline and put the previous value in prev_ccline. 5577 * ccline and put the previous value in prev_ccline.
5618 */ 5578 */
5619 static struct cmdline_info * 5579 static struct cmdline_info *
5620 get_ccline_ptr() 5580 get_ccline_ptr(void)
5621 { 5581 {
5622 if ((State & CMDLINE) == 0) 5582 if ((State & CMDLINE) == 0)
5623 return NULL; 5583 return NULL;
5624 if (ccline.cmdbuff != NULL) 5584 if (ccline.cmdbuff != NULL)
5625 return &ccline; 5585 return &ccline;
5632 * Get the current command line in allocated memory. 5592 * Get the current command line in allocated memory.
5633 * Only works when the command line is being edited. 5593 * Only works when the command line is being edited.
5634 * Returns NULL when something is wrong. 5594 * Returns NULL when something is wrong.
5635 */ 5595 */
5636 char_u * 5596 char_u *
5637 get_cmdline_str() 5597 get_cmdline_str(void)
5638 { 5598 {
5639 struct cmdline_info *p = get_ccline_ptr(); 5599 struct cmdline_info *p = get_ccline_ptr();
5640 5600
5641 if (p == NULL) 5601 if (p == NULL)
5642 return NULL; 5602 return NULL;
5648 * Zero is the first position. 5608 * Zero is the first position.
5649 * Only works when the command line is being edited. 5609 * Only works when the command line is being edited.
5650 * Returns -1 when something is wrong. 5610 * Returns -1 when something is wrong.
5651 */ 5611 */
5652 int 5612 int
5653 get_cmdline_pos() 5613 get_cmdline_pos(void)
5654 { 5614 {
5655 struct cmdline_info *p = get_ccline_ptr(); 5615 struct cmdline_info *p = get_ccline_ptr();
5656 5616
5657 if (p == NULL) 5617 if (p == NULL)
5658 return -1; 5618 return -1;
5663 * Set the command line byte position to "pos". Zero is the first position. 5623 * Set the command line byte position to "pos". Zero is the first position.
5664 * Only works when the command line is being edited. 5624 * Only works when the command line is being edited.
5665 * Returns 1 when failed, 0 when OK. 5625 * Returns 1 when failed, 0 when OK.
5666 */ 5626 */
5667 int 5627 int
5668 set_cmdline_pos(pos) 5628 set_cmdline_pos(
5669 int pos; 5629 int pos)
5670 { 5630 {
5671 struct cmdline_info *p = get_ccline_ptr(); 5631 struct cmdline_info *p = get_ccline_ptr();
5672 5632
5673 if (p == NULL) 5633 if (p == NULL)
5674 return 1; 5634 return 1;
5705 * num > 0: seen as identifying number of a history entry 5665 * num > 0: seen as identifying number of a history entry
5706 * num < 0: relative position in history wrt newest entry 5666 * num < 0: relative position in history wrt newest entry
5707 * "histype" may be one of the HIST_ values. 5667 * "histype" may be one of the HIST_ values.
5708 */ 5668 */
5709 static int 5669 static int
5710 calc_hist_idx(histype, num) 5670 calc_hist_idx(int histype, int num)
5711 int histype;
5712 int num;
5713 { 5671 {
5714 int i; 5672 int i;
5715 histentry_T *hist; 5673 histentry_T *hist;
5716 int wrapped = FALSE; 5674 int wrapped = FALSE;
5717 5675
5747 /* 5705 /*
5748 * Get a history entry by its index. 5706 * Get a history entry by its index.
5749 * "histype" may be one of the HIST_ values. 5707 * "histype" may be one of the HIST_ values.
5750 */ 5708 */
5751 char_u * 5709 char_u *
5752 get_history_entry(histype, idx) 5710 get_history_entry(int histype, int idx)
5753 int histype;
5754 int idx;
5755 { 5711 {
5756 idx = calc_hist_idx(histype, idx); 5712 idx = calc_hist_idx(histype, idx);
5757 if (idx >= 0) 5713 if (idx >= 0)
5758 return history[histype][idx].hisstr; 5714 return history[histype][idx].hisstr;
5759 else 5715 else
5763 /* 5719 /*
5764 * Clear all entries of a history. 5720 * Clear all entries of a history.
5765 * "histype" may be one of the HIST_ values. 5721 * "histype" may be one of the HIST_ values.
5766 */ 5722 */
5767 int 5723 int
5768 clr_history(histype) 5724 clr_history(int histype)
5769 int histype;
5770 { 5725 {
5771 int i; 5726 int i;
5772 histentry_T *hisptr; 5727 histentry_T *hisptr;
5773 5728
5774 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) 5729 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT)
5789 /* 5744 /*
5790 * Remove all entries matching {str} from a history. 5745 * Remove all entries matching {str} from a history.
5791 * "histype" may be one of the HIST_ values. 5746 * "histype" may be one of the HIST_ values.
5792 */ 5747 */
5793 int 5748 int
5794 del_history_entry(histype, str) 5749 del_history_entry(int histype, char_u *str)
5795 int histype;
5796 char_u *str;
5797 { 5750 {
5798 regmatch_T regmatch; 5751 regmatch_T regmatch;
5799 histentry_T *hisptr; 5752 histentry_T *hisptr;
5800 int idx; 5753 int idx;
5801 int i; 5754 int i;
5847 /* 5800 /*
5848 * Remove an indexed entry from a history. 5801 * Remove an indexed entry from a history.
5849 * "histype" may be one of the HIST_ values. 5802 * "histype" may be one of the HIST_ values.
5850 */ 5803 */
5851 int 5804 int
5852 del_history_idx(histype, idx) 5805 del_history_idx(int histype, int idx)
5853 int histype;
5854 int idx;
5855 { 5806 {
5856 int i, j; 5807 int i, j;
5857 5808
5858 i = calc_hist_idx(histype, idx); 5809 i = calc_hist_idx(histype, idx);
5859 if (i < 0) 5810 if (i < 0)
5886 /* 5837 /*
5887 * Very specific function to remove the value in ":set key=val" from the 5838 * Very specific function to remove the value in ":set key=val" from the
5888 * history. 5839 * history.
5889 */ 5840 */
5890 void 5841 void
5891 remove_key_from_history() 5842 remove_key_from_history(void)
5892 { 5843 {
5893 char_u *p; 5844 char_u *p;
5894 int i; 5845 int i;
5895 5846
5896 i = hisidx[HIST_CMD]; 5847 i = hisidx[HIST_CMD];
5921 * Get indices "num1,num2" that specify a range within a list (not a range of 5872 * Get indices "num1,num2" that specify a range within a list (not a range of
5922 * text lines in a buffer!) from a string. Used for ":history" and ":clist". 5873 * text lines in a buffer!) from a string. Used for ":history" and ":clist".
5923 * Returns OK if parsed successfully, otherwise FAIL. 5874 * Returns OK if parsed successfully, otherwise FAIL.
5924 */ 5875 */
5925 int 5876 int
5926 get_list_range(str, num1, num2) 5877 get_list_range(char_u **str, int *num1, int *num2)
5927 char_u **str;
5928 int *num1;
5929 int *num2;
5930 { 5878 {
5931 int len; 5879 int len;
5932 int first = FALSE; 5880 int first = FALSE;
5933 long num; 5881 long num;
5934 5882
5962 #if defined(FEAT_CMDHIST) || defined(PROTO) 5910 #if defined(FEAT_CMDHIST) || defined(PROTO)
5963 /* 5911 /*
5964 * :history command - print a history 5912 * :history command - print a history
5965 */ 5913 */
5966 void 5914 void
5967 ex_history(eap) 5915 ex_history(exarg_T *eap)
5968 exarg_T *eap;
5969 { 5916 {
5970 histentry_T *hist; 5917 histentry_T *hist;
5971 int histype1 = HIST_CMD; 5918 int histype1 = HIST_CMD;
5972 int histype2 = HIST_CMD; 5919 int histype2 = HIST_CMD;
5973 int hisidx1 = 1; 5920 int hisidx1 = 1;
6070 6017
6071 /* 6018 /*
6072 * Translate a history type number to the associated character. 6019 * Translate a history type number to the associated character.
6073 */ 6020 */
6074 static int 6021 static int
6075 hist_type2char(type, use_question) 6022 hist_type2char(
6076 int type; 6023 int type,
6077 int use_question; /* use '?' instead of '/' */ 6024 int use_question) /* use '?' instead of '/' */
6078 { 6025 {
6079 if (type == HIST_CMD) 6026 if (type == HIST_CMD)
6080 return ':'; 6027 return ':';
6081 if (type == HIST_SEARCH) 6028 if (type == HIST_SEARCH)
6082 { 6029 {
6093 /* 6040 /*
6094 * Prepare for reading the history from the viminfo file. 6041 * Prepare for reading the history from the viminfo file.
6095 * This allocates history arrays to store the read history lines. 6042 * This allocates history arrays to store the read history lines.
6096 */ 6043 */
6097 void 6044 void
6098 prepare_viminfo_history(asklen, writing) 6045 prepare_viminfo_history(int asklen, int writing)
6099 int asklen;
6100 int writing;
6101 { 6046 {
6102 int i; 6047 int i;
6103 int num; 6048 int num;
6104 int type; 6049 int type;
6105 int len; 6050 int len;
6135 /* 6080 /*
6136 * Accept a line from the viminfo, store it in the history array when it's 6081 * Accept a line from the viminfo, store it in the history array when it's
6137 * new. 6082 * new.
6138 */ 6083 */
6139 int 6084 int
6140 read_viminfo_history(virp, writing) 6085 read_viminfo_history(vir_T *virp, int writing)
6141 vir_T *virp;
6142 int writing;
6143 { 6086 {
6144 int type; 6087 int type;
6145 long_u len; 6088 long_u len;
6146 char_u *val; 6089 char_u *val;
6147 char_u *p; 6090 char_u *p;
6187 6130
6188 /* 6131 /*
6189 * Finish reading history lines from viminfo. Not used when writing viminfo. 6132 * Finish reading history lines from viminfo. Not used when writing viminfo.
6190 */ 6133 */
6191 void 6134 void
6192 finish_viminfo_history() 6135 finish_viminfo_history(void)
6193 { 6136 {
6194 int idx; 6137 int idx;
6195 int i; 6138 int i;
6196 int type; 6139 int type;
6197 6140
6247 * When "merge" is TRUE merge history lines with a previously read viminfo 6190 * When "merge" is TRUE merge history lines with a previously read viminfo
6248 * file, data is in viminfo_history[]. 6191 * file, data is in viminfo_history[].
6249 * When "merge" is FALSE just write all history lines. Used for ":wviminfo!". 6192 * When "merge" is FALSE just write all history lines. Used for ":wviminfo!".
6250 */ 6193 */
6251 void 6194 void
6252 write_viminfo_history(fp, merge) 6195 write_viminfo_history(
6253 FILE *fp; 6196 FILE *fp,
6254 int merge; 6197 int merge)
6255 { 6198 {
6256 int i; 6199 int i;
6257 int type; 6200 int type;
6258 int num_saved; 6201 int num_saved;
6259 char_u *p; 6202 char_u *p;
6346 /* 6289 /*
6347 * Write a character at the current cursor+offset position. 6290 * Write a character at the current cursor+offset position.
6348 * It is directly written into the command buffer block. 6291 * It is directly written into the command buffer block.
6349 */ 6292 */
6350 void 6293 void
6351 cmd_pchar(c, offset) 6294 cmd_pchar(int c, int offset)
6352 int c, offset;
6353 { 6295 {
6354 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) 6296 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0)
6355 { 6297 {
6356 EMSG(_("E198: cmd_pchar beyond the command length")); 6298 EMSG(_("E198: cmd_pchar beyond the command length"));
6357 return; 6299 return;
6359 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; 6301 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c;
6360 ccline.cmdbuff[ccline.cmdlen] = NUL; 6302 ccline.cmdbuff[ccline.cmdlen] = NUL;
6361 } 6303 }
6362 6304
6363 int 6305 int
6364 cmd_gchar(offset) 6306 cmd_gchar(int offset)
6365 int offset;
6366 { 6307 {
6367 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) 6308 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0)
6368 { 6309 {
6369 /* EMSG(_("cmd_gchar beyond the command length")); */ 6310 /* EMSG(_("cmd_gchar beyond the command length")); */
6370 return NUL; 6311 return NUL;
6381 * CR if the command is to be executed 6322 * CR if the command is to be executed
6382 * Ctrl_C if it is to be abandoned 6323 * Ctrl_C if it is to be abandoned
6383 * K_IGNORE if editing continues 6324 * K_IGNORE if editing continues
6384 */ 6325 */
6385 static int 6326 static int
6386 ex_window() 6327 ex_window(void)
6387 { 6328 {
6388 struct cmdline_info save_ccline; 6329 struct cmdline_info save_ccline;
6389 buf_T *old_curbuf = curbuf; 6330 buf_T *old_curbuf = curbuf;
6390 win_T *old_curwin = curwin; 6331 win_T *old_curwin = curwin;
6391 buf_T *bp; 6332 buf_T *bp;
6672 * {script} 6613 * {script}
6673 * endmarker 6614 * endmarker
6674 * Returns a pointer to allocated memory with {script} or NULL. 6615 * Returns a pointer to allocated memory with {script} or NULL.
6675 */ 6616 */
6676 char_u * 6617 char_u *
6677 script_get(eap, cmd) 6618 script_get(exarg_T *eap, char_u *cmd)
6678 exarg_T *eap;
6679 char_u *cmd;
6680 { 6619 {
6681 char_u *theline; 6620 char_u *theline;
6682 char *end_pattern = NULL; 6621 char *end_pattern = NULL;
6683 char dot[] = "."; 6622 char dot[] = ".";
6684 garray_T ga; 6623 garray_T ga;