Mercurial > vim
comparison src/if_cscope.c @ 10373:bd674706408a v8.0.0081
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 12 19:16:46 2016 +0100
patch 8.0.0081
Problem: Inconsistent function names.
Solution: Rename do_cscope to ex_cscope. Clean up comments.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 12 Nov 2016 19:30:04 +0100 |
parents | 66f1b5bf3fa6 |
children | 9279c939391b |
comparison
equal
deleted
inserted
replaced
10372:f99b48e4cb62 | 10373:bd674706408a |
---|---|
199 } | 199 } |
200 | 200 |
201 #endif /* FEAT_CMDL_COMPL */ | 201 #endif /* FEAT_CMDL_COMPL */ |
202 | 202 |
203 /* | 203 /* |
204 * PRIVATE: do_cscope_general | |
205 * | |
206 * Find the command, print help if invalid, and then call the corresponding | 204 * Find the command, print help if invalid, and then call the corresponding |
207 * command function. | 205 * command function. |
208 */ | 206 */ |
209 static void | 207 static void |
210 do_cscope_general( | 208 do_cscope_general( |
240 postponed_split_tab = 0; | 238 postponed_split_tab = 0; |
241 #endif | 239 #endif |
242 } | 240 } |
243 | 241 |
244 /* | 242 /* |
245 * PUBLIC: do_cscope | 243 * Implementation of ":cscope" and ":lcscope" |
246 */ | 244 */ |
247 void | 245 void |
248 do_cscope(exarg_T *eap) | 246 ex_cscope(exarg_T *eap) |
249 { | 247 { |
250 do_cscope_general(eap, FALSE); | 248 do_cscope_general(eap, FALSE); |
251 } | 249 } |
252 | 250 |
253 /* | 251 /* |
254 * PUBLIC: do_scscope | 252 * Implementation of ":scscope". Same as ex_cscope(), but splits window, too. |
255 * | |
256 * same as do_cscope, but splits window, too. | |
257 */ | 253 */ |
258 void | 254 void |
259 do_scscope(exarg_T *eap) | 255 ex_scscope(exarg_T *eap) |
260 { | 256 { |
261 do_cscope_general(eap, TRUE); | 257 do_cscope_general(eap, TRUE); |
262 } | 258 } |
263 | 259 |
264 /* | 260 /* |
265 * PUBLIC: do_cstag | 261 * Implementation of ":cstag" |
266 * | |
267 */ | 262 */ |
268 void | 263 void |
269 do_cstag(exarg_T *eap) | 264 ex_cstag(exarg_T *eap) |
270 { | 265 { |
271 int ret = FALSE; | 266 int ret = FALSE; |
272 | 267 |
273 if (*eap->arg == NUL) | 268 if (*eap->arg == NUL) |
274 { | 269 { |
334 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | 329 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
335 g_do_tagpreview = 0; | 330 g_do_tagpreview = 0; |
336 #endif | 331 #endif |
337 } | 332 } |
338 | 333 |
339 } /* do_cscope */ | 334 } |
340 | 335 |
341 | 336 |
342 /* | 337 /* |
343 * PUBLIC: cs_find | 338 * This simulates a vim_fgets(), but for cscope, returns the next line |
344 * | |
345 * this simulates a vim_fgets(), but for cscope, returns the next line | |
346 * from the cscope output. should only be called from find_tags() | 339 * from the cscope output. should only be called from find_tags() |
347 * | 340 * |
348 * returns TRUE if eof, FALSE otherwise | 341 * returns TRUE if eof, FALSE otherwise |
349 */ | 342 */ |
350 int | 343 int |
359 return FALSE; | 352 return FALSE; |
360 } /* cs_fgets */ | 353 } /* cs_fgets */ |
361 | 354 |
362 | 355 |
363 /* | 356 /* |
364 * PUBLIC: cs_free_tags | 357 * Called only from do_tag(), when popping the tag stack. |
365 * | |
366 * called only from do_tag(), when popping the tag stack | |
367 */ | 358 */ |
368 void | 359 void |
369 cs_free_tags(void) | 360 cs_free_tags(void) |
370 { | 361 { |
371 cs_manage_matches(NULL, NULL, -1, Free); | 362 cs_manage_matches(NULL, NULL, -1, Free); |
372 } | 363 } |
373 | 364 |
374 | 365 |
375 /* | 366 /* |
376 * PUBLIC: cs_print_tags | 367 * Called from do_tag(). |
377 * | |
378 * called from do_tag() | |
379 */ | 368 */ |
380 void | 369 void |
381 cs_print_tags(void) | 370 cs_print_tags(void) |
382 { | 371 { |
383 cs_manage_matches(NULL, NULL, -1, Print); | 372 cs_manage_matches(NULL, NULL, -1, Print); |
465 /* | 454 /* |
466 * PRIVATE functions | 455 * PRIVATE functions |
467 ****************************************************************************/ | 456 ****************************************************************************/ |
468 | 457 |
469 /* | 458 /* |
470 * PRIVATE: cs_add | 459 * Add cscope database or a directory name (to look for cscope.out) |
471 * | 460 * to the cscope connection list. |
472 * add cscope database or a directory name (to look for cscope.out) | |
473 * to the cscope connection list | |
474 * | |
475 * MAXPATHL 256 | |
476 */ | 461 */ |
477 static int | 462 static int |
478 cs_add(exarg_T *eap UNUSED) | 463 cs_add(exarg_T *eap UNUSED) |
479 { | 464 { |
480 char *fname, *ppath, *flags = NULL; | 465 char *fname, *ppath, *flags = NULL; |
506 (void)EMSG(_("E563: stat error")); | 491 (void)EMSG(_("E563: stat error")); |
507 } | 492 } |
508 | 493 |
509 | 494 |
510 /* | 495 /* |
511 * PRIVATE: cs_add_common | 496 * The common routine to add a new cscope connection. Called by |
512 * | 497 * cs_add() and cs_reset(). I really don't like to do this, but this |
513 * the common routine to add a new cscope connection. called by | |
514 * cs_add() and cs_reset(). i really don't like to do this, but this | |
515 * routine uses a number of goto statements. | 498 * routine uses a number of goto statements. |
516 */ | 499 */ |
517 static int | 500 static int |
518 cs_add_common( | 501 cs_add_common( |
519 char *arg1, /* filename - may contain environment variables */ | 502 char *arg1, /* filename - may contain environment variables */ |
664 return (p_tags[0] != NUL && curbuf->b_p_tags != NULL); | 647 return (p_tags[0] != NUL && curbuf->b_p_tags != NULL); |
665 } /* cs_check_for_tags */ | 648 } /* cs_check_for_tags */ |
666 | 649 |
667 | 650 |
668 /* | 651 /* |
669 * PRIVATE: cs_cnt_connections | 652 * Count the number of cscope connections. |
670 * | |
671 * count the number of cscope connections | |
672 */ | 653 */ |
673 static int | 654 static int |
674 cs_cnt_connections(void) | 655 cs_cnt_connections(void) |
675 { | 656 { |
676 short i; | 657 short i; |
691 EMSGN(_("E262: error reading cscope connection %ld"), idx); | 672 EMSGN(_("E262: error reading cscope connection %ld"), idx); |
692 } | 673 } |
693 | 674 |
694 #define CSREAD_BUFSIZE 2048 | 675 #define CSREAD_BUFSIZE 2048 |
695 /* | 676 /* |
696 * PRIVATE: cs_cnt_matches | 677 * Count the number of matches for a given cscope connection. |
697 * | |
698 * count the number of matches for a given cscope connection. | |
699 */ | 678 */ |
700 static int | 679 static int |
701 cs_cnt_matches(int idx) | 680 cs_cnt_matches(int idx) |
702 { | 681 { |
703 char *stok; | 682 char *stok; |
752 return nlines; | 731 return nlines; |
753 } /* cs_cnt_matches */ | 732 } /* cs_cnt_matches */ |
754 | 733 |
755 | 734 |
756 /* | 735 /* |
757 * PRIVATE: cs_create_cmd | |
758 * | |
759 * Creates the actual cscope command query from what the user entered. | 736 * Creates the actual cscope command query from what the user entered. |
760 */ | 737 */ |
761 static char * | 738 static char * |
762 cs_create_cmd(char *csoption, char *pattern) | 739 cs_create_cmd(char *csoption, char *pattern) |
763 { | 740 { |
815 return cmd; | 792 return cmd; |
816 } /* cs_create_cmd */ | 793 } /* cs_create_cmd */ |
817 | 794 |
818 | 795 |
819 /* | 796 /* |
820 * PRIVATE: cs_create_connection | |
821 * | |
822 * This piece of code was taken/adapted from nvi. do we need to add | 797 * This piece of code was taken/adapted from nvi. do we need to add |
823 * the BSD license notice? | 798 * the BSD license notice? |
824 */ | 799 */ |
825 static int | 800 static int |
826 cs_create_connection(int i) | 801 cs_create_connection(int i) |
1054 return CSCOPE_SUCCESS; | 1029 return CSCOPE_SUCCESS; |
1055 } /* cs_create_connection */ | 1030 } /* cs_create_connection */ |
1056 | 1031 |
1057 | 1032 |
1058 /* | 1033 /* |
1059 * PRIVATE: cs_find | |
1060 * | |
1061 * Query cscope using command line interface. Parse the output and use tselect | 1034 * Query cscope using command line interface. Parse the output and use tselect |
1062 * to allow choices. Like Nvi, creates a pipe to send to/from query/cscope. | 1035 * to allow choices. Like Nvi, creates a pipe to send to/from query/cscope. |
1063 * | 1036 * |
1064 * returns TRUE if we jump to a tag or abort, FALSE if not. | 1037 * returns TRUE if we jump to a tag or abort, FALSE if not. |
1065 */ | 1038 */ |
1100 eap->cmdidx == CMD_lcscope, *eap->cmdlinep); | 1073 eap->cmdidx == CMD_lcscope, *eap->cmdlinep); |
1101 } /* cs_find */ | 1074 } /* cs_find */ |
1102 | 1075 |
1103 | 1076 |
1104 /* | 1077 /* |
1105 * PRIVATE: cs_find_common | 1078 * Common code for cscope find, shared by cs_find() and ex_cstag(). |
1106 * | |
1107 * common code for cscope find, shared by cs_find() and do_cstag() | |
1108 */ | 1079 */ |
1109 static int | 1080 static int |
1110 cs_find_common( | 1081 cs_find_common( |
1111 char *opt, | 1082 char *opt, |
1112 char *pat, | 1083 char *pat, |
1321 } | 1292 } |
1322 | 1293 |
1323 } /* cs_find_common */ | 1294 } /* cs_find_common */ |
1324 | 1295 |
1325 /* | 1296 /* |
1326 * PRIVATE: cs_help | 1297 * Print help. |
1327 * | |
1328 * print help | |
1329 */ | 1298 */ |
1330 static int | 1299 static int |
1331 cs_help(exarg_T *eap UNUSED) | 1300 cs_help(exarg_T *eap UNUSED) |
1332 { | 1301 { |
1333 cscmd_T *cmdp = cs_cmds; | 1302 cscmd_T *cmdp = cs_cmds; |
1406 return msg; | 1375 return msg; |
1407 } | 1376 } |
1408 #endif | 1377 #endif |
1409 | 1378 |
1410 /* | 1379 /* |
1411 * PRIVATE: cs_insert_filelist | 1380 * Insert a new cscope database filename into the filelist. |
1412 * | |
1413 * insert a new cscope database filename into the filelist | |
1414 */ | 1381 */ |
1415 static int | 1382 static int |
1416 cs_insert_filelist( | 1383 cs_insert_filelist( |
1417 char *fname, | 1384 char *fname, |
1418 char *ppath, | 1385 char *ppath, |
1549 return i; | 1516 return i; |
1550 } /* cs_insert_filelist */ | 1517 } /* cs_insert_filelist */ |
1551 | 1518 |
1552 | 1519 |
1553 /* | 1520 /* |
1554 * PRIVATE: cs_lookup_cmd | 1521 * Find cscope command in command table. |
1555 * | |
1556 * find cscope command in command table | |
1557 */ | 1522 */ |
1558 static cscmd_T * | 1523 static cscmd_T * |
1559 cs_lookup_cmd(exarg_T *eap) | 1524 cs_lookup_cmd(exarg_T *eap) |
1560 { | 1525 { |
1561 cscmd_T *cmdp; | 1526 cscmd_T *cmdp; |
1580 return NULL; | 1545 return NULL; |
1581 } /* cs_lookup_cmd */ | 1546 } /* cs_lookup_cmd */ |
1582 | 1547 |
1583 | 1548 |
1584 /* | 1549 /* |
1585 * PRIVATE: cs_kill | 1550 * Nuke em. |
1586 * | |
1587 * nuke em | |
1588 */ | 1551 */ |
1589 static int | 1552 static int |
1590 cs_kill(exarg_T *eap UNUSED) | 1553 cs_kill(exarg_T *eap UNUSED) |
1591 { | 1554 { |
1592 char *stok; | 1555 char *stok; |
1637 return 0; | 1600 return 0; |
1638 } /* cs_kill */ | 1601 } /* cs_kill */ |
1639 | 1602 |
1640 | 1603 |
1641 /* | 1604 /* |
1642 * PRIVATE: cs_kill_execute | |
1643 * | |
1644 * Actually kills a specific cscope connection. | 1605 * Actually kills a specific cscope connection. |
1645 */ | 1606 */ |
1646 static void | 1607 static void |
1647 cs_kill_execute( | 1608 cs_kill_execute( |
1648 int i, /* cscope table index */ | 1609 int i, /* cscope table index */ |
1657 cs_release_csp(i, TRUE); | 1618 cs_release_csp(i, TRUE); |
1658 } | 1619 } |
1659 | 1620 |
1660 | 1621 |
1661 /* | 1622 /* |
1662 * PRIVATE: cs_make_vim_style_matches | 1623 * Convert the cscope output into a ctags style entry (as might be found |
1663 * | |
1664 * convert the cscope output into a ctags style entry (as might be found | |
1665 * in a ctags tags file). there's one catch though: cscope doesn't tell you | 1624 * in a ctags tags file). there's one catch though: cscope doesn't tell you |
1666 * the type of the tag you are looking for. for example, in Darren Hiebert's | 1625 * the type of the tag you are looking for. for example, in Darren Hiebert's |
1667 * ctags (the one that comes with vim), #define's use a line number to find the | 1626 * ctags (the one that comes with vim), #define's use a line number to find the |
1668 * tag in a file while function definitions use a regexp search pattern. | 1627 * tag in a file while function definitions use a regexp search pattern. |
1669 * | 1628 * |
1670 * i'm going to always use the line number because cscope does something | 1629 * I'm going to always use the line number because cscope does something |
1671 * quirky (and probably other things i don't know about): | 1630 * quirky (and probably other things i don't know about): |
1672 * | 1631 * |
1673 * if you have "# define" in your source file, which is | 1632 * if you have "# define" in your source file, which is |
1674 * perfectly legal, cscope thinks you have "#define". this | 1633 * perfectly legal, cscope thinks you have "#define". this |
1675 * will result in a failed regexp search. :( | 1634 * will result in a failed regexp search. :( |
1676 * | 1635 * |
1677 * besides, even if this particular case didn't happen, the search pattern | 1636 * Besides, even if this particular case didn't happen, the search pattern |
1678 * would still have to be modified to escape all the special regular expression | 1637 * would still have to be modified to escape all the special regular expression |
1679 * characters to comply with ctags formatting. | 1638 * characters to comply with ctags formatting. |
1680 */ | 1639 */ |
1681 static char * | 1640 static char * |
1682 cs_make_vim_style_matches( | 1641 cs_make_vim_style_matches( |
1719 return buf; | 1678 return buf; |
1720 } /* cs_make_vim_style_matches */ | 1679 } /* cs_make_vim_style_matches */ |
1721 | 1680 |
1722 | 1681 |
1723 /* | 1682 /* |
1724 * PRIVATE: cs_manage_matches | 1683 * This is kind of hokey, but i don't see an easy way round this. |
1725 * | |
1726 * this is kind of hokey, but i don't see an easy way round this.. | |
1727 * | 1684 * |
1728 * Store: keep a ptr to the (malloc'd) memory of matches originally | 1685 * Store: keep a ptr to the (malloc'd) memory of matches originally |
1729 * generated from cs_find(). the matches are originally lines directly | 1686 * generated from cs_find(). the matches are originally lines directly |
1730 * from cscope output, but transformed to look like something out of a | 1687 * from cscope output, but transformed to look like something out of a |
1731 * ctags. see cs_make_vim_style_matches for more details. | 1688 * ctags. see cs_make_vim_style_matches for more details. |
1799 return p; | 1756 return p; |
1800 } /* cs_manage_matches */ | 1757 } /* cs_manage_matches */ |
1801 | 1758 |
1802 | 1759 |
1803 /* | 1760 /* |
1804 * PRIVATE: cs_parse_results | 1761 * Parse cscope output. |
1805 * | |
1806 * parse cscope output | |
1807 */ | 1762 */ |
1808 static char * | 1763 static char * |
1809 cs_parse_results( | 1764 cs_parse_results( |
1810 int cnumber, | 1765 int cnumber, |
1811 char *buf, | 1766 char *buf, |
1862 return name; | 1817 return name; |
1863 } | 1818 } |
1864 | 1819 |
1865 #ifdef FEAT_QUICKFIX | 1820 #ifdef FEAT_QUICKFIX |
1866 /* | 1821 /* |
1867 * PRIVATE: cs_file_results | 1822 * Write cscope find results to file. |
1868 * | |
1869 * write cscope find results to file | |
1870 */ | 1823 */ |
1871 static void | 1824 static void |
1872 cs_file_results(FILE *f, int *nummatches_a) | 1825 cs_file_results(FILE *f, int *nummatches_a) |
1873 { | 1826 { |
1874 int i, j; | 1827 int i, j; |
1917 vim_free(buf); | 1870 vim_free(buf); |
1918 } | 1871 } |
1919 #endif | 1872 #endif |
1920 | 1873 |
1921 /* | 1874 /* |
1922 * PRIVATE: cs_fill_results | 1875 * Get parsed cscope output and calls cs_make_vim_style_matches to convert |
1923 * | 1876 * into ctags format. |
1924 * get parsed cscope output and calls cs_make_vim_style_matches to convert | |
1925 * into ctags format | |
1926 * When there are no matches sets "*matches_p" to NULL. | 1877 * When there are no matches sets "*matches_p" to NULL. |
1927 */ | 1878 */ |
1928 static void | 1879 static void |
1929 cs_fill_results( | 1880 cs_fill_results( |
1930 char *tagstr, | 1881 char *tagstr, |
2030 ++s; | 1981 ++s; |
2031 return s; | 1982 return s; |
2032 } | 1983 } |
2033 | 1984 |
2034 /* | 1985 /* |
2035 * PRIVATE: cs_print_tags_priv | 1986 * Called from cs_manage_matches(). |
2036 * | |
2037 * called from cs_manage_matches() | |
2038 */ | 1987 */ |
2039 static void | 1988 static void |
2040 cs_print_tags_priv(char **matches, char **cntxts, int num_matches) | 1989 cs_print_tags_priv(char **matches, char **cntxts, int num_matches) |
2041 { | 1990 { |
2042 char *buf = NULL; | 1991 char *buf = NULL; |
2180 vim_free(buf); | 2129 vim_free(buf); |
2181 } /* cs_print_tags_priv */ | 2130 } /* cs_print_tags_priv */ |
2182 | 2131 |
2183 | 2132 |
2184 /* | 2133 /* |
2185 * PRIVATE: cs_read_prompt | 2134 * Read a cscope prompt (basically, skip over the ">> "). |
2186 * | |
2187 * read a cscope prompt (basically, skip over the ">> ") | |
2188 */ | 2135 */ |
2189 static int | 2136 static int |
2190 cs_read_prompt(int i) | 2137 cs_read_prompt(int i) |
2191 { | 2138 { |
2192 int ch; | 2139 int ch; |
2278 SIGRETURN; | 2225 SIGRETURN; |
2279 } | 2226 } |
2280 #endif | 2227 #endif |
2281 | 2228 |
2282 /* | 2229 /* |
2283 * PRIVATE: cs_release_csp | |
2284 * | |
2285 * Does the actual free'ing for the cs ptr with an optional flag of whether | 2230 * Does the actual free'ing for the cs ptr with an optional flag of whether |
2286 * or not to free the filename. Called by cs_kill and cs_reset. | 2231 * or not to free the filename. Called by cs_kill and cs_reset. |
2287 */ | 2232 */ |
2288 static void | 2233 static void |
2289 cs_release_csp(int i, int freefnpp) | 2234 cs_release_csp(int i, int freefnpp) |
2406 clear_csinfo(i); | 2351 clear_csinfo(i); |
2407 } /* cs_release_csp */ | 2352 } /* cs_release_csp */ |
2408 | 2353 |
2409 | 2354 |
2410 /* | 2355 /* |
2411 * PRIVATE: cs_reset | 2356 * Calls cs_kill on all cscope connections then reinits. |
2412 * | |
2413 * calls cs_kill on all cscope connections then reinits | |
2414 */ | 2357 */ |
2415 static int | 2358 static int |
2416 cs_reset(exarg_T *eap UNUSED) | 2359 cs_reset(exarg_T *eap UNUSED) |
2417 { | 2360 { |
2418 char **dblist = NULL, **pplist = NULL, **fllist = NULL; | 2361 char **dblist = NULL, **pplist = NULL, **fllist = NULL; |
2472 return CSCOPE_SUCCESS; | 2415 return CSCOPE_SUCCESS; |
2473 } /* cs_reset */ | 2416 } /* cs_reset */ |
2474 | 2417 |
2475 | 2418 |
2476 /* | 2419 /* |
2477 * PRIVATE: cs_resolve_file | |
2478 * | |
2479 * Construct the full pathname to a file found in the cscope database. | 2420 * Construct the full pathname to a file found in the cscope database. |
2480 * (Prepends ppath, if there is one and if it's not already prepended, | 2421 * (Prepends ppath, if there is one and if it's not already prepended, |
2481 * otherwise just uses the name found.) | 2422 * otherwise just uses the name found.) |
2482 * | 2423 * |
2483 * We need to prepend the prefix because on some cscope's (e.g., the one that | 2424 * We need to prepend the prefix because on some cscope's (e.g., the one that |
2542 return fullname; | 2483 return fullname; |
2543 } | 2484 } |
2544 | 2485 |
2545 | 2486 |
2546 /* | 2487 /* |
2547 * PRIVATE: cs_show | 2488 * Show all cscope connections. |
2548 * | |
2549 * show all cscope connections | |
2550 */ | 2489 */ |
2551 static int | 2490 static int |
2552 cs_show(exarg_T *eap UNUSED) | 2491 cs_show(exarg_T *eap UNUSED) |
2553 { | 2492 { |
2554 short i; | 2493 short i; |
2577 return CSCOPE_SUCCESS; | 2516 return CSCOPE_SUCCESS; |
2578 } /* cs_show */ | 2517 } /* cs_show */ |
2579 | 2518 |
2580 | 2519 |
2581 /* | 2520 /* |
2582 * PUBLIC: cs_end | |
2583 * | |
2584 * Only called when VIM exits to quit any cscope sessions. | 2521 * Only called when VIM exits to quit any cscope sessions. |
2585 */ | 2522 */ |
2586 void | 2523 void |
2587 cs_end(void) | 2524 cs_end(void) |
2588 { | 2525 { |