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 */
42 * For each ith, jth element in the frequency table, set the
43 * ith, jth, element of the probability table to the frequency
44 * table entry divided by the total.
52 total += freq_tab[i][j];
58 prob_tab[i][j] = (double)freq_tab[i][j]/(double)total;
62 * For each ith element in the probability table, make the
63 * jth elements cumulative in order to simplify 'getranchar'.
70 prob_tab[i][j]+=prob_tab[i][j-1];
76 "Probability table built, about to open file \n");
81 * Start off the simulation with seed letter.
87 * Get "count" characters and spit 'em out.
90 count-- ; /* pre-decrement for the final new line */
95 c2=getranchar(c1,ran2());
96 text_buffer[bufindex++]=c2 ;
98 fprintf(stderr,"Character number %d is %c\n",
106 * Complete the last line
110 text_buffer[bufindex++]=c2 ;
113 /* Routine For dumping contents of a buffer to the output
114 Jeff Reilly, 1/15/95 */
115 print_buffer(int count, char* text_buffer)
120 for (i=0;i<count;i++)
121 printf("%c", text_buffer[i]);
126 char getranchar(c,rnno)
136 * Ascend the jth column (given by c1).
137 * if the cumulative probability exceeds the random number, then
138 * the current (char) i is the character to return.
140 if (rnno > prob_tab[c][127])
146 if (rnno < prob_tab[c][mid])
148 else if (rnno > prob_tab[c][mid])
150 else /* exact match found -unlikely */
158 seedi=((314157*seedi)+19)&0xffffff;
159 return ( (double) seedi/(double)0xffffff);
163 /* See "Random Number Generators: Good Ones Are Hard To Find", */
164 /* Park & Miller, CACM 31#10 October 1988 pages 1192-1201. */
165 /***********************************************************/
166 /* THIS IMPLEMENTATION REQUIRES AT LEAST 32 BIT INTEGERS ! */
167 /***********************************************************/
168 #define _A_MULTIPLIER 16807L
169 #define _M_MODULUS 2147483647L /* (2**31)-1 */
170 #define _Q_QUOTIENT 127773L /* 2147483647 / 16807 */
171 #define _R_REMAINDER 2836L /* 2147483647 % 16807 */
177 hi = seedi / _Q_QUOTIENT;
178 lo = seedi % _Q_QUOTIENT;
179 test = _A_MULTIPLIER * lo - _R_REMAINDER * hi;
183 seedi = test + _M_MODULUS;
185 return ( (float) seedi / _M_MODULUS);
188 compare_buffer(char* buf1, int count1, char* buf2, int count2)
190 if (count1 == count2)
192 printf("Files both have length %d\n", count1);
195 if ( (buf1[0] == buf2[0]) && (buf1[count1-1] == buf2[count2-1]) )
197 printf("First character (%c) and Last Character (%c) match. \n", buf1[0], buf1[count1-1]);
201 printf("First and last characters do not match.\n");
202 printf("%c does not match %c\n", buf1[0], buf2[0]);
203 printf("or %c does not match %c\n", buf1[count1-1], buf2[count2-1]);
209 printf("Warning: Files of differing lengths: %d and %d\n", count1, count2);
215 char orig_text_buffer[BUFFERSIZE], comp_text_buffer[BUFFERSIZE], new_text_buffer[BUFFERSIZE];
218 int main(int argc, char *argv[])
226 printf("SPEC 129.compress harness\n");
228 //scanf("%i %c %li", &count, &start_char, &seedi);
232 printf("Initial File Size:%i Start character:%c\n", count, start_char, seedi);
233 fill_text_buffer(count, start_char, orig_text_buffer);
234 for (i = 1; i <= 25; i++)
236 new_count=add_line(orig_text_buffer, count, i, start_char);
239 printf("The starting size is: %d\n", count);
240 //comp_count=spec_select_action(orig_text_buffer, count, oper, comp_text_buffer);
241 printf("The compressed size is: %d\n", comp_count);
243 //new_count=spec_select_action(comp_text_buffer, comp_count, oper, new_text_buffer);
244 printf("The compressed/uncompressed size is: %d\n", new_count);
245 //compare_buffer(orig_text_buffer, count, new_text_buffer, new_count);
247 /* Remove comments for Debugging */
249 printf("Original Text File:\n");
250 print_buffer(count, orig_text_buffer);
251 printf("New Text File:\n");
252 print_buffer(count, new_text_buffer); */