summaryrefslogtreecommitdiff
path: root/utilities/no13.c
diff options
context:
space:
mode:
Diffstat (limited to 'utilities/no13.c')
-rw-r--r--utilities/no13.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/utilities/no13.c b/utilities/no13.c
new file mode 100644
index 0000000..5245d27
--- /dev/null
+++ b/utilities/no13.c
@@ -0,0 +1,34 @@
+#include <fcntl.h>
+#include <stdio.h>
+
+main(int argc, char **argv)
+{
+ int fd, loop;
+ char ch;
+ char breakcnt = 0;
+
+ if (argc != 2) {
+ fprintf(stderr, "This program writes to stdout, so to be useful,\n\tit should be redirected (e.g no13 bla > bla.dat)\nusage: %s <filename>\n", argv[0]);
+ exit(1);
+ }
+ fd = open(argv[1], O_RDONLY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+ while (read(fd, &ch, 1) == 1) {
+ if (ch == 0x0d) { // CR
+ breakcnt++;
+ continue;
+ }
+ if (ch == 0x1a) // Ctrl-Z
+ continue;
+
+ if (ch != 0x0a) { // LF
+ if (breakcnt > 1) {
+ for (loop = breakcnt; loop > 0; loop--)
+ putchar(0x0d);
+ putchar(0x0a);
+ }
+ breakcnt=0;
+ }
+ putchar(ch);
+ }
+ close(fd);
+}