home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnurecod.zip / flat.c < prev    next >
C/C++ Source or Header  |  1994-02-04  |  2KB  |  99 lines

  1. /* Conversion of files between different charsets and usages.
  2.    Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc.
  3.    Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful, but
  11.    WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include "recode.h"
  21.  
  22. static int
  23. file_ascii_flat (const STEP *step, FILE *input_file, FILE *output_file)
  24. {
  25.   int input_char;        /* current character */
  26.   int temp_char;        /* look ahead character */
  27.  
  28.   input_char = getc (input_file);
  29.   while (1)
  30.     switch (input_char)
  31.       {
  32.       case EOF:
  33.     return 0;
  34.  
  35.       case '\n':
  36.       case '\t':
  37.     putc (input_char, output_file);
  38.     input_char = getc (input_file);
  39.     break;
  40.  
  41.       case '\b':
  42.     input_char = getc (input_file);
  43.     switch (input_char)
  44.       {
  45.       case '\'':
  46.       case '`':
  47.       case '^':
  48.       case '"':
  49.       case '~':
  50.       case ',':
  51.       case '_':
  52.         input_char = getc (input_file);
  53.         break;
  54.  
  55.       default:
  56.         putc ('\b', output_file);
  57.       }
  58.     break;
  59.  
  60.       case '\'':
  61.       case '`':
  62.       case '^':
  63.       case '"':
  64.       case '~':
  65.       case ',':
  66.       case '_':
  67.     temp_char = getc (input_file);
  68.     if (temp_char == '\b')
  69.       input_char = getc (input_file);
  70.     else
  71.       {
  72.         putc (input_char, output_file);
  73.         input_char = temp_char;
  74.       }
  75.     break;
  76.  
  77.       default:
  78.     if (input_char & (1 << 7))
  79.       {
  80.         putc ('M', output_file);
  81.         putc ('-', output_file);
  82.         input_char &= ~(~0 << 7);
  83.       }
  84.     if (input_char < ' ' || input_char == ~(~0 << 7))
  85.       {
  86.         putc ('^', output_file);
  87.         input_char ^= (1 << 6);
  88.       }
  89.     putc (input_char, output_file);
  90.     input_char = getc (input_file);
  91.       }
  92. }
  93.  
  94. void
  95. module_flat (void)
  96. {
  97.   declare_step ("ASCII-BS", "flat", MANY_TO_MANY, NULL, file_ascii_flat);
  98. }
  99.