Changeset 147


Ignore:
Timestamp:
Mar 16, 2002, 8:53:47 AM (23 years ago)
Author:
umoeller
Message:

Misc updates for Unicode.

Location:
trunk
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/CodingConventions.txt

    r118 r147  
    139139
    140140        xdoc can create a full change log if these things are set
    141         properly. Try "createdoc.cmd" in the WarpIN and XWorkplace
    142         main source directories, respectively.
     141        properly. Try "createdoc.cmd" or "createchangelog.cmd" in
     142        the WarpIN and XWorkplace main source directories,
     143        respectively.
    143144
    144145        Also, this way I can do a simple search over all files
  • trunk/include/encodings/alltables.h

    r37 r147  
    2727// #include "encodings\cp949.h"
    2828// #include "encodings\cp950.h"
     29#include "encodings\cp1004.h"       // added V0.9.18 (2002-03-08) [umoeller]
    2930#include "encodings\cp1250.h"
    3031#include "encodings\cp1251.h"
  • trunk/include/encodings/base.h

    r97 r147  
    1616    /*
    1717     *@@ XWPENCODINGMAP:
    18      *      entry in an 8-bit to Unicode conversion table.
     18     *      entry in a codepage-to-Unicode conversion table.
    1919     */
    2020
    2121    typedef struct _XWPENCODINGMAP
    2222    {
    23         unsigned short      usFrom;
     23        unsigned short      usCP;
    2424        unsigned short      usUni;
    2525    } XWPENCODINGMAP, *PXWPENCODINGMAP;
    2626
    2727    /*
    28      *@@ XWPENCODINGID:
     28     *@@ ENCID:
    2929     *      enum identifying each encoding set which is
    3030     *      generally supported. Each ID corresponds to
     
    3232     */
    3333
    34     typedef enum _XWPENCODINGID
     34    typedef enum _ENCID
    3535    {
     36        UNSUPPORTED,
    3637        enc_cp437,
    3738        enc_cp737,
     
    5455        enc_cp949,
    5556        enc_cp950,
     57        enc_cp1004,     // added V0.9.18 (2002-03-08) [umoeller]
    5658        enc_cp1250,
    5759        enc_cp1251,
     
    7678        enc_iso8859_14,
    7779        enc_iso8859_15
    78     } XWPENCODINGID;
     80    } ENCID;
     81
     82    /*
     83     *@@ CONVERSION:
     84     *
     85     *@@added V0.9.18 (2002-03-08) [umoeller]
     86     */
     87
     88    typedef struct _CONVERSION
     89    {
     90        ENCID   EncodingID;
     91
     92        // to get Unicode for character 123 in the specific
     93        // encoding, do pTable->ausEntriesUniFromCP[123].
     94        // If you get 0xFFFF, the encoding is undefined.
     95        unsigned short  usHighestCP;
     96        unsigned short  *ausEntriesUniFromCP;  // usHighestCP + 1 entries
     97
     98        // to get codepage for unicode character 123,
     99        // do pTable->ausEntriesCPFromUni[123].
     100        // If you get 0xFFFF, the encoding is undefined.
     101        unsigned short  usHighestUni;
     102        unsigned short  *ausEntriesCPFromUni;   // usHighestUni + 1 entries
     103
     104    } CONVERSION, *PCONVERSION;
     105
     106    typedef enum _ENCBYTECOUNT
     107    {
     108        SINGLE,
     109        DOUBLE,
     110        EBCDIC,
     111        MULTI_UNICODE,
     112        UNKNOWN
     113    } ENCBYTECOUNT;
     114
     115    ENCID encFindIdForCodepage(unsigned short usCodepage,
     116                                       const char **ppcszDescription,
     117                                       ENCBYTECOUNT *pByteCount);
     118
     119    PCONVERSION encCreateCodec(ENCID id);
     120
     121    void encFreeCodec(PCONVERSION *ppTable);
     122
     123    unsigned long encChar2Uni(PCONVERSION pTable,
     124                              unsigned short c);
     125
     126    unsigned short encUni2Char(PCONVERSION pTable,
     127                               unsigned long ulUni);
    79128
    80129    unsigned long encDecodeUTF8(const char **ppch);
  • trunk/include/encodings/cp1250.h

    r37 r147  
    33 *@@sourcefile cp1250.h:
    44 *      encoding translation for CP1250 to Unicode.
     5 *
     6 *      Note: From my checking, 1250 is exactly the
     7 *      same as 1004, except for character point 0xAF.
    58 *
    69 *@@added V0.9.9 (2001-02-10) [umoeller]
  • trunk/include/encodings/cp1252.h

    r37 r147  
    33 *@@sourcefile cp1252.h:
    44 *      encoding translation for CP1252 to Unicode.
     5 *
     6 *      Note: From my checking, 1252 is exactly the
     7 *      same as 1004, except for codepoint 0xAF.
    58 *
    69 *@@added V0.9.9 (2001-02-10) [umoeller]
  • trunk/include/helpers/cnrh.h

    r113 r147  
    8686    {
    8787        ULONG   ulFieldOffset;
    88         PSZ     pszColumnTitle;
     88        PCSZ    pszColumnTitle;
    8989        ULONG   ulDataType;
    9090        ULONG   ulOrientation;
     
    450450     *      This can only be used after BEGIN_CNRINFO().
    451451     *
     452     *      Container sort funcs must have this prototype:
     453     +
     454     +      SHORT EXPENTRY fnCompare(PRECORDCORE p1, PRECORDCORE p2, PVOID pStorage)
     455     *
    452456     *@@added V0.9.0
    453457     */
  • trunk/include/helpers/configsys.h

    r117 r147  
    6666                    // -- CFGRPL_REMOVEPART mode (5)
    6767
    68         PSZ         pszUniqueSearchString2;
     68        PCSZ        pszUniqueSearchString2;
    6969                    // for UNIQUE(statement2):
    7070                    // the "statement2" to search for
     
    7676                    // 2: add before pszSearchString
    7777                    // 3: add after pszSearchString
    78         PSZ         pszVerticalSearchString;
     78        PCSZ        pszVerticalSearchString;
    7979                    // for iVertical == 2 or 3
    8080
    81         PSZ         pszNewLine;
     81        PCSZ        pszNewLine;
    8282                    // this is a copy of stuff before the "|" char
    8383                    // in pszConfigSys given to the constructor
  • trunk/include/helpers/linklist.h

    r141 r147  
    9595    #define LINKLISTMAGIC 0xf124        // could be anything
    9696
    97     typedef signed short _System FNSORTLIST(void*, void*, void*);
     97    typedef signed short XWPENTRY FNSORTLIST(void*, void*, void*);
    9898                            // changed V0.9.0 (99-10-22) [umoeller]
    9999    typedef FNSORTLIST *PFNSORTLIST;
  • trunk/include/helpers/nls.h

    r115 r147  
    9999    APIRET XWPENTRY nlsUpper(PSZ psz, ULONG ulLength);
    100100
     101    /*
     102     *@@ STRINGENTITY:
     103     *
     104     *@@added V0.9.16 (2001-09-29) [umoeller]
     105     */
     106
     107    typedef struct _STRINGENTITY
     108    {
     109        PCSZ    pcszEntity;
     110        PCSZ    *ppcszString;
     111    } STRINGENTITY, *PSTRINGENTITY;
     112
     113    typedef const struct _STRINGENTITY *PCSTRINGENTITY;
     114
     115    VOID nlsInitStrings(HAB hab,
     116                        HMODULE hmod,
     117                        PCSTRINGENTITY paEntities,
     118                        ULONG cEntities);
     119
     120    PCSZ nlsGetString(ULONG ulStringID);
     121
    101122#endif
    102123
  • trunk/include/helpers/stringh.h

    r143 r147  
    145145    ULONG XWPENTRY strhGetBlock(const char *pszSearchIn,
    146146                                PULONG pulSearchOffset,
    147                                 PSZ pszTag,
     147                                const char *pszTag,
    148148                                PSZ *ppszBlock,
    149149                                PSZ *ppszAttribs,
  • trunk/include/helpers/tmsgfile.h

    r113 r147  
    5454                         PCSZ pcszMessageName,
    5555                         PXSTRING pstr,
    56                          PSZ *pTable,
     56                         PCSZ *pTable,
    5757                         ULONG cTableEntries);
    5858
  • trunk/include/helpers/winh.h

    r135 r147  
    652652
    653653    BOOL XWPENTRY winhAdjustControls(HWND hwndDlg,
    654                                      MPARAM *pmpFlags,
     654                                     const MPARAM *pmpFlags,
    655655                                     ULONG ulCount,
    656656                                     PSWP pswpNew,
  • trunk/src/helpers/cctl_checkcnr.c

    r146 r147  
    566566
    567567                    if (lstCountItems(G_pllCnrOwners) == 0)
    568                     {
    569568                        lstFree(&G_pllCnrOwners);
    570                     }
     569
    571570                    DosReleaseMutexSem(G_hmtxCnrOwnersList);
    572571                }
     
    627626            case WM_CONTROL:
    628627            {
    629                 USHORT  usItemID = SHORT1FROMMP(mp1),
    630                         usNotifyCode = SHORT2FROMMP(mp1);
    631 
    632                 if (usItemID == pcbco->usCnrID)
     628                if (SHORT1FROMMP(mp1) == pcbco->usCnrID)
    633629                {
    634                     switch (usNotifyCode)
     630                    switch (SHORT2FROMMP(mp1))
    635631                    {
    636632                        case CN_ENTER:
     
    645641                        }
    646642                        break;
     643
     644                        default:
     645                            mrc = pfnwpOrig(hwndOwner, msg, mp1, mp2);
    647646                    }
    648647                }
    649 
    650                 mrc = pfnwpOrig(hwndOwner, msg, mp1, mp2);
     648                else
     649                    mrc = pfnwpOrig(hwndOwner, msg, mp1, mp2);
    651650            }
    652651            break;
  • trunk/src/helpers/cnrh.c

    r129 r147  
    334334            cnrhSetFieldInfo(&pFieldInfo2,
    335335                             pxfi->ulFieldOffset,
    336                              pxfi->pszColumnTitle,
     336                             (PSZ)pxfi->pszColumnTitle,
    337337                             pxfi->ulDataType,
    338338                             pxfi->ulOrientation,
  • trunk/src/helpers/encodings.c

    r97 r147  
    33 *@@sourcefile encodings.c:
    44 *      character encoding translations.
     5 *
     6 *      See encCreateCodec for an introduction.
    57 *
    68 *@@header "encodings\base.h"
     
    3133#include "setup.h"                      // code generation and debugging options
    3234
    33 #include "encodings\base.h"             // includes all other encodings
     35#include "helpers\standards.h"
     36
     37#include "encodings\base.h"
     38#include "encodings\alltables.h"
     39// #include "encodings\collate.h"
    3440
    3541#pragma hdrstop
    3642
    37 typedef struct _ENCODINGTABLE
    38 {
    39     XWPENCODINGID   EncodingID;
    40 
    41     unsigned short  cEntries;
    42     unsigned short  ausEntries[1];        // variable size
    43 } ENCODINGTABLE, *PENCODINGTABLE;
    44 
    45 
    46 /*
    47  *@@ encRegisterEncoding:
    48  *      registers a new proprietary encoding with the engine.
    49  *
    50  *      Before you can translate encodings with this engine,
    51  *      you have to register them. This makes sure that the
    52  *      big encoding tables will only be linked to the executable
    53  *      code if they are explicitly referenced. As a result, you
    54  *      have to #include "encodings\base.h" and pass a pointer to
    55  *      one of the global tables in the header files to this
    56  *      function.
    57  *
    58  *      This returns an encoding handle that can then be used
    59  *      with the other encoding functions.
    60  *
    61  *      Example:
    62  *
    63  +          #include "encodings\base.h"
    64  +          #include "encodings\alltables.h"     // or a specific table only
    65  +
    66  +          int rc = encRegisterEncoding(&G_iso8859_1,
    67  +                                       sizeof(G_iso8859_1) / sizeof(G_iso8859_1[0]),
    68  +                                       enc_iso8859_1);    // ID to register with
    69  */
    70 
    71 long encRegisterEncoding(PXWPENCODINGMAP pEncodingMap,
    72                          unsigned long cArrayEntries,    // count of array items
    73                          XWPENCODINGID EncodingID)       // enum from encodings\base.h
    74 {
    75     long lrc = 0;
    76 
    77     unsigned short usHighest = 0;
     43#define ENCODINGENTRY(id)   enc_ ## id, G_ ## id, ARRAYITEMCOUNT(G_ ## id)
     44
     45/*
     46 *@@ G_aEncodings:
     47 *      list of all encodings supported by this engine
     48 *      (i.e. we have a corresponding codepage in
     49 *      include\encodings\*.h) together with some
     50 *      additional information for each encoding,
     51 *      such as the corresponding OS/2 codepage
     52 *      number and a descriptive string.
     53 *
     54 *@@added V [umoeller]
     55 */
     56
     57struct
     58{
     59    ENCID               id;                 // engine ID (enum)
     60    PXWPENCODINGMAP     pMap;               // ptr to map from include\encodings\*.h
     61    unsigned long       cEntries;           // entries in map (array item count)
     62    unsigned short      usCodepageOS2;      // corresponding OS/2 codepage or 0 if none
     63    ENCBYTECOUNT        bc;
     64    const char          *pcszDescription;   // description
     65} G_aEncodings[] =
     66    {
     67        ENCODINGENTRY(cp437), 437, SINGLE, "DOS Latin US",
     68        ENCODINGENTRY(cp737), 737, SINGLE, "DOS Greek",
     69        ENCODINGENTRY(cp775), 775, SINGLE, "DOS BaltRim",
     70        ENCODINGENTRY(cp850), 850, SINGLE, "DOS Latin 1",
     71        ENCODINGENTRY(cp852), 852, SINGLE, "DOS Latin 2",               // default in Hungary,
     72                                                                // Romania, Poland
     73        ENCODINGENTRY(cp855), 855, SINGLE, "DOS Cyrillic",
     74        ENCODINGENTRY(cp857), 857, SINGLE, "DOS Latin 5 (Turkish)",
     75        ENCODINGENTRY(cp860), 860, SINGLE, "DOS Portuguese",
     76        ENCODINGENTRY(cp861), 861, SINGLE, "DOS Icelandic",
     77        ENCODINGENTRY(cp862), 862, SINGLE, "DOS Hebrew",
     78        ENCODINGENTRY(cp863), 863, SINGLE, "DOS Canadian French",
     79        ENCODINGENTRY(cp864), 864, SINGLE, "DOS Arabic",                // default in Egypt
     80        ENCODINGENTRY(cp865), 865, SINGLE, "DOS Nordic",
     81        ENCODINGENTRY(cp866), 866, SINGLE, "DOS Cyrillic Russian",      // default in Russia
     82        ENCODINGENTRY(cp869), 869, SINGLE, "DOS Greek2",
     83        ENCODINGENTRY(cp874), 874, SINGLE, "DOS Thai (TIS-620)",        // default in Thailand
     84        // ENCODINGENTRY(cp932), 932 or 943?, DOUBLE, "Japanese Windows",
     85        // ENCODINGENTRY(cp936), 936 or 946?, DOUBLE, "Chinese",
     86        // ENCODINGENTRY(cp949), 951 or 949?, DOUBLE, "Korean",
     87        // ENCODINGENTRY(cp950), 947 or 950?, DOUBLE, "Taiwan Big-5",           // default in China?
     88        ENCODINGENTRY(cp1004), 1004, SINGLE, "Windows Extended",
     89        ENCODINGENTRY(cp1250), 1250, SINGLE, "Windows Latin 2",
     90        ENCODINGENTRY(cp1251), 1251, SINGLE, "Windows Cyrillic",
     91        ENCODINGENTRY(cp1252), 1252, SINGLE, "Windows Latin 1",
     92        ENCODINGENTRY(cp1253), 1253, SINGLE, "Windows Greek",
     93        ENCODINGENTRY(cp1254), 1254, SINGLE, "Windows Turkish",
     94        ENCODINGENTRY(cp1255), 1255, SINGLE, "Windows Hebrew",
     95        ENCODINGENTRY(cp1256), 1256, SINGLE, "Windows Arabic",
     96        ENCODINGENTRY(cp1257), 1257, SINGLE, "Windows Latin-4",
     97        ENCODINGENTRY(cp1258), 1258, UNKNOWN, "unknown",
     98        ENCODINGENTRY(iso8859_1), 819, SINGLE, "ISO/IEC 8859-1:1998 (Latin-1)",
     99        ENCODINGENTRY(iso8859_2), 912, SINGLE, "ISO 8859-2:1999 (Latin-2)",
     100        ENCODINGENTRY(iso8859_3), 913, SINGLE, "ISO/IEC 8859-3:1999 (Latin-3)",
     101        ENCODINGENTRY(iso8859_4), 914, SINGLE, "ISO/IEC 8859-4:1998 (Latin-4)",
     102        ENCODINGENTRY(iso8859_5), 915, SINGLE, "ISO 8859-5:1999 (Cyrillic)",
     103        ENCODINGENTRY(iso8859_6), 1089, SINGLE, "ISO 8859-6:1999 (Arabic)",
     104        ENCODINGENTRY(iso8859_7), 813, SINGLE, "ISO 8859-7:1987 (Greek)",   // default in Greece
     105        ENCODINGENTRY(iso8859_8), 916, SINGLE, "ISO/IEC 8859-8:1999 (Hebrew)",
     106        ENCODINGENTRY(iso8859_9), 920, SINGLE, "ISO/IEC 8859-9:1999 (Latin-5)",
     107        ENCODINGENTRY(iso8859_10), 0, SINGLE, "ISO/IEC 8859-10:1998",
     108        ENCODINGENTRY(iso8859_13), 0, SINGLE, "ISO/IEC 8859-13:1998",
     109        ENCODINGENTRY(iso8859_14), 0, SINGLE, "ISO/IEC 8859-14:1998",
     110        ENCODINGENTRY(iso8859_15), 923, SINGLE, "ISO/IEC 8859-15:1999",
     111
     112        UNSUPPORTED, NULL, 0, 1200, MULTI_UNICODE, "Unicode UCS-2",
     113        UNSUPPORTED, NULL, 0, 1208, MULTI_UNICODE, "Unicode UTF-8"
     114    };
     115
     116/*
     117 *@@ FindEntry:
     118 *
     119 *@@added V0.9.18 (2002-03-08) [umoeller]
     120 */
     121
     122static int FindEntry(ENCID id,
     123                     PXWPENCODINGMAP *ppMap,
     124                     unsigned long *pcEntries)
     125{
    78126    unsigned long ul;
    79 
    80     // step 1:
    81     // run through the table and calculate the highest
    82     // character entry used
    83127    for (ul = 0;
    84          ul < cArrayEntries;
     128         ul < ARRAYITEMCOUNT(G_aEncodings);
    85129         ul++)
    86130    {
    87         unsigned short usFrom = pEncodingMap[ul].usFrom;
    88         if (usFrom > usHighest)
    89             usHighest = usFrom;
     131        if (G_aEncodings[ul].id == id)
     132        {
     133            *ppMap = G_aEncodings[ul].pMap;
     134            *pcEntries = G_aEncodings[ul].cEntries;
     135            return (1);
     136        }
    90137    }
    91138
    92     // step 2: allocate encoding table
    93     if (usHighest)
     139    return (0);
     140}
     141
     142/*
     143 *@@ encFindIdForCodepage:
     144 *      returns the ENCID for the given OS/2
     145 *      codepage, or UNSUPPORTED if there's none.
     146 *
     147 *@@added V0.9.18 (2002-03-08) [umoeller]
     148 */
     149
     150ENCID encFindIdForCodepage(unsigned short usCodepage,
     151                           const char **ppcszDescription,   // out: codepage description; ptr can be NULL
     152                           ENCBYTECOUNT *pByteCount)
     153{
     154    unsigned long ul;
     155    for (ul = 0;
     156         ul < ARRAYITEMCOUNT(G_aEncodings);
     157         ul++)
    94158    {
    95         // allocate memory as needed
    96         unsigned long cb =   sizeof(ENCODINGTABLE)
    97                            + (   (usHighest - 1)
    98                                * sizeof(unsigned short)
    99                              );
    100 
    101         PENCODINGTABLE pTableNew = (PENCODINGTABLE)malloc(cb);
    102         if (pTableNew)
    103         {
    104             memset(pTableNew, -1, cb);
    105             pTableNew->cEntries = usHighest;        // array size
    106 
    107             // step 3: fill encoding table
    108             // this only has the Unicode target USHORTs;
    109             // the source is simply the offset. So to
    110             // get Unicode for character 123 in the specific encoding,
    111             // do pTableNew->ausEntries[123].
    112             // If you get 0xFFFF, the encoding is undefined.
    113 
    114             for (ul = 0;
    115                  ul < cArrayEntries;
    116                  ul++)
     159        if (G_aEncodings[ul].usCodepageOS2 == usCodepage)
     160
     161        {
     162            if (ppcszDescription)
     163                *ppcszDescription = G_aEncodings[ul].pcszDescription;
     164            if (pByteCount)
     165                *pByteCount = G_aEncodings[ul].bc;
     166            return G_aEncodings[ul].id;
     167        }
     168    }
     169
     170    return (UNSUPPORTED);
     171}
     172
     173/*
     174 *@@ encCreateCodec:
     175 *      creates a codec that can be used for conversion between
     176 *      Unicode and codepaged characters (and vice versa).
     177 *
     178 *      A codec essentially consists of two tables which can
     179 *      be used for quick index-based lookups in both directions.
     180 *      This function goes thru the tables provided in
     181 *      include\encodings\*.h and builds the codec tables
     182 *      from them.
     183 *
     184 *      This function takes an encoding ID as input. Each
     185 *      codepage table in include\encodings\*.h has one
     186 *      of those IDs assigned. Use encFindIdForCodepage
     187 *      to find the ID for a given OS/2 codepage.
     188 *
     189 *      Use codecs carefully and only when they are really
     190 *      needed for a specific conversion. Building a codec
     191 *      is expensive, so you should create a codec once
     192 *      and reuse it for future conversions. In addition,
     193 *      create codecs only for the codepages that are
     194 *      actually used. Each codec will take up
     195 *      n * sizeof(USHORT) bytes, where n is the highest
     196 *      Unicode character used in the codepage.
     197 *
     198 *      Remarks:
     199 *
     200 *      --  All codepages share the first 128 characters
     201 *          (0-0x7F) with ASCII.
     202 *
     203 *      --  Since the first 128 characters (0-0x7F) in
     204 *          Unicode are equivalent to ASCII also, codecs
     205 *          are not needed if you process ASCII strings
     206 *          only.
     207 *
     208 *      --  Since the next 128 characters (0x80-0xFF) in
     209 *          Unicode are equivalent to ISO/IEC 8859-1
     210 *          (Latin-1), codecs aren't needed for those
     211 *          strings either.
     212 *
     213 *          Note that codepoints 0x80-0x9F are undefined
     214 *          in Latin-1 but used as control sequences in
     215 *          Unicode.
     216 *
     217 *      --  As far as I know, codepage 1252, which is
     218 *          used per default under Windows, is equivalent
     219 *          to Latin 1 except that it also defines
     220 *          codepoints 0x80-0x9F to certain DTP characters.
     221 *
     222 *      --  From my testing, codepage 1004 (which is
     223 *          described as "Windows-compatible" in most OS/2
     224 *          docs) is the same as codepage 1252, except for
     225 *          character 0xAF.
     226 *
     227 *      Unfortunately, OS/2 uses codepage 850 on most
     228 *      systems (and Windows uses OS/2 codepage 1252),
     229 *      so for conversion between those, codecs are needed.
     230 */
     231
     232PCONVERSION encCreateCodec(ENCID id)
     233{
     234    PXWPENCODINGMAP pEncodingMap;
     235    unsigned long cArrayEntries;
     236
     237    if (FindEntry(id,
     238                  &pEncodingMap,
     239                  &cArrayEntries))
     240    {
     241        unsigned short usHighestCP = 0,
     242                       usHighestUni = 0;
     243        unsigned long ul;
     244
     245        // step 1:
     246        // run through the table and calculate the highest
     247        // character entry used
     248        for (ul = 0;
     249             ul < cArrayEntries;
     250             ul++)
     251        {
     252            if (pEncodingMap[ul].usCP > usHighestCP)
     253                usHighestCP = pEncodingMap[ul].usCP;
     254            if (pEncodingMap[ul].usUni > usHighestUni)
     255                usHighestUni = pEncodingMap[ul].usUni;
     256        }
     257
     258        // step 2: allocate encoding table
     259        if (usHighestCP && usHighestUni)
     260        {
     261            PCONVERSION pTableNew;
     262            if (pTableNew = NEW(CONVERSION))
    117263            {
    118                 PXWPENCODINGMAP pEntry = &pEncodingMap[ul];
    119                 pTableNew->ausEntries[pEntry->usFrom] = pEntry->usUni;
     264                unsigned long cbEntriesUniFromCP
     265                    = (usHighestCP + 1) * sizeof(unsigned short);
     266                unsigned long cbEntriesCPFromUni
     267                    = (usHighestUni + 1) * sizeof(unsigned short);
     268
     269                ZERO(pTableNew);
     270
     271                pTableNew->usHighestCP = usHighestCP;
     272                pTableNew->usHighestUni = usHighestUni;
     273
     274                if (    (pTableNew->ausEntriesUniFromCP
     275                            = (unsigned short*)malloc(cbEntriesUniFromCP))
     276                     && (pTableNew->ausEntriesCPFromUni
     277                            = (unsigned short*)malloc(cbEntriesCPFromUni))
     278                   )
     279                {
     280                    // step 3: fill encoding tables
     281
     282                    memset(pTableNew->ausEntriesUniFromCP,
     283                           0xFF,
     284                           cbEntriesUniFromCP);
     285                    memset(pTableNew->ausEntriesCPFromUni,
     286                           0xFF,
     287                           cbEntriesCPFromUni);
     288
     289                    for (ul = 0;
     290                         ul < cArrayEntries;
     291                         ul++)
     292                    {
     293                        PXWPENCODINGMAP pEntry = &pEncodingMap[ul];
     294
     295                        pTableNew->ausEntriesUniFromCP[pEntry->usCP] = pEntry->usUni;
     296
     297                        pTableNew->ausEntriesCPFromUni[pEntry->usUni] = pEntry->usCP;
     298                    }
     299
     300                    return (pTableNew);
     301                }
     302
     303                free(pTableNew);
    120304            }
    121 
    122             lrc = (long)pTableNew;
    123305        }
    124306    }
    125307
    126     return (lrc);
     308    return (NULL);
     309}
     310
     311/*
     312 *@@ encFreeCodec:
     313 *      frees a codec created with encFreeConversion
     314 *      and sets the given pointer to NULL.
     315 *
     316 *@@added V0.9.18 (2002-03-08) [umoeller]
     317 */
     318
     319void encFreeCodec(PCONVERSION *ppTable)         // in: ptr to codec ptr returned by encCreateCodec
     320{
     321    PCONVERSION pTable;
     322    if (pTable = *ppTable)
     323    {
     324        if (pTable->ausEntriesUniFromCP)
     325            free(pTable->ausEntriesUniFromCP);
     326        if (pTable->ausEntriesCPFromUni)
     327            free(pTable->ausEntriesCPFromUni);
     328        free(pTable);
     329        *ppTable = NULL;
     330    }
     331}
     332
     333/*
     334 *@@ encChar2Uni:
     335 *      converts a codepage-specific character
     336 *      to Unicode, using the given conversion
     337 *      table from encCreateCodec().
     338 *
     339 *      Returns 0xFFFF on errors, which is unlikely
     340 *      with Unicode though.
     341 *
     342 *@@added V0.9.18 (2002-03-08) [umoeller]
     343 */
     344
     345unsigned long encChar2Uni(PCONVERSION pTable,
     346                          unsigned short c)
     347{
     348    if (    (pTable)
     349         && (c <= pTable->usHighestCP)
     350       )
     351        return (pTable->ausEntriesUniFromCP[c]);
     352
     353    return (0xFFFF);
     354}
     355
     356/*
     357 *@@ encUni2Char:
     358 *      converts a Unicode character to the
     359 *      codepage specified by the given
     360 *      conversion table from encCreateCodec().
     361 *
     362 *      Returns 0xFFFF if the Unicode character
     363 *      has no codepage equivalent.
     364 *
     365 *@@added V0.9.18 (2002-03-08) [umoeller]
     366 */
     367
     368unsigned short encUni2Char(PCONVERSION pTable,
     369                           unsigned long ulUni)
     370{
     371    if (    (pTable)
     372         && (ulUni <= pTable->usHighestUni)
     373       )
     374        return (pTable->ausEntriesCPFromUni[ulUni]);
     375
     376    return (0xFFFF);
    127377}
    128378
     
    246496}
    247497
     498#if 0
     499
     500/*
     501 *@@ encCodepageToUTF8:
     502 *
     503 *@@added V0.9.18 (2002-03-08) [umoeller]
     504 */
     505
     506void encCodepageToUTF8(const char **ppch)
     507{
     508
     509}
     510
     511putwchar(c)
     512{
     513  if (c < 0x80) {
     514    putchar (c);
     515  }
     516  else if (c < 0x800) {
     517    putchar (0xC0 | c>>6);
     518    putchar (0x80 | c & 0x3F);
     519  }
     520  else if (c < 0x10000) {
     521    putchar (0xE0 | c>>12);
     522    putchar (0x80 | c>>6 & 0x3F);
     523    putchar (0x80 | c & 0x3F);
     524  }
     525  else if (c < 0x200000) {
     526    putchar (0xF0 | c>>18);
     527    putchar (0x80 | c>>12 & 0x3F);
     528    putchar (0x80 | c>>6 & 0x3F);
     529    putchar (0x80 | c & 0x3F);
     530  }
     531}
     532
     533#endif
     534
  • trunk/src/helpers/linklist.c

    r141 r147  
    961961 *      sort function pfnSort, which works similar to those of the
    962962 *      container sorts, i.e. it must be declared as a
    963  +          SHORT fnSort(void* pItem1, void* pItem2, void* pStorage)
     963 +          signed short XWPENTRY fnSort(void* pItem1, void* pItem2, void* pStorage)
    964964 *
    965965 *      These sort functions need to return the following:
  • trunk/src/helpers/nls.c

    r142 r147  
    4040
    4141#define INCL_DOSNLS
     42#define INCL_DOSSEMAPHORES
     43#define INCL_DOSEXCEPTIONS
     44#define INCL_DOSPROCESS
    4245#define INCL_DOSERRORS
    4346#define INCL_WINSHELLDATA
     
    4851#include <string.h>
    4952#include <math.h>
     53#include <setjmp.h>
    5054
    5155#include "setup.h"                      // code generation and debugging options
    5256
     57#include "helpers\except.h"
     58#include "helpers\nls.h"
    5359#include "helpers\prfh.h"
    54 #include "helpers\nls.h"
     60#include "helpers\standards.h"
     61#include "helpers\stringh.h"
     62#include "helpers\tree.h"
     63#include "helpers\xstring.h"
    5564
    5665#pragma hdrstop
     
    495504    return (ERROR_INVALID_PARAMETER);
    496505}
     506
     507/* ******************************************************************
     508 *
     509 *   NLS strings
     510 *
     511 ********************************************************************/
     512
     513static HAB                 G_hab = NULLHANDLE;
     514static HMODULE             G_hmod = NULLHANDLE;
     515static PCSTRINGENTITY      G_paEntities = NULL;
     516static ULONG               G_cEntities = 0;
     517
     518/*
     519 *@@ ReplaceEntities:
     520 *
     521 *@@added V0.9.16 (2001-09-29) [umoeller]
     522 */
     523
     524static ULONG ReplaceEntities(PXSTRING pstr)
     525{
     526    ULONG ul,
     527          rc = 0;
     528
     529    for (ul = 0;
     530         ul < G_cEntities;
     531         ul++)
     532    {
     533        ULONG ulOfs = 0;
     534        PCSTRINGENTITY pThis = &G_paEntities[ul];
     535        while (xstrFindReplaceC(pstr,
     536                                &ulOfs,
     537                                pThis->pcszEntity,
     538                                *(pThis->ppcszString)))
     539            rc++;
     540    }
     541
     542    return (rc);
     543}
     544
     545/*
     546 *@@ LoadString:
     547 *
     548 *@@added V0.9.18 (2002-03-08) [umoeller]
     549 */
     550
     551static void LoadString(ULONG ulID,
     552                       PSZ *ppsz,
     553                       PULONG pulLength)        // out: length of new string (ptr can be NULL)
     554{
     555    CHAR szBuf[500];
     556    XSTRING str;
     557
     558    if (*ppsz)
     559        free(*ppsz);
     560
     561    if (!WinLoadString(G_hab,
     562                       G_hmod,
     563                       ulID,
     564                       sizeof(szBuf),
     565                       szBuf))
     566        // loading failed:
     567        sprintf(szBuf,
     568                "LoadString error: string resource %d not found in module 0x%lX",
     569                ulID,
     570                G_hmod);
     571
     572    xstrInitCopy(&str, szBuf, 0);
     573    ReplaceEntities(&str);
     574    *ppsz = str.psz;
     575    if (pulLength)
     576        *pulLength = str.ulLength;
     577    // do not free string
     578}
     579
     580static HMTX        G_hmtxStringsCache = NULLHANDLE;
     581static TREE        *G_StringsCache;
     582static LONG        G_cStringsInCache = 0;
     583
     584/*
     585 *@@ LockStrings:
     586 *
     587 *@@added V0.9.9 (2001-04-04) [umoeller]
     588 */
     589
     590static BOOL LockStrings(VOID)
     591{
     592    BOOL brc = FALSE;
     593
     594    if (G_hmtxStringsCache == NULLHANDLE)
     595    {
     596        brc = !DosCreateMutexSem(NULL,
     597                                 &G_hmtxStringsCache,
     598                                 0,
     599                                 TRUE);
     600        treeInit(&G_StringsCache,
     601                 &G_cStringsInCache);
     602    }
     603    else
     604        brc = !DosRequestMutexSem(G_hmtxStringsCache, SEM_INDEFINITE_WAIT);
     605
     606    return (brc);
     607}
     608
     609/*
     610 *@@ UnlockStrings:
     611 *
     612 *@@added V0.9.9 (2001-04-04) [umoeller]
     613 */
     614
     615static VOID UnlockStrings(VOID)
     616{
     617    DosReleaseMutexSem(G_hmtxStringsCache);
     618}
     619
     620/*
     621 *@@ STRINGTREENODE:
     622 *      internal string node structure for cmnGetString.
     623 *
     624 *@@added V0.9.9 (2001-04-04) [umoeller]
     625 *@@changed V0.9.16 (2002-01-26) [umoeller]: no longer using malloc() for string
     626 */
     627
     628typedef struct _STRINGTREENODE
     629{
     630    TREE        Tree;               // tree node (src\helpers\tree.c)
     631    CHAR        szLoaded[1];        // string that was loaded;
     632                                    // the struct is dynamic in size now
     633                                    // V0.9.16 (2002-01-26) [umoeller]
     634} STRINGTREENODE, *PSTRINGTREENODE;
     635
     636/*
     637 *@@ nlsInitStrings:
     638 *      initializes the NLS strings cache. Call this
     639 *      before calling nlsGetString for the first time.
     640 *
     641 *@@added V0.9.18 (2002-03-08) [umoeller]
     642 */
     643
     644VOID nlsInitStrings(HAB hab,                    // in: anchor block
     645                    HMODULE hmod,               // in: module handle to load strings from
     646                    PCSTRINGENTITY paEntities,  // in: entities array or NULL
     647                    ULONG cEntities)            // in: array item count of paEntities or 0
     648{
     649    G_hab = hab;
     650    G_hmod = hmod;
     651    G_paEntities = paEntities;
     652    G_cEntities = cEntities;
     653}
     654
     655/*
     656 *@@ nlsGetString:
     657 *      returns a resource NLS string.
     658 *
     659 *      Before calling this for the first time, initialize
     660 *      the engine with nlsInitStrings.
     661 *
     662 *      After that, this function implements a fast string
     663 *      cache for various NLS strings. Compared to the
     664 *      standard method, this has the following advantages:
     665 *
     666 *      -- Memory is only consumed for strings that are actually
     667 *         used. The NLSSTRINGS array had become terribly big,
     668 *         and lots of strings were loaded that were never used.
     669 *
     670 *      -- Program startup should be a bit faster because we don't
     671 *         have to load a thousand strings at startup.
     672 *
     673 *      -- The memory buffer holding the string is probably close
     674 *         to the rest of the heap data that the caller allocated,
     675 *         so this might lead to less memory page fragmentation.
     676 *
     677 *      -- To add a new NLS string, before this mechanism existed,
     678 *         three files had to be changed (and kept in sync): common.h
     679 *         to add a field to the NLSSTRINGS structure, dlgids.h to
     680 *         add the string ID, and xfldrXXX.rc to add the resource.
     681 *         With the new mechanism, there's no need to change common.h
     682 *         any more, so the danger of forgetting something is a bit
     683 *         reduced. Anyway, fewer recompiles are needed (maybe),
     684 *         and sending in patches to the code is a bit easier.
     685 *
     686 *      On input, specify a string resouce ID that exists
     687 *      in the hmod that was given to nlsInitStrings.
     688 *
     689 *      The way this works is that the function maintains a
     690 *      fast cache of string IDs and only loads the string
     691 *      resources on demand from the given NLS DLL. If a
     692 *      string ID is queried for the first time, the string
     693 *      is loaded. Otherwise the cached copy is returned.
     694 *
     695 *      There is a slight overhead to this function compared to
     696 *      simply getting a static string from an array, because
     697 *      the cache needs to be searched for the string ID. However,
     698 *      this uses a binary tree (balanced according to string IDs)
     699 *      internally, so this is quite fast still.
     700 *
     701 *      This never releases the strings again.
     702 *
     703 *      This never returns NULL. Even if loading the string failed,
     704 *      a string is returned; in that case, it's a meaningful error
     705 *      message specifying the ID that failed.
     706 *
     707 *@@added V0.9.9 (2001-04-04) [umoeller]
     708 *@@changed V0.9.16 (2001-10-19) [umoeller]: fixed bad string count which was never set
     709 *@@changed V0.9.16 (2002-01-26) [umoeller]: optimized heap locality
     710 */
     711
     712PCSZ nlsGetString(ULONG ulStringID)
     713{
     714    BOOL    fLocked = FALSE;
     715    PSZ     pszReturn = "Error";
     716
     717    TRY_LOUD(excpt1)
     718    {
     719        if (fLocked = LockStrings())
     720        {
     721            PSTRINGTREENODE pNode;
     722
     723            if (pNode = (PSTRINGTREENODE)treeFind(G_StringsCache,
     724                                                  ulStringID,
     725                                                  treeCompareKeys))
     726                // already loaded:
     727                pszReturn = pNode->szLoaded;
     728            else
     729            {
     730                // not loaded: load now
     731                PSZ     psz = NULL;
     732                ULONG   ulLength = 0;
     733
     734                LoadString(ulStringID,
     735                           &psz,
     736                           &ulLength);
     737
     738                if (    (!psz)
     739                     || (!(pNode = (PSTRINGTREENODE)malloc(   sizeof(STRINGTREENODE)
     740                                                               // has one byte for null
     741                                                               // terminator already
     742                                                            + ulLength)))
     743                   )
     744                    pszReturn = "malloc() failed.";
     745                else
     746                {
     747                    pNode->Tree.ulKey = ulStringID;
     748                    memcpy(pNode->szLoaded,
     749                           psz,
     750                           ulLength + 1);
     751                    treeInsert(&G_StringsCache,
     752                               &G_cStringsInCache,      // fixed V0.9.16 (2001-10-19) [umoeller]
     753                               (TREE*)pNode,
     754                               treeCompareKeys);
     755                    pszReturn = pNode->szLoaded;
     756                }
     757
     758                if (psz)
     759                    free(psz);
     760            }
     761        }
     762        else
     763        // we must always return a string, never NULL
     764        pszReturn = "Cannot get strings lock.";
     765    }
     766    CATCH(excpt1) {} END_CATCH();
     767
     768    if (fLocked)
     769        UnlockStrings();
     770
     771    return (pszReturn);
     772}
     773
  • trunk/src/helpers/stringh.c

    r144 r147  
    14131413ULONG strhGetBlock(const char *pszSearchIn, // in: buffer to search
    14141414                   PULONG pulSearchOffset, // in/out: offset where to start search (0 for beginning)
    1415                    PSZ pszTag,
     1415                   const char *pszTag,
    14161416                   PSZ *ppszBlock,      // out: block enclosed by the tags
    14171417                   PSZ *ppszAttribs,    // out: attributes of the opening tag
     
    14291429    while ((pszBeginTag = strchr(pszBeginTag, '<')))
    14301430    {
    1431         if (memicmp(pszBeginTag+1, pszTag, strlen(pszTag)) == 0)
     1431        if (memicmp(pszBeginTag+1, (void*)pszTag, strlen(pszTag)) == 0)
    14321432            // yes: stop
    14331433            break;
     
    14801480                // tag, we need to have several closing tags before
    14811481                // we're done
    1482                 if (memicmp(pszClosingTag+1, pszTag, cbTag) == 0)
     1482                if (memicmp(pszClosingTag+1, (void*)pszTag, cbTag) == 0)
    14831483                    ulNestingLevel++;
    14841484                else
     
    14861486                    // is this ours?
    14871487                    if (    (*(pszClosingTag+1) == '/')
    1488                          && (memicmp(pszClosingTag+2, pszTag, cbTag) == 0)
     1488                         && (memicmp(pszClosingTag+2, (void*)pszTag, cbTag) == 0)
    14891489                       )
    14901490                    {
  • trunk/src/helpers/tmsgfile.c

    r129 r147  
    406406                     PCSZ pcszMessageName,      // in: msg name to look for (case-sensitive!)
    407407                     PXSTRING pstr,             // out: message string, if found (XSTRING must be initialized)
    408                      PSZ *pTable,               // in: replacement table or NULL
     408                     PCSZ *pTable,              // in: replacement table or NULL
    409409                     ULONG cTableEntries)       // in: count of items in pTable or null
    410410{
  • trunk/src/helpers/winh.c

    r146 r147  
    23552355
    23562356BOOL winhAdjustControls(HWND hwndDlg,           // in: dialog (req.)
    2357                         MPARAM *pmpFlags,      // in: init flags or NULL for cleanup
     2357                        const MPARAM *pmpFlags, // in: init flags or NULL for cleanup
    23582358                        ULONG ulCount,          // in: item count (req.)
    23592359                        PSWP pswpNew,           // in: pswpNew from WM_WINDOWPOSCHANGED or NULL for cleanup
     
    23692369    {
    23702370        PSWP    pswpThis;
    2371         MPARAM  *pmpThis;
     2371        const MPARAM  *pmpThis;
    23722372        LONG    ldcx, ldcy;
    23732373        ULONG   cWindows = 0;
  • trunk/src/helpers/xml.c

    r142 r147  
    21312131                XSTRING strElementName;
    21322132                xstrInitSet(&strElementName, (PSZ)pcszElementName);
    2133                 pThis = (PCMATTRIBUTEDECLBASE)treeFind(
     2133                if (!(pThis = (PCMATTRIBUTEDECLBASE)treeFind(
    21342134                                    pDocType->AttribDeclBasesTree,
    21352135                                    (ULONG)&strElementName,
    2136                                     CompareXStrings);
    2137 
    2138                 if (!pThis)
     2136                                    CompareXStrings)))
    21392137                {
    21402138                    // still not found:
    21412139                    // we need a new node then
    2142                     pDom->arcDOM = xmlCreateNodeBase(ATTRIBUTE_DECLARATION_BASE,
     2140                    if (!(pDom->arcDOM = xmlCreateNodeBase(ATTRIBUTE_DECLARATION_BASE,
    21432141                                                     sizeof(CMATTRIBUTEDECLBASE),
    21442142                                                     strElementName.psz,
    21452143                                                     strElementName.ulLength,
    2146                                                      (PNODEBASE*)&pThis);
    2147                     if (!pDom->arcDOM)
     2144                                                     (PNODEBASE*)&pThis)))
    21482145                    {
    21492146                        // initialize the subtree
  • trunk/src/helpers/xmlparse.c

    r142 r147  
    829829 */
    830830
    831 XML_Parser XML_ParserCreateNS(const XML_Char * encodingName, XML_Char nsSep)
     831XML_Parser XML_ParserCreateNS(const XML_Char * encodingName,
     832                              XML_Char nsSep)
    832833{
    833834    XML_Char tmp[2];
     
    10061007 */
    10071008
    1008 int XML_SetEncoding(XML_Parser parser, const XML_Char * encodingName)
     1009int XML_SetEncoding(XML_Parser parser,
     1010                    const XML_Char * encodingName)
    10091011{
    10101012    if (!encodingName)
     
    11401142}
    11411143
    1142 static void destroyBindings(BINDING * bindings, XML_Parser parser)
     1144static void destroyBindings(BINDING * bindings,
     1145                            XML_Parser parser)
    11431146{
    11441147    for (;;)
     
    12381241 */
    12391242
    1240 void XML_SetReturnNSTriplet(XML_Parser parser, int do_nst)
     1243void XML_SetReturnNSTriplet(XML_Parser parser,
     1244                            int do_nst)
    12411245{
    12421246    ns_triplets = do_nst;
     
    12571261 */
    12581262
    1259 void XML_SetUserData(XML_Parser parser, void *p)
     1263void XML_SetUserData(XML_Parser parser,
     1264                     void *p)
    12601265{
    12611266    if (handlerArg == userData)
     
    12721277 */
    12731278
    1274 int XML_SetBase(XML_Parser parser, const XML_Char * p)
     1279int XML_SetBase(XML_Parser parser,
     1280                const XML_Char * p)
    12751281{
    12761282    if (p)
     
    20772083 */
    20782084
    2079 int XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
     2085int XML_Parse(XML_Parser parser,
     2086              const char *s,
     2087              int len,
     2088              int isFinal)
    20802089{
    20812090    if (len == 0)
     
    21552164 */
    21562165
    2157 int XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
     2166int XML_ParseBuffer(XML_Parser parser,
     2167                    int len,
     2168                    int isFinal)
    21582169{
    21592170    const char *start = bufferPtr;
     
    22072218 */
    22082219
    2209 void *XML_GetBuffer(XML_Parser parser, int len)
     2220void *XML_GetBuffer(XML_Parser parser,
     2221                    int len)
    22102222{
    22112223    if (len > bufferLim - bufferEnd)
     
    23572369 */
    23582370
    2359 const char *XML_GetInputContext(XML_Parser parser, int *offset, int *size)
     2371const char *XML_GetInputContext(XML_Parser parser,
     2372                                int *offset,
     2373                                int *size)
    23602374{
    23612375#ifdef XML_CONTEXT_BYTES
     
    30953109 * otherwise just check the attributes for well-formedness. */
    30963110
    3097 static XMLERROR storeAtts(XML_Parser parser, const ENCODING * enc,
    3098                           const char *attStr, TAG_NAME * tagNamePtr,
     3111static XMLERROR storeAtts(XML_Parser parser,
     3112                          const ENCODING * enc,
     3113                          const char *attStr,
     3114                          TAG_NAME * tagNamePtr,
    30993115                          BINDING ** bindingsPtr)
    31003116{
     
    54245440}
    54255441
    5426 static int setContext(XML_Parser parser, const XML_Char * context)
     5442static int setContext(XML_Parser parser,
     5443                      const XML_Char * context)
    54275444{
    54285445    const XML_Char *s = context;
     
    55125529}
    55135530
    5514 static int dtdInit(DTD * p, XML_Parser parser)
     5531static int dtdInit(DTD * p,
     5532                   XML_Parser parser)
    55155533{
    55165534    XML_Memory_Handling_Suite *ms = &((Parser *) parser)->m_mem;
     
    57965814}
    57975815
    5798 static NAMED *lookup(HASH_TABLE * table, KEY name, size_t createSize)
     5816static NAMED *lookup(HASH_TABLE * table,
     5817                     KEY name,
     5818                     size_t createSize)
    57995819{
    58005820    size_t i;
  • trunk/src/helpers/xmltok.c

    r98 r147  
    8585#define UTF8_INVALID4(p) ((*p) == 0xF4 && ((p)[1] & 0x30) != 0)
    8686
    87 static
    88 int EXPATENTRY isNever(const ENCODING * enc, const char *p)
     87static int EXPATENTRY isNever(const ENCODING * enc, const char *p)
    8988{
    9089    return 0;
    9190}
    9291
    93 static
    94 int EXPATENTRY utf8_isName2(const ENCODING * enc, const char *p)
     92static int EXPATENTRY utf8_isName2(const ENCODING * enc, const char *p)
    9593{
    9694    return UTF8_GET_NAMING2(namePages, (const unsigned char *)p);
    9795}
    9896
    99 static
    100 int EXPATENTRY utf8_isName3(const ENCODING * enc, const char *p)
     97static int EXPATENTRY utf8_isName3(const ENCODING * enc, const char *p)
    10198{
    10299    return UTF8_GET_NAMING3(namePages, (const unsigned char *)p);
     
    105102#define utf8_isName4 isNever
    106103
    107 static
    108 int EXPATENTRY utf8_isNmstrt2(const ENCODING * enc, const char *p)
     104static int EXPATENTRY utf8_isNmstrt2(const ENCODING * enc, const char *p)
    109105{
    110106    return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p);
    111107}
    112108
    113 static
    114 int EXPATENTRY utf8_isNmstrt3(const ENCODING * enc, const char *p)
     109static int EXPATENTRY utf8_isNmstrt3(const ENCODING * enc, const char *p)
    115110{
    116111    return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p);
     
    121116#define utf8_isInvalid2 isNever
    122117
    123 static
    124 int EXPATENTRY utf8_isInvalid3(const ENCODING * enc, const char *p)
     118static int EXPATENTRY utf8_isInvalid3(const ENCODING * enc, const char *p)
    125119{
    126120    return UTF8_INVALID3((const unsigned char *)p);
    127121}
    128122
    129 static
    130 int EXPATENTRY utf8_isInvalid4(const ENCODING * enc, const char *p)
     123static int EXPATENTRY utf8_isInvalid4(const ENCODING * enc, const char *p)
    131124{
    132125    return UTF8_INVALID4((const unsigned char *)p);
     
    276269
    277270static void EXPATENTRY utf8_toUtf8(const ENCODING * enc,
    278                         const char **fromP,
    279                         const char *fromLim,
    280                         char **toP,
    281                         const char *toLim)
     271                                   const char **fromP,
     272                                   const char *fromLim,
     273                                   char **toP,
     274                                   const char *toLim)
    282275{
    283276    char *to;
     
    302295
    303296static void EXPATENTRY utf8_toUtf16(const ENCODING * enc,
    304                          const char **fromP,
    305                          const char *fromLim,
    306                          unsigned short **toP,
    307                          const unsigned short *toLim)
     297                                    const char **fromP,
     298                                    const char *fromLim,
     299                                    unsigned short **toP,
     300                                    const unsigned short *toLim)
    308301{
    309302    unsigned short *to = *toP;
     
    397390
    398391static void  EXPATENTRY latin1_toUtf8(const ENCODING * enc,
    399                           const char **fromP,
    400                           const char *fromLim,
    401                           char **toP,
    402                           const char *toLim)
     392                                      const char **fromP,
     393                                      const char *fromLim,
     394                                      char **toP,
     395                                      const char *toLim)
    403396{
    404397    for (;;)
     
    427420
    428421static void  EXPATENTRY latin1_toUtf16(const ENCODING * enc,
    429                            const char **fromP,
    430                            const char *fromLim,
    431                            unsigned short **toP,
    432                            const unsigned short *toLim)
     422                                       const char **fromP,
     423                                       const char *fromLim,
     424                                       unsigned short **toP,
     425                                       const unsigned short *toLim)
    433426{
    434427    while (*fromP != fromLim && *toP != toLim)
     
    463456
    464457static void EXPATENTRY ascii_toUtf8(const ENCODING * enc,
    465                          const char **fromP,
    466                          const char *fromLim,
    467                          char **toP,
    468                          const char *toLim)
     458                                    const char **fromP,
     459                                    const char *fromLim,
     460                                    char **toP,
     461                                    const char *toLim)
    469462{
    470463    while (*fromP != fromLim && *toP != toLim)
     
    918911}
    919912
    920 static void  EXPATENTRY initUpdatePosition(const ENCODING * enc, const char *ptr,
    921                         const char *end, POSITION * pos)
     913static void  EXPATENTRY initUpdatePosition(const ENCODING * enc,
     914                                           const char *ptr,
     915                                           const char *end,
     916                                           POSITION * pos)
    922917{
    923918    normal_updatePosition(&utf8_encoding.enc, ptr, end, pos);
    924919}
    925920
    926 static int  EXPATENTRY toAscii(const ENCODING * enc, const char *ptr, const char *end)
     921static int  EXPATENTRY toAscii(const ENCODING * enc,
     922                               const char *ptr,
     923                               const char *end)
    927924{
    928925    char buf[1];
     
    952949 * or there's an S followed by name=val. */
    953950static int  EXPATENTRY parsePseudoAttribute(const ENCODING * enc,
    954                                 const char *ptr,
    955                                 const char *end,
    956                                 const char **namePtr,
    957                                 const char **nameEndPtr,
    958                                 const char **valPtr,
    959                                 const char **nextTokPtr)
     951                                            const char *ptr,
     952                                            const char *end,
     953                                            const char **namePtr,
     954                                            const char **nameEndPtr,
     955                                            const char **valPtr,
     956                                            const char **nextTokPtr)
    960957{
    961958    int c;
     
    13121309
    13131310static void  EXPATENTRY unknown_toUtf8(const ENCODING * enc,
    1314                            const char **fromP,
    1315                            const char *fromLim,
    1316                            char **toP,
    1317                            const char *toLim)
     1311                                       const char **fromP,
     1312                                       const char *fromLim,
     1313                                       char **toP,
     1314                                       const char *toLim)
    13181315{
    13191316    char buf[XML_UTF8_ENCODE_MAX];
     
    13551352
    13561353static void  EXPATENTRY unknown_toUtf16(const ENCODING * enc,
    1357                             const char **fromP,
    1358                             const char *fromLim,
    1359                             unsigned short **toP,
    1360                             const unsigned short *toLim)
     1354                                        const char **fromP,
     1355                                        const char *fromLim,
     1356                                        unsigned short **toP,
     1357                                        const unsigned short *toLim)
    13611358{
    13621359    while (*fromP != fromLim && *toP != toLim)
     
    15591556
    15601557static int EXPATENTRY initScan(const ENCODING ** encodingTable,
    1561                     const INIT_ENCODING * enc,
    1562                     int state,
    1563                     const char *ptr,
    1564                     const char *end,
    1565                     const char **nextTokPtr)
     1558                               const INIT_ENCODING * enc,
     1559                               int state,
     1560                               const char *ptr,
     1561                               const char *end,
     1562                               const char **nextTokPtr)
    15661563{
    15671564    const ENCODING **encPtr;
  • trunk/src/helpers/xmltok_impl.c

    r98 r147  
    156156/* ptr points to character following "<!" */
    157157
    158 static int EXPATENTRY PREFIX(scanDecl)(const ENCODING *enc, const char *ptr, const char *end,
    159              const char **nextTokPtr)
     158static int EXPATENTRY PREFIX(scanDecl)(const ENCODING *enc,
     159                                       const char *ptr,
     160                                       const char *end,
     161                                       const char **nextTokPtr)
    160162{
    161163  if (ptr == end)
     
    202204}
    203205
    204 static int EXPATENTRY PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, const char *end, int *tokPtr)
     206static int EXPATENTRY PREFIX(checkPiTarget)(const ENCODING *enc,
     207                                            const char *ptr,
     208                                            const char *end,
     209                                            int *tokPtr)
    205210{
    206211  int upper = 0;
     
    245250/* ptr points to character following "<?" */
    246251
    247 static int EXPATENTRY PREFIX(scanPi)(const ENCODING *enc, const char *ptr, const char *end,
    248            const char **nextTokPtr)
     252static int EXPATENTRY PREFIX(scanPi)(const ENCODING *enc,
     253                                     const char *ptr,
     254                                     const char *end,
     255                                     const char **nextTokPtr)
    249256{
    250257  int tok;
     
    307314
    308315
    309 static int EXPATENTRY PREFIX(scanCdataSection)(const ENCODING *enc, const char *ptr, const char *end,
    310                  const char **nextTokPtr)
     316static int EXPATENTRY PREFIX(scanCdataSection)(const ENCODING *enc,
     317                                               const char *ptr,
     318                                               const char *end,
     319                                               const char **nextTokPtr)
    311320{
    312321  static const char CDATA_LSQB[] = { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, ASCII_LSQB };
     
    325334}
    326335
    327 static int EXPATENTRY PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, const char *end,
    328                 const char **nextTokPtr)
     336static int EXPATENTRY PREFIX(cdataSectionTok)(const ENCODING *enc,
     337                                              const char *ptr,
     338                                              const char *end,
     339                                              const char **nextTokPtr)
    329340{
    330341  if (ptr == end)
     
    402413/* ptr points to character following "</" */
    403414
    404 static int EXPATENTRY PREFIX(scanEndTag)(const ENCODING *enc, const char *ptr, const char *end,
    405                const char **nextTokPtr)
     415static int EXPATENTRY PREFIX(scanEndTag)(const ENCODING *enc,
     416                                         const char *ptr,
     417                                         const char *end,
     418                                         const char **nextTokPtr)
    406419{
    407420  if (ptr == end)
     
    449462/* ptr points to character following "&#X" */
    450463
    451 static int EXPATENTRY PREFIX(scanHexCharRef)(const ENCODING *enc, const char *ptr, const char *end,
    452                const char **nextTokPtr)
     464static int EXPATENTRY PREFIX(scanHexCharRef)(const ENCODING *enc,
     465                                             const char *ptr,
     466                                             const char *end,
     467                                             const char **nextTokPtr)
    453468{
    454469  if (ptr != end) {
     
    480495/* ptr points to character following "&#" */
    481496
    482 static int EXPATENTRY PREFIX(scanCharRef)(const ENCODING *enc, const char *ptr, const char *end,
    483             const char **nextTokPtr)
     497static int EXPATENTRY PREFIX(scanCharRef)(const ENCODING *enc,
     498                                          const char *ptr,
     499                                          const char *end,
     500                                          const char **nextTokPtr)
    484501{
    485502  if (ptr != end) {
     
    511528/* ptr points to character following "&" */
    512529
    513 static int EXPATENTRY PREFIX(scanRef)(const ENCODING *enc, const char *ptr, const char *end,
    514             const char **nextTokPtr)
     530static int EXPATENTRY PREFIX(scanRef)(const ENCODING *enc,
     531                                     const char *ptr,
     532                                     const char *end,
     533                                     const char **nextTokPtr)
    515534{
    516535  if (ptr == end)
     
    540559/* ptr points to character following first character of attribute name */
    541560
    542 static int EXPATENTRY PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end,
    543              const char **nextTokPtr)
     561static int EXPATENTRY PREFIX(scanAtts)(const ENCODING *enc,
     562                                       const char *ptr,
     563                                       const char *end,
     564                                       const char **nextTokPtr)
    544565{
    545566#ifdef XML_NS
     
    699720/* ptr points to character following "<" */
    700721
    701 static int EXPATENTRY PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end,
    702            const char **nextTokPtr)
     722static int EXPATENTRY PREFIX(scanLt)(const ENCODING *enc,
     723                                     const char *ptr,
     724                                     const char *end,
     725                                     const char **nextTokPtr)
    703726{
    704727#ifdef XML_NS
     
    797820}
    798821
    799 static int EXPATENTRY PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end,
    800                const char **nextTokPtr)
     822static int EXPATENTRY PREFIX(contentTok)(const ENCODING *enc,
     823                                         const char *ptr,
     824                                         const char *end,
     825                                         const char **nextTokPtr)
    801826{
    802827  if (ptr == end)
     
    895920/* ptr points to character following "%" */
    896921
    897 static int EXPATENTRY PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end,
    898             const char **nextTokPtr)
     922static int EXPATENTRY PREFIX(scanPercent)(const ENCODING *enc,
     923                                          const char *ptr,
     924                                          const char *end,
     925                                          const char **nextTokPtr)
    899926{
    900927  if (ptr == end)
     
    923950}
    924951
    925 static int EXPATENTRY PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end,
    926               const char **nextTokPtr)
     952static int EXPATENTRY PREFIX(scanPoundName)(const ENCODING *enc,
     953                                            const char *ptr,
     954                                            const char *end,
     955                                            const char **nextTokPtr)
    927956{
    928957  if (ptr == end)
     
    949978}
    950979
    951 static int EXPATENTRY PREFIX(scanLit)(int open, const ENCODING *enc,
    952             const char *ptr, const char *end,
    953             const char **nextTokPtr)
     980static int EXPATENTRY PREFIX(scanLit)(int open,
     981                                      const ENCODING *enc,
     982                                      const char *ptr,
     983                                      const char *end,
     984                                      const char **nextTokPtr)
    954985{
    955986  while (ptr != end) {
     
    9801011}
    9811012
    982 static int EXPATENTRY PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
    983               const char **nextTokPtr)
     1013static int EXPATENTRY PREFIX(prologTok)(const ENCODING *enc,
     1014                                        const char *ptr,
     1015                                        const char *end,
     1016                                        const char **nextTokPtr)
    9841017{
    9851018  int tok;
     
    12071240}
    12081241
    1209 static int EXPATENTRY PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, const char *end,
    1210                   const char **nextTokPtr)
     1242static int EXPATENTRY PREFIX(attributeValueTok)(const ENCODING *enc,
     1243                                                const char *ptr,
     1244                                                const char *end,
     1245                                                const char **nextTokPtr)
    12111246{
    12121247  const char *start;
     
    12641299}
    12651300
    1266 static int EXPATENTRY PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end,
    1267                const char **nextTokPtr)
     1301static int EXPATENTRY PREFIX(entityValueTok)(const ENCODING *enc,
     1302                                             const char *ptr,
     1303                                             const char *end,
     1304                                             const char **nextTokPtr)
    12681305{
    12691306  const char *start;
     
    13201357#ifdef XML_DTD
    13211358
    1322 static int EXPATENTRY PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, const char *end,
    1323                  const char **nextTokPtr)
     1359static int EXPATENTRY PREFIX(ignoreSectionTok)(const ENCODING *enc,
     1360                                               const char *ptr,
     1361                                               const char *end,
     1362                                               const char **nextTokPtr)
    13241363{
    13251364  int level = 0;
     
    13721411#endif /* XML_DTD */
    13731412
    1374 static int EXPATENTRY PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
    1375                const char **badPtr)
     1413static int EXPATENTRY PREFIX(isPublicId)(const ENCODING *enc,
     1414                                         const char *ptr,
     1415                                         const char *end,
     1416                                         const char **badPtr)
    13761417{
    13771418  ptr += MINBPC(enc);
     
    14301471are stored in atts. */
    14311472
    1432 static int EXPATENTRY PREFIX(getAtts)(const ENCODING *enc, const char *ptr,
    1433             int attsMax, ATTRIBUTE *atts)
     1473static int EXPATENTRY PREFIX(getAtts)(const ENCODING *enc,
     1474                                      const char *ptr,
     1475                                      int attsMax,
     1476                                      ATTRIBUTE *atts)
    14341477{
    14351478  enum { other, inName, inValue } state = inName;
     
    15221565}
    15231566
    1524 static int EXPATENTRY PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr)
     1567static int EXPATENTRY PREFIX(charRefNumber)(const ENCODING *enc,
     1568                                            const char *ptr)
    15251569{
    15261570  int result = 0;
     
    15611605}
    15621606
    1563 static int EXPATENTRY PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, const char *end)
     1607static int EXPATENTRY PREFIX(predefinedEntityName)(const ENCODING *enc,
     1608                                                   const char *ptr,
     1609                                                   const char *end)
    15641610{
    15651611  switch ((end - ptr)/MINBPC(enc)) {
     
    16131659}
    16141660
    1615 static int EXPATENTRY PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2)
     1661static int EXPATENTRY PREFIX(sameName)(const ENCODING *enc,
     1662                                       const char *ptr1,
     1663                                       const char *ptr2)
    16161664{
    16171665  for (;;) {
     
    16761724}
    16771725
    1678 static int EXPATENTRY PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1,
    1679                  const char *end1, const char *ptr2)
     1726static int EXPATENTRY PREFIX(nameMatchesAscii)(const ENCODING *enc,
     1727                                               const char *ptr1,
     1728                                               const char *end1,
     1729                                               const char *ptr2)
    16801730{
    16811731  for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) {
     
    16881738}
    16891739
    1690 static int EXPATENTRY PREFIX(nameLength)(const ENCODING *enc, const char *ptr)
     1740static int EXPATENTRY PREFIX(nameLength)(const ENCODING *enc,
     1741                                         const char *ptr)
    16911742{
    16921743  const char *start = ptr;
     
    17141765}
    17151766
    1716 static const char* EXPATENTRY PREFIX(skipS)(const ENCODING *enc, const char *ptr)
     1767static const char* EXPATENTRY PREFIX(skipS)(const ENCODING *enc,
     1768                                            const char *ptr)
    17171769{
    17181770  for (;;) {
     
    17301782
    17311783static void EXPATENTRY PREFIX(updatePosition)(const ENCODING *enc,
    1732                 const char *ptr,
    1733                 const char *end,
    1734                 POSITION *pos)
     1784                                              const char *ptr,
     1785                                              const char *end,
     1786                                              POSITION *pos)
    17351787{
    17361788  while (ptr != end) {
  • trunk/src/helpers/xmltok_ns.c

    r98 r147  
    2727};
    2828
    29 static int EXPATENTRY NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
    30                const char **nextTokPtr)
     29static int EXPATENTRY NS(initScanProlog)(const ENCODING *enc,
     30                                         const char *ptr,
     31                                         const char *end,
     32                                         const char **nextTokPtr)
    3133{
    3234  return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE, ptr, end, nextTokPtr);
    3335}
    3436
    35 static int EXPATENTRY NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
    36                const char **nextTokPtr)
     37static int EXPATENTRY NS(initScanContent)(const ENCODING *enc,
     38                                          const char *ptr,
     39                                          const char *end,
     40                                          const char **nextTokPtr)
    3741{
    3842  return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE, ptr, end, nextTokPtr);
    3943}
    4044
    41 int NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, const char *name)
     45int NS(XmlInitEncoding)(INIT_ENCODING *p,
     46                        const ENCODING **encPtr,
     47                        const char *name)
    4248{
    4349  int i = getEncodingIndex(name);
     
    5460
    5561static
    56 const ENCODING *NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
     62const ENCODING *NS(findEncoding)(const ENCODING *enc,
     63                                 const char *ptr,
     64                                 const char *end)
    5765{
    5866#define ENCODING_MAX 128
     
    7381
    7482int NS(XmlParseXmlDecl)(int isGeneralTextEntity,
    75             const ENCODING *enc,
    76             const char *ptr,
    77             const char *end,
    78             const char **badPtr,
    79             const char **versionPtr,
    80             const char **versionEndPtr,
    81             const char **encodingName,
    82             const ENCODING **encoding,
    83             int *standalone)
     83                        const ENCODING *enc,
     84                        const char *ptr,
     85                        const char *end,
     86                        const char **badPtr,
     87                        const char **versionPtr,
     88                        const char **versionEndPtr,
     89                        const char **encodingName,
     90                        const ENCODING **encoding,
     91                        int *standalone)
    8492{
    8593  return doParseXmlDecl(NS(findEncoding),
  • trunk/src/helpers/xstring.c

    r144 r147  
    10641064            do  // while p
    10651065            {
    1066                 p = (PSZ)strhmemfind(p,         // in: haystack
    1067                                      pxstr->ulLength - (p - pxstr->psz),
    1068                                                 // remaining length of haystack
    1069                                      pstrFind->psz,
    1070                                      ulFoundLen,
    1071                                      pShiftTable,
    1072                                      pfRepeatFind);
    1073                 if (p)
     1066                if (p = (PSZ)strhmemfind(p,         // in: haystack
     1067                                         pxstr->ulLength - (p - pxstr->psz),
     1068                                                    // remaining length of haystack
     1069                                         pstrFind->psz,
     1070                                         ulFoundLen,
     1071                                         pShiftTable,
     1072                                         pfRepeatFind))
    10741073                {
    10751074                    // string found:
     
    11871186            // yes:
    11881187            ULONG   ulOfs = *pulOfs;
    1189             PCSZ pFound
    1190                 = (PCSZ)strhmemfind(pxstr->psz + ulOfs, // in: haystack
    1191                                             pxstr->ulLength - ulOfs,
    1192                                             pstrSearch->psz,
    1193                                             cSearchLen,
    1194                                             pShiftTable,
    1195                                             pfRepeatFind);
    1196             if (pFound)
     1188            PCSZ pFound;
     1189            if (pFound = (PCSZ)strhmemfind(pxstr->psz + ulOfs, // in: haystack
     1190                                           pxstr->ulLength - ulOfs,
     1191                                           pstrSearch->psz,
     1192                                           cSearchLen,
     1193                                           pShiftTable,
     1194                                           pfRepeatFind))
    11971195            {
    11981196                ULONG ulFirstReplOfs = pFound - pxstr->psz;
Note: See TracChangeset for help on using the changeset viewer.