FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
match.h
1 /*
2 Author: Daniele Fognini, Andreas Wuerl
3 Copyright (C) 2013-2014, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #ifndef MONK_AGENT_MATCH_H
20 #define MONK_AGENT_MATCH_H
21 
22 #include <glib.h>
23 
24 #include "monk.h"
25 #include "string_operations.h"
26 #include "diff.h"
27 
28 #define MATCH_TYPE_FULL 0
29 #define MATCH_TYPE_DIFF 1
30 
31 typedef struct {
32  const License* license;
33  union {
34  DiffPoint* full;
35  DiffResult* diff;
36  } ptr;
37  int type;
38 } Match;
39 
40 typedef struct {
41  int (*onAll)(MonkState* state, const File* file, const GArray* matches);
42  int (*onNo)(MonkState* state, const File* file);
43  int (*onFull)(MonkState* state, const File* file, const License* license, const DiffMatchInfo* matchInfo);
44  int (*onDiff)(MonkState* state, const File* file, const License* license, const DiffResult* diffResult);
45  int (*onBeginOutput)(MonkState* state);
46  int (*onBetweenIndividualOutputs)(MonkState* state);
47  int (*onEndOutput)(MonkState* state);
48  int (*ignore)(MonkState* state, const File* file);
50 
51 void match_array_free(GArray* matches);
52 #define match_array_index(matches, i) (g_array_index(matches, Match*, i))
53 
54 void match_free(Match* match);
55 
56 #if GLIB_CHECK_VERSION(2,32,0)
57 void match_destroyNotify(gpointer matchP);
58 #endif
59 
60 size_t match_getStart(const Match* match);
61 size_t match_getEnd(const Match* match);
62 
63 GArray* findAllMatchesBetween(const File* file, const Licenses* licenses, unsigned maxAllowedDiff, unsigned minAdjacentMatches, unsigned maxLeadingDiff);
64 
65 int matchPFileWithLicenses(MonkState* state, long pFileId, const Licenses* licenses, const MatchCallbacks* callbacks);
66 int matchFileWithLicenses(MonkState* state, const File* file, const Licenses* licenses, const MatchCallbacks* callbacks);
67 
68 void findDiffMatches(const File* file, const License* license,
69  size_t textStartPosition, size_t searchStartPosition,
70  GArray* matches,
71  unsigned maxAllowedDiff, unsigned minAdjacentMatches);
72 
73 GArray* filterNonOverlappingMatches(GArray* matches);
74 int match_partialComparator(const Match* thisMatch, const Match* otherMatch);
75 
76 int processMatches(MonkState* state, const File* file, const GArray* matches, const MatchCallbacks* callbacks);
77 
78 char* formatMatchArray(GArray* matchInfo);
79 
80 #endif // MONK_AGENT_MATCH_H
Definition: monk.h:78
Definition: match.h:31
Definition: monk.h:55
Store the results of a regex match.
Definition: scanners.hpp:39
Definition: monk.h:72
Definition: nomos.h:439
Definition: monk.h:66
Definition: diff.h:25
void matchFileWithLicenses(const string &sContent, unsigned long pFileId, CopyrightState const &state, int agentId, CopyrightDatabaseHandler &databaseHandler)
Scan a given file with all available scanners and save findings to database.
void matchPFileWithLicenses(CopyrightState const &state, int agentId, unsigned long pFileId, CopyrightDatabaseHandler &databaseHandler)
Get the file contents, scan for statements and save findings to database.