Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[e90b2f]: src / util / cut.c Maximize Restore History

Download this file

cut.c    70 lines (61 with data), 1.2 kB

 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
#include <stdio.h>
#include <string.h>
void
sed_emulator(int narg, char **patterns)
{
char buffer[1024];
char buffer2[1024];
size_t i, lengths[1024];
char *b1 = buffer, *b2 = buffer2;
for (i = 0; i < narg; i++)
lengths[i] = strlen(patterns[i]);
while(1) {
if (gets(b1) == 0)
exit(0);
for (i = 0; i < narg; i+=2) {
char *b3, *b4;
while ((b3 = strstr(b1, patterns[i]))) {
if (strcmp(patterns[i+1], "/DELETE/") == 0)
goto GO_ON;
b3[0] = 0;
strcpy(b2, b1);
strcat(b2, patterns[i+1]);
strcat(b2, b3 + lengths[i]);
b4 = b2; b2 = b1; b1 = b4;
}
}
puts(b1);
GO_ON:;
}
}
int
main(int narg, char **argv) {
int i, j;
char buffer[1024];
narg--;
argv++;
/* To make canonical paths in Windows */
for (i = 1; i < narg; i+=2) {
char *new = strdup(argv[i]);
for (j = 0; new[j]; j++) {
if (new[j] == '\\') {
new[j] = '/';
}
}
argv[i] = new;
}
if (narg >= 2)
sed_emulator(narg, argv);
while(1) {
if (gets(buffer) == 0) {
exit(0);
}
if (narg == 0) {
/* This is used to remove part of config.h */
if (strstr(buffer, "-CUT-")) {
exit(0);
}
}
puts(buffer);
}
}