Inital commit for simple tools repo
This commit is contained in:
commit
8f862e91e0
7 changed files with 285 additions and 0 deletions
41
spacesbreak
Executable file
41
spacesbreak
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/tcc -run
|
||||
/* vim: set syn=c: */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define WORD_BREAK " ()<>[]\""
|
||||
|
||||
static unsigned int is_word_break(char c);
|
||||
|
||||
int
|
||||
main() {
|
||||
char buffer, prevbuffer;
|
||||
size_t nread;
|
||||
|
||||
while ((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) {
|
||||
if (is_word_break(buffer))
|
||||
buffer = '\n';
|
||||
|
||||
if (buffer != '\n' || prevbuffer != '\n')
|
||||
fwrite(&buffer, 1, nread, stdout);
|
||||
|
||||
prevbuffer = buffer;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
is_word_break(char c) {
|
||||
static char *word_break = WORD_BREAK;
|
||||
char *s = word_break;
|
||||
|
||||
while (*s) {
|
||||
if (*s == c)
|
||||
return 1;
|
||||
s++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue