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

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

unix.superglobalmegacorp.com

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