The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
no13.c File Reference
#include <fcntl.h>
#include <stdio.h>
+ Include dependency graph for no13.c:

Go to the source code of this file.

Functions

 main (int argc, char **argv)
 

Function Documentation

main ( int  argc,
char **  argv 
)

Definition at line 25 of file no13.c.

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 }
#define S_IRGRP
Definition: filemgr.cpp:52
#define S_IREAD
Definition: filemgr.cpp:70
#define S_IROTH
Definition: filemgr.cpp:56
#define S_IWRITE
Definition: filemgr.cpp:73