home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / GRECODE / FLAT.C < prev    next >
C/C++ Source or Header  |  1993-12-07  |  2KB  |  97 lines

  1. /* Conversion of files between different charsets and usages.
  2.    Copyright (C) 1990, 1993 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 void
  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;
  34.  
  35.       case '\n':
  36.       case '\t':
  37.     putc ('\n', 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.         input_char = getc (input_file);
  52.         break;
  53.  
  54.       default:
  55.         putc ('\b', output_file);
  56.       }
  57.     break;
  58.  
  59.       case '\'':
  60.       case '`':
  61.       case '^':
  62.       case '"':
  63.       case ',':
  64.       case '_':
  65.     temp_char = getc (input_file);
  66.     if (temp_char == '\b')
  67.       input_char = getc (input_file);
  68.     else
  69.       {
  70.         putc (input_char, output_file);
  71.         input_char = temp_char;
  72.       }
  73.     break;
  74.  
  75.       default:
  76.     if (input_char & (1 << 7))
  77.       {
  78.         putc ('M', output_file);
  79.         putc ('-', output_file);
  80.         input_char &= ~(~0 << 7);
  81.       }
  82.     if (input_char < ' ' || input_char == ~(~0 << 7))
  83.       {
  84.         putc ('^', output_file);
  85.         input_char ^= (1 << 6);
  86.       }
  87.     putc (input_char, output_file);
  88.     input_char = getc (input_file);
  89.       }
  90. }
  91.  
  92. void
  93. module_flat (void)
  94. {
  95.   declare_step ("ascii-bs", "flat", MANY_TO_MANY, NULL, file_ascii_flat);
  96. }
  97.