File: flat.c

package info (click to toggle)
recode 3.4.1-11
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,560 kB
  • ctags: 622
  • sloc: ansic: 10,572; perl: 339; makefile: 317; lisp: 243; sh: 173; lex: 165; awk: 127; sed: 10
file content (98 lines) | stat: -rw-r--r-- 2,285 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* Conversion of files between different charsets and usages.
   Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc.
   Francois Pinard <pinard@iro.umontreal.ca>, 1988.

   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; either version 2, or (at your option)
   any later version.

   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.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "recode.h"

static int
file_ascii_flat (const STEP *step, FILE *input_file, FILE *output_file)
{
  int input_char;		/* current character */
  int temp_char;		/* look ahead character */

  input_char = getc (input_file);
  while (1)
    switch (input_char)
      {
      case EOF:
	return 0;

      case '\n':
      case '\t':
	putc (input_char, output_file);
	input_char = getc (input_file);
	break;

      case '\b':
	input_char = getc (input_file);
	switch (input_char)
	  {
	  case '\'':
	  case '`':
	  case '^':
	  case '"':
	  case '~':
	  case ',':
	  case '_':
	    input_char = getc (input_file);
	    break;

	  default:
	    putc ('\b', output_file);
	  }
	break;

      case '\'':
      case '`':
      case '^':
      case '"':
      case '~':
      case ',':
      case '_':
	temp_char = getc (input_file);
	if (temp_char == '\b')
	  input_char = getc (input_file);
	else
	  {
	    putc (input_char, output_file);
	    input_char = temp_char;
	  }
	break;

      default:
	if (input_char & (1 << 7))
	  {
	    putc ('M', output_file);
	    putc ('-', output_file);
	    input_char &= ~(~0 << 7);
	  }
	if (input_char < ' ' || input_char == ~(~0 << 7))
	  {
	    putc ('^', output_file);
	    input_char ^= (1 << 6);
	  }
	putc (input_char, output_file);
	input_char = getc (input_file);
      }
}

void
module_flat (void)
{
  declare_step ("ASCII-BS", "flat", MANY_TO_MANY, NULL, file_ascii_flat);
}