The SWORD Project
1.9.0.svnversion
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
no13.c
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* no13.c - Strips ascii 13 chars out of a file
4
*
5
* $Id: no13.c 2833 2013-06-29 06:40:28Z chrislit $
6
*
7
* Copyright 1996-2013 CrossWire Bible Society (http://www.crosswire.org)
8
* CrossWire Bible Society
9
* P. O. Box 2528
10
* Tempe, AZ 85280-2528
11
*
12
* This program is free software; you can redistribute it and/or modify it
13
* under the terms of the GNU General Public License as published by the
14
* Free Software Foundation version 2.
15
*
16
* This program is distributed in the hope that it will be useful, but
17
* WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* General Public License for more details.
20
*
21
*/
22
#include <fcntl.h>
23
#include <stdio.h>
24
25
main
(
int
argc,
char
**argv)
26
{
27
int
fd, loop;
28
char
ch;
29
char
breakcnt = 0;
30
31
if
(argc != 2) {
32
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]);
33
exit(1);
34
}
35
fd = open(argv[1], O_RDONLY,
S_IREAD
|
S_IWRITE
|
S_IRGRP
|
S_IROTH
);
36
while
(read(fd, &ch, 1) == 1) {
37
if
(ch == 0x0d) {
// CR
38
breakcnt++;
39
continue
;
40
}
41
if
(ch == 0x1a)
// Ctrl-Z
42
continue
;
43
44
if
(ch != 0x0a) {
// LF
45
if
(breakcnt > 1) {
46
for
(loop = breakcnt; loop > 0; loop--)
47
putchar(0x0d);
48
putchar(0x0a);
49
}
50
breakcnt=0;
51
}
52
putchar(ch);
53
}
54
close(fd);
55
}
S_IRGRP
#define S_IRGRP
Definition:
filemgr.cpp:52
S_IREAD
#define S_IREAD
Definition:
filemgr.cpp:70
main
int main(int argc, char **argv)
Definition:
addcomment.cpp:32
S_IROTH
#define S_IROTH
Definition:
filemgr.cpp:56
S_IWRITE
#define S_IWRITE
Definition:
filemgr.cpp:73
utilities
no13.c
Generated by
1.8.5