FOSSology  4.4.0
Open Source License Compliance by Open Source Software
nomos_gap.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2013-2014 Siemens AG
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #include "nomos_gap.h"
8 #include <stdio.h> /* printf, scanf, NULL */
9 #include <stdlib.h> /* malloc, free, rand */
10 
19 GArray* collapseInvisible(char* text, char invisible)
20 {
21  int offset = 0;
22  char* readPointer = text;
23  char* writePointer = text;
24  int iAmVisible;
25  GArray* pairs = g_array_new(FALSE, FALSE, sizeof(pairPosOff));
26  for( iAmVisible = FALSE; *readPointer; readPointer++)
27  {
28  if(*readPointer == invisible){
29  offset++;
30  iAmVisible = FALSE;
31  continue;
32  }
33  // now: *readPointer != invisible
34  if (!iAmVisible){
35  pairPosOff pair;
36  pair.pos = writePointer-text;
37  pair.off = offset;
38  g_array_append_val(pairs, pair);
39  iAmVisible = TRUE;
40  }
41  *writePointer++ = *readPointer;
42  }
43  *writePointer = '\0';
44  return pairs;
45 }
46 
51 GArray* collapseSpaces(char* text)
52 {
53  int start = 0;
54  int cutOff; /* -1,0,1,... */
55  char* readPointer = text;
56  char* writePointer = text;
57  GArray* pairs = g_array_new(FALSE, FALSE, sizeof(pairPosOff));
58  for( cutOff=1; *readPointer; readPointer++)
59  {
60  if((*readPointer!=' ') && (cutOff>0)){
61  pairPosOff pair;
62  pair.pos = start;
63  pair.off = readPointer-writePointer;
64  g_array_append_val(pairs, pair);
65  }
66  if(*readPointer==' '){
67  cutOff++;
68  }
69  else{ // far away from cutting
70  cutOff = -1;
71  }
72  if (cutOff==0){
73  start = writePointer+1-text;
74  }
75  if (cutOff < 1){
76  *writePointer++ = *readPointer;
77  }
78  }
79  *writePointer = '\0';
80  return pairs;
81 }
82 
83 inline pairPosOff* getPairPosOff(GArray* in, int index)
84 {
85  return &g_array_index(in, pairPosOff, index);
86 }
87 
88 int uncollapsePosition(int collapsedPos, GArray* shifter)
89 {
90  int shifterIndex;
91  pairPosOff* thePoA;
92  for (shifterIndex = 1; shifterIndex < shifter->len; ++shifterIndex) {
93  thePoA = getPairPosOff(shifter, shifterIndex);
94  if (thePoA->pos > collapsedPos) {
95  break;
96  }
97  }
98  thePoA = getPairPosOff(shifter, shifterIndex - 1);
99  return collapsedPos + thePoA->off;
100 }
GArray * collapseInvisible(char *text, char invisible)
Definition: nomos_gap.c:19
GArray * collapseSpaces(char *text)
Definition: nomos_gap.c:51
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>....
Definition: pkgConfig.php:1214