comparison src/misc2.c @ 1661:5bbc2d6658ad v7.2a.013

updated for version 7.2a-013
author vimboss
date Fri, 04 Jul 2008 09:44:11 +0000
parents 82b5078be2dd
children 553c97222cc0
comparison
equal deleted inserted replaced
1660:a0c70314350f 1661:5bbc2d6658ad
1260 #if defined(FEAT_EVAL) || defined(PROTO) 1260 #if defined(FEAT_EVAL) || defined(PROTO)
1261 /* 1261 /*
1262 * Escape "string" for use as a shell argument with system(). 1262 * Escape "string" for use as a shell argument with system().
1263 * This uses single quotes, except when we know we need to use double qoutes 1263 * This uses single quotes, except when we know we need to use double qoutes
1264 * (MS-DOS and MS-Windows without 'shellslash' set). 1264 * (MS-DOS and MS-Windows without 'shellslash' set).
1265 * Also replace "%", "#" and things like "<cfile>" when "do_special" is TRUE.
1265 * Returns the result in allocated memory, NULL if we have run out. 1266 * Returns the result in allocated memory, NULL if we have run out.
1266 */ 1267 */
1267 char_u * 1268 char_u *
1268 vim_strsave_shellescape(string) 1269 vim_strsave_shellescape(string, do_special)
1269 char_u *string; 1270 char_u *string;
1271 int do_special;
1270 { 1272 {
1271 unsigned length; 1273 unsigned length;
1272 char_u *p; 1274 char_u *p;
1273 char_u *d; 1275 char_u *d;
1274 char_u *escaped_string; 1276 char_u *escaped_string;
1277 int l;
1275 1278
1276 /* First count the number of extra bytes required. */ 1279 /* First count the number of extra bytes required. */
1277 length = (unsigned)STRLEN(string) + 3; /* two quotes and a trailing NUL */ 1280 length = (unsigned)STRLEN(string) + 3; /* two quotes and a trailing NUL */
1278 for (p = string; *p != NUL; mb_ptr_adv(p)) 1281 for (p = string; *p != NUL; mb_ptr_adv(p))
1279 { 1282 {
1285 } 1288 }
1286 else 1289 else
1287 # endif 1290 # endif
1288 if (*p == '\'') 1291 if (*p == '\'')
1289 length += 3; /* ' => '\'' */ 1292 length += 3; /* ' => '\'' */
1293 if (do_special && find_cmdline_var(p, &l) >= 0)
1294 {
1295 ++length; /* insert backslash */
1296 p += l - 1;
1297 }
1290 } 1298 }
1291 1299
1292 /* Allocate memory for the result and fill it. */ 1300 /* Allocate memory for the result and fill it. */
1293 escaped_string = alloc(length); 1301 escaped_string = alloc(length);
1294 if (escaped_string != NULL) 1302 if (escaped_string != NULL)
1318 } 1326 }
1319 else 1327 else
1320 # endif 1328 # endif
1321 if (*p == '\'') 1329 if (*p == '\'')
1322 { 1330 {
1323 *d++='\''; 1331 *d++ = '\'';
1324 *d++='\\'; 1332 *d++ = '\\';
1325 *d++='\''; 1333 *d++ = '\'';
1326 *d++='\''; 1334 *d++ = '\'';
1327 ++p; 1335 ++p;
1328 continue; 1336 continue;
1337 }
1338 if (do_special && find_cmdline_var(p, &l) >= 0)
1339 {
1340 *d++ = '\\'; /* insert backslash */
1341 while (--l >= 0) /* copy the var */
1342 *d++ = *p++;
1329 } 1343 }
1330 1344
1331 MB_COPY_CHAR(p, d); 1345 MB_COPY_CHAR(p, d);
1332 } 1346 }
1333 1347
2774 return key_names_table[i].key; 2788 return key_names_table[i].key;
2775 } 2789 }
2776 return 0; 2790 return 0;
2777 } 2791 }
2778 2792
2779 #ifdef FEAT_CMDL_COMPL 2793 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
2780 char_u * 2794 char_u *
2781 get_key_name(i) 2795 get_key_name(i)
2782 int i; 2796 int i;
2783 { 2797 {
2784 if (i >= KEY_NAMES_TABLE_LEN) 2798 if (i >= KEY_NAMES_TABLE_LEN)
2785 return NULL; 2799 return NULL;
2786 return key_names_table[i].name; 2800 return key_names_table[i].name;
2787 } 2801 }
2788 #endif 2802 #endif
2789 2803
2790 #ifdef FEAT_MOUSE 2804 #if defined(FEAT_MOUSE) || defined(PROTO)
2791 /* 2805 /*
2792 * Look up the given mouse code to return the relevant information in the other 2806 * Look up the given mouse code to return the relevant information in the other
2793 * arguments. Return which button is down or was released. 2807 * arguments. Return which button is down or was released.
2794 */ 2808 */
2795 int 2809 int