FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
highlight.c
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 #include "highlight.h"
20 #include "string_operations.h"
21 
22 void convertToAbsoluteHighlight(const GArray* tokens, DiffPoint* indexHighlight) {
23  Token* firstToken = tokens_index(tokens, indexHighlight->start);
24 
25  size_t start = token_position_of(indexHighlight->start, tokens);
26 
27  size_t length = 0;
28  if (indexHighlight->length > 0)
29  length += token_length(*firstToken);
30 
31  for (size_t j = indexHighlight->start + 1;
32  j < indexHighlight->start + indexHighlight->length;
33  j++) {
34  Token* currentToken = tokens_index(tokens, j);
35  length += token_length(*currentToken) + currentToken->removedBefore;
36  }
37 
38  indexHighlight->start = start;
39  indexHighlight->length = length;
40 }
41 
42 void convertToAbsolutePositions(GArray* diffMatchInfo,
43  GArray* textTokens,
44  GArray* searchTokens) {
45  size_t len = diffMatchInfo->len;
46  for (size_t i = 0; i < len; i++) {
47  DiffMatchInfo *current = &g_array_index(diffMatchInfo, DiffMatchInfo, i);
48 
49  convertToAbsoluteHighlight(textTokens, &current->text);
50  convertToAbsoluteHighlight(searchTokens, &current->search);
51  }
52 }
53 
54 DiffPoint getFullHighlightFor(const GArray* tokens, size_t firstMatchedIndex, size_t matchedCount) {
55  size_t matchStart = token_position_of(firstMatchedIndex, tokens);
56  if (matchedCount < 1)
57  return (DiffPoint){matchStart, 0};
58 
59  size_t lastMatchedIndex = firstMatchedIndex + matchedCount - 1;
60  Token* lastMatchedToken = tokens_index(tokens, lastMatchedIndex);
61  size_t matchLength = token_position_of(lastMatchedIndex, tokens)
62  - matchStart
63  + token_length(*lastMatchedToken);
64 
65  return (DiffPoint){matchStart, matchLength};
66 }
Definition: diff.h:25
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>. The application passed in should match the script name in /etc/init.d
Definition: pkgConfig.php:1225