2 #define MAXPRINTABLE 128
4 #if ULTRIX || _AIX || _WIN32
13 #define BUFFERSIZE 14500000
18 double prob_tab[MAXPRINTABLE][MAXPRINTABLE];
21 add_line(char* buf, int count, int num_letters, char letter)
24 for (i = count; i < (count + num_letters); i ++)
34 fill_text_buffer(int count, char start_char, char* text_buffer)
36 long int total; /* normalization */
37 int i,j; /* array indexers */
38 char c1,c2; /* character holders for level-three search */
39 int writecount ; /* Number of characters written */
43 * For each ith, jth element in the frequency table, set the
44 * ith, jth, element of the probability table to the frequency
45 * table entry divided by the total.
53 total += freq_tab[i][j];
59 prob_tab[i][j] = (double)freq_tab[i][j]/(double)total;
63 * For each ith element in the probability table, make the
64 * jth elements cumulative in order to simplify 'getranchar'.
71 prob_tab[i][j]+=prob_tab[i][j-1];
77 "Probability table built, about to open file \n");
82 * Start off the simulation with seed letter.
88 * Get "count" characters and spit 'em out.
91 count-- ; /* pre-decrement for the final new line */
96 c2=getranchar(c1,ran2());
97 text_buffer[bufindex++]=c2 ;
99 fprintf(stderr,"Character number %d is %c\n",
107 * Complete the last line
111 text_buffer[bufindex++]=c2 ;
114 /* Routine For dumping contents of a buffer to the output
115 Jeff Reilly, 1/15/95 */
116 print_buffer(int count, char* text_buffer)
121 for (i=0;i<count;i++)
122 printf("%c", text_buffer[i]);
127 char getranchar(c,rnno)
137 * Ascend the jth column (given by c1).
138 * if the cumulative probability exceeds the random number, then
139 * the current (char) i is the character to return.
141 if (rnno > prob_tab[c][127])
147 if (rnno < prob_tab[c][mid])
149 else if (rnno > prob_tab[c][mid])
151 else /* exact match found -unlikely */
159 seedi=((314157*seedi)+19)&0xffffff;
160 return ( (double) seedi/(double)0xffffff);
164 /* See "Random Number Generators: Good Ones Are Hard To Find", */
165 /* Park & Miller, CACM 31#10 October 1988 pages 1192-1201. */
166 /***********************************************************/
167 /* THIS IMPLEMENTATION REQUIRES AT LEAST 32 BIT INTEGERS ! */
168 /***********************************************************/
169 #define _A_MULTIPLIER 16807L
170 #define _M_MODULUS 2147483647L /* (2**31)-1 */
171 #define _Q_QUOTIENT 127773L /* 2147483647 / 16807 */
172 #define _R_REMAINDER 2836L /* 2147483647 % 16807 */
178 hi = seedi / _Q_QUOTIENT;
179 lo = seedi % _Q_QUOTIENT;
180 test = _A_MULTIPLIER * lo - _R_REMAINDER * hi;
184 seedi = test + _M_MODULUS;
186 return ( (float) seedi / _M_MODULUS);
189 compare_buffer(char* buf1, int count1, char* buf2, int count2)
191 if (count1 == count2)
193 printf("Files both have length %d\n", count1);
196 if ( (buf1[0] == buf2[0]) && (buf1[count1-1] == buf2[count2-1]) )
198 printf("First character (%c) and Last Character (%c) match. \n", buf1[0], buf1[count1-1]);
202 printf("First and last characters do not match.\n");
203 printf("%c does not match %c\n", buf1[0], buf2[0]);
204 printf("or %c does not match %c\n", buf1[count1-1], buf2[count2-1]);
210 printf("Warning: Files of differing lengths: %d and %d\n", count1, count2);
216 char orig_text_buffer[BUFFERSIZE], comp_text_buffer[BUFFERSIZE], new_text_buffer[BUFFERSIZE];
219 int main(int argc, char *argv[])
223 int comp_count, new_count;
228 printf("SPEC 129.compress harness\n");
232 scanf("%i %c %li", &count, &start_char, &seedi);
233 printf("Initial File Size:%i Start character:%c\n", count, start_char, seedi);
234 fill_text_buffer(count, start_char, orig_text_buffer);
235 for (i = 1; i <= 25; i++)
237 new_count=add_line(orig_text_buffer, count, i, start_char);
240 printf("The starting size is: %d\n", count);
241 //comp_count=spec_select_action(orig_text_buffer, count, oper, comp_text_buffer);
242 printf("The compressed size is: %d\n", comp_count);
244 //new_count=spec_select_action(comp_text_buffer, comp_count, oper, new_text_buffer);
245 printf("The compressed/uncompressed size is: %d\n", new_count);
246 compare_buffer(orig_text_buffer, count, new_text_buffer, new_count);
248 /* Remove comments for Debugging */
250 printf("Original Text File:\n");
251 print_buffer(count, orig_text_buffer);
252 printf("New Text File:\n");
253 print_buffer(count, new_text_buffer); */