mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2025-12-31 23:00:54 -08:00
Small replacement for sed
This commit is contained in:
parent
c38671bc3e
commit
4613cb05be
1 changed files with 57 additions and 0 deletions
57
src/util/cut.c
Normal file
57
src/util/cut.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#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]))) {
|
||||
b3[0] = 0;
|
||||
strcpy(b2, b1);
|
||||
strcat(b2, patterns[i+1]);
|
||||
strcat(b2, b3 + lengths[i]);
|
||||
b4 = b2; b2 = b1; b1 = b4;
|
||||
}
|
||||
}
|
||||
puts(b1);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int narg, char **argv) {
|
||||
char buffer[1024];
|
||||
|
||||
narg--;
|
||||
argv++;
|
||||
|
||||
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);
|
||||
}
|
||||
} else if (strstr(buffer, "declspec(dllimport)")) {
|
||||
/* This is used to removed the declspec(dllimport) from external.h */
|
||||
continue;
|
||||
}
|
||||
puts(buffer);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue