///////////////////////////////////////////////////////////////////////////// // // Draw DIB on caller's DC. Does stretching from source to destination // rectangles. Generally, it's OK to let the following default to zero: // // bUseDrawDib = whether to use use DrawDib, default TRUE // pPalette = palette, default = 0, (use DIB's palette) // bForeground = realize in foreground (default FALSE) // // If handling palette messages, use bForeground = FALSE, since the // foreground palette will be realized in WM_QUERYNEWPALETTE. // ///////////////////////////////////////////////////////////////////////////// zBOOL ZDib::Draw( CDC& dc, const CRect *rectTgt, const CRect *rectSrc, zBOOL bUseDrawDib, CPalette *pPalette, zBOOL bForeground ) { if ( m_hObject == 0 ) return( FALSE ); // Select, realize palette. if ( pPalette == 0 ) // no palette specified: pPalette = GetPalette( ); // use default CPalette *pOldPal = dc.SelectPalette( pPalette, !bForeground ); dc.RealizePalette( ); zBOOL bRC = FALSE; if ( bUseDrawDib ) { // Compute rectangles where 0 specified. CRect rect( 0, 0, -1, -1 ); // default for ::DrawDibDraw if ( rectSrc == 0 ) rectSrc = ▭ if ( rectTgt == 0 ) rectTgt = rectSrc; if ( m_hdd == 0 ) VERIFY( (m_hdd = ::DrawDibOpen( )) != 0 ); // Get BITMAPINFOHEADER/color table. Copy into stack object each time. // This doesn't seem to slow things down visibly. DIBSECTION ds; VERIFY( GetObject( sizeof( ds ), &ds ) == sizeof( ds ) ); char buf[ sizeof( BITMAPINFOHEADER ) + MAXPALCOLORS * sizeof( RGBQUAD ) ]; BITMAPINFOHEADER& bmih = *(BITMAPINFOHEADER *) buf; RGBQUAD *colors = (RGBQUAD *) (&bmih + 1); zmemcpy( &bmih, &ds.dsBmih, sizeof( bmih ) ); GetColorTable( colors, MAXPALCOLORS ); // Let DrawDib do the work! bRC = ::DrawDibDraw( m_hdd, dc, rectTgt->left, rectTgt->top, rectTgt->Width( ), rectTgt->Height( ), &bmih, // ptr to BITMAPINFOHEADER + colors m_bitmap.bmBits, // bits in memory rectSrc->left, rectSrc->top, rectSrc->Width( ), rectSrc->Height( ), bForeground ? 0 : DDF_BACKGROUNDPAL ); } else { // Use normal draw function. bRC = DrawBitmap( dc, this, rectTgt, rectSrc ); } if ( pOldPal ) dc.SelectPalette( pOldPal, TRUE ); return( bRC ); }
/* ========================================================================= */ EXPORT_C int ZEXPORT deflateSetDictionary ( z_streamp strm, const Bytef *dictionary, uInt dictLength) { // Line to stop compiler warning about unused mandatory global variable char __z=deflate_copyright[0]; __z=__z; deflate_state *s; uInt length = dictLength; uInt n; IPos hash_head = 0; if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || strm->state->status != INIT_STATE) return Z_STREAM_ERROR; s = strm->state; strm->adler = adler32(strm->adler, dictionary, dictLength); if (length < MIN_MATCH) return Z_OK; if (length > MAX_DIST(s)) { length = MAX_DIST(s); #ifndef USE_DICT_HEAD dictionary += dictLength - length; /* use the tail of the dictionary */ #endif } zmemcpy(s->window, dictionary, length); s->strstart = length; s->block_start = (long)length; /* Insert all strings in the hash table (except for the last two bytes). * s->lookahead stays null, so s->ins_h will be recomputed at the next * call of fill_window. */ s->ins_h = s->window[0]; UPDATE_HASH(s, s->ins_h, s->window[1]); for (n = 0; n <= length - MIN_MATCH; n++) { INSERT_STRING(s, n, hash_head); } if (hash_head) hash_head = 0; /* to make compiler happy */ return Z_OK; }
/* copy as much as possible from the sliding window to the output area */ local void ZEXPORT inflate_flush(nsis_z_streamp z) { inflate_blocks_statef *s = &z->blocks; uInt n; Bytef *q; /* local copies of source and destination pointers */ q = s->read; again: /* compute number of bytes to copy as far as end of window */ n = (uInt)((q <= s->write ? s->write : s->end) - q); n = min(n, z->avail_out); /* update counters */ z->avail_out -= n; /* z->total_out += n; */ /* copy as far as end of window */ zmemcpy(z->next_out, q, n); z->next_out += n; q += n; /* see if more to copy at beginning of window */ if (q == s->end) { /* wrap pointers */ q = s->window; if (s->write == s->end) s->write = s->window; /* do the same for the beginning of the window */ goto again; } /* update pointers */ s->read = q; }
/* Open a Zip file. path contain the full pathname (by example, on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer "zlib/zlib109.zip". If the zipfile cannot be opened (file don't exist or in not valid), the return value is NULL. Else, the return value is a HUNZFILE Handle, usable with other function of this unzip package. */ ZEXTERN HUNZFILE ZEXPORT unzOpen(LPCSTR pszFileName) { LPUNZ_INTERNAL s; int err = UNZ_OK; int iPathSize; BOOL fPath; char buf[4]; LPSTR pszName; // getting the full path to the file iPathSize = GetFullPathName(pszFileName, 0, buf, &pszName); if(!iPathSize) { iPathSize = lstrlen(pszFileName); fPath = FALSE; } else fPath = TRUE; // alloc memory for the internal structure s = (LPUNZ_INTERNAL)ALLOCZ(sizeof(UNZ_INTERNAL) + iPathSize + 2); if(!s) return NULL; // copying the file path to the memory if(fPath) { iPathSize = GetFullPathName(pszFileName, iPathSize + 1, s->pszFilePath, &pszName); if(!iPathSize) err = UNZ_ERRNO; } else { zmemcpy(s->pszFilePath, pszFileName, iPathSize); s->pszFilePath[iPathSize] = 0; } // opening the file if(err == UNZ_OK) err = unzLocal_OpenInternal(s); if(err != UNZ_OK) { TRYFREE(s); s = NULL; } return (HUNZFILE)s; }
/* 将BUFFER的内容以十六进制的格式打印出来 */ void fhlog(char *buf, int len) { int ret; int i; int j; char temp1[100]; char temp2[100]; char *p; int offset; int t1; int t2; FILE* fp; /* 如果不打印,退出 */ if (BUF_LEVEL == 0) return; /* 如果文件未打开 */ if ((fp = fopen(BUF_FILE_NAME, "a")) == NULL) return ; /* 初始化 */ i = 0; j = 0; memset(temp1, 0, sizeof(temp1)); memset(temp2, 0, sizeof(temp2)); fprintf(fp, "时间:[%08d] 时间:[%06d]\n", get_sys_date(), get_sys_time()); for (i = 0; i < len; i ++) { if ((i + 1) % 10 == 0 && (i + 1) % 20 != 0) sprintf(temp2, "%02X-", (unsigned char)(*(buf + i))); else sprintf(temp2, "%02X ", (unsigned char)(*(buf + i))); strcat(temp1, temp2); if ((i + 1) % 20 == 0 && i != 0) { fprintf(fp, "%s", temp1); memset(temp1, 0, sizeof(temp1)); zmemcpy(temp1, buf + j, 20); for (t1 = 0; t1 < 20; t1 ++) { if (!isprint(*(temp1 + t1))) *(temp1 + t1) = '.'; fprintf(fp, "%c", *(temp1 + t1)); } fprintf(fp, "\n"); j = i + 1; memset(temp1, 0, sizeof(temp1)); } } if ((i + 1) % 20 != 0) { fprintf(fp, "%-60s", temp1); zmemcpy(temp1, buf + j, len - j); for (t1 = 0; t1 < len - j; t1 ++) { if (!isprint(*(temp1 + t1))) *(temp1 + t1) = '.'; fprintf(fp, "%c", *(temp1 + t1)); } fprintf(fp, "\n"); } fprintf(fp, "\n\n"); fclose(fp); return; }
void fill_window_sse(deflate_state *s) { z_const __m128i xmm_wsize = _mm_set1_epi16(s->w_size); register unsigned n; register Posf *p; unsigned more; /* Amount of free space at the end of the window. */ uInt wsize = s->w_size; Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); do { more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); /* Deal with !@#$% 64K limit: */ if (sizeof(int) <= 2) { if (more == 0 && s->strstart == 0 && s->lookahead == 0) { more = wsize; } else if (more == (unsigned)(-1)) { /* Very unlikely, but possible on 16 bit machine if * strstart == 0 && lookahead == 1 (input done a byte at time) */ more--; } } /* If the window is almost full and there is insufficient lookahead, * move the upper half to the lower one to make room in the upper half. */ if (s->strstart >= wsize+MAX_DIST(s)) { zmemcpy(s->window, s->window+wsize, (unsigned)wsize); s->match_start -= wsize; s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ s->block_start -= (long) wsize; /* Slide the hash table (could be avoided with 32 bit values at the expense of memory usage). We slide even when level == 0 to keep the hash table consistent if we switch back to level > 0 later. (Using level 0 permanently is not an optimal usage of zlib, so we don't care about this pathological case.) */ n = s->hash_size; p = &s->head[n]; p -= 8; do { __m128i value, result; value = _mm_loadu_si128((__m128i *)p); result = _mm_subs_epu16(value, xmm_wsize); _mm_storeu_si128((__m128i *)p, result); p -= 8; n -= 8; } while (n > 0); n = wsize; #ifndef FASTEST p = &s->prev[n]; p -= 8; do { __m128i value, result; value = _mm_loadu_si128((__m128i *)p); result = _mm_subs_epu16(value, xmm_wsize); _mm_storeu_si128((__m128i *)p, result); p -= 8; n -= 8; } while (n > 0); #endif more += wsize; } if (s->strm->avail_in == 0) break; /* If there was no sliding: * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && * more == window_size - lookahead - strstart * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) * => more >= window_size - 2*WSIZE + 2 * In the BIG_MEM or MMAP case (not yet supported), * window_size == input_size + MIN_LOOKAHEAD && * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. * Otherwise, window_size == 2*WSIZE so more >= 2. * If there was sliding, more >= WSIZE. So in all cases, more >= 2. */ Assert(more >= 2, "more < 2"); n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); s->lookahead += n; /* Initialize the hash value now that we have some input: */ if (s->lookahead + s->insert >= MIN_MATCH) { uInt str = s->strstart - s->insert; s->ins_h = s->window[str]; if (str >= 1) UPDATE_HASH(s, s->ins_h, str + 1 - (MIN_MATCH-1)); #if MIN_MATCH != 3 Call UPDATE_HASH() MIN_MATCH-3 more times #endif while (s->insert) { UPDATE_HASH(s, s->ins_h, str); #ifndef FASTEST s->prev[str & s->w_mask] = s->head[s->ins_h]; #endif s->head[s->ins_h] = (Pos)str; str++; s->insert--; if (s->lookahead + s->insert < MIN_MATCH) break; } } /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, * but this is not important since only literal bytes will be emitted. */ } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); /* If the WIN_INIT bytes after the end of the current data have never been * written, then zero those bytes in order to avoid memory check reports of * the use of uninitialized (or uninitialised as Julian writes) bytes by * the longest match routines. Update the high water mark for the next * time through here. WIN_INIT is set to MAX_MATCH since the longest match * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. */ if (s->high_water < s->window_size) { ulg curr = s->strstart + (ulg)(s->lookahead); ulg init; if (s->high_water < curr) { /* Previous high water mark below current data -- zero WIN_INIT * bytes or up to end of window, whichever is less. */ init = s->window_size - curr; if (init > WIN_INIT) init = WIN_INIT; zmemzero(s->window + curr, (unsigned)init); s->high_water = curr + init; } else if (s->high_water < (ulg)curr + WIN_INIT) { /* High water mark at or above current data, but below current data * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up * to end of window, whichever is less. */ init = (ulg)curr + WIN_INIT - s->high_water; if (init > s->window_size - s->high_water) init = s->window_size - s->high_water; zmemzero(s->window + s->high_water, (unsigned)init); s->high_water += init; } } Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, "not enough room for search"); }
/* copy as much as possible from the sliding window to the output area */ int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r) { uInt n; Bytef *p; Bytef *q; /* local copies of source and destination pointers */ p = z->next_out; q = s->read; /* compute number of bytes to copy as far as end of window */ n = (uInt)((q <= s->write ? s->write : s->end) - q); if (n > z->avail_out) n = z->avail_out; if (n && r == Z_BUF_ERROR) r = Z_OK; /* update counters */ z->avail_out -= n; z->total_out += n; /* update check information */ if (s->checkfn != Z_NULL) z->adler = s->check = (*s->checkfn)(s->check, q, n); /* copy as far as end of window */ zmemcpy(p, q, n); p += n; q += n; /* see if more to copy at beginning of window */ if (q == s->end) { /* wrap pointers */ q = s->window; if (s->write == s->end) s->write = s->window; /* compute bytes to copy */ n = (uInt)(s->write - q); if (n > z->avail_out) n = z->avail_out; if (n && r == Z_BUF_ERROR) r = Z_OK; /* update counters */ z->avail_out -= n; z->total_out += n; /* update check information */ if (s->checkfn != Z_NULL) z->adler = s->check = (*s->checkfn)(s->check, q, n); /* copy */ zmemcpy(p, q, n); p += n; q += n; } /* update pointers */ z->next_out = p; s->read = q; /* done */ return r; }
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // // OPERATION: CreateCommaSeparatedList // // N.B. The user is responsible for calling DeleteCommaSeparatedList // with the handle returned from this call. If not, a memory // leak will occur!!! // // lFlags - 0x00000001 ==> use only selected entities // 0x00000002 ==> use only parent-selected entities // 0x00000004 ==> use semi-colon to separate (rather than comma) // ///////////////////////////////////////////////////////////////////////////// zOPER_EXPORT zLONG OPERATION CreateCommaSeparatedList( zVIEW v, zCPCHAR cpcEntityName, zCPCHAR cpcAttributeName, zCPCHAR cpcContext, zCPCHAR cpcScope, zLONG lFlags ) { zCHAR szParentEntity[ 33 ]; zPCHAR lpMemory; zLONG lEntityCnt; zULONG ulAttributeLth; zLONG lTotalSize; zLONG lLth = 0; zCHAR cSeparator; zSHORT nRC; if ( (lFlags & 0x00000002) ) { MiGetParentEntityNameForView( szParentEntity, v, cpcEntityName ); // if ( szParentEntity[ 0 ] ) // SetCursorFirstEntity( v, szParentEntity, cpcScope ); } if ( (lFlags & 0x00000004) == 0 ) cSeparator = ','; else cSeparator = ';'; lEntityCnt = CountEntitiesForView( v, cpcEntityName ); GetAttributeDisplayLength( &ulAttributeLth, v, cpcEntityName, cpcAttributeName, cpcContext ); lTotalSize = lEntityCnt * (zLONG) ulAttributeLth; // a starting point DrAllocTaskMemory( (zCOREMEM) &lpMemory, lTotalSize + 1 ); // For each entity, append the specified data to the list. // nRC = SetCursorFirstEntity( v, cpcEntityName, cpcScope ); nRC = SetEntityCursor( v, cpcEntityName, 0, zPOS_FIRST, 0, 0, 0, 0, cpcScope, 0 ); while ( nRC > zCURSOR_UNCHANGED ) { if ( (lFlags & 0x00000001) == 0 || ((lFlags & 0x00000001) && GetSelectStateOfEntity( v, cpcEntityName ) != 0) || ((lFlags & 0x00000002) && GetSelectStateOfEntity( v, szParentEntity ) != 0) ) { GetVariableFromAttribute( lpMemory + lLth, 0, zTYPE_STRING, lTotalSize - lLth - 1, v, cpcEntityName, cpcAttributeName, cpcContext, cpcContext && *cpcContext ? 0: zUSE_DEFAULT_CONTEXT ); lLth = zstrlen( lpMemory ); while ( lLth > 0 && lpMemory[ lLth - 1 ] == ' ' ) { lLth--; lpMemory[ lLth ] = 0; } } // nRC = SetCursorNextEntity( v, cpcEntityName, cpcScope ); nRC = SetEntityCursor( v, cpcEntityName, 0, zPOS_NEXT, 0, 0, 0, 0, cpcScope, 0 ); if ( nRC > zCURSOR_UNCHANGED ) { // lLth = zstrlen( lpMemory ); if ( lTotalSize - lLth < (zLONG) ulAttributeLth ) { zPCHAR lpTemp; lEntityCnt *= 2; lTotalSize = lEntityCnt * (zLONG) ulAttributeLth; DrAllocTaskMemory( (zCOREMEM) &lpTemp, lTotalSize + 1 ); zmemcpy( lpTemp, lpMemory, lLth ); DrFreeTaskMemory( lpMemory ); lpMemory = lpTemp; } if ( lLth > 0 && lpMemory[ lLth - 1 ] != cSeparator ) { lpMemory[ lLth++ ] = cSeparator; lpMemory[ lLth ] = 0; } } } return( (zLONG) lpMemory ); }
size_t cread(int fd, void *buf, size_t len) { struct sd *s; unsigned char *start = buf; /* starting point for crc computation */ s = ss[fd]; if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return (-1); if (s->z_err == Z_STREAM_END) return (0); /* EOF */ s->stream.next_out = buf; s->stream.avail_out = len; while (s->stream.avail_out != 0) { if (s->compressed == 0) { /* Copy first the lookahead bytes: */ unsigned int n = s->stream.avail_in; if (n > s->stream.avail_out) n = s->stream.avail_out; if (n > 0) { zmemcpy(s->stream.next_out, s->stream.next_in, n); s->stream.next_out += n; s->stream.next_in += n; s->stream.avail_out -= n; s->stream.avail_in -= n; } if (s->stream.avail_out > 0) { int got; got = read(s->fd, s->stream.next_out, s->stream.avail_out); if (got == -1) return (got); s->stream.avail_out -= got; } return (int)(len - s->stream.avail_out); } if (s->stream.avail_in == 0 && !s->z_eof) { int got; errno = 0; got = read(fd, s->inbuf, Z_BUFSIZE); if (got <= 0) { s->z_eof = 1; if (errno) { s->z_err = Z_ERRNO; break; } } s->stream.avail_in = got; s->stream.next_in = s->inbuf; } s->z_err = inflate(&(s->stream), Z_NO_FLUSH); if (s->z_err == Z_STREAM_END) { /* Check CRC and original size */ s->crc = crc32(s->crc, start, (unsigned int) (s->stream.next_out - start)); start = s->stream.next_out; if (getLong(s) != s->crc || getLong(s) != s->stream.total_out) { s->z_err = Z_DATA_ERROR; } else { /* Check for concatenated .gz files: */ check_header(s); if (s->z_err == Z_OK) { inflateReset(&(s->stream)); s->crc = crc32(0L, Z_NULL, 0); } } } if (s->z_err != Z_OK || s->z_eof) break; } s->crc = crc32(s->crc, start, (unsigned int)(s->stream.next_out - start)); return (int)(len - s->stream.avail_out); }