static void sLogRET ( struct MqS * const context, struct MqBufferS * const dyn, MQ_CST prefix, const MQ_INT level, struct MqBufferS * space ) { MQ_INT retNum; // set binary or string dyn->type = MQ_STRING_TYPE(context->config.isString); // read numItems SEEK (dyn, 0); retNum = (dyn->type==MQ_BINT ? MqBufU2INT(dyn->cur) : str2int(dyn->cur.C,NULL,16)); SEEK (dyn, RET_NumItems_S); dyn->numItems = (dyn->type==MQ_BINT ? MqBufU2INT(dyn->cur) : str2int(dyn->cur.C,NULL,16)); SEEK (dyn, RET_SIZE); // Message if (likely (!context->config.isSilent)) MqLog (stderr, "code<%c> retNum<%i> numItems<" MQ_FORMAT_Z ">\n", pReadGetReturnCode(context), retNum, dyn->numItems); // print item's MqBufferPush (space, " "); sLogDynItem (context, dyn, prefix, level, space); MqBufferPop (space, " "); return; }
wxString ReplayList::GetScriptFromReplay (const wxString& ReplayPath , const int version) const { wxString script; try { wxFile replay( ReplayPath, wxFile::read ); if ( !replay.IsOpened() ) return script; SEEK( 20 ); int headerSize=0 ; replay.Read( &headerSize, 4); const int seek = 64 + (version < 5 ? 0 : 240); SEEK( seek ); wxFileOffset scriptSize=0; replay.Read( &scriptSize, 4); scriptSize = LSL::Util::Clamp( wxFileOffset(scriptSize), wxFileOffset(0), replay.Length() ); SEEK( headerSize ); std::string script_a(scriptSize,0); replay.Read( &script_a[0], scriptSize ); script = TowxString( script_a ) ;//(script_a,scriptSize); } catch (...) { } return script; }
/*\ Return in length the length of the file \*/ int elio_length(Fd_t fd, Off_t *dlength) { off_t length; int status; /* Add up the lengths of any extents */ if (fd->next) { status = elio_length((Fd_t) fd->next, dlength); *dlength += elio_max_file_size(fd); return status; } else { #ifdef PABLO int pablo_code = PABLO_elio_length; PABLO_start( pablo_code ); #endif if ((length = SEEK(fd->fd, (off_t) 0, SEEK_END)) != -1) status = ELIO_OK; else status = SEEKFAIL; #ifdef PABLO PABLO_end(pablo_code); #endif *dlength = (Off_t) length; return status; } }
static VC_CONTAINER_STATUS_T avi_finish_data_chunk( VC_CONTAINER_T *p_ctx, uint32_t chunk_size ) { VC_CONTAINER_STATUS_T status = VC_CONTAINER_SUCCESS; if (chunk_size) { /* Rewrite the chunk size, this won't be efficient if it happens often */ if (STREAM_SEEKABLE(p_ctx)) { SEEK(p_ctx, STREAM_POSITION(p_ctx) - chunk_size - 4); WRITE_U32(p_ctx, chunk_size, "Chunk Size"); SKIP_BYTES(p_ctx, chunk_size); } else { LOG_DEBUG(p_ctx, "warning, can't rewrite chunk size, data will be malformed"); status = VC_CONTAINER_ERROR_FAILED; } } AVI_END_CHUNK(p_ctx); if (status != VC_CONTAINER_SUCCESS) status = STREAM_STATUS(p_ctx); return status; }
/*\ Truncate the file at the specified length. \*/ int elio_truncate(Fd_t fd, Off_t dlength) { off_t length = (off_t) dlength; #ifdef WIN32 # define ftruncate _chsize #endif #ifdef PABLO int pablo_code = PABLO_elio_truncate; PABLO_start( pablo_code ); #endif if(dlength >= elio_max_file_size(fd)){ Fd_t next_fd = elio_get_next_extent(fd); dlength -= elio_max_file_size(fd); # if defined(DEBUG) printf(stderr," calling ftruncate with length = %f \n", dlength); #endif return elio_truncate(next_fd, dlength); } (void) SEEK(fd->fd, 0L, SEEK_SET); if (ftruncate(fd->fd, length)) return TRUNFAIL; else { return ELIO_OK; } #ifdef PABLO PABLO_end(pablo_code); #endif }
int replayVersion( const wxString& ReplayPath ) { wxFile replay( ReplayPath, wxFile::read ); if ( !replay.IsOpened() ) return 0; SEEK( 16 ); int version = 0; replay.Read( &version, 4); return version; }
TraceContainerReader::TraceContainerReader(std::string filename) throw (TraceException) { ifs = fopen(filename.c_str(), "rb"); if (!ifs) { throw (TraceException("Unable to open trace for reading")); } /* Verify the magic number. */ uint64_t magic_number_read; READ(magic_number_read); if (magic_number_read != magic_number) { throw (TraceException("Magic number not found in trace")); } READ(trace_version); if (trace_version > highest_supported_version || trace_version < lowest_supported_version) { throw (TraceException("Unsupported trace version")); } uint64_t archt; READ(archt); arch = (bfd_architecture) archt; READ(mach); /* Read number of trace frames. */ READ(num_frames); /* Find offset of toc. */ uint64_t toc_offset; READ(toc_offset); /* Find the toc. */ SEEK(ifs, toc_offset); /* Read number of frames per toc entry. */ READ(frames_per_toc_entry); /* Read each toc entry. */ for (int i = 0; i < ((num_frames - 1) / frames_per_toc_entry); i++) { uint64_t offset; READ(offset); toc.push_back(offset); } /* We should be at the end of the file now. */ traceoff_t us = TELL(ifs); traceoff_t end = SEEKNAME(ifs, 0, SEEK_END); if (us != TELL(ifs) || end != 0) { throw(TraceException("The table of contents is malformed.")); } /* Seek to the first frame. */ seek(0); }
int main(int ac, char ** av) { if(!av[1]){ fprintf(stderr, "Usage: %s filename\n", av[0]); return 1; } FILE * f = fopen(av[1], "r+b"); struct arch_header ah; READ(ah); for(int i=1;i<(int)(ah.index_size / sizeof(struct arch_section_header));i++){ struct arch_section_header ash; printf("Section %d...", i); fflush(stdout); SEEK(ah.index_offset + i * sizeof(struct arch_section_header)); READ(ash); unsigned long block_off = ash.first_block; for(int j=0;j<(int)ash.n_blocks;j++){ struct arch_section_block asb; SEEK(ah.data_offset + block_off); READ(asb); SEEK(ah.data_offset + block_off + 4); CRC crc; for(int j=0;j<(int)asb.length - 4;j++) crc.add(fgetc(f)); asb.crc = crc.get_value(); SEEK(ah.data_offset + block_off); WRITE(asb); block_off = asb.next_block; } } fclose(f); }
void pLogHDR ( struct MqS * const context, MQ_CST prefix, const MQ_INT level, struct MqBufferS * const buf ) { struct MqBufferS * hd = MqBufferDup (buf); register MQ_STR t; register MQ_STR e; if (likely(context->config.isString == MQ_NO)) { SEEK (hd, HDR_CtxId_S); sprintf (hd->cur.C, MQ_FORMAT_XI (HDR_INT_LEN), MqBufU2INT(hd->cur)); SEEK (hd, HDR_BdySize_S); sprintf (hd->cur.C, MQ_FORMAT_XI (HDR_INT_LEN), MqBufU2INT(hd->cur)); SEEK (hd, HDR_Token_S); } SEEK (hd, HDR_Trans_S); mq_snprintf (hd->cur.C, 4, "%d", hd->cur.A->I); hd->data[HDR_Code_S-1] = BUFFER_CHAR; hd->data[HDR_SIZE] = '\0'; // fix \0 t = (MQ_STR) hd->data; e = (MQ_STR) (hd->data + buf->cursize); while (t < e) { if (!isprint (*t)) *t = (*t == 0 ? '+' : '?'); t++; } MqLogV (context, prefix, level, "HEADER <%s> ...\n", hd->data); MqBufferDelete (&hd); }
void ReplayList::GetHeaderInfo(Replay& rep, const wxString& ReplayPath , const int version) const { try { wxFile replay( ReplayPath, wxFile::read ); const int seek = 72 + (version < 5 ? 0 : 240); SEEK( seek ); int gametime = 0 ; replay.Read( &gametime, 4); rep.duration = gametime; rep.size = replay.Length(); //! \todo don't use long long? (pedantic) wxLongLong_t unixtime = 0; SEEK( 56 ); replay.Read( &unixtime, 8 ); wxDateTime dt; dt.Set( (time_t) unixtime ); // todo: add 2 strings one for date other for time? wxString date_string = dt.FormatISODate()+_T(" ")+dt.FormatISOTime(); rep.date = (time_t) unixtime ; rep.date_string = date_string; } catch (...){ } }
void TraceContainerWriter::finish(void) throw (TraceException) { if (is_finished) { throw (TraceException("finish called twice")); } /* Save the offset where we will write the toc. */ uint64_t toc_offset = TELL(ofs); if (toc_offset == -1) { throw (TraceException("Unable to determine the current offset in the trace")); } /* Make sure the toc is the right size. */ assert ((num_frames == 0) || ((num_frames - 1) / frames_per_toc_entry) == toc.size()); /* Write frames per toc entry. */ WRITE(frames_per_toc_entry); /* Write each offset to the file. */ for (std::vector<uint64_t>::size_type i = 0; i < toc.size(); i++) { WRITE(toc[i]); } /* Now we need to write the magic number, number of trace frames and the offset of field m at the start of the trace. */ /* Magic number. */ SEEK(ofs, magic_number_offset); WRITE(magic_number); /* Trace version. */ SEEK(ofs, trace_version_offset); WRITE(out_trace_version); /* CPU architecture. */ SEEK(ofs, bfd_arch_offset); uint64_t archt = (uint64_t) arch; WRITE(archt); /* Machine type. */ SEEK(ofs, bfd_machine_offset); WRITE(mach); /* Numer of trace frames */ SEEK(ofs, num_trace_frames_offset); WRITE(num_frames); /* Offset of toc. */ SEEK(ofs, toc_offset_offset); WRITE(toc_offset); /* Finally, close the file and mark us as finished. */ if (fclose(ofs)) { throw (TraceException("Unable to close trace file")); } is_finished = true; }
void TraceContainerReader::seek(uint64_t frame_number) throw (TraceException) { /* First, make sure the frame is in range. */ check_end_of_trace_num(frame_number, "seek() to non-existant frame"); /* Find the closest toc entry, if any. */ uint64_t toc_number = frame_number / frames_per_toc_entry; if (toc_number == 0) { current_frame = 0; SEEK(ifs, first_frame_offset); } else { current_frame = toc_number * frames_per_toc_entry; /* Use toc_number - 1 because there is no toc for frames [0,m). */ SEEK(ifs, toc[toc_number - 1]); } while (current_frame != frame_number) { /* Read frame length and skip that far ahead. */ uint64_t frame_len; READ(frame_len); SEEK(ifs, (uint64_t)TELL(ifs) + frame_len); current_frame++; } }
/* ** Read data from a file into a buffer. Return SQLITE_OK if all ** bytes were read successfully and SQLITE_IOERR if anything goes ** wrong. */ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){ int got; assert( id->isOpen ); SimulateIOError(SQLITE_IOERR); TIMER_START; got = read(id->h, pBuf, amt); TIMER_END; TRACE5("READ %-3d %5d %7d %d\n", id->h, got, last_page, TIMER_ELAPSED); SEEK(0); /* if( got<0 ) got = 0; */ if( got==amt ){ return SQLITE_OK; }else{ return SQLITE_IOERR; } }
TraceContainerWriter::TraceContainerWriter(std::string filename, bfd_architecture arch, uint64_t machine, uint64_t frames_per_toc_entry_in, bool auto_finish_in) throw (TraceException) : num_frames (0), frames_per_toc_entry (frames_per_toc_entry_in), arch (arch), mach (machine), auto_finish (auto_finish_in), is_finished (false) { ofs = fopen(filename.c_str(), "wb"); if (!ofs) { throw (TraceException("Unable to open trace file for writing")); } SEEK(ofs, first_frame_offset); }
/* ** Write data from a buffer into a file. Return SQLITE_OK on success ** or some other error code on failure. */ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){ int wrote = 0; assert( id->isOpen ); assert( amt>0 ); SimulateIOError(SQLITE_IOERR); SimulateDiskfullError; TIMER_START; while( amt>0 && (wrote = write(id->h, pBuf, amt))>0 ){ amt -= wrote; pBuf = &((char*)pBuf)[wrote]; } TIMER_END; TRACE5("WRITE %-3d %5d %7d %d\n", id->h, wrote, last_page, TIMER_ELAPSED); SEEK(0); if( amt>0 ){ return SQLITE_FULL; } return SQLITE_OK; }
int elio_set_cb(Fd_t fd, Off_t doffset, int reqn, void *buf, Size_t bytes) { #if defined(AIO) off_t offset = (off_t) doffset; # if defined(CRAY) if(offset != SEEK(fd->fd, offset, SEEK_SET))return (SEEKFAIL); cb_fout_arr[reqn] = cb_fout+reqn; cb_fout[reqn].filedes = fd->fd; # else cb_fout[reqn].aio_offset = offset; cb_fout_arr[reqn] = cb_fout+reqn; cb_fout[reqn].aio_buf = buf; cb_fout[reqn].aio_nbytes = bytes; # if defined(AIX) cb_fout[reqn].aio_whence = SEEK_SET; # else cb_fout[reqn].aio_sigevent.sigev_notify = SIGEV_NONE; cb_fout[reqn].aio_fildes = fd->fd; # endif # endif #endif return ELIO_OK; }
/*\ Blocking Write * - returns number of bytes written or error code (<0) if failed \*/ Size_t elio_write(Fd_t fd, Off_t doffset, const void* buf, Size_t bytes) { off_t offset; Size_t stat, bytes_to_write = bytes; Size_t nextbytes; if (doffset >= ABSURDLY_LARGE) ELIO_ERROR(SEEKFAIL,0); /* Follow the linked list of extents down until we hit the file that contains the offset */ if (doffset >= elio_max_file_size(fd)) { Fd_t next_fd = elio_get_next_extent(fd); if (!next_fd) ELIO_ERROR(OPENFAIL,0); doffset -= elio_max_file_size(fd); return elio_write(next_fd, doffset, buf, bytes); } /* Figure out if the write continues onto the next extent */ offset = (off_t) doffset; nextbytes = 0; if ((doffset+bytes_to_write) >= elio_max_file_size(fd)) { nextbytes = bytes_to_write; bytes_to_write = (Size_t) (elio_max_file_size(fd)-doffset); nextbytes -= bytes_to_write; } /*printf("TRYING TO WRITE AT doffset=%f offset=%lu bw=%lu nb=%lu\n", doffset, offset, bytes_to_write, nextbytes);*/ /* Write to this extent */ #ifdef PABLO int pablo_code = PABLO_elio_write; PABLO_start( pablo_code ); #endif if(offset != SEEK(fd->fd,offset,SEEK_SET)) ELIO_ERROR(SEEKFAIL,0); while (bytes_to_write) { stat = WRITE(fd->fd, buf, bytes_to_write); if ((stat == -1) && ((errno == EINTR) || (errno == EAGAIN))) { ; /* interrupted write should be restarted */ } else if (stat > 0) { bytes_to_write -= stat; buf = stat + (char*)buf; /*advance pointer by # bytes written*/ } else { ELIO_ERROR(WRITFAIL, stat); } } /* Only get here if all has gone OK */ #ifdef PABLO PABLO_end(pablo_code); #endif /* Write to next extent(s) ... relies on incrementing of buf */ if (nextbytes) { Fd_t next_fd = elio_get_next_extent(fd); if (!next_fd) ELIO_ERROR(OPENFAIL,0); stat = elio_write(next_fd, (Off_t) 0, buf, nextbytes); if (stat != nextbytes) ELIO_ERROR(WRITFAIL, stat); } return bytes; }
BOOL ShowBitmapWithTrColorMem( HDC hDC, int xPos, int yPos, char* pFile, COLORREF crTrColor ) { FILE_P fd; BMPINFOHEADER infoHeader; int iBmpWidth, iBmpHeight; int iCliWidth,iCliHeight; int iWinWidth,iWinHeight; int iWidth,iHeight; int x,y; void* pCurPointer; void* pOutPointer; void *pData; RECT rc; if(!(hDC->hWnd)) return false; GetWindowRect(hDC->hWnd,&rc); iWinWidth = rc.right - rc.left + 1; iWinHeight = rc.bottom - rc.top + 1; if(!(hDC->hWnd)) return false; GetWindowRect(hDC->hWnd,&rc); iWinWidth = rc.right - rc.left + 1; iWinHeight = rc.bottom - rc.top + 1; GetClientRect(hDC->hWnd,&rc); iCliWidth = rc.right - rc.left + 1; iCliHeight = rc.bottom - rc.top + 1; if(xPos>=iWinWidth || xPos<0){ printerror("show bitmap out of range."); return false; } if(yPos>=iWinHeight || yPos<0){ printerror("show bitmap out of range."); return false; } fd=OPEN(pFile,RDONLY); if(fd<0){ printerror("open file error!"); return false; } SEEK(fd,0x12,0); READ(fd,&(infoHeader.biWidth),sizeof(infoHeader.biWidth)); READ(fd,&(infoHeader.biHeight),sizeof(infoHeader.biHeight)); SEEK(fd,0x1c,0); READ(fd,&(infoHeader.biBitCount),sizeof(infoHeader.biBitCount)); iBmpWidth=infoHeader.biWidth; iBmpHeight=infoHeader.biHeight; iWidth=min(iBmpWidth,iCliWidth-xPos); iHeight=min(iBmpHeight,iCliHeight-yPos); pData=malloc(iWidth*iHeight*Gal_iBytesDataType); if(!pData){ printerror("alloc memory error!"); return false; } if(!ReadBmpToBuf(fd, iWidth, iHeight, pData)){ free(pData); CLOSE(fd); return false; } for(y=0;y<iHeight;y++){ for(x=0;x<iWidth;x++){ pCurPointer=(acoral_u8*)pData + (y*iWidth+x)*Gal_iBytesDataType; if(*((PCOLORREF)(pCurPointer))!=crTrColor){ pOutPointer=(acoral_u8*)hDC->pData + (y + yPos)*iWinWidth*Gal_iBytesDataType + (x + xPos)*Gal_iBytesDataType; memcpy(pOutPointer,pCurPointer,Gal_iBytesDataType); } } } free(pData); CLOSE(fd); return true; }
/* ( open -- flag ) */ static void macparts_open( macparts_info_t *di ) { char *str = my_args_copy(); char *parstr = NULL, *argstr = NULL; char *tmpstr; int bs, parnum=-1, apple_parnum=-1; int parlist[2], parlist_size = 0; desc_map_t dmap; part_entry_t par; int ret = 0, i = 0, j = 0; int want_bootcode = 0; phandle_t ph; ducell offs = 0, size = -1; DPRINTF("macparts_open '%s'\n", str ); /* Arguments that we accept: id: [0-7] [(id)][,][filespec] */ if ( str && strlen(str) ) { /* Detect the arguments */ if ((*str >= '0' && *str <= '9') || (*str == ',')) { push_str(str); PUSH(','); fword("left-parse-string"); parstr = pop_fstr_copy(); argstr = pop_fstr_copy(); } else { argstr = str; } /* Make sure argstr is not null */ if (argstr == NULL) argstr = strdup(""); /* Convert the id to a partition number */ if (parstr && strlen(parstr)) parnum = atol(parstr); /* Detect if we are looking for the bootcode */ if (strcmp(argstr, "%BOOT") == 0) { want_bootcode = 1; } } DPRINTF("parstr: %s argstr: %s parnum: %d\n", parstr, argstr, parnum); DPRINTF("want_bootcode %d\n", want_bootcode); DPRINTF("macparts_open %d\n", parnum); di->filesystem_ph = 0; di->read_xt = find_parent_method("read"); di->seek_xt = find_parent_method("seek"); SEEK( 0 ); if( READ(&dmap, sizeof(dmap)) != sizeof(dmap) ) goto out; /* partition maps might support multiple block sizes; in this case, * pmPyPartStart is typically given in terms of 512 byte blocks. */ bs = __be16_to_cpu(dmap.sbBlockSize); if( bs != 512 ) { SEEK( 512 ); READ( &par, sizeof(par) ); if( __be16_to_cpu(par.pmSig) == DESC_PART_SIGNATURE ) bs = 512; } SEEK( bs ); if( READ(&par, sizeof(par)) != sizeof(par) ) goto out; if (__be16_to_cpu(par.pmSig) != DESC_PART_SIGNATURE) goto out; /* * Implement partition selection as per the PowerPC Microprocessor CHRP bindings */ if (argstr == NULL || parnum == 0) { /* According to the spec, partition 0 as well as no arguments means the whole disk */ offs = (long long)0; size = (long long)__be32_to_cpu(dmap.sbBlkCount) * bs; di->blocksize = (unsigned int)bs; di->offs_hi = offs >> BITS; di->offs_lo = offs & (ucell) -1; di->size_hi = size >> BITS; di->size_lo = size & (ucell) -1; ret = -1; goto out; } else if (parnum == -1) {
BOOL ShowBitmapMem( HDC hDC, int xPos, int yPos, char* pFile ) { FILE_P fd; BMPINFOHEADER infoHeader; int iBmpWidth, iBmpHeight; int iWinWidth,iWinHeight; int iCliWidth,iCliHeight; int iWidth,iHeight; int iLeftMarge,iTopMarge,iBottom; int y; void* pCurPointer; void* pOutPointer; void *pData; RECT rc; if(!(hDC->hWnd)) return false; GetWindowRect(hDC->hWnd,&rc); iWinWidth = rc.right - rc.left + 1; iWinHeight = rc.bottom - rc.top + 1; GetClientRect(hDC->hWnd,&rc); iCliWidth = rc.right - rc.left + 1; iCliHeight = rc.bottom - rc.top + 1; if(xPos>=iWinWidth || xPos<0){ printerror("show bitmap out of range."); return false; } if(yPos>=iWinHeight || yPos<0){ printerror("show bitmap out of range."); return false; } fd=OPEN(pFile,RDONLY); if(fd<0){ printerror("open file error!"); return false; } SEEK(fd,0x12,0); READ(fd,&(infoHeader.biWidth),sizeof(infoHeader.biWidth)); READ(fd,&(infoHeader.biHeight),sizeof(infoHeader.biHeight)); SEEK(fd,0x1c,0); READ(fd,&(infoHeader.biBitCount),sizeof(infoHeader.biBitCount)); iBmpWidth=infoHeader.biWidth; iBmpHeight=infoHeader.biHeight; iWidth=min(iBmpWidth,iCliWidth-xPos); iHeight=min(iBmpHeight,iCliHeight-yPos); pData=malloc(iWidth*iHeight*Gal_iBytesDataType); if(!pData){ printerror("alloc memory error!"); return false; } if(!ReadBmpToBuf(fd, iWidth, iHeight, pData)){ free(pData); CLOSE(fd); return false; } iBottom=yPos+iHeight-1; iLeftMarge=xPos*Gal_iBytesDataType; iTopMarge=iWinWidth*yPos*Gal_iBytesDataType; pCurPointer=pData; pOutPointer=(acoral_u8*)hDC->pData+iTopMarge+iLeftMarge; for(y=yPos;y<=iBottom;y++){ memcpy(pOutPointer,pCurPointer,iWidth*Gal_iBytesDataType); pOutPointer = (void*)((acoral_u8*)pOutPointer+iWinWidth*Gal_iBytesDataType); pCurPointer= (void*)((acoral_u8*) pCurPointer + iWidth*Gal_iBytesDataType); } free(pData); CLOSE(fd); return true; }
/* ** Move the read/write pointer in a file. */ int sqlite3OsSeek(OsFile *id, i64 offset){ assert( id->isOpen ); SEEK(offset/1024 + 1); lseek(id->h, offset, SEEK_SET); return SQLITE_OK; }
/* ( open -- flag ) */ static void pcparts_open( pcparts_info_t *di ) { char *str = my_args_copy(); char *argstr = strdup(""); char *parstr = strdup(""); int bs, parnum=-1; int found = 0; phandle_t ph; ducell offs, size; /* Layout of PC partition table */ struct pc_partition { unsigned char boot; unsigned char head; unsigned char sector; unsigned char cyl; unsigned char type; unsigned char e_head; unsigned char e_sector; unsigned char e_cyl; u32 start_sect; /* unaligned little endian */ u32 nr_sects; /* ditto */ } *p, *partition; unsigned char buf[512]; DPRINTF("pcparts_open '%s'\n", str ); /* Arguments that we accept: id: [0-7] [(id)][,][filespec] */ if ( strlen(str) ) { /* Detect the arguments */ if ((*str >= '0' && *str <= '7') || (*str == ',')) { push_str(str); PUSH(','); fword("left-parse-string"); parstr = pop_fstr_copy(); argstr = pop_fstr_copy(); } else { argstr = str; } /* Convert the id to a partition number */ if (parstr && strlen(parstr)) parnum = atol(parstr); } /* Make sure argstr is not null */ if (argstr == NULL) argstr = strdup(""); DPRINTF("parstr: %s argstr: %s parnum: %d\n", parstr, argstr, parnum); free(parstr); if( parnum < 0 ) parnum = 0; di->filesystem_ph = 0; di->read_xt = find_parent_method("read"); di->seek_xt = find_parent_method("seek"); SEEK( 0 ); if( READ(buf, 512) != 512 ) RET(0); /* Check Magic */ if (!has_pc_part_magic(buf)) { DPRINTF("pc partition magic not found.\n"); RET(0); } /* Actual partition data */ partition = (struct pc_partition *) (buf + 0x1be); /* Make sure we use a copy accessible from an aligned pointer (some archs e.g. SPARC will crash otherwise) */ p = malloc(sizeof(struct pc_partition)); bs = 512; if (parnum < 4) { /* primary partition */ partition += parnum; memcpy(p, partition, sizeof(struct pc_partition)); if (p->type == 0 || is_pc_extended_part(p->type)) { DPRINTF("partition %d does not exist\n", parnum+1 ); RET( 0 ); } offs = (long long)(__le32_to_cpu(p->start_sect)) * bs; di->offs_hi = offs >> BITS; di->offs_lo = offs & (ucell) -1; size = (long long)(__le32_to_cpu(p->nr_sects)) * bs; di->size_hi = size >> BITS; di->size_lo = size & (ucell) -1; DPRINTF("Primary partition at sector %x\n", __le32_to_cpu(p->start_sect)); /* If PReP boot partition, exit immediately with no filesystem probe */ if (p->type == 0x41) { RET(-1); } found = 1; } else {
/*\ Blocking Read * - returns number of bytes read or error code (<0) if failed \*/ Size_t elio_read(Fd_t fd, Off_t doffset, void* buf, Size_t bytes) { off_t offset; Size_t stat, bytes_to_read = bytes; Size_t nextbytes; int attempt=0; if (doffset >= ABSURDLY_LARGE) ELIO_ERROR(SEEKFAIL,0); /* Follow the linked list of extents down until we hit the file that contains the offset */ if (doffset >= elio_max_file_size(fd)) { Fd_t next_fd = elio_get_next_extent(fd); if (!next_fd) ELIO_ERROR(OPENFAIL,0); doffset -= elio_max_file_size(fd); return elio_read(next_fd, doffset, buf, bytes); } /* Figure out if the read continues onto the next extent */ offset = (off_t) doffset; nextbytes = 0; if ((doffset+bytes_to_read) >= elio_max_file_size(fd)) { nextbytes = bytes_to_read; bytes_to_read = (Size_t) (elio_max_file_size(fd)-doffset); nextbytes -= bytes_to_read; } /* Read from this physical file */ #ifdef PABLO int pablo_code = PABLO_elio_read; PABLO_start( pablo_code ); #endif if(offset != SEEK(fd->fd,offset,SEEK_SET)) ELIO_ERROR(SEEKFAIL,0); while (bytes_to_read) { stat = READ(fd->fd, buf, bytes_to_read); if(stat==0){ ELIO_ERROR(EOFFAIL, stat); } else if ((stat == -1) && ((errno == EINTR) || (errno == EAGAIN))) { ; /* interrupted read should be restarted */ } else if (stat > 0) { bytes_to_read -= stat; buf = stat + (char*)buf; /*advance pointer by # bytes read*/ } else { ELIO_ERROR(READFAIL, stat); } attempt++; } /* Only get here if all went OK */ #ifdef PABLO PABLO_end(pablo_code); #endif /* Read from next extent(s) ... relies on incrementing of buf */ if (nextbytes) { Fd_t next_fd = elio_get_next_extent(fd); if (!next_fd) ELIO_ERROR(OPENFAIL,0); stat = elio_read(next_fd, (Off_t) 0, buf, nextbytes); if (stat != nextbytes) ELIO_ERROR(READFAIL, stat); } return bytes; }
void ZFXModel::ReadFile() { ZFXCOLOR cA, cD, cE, cS; UINT i, nNumFaces, nNumTris = 0; float fPower = 0; char Line[80]; char Texture[80]; TRI *pTris = NULL; // READ SKINS SEEK(Line, "BEGIN_SKINS"); NEXT(Line); sscanf(Line, "%d;", &m_nSkinNum); m_pSkin = new UINT[m_nSkinNum]; for (i = 0; i < m_nSkinNum; i++) { NEXT(Line); NEXT(Line);// skip opening brag sscanf(Line, "%f, %f, %f, %f;", &cA.fR, &cA.fG, &cA.fB, &cA.fA); NEXT(Line); sscanf(Line, "%f,%f,%f,%f;", &cD.fR, &cD.fG, &cD.fB, &cD.fA); NEXT(Line); sscanf(Line, "%f,%f,%f,%f;", &cE.fR, &cE.fG, &cE.fB, &cE.fA); NEXT(Line); sscanf(Line, "%f,%f,%f,%f,%f;", &cS.fR, &cS.fG, &cS.fB, &cS.fA, &fPower); NEXT(Line); sscanf(Line, "%s", &Texture); // add skin to skin-manager m_pRenderDevice->GetSkinManager()->AddSkin(&cA, &cD, &cE, &cS, fPower, &m_pSkin[i]); m_pRenderDevice->GetSkinManager()->AddTexture(m_pSkin[i], Texture, false, 0, NULL, 0); NEXT(Line); // skip closing brag } // READ VERTICES rewind(m_pFile); SEEK(Line, "BEGIN_VERTICES"); NEXT(Line); sscanf(Line, "%d;", &m_nVertexNum); m_pVertex = new VERTEX[m_nVertexNum]; m_pVertex3T = new VERTEX3T[m_nVertexNum]; for (i = 0; i < m_nVertexNum; i++) { NEXT(Line); sscanf(Line, "%f,%f,%f,%f,%f;", &m_pVertex[i].x, &m_pVertex[i].y, &m_pVertex[i].z, &m_pVertex[i].tu, &m_pVertex[i].tv); memset(&m_pVertex3T[i], 0, sizeof(VERTEX3T)); m_pVertex3T[i].x = m_pVertex[i].x; m_pVertex3T[i].y = m_pVertex[i].y; m_pVertex3T[i].z = m_pVertex[i].z; m_pVertex3T[i].tu0 = m_pVertex[i].tu; m_pVertex3T[i].tv0 = m_pVertex[i].tv; } // READ FACES (n-sided polys) TO COUNT TRIS NEEDED rewind(m_pFile); SEEK(Line, "BEGIN_FACES"); NEXT(Line); sscanf(Line, "%d;", &nNumFaces); pTris = new TRI[nNumFaces]; for (i = 0; i < nNumFaces; i++) { NEXT(Line); sscanf(Line, "%d,%d,%d;%d", &pTris[nNumTris].i0, &pTris[nNumTris].i1, &pTris[nNumTris].i2, &pTris[nNumTris].nMat); nNumTris++; } // sort tris by material qsort((void*)pTris, nNumTris, sizeof(TRI), (CMPFUNC)SortTris); // COUNT INDICES FOR EACH MATERIAL UINT nOldMat = pTris[0].nMat; m_pCount = new UINT[m_nSkinNum]; m_pBufferID = new UINT[m_nSkinNum]; m_pBufferID3T = new UINT[m_nSkinNum]; memset(m_pCount, 0, sizeof(UINT)*m_nSkinNum); memset(m_pBufferID, 0, sizeof(UINT)*m_nSkinNum); memset(m_pBufferID3T, 0, sizeof(UINT)*m_nSkinNum); m_pIndex = new WORD[nNumTris * 3]; m_nIndexNum = nNumFaces * 3; for (i = 0; i < nNumTris; i++) { // copy indices in indexlist m_pIndex[i * 3] = pTris[i].i0; m_pIndex[i * 3 + 1] = pTris[i].i1; m_pIndex[i * 3 + 2] = pTris[i].i2; // count indices per material if (pTris[i].nMat != nOldMat) nOldMat = pTris[i].nMat; else m_pCount[pTris[i].nMat] += 3; } WORD *pIndices = m_pIndex; for (i = 0; i < m_nSkinNum; pIndices += m_pCount[i], i++) { if (FAILED(m_pRenderDevice->GetVertexManager()->CreateStaticBuffer( VID_UU, m_pSkin[i], m_nVertexNum, m_pCount[i], m_pVertex, m_pIndex, &m_pBufferID[i]))) Log("CREATE STATIC FAILED\n"); if (FAILED(m_pRenderDevice->GetVertexManager()->CreateStaticBuffer( VID_3T, m_pSkin[i], m_nVertexNum, m_pCount[i], m_pVertex3T, m_pIndex, &m_pBufferID3T[i]))) Log("CREATE STATIC 3T FAILED\n"); } delete[] pTris; }
BOOL ShowBitmapWithTrColorWin( HDC hDC, int xPos, int yPos, char* pFile, COLORREF crTrColor ) { PClipRect pClipRect; FILE_P fd; BMPINFOHEADER infoHeader; void* pData; RECT rcSource,rcDest; int iWinWidth, iWinHeight; int iBmpWidth, iBmpHeight; int iWidth,iHeight; GetWindowRect(hDC->hWnd,&rcSource); WindowToScreen(hDC->hWnd,&xPos,&yPos); if(xPos>rcSource.right || xPos<rcSource.left) return false; if(yPos>rcSource.bottom || yPos<rcSource.top) return false; iWinWidth =rcSource.right-xPos+1; iWinHeight =rcSource.bottom-yPos+1; fd=OPEN(pFile,RDONLY); if(fd<0) return false; SEEK(fd,0x12,0); READ(fd,&(infoHeader.biWidth),sizeof(infoHeader.biWidth)); READ(fd,&(infoHeader.biHeight),sizeof(infoHeader.biHeight)); SEEK(fd,0x1c,0); READ(fd,&(infoHeader.biBitCount),sizeof(infoHeader.biBitCount)); iBmpWidth =infoHeader.biWidth; iBmpHeight =infoHeader.biHeight; iWidth=min(iBmpWidth,iWinWidth); iHeight=min(iBmpHeight,iWinHeight); pData=malloc(iWidth*iHeight*Gal_iBytesDataType); if(!pData){ CLOSE(fd); return false; } SetRect(&rcSource,xPos,yPos,xPos+iWidth-1,yPos+iHeight-1); if(!ReadBmpToBuf(fd, iWidth, iHeight, pData)){ free(pData); CLOSE(fd); return false; } pClipRect=((PWindowsTree)(hDC->hWnd))->pClipRgn->pHead; while(pClipRect){ if(IntersectRect(&rcDest,&rcSource,&(pClipRect->rect))) Gal_PutRectWithTrCor(&rcDest,&rcSource,pData,crTrColor); pClipRect=pClipRect->pNext; } free(pData); CLOSE(fd); return true; }
kal_int32 _gif_sw_draw_internal( kal_int32 ox, kal_int32 oy, kal_bool is_resized, kal_int32 resized_width, kal_int32 resized_height, kal_uint8 *src, kal_uint32 size, kal_uint32 cache_id, kal_uint16 frame_number, kal_bool use_disposal_method, kal_bool transparent_enable, GIF_COLOR_FORMAT_ENUM gif_color_format, GIF_COLOR_FORMAT_ENUM palette_format) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ kal_int8 gif_done; kal_int32 frame_counter = 0; kal_uint16 transparent_index = 256; kal_uint16 temp_width, temp_height; kal_int32 n; kal_int16 lcd_idx; kal_int8 gif_is_hit_cache = 0; gif_sw_image_struct *cache; //kal_uint32 start, end; //kal_uint32 start_after_decode, end_after_decode; //start = drv_get_current_time(); //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_draw_internal(): Enter.\n"); /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ INIT_SRC(src, size); // try to hit the cache and initialize the cache item { kal_int32 offset; /* If the frame_counter<frame_number, gif will decode from frame_counter to frame_number. */ if (gif_sw_gif_hit_cache(cache_id, ox,oy, KAL_FALSE, frame_number, &lcd_idx, &frame_counter, &offset, KAL_TRUE)) { gif_is_hit_cache = 1; SEEK(offset); } cache = &g_gif_sw_cache[lcd_idx]; //pcurrent_match_gif_sw_cache = cache; } g_gif_sw_palette_size = 0; // ///////////////////////////////////////////////////////// // read the GIF file signature if (frame_counter == 0) { kal_uint32 header; kal_uint32 bg_color_idx = 0; header = _get_data(FSAL_ACCESS_U24, pfsal_handle); //GET_U24(header); if (header != 0x464947) /* 'GIF' */ { return GIF_SW_RET_FAILED; } /////////////////////////////////////////////////////////// // read the GIF dimension FLUSH(3); temp_width = _get_data(FSAL_ACCESS_U16, pfsal_handle); //GET_U16(temp_width); temp_height = _get_data(FSAL_ACCESS_U16, pfsal_handle); //GET_U16(temp_height); cache->image_width = temp_width; cache->image_height = temp_height; /* * Check the validity of clipping */ if (ox > g_gif_sw_dest_clipx2 || oy > g_gif_sw_dest_clipy2 || ox + temp_width - 1 < g_gif_sw_dest_clipx1 || oy + temp_height - 1 < g_gif_sw_dest_clipy1) { return GIF_SW_RET_SUCCEED; } /* ///////////////////////////////////////////////////////// */ /* * Read the global color palette */ n = _get_data(FSAL_ACCESS_U8, pfsal_handle); //GET_U8(n); bg_color_idx = _get_data(FSAL_ACCESS_U8, pfsal_handle); FLUSH(1); cache->has_gct = ((n & 0x80) > 0) ? 1 : 0; if (cache->has_gct) { kal_int32 i; gif_sw_color_from_rgb_func palette_color_from_rgb; n = 1 << ((n & 0x7) + 1); if (gif_color_format == GIF_SW_COLOR_FORMAT_8) { #if defined(GIF_SUPPORT_SET_PALETTE_FORMAT) palette_color_from_rgb = gif_sw_color_from_rgb_array[palette_format]; #else palette_color_from_rgb = GIF_SW_PALETTE_COLOR_FROM_RGB; #endif } else { palette_color_from_rgb = g_gif_sw_act_color_from_rgb; } /* Read the global color palette */ if (n) { g_gif_sw_palette_size = n; } for (i = 0; i < n; i++) { kal_uint8 R, G, B; R = _get_data(FSAL_ACCESS_U8, pfsal_handle); G = _get_data(FSAL_ACCESS_U8, pfsal_handle); B = _get_data(FSAL_ACCESS_U8, pfsal_handle); cache->palette[i] = palette_color_from_rgb(0xFF, R, G, B); if ((g_gif_sw_dest_source_key_enable && cache->palette[i] == g_gif_sw_dest_source_key) || (g_gif_sw_decoder_is_bypass_color && cache->palette[i] == g_gif_sw_decoder_bypass_color)) { cache->palette[i] ^= 1; } } /* current layer is index color layer */ if (gif_color_format == GIF_SW_COLOR_FORMAT_8) { for (i = 0; i < (kal_int32) n; i++) { if(g_gif_sw_layer_set_palette) (*g_gif_sw_layer_set_palette)((kal_uint8) i, cache->palette[i]); { cache->palette[i] = i; } } } } //_gif_sw_set_background_color((gif_sw_color) cache->palette[bg_color_idx]); //MAUI_03107299 g_gif_sw_cache[lcd_idx].original_background = g_gif_sw_background_color; } /* If resized width > original width or resized height > original height, do not resize */ if (!is_resized || resized_width > cache->image_width || resized_height > cache->image_height) { resized_width = cache->image_width; resized_height = cache->image_height; } /* don't process resized_width/resized_height == 0*/ if (resized_width == 0 || resized_height == 0) { return (GIF_SW_RET_SUCCEED); } /* first draw , we should keep 1 pixels background color for later used. */ if (!gif_is_hit_cache) { ////MAUI_03107299 //g_gif_sw_cache[lcd_idx].original_background = g_gif_sw_background_color; { kal_int32 x1; kal_int32 y1; x1 = ox; y1 = oy; if (x1 < g_gif_sw_dest_clipx1) { x1 = g_gif_sw_dest_clipx1; } if (y1 < g_gif_sw_dest_clipy1) { y1 = g_gif_sw_dest_clipy1; } /* If using disposal, alloc a memory to save the origianl background. */ /* If memory is not enougn, use the 1 pixel background color to redraw the background. */ /* Currently, only support "restore to background", not support "restore to previous". */ if (g_gif_sw_using_disposal) { g_gif_sw_cache[lcd_idx].disposal_bg_buf_size = (resized_width * resized_height * DRV_MAINLCD_BIT_PER_PIXEL) >> 3; g_gif_sw_cache[lcd_idx].disposal_bg_buf = (kal_uint8 *)g_gif_malloc(g_gif_sw_cache[lcd_idx].disposal_bg_buf_size); //SW_GIF_TRACE(MOD_MMI, "[gif_hal_dbg] - _gif_sw_draw_internal() g_gif_sw_using_disposal=KAL_TRUE \n"); if (g_gif_sw_cache[lcd_idx].disposal_bg_buf) { gif_sw_rect_struct dest_clip; dest_clip.x1 = 0; dest_clip.y1 = 0; dest_clip.x2 = resized_width - 1; dest_clip.y2 = resized_height - 1; /* copy the content of original background */ if(g_gif_sw_bitblt) { (*g_gif_sw_bitblt)( g_gif_sw_dest_buf_ptr, //dst g_gif_sw_dest_buf_width, x1, y1, resized_width, resized_height, cache->disposal_bg_buf, //src resized_width, 0, 0, dest_clip, DRV_MAINLCD_BIT_PER_PIXEL); //SW_GIF_TRACE(MOD_MMI, "[gif_hal_dbg] - _gif_sw_draw_internal() g_gif_sw_bitblt=KAL_TRUE \n"); } } } }
OFFT CPPF::FileSize(FILE* f) { SEEK(f,0,SEEK_END); return(FTELL(f)); }