void StringCopyBuilder::BuildStringUT(WEBC_CHAR *pStringBuffer) { #if (WEBC_SUPPORT_UNICODE) if (mpStr8) { const char *copyFrom = mpStr8; WEBC_CHAR tempStr[32]; int charsLeft = GetStringLength(), toCopy; while (charsLeft > 0) { toCopy = EBSMIN(31, charsLeft); webc_c_strncpy(tempStr, copyFrom, toCopy); tc_movebytes(pStringBuffer, tempStr, toCopy*sizeof(WEBC_CHAR)); pStringBuffer += toCopy; copyFrom += toCopy; charsLeft -= toCopy; } } else { tc_movebytes(pStringBuffer, mpStr, GetStringLength()*sizeof(WEBC_CHAR)); } #else tc_movebytes(pStringBuffer, mpStr, GetStringLength()*sizeof(WEBC_CHAR)); #endif }
int wcache_add_entry ( struct wcache_ctx *cc, const char * key, void* vdata, long len, WEBC_UINT8 append, int dataType, RTP_TIMESTAMP* date, RTP_TIMESTAMP* expires ) { struct wcache_stream wcs[1]; int result; if (append) { result = wcache_open(cc, key, wcs, WEBC_CO_APPEND); } else { result = wcache_open(cc, key, wcs, WEBC_CO_CREATE); if (result >= 0) { wcs->entry->dataType = dataType; if (!date) { rtp_date_get_timestamp(wcs->entry->date); } if (!expires) { rtp_date_get_timestamp(wcs->entry->expires); } } } if (result >= 0) { if (date) { tc_movebytes((WEBC_PFBYTE)wcs->entry->date, (WEBC_PFBYTE)date, sizeof(RTP_TIMESTAMP)); } if (expires) { tc_movebytes((WEBC_PFBYTE)wcs->entry->expires, (WEBC_PFBYTE)expires, sizeof(RTP_TIMESTAMP)); } result = (wcache_write(wcs, (WEBC_PFBYTE) vdata, len) == len)? 0 : -1; wcache_close(wcs); } return (result); }
char *webc_CreateVFile (const char *pName, int iMimeType, long lSize, WEBC_PFBYTE pData, WEBC_UINT16 wFlags, VFileDeleteFn Destructor) { #if (WEBC_SUPPORT_INTERNAL) int n; char unique_name[20]; if (!pName) { tc_strcpy(unique_name, "\xffvfile"); tc_itoa(_nextUniqueNum, &unique_name[tc_strlen(unique_name)], 10); pName = unique_name; _nextUniqueNum++; } for (n=0; n<NUM_VFILE_ENTRIES; n++) { if (!gWebcVFileTable[n].pName) { gWebcVFileTable[n].pName = webc_malloc_string_copy_8(pName, __FILE__, __LINE__); gWebcVFileTable[n].iMimeType = (WebcFileContentType) iMimeType; gWebcVFileTable[n].lSize = lSize; if (wFlags & WEBC_VFILE_COPY) { gWebcVFileTable[n].pData = (WEBC_PFBYTE) WEBC_MALLOC(lSize); if (!gWebcVFileTable[n].pData) { gWebcVFileTable[n].lSize = 0; } else { tc_movebytes(gWebcVFileTable[n].pData, pData, lSize); } } else { gWebcVFileTable[n].pData = pData; } gWebcVFileTable[n].wFlags = wFlags | WEBC_VFILE_CREATED; gWebcVFileTable[n].Destroy = Destructor; return (gWebcVFileTable[n].pName); } } #endif return 0; }
/* in the system to ks_malloc() */ void display_malloc(void) { int i; tc_memset(debug_malloc_totals_info, 0, sizeof(debug_malloc_totals_info)); tc_memset(debug_malloc_max_info, 0, sizeof(debug_malloc_max_info)); DEBUG_ERROR("\nMALLOC INFORMATION", NOVAR, 0, 0); DEBUG_ERROR("----------------", NOVAR, 0, 0); for (i=0; i < CFG_DEBUG_MALLOC_SIZE; i++) { if (debug_malloc_info[i].addr != (void *)0) { /* calculate 'total usage' too for 'who' */ int idx = debug_malloc_info[i].who - CONFIG_WHO_BASE_MALLOC; if (idx < 0 || idx >= sizeof(debug_malloc_totals_info)/sizeof(debug_malloc_totals_info[0])) { idx = 0; } debug_malloc_totals_info[idx] += debug_malloc_info[i].size; DEBUG_ERROR("MALLOC addr, who: ", DINT2, debug_malloc_info[i].addr, idx); DEBUG_ERROR(" size, num_elements:", EBS_INT2, debug_malloc_info[i].size, debug_malloc_info[i].num_ele); } } tc_movebytes(debug_malloc_max_info, debug_malloc_totals_info, sizeof(debug_malloc_max_info)); DEBUG_ERROR("--- TOTALS (NON-ZERO ONLY) ----", NOVAR, 0, 0); for (i=0; i < sizeof(debug_malloc_totals_info)/sizeof(debug_malloc_totals_info[0]); i++) { if (debug_malloc_totals_info[i] != 0) { DEBUG_ERROR("MALLOC TOTAL who, size: ", DINT2, i, debug_malloc_totals_info[i]); } } }
long wload_WebcRead(UrlStreamCtx *pStream, char * buffer, long length) { #if (WEBC_SUPPORT_INTERNAL) long vfsize; WEBC_PFBYTE vfbuf; struct WebcVFileEntry *FileTable = (struct WebcVFileEntry *) pStream->stream.webc.vfileTable; vfsize = FileTable[pStream->stream.webc.vfile].lSize; vfbuf = &FileTable[pStream->stream.webc.vfile].pData[pStream->stream.webc.pos]; length = EBSMIN(vfsize - pStream->stream.webc.pos, length); tc_movebytes(buffer, vfbuf, length); pStream->stream.webc.pos += length; return (length); #else return (-1); #endif }
int AggregateStringBuilder::Add(StringBuilder *pPart, int toDelete) { if (!pPart) { return (-1); } if (!mpParts) { if (toDelete) { WEBC_DELETE(pPart); } return (-1); } if (miNumParts + 1 > miPartsSize) { // Our parts array is too small; re-alloc it StringBuilderInfo *pNewParts = (StringBuilderInfo *) WEBC_MALLOC(sizeof(StringBuilderInfo) * (miPartsSize + 5)); if (pNewParts) { tc_movebytes((WEBC_PFBYTE) pNewParts, (WEBC_PFBYTE) mpParts, sizeof(StringBuilderInfo) * miNumParts); WEBC_FREE(mpParts); mpParts = pNewParts; miPartsSize += 5; } else { return (-1); } } mpParts[miNumParts].pBuilder = pPart; mpParts[miNumParts].toDelete = toDelete; miNumParts++; miStringLength += pPart->GetStringLength(); return (0); }
int pcvid_scroll_up(void) { int line,n; PFBYTE pto; PFBYTE pfr; pcvid_init_term(0); pto = pvideo; pfr = pvideo+160; for(line=0; line < 24; line++) { tc_movebytes(pto,pfr,160); pto += 160; pfr += 160; } for(n=0; n < 80; n++) { *pto++=' '; *pto++=0x0f; } return(0); }
int wcache_write(struct wcache_stream *wcs, WEBC_PFBYTE buf, long len) { #if (WEBC_SUPPORT_CACHE_COMPRESSION) if (wcs->entry->flags & WEBC_CACHE_ENTRY_COMPRESSED) { z_streamp pz = (z_streamp) wcs->pZlibStream; long bytes_to_zip = len; long bytes_written = 0; int result, val; while (bytes_to_zip > 0) { pz->avail_in = EBSMIN(bytes_to_zip, wcs->inBufferSize); pz->next_in = wcs->pInBuffer; bytes_to_zip -= pz->avail_in; tc_movebytes(wcs->pInBuffer, buf, pz->avail_in); buf += pz->avail_in; do { result = deflate(pz, Z_SYNC_FLUSH); if (result < 0) { // error! return (-1); } if (pz->avail_out == 0) { if (wcs->outBufferSize > (wcs->cc->bytesMax - wcs->cc->bytesUsed)) { // won't fit; try to free up some space if (_wcache_free_bytes(wcs->cc, wcs->outBufferSize) == 0) { return (-1); } } val = wcs->cc->spec.sys_write(wcs->cc->sysPtr, wcs->fp, wcs->pOutBuffer, wcs->outBufferSize); if (val < 0) { return (val); } wcs->cc->bytesUsed += val; bytes_written += val; pz->avail_out = wcs->outBufferSize; pz->next_out = wcs->pOutBuffer; } else { break; } } while (1); } wcs->entry->size += bytes_written; return (len); } else #endif // WEBC_SUPPORT_CACHE_COMPRESSION { #if (WEBC_CACHE_MAX_FILE_SIZE) len = EBSMIN(len, WEBC_CACHE_MAX_FILE_SIZE - wcs->entry->size); if (len <= 0) { return (0); } #endif if (len > (wcs->cc->bytesMax - wcs->cc->bytesUsed)) { // won't fit; try to free up some space if (_wcache_free_bytes(wcs->cc, len) == 0) { return (-1); } } len = wcs->cc->spec.sys_write(wcs->cc->sysPtr, wcs->fp, buf, len); dump_write_cache_info("write", buf, len); if (len >= 0) { wcs->entry->size += len; wcs->cc->bytesUsed += len; } return (len); } }
int wcache_read(struct wcache_stream *wcs, WEBC_PFBYTE buf, long len) { #if (WEBC_SUPPORT_CACHE_COMPRESSION) if (wcs->entry->flags & WEBC_CACHE_ENTRY_COMPRESSED) { z_streamp pz = wcs->pZlibStream; long bytes_to_read = len, to_copy, bytes_read = 0; int result; while (bytes_to_read > 0) { // fill up our output buffer with inflated data (note - this will probably slow // down some operations that grab small amounts of data, but will likely speed up the // inflation process on the whole) if (wcs->outBufferPos == wcs->outBufferAvail) { wcs->outBufferPos = 0; wcs->outBufferAvail = 0; pz->next_out = wcs->pOutBuffer; pz->avail_out = wcs->outBufferSize; while (pz->avail_out > 0) { if (pz->avail_in == 0) { pz->avail_in = webc_fread (wcs->fp, wcs->pInBuffer, wcs->inBufferSize); pz->next_in = wcs->pInBuffer; } if (pz->avail_in == 0) { break; } result = inflate(pz, Z_SYNC_FLUSH); if (result < 0) { // error! return (-1); } wcs->outBufferAvail = (wcs->outBufferSize - pz->avail_out); } } // any inflated data waiting in the buffer? if (wcs->outBufferAvail > wcs->outBufferPos) { to_copy = EBSMIN(bytes_to_read, wcs->outBufferAvail - wcs->outBufferPos); tc_movebytes(buf, &wcs->pOutBuffer[wcs->outBufferPos], to_copy); buf += to_copy; wcs->outBufferPos += to_copy; bytes_to_read -= to_copy; bytes_read += to_copy; } else { break; } } return (bytes_read); } else #endif // WEBC_SUPPORT_CACHE_COMPRESSION { int l; l = wcs->cc->spec.sys_read(wcs->cc->sysPtr, wcs->fp, buf, len); dump_read_cache_info("read", buf, l); return(l); } }
void wcache_set_expires(struct wcache_stream *wcs, RTP_TIMESTAMP* pExpDate) { tc_movebytes(wcs->entry->expires, pExpDate, sizeof(RTP_TIMESTAMP)); }
void wcache_set_date(struct wcache_stream *wcs, RTP_TIMESTAMP* pDate) { tc_movebytes(wcs->entry->date, pDate, sizeof(RTP_TIMESTAMP)); }
void DecimalStringBuilder::BuildStringUT(WEBC_CHAR *pStringBuffer) { tc_movebytes(pStringBuffer, mpStr, GetStringLength()*sizeof(WEBC_CHAR)); }