aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c97
1 files changed, 41 insertions, 56 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index e1fcbdedd9c..4bccca0e3ad 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -31,7 +31,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer. 31 * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer.
32 */ 32 */
33 33
34char pot_etags_version[] = "@(#) pot revision number is 11.12"; 34char pot_etags_version[] = "@(#) pot revision number is 11.14";
35 35
36#ifdef MSDOS 36#ifdef MSDOS
37#include <fcntl.h> 37#include <fcntl.h>
@@ -185,7 +185,7 @@ char *relative_filename (), *absolute_filename (), *absolute_dirname ();
185char *xmalloc (), *xrealloc (); 185char *xmalloc (), *xrealloc ();
186 186
187typedef void Lang_function (); 187typedef void Lang_function ();
188#if 0 /* many compilers barf on this */ 188#if FALSE /* many compilers barf on this */
189Lang_function Asm_labels; 189Lang_function Asm_labels;
190Lang_function default_C_entries; 190Lang_function default_C_entries;
191Lang_function C_entries; 191Lang_function C_entries;
@@ -224,7 +224,7 @@ void add_regex ();
224#endif 224#endif
225void add_node (); 225void add_node ();
226void error (); 226void error ();
227void fatal (); 227void fatal (), pfatal ();
228logical find_entries (); 228logical find_entries ();
229void free_tree (); 229void free_tree ();
230void getit (); 230void getit ();
@@ -949,10 +949,7 @@ main (argc, argv)
949 else 949 else
950 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w"); 950 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
951 if (tagf == NULL) 951 if (tagf == NULL)
952 { 952 pfatal (tagfile);
953 perror (tagfile);
954 exit (BAD);
955 }
956 } 953 }
957 954
958 /* 955 /*
@@ -1308,10 +1305,7 @@ free_tree (node)
1308 * add_node is the only function allowed to add nodes, so it can 1305 * add_node is the only function allowed to add nodes, so it can
1309 * maintain state. 1306 * maintain state.
1310 */ 1307 */
1311/* Must avoid static vars within functions since some systems
1312 #define static as nothing. */
1313NODE *last_node = NULL; 1308NODE *last_node = NULL;
1314
1315void 1309void
1316add_node (node, cur_node_p) 1310add_node (node, cur_node_p)
1317 NODE *node, **cur_node_p; 1311 NODE *node, **cur_node_p;
@@ -1703,7 +1697,7 @@ DEFINEST definedef;
1703 1697
1704/* 1698/*
1705 * Set this to TRUE, and the next token considered is called a function. 1699 * Set this to TRUE, and the next token considered is called a function.
1706 * Used only for GNUmacs's function-defining macros. 1700 * Used only for GNU emacs's function-defining macros.
1707 */ 1701 */
1708logical next_token_is_func; 1702logical next_token_is_func;
1709 1703
@@ -3739,6 +3733,14 @@ fatal (s1, s2)
3739 exit (BAD); 3733 exit (BAD);
3740} 3734}
3741 3735
3736void
3737pfatal (s1)
3738 char *s1;
3739{
3740 perror (s1);
3741 exit (BAD);
3742}
3743
3742/* Print error message. `s1' is printf control string, `s2' is arg for it. */ 3744/* Print error message. `s1' is printf control string, `s2' is arg for it. */
3743void 3745void
3744error (s1, s2) 3746error (s1, s2)
@@ -3766,70 +3768,53 @@ concat (s1, s2, s3)
3766 return result; 3768 return result;
3767} 3769}
3768 3770
3769#ifdef DOS_NT 3771/* Does the same work as the system V getcwd, but does not need to
3772 guess buffer size in advance. */
3770char * 3773char *
3771etags_getcwd () 3774etags_getcwd ()
3775#ifdef DOS_NT
3772{ 3776{
3773 char *p, cwd[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */ 3777 char *p, path[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */
3774 getwd (cwd); 3778
3775 p = cwd; 3779 getwd (path);
3780 p = path;
3776 while (*p) 3781 while (*p)
3777 if (*p == '\\') 3782 if (*p == '\\')
3778 *p++ = '/'; 3783 *p++ = '/';
3779 else 3784 else
3780 *p++ = tolower (*p); 3785 *p++ = tolower (*p);
3781 return strdup (cwd); 3786
3787 return strdup (path);
3782} 3788}
3783#else /* not DOS_NT */ 3789#elif HAVE_GETCWD /* not DOS_NT */
3784/* Does the same work as the system V getcwd, but does not need to
3785 guess buffer size in advance. */
3786char *
3787etags_getcwd ()
3788{ 3790{
3789 char *buf; 3791 int bufsize = 200;
3790 int bufsize = 256; 3792 char *path = xnew (bufsize, char);
3791 3793
3792#ifdef HAVE_GETCWD 3794 while (getcwd (path, bufsize) == NULL)
3793 buf = xnew (bufsize, char);
3794 while (getcwd (buf, bufsize / 2) == NULL)
3795 { 3795 {
3796 if (errno != ERANGE) 3796 if (errno != ERANGE)
3797 { 3797 pfatal ("pwd");
3798 perror ("pwd");
3799 exit (BAD);
3800 }
3801 bufsize *= 2; 3798 bufsize *= 2;
3802 buf = xnew (bufsize, char); 3799 path = xnew (bufsize, char);
3803 } 3800 }
3804#else
3805 do
3806 {
3807 FILE *pipe;
3808
3809 buf = xnew (bufsize, char);
3810
3811 pipe = (FILE *) popen ("pwd 2>/dev/null", "r");
3812 if (pipe == NULL)
3813 {
3814 perror ("pwd");
3815 exit (BAD);
3816 }
3817 if (fgets (buf, bufsize, pipe) == NULL)
3818 {
3819 perror ("pwd");
3820 exit (BAD);
3821 }
3822 pclose (pipe);
3823 3801
3824 bufsize *= 2; 3802 return path;
3803}
3804#else /* not DOS_NT and not HAVE_GETCWD */
3805{
3806 struct linebuffer path;
3807 FILE *pipe;
3825 3808
3826 } while (buf[strlen (buf) - 1] != '\n'); 3809 initbuffer (&path);
3827#endif 3810 pipe = (FILE *) popen ("pwd 2>/dev/null", "r");
3811 if (pipe == NULL || readline_internal (&path, pipe) == 0)
3812 pfatal ("pwd");
3813 pclose (pipe);
3828 3814
3829 buf[strlen (buf) - 1] = '\0'; 3815 return path.buffer;
3830 return buf;
3831} 3816}
3832#endif /* not DOS_NT */ 3817#endif /* not DOS_NT and not HAVE_GETCWD */
3833 3818
3834/* Return a newly allocated string containing the filename 3819/* Return a newly allocated string containing the filename
3835 of FILE relative to the absolute directory DIR (which 3820 of FILE relative to the absolute directory DIR (which