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