Update HACKING for changed doc generation instructions
[geany-mirror.git] / tagmanager / ctags / diff.c
blob5eec7c08a75c31c1b86937cab47ff585bca58a3e
1 /*
3 * Copyright (c) 2000-2001, Darren Hiebert
5 * This source code is released for free distribution under the terms of the
6 * GNU General Public License.
8 * This module contains functions for generating tags for diff files (based on Sh parser).
9 */
12 * INCLUDE FILES
14 #include "general.h" /* must always come first */
16 #include <ctype.h>
17 #include <string.h>
19 #include "parse.h"
20 #include "read.h"
21 #include "vstring.h"
24 * DATA DEFINITIONS
26 typedef enum {
27 K_FUNCTION
28 } diffKind;
30 static kindOption DiffKinds [] = {
31 { TRUE, 'f', "function", "functions"}
34 enum {
35 DIFF_DELIM_MINUS = 0,
36 DIFF_DELIM_PLUS
39 static const char *DiffDelims[2] = {
40 "--- ",
41 "+++ "
45 * FUNCTION DEFINITIONS
48 static const unsigned char *stripAbsolute (const unsigned char *filename)
50 const unsigned char *tmp;
52 /* strip any absolute path */
53 if (*filename == '/' || *filename == '\\')
55 boolean skipSlash = TRUE;
57 tmp = (const unsigned char*) strrchr ((const char*) filename, '/');
58 if (tmp == NULL)
59 { /* if no / is contained try \ in case of a Windows filename */
60 tmp = (const unsigned char*) strrchr ((const char*) filename, '\\');
61 if (tmp == NULL)
62 { /* last fallback, probably the filename doesn't contain a path, so take it */
63 tmp = filename;
64 skipSlash = FALSE;
68 /* skip the leading slash or backslash */
69 if (skipSlash)
70 tmp++;
72 else
73 tmp = filename;
75 return tmp;
78 static void findDiffTags (void)
80 vString *filename = vStringNew ();
81 const unsigned char *line, *tmp;
82 int delim = DIFF_DELIM_MINUS;
84 while ((line = fileReadLine ()) != NULL)
86 const unsigned char* cp = line;
88 if (strncmp ((const char*) cp, DiffDelims[delim], 4u) == 0)
90 cp += 4;
91 if (isspace ((int) *cp)) continue;
92 /* when original filename is /dev/null use the new one instead */
93 if (delim == DIFF_DELIM_MINUS &&
94 strncmp ((const char*) cp, "/dev/null", 9u) == 0 &&
95 (cp[9] == 0 || isspace (cp[9])))
97 delim = DIFF_DELIM_PLUS;
98 continue;
101 tmp = stripAbsolute (cp);
103 if (tmp != NULL)
105 while (! isspace(*tmp) && *tmp != '\0')
107 vStringPut(filename, *tmp);
108 tmp++;
111 vStringTerminate(filename);
112 makeSimpleTag (filename, DiffKinds, K_FUNCTION);
113 vStringClear (filename);
116 /* restore default delim */
117 delim = DIFF_DELIM_MINUS;
120 vStringDelete (filename);
123 extern parserDefinition* DiffParser (void)
125 static const char *const patterns [] = { "*.diff", "*.patch", NULL };
126 static const char *const extensions [] = { "diff", NULL };
127 parserDefinition* const def = parserNew ("Diff");
128 def->kinds = DiffKinds;
129 def->kindCount = KIND_COUNT (DiffKinds);
130 def->patterns = patterns;
131 def->extensions = extensions;
132 def->parser = findDiffTags;
133 return def;
136 /* vi:set tabstop=8 shiftwidth=4: */