-
Notifications
You must be signed in to change notification settings - Fork 2
/
lib_str.c
152 lines (137 loc) · 3.96 KB
/
lib_str.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Lessfs: A data deduplicating filesystem.
* Copyright (C) 2008 Mark Ruijter <[email protected]>
*
* This program is free software.
* You can redistribute lessfs and/or modify it under the terms of either
* (1) the GNU General Public License; either version 3 of the License,
* or (at your option) any later version as published by
* the Free Software Foundation; or (2) obtain a commercial license
* by contacting the Author.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <unistd.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <ctype.h>
#include "lib_safe.h"
/******************************************************
* Procedure trim() *
* Doel : Ontdoe een regel van spaties,tabs,nl,cr *
* Input: char naam logbestand *
* Output: filehandler anders -1 *
******************************************************/
void trim(char *regel)
{
int tel;
int einde, lengte;
char *tmpstr;
if (regel == NULL)
return; /* Een lege string is niet te trimmen */
lengte = strlen(regel);
tmpstr = s_strdup(regel);
for (tel = 0; tel <= lengte; tel++) {
if (regel[tel] != ' ' && regel[tel] != '\t')
break;
}
einde = lengte;
if (einde == 0) {
regel[0] = 0;
free(tmpstr);
return; /* Na het begin v.d. regel trimmen niets over */
}
while (einde > 0) {
einde--;
if (regel[einde] != ' ' && regel[einde] != '\t'
&& regel[einde] != '\n' && regel[einde] != '\r')
break;
}
lengte = einde - tel + 1;
memcpy(®el[0], &tmpstr[tel], lengte);
regel[lengte] = 0;
free(tmpstr);
return;
}
void replacechar(char *buffer, char zoek, char vervang)
{
char *p;
p = buffer;
while (*buffer != 0) {
if (*buffer != zoek) {
*p = *buffer;
p++;
} else {
p[0] = vervang;
p++;
}
buffer++;
}
*p = 0;
}
/***********************************************************************
Procedure stripchar
Doel : Verwijderd een %c uit een %s
***********************************************************************/
void stripchar(char *a, char c)
{
char *p;
p = a;
while (*a != 0) {
if (*a != c) {
*p = *a;
p++;
}
a++;
}
*p = 0;
}
/***********************************************************************
Procedure lcase
Doel : Convert een string naar lowercase
***********************************************************************/
void lcase(char *convert)
{
while (*convert != 0) {
*convert = tolower(*convert);
convert++;
}
}
/***********************************************************************
Procedure ucase
Doel : Convert een string naar uppercase
***********************************************************************/
void ucase(char *convert)
{
while (*convert != 0) {
*convert = toupper(*convert);
convert++;
}
}
/***********************************************************************
Procedure unrem
Invoer regel[]
Uitvoer regel zonder remark's
return lengte ge 'unremde' string
***********************************************************************/
int unrem(char *regel)
{
char *c;
c = strchr(regel, '#');
if (c != NULL)
c[0] = 0;
return (strlen(regel));
}