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 version 2 or (at your option) any later version.
8 * This module contains functions for generating tags for diff files (based on Sh parser).
14 #include "general.h" /* must always come first */
31 static kindOption DiffKinds
[] = {
32 { TRUE
, 'f', "function", "functions"}
40 static const char *DiffDelims
[2] = {
46 * FUNCTION DEFINITIONS
49 static const unsigned char *stripAbsolute (const unsigned char *filename
)
51 const unsigned char *tmp
;
53 /* strip any absolute path */
54 if (*filename
== '/' || *filename
== '\\')
56 boolean skipSlash
= TRUE
;
58 tmp
= (const unsigned char*) strrchr ((const char*) filename
, '/');
60 { /* if no / is contained try \ in case of a Windows filename */
61 tmp
= (const unsigned char*) strrchr ((const char*) filename
, '\\');
63 { /* last fallback, probably the filename doesn't contain a path, so take it */
69 /* skip the leading slash or backslash */
79 static void findDiffTags (void)
81 vString
*filename
= vStringNew ();
82 const unsigned char *line
, *tmp
;
83 int delim
= DIFF_DELIM_MINUS
;
85 while ((line
= fileReadLine ()) != NULL
)
87 const unsigned char* cp
= line
;
89 if (strncmp ((const char*) cp
, DiffDelims
[delim
], 4u) == 0)
92 if (isspace ((int) *cp
)) continue;
93 /* when original filename is /dev/null use the new one instead */
94 if (delim
== DIFF_DELIM_MINUS
&&
95 strncmp ((const char*) cp
, "/dev/null", 9u) == 0 &&
96 (cp
[9] == 0 || isspace (cp
[9])))
98 delim
= DIFF_DELIM_PLUS
;
102 tmp
= stripAbsolute (cp
);
106 while (! isspace(*tmp
) && *tmp
!= '\0')
108 vStringPut(filename
, *tmp
);
112 vStringTerminate(filename
);
113 makeSimpleTag (filename
, DiffKinds
, K_FUNCTION
);
114 vStringClear (filename
);
117 /* restore default delim */
118 delim
= DIFF_DELIM_MINUS
;
121 vStringDelete (filename
);
124 extern parserDefinition
* DiffParser (void)
126 static const char *const patterns
[] = { "*.diff", "*.patch", NULL
};
127 static const char *const extensions
[] = { "diff", NULL
};
128 parserDefinition
* const def
= parserNew ("Diff");
129 def
->kinds
= DiffKinds
;
130 def
->kindCount
= KIND_COUNT (DiffKinds
);
131 def
->patterns
= patterns
;
132 def
->extensions
= extensions
;
133 def
->parser
= findDiffTags
;
137 /* vi:set tabstop=8 shiftwidth=4: */