========================================================================= */
(strm, dictionary, dictLength)
| 377 | |
| 378 | /* ========================================================================= */ |
| 379 | int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) |
| 380 | z_streamp strm; |
| 381 | const Bytef *dictionary; |
| 382 | uInt dictLength; |
| 383 | { |
| 384 | deflate_state *s; |
| 385 | uInt str, n; |
| 386 | int wrap; |
| 387 | unsigned avail; |
| 388 | z_const unsigned char *next; |
| 389 | |
| 390 | if (deflateStateCheck(strm) || dictionary == Z_NULL) |
| 391 | return Z_STREAM_ERROR; |
| 392 | s = strm->state; |
| 393 | wrap = s->wrap; |
| 394 | if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) |
| 395 | return Z_STREAM_ERROR; |
| 396 | |
| 397 | /* when using zlib wrappers, compute Adler-32 for provided dictionary */ |
| 398 | if (wrap == 1) |
| 399 | strm->adler = adler32(strm->adler, dictionary, dictLength); |
| 400 | s->wrap = 0; /* avoid computing Adler-32 in read_buf */ |
| 401 | |
| 402 | /* if dictionary would fill window, just replace the history */ |
| 403 | if (dictLength >= s->w_size) { |
| 404 | if (wrap == 0) { /* already empty otherwise */ |
| 405 | CLEAR_HASH(s); |
| 406 | s->strstart = 0; |
| 407 | s->block_start = 0L; |
| 408 | s->insert = 0; |
| 409 | } |
| 410 | dictionary += dictLength - s->w_size; /* use the tail */ |
| 411 | dictLength = s->w_size; |
| 412 | } |
| 413 | |
| 414 | /* insert dictionary into window and hash */ |
| 415 | avail = strm->avail_in; |
| 416 | next = strm->next_in; |
| 417 | strm->avail_in = dictLength; |
| 418 | strm->next_in = (z_const Bytef *)dictionary; |
| 419 | fill_window(s); |
| 420 | while (s->lookahead >= MIN_MATCH) { |
| 421 | str = s->strstart; |
| 422 | n = s->lookahead - (MIN_MATCH-1); |
| 423 | do { |
| 424 | UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); |
| 425 | #ifndef FASTEST |
| 426 | s->prev[str & s->w_mask] = s->head[s->ins_h]; |
| 427 | #endif |
| 428 | s->head[s->ins_h] = (Pos)str; |
| 429 | str++; |
| 430 | } while (--n); |
| 431 | s->strstart = str; |
| 432 | s->lookahead = MIN_MATCH-1; |
| 433 | fill_window(s); |
| 434 | } |
| 435 | s->strstart += s->lookahead; |
| 436 | s->block_start = (long)s->strstart; |