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).
14 #include "general.h" /* must always come first */
30 static kindOption DiffKinds
[] = {
31 { TRUE
, 'f', "function", "functions"}
39 static const char *DiffDelims
[2] = {
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
, '/');
59 { /* if no / is contained try \ in case of a Windows filename */
60 tmp
= (const unsigned char*) strrchr ((const char*) filename
, '\\');
62 { /* last fallback, probably the filename doesn't contain a path, so take it */
68 /* skip the leading slash or backslash */
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)
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
;
101 tmp
= stripAbsolute (cp
);
105 while (! isspace(*tmp
) && *tmp
!= '\0')
107 vStringPut(filename
, *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
;
136 /* vi:set tabstop=8 shiftwidth=4: */