blob: f84cfcc0e805edbc565eeb5205a907d3f8afaf8b (
plain)
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
|
/******************************************************************************
* Strips ascii 13 chars out of a file
*
* $Id: no13.c 2327 2009-04-22 11:42:33Z scribe $
*
* Copyright 1998-2009 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2.
*
* 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.
*
*/
#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);
}
|