Annotation of mstools/samples/ddeml/client/huge.c, revision 1.1.1.3

1.1.1.3 ! root        1: 
        !             2: /******************************************************************************\
        !             3: *       This is a part of the Microsoft Source Code Samples. 
        !             4: *       Copyright (C) 1993 Microsoft Corporation.
        !             5: *       All rights reserved. 
        !             6: *       This source code is only intended as a supplement to 
        !             7: *       Microsoft Development Tools and/or WinHelp documentation.
        !             8: *       See these sources for detailed information regarding the 
        !             9: *       Microsoft samples programs.
        !            10: \******************************************************************************/
        !            11: 
1.1       root       12: /***************************************************************************
                     13:  *                                                                         *
                     14:  *  MODULE      : huge.c                                                   *
                     15:  *                                                                         *
                     16:  *  PURPOSE     : This contains functions useful for generating and        *
                     17:  *                verifying huge text data blocks.                         *
                     18:  *                                                                         *
                     19:  ***************************************************************************/
                     20: 
                     21: #include <windows.h>
                     22: #include <string.h>
                     23: #include <stdio.h>
                     24: #include <ddeml.h>
                     25: #include "huge.h"
                     26: 
                     27: extern DWORD idInst;
                     28: #define BUFSZ   435
                     29: 
                     30: LONG lseed, lmult, ladd;
                     31: CHAR szT[BUFSZ];
                     32: 
                     33: VOID SetMyRand(LONG seed, LONG mult, LONG add);
                     34: CHAR MyRand(VOID);
                     35: BOOL RandTest(LONG length, LONG seed, LONG mult, LONG add);
                     36: 
                     37: /****************************************************************************
                     38:  *                                                                          *
                     39:  *  FUNCTION   : SetMyRand()                                                *
                     40:  *                                                                          *
                     41:  *  PURPOSE    : Transfers random sequence generation variables to globals. *
                     42:  *                                                                          *
                     43:  ****************************************************************************/
                     44: VOID SetMyRand(
                     45: LONG seed,
                     46: LONG mult,
                     47: LONG add)
                     48: {
                     49:     lseed = seed;
                     50:     lmult = mult;
                     51:     ladd = add;
                     52: }
                     53: 
                     54: 
                     55: /****************************************************************************
                     56:  *                                                                          *
                     57:  *  FUNCTION   : MyRand()                                                   *
                     58:  *                                                                          *
                     59:  *  PURPOSE    : Generates the next random character in a sequence.         *
                     60:  *                                                                          *
                     61:  *  RETURNS    : the character generated                                    *
                     62:  *                                                                          *
                     63:  ****************************************************************************/
                     64: CHAR MyRand()
                     65: {
                     66:     CHAR c;
                     67: 
                     68:     lseed = lseed * lmult + ladd;
                     69:     c = (CHAR)(LOWORD(lseed) ^ HIWORD(lseed));
                     70:     return((CHAR)((c & (CHAR)0x4f) + ' '));   // 0x20 - 0x6f - all printable
                     71: }
                     72: 
                     73: 
                     74: /*
                     75:  * This function allocates and fills a HUGE data handle with a verifiable
                     76:  * text string.
                     77:  *
                     78:  * The format of the text string is:
                     79:  * "<length>=<seed>*<mult>+<add>;---data of length <length>---\0"
                     80:  * all values are stored in base 16 numbers.
                     81:  */
                     82: /****************************************************************************
                     83:  *                                                                          *
                     84:  *  FUNCTION   : CreateHugeDataHandle()                                     *
                     85:  *                                                                          *
                     86:  *  PURPOSE    : Generates a huge pseudo-random sequence of printable       *
                     87:  *               characters of the length given and places then into        *
                     88:  *               a DDEML data handle.                                       *
                     89:  *                                                                          *
                     90:  *  RETURNS    : The data handle created or 0 on failure.                   *
                     91:  *                                                                          *
                     92:  ****************************************************************************/
                     93: HDDEDATA CreateHugeDataHandle(
                     94: LONG length,
                     95: LONG seed,
                     96: LONG mult,
                     97: LONG add,
                     98: HSZ hszItem,
                     99: DWORD wFmt,
                    100: DWORD afCmd)
                    101: {
                    102:     register DWORD cb;
                    103:     HDDEDATA hData;
                    104:     DWORD cbData;
                    105:     CHAR *psz;
                    106: 
                    107:     wsprintf(szT, "%ld=%ld*%ld+%ld;", length, seed, mult, add);
                    108:     cb = strlen(szT);
                    109:     hData = DdeCreateDataHandle(idInst, szT, cb + 1, 0, hszItem, wFmt, afCmd);
                    110:     if (hData)
                    111:         hData = DdeAddData(hData, NULL, 0, cb + length + 1);
                    112:     cbData = cb;
                    113:     SetMyRand(seed, mult, add);
                    114:     while (hData && (length > 0)) {
                    115:         psz = szT;
                    116:         cb = BUFSZ;
                    117:         while (cb--)
                    118:             *psz++ = MyRand();
                    119:         hData = DdeAddData(hData, szT, min(length, BUFSZ), cbData);
                    120:         cbData += BUFSZ;
                    121:         length -= BUFSZ;
                    122:     }
                    123:     return(hData);
                    124: }
                    125: 
                    126: /****************************************************************************
                    127:  *                                                                          *
                    128:  *  FUNCTION   : CheckHugeData()                                            *
                    129:  *                                                                          *
                    130:  *  PURPOSE    : Verifies the correctness of a pseudo-random character      *
                    131:  *               sequence generated by CreateHugeData.                      *
                    132:  *                                                                          *
                    133:  *  RETURNS    : TRUE if verified ok, FALSE otherwise.                      *
                    134:  *                                                                          *
                    135:  ****************************************************************************/
                    136: BOOL CheckHugeData(
                    137: HDDEDATA hData)
                    138: {
                    139:     LONG length;
                    140:     LONG seed;
                    141:     LONG mult;
                    142:     LONG add;
                    143:     CHAR *psz;
                    144:     DWORD cbOff;
                    145:     DWORD cb;
                    146: 
                    147:     if (!DdeGetData(hData, szT, BUFSZ, 0))
                    148:         return(FALSE);
                    149:     szT[BUFSZ - 1] = '\0';
                    150:     psz = strchr(szT, ';');
                    151:     if (psz == NULL)
                    152:         return(FALSE);
                    153:     *psz = '\0';
                    154: 
                    155:     if (sscanf(szT, "%ld=%ld*%ld+%ld", &length, &seed, &mult, &add) != 4)
                    156:         return(FALSE);
                    157: 
                    158:     if (length < 0)
                    159:         return(FALSE);
                    160:     SetMyRand(seed, mult, add);
                    161:     cbOff = strlen(szT) + 1;
                    162:     while (length > 0) {
                    163:         DdeGetData(hData, szT, BUFSZ, cbOff);
                    164:         psz = szT;
                    165:         cb = BUFSZ;
                    166:         while (length-- && cb--)
                    167:             if (*psz++ != MyRand())
                    168:                 return(FALSE);
                    169:         cbOff += BUFSZ;
                    170:         length -= BUFSZ;
                    171:     }
                    172:     return(TRUE);
                    173: }
                    174: 
                    175: #if 0
                    176: /****************************************************************************
                    177:  *                                                                          *
                    178:  *  FUNCTION   : RandTest()                                                 *
                    179:  *                                                                          *
                    180:  *  PURPOSE    : Verifies the correctness of CreateHugeDataHandle() and     *
                    181:  *               CheckHugeData().                                           *
                    182:  *                                                                          *
                    183:  *  RETURNS    :                                                            *
                    184:  *                                                                          *
                    185:  ****************************************************************************/
                    186: BOOL RandTest(
                    187: LONG length,
                    188: LONG seed,
                    189: LONG mult,
                    190: LONG add)
                    191: {
                    192:     HDDEDATA hData;
                    193:     BOOL fSuccess;
                    194: 
                    195:     hData = CreateHugeDataHandle(length, seed, mult, add, 0, 1, 0);
                    196:     if (!hData)
                    197:         return(FALSE);
                    198:     fSuccess = CheckHugeData(hData);
                    199:     DdeFreeDataHandle(hData);
                    200:     return(fSuccess);
                    201: }
                    202: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.