Mercurial > vim
comparison src/if_cscope.c @ 18798:f0f9692d4487 v8.1.2387
patch 8.1.2387: using old C style comments
Commit: https://github.com/vim/vim/commit/2ab2e8608f9b2c85432715bb9a7f226fdbf8cd35
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Dec 4 21:24:53 2019 +0100
patch 8.1.2387: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 04 Dec 2019 21:30:04 +0100 |
parents | 8976c3a3803a |
children | 6a4806e326dd |
comparison
equal
deleted
inserted
replaced
18797:76af6d0ea316 | 18798:f0f9692d4487 |
---|---|
49 static char * cs_resolve_file(int, char *); | 49 static char * cs_resolve_file(int, char *); |
50 static int cs_show(exarg_T *eap); | 50 static int cs_show(exarg_T *eap); |
51 | 51 |
52 | 52 |
53 static csinfo_T * csinfo = NULL; | 53 static csinfo_T * csinfo = NULL; |
54 static int csinfo_size = 0; /* number of items allocated in | 54 static int csinfo_size = 0; // number of items allocated in |
55 csinfo[] */ | 55 // csinfo[] |
56 | 56 |
57 static int eap_arg_len; /* length of eap->arg, set in | 57 static int eap_arg_len; // length of eap->arg, set in |
58 cs_lookup_cmd() */ | 58 // cs_lookup_cmd() |
59 static cscmd_T cs_cmds[] = | 59 static cscmd_T cs_cmds[] = |
60 { | 60 { |
61 { "add", cs_add, | 61 { "add", cs_add, |
62 N_("Add a new database"), "add file|dir [pre-path] [flags]", 0 }, | 62 N_("Add a new database"), "add file|dir [pre-path] [flags]", 0 }, |
63 { "find", cs_find, | 63 { "find", cs_find, |
79 (void)semsg(_("E560: Usage: cs[cope] %s"), cs_cmds[(int)x].usage); | 79 (void)semsg(_("E560: Usage: cs[cope] %s"), cs_cmds[(int)x].usage); |
80 } | 80 } |
81 | 81 |
82 static enum | 82 static enum |
83 { | 83 { |
84 EXP_CSCOPE_SUBCMD, /* expand ":cscope" sub-commands */ | 84 EXP_CSCOPE_SUBCMD, // expand ":cscope" sub-commands |
85 EXP_SCSCOPE_SUBCMD, /* expand ":scscope" sub-commands */ | 85 EXP_SCSCOPE_SUBCMD, // expand ":scscope" sub-commands |
86 EXP_CSCOPE_FIND, /* expand ":cscope find" arguments */ | 86 EXP_CSCOPE_FIND, // expand ":cscope find" arguments |
87 EXP_CSCOPE_KILL /* expand ":cscope kill" arguments */ | 87 EXP_CSCOPE_KILL // expand ":cscope kill" arguments |
88 } expand_what; | 88 } expand_what; |
89 | 89 |
90 /* | 90 /* |
91 * Function given to ExpandGeneric() to obtain the cscope command | 91 * Function given to ExpandGeneric() to obtain the cscope command |
92 * expansion. | 92 * expansion. |
98 int i; | 98 int i; |
99 | 99 |
100 switch (expand_what) | 100 switch (expand_what) |
101 { | 101 { |
102 case EXP_CSCOPE_SUBCMD: | 102 case EXP_CSCOPE_SUBCMD: |
103 /* Complete with sub-commands of ":cscope": | 103 // Complete with sub-commands of ":cscope": |
104 * add, find, help, kill, reset, show */ | 104 // add, find, help, kill, reset, show |
105 return (char_u *)cs_cmds[idx].name; | 105 return (char_u *)cs_cmds[idx].name; |
106 case EXP_SCSCOPE_SUBCMD: | 106 case EXP_SCSCOPE_SUBCMD: |
107 /* Complete with sub-commands of ":scscope": same sub-commands as | 107 // Complete with sub-commands of ":scscope": same sub-commands as |
108 * ":cscope" but skip commands which don't support split windows */ | 108 // ":cscope" but skip commands which don't support split windows |
109 for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++) | 109 for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++) |
110 if (cs_cmds[i].cansplit) | 110 if (cs_cmds[i].cansplit) |
111 if (current_idx++ == idx) | 111 if (current_idx++ == idx) |
112 break; | 112 break; |
113 return (char_u *)cs_cmds[i].name; | 113 return (char_u *)cs_cmds[i].name; |
116 const char *query_type[] = | 116 const char *query_type[] = |
117 { | 117 { |
118 "a", "c", "d", "e", "f", "g", "i", "s", "t", NULL | 118 "a", "c", "d", "e", "f", "g", "i", "s", "t", NULL |
119 }; | 119 }; |
120 | 120 |
121 /* Complete with query type of ":cscope find {query_type}". | 121 // Complete with query type of ":cscope find {query_type}". |
122 * {query_type} can be letters (c, d, ... a) or numbers (0, 1, | 122 // {query_type} can be letters (c, d, ... a) or numbers (0, 1, |
123 * ..., 9) but only complete with letters, since numbers are | 123 // ..., 9) but only complete with letters, since numbers are |
124 * redundant. */ | 124 // redundant. |
125 return (char_u *)query_type[idx]; | 125 return (char_u *)query_type[idx]; |
126 } | 126 } |
127 case EXP_CSCOPE_KILL: | 127 case EXP_CSCOPE_KILL: |
128 { | 128 { |
129 static char connection[5]; | 129 static char connection[5]; |
130 | 130 |
131 /* ":cscope kill" accepts connection numbers or partial names of | 131 // ":cscope kill" accepts connection numbers or partial names of |
132 * the pathname of the cscope database as argument. Only complete | 132 // the pathname of the cscope database as argument. Only complete |
133 * with connection numbers. -1 can also be used to kill all | 133 // with connection numbers. -1 can also be used to kill all |
134 * connections. */ | 134 // connections. |
135 for (i = 0, current_idx = 0; i < csinfo_size; i++) | 135 for (i = 0, current_idx = 0; i < csinfo_size; i++) |
136 { | 136 { |
137 if (csinfo[i].fname == NULL) | 137 if (csinfo[i].fname == NULL) |
138 continue; | 138 continue; |
139 if (current_idx++ == idx) | 139 if (current_idx++ == idx) |
158 char_u *arg, | 158 char_u *arg, |
159 cmdidx_T cmdidx) | 159 cmdidx_T cmdidx) |
160 { | 160 { |
161 char_u *p; | 161 char_u *p; |
162 | 162 |
163 /* Default: expand subcommands */ | 163 // Default: expand subcommands |
164 xp->xp_context = EXPAND_CSCOPE; | 164 xp->xp_context = EXPAND_CSCOPE; |
165 xp->xp_pattern = arg; | 165 xp->xp_pattern = arg; |
166 expand_what = (cmdidx == CMD_scscope) | 166 expand_what = (cmdidx == CMD_scscope) |
167 ? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD; | 167 ? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD; |
168 | 168 |
169 /* (part of) subcommand already typed */ | 169 // (part of) subcommand already typed |
170 if (*arg != NUL) | 170 if (*arg != NUL) |
171 { | 171 { |
172 p = skiptowhite(arg); | 172 p = skiptowhite(arg); |
173 if (*p != NUL) /* past first word */ | 173 if (*p != NUL) // past first word |
174 { | 174 { |
175 xp->xp_pattern = skipwhite(p); | 175 xp->xp_pattern = skipwhite(p); |
176 if (*skiptowhite(xp->xp_pattern) != NUL) | 176 if (*skiptowhite(xp->xp_pattern) != NUL) |
177 xp->xp_context = EXPAND_NOTHING; | 177 xp->xp_context = EXPAND_NOTHING; |
178 else if (STRNICMP(arg, "add", p - arg) == 0) | 178 else if (STRNICMP(arg, "add", p - arg) == 0) |
192 * command function. | 192 * command function. |
193 */ | 193 */ |
194 static void | 194 static void |
195 do_cscope_general( | 195 do_cscope_general( |
196 exarg_T *eap, | 196 exarg_T *eap, |
197 int make_split UNUSED) /* whether to split window */ | 197 int make_split UNUSED) // whether to split window |
198 { | 198 { |
199 cscmd_T *cmdp; | 199 cscmd_T *cmdp; |
200 | 200 |
201 if ((cmdp = cs_lookup_cmd(eap)) == NULL) | 201 if ((cmdp = cs_lookup_cmd(eap)) == NULL) |
202 { | 202 { |
331 if ((p = cs_manage_matches(NULL, NULL, -1, Get)) == NULL) | 331 if ((p = cs_manage_matches(NULL, NULL, -1, Get)) == NULL) |
332 return TRUE; | 332 return TRUE; |
333 vim_strncpy(buf, (char_u *)p, size - 1); | 333 vim_strncpy(buf, (char_u *)p, size - 1); |
334 | 334 |
335 return FALSE; | 335 return FALSE; |
336 } /* cs_fgets */ | 336 } |
337 | 337 |
338 | 338 |
339 /* | 339 /* |
340 * Called only from do_tag(), when popping the tag stack. | 340 * Called only from do_tag(), when popping the tag stack. |
341 */ | 341 */ |
481 * cs_add() and cs_reset(). I really don't like to do this, but this | 481 * cs_add() and cs_reset(). I really don't like to do this, but this |
482 * routine uses a number of goto statements. | 482 * routine uses a number of goto statements. |
483 */ | 483 */ |
484 static int | 484 static int |
485 cs_add_common( | 485 cs_add_common( |
486 char *arg1, /* filename - may contain environment variables */ | 486 char *arg1, // filename - may contain environment variables |
487 char *arg2, /* prepend path - may contain environment variables */ | 487 char *arg2, // prepend path - may contain environment variables |
488 char *flags) | 488 char *flags) |
489 { | 489 { |
490 stat_T statbuf; | 490 stat_T statbuf; |
491 int ret; | 491 int ret; |
492 char *fname = NULL; | 492 char *fname = NULL; |
495 int i; | 495 int i; |
496 int len; | 496 int len; |
497 int usedlen = 0; | 497 int usedlen = 0; |
498 char_u *fbuf = NULL; | 498 char_u *fbuf = NULL; |
499 | 499 |
500 /* get the filename (arg1), expand it, and try to stat it */ | 500 // get the filename (arg1), expand it, and try to stat it |
501 if ((fname = alloc(MAXPATHL + 1)) == NULL) | 501 if ((fname = alloc(MAXPATHL + 1)) == NULL) |
502 goto add_err; | 502 goto add_err; |
503 | 503 |
504 expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL); | 504 expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL); |
505 len = (int)STRLEN(fname); | 505 len = (int)STRLEN(fname); |
518 if (p_csverbose) | 518 if (p_csverbose) |
519 cs_stat_emsg(fname); | 519 cs_stat_emsg(fname); |
520 goto add_err; | 520 goto add_err; |
521 } | 521 } |
522 | 522 |
523 /* get the prepend path (arg2), expand it, and try to stat it */ | 523 // get the prepend path (arg2), expand it, and try to stat it |
524 if (arg2 != NULL) | 524 if (arg2 != NULL) |
525 { | 525 { |
526 stat_T statbuf2; | 526 stat_T statbuf2; |
527 | 527 |
528 if ((ppath = alloc(MAXPATHL + 1)) == NULL) | 528 if ((ppath = alloc(MAXPATHL + 1)) == NULL) |
532 ret = mch_stat(ppath, &statbuf2); | 532 ret = mch_stat(ppath, &statbuf2); |
533 if (ret < 0) | 533 if (ret < 0) |
534 goto staterr; | 534 goto staterr; |
535 } | 535 } |
536 | 536 |
537 /* if filename is a directory, append the cscope database name to it */ | 537 // if filename is a directory, append the cscope database name to it |
538 if (S_ISDIR(statbuf.st_mode)) | 538 if (S_ISDIR(statbuf.st_mode)) |
539 { | 539 { |
540 fname2 = alloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2); | 540 fname2 = alloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2); |
541 if (fname2 == NULL) | 541 if (fname2 == NULL) |
542 goto add_err; | 542 goto add_err; |
605 add_err: | 605 add_err: |
606 vim_free(fname2); | 606 vim_free(fname2); |
607 vim_free(fname); | 607 vim_free(fname); |
608 vim_free(ppath); | 608 vim_free(ppath); |
609 return CSCOPE_FAILURE; | 609 return CSCOPE_FAILURE; |
610 } /* cs_add_common */ | 610 } |
611 | 611 |
612 | 612 |
613 static int | 613 static int |
614 cs_check_for_connections(void) | 614 cs_check_for_connections(void) |
615 { | 615 { |
616 return (cs_cnt_connections() > 0); | 616 return (cs_cnt_connections() > 0); |
617 } /* cs_check_for_connections */ | 617 } |
618 | 618 |
619 | 619 |
620 static int | 620 static int |
621 cs_check_for_tags(void) | 621 cs_check_for_tags(void) |
622 { | 622 { |
623 return (p_tags[0] != NUL && curbuf->b_p_tags != NULL); | 623 return (p_tags[0] != NUL && curbuf->b_p_tags != NULL); |
624 } /* cs_check_for_tags */ | 624 } |
625 | 625 |
626 | 626 |
627 /* | 627 /* |
628 * Count the number of cscope connections. | 628 * Count the number of cscope connections. |
629 */ | 629 */ |
637 { | 637 { |
638 if (csinfo[i].fname != NULL) | 638 if (csinfo[i].fname != NULL) |
639 cnt++; | 639 cnt++; |
640 } | 640 } |
641 return cnt; | 641 return cnt; |
642 } /* cs_cnt_connections */ | 642 } |
643 | 643 |
644 static void | 644 static void |
645 cs_reading_emsg( | 645 cs_reading_emsg( |
646 int idx) /* connection index */ | 646 int idx) // connection index |
647 { | 647 { |
648 semsg(_("E262: error reading cscope connection %d"), idx); | 648 semsg(_("E262: error reading cscope connection %d"), idx); |
649 } | 649 } |
650 | 650 |
651 #define CSREAD_BUFSIZE 2048 | 651 #define CSREAD_BUFSIZE 2048 |
706 break; | 706 break; |
707 } | 707 } |
708 | 708 |
709 vim_free(buf); | 709 vim_free(buf); |
710 return nlines; | 710 return nlines; |
711 } /* cs_cnt_matches */ | 711 } |
712 | 712 |
713 | 713 |
714 /* | 714 /* |
715 * Creates the actual cscope command query from what the user entered. | 715 * Creates the actual cscope command query from what the user entered. |
716 */ | 716 */ |
754 (void)emsg(_("E561: unknown cscope search type")); | 754 (void)emsg(_("E561: unknown cscope search type")); |
755 cs_usage_msg(Find); | 755 cs_usage_msg(Find); |
756 return NULL; | 756 return NULL; |
757 } | 757 } |
758 | 758 |
759 /* Skip white space before the patter, except for text and pattern search, | 759 // Skip white space before the patter, except for text and pattern search, |
760 * they may want to use the leading white space. */ | 760 // they may want to use the leading white space. |
761 pat = pattern; | 761 pat = pattern; |
762 if (search != 4 && search != 6) | 762 if (search != 4 && search != 6) |
763 while VIM_ISWHITE(*pat) | 763 while VIM_ISWHITE(*pat) |
764 ++pat; | 764 ++pat; |
765 | 765 |
767 return NULL; | 767 return NULL; |
768 | 768 |
769 (void)sprintf(cmd, "%d%s", search, pat); | 769 (void)sprintf(cmd, "%d%s", search, pat); |
770 | 770 |
771 return cmd; | 771 return cmd; |
772 } /* cs_create_cmd */ | 772 } |
773 | 773 |
774 | 774 |
775 /* | 775 /* |
776 * This piece of code was taken/adapted from nvi. do we need to add | 776 * This piece of code was taken/adapted from nvi. do we need to add |
777 * the BSD license notice? | 777 * the BSD license notice? |
824 switch (csinfo[i].pid = fork()) | 824 switch (csinfo[i].pid = fork()) |
825 { | 825 { |
826 case -1: | 826 case -1: |
827 (void)emsg(_("E622: Could not fork for cscope")); | 827 (void)emsg(_("E622: Could not fork for cscope")); |
828 goto err_closing; | 828 goto err_closing; |
829 case 0: /* child: run cscope. */ | 829 case 0: // child: run cscope. |
830 if (dup2(to_cs[0], STDIN_FILENO) == -1) | 830 if (dup2(to_cs[0], STDIN_FILENO) == -1) |
831 PERROR("cs_create_connection 1"); | 831 PERROR("cs_create_connection 1"); |
832 if (dup2(from_cs[1], STDOUT_FILENO) == -1) | 832 if (dup2(from_cs[1], STDOUT_FILENO) == -1) |
833 PERROR("cs_create_connection 2"); | 833 PERROR("cs_create_connection 2"); |
834 if (dup2(from_cs[1], STDERR_FILENO) == -1) | 834 if (dup2(from_cs[1], STDERR_FILENO) == -1) |
835 PERROR("cs_create_connection 3"); | 835 PERROR("cs_create_connection 3"); |
836 | 836 |
837 /* close unused */ | 837 // close unused |
838 (void)close(to_cs[1]); | 838 (void)close(to_cs[1]); |
839 (void)close(from_cs[0]); | 839 (void)close(from_cs[0]); |
840 #else | 840 #else |
841 /* MSWIN */ | 841 // MSWIN |
842 /* Create pipes to communicate with cscope */ | 842 // Create pipes to communicate with cscope |
843 sa.nLength = sizeof(SECURITY_ATTRIBUTES); | 843 sa.nLength = sizeof(SECURITY_ATTRIBUTES); |
844 sa.bInheritHandle = TRUE; | 844 sa.bInheritHandle = TRUE; |
845 sa.lpSecurityDescriptor = NULL; | 845 sa.lpSecurityDescriptor = NULL; |
846 | 846 |
847 if (!(pipe_stdin = CreatePipe(&stdin_rd, &stdin_wr, &sa, 0)) | 847 if (!(pipe_stdin = CreatePipe(&stdin_rd, &stdin_wr, &sa, 0)) |
860 CloseHandle(stdout_wr); | 860 CloseHandle(stdout_wr); |
861 } | 861 } |
862 return CSCOPE_FAILURE; | 862 return CSCOPE_FAILURE; |
863 } | 863 } |
864 #endif | 864 #endif |
865 /* expand the cscope exec for env var's */ | 865 // expand the cscope exec for env var's |
866 if ((prog = alloc(MAXPATHL + 1)) == NULL) | 866 if ((prog = alloc(MAXPATHL + 1)) == NULL) |
867 { | 867 { |
868 #ifdef UNIX | 868 #ifdef UNIX |
869 return CSCOPE_FAILURE; | 869 return CSCOPE_FAILURE; |
870 #else | 870 #else |
871 /* MSWIN */ | 871 // MSWIN |
872 goto err_closing; | 872 goto err_closing; |
873 #endif | 873 #endif |
874 } | 874 } |
875 expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL); | 875 expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL); |
876 | 876 |
877 /* alloc space to hold the cscope command */ | 877 // alloc space to hold the cscope command |
878 len = (int)(strlen(prog) + strlen(csinfo[i].fname) + 32); | 878 len = (int)(strlen(prog) + strlen(csinfo[i].fname) + 32); |
879 if (csinfo[i].ppath) | 879 if (csinfo[i].ppath) |
880 { | 880 { |
881 /* expand the prepend path for env var's */ | 881 // expand the prepend path for env var's |
882 if ((ppath = alloc(MAXPATHL + 1)) == NULL) | 882 if ((ppath = alloc(MAXPATHL + 1)) == NULL) |
883 { | 883 { |
884 vim_free(prog); | 884 vim_free(prog); |
885 #ifdef UNIX | 885 #ifdef UNIX |
886 return CSCOPE_FAILURE; | 886 return CSCOPE_FAILURE; |
887 #else | 887 #else |
888 /* MSWIN */ | 888 // MSWIN |
889 goto err_closing; | 889 goto err_closing; |
890 #endif | 890 #endif |
891 } | 891 } |
892 expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL); | 892 expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL); |
893 | 893 |
902 vim_free(prog); | 902 vim_free(prog); |
903 vim_free(ppath); | 903 vim_free(ppath); |
904 #ifdef UNIX | 904 #ifdef UNIX |
905 return CSCOPE_FAILURE; | 905 return CSCOPE_FAILURE; |
906 #else | 906 #else |
907 /* MSWIN */ | 907 // MSWIN |
908 goto err_closing; | 908 goto err_closing; |
909 #endif | 909 #endif |
910 } | 910 } |
911 | 911 |
912 /* run the cscope command; is there execl for non-unix systems? */ | 912 // run the cscope command; is there execl for non-unix systems? |
913 #if defined(UNIX) | 913 #if defined(UNIX) |
914 (void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname); | 914 (void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname); |
915 #else | 915 #else |
916 /* MSWIN */ | 916 // MSWIN |
917 (void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname); | 917 (void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname); |
918 #endif | 918 #endif |
919 if (csinfo[i].ppath != NULL) | 919 if (csinfo[i].ppath != NULL) |
920 { | 920 { |
921 (void)strcat(cmd, " -P"); | 921 (void)strcat(cmd, " -P"); |
925 { | 925 { |
926 (void)strcat(cmd, " "); | 926 (void)strcat(cmd, " "); |
927 (void)strcat(cmd, csinfo[i].flags); | 927 (void)strcat(cmd, csinfo[i].flags); |
928 } | 928 } |
929 # ifdef UNIX | 929 # ifdef UNIX |
930 /* on Win32 we still need prog */ | 930 // on Win32 we still need prog |
931 vim_free(prog); | 931 vim_free(prog); |
932 # endif | 932 # endif |
933 vim_free(ppath); | 933 vim_free(ppath); |
934 | 934 |
935 #if defined(UNIX) | 935 #if defined(UNIX) |
936 # if defined(HAVE_SETSID) || defined(HAVE_SETPGID) | 936 # if defined(HAVE_SETSID) || defined(HAVE_SETPGID) |
937 /* Change our process group to avoid cscope receiving SIGWINCH. */ | 937 // Change our process group to avoid cscope receiving SIGWINCH. |
938 # if defined(HAVE_SETSID) | 938 # if defined(HAVE_SETSID) |
939 (void)setsid(); | 939 (void)setsid(); |
940 # else | 940 # else |
941 if (setpgid(0, 0) == -1) | 941 if (setpgid(0, 0) == -1) |
942 PERROR(_("cs_create_connection setpgid failed")); | 942 PERROR(_("cs_create_connection setpgid failed")); |
944 # endif | 944 # endif |
945 if (execl("/bin/sh", "sh", "-c", cmd, (char *)NULL) == -1) | 945 if (execl("/bin/sh", "sh", "-c", cmd, (char *)NULL) == -1) |
946 PERROR(_("cs_create_connection exec failed")); | 946 PERROR(_("cs_create_connection exec failed")); |
947 | 947 |
948 exit(127); | 948 exit(127); |
949 /* NOTREACHED */ | 949 // NOTREACHED |
950 default: /* parent. */ | 950 default: // parent. |
951 /* | 951 /* |
952 * Save the file descriptors for later duplication, and | 952 * Save the file descriptors for later duplication, and |
953 * reopen as streams. | 953 * reopen as streams. |
954 */ | 954 */ |
955 if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL) | 955 if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL) |
956 PERROR(_("cs_create_connection: fdopen for to_fp failed")); | 956 PERROR(_("cs_create_connection: fdopen for to_fp failed")); |
957 if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL) | 957 if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL) |
958 PERROR(_("cs_create_connection: fdopen for fr_fp failed")); | 958 PERROR(_("cs_create_connection: fdopen for fr_fp failed")); |
959 | 959 |
960 /* close unused */ | 960 // close unused |
961 (void)close(to_cs[0]); | 961 (void)close(to_cs[0]); |
962 (void)close(from_cs[1]); | 962 (void)close(from_cs[1]); |
963 | 963 |
964 break; | 964 break; |
965 } | 965 } |
966 | 966 |
967 #else | 967 #else |
968 /* MSWIN */ | 968 // MSWIN |
969 /* Create a new process to run cscope and use pipes to talk with it */ | 969 // Create a new process to run cscope and use pipes to talk with it |
970 GetStartupInfo(&si); | 970 GetStartupInfo(&si); |
971 si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; | 971 si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; |
972 si.wShowWindow = SW_HIDE; /* Hide child application window */ | 972 si.wShowWindow = SW_HIDE; // Hide child application window |
973 si.hStdOutput = stdout_wr; | 973 si.hStdOutput = stdout_wr; |
974 si.hStdError = stdout_wr; | 974 si.hStdError = stdout_wr; |
975 si.hStdInput = stdin_rd; | 975 si.hStdInput = stdin_rd; |
976 created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, | 976 created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, |
977 NULL, NULL, &si, &pi); | 977 NULL, NULL, &si, &pi); |
982 { | 982 { |
983 PERROR(_("cs_create_connection exec failed")); | 983 PERROR(_("cs_create_connection exec failed")); |
984 (void)emsg(_("E623: Could not spawn cscope process")); | 984 (void)emsg(_("E623: Could not spawn cscope process")); |
985 goto err_closing; | 985 goto err_closing; |
986 } | 986 } |
987 /* else */ | 987 // else |
988 csinfo[i].pid = pi.dwProcessId; | 988 csinfo[i].pid = pi.dwProcessId; |
989 csinfo[i].hProc = pi.hProcess; | 989 csinfo[i].hProc = pi.hProcess; |
990 CloseHandle(pi.hThread); | 990 CloseHandle(pi.hThread); |
991 | 991 |
992 /* TODO - tidy up after failure to create files on pipe handles. */ | 992 // TODO - tidy up after failure to create files on pipe handles. |
993 if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdin_wr, | 993 if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdin_wr, |
994 _O_TEXT|_O_APPEND)) < 0) | 994 _O_TEXT|_O_APPEND)) < 0) |
995 || ((csinfo[i].to_fp = _fdopen(fd, "w")) == NULL)) | 995 || ((csinfo[i].to_fp = _fdopen(fd, "w")) == NULL)) |
996 PERROR(_("cs_create_connection: fdopen for to_fp failed")); | 996 PERROR(_("cs_create_connection: fdopen for to_fp failed")); |
997 if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdout_rd, | 997 if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdout_rd, |
998 _O_TEXT|_O_RDONLY)) < 0) | 998 _O_TEXT|_O_RDONLY)) < 0) |
999 || ((csinfo[i].fr_fp = _fdopen(fd, "r")) == NULL)) | 999 || ((csinfo[i].fr_fp = _fdopen(fd, "r")) == NULL)) |
1000 PERROR(_("cs_create_connection: fdopen for fr_fp failed")); | 1000 PERROR(_("cs_create_connection: fdopen for fr_fp failed")); |
1001 | 1001 |
1002 /* Close handles for file descriptors inherited by the cscope process */ | 1002 // Close handles for file descriptors inherited by the cscope process |
1003 CloseHandle(stdin_rd); | 1003 CloseHandle(stdin_rd); |
1004 CloseHandle(stdout_wr); | 1004 CloseHandle(stdout_wr); |
1005 | 1005 |
1006 #endif /* !UNIX */ | 1006 #endif // !UNIX |
1007 | 1007 |
1008 return CSCOPE_SUCCESS; | 1008 return CSCOPE_SUCCESS; |
1009 } /* cs_create_connection */ | 1009 } |
1010 | 1010 |
1011 | 1011 |
1012 /* | 1012 /* |
1013 * Query cscope using command line interface. Parse the output and use tselect | 1013 * Query cscope using command line interface. Parse the output and use tselect |
1014 * to allow choices. Like Nvi, creates a pipe to send to/from query/cscope. | 1014 * to allow choices. Like Nvi, creates a pipe to send to/from query/cscope. |
1048 if (NUL == eap->arg[i]) | 1048 if (NUL == eap->arg[i]) |
1049 eap->arg[i] = ' '; | 1049 eap->arg[i] = ' '; |
1050 | 1050 |
1051 return cs_find_common(opt, pat, eap->forceit, TRUE, | 1051 return cs_find_common(opt, pat, eap->forceit, TRUE, |
1052 eap->cmdidx == CMD_lcscope, *eap->cmdlinep); | 1052 eap->cmdidx == CMD_lcscope, *eap->cmdlinep); |
1053 } /* cs_find */ | 1053 } |
1054 | 1054 |
1055 | 1055 |
1056 /* | 1056 /* |
1057 * Common code for cscope find, shared by cs_find() and ex_cstag(). | 1057 * Common code for cscope find, shared by cs_find() and ex_cstag(). |
1058 */ | 1058 */ |
1071 int totmatches; | 1071 int totmatches; |
1072 #ifdef FEAT_QUICKFIX | 1072 #ifdef FEAT_QUICKFIX |
1073 char cmdletter; | 1073 char cmdletter; |
1074 char *qfpos; | 1074 char *qfpos; |
1075 | 1075 |
1076 /* get cmd letter */ | 1076 // get cmd letter |
1077 switch (opt[0]) | 1077 switch (opt[0]) |
1078 { | 1078 { |
1079 case '0' : | 1079 case '0' : |
1080 cmdletter = 's'; | 1080 cmdletter = 's'; |
1081 break; | 1081 break; |
1109 | 1109 |
1110 qfpos = (char *)vim_strchr(p_csqf, cmdletter); | 1110 qfpos = (char *)vim_strchr(p_csqf, cmdletter); |
1111 if (qfpos != NULL) | 1111 if (qfpos != NULL) |
1112 { | 1112 { |
1113 qfpos++; | 1113 qfpos++; |
1114 /* next symbol must be + or - */ | 1114 // next symbol must be + or - |
1115 if (strchr(CSQF_FLAGS, *qfpos) == NULL) | 1115 if (strchr(CSQF_FLAGS, *qfpos) == NULL) |
1116 { | 1116 { |
1117 char *nf = _("E469: invalid cscopequickfix flag %c for %c"); | 1117 char *nf = _("E469: invalid cscopequickfix flag %c for %c"); |
1118 char *buf = alloc(strlen(nf)); | 1118 char *buf = alloc(strlen(nf)); |
1119 | 1119 |
1120 /* strlen will be enough because we use chars */ | 1120 // strlen will be enough because we use chars |
1121 if (buf != NULL) | 1121 if (buf != NULL) |
1122 { | 1122 { |
1123 sprintf(buf, nf, *qfpos, *(qfpos-1)); | 1123 sprintf(buf, nf, *qfpos, *(qfpos-1)); |
1124 (void)emsg(buf); | 1124 (void)emsg(buf); |
1125 vim_free(buf); | 1125 vim_free(buf); |
1137 # endif | 1137 # endif |
1138 } | 1138 } |
1139 } | 1139 } |
1140 #endif | 1140 #endif |
1141 | 1141 |
1142 /* create the actual command to send to cscope */ | 1142 // create the actual command to send to cscope |
1143 cmd = cs_create_cmd(opt, pat); | 1143 cmd = cs_create_cmd(opt, pat); |
1144 if (cmd == NULL) | 1144 if (cmd == NULL) |
1145 return FALSE; | 1145 return FALSE; |
1146 | 1146 |
1147 nummatches = ALLOC_MULT(int, csinfo_size); | 1147 nummatches = ALLOC_MULT(int, csinfo_size); |
1149 { | 1149 { |
1150 vim_free(cmd); | 1150 vim_free(cmd); |
1151 return FALSE; | 1151 return FALSE; |
1152 } | 1152 } |
1153 | 1153 |
1154 /* Send query to all open connections, then count the total number | 1154 // Send query to all open connections, then count the total number |
1155 * of matches so we can alloc all in one swell foop. */ | 1155 // of matches so we can alloc all in one swell foop. |
1156 for (i = 0; i < csinfo_size; i++) | 1156 for (i = 0; i < csinfo_size; i++) |
1157 nummatches[i] = 0; | 1157 nummatches[i] = 0; |
1158 totmatches = 0; | 1158 totmatches = 0; |
1159 for (i = 0; i < csinfo_size; i++) | 1159 for (i = 0; i < csinfo_size; i++) |
1160 { | 1160 { |
1161 if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL) | 1161 if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL) |
1162 continue; | 1162 continue; |
1163 | 1163 |
1164 /* send cmd to cscope */ | 1164 // send cmd to cscope |
1165 (void)fprintf(csinfo[i].to_fp, "%s\n", cmd); | 1165 (void)fprintf(csinfo[i].to_fp, "%s\n", cmd); |
1166 (void)fflush(csinfo[i].to_fp); | 1166 (void)fflush(csinfo[i].to_fp); |
1167 | 1167 |
1168 nummatches[i] = cs_cnt_matches(i); | 1168 nummatches[i] = cs_cnt_matches(i); |
1169 | 1169 |
1200 } | 1200 } |
1201 | 1201 |
1202 #ifdef FEAT_QUICKFIX | 1202 #ifdef FEAT_QUICKFIX |
1203 if (qfpos != NULL && *qfpos != '0' && totmatches > 0) | 1203 if (qfpos != NULL && *qfpos != '0' && totmatches > 0) |
1204 { | 1204 { |
1205 /* fill error list */ | 1205 // fill error list |
1206 FILE *f; | 1206 FILE *f; |
1207 char_u *tmp = vim_tempname('c', TRUE); | 1207 char_u *tmp = vim_tempname('c', TRUE); |
1208 qf_info_T *qi = NULL; | 1208 qf_info_T *qi = NULL; |
1209 win_T *wp = NULL; | 1209 win_T *wp = NULL; |
1210 | 1210 |
1213 semsg(_(e_notopen), tmp); | 1213 semsg(_(e_notopen), tmp); |
1214 else | 1214 else |
1215 { | 1215 { |
1216 cs_file_results(f, nummatches); | 1216 cs_file_results(f, nummatches); |
1217 fclose(f); | 1217 fclose(f); |
1218 if (use_ll) /* Use location list */ | 1218 if (use_ll) // Use location list |
1219 wp = curwin; | 1219 wp = curwin; |
1220 /* '-' starts a new error list */ | 1220 // '-' starts a new error list |
1221 if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m", | 1221 if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m", |
1222 *qfpos == '-', cmdline, NULL) > 0) | 1222 *qfpos == '-', cmdline, NULL) > 0) |
1223 { | 1223 { |
1224 if (postponed_split != 0) | 1224 if (postponed_split != 0) |
1225 { | 1225 { |
1245 vim_free(tmp); | 1245 vim_free(tmp); |
1246 vim_free(nummatches); | 1246 vim_free(nummatches); |
1247 return TRUE; | 1247 return TRUE; |
1248 } | 1248 } |
1249 else | 1249 else |
1250 #endif /* FEAT_QUICKFIX */ | 1250 #endif // FEAT_QUICKFIX |
1251 { | 1251 { |
1252 char **matches = NULL, **contexts = NULL; | 1252 char **matches = NULL, **contexts = NULL; |
1253 int matched = 0; | 1253 int matched = 0; |
1254 | 1254 |
1255 /* read output */ | 1255 // read output |
1256 cs_fill_results((char *)pat, totmatches, nummatches, &matches, | 1256 cs_fill_results((char *)pat, totmatches, nummatches, &matches, |
1257 &contexts, &matched); | 1257 &contexts, &matched); |
1258 vim_free(nummatches); | 1258 vim_free(nummatches); |
1259 if (matches == NULL) | 1259 if (matches == NULL) |
1260 return FALSE; | 1260 return FALSE; |
1262 (void)cs_manage_matches(matches, contexts, matched, Store); | 1262 (void)cs_manage_matches(matches, contexts, matched, Store); |
1263 | 1263 |
1264 return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose); | 1264 return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose); |
1265 } | 1265 } |
1266 | 1266 |
1267 } /* cs_find_common */ | 1267 } |
1268 | 1268 |
1269 /* | 1269 /* |
1270 * Print help. | 1270 * Print help. |
1271 */ | 1271 */ |
1272 static int | 1272 static int |
1278 while (cmdp->name != NULL) | 1278 while (cmdp->name != NULL) |
1279 { | 1279 { |
1280 char *help = _(cmdp->help); | 1280 char *help = _(cmdp->help); |
1281 int space_cnt = 30 - vim_strsize((char_u *)help); | 1281 int space_cnt = 30 - vim_strsize((char_u *)help); |
1282 | 1282 |
1283 /* Use %*s rather than %30s to ensure proper alignment in utf-8 */ | 1283 // Use %*s rather than %30s to ensure proper alignment in utf-8 |
1284 if (space_cnt < 0) | 1284 if (space_cnt < 0) |
1285 space_cnt = 0; | 1285 space_cnt = 0; |
1286 (void)smsg(_("%-5s: %s%*s (Usage: %s)"), | 1286 (void)smsg(_("%-5s: %s%*s (Usage: %s)"), |
1287 cmdp->name, | 1287 cmdp->name, |
1288 help, space_cnt, " ", | 1288 help, space_cnt, " ", |
1302 cmdp++; | 1302 cmdp++; |
1303 } | 1303 } |
1304 | 1304 |
1305 wait_return(TRUE); | 1305 wait_return(TRUE); |
1306 return 0; | 1306 return 0; |
1307 } /* cs_help */ | 1307 } |
1308 | 1308 |
1309 | 1309 |
1310 static void | 1310 static void |
1311 clear_csinfo(int i) | 1311 clear_csinfo(int i) |
1312 { | 1312 { |
1336 char *msg = NULL; | 1336 char *msg = NULL; |
1337 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, | 1337 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, |
1338 NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL); | 1338 NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL); |
1339 if (msg != NULL) | 1339 if (msg != NULL) |
1340 { | 1340 { |
1341 /* remove trailing \r\n */ | 1341 // remove trailing \r\n |
1342 char *pcrlf = strstr(msg, "\r\n"); | 1342 char *pcrlf = strstr(msg, "\r\n"); |
1343 if (pcrlf != NULL) | 1343 if (pcrlf != NULL) |
1344 *pcrlf = '\0'; | 1344 *pcrlf = '\0'; |
1345 } | 1345 } |
1346 return msg; | 1346 return msg; |
1361 #ifndef UNIX | 1361 #ifndef UNIX |
1362 BY_HANDLE_FILE_INFORMATION bhfi; | 1362 BY_HANDLE_FILE_INFORMATION bhfi; |
1363 | 1363 |
1364 switch (win32_fileinfo((char_u *)fname, &bhfi)) | 1364 switch (win32_fileinfo((char_u *)fname, &bhfi)) |
1365 { | 1365 { |
1366 case FILEINFO_ENC_FAIL: /* enc_to_utf16() failed */ | 1366 case FILEINFO_ENC_FAIL: // enc_to_utf16() failed |
1367 case FILEINFO_READ_FAIL: /* CreateFile() failed */ | 1367 case FILEINFO_READ_FAIL: // CreateFile() failed |
1368 if (p_csverbose) | 1368 if (p_csverbose) |
1369 { | 1369 { |
1370 char *cant_msg = _("E625: cannot open cscope database: %s"); | 1370 char *cant_msg = _("E625: cannot open cscope database: %s"); |
1371 char *winmsg = GetWin32Error(); | 1371 char *winmsg = GetWin32Error(); |
1372 | 1372 |
1374 { | 1374 { |
1375 (void)semsg(cant_msg, winmsg); | 1375 (void)semsg(cant_msg, winmsg); |
1376 LocalFree(winmsg); | 1376 LocalFree(winmsg); |
1377 } | 1377 } |
1378 else | 1378 else |
1379 /* subst filename if can't get error text */ | 1379 // subst filename if can't get error text |
1380 (void)semsg(cant_msg, fname); | 1380 (void)semsg(cant_msg, fname); |
1381 } | 1381 } |
1382 return -1; | 1382 return -1; |
1383 | 1383 |
1384 case FILEINFO_INFO_FAIL: /* GetFileInformationByHandle() failed */ | 1384 case FILEINFO_INFO_FAIL: // GetFileInformationByHandle() failed |
1385 if (p_csverbose) | 1385 if (p_csverbose) |
1386 (void)emsg(_("E626: cannot get cscope database information")); | 1386 (void)emsg(_("E626: cannot get cscope database information")); |
1387 return -1; | 1387 return -1; |
1388 } | 1388 } |
1389 #endif | 1389 #endif |
1390 | 1390 |
1391 i = -1; /* can be set to the index of an empty item in csinfo */ | 1391 i = -1; // can be set to the index of an empty item in csinfo |
1392 for (j = 0; j < csinfo_size; j++) | 1392 for (j = 0; j < csinfo_size; j++) |
1393 { | 1393 { |
1394 if (csinfo[j].fname != NULL | 1394 if (csinfo[j].fname != NULL |
1395 #if defined(UNIX) | 1395 #if defined(UNIX) |
1396 && csinfo[j].st_dev == sb->st_dev && csinfo[j].st_ino == sb->st_ino | 1396 && csinfo[j].st_dev == sb->st_dev && csinfo[j].st_ino == sb->st_ino |
1409 (void)emsg(_("E568: duplicate cscope database not added")); | 1409 (void)emsg(_("E568: duplicate cscope database not added")); |
1410 return -1; | 1410 return -1; |
1411 } | 1411 } |
1412 | 1412 |
1413 if (csinfo[j].fname == NULL && i == -1) | 1413 if (csinfo[j].fname == NULL && i == -1) |
1414 i = j; /* remember first empty entry */ | 1414 i = j; // remember first empty entry |
1415 } | 1415 } |
1416 | 1416 |
1417 if (i == -1) | 1417 if (i == -1) |
1418 { | 1418 { |
1419 i = csinfo_size; | 1419 i = csinfo_size; |
1420 if (csinfo_size == 0) | 1420 if (csinfo_size == 0) |
1421 { | 1421 { |
1422 /* First time allocation: allocate only 1 connection. It should | 1422 // First time allocation: allocate only 1 connection. It should |
1423 * be enough for most users. If more is needed, csinfo will be | 1423 // be enough for most users. If more is needed, csinfo will be |
1424 * reallocated. */ | 1424 // reallocated. |
1425 csinfo_size = 1; | 1425 csinfo_size = 1; |
1426 csinfo = ALLOC_CLEAR_ONE(csinfo_T); | 1426 csinfo = ALLOC_CLEAR_ONE(csinfo_T); |
1427 } | 1427 } |
1428 else | 1428 else |
1429 { | 1429 { |
1430 csinfo_T *t_csinfo = csinfo; | 1430 csinfo_T *t_csinfo = csinfo; |
1431 | 1431 |
1432 /* Reallocate space for more connections. */ | 1432 // Reallocate space for more connections. |
1433 csinfo_size *= 2; | 1433 csinfo_size *= 2; |
1434 csinfo = vim_realloc(csinfo, sizeof(csinfo_T)*csinfo_size); | 1434 csinfo = vim_realloc(csinfo, sizeof(csinfo_T)*csinfo_size); |
1435 if (csinfo == NULL) | 1435 if (csinfo == NULL) |
1436 { | 1436 { |
1437 vim_free(t_csinfo); | 1437 vim_free(t_csinfo); |
1480 csinfo[i].nVolume = bhfi.dwVolumeSerialNumber; | 1480 csinfo[i].nVolume = bhfi.dwVolumeSerialNumber; |
1481 csinfo[i].nIndexLow = bhfi.nFileIndexLow; | 1481 csinfo[i].nIndexLow = bhfi.nFileIndexLow; |
1482 csinfo[i].nIndexHigh = bhfi.nFileIndexHigh; | 1482 csinfo[i].nIndexHigh = bhfi.nFileIndexHigh; |
1483 #endif | 1483 #endif |
1484 return i; | 1484 return i; |
1485 } /* cs_insert_filelist */ | 1485 } |
1486 | 1486 |
1487 | 1487 |
1488 /* | 1488 /* |
1489 * Find cscope command in command table. | 1489 * Find cscope command in command table. |
1490 */ | 1490 */ |
1496 size_t len; | 1496 size_t len; |
1497 | 1497 |
1498 if (eap->arg == NULL) | 1498 if (eap->arg == NULL) |
1499 return NULL; | 1499 return NULL; |
1500 | 1500 |
1501 /* Store length of eap->arg before it gets modified by strtok(). */ | 1501 // Store length of eap->arg before it gets modified by strtok(). |
1502 eap_arg_len = (int)STRLEN(eap->arg); | 1502 eap_arg_len = (int)STRLEN(eap->arg); |
1503 | 1503 |
1504 if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL) | 1504 if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL) |
1505 return NULL; | 1505 return NULL; |
1506 | 1506 |
1509 { | 1509 { |
1510 if (strncmp((const char *)(stok), cmdp->name, len) == 0) | 1510 if (strncmp((const char *)(stok), cmdp->name, len) == 0) |
1511 return (cmdp); | 1511 return (cmdp); |
1512 } | 1512 } |
1513 return NULL; | 1513 return NULL; |
1514 } /* cs_lookup_cmd */ | 1514 } |
1515 | 1515 |
1516 | 1516 |
1517 /* | 1517 /* |
1518 * Nuke em. | 1518 * Nuke em. |
1519 */ | 1519 */ |
1527 { | 1527 { |
1528 cs_usage_msg(Kill); | 1528 cs_usage_msg(Kill); |
1529 return CSCOPE_FAILURE; | 1529 return CSCOPE_FAILURE; |
1530 } | 1530 } |
1531 | 1531 |
1532 /* only single digit positive and negative integers are allowed */ | 1532 // only single digit positive and negative integers are allowed |
1533 if ((strlen(stok) < 2 && VIM_ISDIGIT((int)(stok[0]))) | 1533 if ((strlen(stok) < 2 && VIM_ISDIGIT((int)(stok[0]))) |
1534 || (strlen(stok) < 3 && stok[0] == '-' | 1534 || (strlen(stok) < 3 && stok[0] == '-' |
1535 && VIM_ISDIGIT((int)(stok[1])))) | 1535 && VIM_ISDIGIT((int)(stok[1])))) |
1536 i = atoi(stok); | 1536 i = atoi(stok); |
1537 else | 1537 else |
1538 { | 1538 { |
1539 /* It must be part of a name. We will try to find a match | 1539 // It must be part of a name. We will try to find a match |
1540 * within all the names in the csinfo data structure | 1540 // within all the names in the csinfo data structure |
1541 */ | |
1542 for (i = 0; i < csinfo_size; i++) | 1541 for (i = 0; i < csinfo_size; i++) |
1543 { | 1542 { |
1544 if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok)) | 1543 if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok)) |
1545 break; | 1544 break; |
1546 } | 1545 } |
1564 else | 1563 else |
1565 cs_kill_execute(i, stok); | 1564 cs_kill_execute(i, stok); |
1566 } | 1565 } |
1567 | 1566 |
1568 return 0; | 1567 return 0; |
1569 } /* cs_kill */ | 1568 } |
1570 | 1569 |
1571 | 1570 |
1572 /* | 1571 /* |
1573 * Actually kills a specific cscope connection. | 1572 * Actually kills a specific cscope connection. |
1574 */ | 1573 */ |
1575 static void | 1574 static void |
1576 cs_kill_execute( | 1575 cs_kill_execute( |
1577 int i, /* cscope table index */ | 1576 int i, // cscope table index |
1578 char *cname) /* cscope database name */ | 1577 char *cname) // cscope database name |
1579 { | 1578 { |
1580 if (p_csverbose) | 1579 if (p_csverbose) |
1581 { | 1580 { |
1582 msg_clr_eos(); | 1581 msg_clr_eos(); |
1583 (void)smsg_attr(HL_ATTR(HLF_R) | MSG_HIST, | 1582 (void)smsg_attr(HL_ATTR(HLF_R) | MSG_HIST, |
1610 char *fname, | 1609 char *fname, |
1611 char *slno, | 1610 char *slno, |
1612 char *search, | 1611 char *search, |
1613 char *tagstr) | 1612 char *tagstr) |
1614 { | 1613 { |
1615 /* vim style is ctags: | 1614 // vim style is ctags: |
1616 * | 1615 // |
1617 * <tagstr>\t<filename>\t<linenum_or_search>"\t<extra> | 1616 // <tagstr>\t<filename>\t<linenum_or_search>"\t<extra> |
1618 * | 1617 // |
1619 * but as mentioned above, we'll always use the line number and | 1618 // but as mentioned above, we'll always use the line number and |
1620 * put the search pattern (if one exists) as "extra" | 1619 // put the search pattern (if one exists) as "extra" |
1621 * | 1620 // |
1622 * buf is used as part of vim's method of handling tags, and | 1621 // buf is used as part of vim's method of handling tags, and |
1623 * (i think) vim frees it when you pop your tags and get replaced | 1622 // (i think) vim frees it when you pop your tags and get replaced |
1624 * by new ones on the tag stack. | 1623 // by new ones on the tag stack. |
1625 */ | |
1626 char *buf; | 1624 char *buf; |
1627 int amt; | 1625 int amt; |
1628 | 1626 |
1629 if (search != NULL) | 1627 if (search != NULL) |
1630 { | 1628 { |
1642 | 1640 |
1643 (void)sprintf(buf, "%s\t%s\t%s;\"", tagstr, fname, slno); | 1641 (void)sprintf(buf, "%s\t%s\t%s;\"", tagstr, fname, slno); |
1644 } | 1642 } |
1645 | 1643 |
1646 return buf; | 1644 return buf; |
1647 } /* cs_make_vim_style_matches */ | 1645 } |
1648 | 1646 |
1649 | 1647 |
1650 /* | 1648 /* |
1651 * This is kind of hokey, but i don't see an easy way round this. | 1649 * This is kind of hokey, but i don't see an easy way round this. |
1652 * | 1650 * |
1714 next = 0; | 1712 next = 0; |
1715 break; | 1713 break; |
1716 case Print: | 1714 case Print: |
1717 cs_print_tags_priv(mp, cp, cnt); | 1715 cs_print_tags_priv(mp, cp, cnt); |
1718 break; | 1716 break; |
1719 default: /* should not reach here */ | 1717 default: // should not reach here |
1720 iemsg(_("E570: fatal error in cs_manage_matches")); | 1718 iemsg(_("E570: fatal error in cs_manage_matches")); |
1721 return NULL; | 1719 return NULL; |
1722 } | 1720 } |
1723 | 1721 |
1724 return p; | 1722 return p; |
1725 } /* cs_manage_matches */ | 1723 } |
1726 | 1724 |
1727 | 1725 |
1728 /* | 1726 /* |
1729 * Parse cscope output. | 1727 * Parse cscope output. |
1730 */ | 1728 */ |
1749 cs_reading_emsg(cnumber); | 1747 cs_reading_emsg(cnumber); |
1750 | 1748 |
1751 return NULL; | 1749 return NULL; |
1752 } | 1750 } |
1753 | 1751 |
1754 /* If the line's too long for the buffer, discard it. */ | 1752 // If the line's too long for the buffer, discard it. |
1755 if ((p = strchr(buf, '\n')) == NULL) | 1753 if ((p = strchr(buf, '\n')) == NULL) |
1756 { | 1754 { |
1757 while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n') | 1755 while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n') |
1758 ; | 1756 ; |
1759 return NULL; | 1757 return NULL; |
1769 return NULL; | 1767 return NULL; |
1770 if ((*context = strtok(NULL, (const char *)" ")) == NULL) | 1768 if ((*context = strtok(NULL, (const char *)" ")) == NULL) |
1771 return NULL; | 1769 return NULL; |
1772 if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL) | 1770 if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL) |
1773 return NULL; | 1771 return NULL; |
1774 *search = *linenumber + strlen(*linenumber) + 1; /* +1 to skip \0 */ | 1772 *search = *linenumber + strlen(*linenumber) + 1; // +1 to skip \0 |
1775 | 1773 |
1776 /* --- nvi --- | 1774 // --- nvi --- |
1777 * If the file is older than the cscope database, that is, | 1775 // If the file is older than the cscope database, that is, |
1778 * the database was built since the file was last modified, | 1776 // the database was built since the file was last modified, |
1779 * or there wasn't a search string, use the line number. | 1777 // or there wasn't a search string, use the line number. |
1780 */ | |
1781 if (strcmp(*search, "<unknown>") == 0) | 1778 if (strcmp(*search, "<unknown>") == 0) |
1782 *search = NULL; | 1779 *search = NULL; |
1783 | 1780 |
1784 name = cs_resolve_file(cnumber, name); | 1781 name = cs_resolve_file(cnumber, name); |
1785 return name; | 1782 return name; |
1828 else | 1825 else |
1829 fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search); | 1826 fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search); |
1830 | 1827 |
1831 vim_free(context); | 1828 vim_free(context); |
1832 vim_free(fullname); | 1829 vim_free(fullname); |
1833 } /* for all matches */ | 1830 } // for all matches |
1834 | 1831 |
1835 (void)cs_read_prompt(i); | 1832 (void)cs_read_prompt(i); |
1836 | 1833 |
1837 } /* for all cscope connections */ | 1834 } // for all cscope connections |
1838 vim_free(buf); | 1835 vim_free(buf); |
1839 } | 1836 } |
1840 #endif | 1837 #endif |
1841 | 1838 |
1842 /* | 1839 /* |
1890 vim_free(fullname); | 1887 vim_free(fullname); |
1891 | 1888 |
1892 if (strcmp(cntx, "<global>") == 0) | 1889 if (strcmp(cntx, "<global>") == 0) |
1893 cntxts[totsofar] = NULL; | 1890 cntxts[totsofar] = NULL; |
1894 else | 1891 else |
1895 /* note: if vim_strsave returns NULL, then the context | 1892 // note: if vim_strsave returns NULL, then the context |
1896 * will be "<global>", which is misleading. | 1893 // will be "<global>", which is misleading. |
1897 */ | |
1898 cntxts[totsofar] = (char *)vim_strsave((char_u *)cntx); | 1894 cntxts[totsofar] = (char *)vim_strsave((char_u *)cntx); |
1899 | 1895 |
1900 if (matches[totsofar] != NULL) | 1896 if (matches[totsofar] != NULL) |
1901 totsofar++; | 1897 totsofar++; |
1902 | 1898 |
1903 } /* for all matches */ | 1899 } // for all matches |
1904 | 1900 |
1905 (void)cs_read_prompt(i); | 1901 (void)cs_read_prompt(i); |
1906 | 1902 |
1907 } /* for all cscope connections */ | 1903 } // for all cscope connections |
1908 | 1904 |
1909 parse_out: | 1905 parse_out: |
1910 if (totsofar == 0) | 1906 if (totsofar == 0) |
1911 { | 1907 { |
1912 /* No matches, free the arrays and return NULL in "*matches_p". */ | 1908 // No matches, free the arrays and return NULL in "*matches_p". |
1913 VIM_CLEAR(matches); | 1909 VIM_CLEAR(matches); |
1914 VIM_CLEAR(cntxts); | 1910 VIM_CLEAR(cntxts); |
1915 } | 1911 } |
1916 *matched = totsofar; | 1912 *matched = totsofar; |
1917 *matches_p = matches; | 1913 *matches_p = matches; |
1918 *cntxts_p = cntxts; | 1914 *cntxts_p = cntxts; |
1919 | 1915 |
1920 vim_free(buf); | 1916 vim_free(buf); |
1921 } /* cs_fill_results */ | 1917 } |
1922 | 1918 |
1923 | 1919 |
1924 /* get the requested path components */ | 1920 /* |
1921 * get the requested path components | |
1922 */ | |
1925 static char * | 1923 static char * |
1926 cs_pathcomponents(char *path) | 1924 cs_pathcomponents(char *path) |
1927 { | 1925 { |
1928 int i; | 1926 int i; |
1929 char *s; | 1927 char *s; |
1954 static void | 1952 static void |
1955 cs_print_tags_priv(char **matches, char **cntxts, int num_matches) | 1953 cs_print_tags_priv(char **matches, char **cntxts, int num_matches) |
1956 { | 1954 { |
1957 char *buf = NULL; | 1955 char *buf = NULL; |
1958 char *t_buf; | 1956 char *t_buf; |
1959 int bufsize = 0; /* Track available bufsize */ | 1957 int bufsize = 0; // Track available bufsize |
1960 int newsize = 0; | 1958 int newsize = 0; |
1961 char *ptag; | 1959 char *ptag; |
1962 char *fname, *lno, *extra, *tbuf; | 1960 char *fname, *lno, *extra, *tbuf; |
1963 int i, idx, num; | 1961 int i, idx, num; |
1964 char *globalcntx = "GLOBAL"; | 1962 char *globalcntx = "GLOBAL"; |
1989 msg_puts_attr(buf, HL_ATTR(HLF_T)); | 1987 msg_puts_attr(buf, HL_ATTR(HLF_T)); |
1990 } | 1988 } |
1991 | 1989 |
1992 vim_free(tbuf); | 1990 vim_free(tbuf); |
1993 | 1991 |
1994 msg_puts_attr(_("\n # line"), HL_ATTR(HLF_T)); /* strlen is 7 */ | 1992 msg_puts_attr(_("\n # line"), HL_ATTR(HLF_T)); // strlen is 7 |
1995 msg_advance(msg_col + 2); | 1993 msg_advance(msg_col + 2); |
1996 msg_puts_attr(_("filename / context / line\n"), HL_ATTR(HLF_T)); | 1994 msg_puts_attr(_("filename / context / line\n"), HL_ATTR(HLF_T)); |
1997 | 1995 |
1998 num = 1; | 1996 num = 1; |
1999 for (i = 0; i < num_matches; i++) | 1997 for (i = 0; i < num_matches; i++) |
2000 { | 1998 { |
2001 idx = i; | 1999 idx = i; |
2002 | 2000 |
2003 /* if we really wanted to, we could avoid this malloc and strcpy | 2001 // if we really wanted to, we could avoid this malloc and strcpy |
2004 * by parsing matches[i] on the fly and placing stuff into buf | 2002 // by parsing matches[i] on the fly and placing stuff into buf |
2005 * directly, but that's too much of a hassle | 2003 // directly, but that's too much of a hassle |
2006 */ | |
2007 if ((tbuf = alloc(strlen(matches[idx]) + 1)) == NULL) | 2004 if ((tbuf = alloc(strlen(matches[idx]) + 1)) == NULL) |
2008 continue; | 2005 continue; |
2009 (void)strcpy(tbuf, matches[idx]); | 2006 (void)strcpy(tbuf, matches[idx]); |
2010 | 2007 |
2011 if (strtok(tbuf, (const char *)"\t") == NULL | 2008 if (strtok(tbuf, (const char *)"\t") == NULL |
2015 vim_free(tbuf); | 2012 vim_free(tbuf); |
2016 continue; | 2013 continue; |
2017 } | 2014 } |
2018 extra = strtok(NULL, (const char *)"\t"); | 2015 extra = strtok(NULL, (const char *)"\t"); |
2019 | 2016 |
2020 lno[strlen(lno)-2] = '\0'; /* ignore ;" at the end */ | 2017 lno[strlen(lno)-2] = '\0'; // ignore ;" at the end |
2021 | 2018 |
2022 /* hopefully 'num' (num of matches) will be less than 10^16 */ | 2019 // hopefully 'num' (num of matches) will be less than 10^16 |
2023 newsize = (int)(strlen(csfmt_str) + 16 + strlen(lno)); | 2020 newsize = (int)(strlen(csfmt_str) + 16 + strlen(lno)); |
2024 if (bufsize < newsize) | 2021 if (bufsize < newsize) |
2025 { | 2022 { |
2026 t_buf = buf; | 2023 t_buf = buf; |
2027 buf = vim_realloc(buf, newsize); | 2024 buf = vim_realloc(buf, newsize); |
2033 else | 2030 else |
2034 bufsize = newsize; | 2031 bufsize = newsize; |
2035 } | 2032 } |
2036 if (buf != NULL) | 2033 if (buf != NULL) |
2037 { | 2034 { |
2038 /* csfmt_str = "%4d %6s "; */ | 2035 // csfmt_str = "%4d %6s "; |
2039 (void)sprintf(buf, csfmt_str, num, lno); | 2036 (void)sprintf(buf, csfmt_str, num, lno); |
2040 msg_puts_attr(buf, HL_ATTR(HLF_CM)); | 2037 msg_puts_attr(buf, HL_ATTR(HLF_CM)); |
2041 } | 2038 } |
2042 msg_outtrans_long_attr((char_u *)cs_pathcomponents(fname), | 2039 msg_outtrans_long_attr((char_u *)cs_pathcomponents(fname), |
2043 HL_ATTR(HLF_CM)); | 2040 HL_ATTR(HLF_CM)); |
2044 | 2041 |
2045 /* compute the required space for the context */ | 2042 // compute the required space for the context |
2046 if (cntxts[idx] != NULL) | 2043 if (cntxts[idx] != NULL) |
2047 context = cntxts[idx]; | 2044 context = cntxts[idx]; |
2048 else | 2045 else |
2049 context = globalcntx; | 2046 context = globalcntx; |
2050 newsize = (int)(strlen(context) + strlen(cntxformat)); | 2047 newsize = (int)(strlen(context) + strlen(cntxformat)); |
2063 } | 2060 } |
2064 if (buf != NULL) | 2061 if (buf != NULL) |
2065 { | 2062 { |
2066 (void)sprintf(buf, cntxformat, context); | 2063 (void)sprintf(buf, cntxformat, context); |
2067 | 2064 |
2068 /* print the context only if it fits on the same line */ | 2065 // print the context only if it fits on the same line |
2069 if (msg_col + (int)strlen(buf) >= (int)Columns) | 2066 if (msg_col + (int)strlen(buf) >= (int)Columns) |
2070 msg_putchar('\n'); | 2067 msg_putchar('\n'); |
2071 msg_advance(12); | 2068 msg_advance(12); |
2072 msg_outtrans_long_attr((char_u *)buf, 0); | 2069 msg_outtrans_long_attr((char_u *)buf, 0); |
2073 msg_putchar('\n'); | 2070 msg_putchar('\n'); |
2076 { | 2073 { |
2077 msg_advance(13); | 2074 msg_advance(13); |
2078 msg_outtrans_long_attr((char_u *)extra, 0); | 2075 msg_outtrans_long_attr((char_u *)extra, 0); |
2079 } | 2076 } |
2080 | 2077 |
2081 vim_free(tbuf); /* only after printing extra due to strtok use */ | 2078 vim_free(tbuf); // only after printing extra due to strtok use |
2082 | 2079 |
2083 if (msg_col) | 2080 if (msg_col) |
2084 msg_putchar('\n'); | 2081 msg_putchar('\n'); |
2085 | 2082 |
2086 ui_breakcheck(); | 2083 ui_breakcheck(); |
2087 if (got_int) | 2084 if (got_int) |
2088 { | 2085 { |
2089 got_int = FALSE; /* don't print any more matches */ | 2086 got_int = FALSE; // don't print any more matches |
2090 break; | 2087 break; |
2091 } | 2088 } |
2092 | 2089 |
2093 num++; | 2090 num++; |
2094 } /* for all matches */ | 2091 } // for all matches |
2095 | 2092 |
2096 vim_free(buf); | 2093 vim_free(buf); |
2097 } /* cs_print_tags_priv */ | 2094 } |
2098 | 2095 |
2099 | 2096 |
2100 /* | 2097 /* |
2101 * Read a cscope prompt (basically, skip over the ">> "). | 2098 * Read a cscope prompt (basically, skip over the ">> "). |
2102 */ | 2099 */ |
2103 static int | 2100 static int |
2104 cs_read_prompt(int i) | 2101 cs_read_prompt(int i) |
2105 { | 2102 { |
2106 int ch; | 2103 int ch; |
2107 char *buf = NULL; /* buffer for possible error message from cscope */ | 2104 char *buf = NULL; // buffer for possible error message from cscope |
2108 int bufpos = 0; | 2105 int bufpos = 0; |
2109 char *cs_emsg; | 2106 char *cs_emsg; |
2110 int maxlen; | 2107 int maxlen; |
2111 static char *eprompt = "Press the RETURN key to continue:"; | 2108 static char *eprompt = "Press the RETURN key to continue:"; |
2112 int epromptlen = (int)strlen(eprompt); | 2109 int epromptlen = (int)strlen(eprompt); |
2113 int n; | 2110 int n; |
2114 | 2111 |
2115 cs_emsg = _("E609: Cscope error: %s"); | 2112 cs_emsg = _("E609: Cscope error: %s"); |
2116 /* compute maximum allowed len for Cscope error message */ | 2113 // compute maximum allowed len for Cscope error message |
2117 maxlen = (int)(IOSIZE - strlen(cs_emsg)); | 2114 maxlen = (int)(IOSIZE - strlen(cs_emsg)); |
2118 | 2115 |
2119 for (;;) | 2116 for (;;) |
2120 { | 2117 { |
2121 while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0]) | 2118 while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0]) |
2122 /* if there is room and char is printable */ | 2119 // if there is room and char is printable |
2123 if (bufpos < maxlen - 1 && vim_isprintc(ch)) | 2120 if (bufpos < maxlen - 1 && vim_isprintc(ch)) |
2124 { | 2121 { |
2125 if (buf == NULL) /* lazy buffer allocation */ | 2122 if (buf == NULL) // lazy buffer allocation |
2126 buf = alloc(maxlen); | 2123 buf = alloc(maxlen); |
2127 if (buf != NULL) | 2124 if (buf != NULL) |
2128 { | 2125 { |
2129 /* append character to the message */ | 2126 // append character to the message |
2130 buf[bufpos++] = ch; | 2127 buf[bufpos++] = ch; |
2131 buf[bufpos] = NUL; | 2128 buf[bufpos] = NUL; |
2132 if (bufpos >= epromptlen | 2129 if (bufpos >= epromptlen |
2133 && strcmp(&buf[bufpos - epromptlen], eprompt) == 0) | 2130 && strcmp(&buf[bufpos - epromptlen], eprompt) == 0) |
2134 { | 2131 { |
2135 /* remove eprompt from buf */ | 2132 // remove eprompt from buf |
2136 buf[bufpos - epromptlen] = NUL; | 2133 buf[bufpos - epromptlen] = NUL; |
2137 | 2134 |
2138 /* print message to user */ | 2135 // print message to user |
2139 (void)semsg(cs_emsg, buf); | 2136 (void)semsg(cs_emsg, buf); |
2140 | 2137 |
2141 /* send RETURN to cscope */ | 2138 // send RETURN to cscope |
2142 (void)putc('\n', csinfo[i].to_fp); | 2139 (void)putc('\n', csinfo[i].to_fp); |
2143 (void)fflush(csinfo[i].to_fp); | 2140 (void)fflush(csinfo[i].to_fp); |
2144 | 2141 |
2145 /* clear buf */ | 2142 // clear buf |
2146 bufpos = 0; | 2143 bufpos = 0; |
2147 buf[bufpos] = NUL; | 2144 buf[bufpos] = NUL; |
2148 } | 2145 } |
2149 } | 2146 } |
2150 } | 2147 } |
2157 { | 2154 { |
2158 PERROR("cs_read_prompt EOF"); | 2155 PERROR("cs_read_prompt EOF"); |
2159 if (buf != NULL && buf[0] != NUL) | 2156 if (buf != NULL && buf[0] != NUL) |
2160 (void)semsg(cs_emsg, buf); | 2157 (void)semsg(cs_emsg, buf); |
2161 else if (p_csverbose) | 2158 else if (p_csverbose) |
2162 cs_reading_emsg(i); /* don't have additional information */ | 2159 cs_reading_emsg(i); // don't have additional information |
2163 cs_release_csp(i, TRUE); | 2160 cs_release_csp(i, TRUE); |
2164 vim_free(buf); | 2161 vim_free(buf); |
2165 return CSCOPE_FAILURE; | 2162 return CSCOPE_FAILURE; |
2166 } | 2163 } |
2167 | 2164 |
2171 break; | 2168 break; |
2172 } | 2169 } |
2173 } | 2170 } |
2174 | 2171 |
2175 if (ch == EOF) | 2172 if (ch == EOF) |
2176 continue; /* didn't find the prompt */ | 2173 continue; // didn't find the prompt |
2177 break; /* did find the prompt */ | 2174 break; // did find the prompt |
2178 } | 2175 } |
2179 | 2176 |
2180 vim_free(buf); | 2177 vim_free(buf); |
2181 return CSCOPE_SUCCESS; | 2178 return CSCOPE_SUCCESS; |
2182 } | 2179 } |
2186 * Used to catch and ignore SIGALRM below. | 2183 * Used to catch and ignore SIGALRM below. |
2187 */ | 2184 */ |
2188 static RETSIGTYPE | 2185 static RETSIGTYPE |
2189 sig_handler SIGDEFARG(sigarg) | 2186 sig_handler SIGDEFARG(sigarg) |
2190 { | 2187 { |
2191 /* do nothing */ | 2188 // do nothing |
2192 SIGRETURN; | 2189 SIGRETURN; |
2193 } | 2190 } |
2194 #endif | 2191 #endif |
2195 | 2192 |
2196 /* | 2193 /* |
2215 pid_t pid; | 2212 pid_t pid; |
2216 | 2213 |
2217 # if defined(HAVE_SIGACTION) | 2214 # if defined(HAVE_SIGACTION) |
2218 struct sigaction sa, old; | 2215 struct sigaction sa, old; |
2219 | 2216 |
2220 /* Use sigaction() to limit the waiting time to two seconds. */ | 2217 // Use sigaction() to limit the waiting time to two seconds. |
2221 sigemptyset(&sa.sa_mask); | 2218 sigemptyset(&sa.sa_mask); |
2222 sa.sa_handler = sig_handler; | 2219 sa.sa_handler = sig_handler; |
2223 # ifdef SA_NODEFER | 2220 # ifdef SA_NODEFER |
2224 sa.sa_flags = SA_NODEFER; | 2221 sa.sa_flags = SA_NODEFER; |
2225 # else | 2222 # else |
2226 sa.sa_flags = 0; | 2223 sa.sa_flags = 0; |
2227 # endif | 2224 # endif |
2228 sigaction(SIGALRM, &sa, &old); | 2225 sigaction(SIGALRM, &sa, &old); |
2229 alarm(2); /* 2 sec timeout */ | 2226 alarm(2); // 2 sec timeout |
2230 | 2227 |
2231 /* Block until cscope exits or until timer expires */ | 2228 // Block until cscope exits or until timer expires |
2232 pid = waitpid(csinfo[i].pid, &pstat, 0); | 2229 pid = waitpid(csinfo[i].pid, &pstat, 0); |
2233 waitpid_errno = errno; | 2230 waitpid_errno = errno; |
2234 | 2231 |
2235 /* cancel pending alarm if still there and restore signal */ | 2232 // cancel pending alarm if still there and restore signal |
2236 alarm(0); | 2233 alarm(0); |
2237 sigaction(SIGALRM, &old, NULL); | 2234 sigaction(SIGALRM, &old, NULL); |
2238 # else | 2235 # else |
2239 int waited; | 2236 int waited; |
2240 | 2237 |
2241 /* Can't use sigaction(), loop for two seconds. First yield the CPU | 2238 // Can't use sigaction(), loop for two seconds. First yield the CPU |
2242 * to give cscope a chance to exit quickly. */ | 2239 // to give cscope a chance to exit quickly. |
2243 sleep(0); | 2240 sleep(0); |
2244 for (waited = 0; waited < 40; ++waited) | 2241 for (waited = 0; waited < 40; ++waited) |
2245 { | 2242 { |
2246 pid = waitpid(csinfo[i].pid, &pstat, WNOHANG); | 2243 pid = waitpid(csinfo[i].pid, &pstat, WNOHANG); |
2247 waitpid_errno = errno; | 2244 waitpid_errno = errno; |
2248 if (pid != 0) | 2245 if (pid != 0) |
2249 break; /* break unless the process is still running */ | 2246 break; // break unless the process is still running |
2250 mch_delay(50L, FALSE); /* sleep 50 ms */ | 2247 mch_delay(50L, FALSE); // sleep 50 ms |
2251 } | 2248 } |
2252 # endif | 2249 # endif |
2253 /* | 2250 /* |
2254 * If the cscope process is still running: kill it. | 2251 * If the cscope process is still running: kill it. |
2255 * Safety check: If the PID would be zero here, the entire X session | 2252 * Safety check: If the PID would be zero here, the entire X session |
2274 int waited; | 2271 int waited; |
2275 | 2272 |
2276 sleep(0); | 2273 sleep(0); |
2277 for (waited = 0; waited < 40; ++waited) | 2274 for (waited = 0; waited < 40; ++waited) |
2278 { | 2275 { |
2279 /* Check whether cscope process is still alive */ | 2276 // Check whether cscope process is still alive |
2280 if (kill(csinfo[i].pid, 0) != 0) | 2277 if (kill(csinfo[i].pid, 0) != 0) |
2281 { | 2278 { |
2282 alive = FALSE; /* cscope process no longer exists */ | 2279 alive = FALSE; // cscope process no longer exists |
2283 break; | 2280 break; |
2284 } | 2281 } |
2285 mch_delay(50L, FALSE); /* sleep 50ms */ | 2282 mch_delay(50L, FALSE); // sleep 50ms |
2286 } | 2283 } |
2287 } | 2284 } |
2288 if (alive) | 2285 if (alive) |
2289 # endif | 2286 # endif |
2290 { | 2287 { |
2291 kill(csinfo[i].pid, SIGKILL); | 2288 kill(csinfo[i].pid, SIGKILL); |
2292 (void)waitpid(csinfo[i].pid, &pstat, 0); | 2289 (void)waitpid(csinfo[i].pid, &pstat, 0); |
2293 } | 2290 } |
2294 } | 2291 } |
2295 } | 2292 } |
2296 #else /* !UNIX */ | 2293 #else // !UNIX |
2297 if (csinfo[i].hProc != NULL) | 2294 if (csinfo[i].hProc != NULL) |
2298 { | 2295 { |
2299 /* Give cscope a chance to exit normally */ | 2296 // Give cscope a chance to exit normally |
2300 if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT) | 2297 if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT) |
2301 TerminateProcess(csinfo[i].hProc, 0); | 2298 TerminateProcess(csinfo[i].hProc, 0); |
2302 CloseHandle(csinfo[i].hProc); | 2299 CloseHandle(csinfo[i].hProc); |
2303 } | 2300 } |
2304 #endif | 2301 #endif |
2314 vim_free(csinfo[i].ppath); | 2311 vim_free(csinfo[i].ppath); |
2315 vim_free(csinfo[i].flags); | 2312 vim_free(csinfo[i].flags); |
2316 } | 2313 } |
2317 | 2314 |
2318 clear_csinfo(i); | 2315 clear_csinfo(i); |
2319 } /* cs_release_csp */ | 2316 } |
2320 | 2317 |
2321 | 2318 |
2322 /* | 2319 /* |
2323 * Calls cs_kill on all cscope connections then reinits. | 2320 * Calls cs_kill on all cscope connections then reinits. |
2324 */ | 2321 */ |
2325 static int | 2322 static int |
2326 cs_reset(exarg_T *eap UNUSED) | 2323 cs_reset(exarg_T *eap UNUSED) |
2327 { | 2324 { |
2328 char **dblist = NULL, **pplist = NULL, **fllist = NULL; | 2325 char **dblist = NULL, **pplist = NULL, **fllist = NULL; |
2329 int i; | 2326 int i; |
2330 char buf[20]; /* for sprintf " (#%d)" */ | 2327 char buf[20]; // for sprintf " (#%d)" |
2331 | 2328 |
2332 if (csinfo_size == 0) | 2329 if (csinfo_size == 0) |
2333 return CSCOPE_SUCCESS; | 2330 return CSCOPE_SUCCESS; |
2334 | 2331 |
2335 /* malloc our db and ppath list */ | 2332 // malloc our db and ppath list |
2336 dblist = ALLOC_MULT(char *, csinfo_size); | 2333 dblist = ALLOC_MULT(char *, csinfo_size); |
2337 pplist = ALLOC_MULT(char *, csinfo_size); | 2334 pplist = ALLOC_MULT(char *, csinfo_size); |
2338 fllist = ALLOC_MULT(char *, csinfo_size); | 2335 fllist = ALLOC_MULT(char *, csinfo_size); |
2339 if (dblist == NULL || pplist == NULL || fllist == NULL) | 2336 if (dblist == NULL || pplist == NULL || fllist == NULL) |
2340 { | 2337 { |
2351 fllist[i] = csinfo[i].flags; | 2348 fllist[i] = csinfo[i].flags; |
2352 if (csinfo[i].fname != NULL) | 2349 if (csinfo[i].fname != NULL) |
2353 cs_release_csp(i, FALSE); | 2350 cs_release_csp(i, FALSE); |
2354 } | 2351 } |
2355 | 2352 |
2356 /* rebuild the cscope connection list */ | 2353 // rebuild the cscope connection list |
2357 for (i = 0; i < csinfo_size; i++) | 2354 for (i = 0; i < csinfo_size; i++) |
2358 { | 2355 { |
2359 if (dblist[i] != NULL) | 2356 if (dblist[i] != NULL) |
2360 { | 2357 { |
2361 cs_add_common(dblist[i], pplist[i], fllist[i]); | 2358 cs_add_common(dblist[i], pplist[i], fllist[i]); |
2362 if (p_csverbose) | 2359 if (p_csverbose) |
2363 { | 2360 { |
2364 /* don't use smsg_attr() because we want to display the | 2361 // don't use smsg_attr() because we want to display the |
2365 * connection number in the same line as | 2362 // connection number in the same line as |
2366 * "Added cscope database..." | 2363 // "Added cscope database..." |
2367 */ | |
2368 sprintf(buf, " (#%d)", i); | 2364 sprintf(buf, " (#%d)", i); |
2369 msg_puts_attr(buf, HL_ATTR(HLF_R)); | 2365 msg_puts_attr(buf, HL_ATTR(HLF_R)); |
2370 } | 2366 } |
2371 } | 2367 } |
2372 vim_free(dblist[i]); | 2368 vim_free(dblist[i]); |
2378 vim_free(fllist); | 2374 vim_free(fllist); |
2379 | 2375 |
2380 if (p_csverbose) | 2376 if (p_csverbose) |
2381 msg_attr(_("All cscope databases reset"), HL_ATTR(HLF_R) | MSG_HIST); | 2377 msg_attr(_("All cscope databases reset"), HL_ATTR(HLF_R) | MSG_HIST); |
2382 return CSCOPE_SUCCESS; | 2378 return CSCOPE_SUCCESS; |
2383 } /* cs_reset */ | 2379 } |
2384 | 2380 |
2385 | 2381 |
2386 /* | 2382 /* |
2387 * Construct the full pathname to a file found in the cscope database. | 2383 * Construct the full pathname to a file found in the cscope database. |
2388 * (Prepends ppath, if there is one and if it's not already prepended, | 2384 * (Prepends ppath, if there is one and if it's not already prepended, |
2407 len = (int)(strlen(name) + 2); | 2403 len = (int)(strlen(name) + 2); |
2408 if (csinfo[i].ppath != NULL) | 2404 if (csinfo[i].ppath != NULL) |
2409 len += (int)strlen(csinfo[i].ppath); | 2405 len += (int)strlen(csinfo[i].ppath); |
2410 else if (p_csre && csinfo[i].fname != NULL) | 2406 else if (p_csre && csinfo[i].fname != NULL) |
2411 { | 2407 { |
2412 /* If 'cscoperelative' is set and ppath is not set, use cscope.out | 2408 // If 'cscoperelative' is set and ppath is not set, use cscope.out |
2413 * path in path resolution. */ | 2409 // path in path resolution. |
2414 csdir = alloc(MAXPATHL); | 2410 csdir = alloc(MAXPATHL); |
2415 if (csdir != NULL) | 2411 if (csdir != NULL) |
2416 { | 2412 { |
2417 vim_strncpy(csdir, (char_u *)csinfo[i].fname, | 2413 vim_strncpy(csdir, (char_u *)csinfo[i].fname, |
2418 gettail((char_u *)csinfo[i].fname) | 2414 gettail((char_u *)csinfo[i].fname) |
2419 - (char_u *)csinfo[i].fname); | 2415 - (char_u *)csinfo[i].fname); |
2420 len += (int)STRLEN(csdir); | 2416 len += (int)STRLEN(csdir); |
2421 } | 2417 } |
2422 } | 2418 } |
2423 | 2419 |
2424 /* Note/example: this won't work if the cscope output already starts | 2420 // Note/example: this won't work if the cscope output already starts |
2425 * "../.." and the prefix path is also "../..". if something like this | 2421 // "../.." and the prefix path is also "../..". if something like this |
2426 * happens, you are screwed up and need to fix how you're using cscope. */ | 2422 // happens, you are screwed up and need to fix how you're using cscope. |
2427 if (csinfo[i].ppath != NULL | 2423 if (csinfo[i].ppath != NULL |
2428 && (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0) | 2424 && (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0) |
2429 && (name[0] != '/') | 2425 && (name[0] != '/') |
2430 #ifdef MSWIN | 2426 #ifdef MSWIN |
2431 && name[0] != '\\' && name[1] != ':' | 2427 && name[0] != '\\' && name[1] != ':' |
2435 if ((fullname = alloc(len)) != NULL) | 2431 if ((fullname = alloc(len)) != NULL) |
2436 (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name); | 2432 (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name); |
2437 } | 2433 } |
2438 else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) | 2434 else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) |
2439 { | 2435 { |
2440 /* Check for csdir to be non empty to avoid empty path concatenated to | 2436 // Check for csdir to be non empty to avoid empty path concatenated to |
2441 * cscope output. */ | 2437 // cscope output. |
2442 fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE); | 2438 fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE); |
2443 } | 2439 } |
2444 else | 2440 else |
2445 { | 2441 { |
2446 fullname = (char *)vim_strsave((char_u *)name); | 2442 fullname = (char *)vim_strsave((char_u *)name); |
2479 } | 2475 } |
2480 } | 2476 } |
2481 | 2477 |
2482 wait_return(TRUE); | 2478 wait_return(TRUE); |
2483 return CSCOPE_SUCCESS; | 2479 return CSCOPE_SUCCESS; |
2484 } /* cs_show */ | 2480 } |
2485 | 2481 |
2486 | 2482 |
2487 /* | 2483 /* |
2488 * Only called when VIM exits to quit any cscope sessions. | 2484 * Only called when VIM exits to quit any cscope sessions. |
2489 */ | 2485 */ |
2496 cs_release_csp(i, TRUE); | 2492 cs_release_csp(i, TRUE); |
2497 vim_free(csinfo); | 2493 vim_free(csinfo); |
2498 csinfo_size = 0; | 2494 csinfo_size = 0; |
2499 } | 2495 } |
2500 | 2496 |
2501 #endif /* FEAT_CSCOPE */ | 2497 #endif // FEAT_CSCOPE |
2502 | 2498 |
2503 #if defined(FEAT_EVAL) || defined(PROTO) | 2499 #if defined(FEAT_EVAL) || defined(PROTO) |
2504 | 2500 |
2505 /* | 2501 /* |
2506 * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function | 2502 * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function |