home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / Sessions / Traut / ZStrings / Source / CrossPlatform / ZStringParser.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  6.7 KB  |  286 lines

  1. /*==================================================================
  2.     File:        ZStringParser.h
  3.     
  4.     Contains:    Class for parsing named ZStrings into platform-
  5.                 specific strings.
  6.  
  7.     Written by:    Eric Traut
  8.     
  9.     Copyright:    2000-2001 Connectix Corporation
  10.     
  11.     This source has been placed into the public domain by
  12.     Connectix Corporation. You have the right to modify, 
  13.     distribute or use this code without any legal limitations
  14.     or finanicial/licensing requirements. Connectix is not 
  15.     liable for any problems that result from the use of this 
  16.     code.
  17.     
  18.     If you have comments, feedback, questions, or would like
  19.     to submit bug fixes or updates to this code, please email
  20.     opensource@connectix.com.
  21. ==================================================================*/
  22.  
  23. #ifndef __ZSTRINGPARSER__
  24. #define __ZSTRINGPARSER__
  25.  
  26.  
  27. #include "ZStringData.h"
  28. #include <cstdio>
  29.  
  30. typedef Z_UInt16 ZStringTagID;
  31.  
  32. // WARNING: If you add to the following enumeration,
  33. // you may need to visit all the platform-specific
  34. // parsing routines (GetTagReplacement methods).
  35. enum
  36. {
  37.     kZTag_Invalid                     = 0,
  38.     kZTag_AElig,
  39.     kZTag_Aacute,
  40.     kZTag_Acirc,
  41.     kZTag_Agrave,
  42.     kZTag_Aring,
  43.     kZTag_Atilde,
  44.     kZTag_Auml,
  45.     kZTag_Ccedil,
  46.     kZTag_Eacute,
  47.     kZTag_Ecirc,
  48.     kZTag_Egrave,
  49.     kZTag_Euml,
  50.     kZTag_Iacute,
  51.     kZTag_Icirc,
  52.     kZTag_Igrave,
  53.     kZTag_Iuml,
  54.     kZTag_Ntilde,
  55.     kZTag_Oacute,
  56.     kZTag_Ocirc,
  57.     kZTag_Ograve,
  58.     kZTag_Oslash,
  59.     kZTag_Otilde,
  60.     kZTag_Ouml,
  61.     kZTag_Uacute,
  62.     kZTag_Ucirc,
  63.     kZTag_Ugrave,
  64.     kZTag_Uuml,
  65.     kZTag_aacute,
  66.     kZTag_acirc,
  67.     kZTag_aelig,
  68.     kZTag_agrave,
  69.     kZTag_amp,
  70.     kZTag_aring,
  71.     kZTag_atilde,
  72.     kZTag_auml,
  73.     kZTag_bdquo,
  74.     kZTag_bull,
  75.     kZTag_ccedil,
  76.     kZTag_cent,
  77.     kZTag_copy,
  78.     kZTag_eacute,
  79.     kZTag_ecirc,
  80.     kZTag_egrave,
  81.     kZTag_euml,
  82.     kZTag_gt,
  83.     kZTag_hellip,
  84.     kZTag_iacute,
  85.     kZTag_icirc,
  86.     kZTag_iexcl,
  87.     kZTag_igrave,
  88.     kZTag_iquest,
  89.     kZTag_iuml,
  90.     kZTag_ldquo,
  91.     kZTag_lsquo,
  92.     kZTag_lt,
  93.     kZTag_mdash,
  94.     kZTag_micro,
  95.     kZTag_nbsp,
  96.     kZTag_ndash,
  97.     kZTag_ntilde,
  98.     kZTag_oacute,
  99.     kZTag_ocirc,
  100.     kZTag_ograve,
  101.     kZTag_oslash,
  102.     kZTag_otilde,
  103.     kZTag_ouml,
  104.     kZTag_para,
  105.     kZTag_pi,
  106.     kZTag_pound,
  107.     kZTag_rdquo,
  108.     kZTag_reg,
  109.     kZTag_replace,
  110.     kZTag_rsquo,
  111.     kZTag_sbquo,
  112.     kZTag_szlig,
  113.     kZTag_trade,
  114.     kZTag_uacute,
  115.     kZTag_ucirc,
  116.     kZTag_ugrave,
  117.     kZTag_uuml,
  118.     kZTag_yen,
  119.     kZTag_yuml,
  120.     kZTag_br
  121. };
  122.  
  123.  
  124. typedef struct ZStringParseInfo ZStringParseInfo;
  125.  
  126. struct ZStringParseInfo
  127. {
  128.     Z_Boolean        fValidNamedString;        // Is the string valid?
  129.     const char *    fNamedStringStart;        // Start of entire named string
  130.     const char *    fNamedStringLimit;        // Points one byte beyond the end
  131.     
  132.     const char *    fNameStr;                // Points to the path-delimited name of the string
  133.     Z_UInt16        fNameStrLen;            // Length of the path-delimited name
  134.  
  135.     Z_Boolean        fHasMaxDataLen;            // Data has a maximum length
  136.     Z_UInt16        fMaxDataLen;            // Maximum length of the data
  137.     
  138.     const char *    fValueStr;                // Points to the "prototype" of the string (including embedded tags)
  139.     Z_UInt16        fValueStrLen;            // Length of "prototype"
  140.     
  141.     Z_Boolean        fIsVolatile;            // Data pointed to are not to guaranteed to persist for the life of the program
  142. };
  143.  
  144.  
  145. /*==================================================================
  146.     ZToolOptions
  147.  
  148.     This class groups the options that can be set for the ZStringTool.
  149.     The default values are contained in the first constructor.
  150. ==================================================================*/
  151.  
  152. class ZToolOptions
  153. {
  154.     public:
  155.         ZToolOptions();
  156.         ZToolOptions(
  157.             Z_Boolean    inOutputNumeric,
  158.             Z_Boolean    inCategorizeOutput,
  159.             Z_Boolean    inAllowSemicolon,
  160.             Z_Boolean    inFlagDuplicates,
  161.             Z_Boolean    inOuputWarnings,
  162.             Z_Boolean    inConvertHighASCIIChar);
  163.  
  164.         Z_Boolean        mOutputNumericTags;        // The tags written are in numeric form (and not alphabetic).
  165.         Z_Boolean        mCategorizeOutput;        // Output is grouped according to category (instead of strictly alphabetical).
  166.         Z_Boolean        mAllowTagSemicolon;        // Semicolons are ignored at the end of alphabetic tags
  167.         Z_Boolean        mFlagDuplicates;        // Duplicate ZStrings are indicated in the output
  168.         Z_Boolean        mHasOTags;                // File contains O tags instead of Z tags (occurs when input file is a dictionary file - so that dict files can be compared)
  169.         Z_Boolean        mOutputWarnings;        // Print warnings to the output file
  170.         Z_Boolean        mPrintErrorsOnly;        // Only errors are printed to the output file (for reporting errors during the creation of the override dictionary)
  171.         Z_Boolean        mConvertHighASCIIChar;    // Automatically convert high ascii characters to their html tags and produce a warning
  172. };
  173.  
  174. typedef Z_UInt16 ZParserWarningType;
  175. enum {
  176.         kZParser_NoWarnings                        = 0x0000,        // No warnings
  177.         kZParser_ChangedString                    = 0x0001,        // A string has been modified because of a high ASCII character
  178.         kZParser_FoundPossibleTag                = 0x0002,        // A possible tag has been found that is missing the &
  179.         kZParser_HasHighASCII                    = 0x0004        // High ASCII characters still exist in the string
  180. };
  181.  
  182. /*==================================================================
  183.     ZStringParser
  184. ==================================================================*/
  185.  
  186. class ZStringParser
  187. {
  188.     public:
  189.         enum
  190.         {
  191.             kTwoByteTableSize                 = 256
  192.         };
  193.         
  194.         // Construction & Destruction
  195.         ZStringParser();
  196.  
  197.         virtual
  198.         ~ZStringParser()
  199.         {
  200.             check(sParser == this);
  201.             sParser = 0L;
  202.         }
  203.  
  204.         static ZStringParser &
  205.         GetZStringParser()
  206.         {
  207.             check(sParser != NULL);
  208.             return *sParser;
  209.         }
  210.  
  211.         virtual void
  212.         OverrideTwoByteTable(
  213.             Z_UInt8 *                    inNewTable);
  214.  
  215.         static const char *
  216.         SkipOverSpaces(
  217.             const char *                inCurrentPtr);
  218.  
  219.         static Z_Boolean
  220.         ParseAdditionalParameters(
  221.             const char *                inCurrentPtr,
  222.             ZStringParseInfo &            outParseInfo);
  223.  
  224.         static Z_Boolean
  225.         ParseNamedString(
  226.             const char *                inNamedString,
  227.             ZStringParseInfo &            outParseInfo,
  228.             Z_Boolean                    inDataIsVolatile);
  229.  
  230.         virtual void
  231.         CreateNewZString(
  232.             const ZStringParseInfo &    inParseInfo,
  233.             ZString &                    outDestString);
  234.     
  235.         static ZStringTagID
  236.         LookUpTagID(
  237.             const char *                inStartOfTag,
  238.             const char *                inStringLimit,
  239.             Z_UInt16 &                    outTagNameLength);
  240.         
  241.         virtual Z_UInt16
  242.         GetTagReplacement(
  243.             ZStringTagID                inTagID,
  244.             char *                        outReplacement) = 0;
  245.     
  246.         static Z_UInt32
  247.         ConvertTagIDToNumeric(
  248.             ZStringTagID                inTag);
  249.  
  250.         static const char *
  251.         ConvertTagIDToString(
  252.             ZStringTagID                inTag);
  253.  
  254.         static Z_Boolean
  255.         ConvertNamedStringToTag(
  256.             const ZStringParseInfo &    inParseInfo,
  257.             const ZToolOptions &        inOptions,
  258.             ZString &                    outDestString,
  259.             Z_UInt16 &                    outState);
  260.  
  261.         static Z_Boolean 
  262.         CheckDataLength(
  263.             const ZStringParseInfo &    inParseInfo);
  264.  
  265.     private:
  266.         static Z_Boolean
  267.         FindPossibleTag(
  268.             const char *                inCurInputPtr,
  269.             const ZStringParseInfo &    inParseInfo);
  270.  
  271.         static Z_SInt32
  272.         CompareTagStrings(
  273.             const char *                inTagFromTable,
  274.             const char *                inParseString,
  275.             const char *                inParseStringLimit);
  276.  
  277.         static ZStringParser *            sParser;
  278.         
  279.         Z_UInt8                            mTwoByteTable[kTwoByteTableSize];
  280. };
  281.  
  282.  
  283. #endif // __ZSTRINGPARSER__
  284.  
  285.  
  286.