File: diff.c

package info (click to toggle)
geany 0.19.1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 15,216 kB
  • ctags: 12,981
  • sloc: ansic: 75,212; cpp: 36,044; sh: 9,336; python: 660; makefile: 622; xml: 119; cs: 64; java: 58; perl: 49; ada: 42; fortran: 41; tcl: 31; asm: 27; sql: 22; ruby: 6; php: 1
file content (104 lines) | stat: -rw-r--r-- 2,297 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
*
*   Copyright (c) 2000-2001, Darren Hiebert
*
*   This source code is released for free distribution under the terms of the
*   GNU General Public License.
*
*   This module contains functions for generating tags for diff files (based on Sh parser).
*/

/*
*   INCLUDE FILES
*/
#include "general.h"	/* must always come first */

#include <ctype.h>
#include <string.h>

#include "parse.h"
#include "read.h"
#include "vstring.h"

/*
*   DATA DEFINITIONS
*/
typedef enum {
	K_FUNCTION
} diffKind;

static kindOption DiffKinds [] = {
	{ TRUE, 'f', "function", "functions"}
};

/*
*   FUNCTION DEFINITIONS
*/

static void findDiffTags (void)
{
	vString *filename = vStringNew ();
	const unsigned char *line, *tmp;

	while ((line = fileReadLine ()) != NULL)
	{
		const unsigned char* cp = line;
		boolean skipSlash = FALSE;

		if (strncmp((const char*) cp, "--- ", (size_t) 4) == 0)
		{
			cp += 4;
			if (isspace ((int) *cp)) continue;

			/* strip any absolute path */
			if (*cp == '/' || *cp == '\\')
			{
				skipSlash = TRUE;
				tmp = (const unsigned char*) strrchr((const char*) cp,  '/');
				if (tmp == NULL)
				{	/* if no / is contained try \ in case of a Windows filename */
					tmp = (const unsigned char*) strrchr((const char*) cp, '\\');
					if (tmp == NULL)
					{	/* last fallback, probably the filename doesn't contain a path, so take it */
						if (strlen((const char*) cp) > 0)
						{
							tmp = cp;
							skipSlash = FALSE;
						}
					}
				}
			}
			else
				tmp = cp;

			if (tmp != NULL)
			{
				if (skipSlash) tmp++; /* skip the leading slash or backslash */
				while (! isspace(*tmp) && *tmp != '\0')
				{
					vStringPut(filename, *tmp);
					tmp++;
				}
				vStringTerminate(filename);
				makeSimpleTag (filename, DiffKinds, K_FUNCTION);
				vStringClear (filename);
			}
		}
	}
	vStringDelete (filename);
}

extern parserDefinition* DiffParser (void)
{
	static const char *const patterns [] = { "*.diff", "*.patch", NULL };
	static const char *const extensions [] = { "diff", NULL };
	parserDefinition* const def = parserNew ("Diff");
	def->kinds      = DiffKinds;
	def->kindCount  = KIND_COUNT (DiffKinds);
	def->patterns   = patterns;
	def->extensions = extensions;
	def->parser     = findDiffTags;
	return def;
}

/* vi:set tabstop=8 shiftwidth=4: */