comparison src/os_unix.c @ 1508:c89903e16772 v7.1.223

updated for version 7.1-223
author vimboss
date Sun, 13 Jan 2008 12:54:11 +0000
parents ae7e29b64923
children 56fb4ab9f62f
comparison
equal deleted inserted replaced
1507:a6776e2c9f01 1508:c89903e16772
4944 int i; 4944 int i;
4945 size_t len; 4945 size_t len;
4946 char_u *p; 4946 char_u *p;
4947 int dir; 4947 int dir;
4948 #ifdef __EMX__ 4948 #ifdef __EMX__
4949 /*
4950 * This is the OS/2 implementation.
4951 */
4949 # define EXPL_ALLOC_INC 16 4952 # define EXPL_ALLOC_INC 16
4950 char_u **expl_files; 4953 char_u **expl_files;
4951 size_t files_alloced, files_free; 4954 size_t files_alloced, files_free;
4952 char_u *buf; 4955 char_u *buf;
4953 int has_wildcard; 4956 int has_wildcard;
5054 } 5057 }
5055 } 5058 }
5056 return OK; 5059 return OK;
5057 5060
5058 #else /* __EMX__ */ 5061 #else /* __EMX__ */
5059 5062 /*
5063 * This is the non-OS/2 implementation (really Unix).
5064 */
5060 int j; 5065 int j;
5061 char_u *tempname; 5066 char_u *tempname;
5062 char_u *command; 5067 char_u *command;
5063 FILE *fd; 5068 FILE *fd;
5064 char_u *buffer; 5069 char_u *buffer;
5065 #define STYLE_ECHO 0 /* use "echo" to expand */ 5070 #define STYLE_ECHO 0 /* use "echo", the default */
5066 #define STYLE_GLOB 1 /* use "glob" to expand, for csh */ 5071 #define STYLE_GLOB 1 /* use "glob", for csh */
5067 #define STYLE_PRINT 2 /* use "print -N" to expand, for zsh */ 5072 #define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */
5068 #define STYLE_BT 3 /* `cmd` expansion, execute the pattern directly */ 5073 #define STYLE_PRINT 3 /* use "print -N", for zsh */
5074 #define STYLE_BT 4 /* `cmd` expansion, execute the pattern
5075 * directly */
5069 int shell_style = STYLE_ECHO; 5076 int shell_style = STYLE_ECHO;
5070 int check_spaces; 5077 int check_spaces;
5071 static int did_find_nul = FALSE; 5078 static int did_find_nul = FALSE;
5072 int ampersent = FALSE; 5079 int ampersent = FALSE;
5080 /* vimglob() function to define for Posix shell */
5081 static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo -n \"$1\"; echo; shift; done }; vimglob >";
5073 5082
5074 *num_file = 0; /* default: no files found */ 5083 *num_file = 0; /* default: no files found */
5075 *file = NULL; 5084 *file = NULL;
5076 5085
5077 /* 5086 /*
5105 return FAIL; 5114 return FAIL;
5106 } 5115 }
5107 5116
5108 /* 5117 /*
5109 * Let the shell expand the patterns and write the result into the temp 5118 * Let the shell expand the patterns and write the result into the temp
5110 * file. if expanding `cmd` execute it directly. 5119 * file.
5111 * If we use csh, glob will work better than echo. 5120 * STYLE_BT: NL separated
5112 * If we use zsh, print -N will work better than glob. 5121 * If expanding `cmd` execute it directly.
5122 * STYLE_GLOB: NUL separated
5123 * If we use *csh, "glob" will work better than "echo".
5124 * STYLE_PRINT: NL or NUL separated
5125 * If we use *zsh, "print -N" will work better than "glob".
5126 * STYLE_VIMGLOB: NL separated
5127 * If we use *sh*, we define "vimglob()".
5128 * STYLE_ECHO: space separated.
5129 * A shell we don't know, stay safe and use "echo".
5113 */ 5130 */
5114 if (num_pat == 1 && *pat[0] == '`' 5131 if (num_pat == 1 && *pat[0] == '`'
5115 && (len = STRLEN(pat[0])) > 2 5132 && (len = STRLEN(pat[0])) > 2
5116 && *(pat[0] + len - 1) == '`') 5133 && *(pat[0] + len - 1) == '`')
5117 shell_style = STYLE_BT; 5134 shell_style = STYLE_BT;
5120 if (STRCMP(p_sh + len - 3, "csh") == 0) 5137 if (STRCMP(p_sh + len - 3, "csh") == 0)
5121 shell_style = STYLE_GLOB; 5138 shell_style = STYLE_GLOB;
5122 else if (STRCMP(p_sh + len - 3, "zsh") == 0) 5139 else if (STRCMP(p_sh + len - 3, "zsh") == 0)
5123 shell_style = STYLE_PRINT; 5140 shell_style = STYLE_PRINT;
5124 } 5141 }
5125 5142 if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh),
5126 /* "unset nonomatch; print -N >" plus two is 29 */ 5143 "sh") != NULL)
5144 shell_style = STYLE_VIMGLOB;
5145
5146 /* Compute the length of the command. We need 2 extra bytes: for the
5147 * optional '&' and for the NUL.
5148 * Worst case: "unset nonomatch; print -N >" plus two is 29 */
5127 len = STRLEN(tempname) + 29; 5149 len = STRLEN(tempname) + 29;
5150 if (shell_style == STYLE_VIMGLOB)
5151 len += STRLEN(sh_vimglob_func);
5152
5128 for (i = 0; i < num_pat; ++i) 5153 for (i = 0; i < num_pat; ++i)
5129 { 5154 {
5130 /* Count the length of the patterns in the same way as they are put in 5155 /* Count the length of the patterns in the same way as they are put in
5131 * "command" below. */ 5156 * "command" below. */
5132 #ifdef USE_SYSTEM 5157 #ifdef USE_SYSTEM
5181 STRCPY(command, "unset nonomatch; "); 5206 STRCPY(command, "unset nonomatch; ");
5182 if (shell_style == STYLE_GLOB) 5207 if (shell_style == STYLE_GLOB)
5183 STRCAT(command, "glob >"); 5208 STRCAT(command, "glob >");
5184 else if (shell_style == STYLE_PRINT) 5209 else if (shell_style == STYLE_PRINT)
5185 STRCAT(command, "print -N >"); 5210 STRCAT(command, "print -N >");
5211 else if (shell_style == STYLE_VIMGLOB)
5212 STRCAT(command, sh_vimglob_func);
5186 else 5213 else
5187 STRCAT(command, "echo >"); 5214 STRCAT(command, "echo >");
5188 } 5215 }
5216
5189 STRCAT(command, tempname); 5217 STRCAT(command, tempname);
5218
5190 if (shell_style != STYLE_BT) 5219 if (shell_style != STYLE_BT)
5191 for (i = 0; i < num_pat; ++i) 5220 for (i = 0; i < num_pat; ++i)
5192 { 5221 {
5193 /* When using system() always add extra quotes, because the shell 5222 /* When using system() always add extra quotes, because the shell
5194 * is started twice. Otherwise put a backslash before special 5223 * is started twice. Otherwise put a backslash before special
5230 #endif 5259 #endif
5231 } 5260 }
5232 if (flags & EW_SILENT) 5261 if (flags & EW_SILENT)
5233 show_shell_mess = FALSE; 5262 show_shell_mess = FALSE;
5234 if (ampersent) 5263 if (ampersent)
5235 STRCAT(command, "&"); /* put the '&' back after the 5264 STRCAT(command, "&"); /* put the '&' after the redirection */
5236 redirection */
5237 5265
5238 /* 5266 /*
5239 * Using zsh -G: If a pattern has no matches, it is just deleted from 5267 * Using zsh -G: If a pattern has no matches, it is just deleted from
5240 * the argument list, otherwise zsh gives an error message and doesn't 5268 * the argument list, otherwise zsh gives an error message and doesn't
5241 * expand any other pattern. 5269 * expand any other pattern.
5263 5291
5264 extra_shell_arg = NULL; /* cleanup */ 5292 extra_shell_arg = NULL; /* cleanup */
5265 show_shell_mess = TRUE; 5293 show_shell_mess = TRUE;
5266 vim_free(command); 5294 vim_free(command);
5267 5295
5268 if (i) /* mch_call_shell() failed */ 5296 if (i != 0) /* mch_call_shell() failed */
5269 { 5297 {
5270 mch_remove(tempname); 5298 mch_remove(tempname);
5271 vim_free(tempname); 5299 vim_free(tempname);
5272 /* 5300 /*
5273 * With interactive completion, the error message is not printed. 5301 * With interactive completion, the error message is not printed.
5334 vim_free(buffer); 5362 vim_free(buffer);
5335 return FAIL; 5363 return FAIL;
5336 } 5364 }
5337 vim_free(tempname); 5365 vim_free(tempname);
5338 5366
5339 #if defined(__CYGWIN__) || defined(__CYGWIN32__) 5367 # if defined(__CYGWIN__) || defined(__CYGWIN32__)
5340 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ 5368 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */
5341 p = buffer; 5369 p = buffer;
5342 for (i = 0; i < len; ++i) 5370 for (i = 0; i < len; ++i)
5343 if (!(buffer[i] == CAR && buffer[i + 1] == NL)) 5371 if (!(buffer[i] == CAR && buffer[i + 1] == NL))
5344 *p++ = buffer[i]; 5372 *p++ = buffer[i];
5357 ++p; 5385 ++p;
5358 p = skipwhite(p); /* skip to next entry */ 5386 p = skipwhite(p); /* skip to next entry */
5359 } 5387 }
5360 } 5388 }
5361 /* file names are separated with NL */ 5389 /* file names are separated with NL */
5362 else if (shell_style == STYLE_BT) 5390 else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB)
5363 { 5391 {
5364 buffer[len] = NUL; /* make sure the buffer ends in NUL */ 5392 buffer[len] = NUL; /* make sure the buffer ends in NUL */
5365 p = buffer; 5393 p = buffer;
5366 for (i = 0; *p != NUL; ++i) /* count number of entries */ 5394 for (i = 0; *p != NUL; ++i) /* count number of entries */
5367 { 5395 {
5436 p = buffer; 5464 p = buffer;
5437 for (i = 0; i < *num_file; ++i) 5465 for (i = 0; i < *num_file; ++i)
5438 { 5466 {
5439 (*file)[i] = p; 5467 (*file)[i] = p;
5440 /* Space or NL separates */ 5468 /* Space or NL separates */
5441 if (shell_style == STYLE_ECHO || shell_style == STYLE_BT) 5469 if (shell_style == STYLE_ECHO || shell_style == STYLE_BT
5470 || shell_style == STYLE_VIMGLOB)
5442 { 5471 {
5443 while (!(shell_style == STYLE_ECHO && *p == ' ') 5472 while (!(shell_style == STYLE_ECHO && *p == ' ')
5444 && *p != '\n' && *p != NUL) 5473 && *p != '\n' && *p != NUL)
5445 ++p; 5474 ++p;
5446 if (p == buffer + len) /* last entry */ 5475 if (p == buffer + len) /* last entry */