~ubuntu-branches/ubuntu/utopic/geany/utopic

« back to all changes in this revision

Viewing changes to tagmanager/diff.c

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-12-10 07:43:26 UTC
  • mfrom: (3.3.7 sid)
  • Revision ID: package-import@ubuntu.com-20111210074326-s8yqbew5i20h33tf
Tags: 0.21-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  - debian/patches/20_use_evince_viewer.patch:
     + use evince as viewer for pdf and dvi files
  - debian/patches/20_use_x_terminal_emulator.patch:
     + use x-terminal-emulator as terminal
  - debian/control
     + Add breaks on geany-plugins-common << 0.20
* Also fixes bugs:
  - Filter for MATLAB/Octave files filters everythign (LP: 885505)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        { TRUE, 'f', "function", "functions"}
32
32
};
33
33
 
 
34
enum {
 
35
        DIFF_DELIM_MINUS = 0,
 
36
        DIFF_DELIM_PLUS
 
37
};
 
38
 
 
39
static const char *DiffDelims[2] = {
 
40
        "--- ",
 
41
        "+++ "
 
42
};
 
43
 
34
44
/*
35
45
*   FUNCTION DEFINITIONS
36
46
*/
37
47
 
 
48
static const unsigned char *stripAbsolute (const unsigned char *filename)
 
49
{
 
50
        const unsigned char *tmp;
 
51
 
 
52
        /* strip any absolute path */
 
53
        if (*filename == '/' || *filename == '\\')
 
54
        {
 
55
                boolean skipSlash = TRUE;
 
56
 
 
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;
 
65
                        }
 
66
                }
 
67
 
 
68
                /* skip the leading slash or backslash */
 
69
                if (skipSlash)
 
70
                        tmp++;
 
71
        }
 
72
        else
 
73
                tmp = filename;
 
74
 
 
75
        return tmp;
 
76
}
 
77
 
38
78
static void findDiffTags (void)
39
79
{
40
80
        vString *filename = vStringNew ();
41
81
        const unsigned char *line, *tmp;
 
82
        int delim = DIFF_DELIM_MINUS;
42
83
 
43
84
        while ((line = fileReadLine ()) != NULL)
44
85
        {
45
86
                const unsigned char* cp = line;
46
 
                boolean skipSlash = FALSE;
47
87
 
48
 
                if (strncmp((const char*) cp, "--- ", (size_t) 4) == 0)
 
88
                if (strncmp ((const char*) cp, DiffDelims[delim], 4u) == 0)
49
89
                {
50
90
                        cp += 4;
51
91
                        if (isspace ((int) *cp)) continue;
52
 
 
53
 
                        /* strip any absolute path */
54
 
                        if (*cp == '/' || *cp == '\\')
 
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])))
55
96
                        {
56
 
                                skipSlash = TRUE;
57
 
                                tmp = (const unsigned char*) strrchr((const char*) cp,  '/');
58
 
                                if (tmp == NULL)
59
 
                                {       /* if no / is contained try \ in case of a Windows filename */
60
 
                                        tmp = (const unsigned char*) strrchr((const char*) cp, '\\');
61
 
                                        if (tmp == NULL)
62
 
                                        {       /* last fallback, probably the filename doesn't contain a path, so take it */
63
 
                                                if (strlen((const char*) cp) > 0)
64
 
                                                {
65
 
                                                        tmp = cp;
66
 
                                                        skipSlash = FALSE;
67
 
                                                }
68
 
                                        }
69
 
                                }
 
97
                                delim = DIFF_DELIM_PLUS;
 
98
                                continue;
70
99
                        }
71
 
                        else
72
 
                                tmp = cp;
 
100
 
 
101
                        tmp = stripAbsolute (cp);
73
102
 
74
103
                        if (tmp != NULL)
75
104
                        {
76
 
                                if (skipSlash) tmp++; /* skip the leading slash or backslash */
77
105
                                while (! isspace(*tmp) && *tmp != '\0')
78
106
                                {
79
107
                                        vStringPut(filename, *tmp);
80
108
                                        tmp++;
81
109
                                }
 
110
 
82
111
                                vStringTerminate(filename);
83
112
                                makeSimpleTag (filename, DiffKinds, K_FUNCTION);
84
113
                                vStringClear (filename);
85
114
                        }
 
115
 
 
116
                        /* restore default delim */
 
117
                        delim = DIFF_DELIM_MINUS;
86
118
                }
87
119
        }
88
120
        vStringDelete (filename);