FOSSology  4.4.0
Open Source License Compliance by Open Source Software
highlight.c
1 /*
2  Author: Daniele Fognini, Andreas Wuerl
3  SPDX-FileCopyrightText: © 2013-2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 #include "highlight.h"
9 #include "string_operations.h"
10 
11 void convertToAbsoluteHighlight(const GArray* tokens, DiffPoint* indexHighlight) {
12  Token* firstToken = tokens_index(tokens, indexHighlight->start);
13 
14  size_t start = token_position_of(indexHighlight->start, tokens);
15 
16  size_t length = 0;
17  if (indexHighlight->length > 0)
18  length += token_length(*firstToken);
19 
20  for (size_t j = indexHighlight->start + 1;
21  j < indexHighlight->start + indexHighlight->length;
22  j++) {
23  Token* currentToken = tokens_index(tokens, j);
24  length += token_length(*currentToken) + currentToken->removedBefore;
25  }
26 
27  indexHighlight->start = start;
28  indexHighlight->length = length;
29 }
30 
31 void convertToAbsolutePositions(GArray* diffMatchInfo,
32  GArray* textTokens,
33  GArray* searchTokens) {
34  size_t len = diffMatchInfo->len;
35  for (size_t i = 0; i < len; i++) {
36  DiffMatchInfo *current = &g_array_index(diffMatchInfo, DiffMatchInfo, i);
37 
38  convertToAbsoluteHighlight(textTokens, &current->text);
39  convertToAbsoluteHighlight(searchTokens, &current->search);
40  }
41 }
42 
43 DiffPoint getFullHighlightFor(const GArray* tokens, size_t firstMatchedIndex, size_t matchedCount) {
44  size_t matchStart = token_position_of(firstMatchedIndex, tokens);
45  if (matchedCount < 1)
46  return (DiffPoint){matchStart, 0};
47 
48  size_t lastMatchedIndex = firstMatchedIndex + matchedCount - 1;
49  Token* lastMatchedToken = tokens_index(tokens, lastMatchedIndex);
50  size_t matchLength = token_position_of(lastMatchedIndex, tokens)
51  - matchStart
52  + token_length(*lastMatchedToken);
53 
54  return (DiffPoint){matchStart, matchLength};
55 }
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>....
Definition: pkgConfig.php:1214
Definition: diff.h:14