home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / richmail / richlex.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-21  |  5.1 KB  |  161 lines

  1. /*-------------------------------------------------------------------------
  2.  
  3.   richlex.h - Lexical analysis routines for parsing richtext messages.
  4.  
  5.   Copyright (c) 1992 Rhys Weatherley
  6.  
  7.   Permission to use, copy, modify, and distribute this material
  8.   for any purpose and without fee is hereby granted, provided
  9.   that the above copyright notice and this permission notice
  10.   appear in all copies, and that the name of Rhys Weatherley not be
  11.   used in advertising or publicity pertaining to this
  12.   material without specific, prior written permission.
  13.   RHYS WEATHERLEY MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR
  14.   SUITABILITY OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED
  15.   "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  16.  
  17.   Revision History:
  18.   ================
  19.  
  20.    Version  DD/MM/YY  By  Description
  21.    -------  --------  --  --------------------------------------
  22.      1.0    31/01/92  RW  Original Version of richlex.h
  23.      1.1    19/06/92  RW  Add support for multi-byte ISO-2022 codes.
  24.  
  25.   You may contact the author by:
  26.   =============================
  27.  
  28.    e-mail: rhys@cs.uq.oz.au
  29.      mail: Rhys Weatherley
  30.        5 Horizon Drive
  31.        Jamboree Heights
  32.        Queensland 4074
  33.        Australia
  34.  
  35. -------------------------------------------------------------------------*/
  36.  
  37. #ifndef    __RICHTEXT_H__
  38. #define    __RICHTEXT_H__
  39.  
  40. #ifdef    __cplusplus
  41. extern "C" {
  42. #endif
  43.  
  44. /*
  45.  * Define the data type to be used by characters in the richtext
  46.  * system.  Note: this is a long because some machines, MS-DOS
  47.  * machines for example, only have 16-bit integers and hence won't
  48.  * be able to cope with large multi-byte character codes.  If
  49.  * something is strange with your character processing, it is
  50.  * probably because you aren't using the right types.
  51.  */
  52. typedef    long    RCHAR;
  53.  
  54. /*
  55.  * Set the following variable to zero to disable the
  56.  * correction of richtext commands.  The default
  57.  * value is non-zero.
  58.  */
  59. extern    int CorrectionEnabled;
  60.  
  61. /*
  62.  * Set the following value to non-zero to enable the
  63.  * multi-byte '<' hack which ignores richtext commands
  64.  * in multi-byte modes.  The default value is zero.
  65.  */
  66. extern    int RichtextLessThanFlag;
  67.  
  68. /*
  69.  * Define the function to call to get characters from
  70.  * the message.  The calling convention of this
  71.  * function is: "int func (void *param)".  The default
  72.  * value is "fgetc".  The function must return EOF
  73.  * at the end of the messsage;
  74.  */
  75. extern    int (*RichtextGetc) ();
  76.  
  77. /*
  78.  * Define the function to call to output characters from
  79.  * richtextcorrect.  The calling convention of this
  80.  * function is: "int func (int c,void *param)".  The default
  81.  * value is "fputc".
  82.  */
  83. extern    int (*RichtextPutc) ();
  84.  
  85. /*
  86.  * Define the maximum size of richtext command tokens.
  87.  */
  88. #define    MAX_TOKEN_SIZE        50
  89.  
  90. /*
  91.  * Define the special token values that are returned by
  92.  * the "richtextlex" function.  These values were chosen
  93.  * to keep away from legal ASCII.
  94.  *
  95.  * Version 1.1: modified to negative values to keep away
  96.  * from legal ISO-2022 and other multi-byte characters.
  97.  */
  98. #define    RICHTEXT_COMMAND    ((RCHAR)(-2))
  99. #define    RICHTEXT_NEG_COMMAND    ((RCHAR)(-3))
  100.  
  101. /*
  102.  * Reset the richtext parsing mechanism.
  103.  */
  104. extern    richtextreset();
  105.  
  106. /*
  107.  * Get the next token from the input stream.  RICHTEXT_COMMAND
  108.  * or RICHTEXT_NEG_COMMAND are returned if it is a richtext command.
  109.  * e.g. "<cmd>" or "</cmd>".  The "token" buffer will receive the
  110.  * name of the command (without <,> or /) if it is a command.  This
  111.  * function will also truncate commands longer than MAX_TOKEN_SIZE - 1
  112.  * characters and abort command parsing if white space is encountered,
  113.  * so, for example, errors like "<bold hi kids</bold>" don't cause
  114.  * problems: it will be corrected to "<bold>hi kids</bold>".
  115.  * The "file" parameter is passed to the function pointed to by
  116.  * "RichtextGetc" on each call.
  117.  */
  118. extern    RCHAR    richtextlex( /* void *file,char *token */ );
  119.  
  120. /*
  121.  * Read the input stream, correct the richtext, and write the
  122.  * results to the output stream.  "outparam" is passed to the
  123.  * "RichtextPutc" function as the second argument, and "inparam"
  124.  * is passed to "richtextlex" during parsing.
  125.  */
  126. extern    richtextcorrect( /* void *inparam,void *outparam */ );
  127.  
  128. #define    RICH_ENC_US_ASCII    0    /* US-ASCII encoding: one-byte */
  129. #define    RICH_ENC_JP_ASCII    1    /* JP-ASCII encoding: one-byte */
  130. #define    RICH_ENC_KR_ASCII    2    /* KR-ASCII encoding: one-byte */
  131. #define    RICH_ENC_JIS_1978    100    /* JIS-X-0208-1978: two-byte */
  132. #define    RICH_ENC_JIS_1983    101    /* JIS-X-0208-1983: two-byte */
  133. #define    RICH_ENC_KSC_5601    200    /* KSC-5601 (Korean): two-byte */
  134.  
  135. /*
  136.  * The following variable contains the current character
  137.  * encoding in use.  This should only be read.  Setting it
  138.  * is done via "richtextencoding".
  139.  */
  140. extern    int    RichtextCharEncoding;
  141.  
  142. /*
  143.  * Change the encoding used for characters not present in
  144.  * richtext command sequences.
  145.  */
  146. extern    richtextencoding( /* int encoding */ );
  147.  
  148. /*
  149.  * Define a number of macros for decoding multi-byte character
  150.  * codes.  The names of the macros have the form "RICHCHn_xxx"
  151.  * where "n" is the number of bytes in the character.
  152.  */
  153. #define    RICHCH2_FIRST(c)    (((c) >> 8) & 0xFF)
  154. #define    RICHCH2_SECOND(c)    ((c) & 0xFF)
  155.  
  156. #ifdef    __cplusplus
  157. };
  158. #endif
  159.  
  160. #endif    /* __RICHTEXT_H__ */
  161.