home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnurecod.zip / recode.h < prev    next >
C/C++ Source or Header  |  1994-10-31  |  5KB  |  169 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. #if HAVE_CONFIG_H
  21. # include <config.h>
  22. #endif
  23.  
  24. #include <stdio.h>
  25.  
  26. #if STDC_HEADERS
  27. # include <stdlib.h>
  28. #endif
  29.  
  30. #if DIFF_HASH
  31. # ifdef HAVE_LIMITS_H
  32. #  include <limits.h>
  33. # endif
  34. # ifndef CHAR_BIT
  35. #  define CHAR_BIT 8
  36. # endif
  37. #endif
  38.  
  39. /* Some systems do not define EXIT_*, even with STDC_HEADERS.  */
  40. #ifndef EXIT_SUCCESS
  41. # define EXIT_SUCCESS 0
  42. #endif
  43. #ifndef EXIT_FAILURE
  44. # define EXIT_FAILURE 1
  45. #endif
  46.  
  47. #if __STDC__
  48. # define _(Args) Args
  49. #else
  50. # define _(Args) ()
  51. #endif
  52.  
  53. void *xmalloc _((int));
  54. char *xstrdup _((const char *));
  55. int argmatch _((const char *, const char *const *));
  56. void error _((int, int, const char *, ...));
  57.  
  58. /* Description of a charset.  */
  59.  
  60. typedef const char* DOUBLE_TABLE[8];
  61.  
  62. typedef struct charset CHARSET;
  63.  
  64. struct charset
  65.   {
  66.     const char *name;        /* main name */
  67.     int ignore;            /* non zero if should be ignored */
  68.     DOUBLE_TABLE *table;    /* double table for RFC 1345 */
  69.     int size;            /* size of each DOUBLE_TABLE entry */
  70.   };
  71.  
  72. /* Description of a single step of recoding.  */
  73.  
  74. typedef enum quality QUALITY;
  75.  
  76. enum quality
  77.   {
  78.     REVERSIBLE,            /* reversible one to one recoding */
  79.     ONE_TO_ONE,            /* one character to one */
  80.     ONE_TO_MAYBE,        /* one character to none or one */
  81.     ONE_TO_MANY,        /* one character to none, one or many */
  82.     MANY_TO_ONE,        /* one or many characters to one */
  83.     MANY_TO_MANY        /* one or many characters to one or many */
  84.   };
  85.  
  86. typedef struct step STEP;
  87.  
  88. struct step
  89.   {
  90.     CHARSET *before;        /* charset before conversion */
  91.     CHARSET *after;        /* charset after conversion */
  92.     QUALITY quality;        /* recoding quality */
  93.     void (*init_recode) _((STEP *));
  94.     int (*file_recode) _((const STEP *, FILE *, FILE *));
  95.     const unsigned char *one_to_one; /* recoding array of 256 chars */
  96.     const char *const *one_to_many; /* recoding array of 256 strings */
  97.     int conversion_cost;    /* cost for this single step only */
  98.   };
  99.  
  100. typedef struct known_pair KNOWN_PAIR;
  101.  
  102. struct known_pair
  103.   {
  104.     unsigned char left;        /* first character in pair */
  105.     unsigned char right;    /* second character in pair */
  106.   };
  107.  
  108. /* Description of list formats.  */
  109.  
  110. enum list_format
  111.   {
  112.     NO_FORMAT,            /* format not decided yet */
  113.     DECIMAL_FORMAT,        /* concise tabular list using decimal */
  114.     OCTAL_FORMAT,        /* concise tabular list using octal */
  115.     HEXADECIMAL_FORMAT,        /* concise tabular list using hexadecimal */
  116.     FULL_FORMAT            /* full list, one character per line */
  117.   };
  118.  
  119. /* recode.c.  */
  120.  
  121. extern int ascii_graphics;
  122. extern char diaeresis_char;
  123. extern int diacritics_only;
  124. extern int strict_mapping;
  125. extern enum list_format list_format;
  126.  
  127. extern int decoding_charset_flag;
  128. extern const unsigned char *one_to_same;
  129. extern CHARSET *rfc1345;
  130.  
  131. void usage _((int));
  132. const char *quality_to_string _((QUALITY));
  133. QUALITY merge_qualities _((QUALITY, QUALITY));
  134. void declare_step _((const char *, const char *, QUALITY, void (*) (STEP *),
  135.              int (*) (const STEP *, FILE *, FILE *)));
  136. void declare_double_step _((DOUBLE_TABLE *, const char *, int));
  137. unsigned char *invert_table _((const unsigned char *));
  138. void complete_pairs _((STEP *, int, const KNOWN_PAIR *, int, int));
  139. int file_one_to_one _((const STEP *, FILE *, FILE *));
  140. int file_one_to_many _((const STEP *, FILE *, FILE *));
  141.  
  142. /* charname.c.  */
  143.  
  144. char *symbol_to_charname _((const char *));
  145.  
  146. /* charset.c.  */
  147.  
  148. extern CHARSET charset_array[];
  149. extern int number_of_charsets;
  150.  
  151. void decode_known_pairs _((const char *));
  152. void prepare_charset_initialization _((void));
  153. CHARSET *find_charset _((const char *));
  154. void declare_alias _((const char *, const char *));
  155. void make_argmatch_array _((void));
  156. const char *clean_charset_name _((const char *));
  157.  
  158. void list_all_charsets _((CHARSET *));
  159. void init_table_for_rfc1345 _((STEP *));
  160. void list_concise_charset _((CHARSET *));
  161. void list_full_charset _((CHARSET *));
  162.  
  163. /* Debugging the memory allocator.  */
  164.  
  165. #if WITH_DMALLOC
  166. # define DMALLOC_FUNC_CHECK
  167. # include <dmalloc.h>
  168. #endif
  169.