FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
nomos_gap.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 2013-2014, Siemens AG
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 */
17 
18 #include "nomos_gap.h"
19 #include <stdio.h> /* printf, scanf, NULL */
20 #include <stdlib.h> /* malloc, free, rand */
21 
30 GArray* collapseInvisible(char* text, char invisible)
31 {
32  int offset = 0;
33  char* readPointer = text;
34  char* writePointer = text;
35  int iAmVisible;
36  GArray* pairs = g_array_new(FALSE, FALSE, sizeof(pairPosOff));
37  for( iAmVisible = FALSE; *readPointer; readPointer++)
38  {
39  if(*readPointer == invisible){
40  offset++;
41  iAmVisible = FALSE;
42  continue;
43  }
44  // now: *readPointer != invisible
45  if (!iAmVisible){
46  pairPosOff pair;
47  pair.pos = writePointer-text;
48  pair.off = offset;
49  g_array_append_val(pairs, pair);
50  iAmVisible = TRUE;
51  }
52  *writePointer++ = *readPointer;
53  }
54  *writePointer = '\0';
55  return pairs;
56 }
57 
62 GArray* collapseSpaces(char* text)
63 {
64  int start = 0;
65  int cutOff; /* -1,0,1,... */
66  char* readPointer = text;
67  char* writePointer = text;
68  GArray* pairs = g_array_new(FALSE, FALSE, sizeof(pairPosOff));
69  for( cutOff=1; *readPointer; readPointer++)
70  {
71  if((*readPointer!=' ') && (cutOff>0)){
72  pairPosOff pair;
73  pair.pos = start;
74  pair.off = readPointer-writePointer;
75  g_array_append_val(pairs, pair);
76  }
77  if(*readPointer==' '){
78  cutOff++;
79  }
80  else{ // far away from cutting
81  cutOff = -1;
82  }
83  if (cutOff==0){
84  start = writePointer+1-text;
85  }
86  if (cutOff < 1){
87  *writePointer++ = *readPointer;
88  }
89  }
90  *writePointer = '\0';
91  return pairs;
92 }
93 
94 inline pairPosOff* getPairPosOff(GArray* in, int index)
95 {
96  return &g_array_index(in, pairPosOff, index);
97 }
98 
99 int uncollapsePosition(int collapsedPos, GArray* shifter)
100 {
101  int shifterIndex;
102  pairPosOff* thePoA;
103  for (shifterIndex = 1; shifterIndex < shifter->len; ++shifterIndex) {
104  thePoA = getPairPosOff(shifter, shifterIndex);
105  if (thePoA->pos > collapsedPos) {
106  break;
107  }
108  }
109  thePoA = getPairPosOff(shifter, shifterIndex - 1);
110  return collapsedPos + thePoA->off;
111 }
GArray * collapseInvisible(char *text, char invisible)
Definition: nomos_gap.c:30
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
GArray * collapseSpaces(char *text)
Definition: nomos_gap.c:62