1diff --git a/main/parsers.h b/main/parsers.h 2index 8000fa0..5332052 100644 3--- a/main/parsers.h 4+++ b/main/parsers.h 5@@ -28,6 +28,7 @@ 6 CsharpParser, \ 7 CobolParser, \ 8 DParser, \ 9+ DiffParser, \ 10 DosBatchParser, \ 11 EiffelParser, \ 12 ErlangParser, \ 13diff --git a/parsers/diff.c b/parsers/diff.c 14new file mode 100644 15index 0000000..a1bf5f3 16--- /dev/null 17+++ b/parsers/diff.c 18@@ -0,0 +1,134 @@ 19+/* 20+* 21+* Copyright (c) 2000-2001, Darren Hiebert 22+* 23+* This source code is released for free distribution under the terms of the 24+* GNU General Public License. 25+* 26+* This module contains functions for generating tags for diff files (based on Sh parser). 27+*/ 28+ 29+/* 30+* INCLUDE FILES 31+*/ 32+#include "general.h" /* must always come first */ 33+ 34+#include <ctype.h> 35+#include <string.h> 36+ 37+#include "parse.h" 38+#include "read.h" 39+#include "vstring.h" 40+ 41+/* 42+* DATA DEFINITIONS 43+*/ 44+typedef enum { 45+ K_FUNCTION 46+} diffKind; 47+ 48+static kindOption DiffKinds [] = { 49+ { TRUE, 'f', "compared file", "compared files"} 50+}; 51+ 52+enum { 53+ DIFF_DELIM_MINUS = 0, 54+ DIFF_DELIM_PLUS 55+}; 56+ 57+static const char *DiffDelims[2] = { 58+ "--- ", 59+ "+++ " 60+}; 61+ 62+/* 63+* FUNCTION DEFINITIONS 64+*/ 65+ 66+static const unsigned char *stripAbsolute (const unsigned char *filename) 67+{ 68+ const unsigned char *tmp; 69+ 70+ /* strip any absolute path */ 71+ if (*filename == '/' || *filename == '\\') 72+ { 73+ boolean skipSlash = TRUE; 74+ 75+ tmp = (const unsigned char*) strrchr ((const char*) filename, '/'); 76+ if (tmp == NULL) 77+ { /* if no / is contained try \ in case of a Windows filename */ 78+ tmp = (const unsigned char*) strrchr ((const char*) filename, '\\'); 79+ if (tmp == NULL) 80+ { /* last fallback, probably the filename doesn't contain a path, so take it */ 81+ tmp = filename; 82+ skipSlash = FALSE; 83+ } 84+ } 85+ 86+ /* skip the leading slash or backslash */ 87+ if (skipSlash) 88+ tmp++; 89+ } 90+ else 91+ tmp = filename; 92+ 93+ return tmp; 94+} 95+ 96+static void findDiffTags (void) 97+{ 98+ vString *filename = vStringNew (); 99+ const unsigned char *line, *tmp; 100+ int delim = DIFF_DELIM_MINUS; 101+ 102+ while ((line = fileReadLine ()) != NULL) 103+ { 104+ const unsigned char* cp = line; 105+ 106+ if (strncmp ((const char*) cp, DiffDelims[delim], 4u) == 0) 107+ { 108+ cp += 4; 109+ if (isspace ((int) *cp)) continue; 110+ /* when original filename is /dev/null use the new one instead */ 111+ if (delim == DIFF_DELIM_MINUS && 112+ strncmp ((const char*) cp, "/dev/null", 9u) == 0 && 113+ (cp[9] == 0 || isspace (cp[9]))) 114+ { 115+ delim = DIFF_DELIM_PLUS; 116+ continue; 117+ } 118+ 119+ tmp = stripAbsolute (cp); 120+ 121+ if (tmp != NULL) 122+ { 123+ while (! isspace(*tmp) && *tmp != '\0') 124+ { 125+ vStringPut(filename, *tmp); 126+ tmp++; 127+ } 128+ 129+ vStringTerminate(filename); 130+ makeSimpleTag (filename, DiffKinds, K_FUNCTION); 131+ vStringClear (filename); 132+ } 133+ 134+ /* restore default delim */ 135+ delim = DIFF_DELIM_MINUS; 136+ } 137+ } 138+ vStringDelete (filename); 139+} 140+ 141+extern parserDefinition* DiffParser (void) 142+{ 143+ static const char *const extensions [] = { "diff", "patch", NULL }; 144+ parserDefinition* const def = parserNew ("Diff"); 145+ def->kinds = DiffKinds; 146+ def->kindCount = KIND_COUNT (DiffKinds); 147+ def->extensions = extensions; 148+ def->parser = findDiffTags; 149+ return def; 150+} 151+ 152+/* vi:set tabstop=8 shiftwidth=4: */ 153diff --git a/source.mak b/source.mak 154index 2550028..eaa9154 100644 155--- a/source.mak 156+++ b/source.mak 157@@ -44,6 +44,7 @@ PARSER_SOURCES = \ 158 $(PARSER_DIR)/clojure.c \ 159 $(PARSER_DIR)/css.c \ 160 $(PARSER_DIR)/cobol.c \ 161+ $(PARSER_DIR)/diff.c \ 162 $(PARSER_DIR)/dosbatch.c \ 163 $(PARSER_DIR)/eiffel.c \ 164 $(PARSER_DIR)/erlang.c \ 165 166--- a/Units/review-needed.r/simple.ksh.t/expected.tags 167+++ /dev/null 168@@ -1,2 +0,0 @@ 169-f1 input.ksh /^f1() {$/;" f 170-f2 input.ksh /^function f2 {$/;" f 171