diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 2000-05-17 12:33:28 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 2000-05-17 12:33:28 +0000 |
commit | 63c66f03f63dff85682274d58c854cd1ba34b01a (patch) | |
tree | 5e5101e019854edd0626204066b8303dcc76126f | |
parent | 3b4b3edb4f7ee43d676a2f92cf7c6c469931fcac (diff) |
Some beautifications.
-rw-r--r-- | mkjtags.c | 46 |
1 files changed, 33 insertions, 13 deletions
@@ -1,5 +1,7 @@ /* - * convert multi-file etags files to something + * $Id$ + * + * Convert multi-file etags files to something * which can be used by jed. * * Thomas Roessler <roessler@guug.de> @@ -10,9 +12,13 @@ #include <stdlib.h> #include <string.h> -void doit (const char *fname, const char *prefix, int crlf_pending); +#include <unistd.h> + +void doit (const char *fname, char *prefix, int crlf_pending); + +char Cwd[2048]; +size_t Cwdl; - int main (int argc, char *argv[]) { if (argc < 2) @@ -20,20 +26,38 @@ int main (int argc, char *argv[]) fprintf (stderr, "usage: %s filename\n", argv[0]); exit (1); } + + if (getcwd (Cwd, sizeof (Cwd)) == NULL) + { + fprintf (stderr, "%s: Your current working directory has a really long name.\n", argv[0]); + exit (1); + } + + Cwdl = strlen (Cwd); - doit (argv[1], NULL, 0); + doit (argv[1], Cwd, 0); return 0; } -void doit (const char *fname, const char *prefix, int crlf_pending) +void doit (const char *fname, char *prefix, int crlf_pending) { char buffer[2048]; char tmpf[2048]; FILE *fp; char *cp; - size_t l; + + if (strncmp (prefix, Cwd, Cwdl) == 0) + { + prefix += Cwdl; + if (*prefix == '/') + prefix++; + } + + if (!*prefix) + prefix = NULL; + if (!(fp = fopen (fname, "r"))) { perror (fname); @@ -43,11 +67,9 @@ void doit (const char *fname, const char *prefix, int crlf_pending) while (fgets (buffer, sizeof (buffer), fp)) { l = strlen (buffer); - if (*buffer == '\f') - { - if (!crlf_pending) - fputs (buffer, stdout); - } + + if (*buffer == '\f' && !crlf_pending) + fputs (buffer, stdout); else if (crlf_pending && l > 9 && !strcmp (buffer + l - 9, ",include\n")) { if ((cp = strrchr (buffer, ','))) @@ -69,5 +91,3 @@ void doit (const char *fname, const char *prefix, int crlf_pending) fclose (fp); } - - |