int EpsilonDataset::ScanBlocks(int* pnBands)
{
    int bRet = FALSE;

    int nExpectedX = 0;
    int nExpectedY = 0;

    int nTileW = -1;
    int nTileH = -1;

    *pnBands = 0;

    bRegularTiling = TRUE;

    eps_block_header hdr;
    while(TRUE)
    {
        Seek(nStartBlockFileOff + nBlockDataSize);

        if (!GetNextBlockData())
        {
            break;
        }

        /* Ignore rasterlite wavelet header */
        int nRasterliteWaveletHeaderLen = strlen(RASTERLITE_WAVELET_HEADER);
        if (nBlockDataSize >= nRasterliteWaveletHeaderLen &&
                memcmp(pabyBlockData, RASTERLITE_WAVELET_HEADER,
                       nRasterliteWaveletHeaderLen) == 0)
        {
            continue;
        }

        /* Stop at rasterlite wavelet footer */
        int nRasterlineWaveletFooterLen = strlen(RASTERLITE_WAVELET_FOOTER);
        if (nBlockDataSize >= nRasterlineWaveletFooterLen &&
                memcmp(pabyBlockData, RASTERLITE_WAVELET_FOOTER,
                       nRasterlineWaveletFooterLen) == 0)
        {
            break;
        }

        if (eps_read_block_header (pabyBlockData,
                                   nBlockDataSize, &hdr) != EPS_OK)
        {
            CPLError(CE_Warning, CPLE_AppDefined, "cannot read block header");
            continue;
        }

        if (hdr.chk_flag == EPS_BAD_CRC ||
                hdr.crc_flag == EPS_BAD_CRC)
        {
            CPLError(CE_Warning, CPLE_AppDefined, "bad CRC");
            continue;
        }

        int W = GET_FIELD(hdr, W);
        int H = GET_FIELD(hdr, H);
        int x = GET_FIELD(hdr, x);
        int y = GET_FIELD(hdr, y);
        int w = GET_FIELD(hdr, w);
        int h = GET_FIELD(hdr, h);

        //CPLDebug("EPSILON", "W=%d,H=%d,x=%d,y=%d,w=%d,h=%d,offset=" CPL_FRMT_GUIB,
        //                    W, H, x, y, w, h, nStartBlockFileOff);

        int nNewBands = (hdr.block_type == EPS_GRAYSCALE_BLOCK) ? 1 : 3;
        if (nRasterXSize == 0)
        {
            if (W <= 0 || H <= 0)
            {
                break;
            }

            bRet = TRUE;
            nRasterXSize = W;
            nRasterYSize = H;
            *pnBands = nNewBands;
        }

        if (nRasterXSize != W || nRasterYSize != H || *pnBands != nNewBands ||
                x < 0 || y < 0 || x + w > W || y + h > H)
        {
            CPLError(CE_Failure, CPLE_AppDefined, "Bad block characteristics");
            bRet = FALSE;
            break;
        }

        nBlocks++;
        pasBlocks = (BlockDesc*)VSIRealloc(pasBlocks, sizeof(BlockDesc) * nBlocks);
        pasBlocks[nBlocks-1].x = x;
        pasBlocks[nBlocks-1].y = y;
        pasBlocks[nBlocks-1].w = w;
        pasBlocks[nBlocks-1].h = h;
        pasBlocks[nBlocks-1].offset = nStartBlockFileOff;

        if (bRegularTiling)
        {
            if (nTileW < 0)
            {
                nTileW = w;
                nTileH = h;
            }

            if (w > nTileW || h > nTileH)
                bRegularTiling = FALSE;

            if (x != nExpectedX)
                bRegularTiling = FALSE;

            if (y != nExpectedY || nTileH != h)
            {
                if (y + h != H)
                    bRegularTiling = FALSE;
            }

            if (nTileW != w)
            {
                if (x + w != W)
                    bRegularTiling = FALSE;
                else
                {
                    nExpectedX = 0;
                    nExpectedY += nTileW;
                }
            }
            else
                nExpectedX += nTileW;

            //if (!bRegularTiling)
            //    CPLDebug("EPSILON", "not regular tiling!");
        }
    }

    return bRet;
}
Exemplo n.º 2
0
Arquivo: vdr.c Projeto: Flameeyes/vlc
/*****************************************************************************
 * Control input stream
 *****************************************************************************/
static int Control( access_t *p_access, int i_query, va_list args )
{
    access_sys_t *p_sys = p_access->p_sys;
    input_title_t ***ppp_title;
    int i;
    int64_t *pi64;
    vlc_meta_t *p_meta;

    switch( i_query )
    {
        case ACCESS_CAN_SEEK:
        case ACCESS_CAN_FASTSEEK:
        case ACCESS_CAN_PAUSE:
        case ACCESS_CAN_CONTROL_PACE:
            *va_arg( args, bool* ) = true;
            break;

        case ACCESS_GET_PTS_DELAY:
            pi64 = va_arg( args, int64_t * );
            *pi64 = INT64_C(1000)
                  * var_InheritInteger( p_access, "file-caching" );
            break;

        case ACCESS_SET_PAUSE_STATE:
            /* nothing to do */
            break;

        case ACCESS_GET_TITLE_INFO:
            /* return a copy of our seek points */
            if( !p_sys->p_marks )
                return VLC_EGENERIC;
            ppp_title = va_arg( args, input_title_t*** );
            *va_arg( args, int* ) = 1;
            *ppp_title = malloc( sizeof( input_title_t** ) );
            if( !*ppp_title )
                return VLC_ENOMEM;
            **ppp_title = vlc_input_title_Duplicate( p_sys->p_marks );
            break;

        case ACCESS_SET_TITLE:
            /* ignore - only one title */
            break;

        case ACCESS_SET_SEEKPOINT:
            i = va_arg( args, int );
            /* Seek updates p_access->info */
            return Seek( p_access, p_sys->p_marks->seekpoint[i]->i_byte_offset );

        case ACCESS_GET_META:
            if( !p_sys->p_meta )
                return VLC_EGENERIC;
            p_meta = va_arg( args, vlc_meta_t* );
            vlc_meta_Merge( p_meta, p_sys->p_meta );
            break;

        case ACCESS_SET_PRIVATE_ID_STATE:
        case ACCESS_GET_CONTENT_TYPE:
            return VLC_EGENERIC;

        default:
            msg_Warn( p_access, "unimplemented query in control" );
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
}
Exemplo n.º 3
0
/// Move the file pointer relative to the end of the file
///
/// @param offset - Number of bytes to seek
///
u64 YCFile::SeekEnd(s64 offset)
{
	return Seek(-offset, end);
}
Exemplo n.º 4
0
/**
  Read or Write a number of blocks in the same cylinder.
 
  @param  FdcDev      A pointer to FDC_BLK_IO_DEV
  @param  HostAddress device address 
  @param  Lba         The starting logic block address to read from on the device
  @param  NumberOfBlocks The number of block wanted to be read or write
  @param  Read        Operation type: read or write
  
  @retval EFI_SUCCESS Success operate

**/
EFI_STATUS
ReadWriteDataSector (
  IN  FDC_BLK_IO_DEV  *FdcDev,
  IN  VOID            *HostAddress,
  IN  EFI_LBA         Lba,
  IN  UINTN           NumberOfBlocks,
  IN  BOOLEAN         Read
  )
{
  EFI_STATUS                                    Status;
  FDD_COMMAND_PACKET1                           Command;
  FDD_RESULT_PACKET                             Result;
  UINTN                                         Index;
  UINTN                                         Times;
  UINT8                                         *CommandPointer;

  EFI_PHYSICAL_ADDRESS                          DeviceAddress;
  EFI_ISA_IO_PROTOCOL                           *IsaIo;
  UINTN                                         NumberofBytes;
  VOID                                          *Mapping;
  EFI_ISA_IO_PROTOCOL_OPERATION                 Operation;
  EFI_STATUS                                    Status1;
  UINT8                                         Channel;
  EFI_ISA_ACPI_RESOURCE                         *ResourceItem;
  UINT32                                        Attribute;

  Status = Seek (FdcDev, Lba);
  if (EFI_ERROR (Status)) {
    return EFI_DEVICE_ERROR;
  }
  //
  // Map Dma
  //
  IsaIo         = FdcDev->IsaIo;
  NumberofBytes = NumberOfBlocks * 512;
  if (Read == READ) {
    Operation = EfiIsaIoOperationSlaveWrite;
  } else {
    Operation = EfiIsaIoOperationSlaveRead;
  }

  ResourceItem  = IsaIo->ResourceList->ResourceItem;
  Index         = 0;
  while (ResourceItem[Index].Type != EfiIsaAcpiResourceEndOfList) {
    if (ResourceItem[Index].Type == EfiIsaAcpiResourceDma) {
      break;
    }

    Index++;
  }

  if (ResourceItem[Index].Type == EfiIsaAcpiResourceEndOfList) {
    return EFI_DEVICE_ERROR;
  }

  Channel   = (UINT8) IsaIo->ResourceList->ResourceItem[Index].StartRange;
  Attribute = IsaIo->ResourceList->ResourceItem[Index].Attribute;

  Status1 = IsaIo->Map (
                    IsaIo,
                    Operation,
                    Channel,
                    Attribute,
                    HostAddress,
                    &NumberofBytes,
                    &DeviceAddress,
                    &Mapping
                    );
  if (EFI_ERROR (Status1)) {
    return Status1;
  }

  //
  // Allocate Read or Write command packet
  //
  ZeroMem (&Command, sizeof (FDD_COMMAND_PACKET1));
  if (Read == READ) {
    Command.CommandCode = READ_DATA_CMD | CMD_MT | CMD_MFM | CMD_SK;
  } else {
    Command.CommandCode = WRITE_DATA_CMD | CMD_MT | CMD_MFM;
  }

  FillPara (FdcDev, Lba, &Command);

  //
  // Write command bytes to FDC
  //
  CommandPointer = (UINT8 *) (&Command);
  for (Index = 0; Index < sizeof (FDD_COMMAND_PACKET1); Index++) {
    if (EFI_ERROR (DataOutByte (FdcDev, CommandPointer++))) {
      return EFI_DEVICE_ERROR;
    }
  }
  //
  // wait for some time
  //
  Times = (STALL_1_SECOND / 50) + 1;
  do {
    if ((FdcReadPort (FdcDev, FDC_REGISTER_MSR) & 0xc0) == 0xc0) {
      break;
    }

    MicroSecondDelay (50);
    Times = Times - 1;
  } while (Times > 0);

  if (Times == 0) {
    return EFI_TIMEOUT;
  }
  //
  // Read result bytes from FDC
  //
  CommandPointer = (UINT8 *) (&Result);
  for (Index = 0; Index < sizeof (FDD_RESULT_PACKET); Index++) {
    if (EFI_ERROR (DataInByte (FdcDev, CommandPointer++))) {
      return EFI_DEVICE_ERROR;
    }
  }
  //
  // Flush before Unmap
  //
  if (Read == READ) {
    Status1 = IsaIo->Flush (IsaIo);
    if (EFI_ERROR (Status1)) {
      return Status1;
    }
  }
  //
  // Unmap Dma
  //
  Status1 = IsaIo->Unmap (IsaIo, Mapping);
  if (EFI_ERROR (Status1)) {
    return Status1;
  }

  return CheckResult (&Result, FdcDev);
}
Exemplo n.º 5
0
/**
This is not called in bulk_extractor
*/
void File::Write(const void *Data,size_t Size)
{ //This is not called in bulk_extractor 
  if (Size==0)
    return;
#ifndef _WIN_CE
  if (HandleType!=FILE_HANDLENORMAL)
    switch(HandleType)
    {
      case FILE_HANDLESTD:
#ifdef _WIN_ALL
        hFile=GetStdHandle(STD_OUTPUT_HANDLE);
#else
        hFile=stdout;
#endif
        break;
      case FILE_HANDLEERR:
#ifdef _WIN_ALL
        hFile=GetStdHandle(STD_ERROR_HANDLE);
#else
        hFile=stderr;
#endif
        break;
    }
#endif
  while (1)
  {
    bool Success=false;
#ifdef _WIN_ALL
    DWORD Written=0;
    if (HandleType!=FILE_HANDLENORMAL)
    {
      // writing to stdout can fail in old Windows if data block is too large
      const size_t MaxSize=0x4000;
      for (size_t I=0;I<Size;I+=MaxSize)
      {
        Success=WriteFile(hFile,(byte *)Data+I,(DWORD)Min(Size-I,MaxSize),&Written,NULL)==TRUE; //Writing happens here
        if (!Success)
          break;
      }
    }
    else
      Success=WriteFile(hFile,Data,(DWORD)Size,&Written,NULL)==TRUE;
#else
    int Written=fwrite(Data,1,Size,hFile);
    Success=Written==Size && !ferror(hFile);
#endif
    if (!Success && AllowExceptions && HandleType==FILE_HANDLENORMAL)
    {
#if defined(_WIN_ALL) && !defined(SFX_MODULE) && !defined(RARDLL)
      int ErrCode=GetLastError();
      int64 FilePos=Tell();
      uint64 FreeSize=GetFreeDisk(FileName);
      SetLastError(ErrCode);
      if (FreeSize>Size && FilePos-Size<=0xffffffff && FilePos+Size>0xffffffff)
        ErrHandler.WriteErrorFAT(FileName,FileNameW);
#endif
      if (ErrHandler.AskRepeatWrite(FileName,FileNameW,false))
      {
#ifndef _WIN_ALL
        clearerr(hFile);
#endif
        if (Written<Size && Written>0)
          Seek(Tell()-Written,SEEK_SET);
        continue;
      }
      ErrHandler.WriteError(NULL,NULL,FileName,FileNameW);
    }
    break;
  }
  LastWrite=true;
}
Exemplo n.º 6
0
void CFFMPEGLoader::Seek(const UINT &iSec, const uint64_t &iFrame, const bool &bExact, const int &dst_pix_fmt ) {
    int64_t seek_target=0;


    for(UINT i=0; i<iPKTVideoLength; i++) {
        if(pktLastVideo[i].data) {
            av_free_packet(&pktLastVideo[i]);
            pktLastVideo[i].data=NULL;
        }
    }
    iPKTVideoLength = 0;

    bLock=true;
    for(UINT i=0; i<iPKTAudioLength; i++) {
        if(pktLastAudio[i].data) {
            av_free_packet(&pktLastAudio[i]);
            pktLastAudio[i].data=NULL;
        }
    }
    iPKTAudioLength = 0;
    bLock=false;

    AVRational temp;
    temp.num=1;
    temp.den=AV_TIME_BASE;

    /*	seek_target = av_rescale_q(iFrame+iSec*pFormatCon->streams[videoStream]->time_base.den, temp,
                      pFormatCon->streams[videoStream]->time_base);

    av_seek_frame( pFormatCon, -1, seek_target, AVSEEK_FLAG_BACKWARD );
    pVCodecCon->hurry_up = 1;
    int gotFrame;
    AVPacket Packet;
    uint64_t MyPts=0;
    do {
        av_read_frame( pFormatCon, &Packet );
        // should really be checking that this is a video packet
        MyPts=av_rescale( Packet.pts,
            AV_TIME_BASE * (int64_t) pFormatCon->streams[videoStream]->time_base.num,
            pFormatCon->streams[videoStream]->time_base.den );
        // Once we pass the target point, break from the loop
        if( MyPts >= seek_target )
            break;
        avcodec_decode_video( pVCodecCon, pFrame, &gotFrame, Packet.data,
            Packet.size );
        av_free_packet( &Packet );
    } while(1);
    pVCodecCon->hurry_up = 0;*/
    if(pVCodecCon) {
        int64_t si_st = iFrame+iSec*GetFPS();//)*pVCodecCon->time_base.den; //av_rescale_q( (iFrame+iSec*pFormatCon->streams[videoStream]->time_base.den), temp,
        //pFormatCon->streams[videoStream]->time_base);
        //seek_target=av_rescale( iFrame+iSec*pVCodecCon->time_base.den,
        //    AV_TIME_BASE * (int64_t) pFormatCon->streams[videoStream]->time_base.num,
        //    pFormatCon->streams[videoStream]->time_base.den );
        seek_target= si_st;//av_rescale_q(iSec*AV_TIME_BASE+iFrame*AV_TIME_BASE/GetFPS(), temp,
        //pFormatCon->streams[videoStream]->time_base);

        int gotFrame;
        bool bIFrame=false;
        //AVPacket Packet;
        //uint64_t MyPts=0;
        //av_read_frame( pFormatCon, &Packet );
        //MyPts=av_rescale_q( Packet.pts, temp,
        //        pFormatCon->streams[videoStream]->time_base );
        //MyPts=av_rescale( Packet.dts,
        //          AV_TIME_BASE * (int64_t) pFormatCon->streams[videoStream]->time_base.num,
//            pFormatCon->streams[videoStream]->time_base.den );

        //if(Packet.dts > si_st|| (MyPts<seek_target-20*pFormatCon->streams[videoStream]->time_base.den&&seek_target>=20*pFormatCon->streams[videoStream]->time_base.den) ) {
        if(av_seek_frame(pFormatCon, videoStream,
                         seek_target, AVSEEK_FLAG_BACKWARD) < 0)
            cout<<"error while seeking\n";

        //}
        //pVCodecCon->hurry_up = 1;
        do {

            UINT w=0,h=0;
            if(dst_pix_fmt==-1) {
                while( ReadVideoData(NULL,&w,&h)==0 )
                    if(LoadFrame()<0) return;
            }
            else {
                unsigned char *buf;
                while( ReadVideoData(&buf,&w,&h,dst_pix_fmt,&buf)==0 )
                    if(LoadFrame()<0) return;
            }

            /*if(iPKTAudioLength>0){
            	if(pktLastAudio[0].data)
            		av_free_packet(&pktLastAudio[0]);

            	iPKTAudioLength--;
            	for(UINT i=0; i<iPKTAudioLength;i++)
            		pktLastAudio[i]=pktLastAudio[i+1];
            	pktLastAudio[iPKTAudioLength].data=NULL;
            }*/
            static unsigned char buffer[4096];
            ReadAudioData(buffer,4096);

            if( pktLastVideo[0].dts >= seek_target ) {
                if(!bIFrame&&bExact&&iSec!=0) {
                    Seek(iSec-2,iFrame,false,dst_pix_fmt);
                    bIFrame=true;
//				cout<<"SHIT";
                    //if(iSec!=0)
                    ;//Seek(iSec>1?iSec-1:0);
                }
                else
                    break;
            }
            //avcodec_decode_video( pVCodecCon, pFrame, &gotFrame, Packet.data,
            //   Packet.size );
            int pt=0;
            if(dst_pix_fmt==-1)
                pt=pFrame->pict_type;
            else
                pt=pFrameRGB->pict_type;
            if(pt==FF_I_TYPE) {
                if(!bExact) break;
                bIFrame=true;
            }


        } while(1);
        //pVCodecCon->hurry_up = 0;
        //if(av_seek_frame(pFormatCon, audioStream,
        //                seek_target, 0) < 0)
        //		cout<<"error while seeking\n";
    }
    /*if(pACodecCon) {
    	seek_target = av_rescale_q(iFrame+iSec*pFormatCon->streams[audioStream]->time_base.den, temp,
    		pFormatCon->streams[audioStream]->time_base);
    	if(av_seek_frame(pFormatCon, audioStream,
                    seek_target, 0) < 0)
    		cout<<"error while seeking\n";
    }*/
}
Exemplo n.º 7
0
long HFSInitPartition(CICell ih)
{
	u_int64_t extentSize;
	void *extent;
	u_int32_t extentFile;
	u_int16_t nodeSize;

	if (ih == gCurrentIH)
	{
#ifdef __i386__
		CacheInit(ih, gCacheBlockSize);
#endif
	return 0;
	}

#ifdef __i386__
	if (!gTempStr)
	{
		gTempStr = (char *)malloc(4096);
	}

	if (!gLinkTemp)
	{
		gLinkTemp = (char *)malloc(64);
	}

	if (!gBTreeHeaderBuffer)
	{
		gBTreeHeaderBuffer = (char *)malloc(512);
	}

	if (!gHFSMdbVib)
	{
		gHFSMdbVib = (char *)malloc(kBlockSize);
		gHFSMDB = (HFSMasterDirectoryBlock *)gHFSMdbVib;
	}

	if (!gHFSPlusHeader)
	{
		gHFSPlusHeader = (char *)malloc(kBlockSize);
		gHFSPlus = (HFSPlusVolumeHeader *)gHFSPlusHeader;
	}

	if (!gTempStr || !gLinkTemp || !gBTreeHeaderBuffer || !gHFSMdbVib || !gHFSPlusHeader)
	{
		return -1;
	}
#endif /* __i386__ */

	gAllocationOffset = 0;
	gIsHFSPlus = 0;
	gCaseSensitive = 0;
	gBTHeaders[0] = 0;
	gBTHeaders[1] = 0;

	// Look for the HFS MDB
	Seek(ih, kMDBBaseOffset);
	Read(ih, (long)gHFSMdbVib, kBlockSize);

	if (SWAP_BE16(gHFSMDB->drSigWord) == kHFSSigWord)
	{
		gAllocationOffset = SWAP_BE16(gHFSMDB->drAlBlSt) * kBlockSize;

		// See if it is HFSPlus
		if (SWAP_BE16(gHFSMDB->drEmbedSigWord) != kHFSPlusSigWord)
		{
			// Normal HFS;
			gCacheBlockSize = gBlockSize = SWAP_BE32(gHFSMDB->drAlBlkSiz);
			CacheInit(ih, gCacheBlockSize);
			gCurrentIH = ih;

			// grab the 64 bit volume ID
			bcopy(&gHFSMDB->drFndrInfo[6], &gVolID, 8);

			// Get the Catalog BTree node size.
			extent     = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;
			extentSize = SWAP_BE32(gHFSMDB->drCTFlSize);
			extentFile = kHFSCatalogFileID;
			ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + kBTreeCatalog * 256, 0);

			nodeSize = SWAP_BE16(((BTHeaderRec *)(gBTreeHeaderBuffer + kBTreeCatalog * 256 + sizeof(BTNodeDescriptor)))->nodeSize);

			// If the BTree node size is larger than the block size, reset the cache.
			if (nodeSize > gBlockSize)
			{
				gCacheBlockSize = nodeSize;
				CacheInit(ih, gCacheBlockSize);
			}

		return 0;
		}

		// Calculate the offset to the embeded HFSPlus volume.
		gAllocationOffset += (long long)SWAP_BE16(gHFSMDB->drEmbedExtent.startBlock) *
                                        SWAP_BE32(gHFSMDB->drAlBlkSiz);
	}

	// Look for the HFSPlus Header
	Seek(ih, gAllocationOffset + kMDBBaseOffset);
	Read(ih, (long)gHFSPlusHeader, kBlockSize);

	// Not a HFS+ or HFSX volume.
	if (SWAP_BE16(gHFSPlus->signature) != kHFSPlusSigWord && SWAP_BE16(gHFSPlus->signature) != kHFSXSigWord)
	{
		verbose("HFS signature was not present.\n");
		gCurrentIH = 0;
		return -1;
	}

	gIsHFSPlus = 1;
	gCacheBlockSize = gBlockSize = SWAP_BE32(gHFSPlus->blockSize);
	CacheInit(ih, gCacheBlockSize);
	gCurrentIH = ih;

	ih->modTime = SWAP_BE32(gHFSPlus->modifyDate) - 2082844800;

	// grab the 64 bit volume ID
	bcopy(&gHFSPlus->finderInfo[24], &gVolID, 8);

	// Get the Catalog BTree node size.
	extent     = &gHFSPlus->catalogFile.extents;
	extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize);
	extentFile = kHFSCatalogFileID;

	ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + kBTreeCatalog * 256, 0);

	nodeSize = SWAP_BE16(((BTHeaderRec *)(gBTreeHeaderBuffer + kBTreeCatalog * 256 + sizeof(BTNodeDescriptor)))->nodeSize);

	// If the BTree node size is larger than the block size, reset the cache.
	if (nodeSize > gBlockSize)
	{
		gCacheBlockSize = nodeSize;
		CacheInit(ih, gCacheBlockSize);
	}

	return 0;
}
Exemplo n.º 8
0
static int look(Scanner * s) {
  int state;
  int c = 0;

  state = 0;
  Clear(s->text);
  s->start_line = s->line;
  Setfile(s->text, Getfile(s->str));
  while (1) {
    switch (state) {
    case 0:
      if ((c = nextchar(s)) == 0)
	return (0);

      /* Process delimiters */

      if (c == '\n') {
	return SWIG_TOKEN_ENDLINE;
      } else if (!isspace(c)) {
	retract(s, 1);
	state = 1000;
	Clear(s->text);
	Setline(s->text, s->line);
	Setfile(s->text, Getfile(s->str));
      }
      break;

    case 1000:
      if ((c = nextchar(s)) == 0)
	return (0);
      if (c == '%')
	state = 4;		/* Possibly a SWIG directive */

      /* Look for possible identifiers */

      else if ((isalpha(c)) || (c == '_') ||
	       (s->idstart && strchr(s->idstart, c)))
	state = 7;

      /* Look for single character symbols */

      else if (c == '(')
	return SWIG_TOKEN_LPAREN;
      else if (c == ')')
	return SWIG_TOKEN_RPAREN;
      else if (c == ';')
	return SWIG_TOKEN_SEMI;
      else if (c == ',')
	return SWIG_TOKEN_COMMA;
      else if (c == '*')
	state = 220;
      else if (c == '}')
	return SWIG_TOKEN_RBRACE;
      else if (c == '{')
	return SWIG_TOKEN_LBRACE;
      else if (c == '=')
	state = 33;
      else if (c == '+')
	state = 200;
      else if (c == '-')
	state = 210;
      else if (c == '&')
	state = 31;
      else if (c == '|')
	state = 32;
      else if (c == '^')
	state = 230;
      else if (c == '<')
	state = 60;
      else if (c == '>')
	state = 61;
      else if (c == '~')
	return SWIG_TOKEN_NOT;
      else if (c == '!')
	state = 3;
      else if (c == '\\')
	return SWIG_TOKEN_BACKSLASH;
      else if (c == '[')
	return SWIG_TOKEN_LBRACKET;
      else if (c == ']')
	return SWIG_TOKEN_RBRACKET;
      else if (c == '@')
	return SWIG_TOKEN_AT;
      else if (c == '$')
	state = 75;
      else if (c == '#')
	return SWIG_TOKEN_POUND;
      else if (c == '?')
	return SWIG_TOKEN_QUESTION;

      /* Look for multi-character sequences */

      else if (c == '/') {
	state = 1;		/* Comment (maybe)  */
	s->start_line = s->line;
      }
      else if (c == '\"') {
	state = 2;		/* Possibly a string */
	s->start_line = s->line;
	Clear(s->text);
      }

      else if (c == ':')
	state = 5;		/* maybe double colon */
      else if (c == '0')
	state = 83;		/* An octal or hex value */
      else if (c == '\'') {
	s->start_line = s->line;
	Clear(s->text);
	state = 9;		/* A character constant */
      } else if (c == '`') {
	s->start_line = s->line;
	Clear(s->text);
	state = 900;
      }

      else if (c == '.')
	state = 100;		/* Maybe a number, maybe just a period */
      else if (isdigit(c))
	state = 8;		/* A numerical value */
      else
	state = 99;		/* An error */
      break;

    case 1:			/*  Comment block */
      if ((c = nextchar(s)) == 0)
	return (0);
      if (c == '/') {
	state = 10;		/* C++ style comment */
	Clear(s->text);
	Setline(s->text, Getline(s->str));
	Setfile(s->text, Getfile(s->str));
	Append(s->text, "//");
      } else if (c == '*') {
	state = 11;		/* C style comment */
	Clear(s->text);
	Setline(s->text, Getline(s->str));
	Setfile(s->text, Getfile(s->str));
	Append(s->text, "/*");
      } else if (c == '=') {
	return SWIG_TOKEN_DIVEQUAL;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_SLASH;
      }
      break;
    case 10:			/* C++ style comment */
      if ((c = nextchar(s)) == 0) {
	Swig_error(cparse_file, cparse_start_line, "Unterminated comment\n");
	return SWIG_TOKEN_ERROR;
      }
      if (c == '\n') {
	retract(s,1);
	return SWIG_TOKEN_COMMENT;
      } else {
	state = 10;
      }
      break;
    case 11:			/* C style comment block */
      if ((c = nextchar(s)) == 0) {
	Swig_error(cparse_file, cparse_start_line, "Unterminated comment\n");
	return SWIG_TOKEN_ERROR;
      }
      if (c == '*') {
	state = 12;
      } else {
	state = 11;
      }
      break;
    case 12:			/* Still in C style comment */
      if ((c = nextchar(s)) == 0) {
	Swig_error(cparse_file, cparse_start_line, "Unterminated comment\n");
	return SWIG_TOKEN_ERROR;
      }
      if (c == '*') {
	state = 12;
      } else if (c == '/') {
	return SWIG_TOKEN_COMMENT;
      } else {
	state = 11;
      }
      break;

    case 2:			/* Processing a string */
      if ((c = nextchar(s)) == 0) {
	Swig_error(cparse_file, cparse_start_line, "Unterminated string\n");
	return SWIG_TOKEN_ERROR;
      }
      if (c == '\"') {
	Delitem(s->text, DOH_END);
	return SWIG_TOKEN_STRING;
      } else if (c == '\\') {
	Delitem(s->text, DOH_END);
	get_escape(s);
      } else
	state = 2;
      break;

    case 3:			/* Maybe a not equals */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_LNOT;
      else if (c == '=')
	return SWIG_TOKEN_NOTEQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_LNOT;
      }
      break;

    case 31:			/* AND or Logical AND or ANDEQUAL */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_AND;
      else if (c == '&')
	return SWIG_TOKEN_LAND;
      else if (c == '=')
	return SWIG_TOKEN_ANDEQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_AND;
      }
      break;

    case 32:			/* OR or Logical OR */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_OR;
      else if (c == '|')
	return SWIG_TOKEN_LOR;
      else if (c == '=')
	return SWIG_TOKEN_OREQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_OR;
      }
      break;

    case 33:			/* EQUAL or EQUALTO */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_EQUAL;
      else if (c == '=')
	return SWIG_TOKEN_EQUALTO;
      else {
	retract(s, 1);
	return SWIG_TOKEN_EQUAL;
      }
      break;

    case 4:			/* A wrapper generator directive (maybe) */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_PERCENT;
      if (c == '{') {
	state = 40;		/* Include block */
	Clear(s->text);
	Setline(s->text, Getline(s->str));
	Setfile(s->text, Getfile(s->str));
	s->start_line = s->line;
      } else if (s->idstart && strchr(s->idstart, '%') &&
	         ((isalpha(c)) || (c == '_'))) {
	state = 7;
      } else if (c == '=') {
	return SWIG_TOKEN_MODEQUAL;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_PERCENT;
      }
      break;

    case 40:			/* Process an include block */
      if ((c = nextchar(s)) == 0) {
	Swig_error(cparse_file, cparse_start_line, "Unterminated block\n");
	return SWIG_TOKEN_ERROR;
      }
      if (c == '%')
	state = 41;
      break;
    case 41:			/* Still processing include block */
      if ((c = nextchar(s)) == 0) {
	set_error(s,s->start_line,"Unterminated code block");
	return 0;
      }
      if (c == '}') {
	Delitem(s->text, DOH_END);
	Delitem(s->text, DOH_END);
	Seek(s->text,0,SEEK_SET);
	return SWIG_TOKEN_CODEBLOCK;
      } else {
	state = 40;
      }
      break;

    case 5:			/* Maybe a double colon */

      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_COLON;
      if (c == ':')
	state = 50;
      else {
	retract(s, 1);
	return SWIG_TOKEN_COLON;
      }
      break;

    case 50:			/* DCOLON, DCOLONSTAR */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_DCOLON;
      else if (c == '*')
	return SWIG_TOKEN_DCOLONSTAR;
      else {
	retract(s, 1);
	return SWIG_TOKEN_DCOLON;
      }
      break;

    case 60:			/* shift operators */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_LESSTHAN;
      if (c == '<')
	state = 240;
      else if (c == '=')
	return SWIG_TOKEN_LTEQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_LESSTHAN;
      }
      break;
    case 61:
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_GREATERTHAN;
      if (c == '>')
	state = 250;
      else if (c == '=')
	return SWIG_TOKEN_GTEQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_GREATERTHAN;
      }
      break;
    case 7:			/* Identifier */
      if ((c = nextchar(s)) == 0)
	state = 71;
      else if (isalnum(c) || (c == '_') || (c == '$')) {
	state = 7;
      } else {
	retract(s, 1);
	state = 71;
      }
      break;

    case 71:			/* Identifier or true/false */
      if (cparse_cplusplus) {
	if (Strcmp(s->text, "true") == 0)
	  return SWIG_TOKEN_BOOL;
	else if (Strcmp(s->text, "false") == 0)
	  return SWIG_TOKEN_BOOL;
	}
      return SWIG_TOKEN_ID;
      break;

    case 75:			/* Special identifier $ */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_DOLLAR;
      if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) {
	state = 7;
      } else {
	retract(s,1);
	if (Len(s->text) == 1) return SWIG_TOKEN_DOLLAR;
	state = 71;
      }
      break;

    case 8:			/* A numerical digit */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_INT;
      if (c == '.') {
	state = 81;
      } else if ((c == 'e') || (c == 'E')) {
	state = 82;
      } else if ((c == 'f') || (c == 'F')) {
	Delitem(s->text, DOH_END);
	return SWIG_TOKEN_FLOAT;
      } else if (isdigit(c)) {
	state = 8;
      } else if ((c == 'l') || (c == 'L')) {
	state = 87;
      } else if ((c == 'u') || (c == 'U')) {
	state = 88;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_INT;
      }
      break;
    case 81:			/* A floating pointer number of some sort */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_DOUBLE;
      if (isdigit(c))
	state = 81;
      else if ((c == 'e') || (c == 'E'))
	state = 820;
      else if ((c == 'f') || (c == 'F')) {
	Delitem(s->text, DOH_END);
	return SWIG_TOKEN_FLOAT;
      } else if ((c == 'l') || (c == 'L')) {
	Delitem(s->text, DOH_END);
	return SWIG_TOKEN_DOUBLE;
      } else {
	retract(s, 1);
	return (SWIG_TOKEN_DOUBLE);
      }
      break;
    case 82:
      if ((c = nextchar(s)) == 0) {
	retract(s, 1);
	return SWIG_TOKEN_INT;
      }
      if ((isdigit(c)) || (c == '-') || (c == '+'))
	state = 86;
      else {
	retract(s, 2);
	return (SWIG_TOKEN_INT);
      }
      break;
    case 820:
      /* Like case 82, but we've seen a decimal point. */
      if ((c = nextchar(s)) == 0) {
	retract(s, 1);
	return SWIG_TOKEN_DOUBLE;
      }
      if ((isdigit(c)) || (c == '-') || (c == '+'))
	state = 86;
      else {
	retract(s, 2);
	return (SWIG_TOKEN_DOUBLE);
      }
      break;
    case 83:
      /* Might be a hexadecimal or octal number */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_INT;
      if (isdigit(c))
	state = 84;
      else if ((c == 'x') || (c == 'X'))
	state = 85;
      else if (c == '.')
	state = 81;
      else if ((c == 'l') || (c == 'L')) {
	state = 87;
      } else if ((c == 'u') || (c == 'U')) {
	state = 88;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_INT;
      }
      break;
    case 84:
      /* This is an octal number */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_INT;
      if (isdigit(c))
	state = 84;
      else if ((c == 'l') || (c == 'L')) {
	state = 87;
      } else if ((c == 'u') || (c == 'U')) {
	state = 88;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_INT;
      }
      break;
    case 85:
      /* This is an hex number */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_INT;
      if (isxdigit(c))
	state = 85;
      else if ((c == 'l') || (c == 'L')) {
	state = 87;
      } else if ((c == 'u') || (c == 'U')) {
	state = 88;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_INT;
      }
      break;

    case 86:
      /* Rest of floating point number */

      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_DOUBLE;
      if (isdigit(c))
	state = 86;
      else if ((c == 'f') || (c == 'F')) {
	Delitem(s->text, DOH_END);
	return SWIG_TOKEN_FLOAT;
      } else if ((c == 'l') || (c == 'L')) {
	Delitem(s->text, DOH_END);
	return SWIG_TOKEN_DOUBLE;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_DOUBLE;
      }
      break;

    case 87:
      /* A long integer of some sort */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_LONG;
      if ((c == 'u') || (c == 'U')) {
	return SWIG_TOKEN_ULONG;
      } else if ((c == 'l') || (c == 'L')) {
	state = 870;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_LONG;
      }
      break;

      /* A long long integer */

    case 870:
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_LONGLONG;
      if ((c == 'u') || (c == 'U')) {
	return SWIG_TOKEN_ULONGLONG;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_LONGLONG;
      }

      /* An unsigned number */
    case 88:

      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_UINT;
      if ((c == 'l') || (c == 'L')) {
	state = 880;
      } else {
	retract(s, 1);
	return SWIG_TOKEN_UINT;
      }
      break;

      /* Possibly an unsigned long long or unsigned long */
    case 880:
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_ULONG;
      if ((c == 'l') || (c == 'L'))
	return SWIG_TOKEN_ULONGLONG;
      else {
	retract(s, 1);
	return SWIG_TOKEN_ULONG;
      }

      /* A character constant */
    case 9:
      if ((c = nextchar(s)) == 0) {
	Swig_error(cparse_file, cparse_start_line, "Unterminated character constant\n");
	return SWIG_TOKEN_ERROR;
      }
      if (c == '\'') {
	Delitem(s->text, DOH_END);
	return (SWIG_TOKEN_CHAR);
      } else if (c == '\\') {
	Delitem(s->text, DOH_END);
	get_escape(s);
      }
      break;

      /* A period or maybe a floating point number */

    case 100:
      if ((c = nextchar(s)) == 0)
	return (0);
      if (isdigit(c))
	state = 81;
      else {
	retract(s, 1);
	return SWIG_TOKEN_PERIOD;
      }
      break;

    case 200:			/* PLUS, PLUSPLUS, PLUSEQUAL */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_PLUS;
      else if (c == '+')
	return SWIG_TOKEN_PLUSPLUS;
      else if (c == '=')
	return SWIG_TOKEN_PLUSEQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_PLUS;
      }
      break;

    case 210:			/* MINUS, MINUSMINUS, MINUSEQUAL, ARROW */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_MINUS;
      else if (c == '-')
	return SWIG_TOKEN_MINUSMINUS;
      else if (c == '=')
	return SWIG_TOKEN_MINUSEQUAL;
      else if (c == '>')
	state = 211;
      else {
	retract(s, 1);
	return SWIG_TOKEN_MINUS;
      }
      break;

    case 211:			/* ARROW, ARROWSTAR */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_ARROW;
      else if (c == '*')
	return SWIG_TOKEN_ARROWSTAR;
      else {
	retract(s, 1);
	return SWIG_TOKEN_ARROW;
      }
      break;


    case 220:			/* STAR, TIMESEQUAL */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_STAR;
      else if (c == '=')
	return SWIG_TOKEN_TIMESEQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_STAR;
      }
      break;

    case 230:			/* XOR, XOREQUAL */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_XOR;
      else if (c == '=')
	return SWIG_TOKEN_XOREQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_XOR;
      }
      break;

    case 240:			/* LSHIFT, LSEQUAL */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_LSHIFT;
      else if (c == '=')
	return SWIG_TOKEN_LSEQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_LSHIFT;
      }
      break;

    case 250:			/* RSHIFT, RSEQUAL */
      if ((c = nextchar(s)) == 0)
	return SWIG_TOKEN_RSHIFT;
      else if (c == '=')
	return SWIG_TOKEN_RSEQUAL;
      else {
	retract(s, 1);
	return SWIG_TOKEN_RSHIFT;
      }
      break;


      /* An illegal character */

      /* Reverse string */
    case 900:
      if ((c = nextchar(s)) == 0) {
	Swig_error(cparse_file, cparse_start_line, "Unterminated character constant\n");
	return SWIG_TOKEN_ERROR;
      }
      if (c == '`') {
	Delitem(s->text, DOH_END);
	return (SWIG_TOKEN_RSTRING);
      }
      break;

    default:
      return SWIG_TOKEN_ILLEGAL;
    }
  }
}
Exemplo n.º 9
0
void boot(Rd_clp rd, bool_t verbose, string_t cmdline)
{
#ifdef INTEL
    uint32_t NOCLOBBER length;
    uint32_t start, slen;
    uint8_t * NOCLOBBER buff;
    Stretch_clp stretch;
    
    length=Rd$Length(rd);

    /* Read the header of the file to try to work out what it is */

    buff=Heap$Malloc(Pvs(heap), 512);
    Rd$GetChars(rd, buff, 512);

    if (buff[510]==0x55 && buff[511]==0xaa) {
	if (verbose) printf(
	    "Traditional bootable Nemesis image with %d setup blocks.\n",
	    buff[497]);
	start=512*(buff[497]+1);
    } else if (buff[0]==0xfa && buff[1]==0xfc ) {
	if (verbose) printf("Hmm... looks like a bare Nemesis image.\n");
	start=0;
    } else {
	printf("This does not look like a Nemesis image.\n");
	return;
    }

    Heap$Free(Pvs(heap), buff);

    length-=start;

    /* Get a stretch of the appropriate size */
    stretch = STR_NEW(length);
    buff    = STR_RANGE(stretch, &slen);

    /* Read the image */
    Rd$Seek(rd, start);
#define PKTSIZE 8192
    {
	char *bufptr = buff;
	int n;
	int togo = length;

	while (togo) {
	    n = Rd$GetChars(rd, bufptr, PKTSIZE);
	    togo -= n;
	    bufptr += n;
	    printf("."); fflush(stdout);
	} 
    }
    printf("\n");

    /* now shut down any Ethernet cards, so we don't get anything DMAed
     * over the image while it boots */
    /* XXX AND This is a privileged operation.  And we shouldn't really
     * dive at the Netif interface directly. */
    /* XXX SDE we might be in a UDPnash at the moment, so there should be
     * NO OUTPUT after this point */
    verbose=False;
    {
	Type_Any any;
	Netif_clp netif;
	const char * const downlist[] = {"de4x5-0",
					 "de4x5-1",
					 /* don't need 3c509, since no DMA */
					 "eth0",
					 NULL};
	/* HACK: need to lose the "const", since Context$Get() doesn't
         * have it. */
	char ** NOCLOBBER eth = (char**)downlist;
	char buf[32];

	while(*eth)
	{
	    sprintf(buf, "dev>%s>control", *eth);

	    if (Context$Get(Pvs(root), buf, &any))
	    {
		if (verbose)
		{
		    printf("Shutting down %s... ", *eth);
		    fflush(stdout);
		}

		TRY {
		    netif = IDC_OPEN(buf, Netif_clp);
		} CATCH_ALL {
		    if (verbose)
			printf("failed: caught exception\n");
		    netif = NULL;
		} ENDTRY;

		if (netif && !Netif$Down(netif) && verbose)
		{
		    printf("failed: Netif$Down() error\n");
		    netif = NULL;
		}

		if (netif && verbose)
		    printf("ok\n");
	    }

	    eth++;
	}
    }

    if (verbose)
    {
	printf("Starting image...\n");
	PAUSE(MILLISECS(1000));
    }

    /* Chain to the new image */
    ENTER_KERNEL_CRITICAL_SECTION();
    ntsc_chain(buff, length, cmdline);
    LEAVE_KERNEL_CRITICAL_SECTION();

    printf("Bogosity: the new image was not started\n");
    printf("bogosity: (n) (slang); the degree of unusallness and brokenness of some item or event\n");
#else
    printf("Boot chaining not supported\n");
#endif
}
Exemplo n.º 10
0
void Archive::SeekToNext()
{
    Seek(NextBlockPos, SEEK_SET);
}
Exemplo n.º 11
0
void Scanner_locator(Scanner *s, String *loc) {
  static Locator *locs = 0;
  static int expanding_macro = 0;

  if (!follow_locators) {
    if (Equal(loc, "/*@SWIG@*/")) {
      /* End locator. */
      if (expanding_macro)
	--expanding_macro;
    } else {
      /* Begin locator. */
      ++expanding_macro;
    }
    /* Freeze line number processing in Scanner */
    freeze_line(s,expanding_macro);
  } else {
    int c;
    Locator *l;
    Seek(loc, 7, SEEK_SET);
    c = Getc(loc);
    if (c == '@') {
      /* Empty locator.  We pop the last location off */
      if (locs) {
	Scanner_set_location(s, locs->filename, locs->line_number);
	cparse_file = locs->filename;
	cparse_line = locs->line_number;
	l = locs->next;
	free(locs);
	locs = l;
      }
      return;
    }

    /* We're going to push a new location */
    l = (Locator *) malloc(sizeof(Locator));
    l->filename = cparse_file;
    l->line_number = cparse_line;
    l->next = locs;
    locs = l;

    /* Now, parse the new location out of the locator string */
    {
      String *fn = NewStringEmpty();
      /*      Putc(c, fn); */
      
      while ((c = Getc(loc)) != EOF) {
	if ((c == '@') || (c == ','))
	  break;
	Putc(c, fn);
      }
      cparse_file = Swig_copy_string(Char(fn));
      Clear(fn);
      cparse_line = 1;
      /* Get the line number */
      while ((c = Getc(loc)) != EOF) {
	if ((c == '@') || (c == ','))
	  break;
	Putc(c, fn);
      }
      cparse_line = atoi(Char(fn));
      Clear(fn);
      
      /* Get the rest of it */
      while ((c = Getc(loc)) != EOF) {
	if (c == '@')
	  break;
	Putc(c, fn);
      }
      /*  Swig_diagnostic(cparse_file, cparse_line, "Scanner_set_location\n"); */
      Scanner_set_location(s, cparse_file, cparse_line);
      Delete(fn);
    }
  }
}
Exemplo n.º 12
0
bool Archive::IsArchive(bool EnableBroken)
{
    Encrypted = false;
#ifndef SFX_MODULE

    if (IsDevice())
    {
#ifndef SHELL_EXT
        Log(FileName, St(MInvalidName), FileName);
#endif
        return(false);
    }

#endif

    if (Read(MarkHead.Mark, SIZEOF_MARKHEAD) != SIZEOF_MARKHEAD)
        return(false);

    SFXSize = 0;

    if (IsSignature(MarkHead.Mark))
    {
        if (OldFormat)
            Seek(0, SEEK_SET);
    }

    else
    {
        Array<char> Buffer(MAXSFXSIZE);
        long CurPos = (long)Tell();
        int ReadSize = Read(&Buffer[0], Buffer.Size() - 16);

        for (int I = 0; I < ReadSize; I++)
            if (Buffer[I] == 0x52 && IsSignature((byte*)&Buffer[I]))
            {
                if (OldFormat && I > 0 && CurPos < 28 && ReadSize > 31)
                {
                    char* D = &Buffer[28 - CurPos];

                    if (D[0] != 0x52 || D[1] != 0x53 || D[2] != 0x46 || D[3] != 0x58)
                        continue;
                }

                SFXSize = CurPos + I;
                Seek(SFXSize, SEEK_SET);

                if (!OldFormat)
                    Read(MarkHead.Mark, SIZEOF_MARKHEAD);

                break;
            }

        if (SFXSize == 0)
            return(false);
    }

    ReadHeader();
    SeekToNext();
#ifndef SFX_MODULE

    if (OldFormat)
    {
        NewMhd.Flags = OldMhd.Flags & 0x3f;
        NewMhd.HeadSize = OldMhd.HeadSize;
    }

    else
#endif
    {
        if (HeaderCRC != NewMhd.HeadCRC)
        {
#ifndef SHELL_EXT
            Log(FileName, St(MLogMainHead));
#endif
            Alarm();

            if (!EnableBroken)
                return(false);
        }
    }

    Volume = (NewMhd.Flags & MHD_VOLUME);
    Solid = (NewMhd.Flags & MHD_SOLID) != 0;
    MainComment = (NewMhd.Flags & MHD_COMMENT) != 0;
    Locked = (NewMhd.Flags & MHD_LOCK) != 0;
    Signed = (NewMhd.PosAV != 0);
    Protected = (NewMhd.Flags & MHD_PROTECT) != 0;
    Encrypted = (NewMhd.Flags & MHD_PASSWORD) != 0;

    if (NewMhd.EncryptVer > UNP_VER)
    {
#ifdef RARDLL
        Cmd->DllError = ERAR_UNKNOWN_FORMAT;
#else
        ErrHandler.SetErrorCode(WARNING);
#if !defined(SILENT) && !defined(SFX_MODULE)
        Log(FileName, St(MUnknownMeth), FileName);
        Log(FileName, St(MVerRequired), NewMhd.EncryptVer / 10, NewMhd.EncryptVer % 10);
#endif
#endif
        return(false);
    }

#ifdef RARDLL

    // If callback function is not set, we cannot get the password,
    // so we skip the initial header processing for encrypted header archive.
    // It leads to skipped archive comment, but the rest of archive data
    // is processed correctly.
    if (Cmd->Callback == NULL)
        SilentOpen = true;

#endif
    // If not encrypted, we'll check it below.
    NotFirstVolume = Encrypted && (NewMhd.Flags & MHD_FIRSTVOLUME) == 0;

    if (!SilentOpen || !Encrypted)
    {
        SaveFilePos SavePos(*this);
        int64 SaveCurBlockPos = CurBlockPos, SaveNextBlockPos = NextBlockPos;
        NotFirstVolume = false;

        while (ReadHeader() != 0)
        {
            int HeaderType = GetHeaderType();

            if (HeaderType == NEWSUB_HEAD)
            {
                if (SubHead.CmpName(SUBHEAD_TYPE_CMT))
                    MainComment = true;

                if ((SubHead.Flags & LHD_SPLIT_BEFORE) ||
                        Volume && (NewMhd.Flags & MHD_FIRSTVOLUME) == 0)
                    NotFirstVolume = true;
            }

            else
            {
                if (HeaderType == FILE_HEAD && ((NewLhd.Flags & LHD_SPLIT_BEFORE) != 0 ||
                                                Volume && NewLhd.UnpVer >= 29 && (NewMhd.Flags & MHD_FIRSTVOLUME) == 0))
                    NotFirstVolume = true;

                break;
            }

            SeekToNext();
        }

        CurBlockPos = SaveCurBlockPos;
        NextBlockPos = SaveNextBlockPos;
    }

    if (!Volume || !NotFirstVolume)
    {
        strcpy(FirstVolumeName, FileName);
        wcscpy(FirstVolumeNameW, FileNameW);
    }

    return(true);
}
Exemplo n.º 13
0
bool CDSK::Open(char * dskName, DiskOpenMode mode)
{
	strcpy(this->dskName, dskName);
	dskFile = fopen(dskName, (mode == OPEN_MODE_EXISTING ? "rb+" : "w+b"));	

	if (dskFile)
	{
		if (mode == OPEN_MODE_EXISTING)
		{			
			if ((fread(&diskInfoBlk, sizeof(diskInfoBlk), 1, dskFile) == 1) &&				
				(memcmp(GetSignature(), diskInfoBlk.signature, sigMinValidLen) == 0) &&
				Seek(0))
			{
				DiskDefinition.SideCnt = diskInfoBlk.sideNo;
				DiskDefinition.TrackCnt = diskInfoBlk.trackNo;				
				DiskDefinition.SPT = currTrack.sectorCount;
				DiskDefinition.SectSize = CDiskBase::SectCode2SectSize(currSectorInfo[0].sectorSizeCode);
				DiskDefinition.Filler = currTrack.fillerByte;
				DiskDefinition.GapFmt = currTrack.gap3;

				//Take interleave from firs track.
				for (byte secIdx = 0; secIdx < currTrack.sectorCount; secIdx++)
					InterlaveTbl[secIdx] = currSectorInfo[secIdx].sectorID;
				
				if (currTrack.dataRate == DATA_RATE_HIGH)
					DiskDefinition.Density = DISK_DATARATE_HD;
				else if (currTrack.dataRate == DATA_RATE_HIGH)
					DiskDefinition.Density = DISK_DATARATE_ED;
				else if (DiskDefinition.TrackCnt > 42)
					 DiskDefinition.Density= DISK_DATARATE_DD_3_5;
				else
					DiskDefinition.Density = DISK_DATARATE_DD_5_25;
				
				return true;
			}
			else
			{
				LastError = ERR_READ;
				return false;
			}
		}
		else
		{
			if (!CreateImage())
				return false;

			if (fseek(dskFile, 0, SEEK_SET) == 0 &&
				fread(&diskInfoBlk, sizeof(diskInfoBlk), 1, dskFile) == 1)
				return true;
			else
			{
				LastError = ERR_READ;
				return false;
			}
		}				
	}
	else
	{
		LastError = ERR_READ;
		return false;
	}
}
Exemplo n.º 14
0
			const bool				CFileResource::Reset(void)
			{
				return (Seek(0));
			}
Exemplo n.º 15
0
bool CTapFile::GetBlock(word blkIdx, CTapeBlock* tb)
{	
	return blkIdx < GetBlockCount() && Seek(blkIdx) && (blkIdx == 0 ? GetFirstBlock(tb) : GetNextBlock(tb));
}
Exemplo n.º 16
0
void FILEFile::init()
{
    // Open mode for file's open
    const char *omode = "rb";

    if (OpenFlags & Open_Truncate)
    {
        if (OpenFlags & Open_Read)
            omode = "w+b";
        else
            omode = "wb";
    }
    else if (OpenFlags & Open_Create)
    {
        if (OpenFlags & Open_Read)
            omode = "a+b";
        else
            omode = "ab";
    }
    else if (OpenFlags & Open_Write)
        omode = "r+b";

#ifdef OVR_OS_WIN32
    SysErrorModeDisabler disabler(FileName.ToCStr());
#endif

#if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400)
    wchar_t womode[16];
    wchar_t *pwFileName = (wchar_t*)OVR_ALLOC((UTF8Util::GetLength(FileName.ToCStr())+1) * sizeof(wchar_t));
    UTF8Util::DecodeString(pwFileName, FileName.ToCStr());
    OVR_ASSERT(strlen(omode) < sizeof(womode)/sizeof(womode[0]));
    UTF8Util::DecodeString(womode, omode);
    _wfopen_s(&fs, pwFileName, womode);
    OVR_FREE(pwFileName);
#else
    fs = fopen(FileName.ToCStr(), omode);
#endif
    if (fs)
        rewind (fs);
    Opened = (fs != NULL);
    // Set error code
    if (!Opened)
        ErrorCode = SFerror();
    else
    {
        // If we are testing file seek correctness, pre-load the entire file so
        // that we can do comparison tests later.
#ifdef OVR_FILE_VERIFY_SEEK_ERRORS
        TestPos         = 0;
        fseek(fs, 0, SEEK_END);
        FileTestLength  = ftell(fs);
        fseek(fs, 0, SEEK_SET);
        pFileTestBuffer = (UByte*)OVR_ALLOC(FileTestLength);
        if (pFileTestBuffer)
        {
            OVR_ASSERT(FileTestLength == (unsigned)Read(pFileTestBuffer, FileTestLength));
            Seek(0, Seek_Set);
        }
#endif

        ErrorCode = 0;
    }
    LastOp = 0;
}
Exemplo n.º 17
0
void MpvHandler::Restart()
{
    Seek(0);
    Play();
}
Exemplo n.º 18
0
SInt64  FILEFile::LSeek(SInt64 offset, int origin)
{
    return Seek((int)offset,origin);
}
Exemplo n.º 19
0
int
Preprocessor_expr(DOH *s, int *error) {
  int     token = 0;
  int     op = 0;

  sp = 0;
  assert(s);
  assert(scan);

  Seek(s,0,SEEK_SET);
  /*  Printf(stdout,"evaluating : '%s'\n", s); */
  *error = 0;
  SwigScanner_clear(scan);
  SwigScanner_push(scan,s);

  /* Put initial state onto the stack */
  stack[sp].op = EXPR_TOP;
  stack[sp].value = 0;

  while (1) {
    /* Look at the top of the stack */
    switch(stack[sp].op) {
    case EXPR_TOP:
      /* An expression.   Can be a number or another expression enclosed in parens */
      token = SwigScanner_token(scan);
      if (!token) {
	errmsg = "Expected an expression";
	*error = 1;
	return 0;
      }
      if ((token == SWIG_TOKEN_INT) || (token == SWIG_TOKEN_UINT) || (token == SWIG_TOKEN_LONG) || (token == SWIG_TOKEN_ULONG)) {
	/* A number.  Reduce EXPR_TOP to an EXPR_VALUE */
	char *c = Char(SwigScanner_text(scan));
	stack[sp].value = (long) strtol(c,0,0);
	stack[sp].svalue = 0;
	/*	  stack[sp].value = (long) atol(Char(SwigScanner_text(scan))); */
	stack[sp].op = EXPR_VALUE;
      } else if (token == SWIG_TOKEN_PLUS) { }
       else if ((token == SWIG_TOKEN_MINUS) || (token == SWIG_TOKEN_LNOT) || (token==SWIG_TOKEN_NOT)) {
	if (token == SWIG_TOKEN_MINUS) token = EXPR_UMINUS;
	stack[sp].value = token;
	stack[sp++].op = EXPR_OP;
	stack[sp].op = EXPR_TOP;
	stack[sp].svalue = 0;
      } else if ((token == SWIG_TOKEN_LPAREN)) {
	stack[sp++].op = EXPR_GROUP;
	stack[sp].op = EXPR_TOP;
	stack[sp].value = 0;
	stack[sp].svalue = 0;
      } else if (token == SWIG_TOKEN_ENDLINE) { 
      } else if ((token == SWIG_TOKEN_STRING)) {
	stack[sp].svalue = NewString(SwigScanner_text(scan));
	stack[sp].op = EXPR_VALUE;
      } else if ((token == SWIG_TOKEN_ID)) {
	stack[sp].value = 0;
	stack[sp].svalue = 0;
	stack[sp].op = EXPR_VALUE;
      } else goto syntax_error;
      break;
    case EXPR_VALUE:
      /* A value is on the stack.   We may reduce or evaluate depending on what the next token is */
      token = SwigScanner_token(scan);
      if (!token) {
	/* End of input. Might have to reduce if an operator is on stack */
	while (sp > 0) {
	  if (stack[sp-1].op == EXPR_OP) {
	    reduce_op();
	  } else if (stack[sp-1].op == EXPR_GROUP) {
	    errmsg = "Missing \')\'";
	    *error = 1;
	    return 0;
	  } else goto syntax_error;
	}
	return stack[sp].value;
      }
      /* Token must be an operator */
      switch(token) {
      case SWIG_TOKEN_STAR:
      case SWIG_TOKEN_EQUALTO:
      case SWIG_TOKEN_NOTEQUAL:
      case SWIG_TOKEN_PLUS:
      case SWIG_TOKEN_MINUS:
      case SWIG_TOKEN_AND:
      case SWIG_TOKEN_LAND:
      case SWIG_TOKEN_OR:
      case SWIG_TOKEN_LOR:
      case SWIG_TOKEN_XOR:
      case SWIG_TOKEN_LESSTHAN:
      case SWIG_TOKEN_GREATERTHAN:
      case SWIG_TOKEN_LTEQUAL:
      case SWIG_TOKEN_GTEQUAL:
      case SWIG_TOKEN_SLASH:
      case SWIG_TOKEN_PERCENT:
      case SWIG_TOKEN_LSHIFT:
      case SWIG_TOKEN_RSHIFT:
	if ((sp == 0) || (stack[sp-1].op == EXPR_GROUP)) {
	  /* No possibility of reduce. Push operator and expression */
	  sp++;
	  stack[sp].op = EXPR_OP;
	  stack[sp].value = token;
	  sp++;
	  stack[sp].op = EXPR_TOP;
	  stack[sp].value = 0;
	} else {
	  if (stack[sp-1].op != EXPR_OP) goto syntax_error;
	  op = stack[sp-1].value;         /* Previous operator */

	  /* Now, depending on the precedence relationship between the last operator and the current
	     we will reduce or push */

	  if (prec[op] <= prec[token]) {
	    /* Reduce the previous operator */
	    reduce_op();
	    if (stack[sp].op != EXPR_VALUE) goto syntax_error;
	  }
	  sp++;
	  stack[sp].op = EXPR_OP;
	  stack[sp].value = token;
	  sp++;
	  stack[sp].op = EXPR_TOP;
	  stack[sp].value = 0;
	}
	break;
      case SWIG_TOKEN_RPAREN:
	if (sp ==  0) goto extra_rparen;

	/* Might have to reduce operators first */
	while ((sp > 0) && (stack[sp-1].op == EXPR_OP)) reduce_op();
	if ((sp == 0) || (stack[sp-1].op != EXPR_GROUP)) goto extra_rparen;
	stack[sp-1].op = EXPR_VALUE;
	stack[sp-1].value = stack[sp].value;
	sp--;
	break;
      default:
	goto syntax_error;
	break;
      }
      break;

    default:
      fprintf(stderr,"Internal error in expression evaluator.\n");
      abort();
    }
  }
 syntax_error:
  errmsg = "Syntax error";
  *error = 1;
  return 0;

 extra_rparen:
  errmsg = "Extra \')\'";
  *error = 1;
  return 0;
}
Exemplo n.º 20
0
void VDFileAsyncNT::Truncate(sint64 pos) {
	Seek(pos);
	if (!SetEndOfFile(mhFileSlow))
		throw MyWin32Error("I/O error on file \"%s\": %%s", GetLastError(), mFilename.c_str());
}
Exemplo n.º 21
0
bool CMyFile::FOpen(CString szFileName, bool bWrite)
{
    if(this->_bOpen == true)
        return true;

    if(szFileName.GetLength() <= 0)
        return false;

    this->_bWrite = bWrite;
    this->_szFileName = szFileName;

    try
    {
        if(Open(this->_szFileName,  
            this->_bWrite ? this->nOpenFlagsWrite : this->nOpenFlagsRead) == FALSE)
        {
            this->_bOpen = false;
            return false;
        }
        else
        {
            // auto-select read & write modes
            if(this->_nMode == -1)
            {
                if(this->_bWrite == false)
                {
                    // set read mode
                    bool bHaveBomHeader = false;
                    unsigned char szUnicodeHeader[nBomHeaderSize];

                    if(Read(szUnicodeHeader, nBomHeaderSize) != nBomHeaderSize)
                    {
                        Close();
                        this->_bOpen = false;
                        return false;
                    }

                    if((szUnicodeHeader[0] != szUnicode[0]) || (szUnicodeHeader[1] != szUnicode[1]))
                        bHaveBomHeader = false;
                    else
                        bHaveBomHeader = true;

#ifdef _UNICODE
                    if(bHaveBomHeader == true)
                        this->_nMode = 0;
                    else
                        this->_nMode = 1;   
#else
                    if(bHaveBomHeader == true)
                        this->_nMode = 2;
                    else
                        this->_nMode = 3;   
#endif

                    // if input is Ansi than seek to the beginning of the file
                    if((this->_nMode == 1) || (this->_nMode == 3))
                        Seek(0, begin);
                }
                else
                {
                    // set write mode
#ifdef _UNICODE
                    this->_nMode = 0;
                    Write(szUnicode, nBomHeaderSize);
#else
                    this->_nMode = 3;
#endif
                }
            }
            else
            {
                // mode was selected by user
                if(this->_bWrite == true)
                {
                    switch(this->_nMode)
                    {
                        // dst = Unicode
                    case 0:
                    case 1:
                        {
                            Write(szUnicode, nBomHeaderSize);
                        }
                        break;
                        // dst = Ansi
                    case 2:
                    case 3:
                        {
                            // nothing to do
                        }
                        break;
                    }
                }
                else
                {
                    switch(this->_nMode)
                    {
                        // src = Unicode
                    case 0:
                    case 2:
                        {
                            Seek(nBomHeaderSize, begin);
                        }
                        break;
                        // src = Ansi
                    case 1:
                    case 3:
                        {
                             Seek(0, begin);
                        }
                        break;
                    }
                }
            }

            this->_bOpen = true;
            return true;
        }
    }
    catch(...)
    {
        return false;
    }
}
Vector2D S013010C_Aaron_Smith_Steering::Calculate(float deltaTime)
{
	Vector2D force;
	Vector2D totalForce;
	if (mIsObstacleAvoiding)
	{
		force = ObstacleAvoidance() * mObstacleAvoidanceWeight;
		if (!AccumulateForce(totalForce, force)) return totalForce;
	}

	if (mIsWallAvoided)
	{
		force = WallAvoidance() * mWallAvoidWeight;
		if (!AccumulateForce(totalForce, force)) return totalForce;
	}

	if (mIsWandering)
	{
		force = Wander(deltaTime) * mSeekWeight;
		if (!AccumulateForce(totalForce, force)) return totalForce;
	}

	if (mIsPursuing)
	{
		force = Pursuing() * mPursuitWeight;
		if (!AccumulateForce(totalForce, force)) return totalForce;

	}
	if (mIsSeeking)
	{
		force = Seek(mTank->GetTarget()) * mSeekWeight;
		if (!AccumulateForce(totalForce, force)) return totalForce;

	}
	if (mIsArriving)
	{
		force = Arrive(mTank->GetTarget(), Deceleration::NORMAL) * mArriveWeight;
		if (!AccumulateForce(totalForce, force)) return totalForce;
	}
	if (mIsFleeing)
	{
		force = Flee(mTank->GetTarget()) * mFleeWeight;
		if (!AccumulateForce(totalForce, force)) return totalForce;
	}

	return totalForce;

	//if (isFleeing) Flee(mTank->GetTarget());
	
	

	//Vector2D totalForce;


	

	/*for (Vector2D vec : mSteeringForces)
	{
		totalForce += vec;
	}
	mSteeringForces.clear();
	
	return totalForce;*/
}
Exemplo n.º 23
0
Arquivo: disc.c Projeto: 4ad/sam
void
bkread(Disc *d, Rune *loc, int n, int bk, int off)
{
	Seek(d->desc->fd, RUNESIZE*(BLOCKSIZE*d->block.blkptr[bk].bnum+off), 0);
	Read(d->desc->fd, loc, n*RUNESIZE);
}
Exemplo n.º 24
0
//TODO: Make sure this actually makes sense
bool FZipPackage::LoadPackage( FStringConst& Path )
{
	Logf( LOG_ENGINE, L"Loading zip package '%s'", Path.Data );
	if(Open( Path.Data ))
	{
		PackageName = Path.Substring(0, Path.IndexOf('.'));
		Seek( 0, Begin );
		//Index all assets
		while(Position != Filesize)
		{
			//Read in the zip header
			FZipFileHeader ZipFileHeader;
			Read( &ZipFileHeader.Signature, 4 );
			if( ZipFileHeader.Signature != 0x04034b50 )
			{
				Close();
				return false;
			}
			Read( &ZipFileHeader.MinVersion, 10 );
			Read( &ZipFileHeader.CRC32, 12 );
			Read( &ZipFileHeader.FileNameLen, 4 );

			ZipFileHeader.FileName = ( ZipFileHeader.FileNameLen > 0 ) ? new char[ZipFileHeader.FileNameLen+1] : nullptr;
			ZipFileHeader.ExtraField = ( ZipFileHeader.ExtraFieldLen > 0 ) ? new char[ZipFileHeader.ExtraFieldLen+1] : nullptr;

			Read( ZipFileHeader.FileName, ZipFileHeader.FileNameLen );
			ZipFileHeader.FileName[ZipFileHeader.FileNameLen] = '\0';
			Read( ZipFileHeader.ExtraField, ZipFileHeader.ExtraFieldLen );

			//Skip past the compressed file
			Seek( ZipFileHeader.CompressSize, Current );

			//Index the asset
			FZipAsset* ZipAsset = new FZipAsset();
			ZipAsset->IsDirectory = (GMemory->Find( ZipFileHeader.FileName, '.', ZipFileHeader.FileNameLen ) == 0) ? true : false;
			ZipAsset->Path = new FStringConst(ZipFileHeader.FileName);

			if (ZipAsset->IsDirectory)
			{
				FString* sPath = new FString( ZipAsset->Path->Data );
				uint64 SecondSlashMark = sPath->LastIndexOf( '/', 2 )+1;

				FString* sName = sPath->Substring( SecondSlashMark, sPath->GetSize() - 1 - SecondSlashMark );
				ZipAsset->Name = sName->ConstructConstString();

				delete sPath;
				delete sName;
			}
			else
			{
				ZipAsset->Name = ZipAsset->Path->Substring( ZipAsset->Path->LastIndexOf( '/' ) + 1 );
			}

			uint64 ExtIndex = ZipAsset->Name->LastIndexOf( '.' );
			FStringConst* Ext = (ExtIndex != MAXDWORD64) ? ZipAsset->Name->Substring( ExtIndex ) : new FStringConst( "" );
			ZipAsset->Type = ResolveAssetType( Ext );
			delete Ext;

			ZipAsset->Size = ZipFileHeader.UncompressSize;
			ZipAsset->CompressSize = ZipFileHeader.CompressSize;
			ZipAsset->CompressType = ZipFileHeader.CompressType;
			ZipAsset->Location = Position - ZipFileHeader.CompressSize;
			Assets.Add( (FAsset*)ZipAsset );

			//Clean up
			if (ZipFileHeader.FileNameLen > 0) delete ZipFileHeader.FileName;
			if (ZipFileHeader.ExtraFieldLen > 0) delete ZipFileHeader.ExtraField;

			//Check for the central directory header
			uint32 MaybeCDHSig;
			Peek( &MaybeCDHSig, sizeof(uint32) );
			if(MaybeCDHSig == 0x02014b50)
				break; //No more local file headers
		}
		return true;
	}
	Logf( LOG_ENGINE, L"Zip package '%s' does not exist", Path.Data );
	return false;
}
Exemplo n.º 25
0
int tReadEntry()
{
  int fd, retR, retC;
  struct VFS_Dir_Entry dirEntry;

  retC = Create_Directory("/d/basic11d");
  if (retC < 0) {
    Print("couldn't create basic11d: %d\n", retC);
    return -1;
  }

  retC = Create_Directory("/d/basic11d/d1");
  if (retC < 0) {
    Print("couldn't create basic11d/d1: %d\n", retC);
    return -1;
  }

  retC = Create_Directory("/d/basic11d/d2");
  if (retC < 0) {
    Print("couldn't create basic11d/d2: %d\n", retC);
    return -1;
  }

  fd = Open("/d/basic11d/f1", O_CREATE);
  if (fd < 0) {
    Print("couldn't create basic11d/f1: %d\n", fd);
    return -1;
  }

  Close(fd);

  fd = Open_Directory("/d/basic11d");
  if (fd < 0) {
    Print("couldn't opendir basic11d: %d\n", fd);
    return -1;
  }

  do {
    retR = Read_Entry(fd, &dirEntry);
  } while(retR == 0 && dirEntry.name[0] == '.');

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "d1", 2) != 0) ||
       (! dirEntry.stats.isDirectory))
    return -1;

  retR = Read_Entry(fd, &dirEntry);

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "d2", 2) != 0) ||
       (! dirEntry.stats.isDirectory))
    return -1;

  retR = Read_Entry(fd, &dirEntry);

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "f1", 2) != 0) ||
       (dirEntry.stats.isDirectory))
    return -1;
  
  Close(fd);

  fd = Open_Directory("/d/basic11d");
  if (fd < 0)
    return -1;

  retR = Seek(fd, 2);
  if (retR < 0)
    return -1;

  retR = Read_Entry(fd, &dirEntry);

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "f1", 2) != 0) ||
       (dirEntry.stats.isDirectory))
    return -1;
  
  Close(fd);
  Delete("/d/basic11d/d1");
  Delete("/d/basic11d/d2");
  Delete("/d/basic11d/f1");

  Delete("/d/basic11d");
  return 1;
}
Exemplo n.º 26
0
long vFile::Length(void)
{
    Seek(0, SEEK_END);
    return ftell(m_fp);
}
Exemplo n.º 27
0
// /Move file relative to the start of the file
///
/// @param offset Number of bytes to seek
///
u64 YCFile::SeekHed(s64 offset)
{
	return Seek(offset, begin);
}
Exemplo n.º 28
0
/*
 * Examine a volume to see if we recognize it as a mountable.
 */
void
NTFSGetDescription(CICell ih, char *str, long strMaxLen)
{
    struct bootfile *boot;
    unsigned bytesPerSector;
    unsigned sectorsPerCluster;
    int mftRecordSize;
    u_int64_t totalClusters;
    u_int64_t cluster, mftCluster;
    size_t mftOffset;
    void *nameAttr;
    size_t nameSize;
    char *buf;

    buf = (char *)malloc(MAX_CLUSTER_SIZE);
    if (buf == 0) {
        goto error;
    }

    /*
     * Read the boot sector, check signatures, and do some minimal
     * sanity checking.  NOTE: the size of the read below is intended
     * to be a multiple of all supported block sizes, so we don't
     * have to determine or change the device's block size.
     */
    Seek(ih, 0);
    Read(ih, (long)buf, MAX_BLOCK_SIZE);

    boot = (struct bootfile *) buf;
    
    /*
     * The first three bytes are an Intel x86 jump instruction.  I assume it
     * can be the same forms as DOS FAT:
     *    0xE9 0x?? 0x??
     *    0xEC 0x?? 0x90
     * where 0x?? means any byte value is OK.
     */
    if (boot->reserved1[0] != 0xE9
        && (boot->reserved1[0] != 0xEB || boot->reserved1[2] != 0x90))
    {
        goto error;
    }

    /*
     * Check the "NTFS    " signature.
     */
    if (memcmp((const char *)boot->bf_sysid, "NTFS    ", 8) != 0)
    {
        goto error;
    }

    /*
     * Make sure the bytes per sector and sectors per cluster are
     * powers of two, and within reasonable ranges.
     */
    bytesPerSector = OSReadLittleInt16(&boot->bf_bps,0);
    if ((bytesPerSector & (bytesPerSector-1)) || bytesPerSector < 512 || bytesPerSector > 32768)
    {
        //verbose("NTFS: invalid bytes per sector (%d)\n", bytesPerSector);
        goto error;
    }

    sectorsPerCluster = boot->bf_spc;	/* Just one byte; no swapping needed */
    if ((sectorsPerCluster & (sectorsPerCluster-1)) || sectorsPerCluster > 128)
    {
        //verbose("NTFS: invalid sectors per cluster (%d)\n", bytesPerSector);
        goto error;
    }
    
    /*
     * Calculate the number of clusters from the number of sectors.
     * Then bounds check the $MFT and $MFTMirr clusters.
     */
    totalClusters = OSReadLittleInt64(&boot->bf_spv,0) / sectorsPerCluster;
    mftCluster = OSReadLittleInt64(&boot->bf_mftcn,0);
    if (mftCluster > totalClusters)
    {
        ////verbose("NTFS: invalid $MFT cluster (%lld)\n", mftCluster);
        goto error;
    }
    cluster = OSReadLittleInt64(&boot->bf_mftmirrcn,0);
    if (cluster > totalClusters)
    {
        //verbose("NTFS: invalid $MFTMirr cluster (%lld)\n", cluster);
        goto error;
    }
    
    /*
     * Determine the size of an MFT record.
     */
    mftRecordSize = (int8_t) boot->bf_mftrecsz;
    if (mftRecordSize < 0)
        mftRecordSize = 1 << -mftRecordSize;
    else
        mftRecordSize *= bytesPerSector * sectorsPerCluster;
    //verbose("NTFS: MFT record size = %d\n", mftRecordSize);

    /*
     * Read the MFT record for $Volume.  This assumes the first four
     * file records in the MFT are contiguous; if they aren't, we
     * would have to map the $MFT itself.
     *
     * This will fail if the device sector size is larger than the
     * MFT record size, since the $Volume record won't be aligned
     * on a sector boundary.
     */
    mftOffset = mftCluster * sectorsPerCluster * bytesPerSector;
    mftOffset += mftRecordSize * NTFS_VOLUMEINO;

    Seek(ih, mftOffset);
    Read(ih, (long)buf, mftRecordSize);
#if UNUSED
    if (lseek(fd, mftOffset, SEEK_SET) == -1)
    {
        //verbose("NTFS: lseek to $Volume failed: %s\n", strerror(errno));
        goto error;
    }
    if (read(fd, buf, mftRecordSize) != mftRecordSize)
    {
        //verbose("NTFS: error reading MFT $Volume record: %s\n",
                strerror(errno));
        goto error;
    }
Exemplo n.º 29
0
/// Move the file pointer relative to its current position
///
/// @param offset Number of bytes to seek
///
u64 YCFile::SeekCur(s64 offset)
{
	return Seek(offset, current);
}
Exemplo n.º 30
0
bool CGUIWindowFullScreen::OnAction(const CAction &action)
{
  if (g_application.m_pPlayer != NULL && g_application.m_pPlayer->OnAction(action))
    return true;

  switch (action.wID)
  {

  case ACTION_SHOW_GUI:
    {
      // switch back to the menu
      OutputDebugString("Switching to GUI\n");
      m_gWindowManager.PreviousWindow();
      OutputDebugString("Now in GUI\n");
      return true;
    }
    break;

  case ACTION_STEP_BACK:
    Seek(false, false);
    return true;
    break;

  case ACTION_STEP_FORWARD:
    Seek(true, false);
    return true;
    break;

  case ACTION_BIG_STEP_BACK:
    SeekChapter(g_application.m_pPlayer->GetChapter() - 1);
    return true;
    break;

  case ACTION_BIG_STEP_FORWARD:
    SeekChapter(g_application.m_pPlayer->GetChapter() + 1);
    return true;
    break;

  case ACTION_NEXT_SCENE:
    if (g_application.m_pPlayer->SeekScene(true))
      g_infoManager.SetDisplayAfterSeek();
    return true;
    break;

  case ACTION_PREV_SCENE:
    if (g_application.m_pPlayer->SeekScene(false))
      g_infoManager.SetDisplayAfterSeek();
    return true;
    break;

  case ACTION_SHOW_OSD_TIME:
    m_bShowCurrentTime = !m_bShowCurrentTime;
    if(!m_bShowCurrentTime)
      g_infoManager.SetDisplayAfterSeek(0); //Force display off
    g_infoManager.SetShowTime(m_bShowCurrentTime);
    return true;
    break;

  case ACTION_SHOW_OSD:  // Show the OSD
    {
      CGUIWindowOSD *pOSD = (CGUIWindowOSD *)m_gWindowManager.GetWindow(WINDOW_OSD);
      if (pOSD) pOSD->DoModal();
      return true;
    }
    break;

  case ACTION_SHOW_SUBTITLES:
    {
      g_application.m_pPlayer->SetSubtitleVisible(!g_application.m_pPlayer->GetSubtitleVisible());
    }
    return true;
    break;

  case ACTION_NEXT_SUBTITLE:
    {
      if (g_application.m_pPlayer->GetSubtitleCount() == 1)
        return true;

      g_stSettings.m_currentVideoSettings.m_SubtitleStream++;
      if (g_stSettings.m_currentVideoSettings.m_SubtitleStream >= g_application.m_pPlayer->GetSubtitleCount())
        g_stSettings.m_currentVideoSettings.m_SubtitleStream = 0;
      g_application.m_pPlayer->SetSubtitle(g_stSettings.m_currentVideoSettings.m_SubtitleStream);
      return true;
    }
    return true;
    break;

  case ACTION_SUBTITLE_DELAY_MIN:
    g_stSettings.m_currentVideoSettings.m_SubtitleDelay -= 0.1f;
    if (g_stSettings.m_currentVideoSettings.m_SubtitleDelay < -g_advancedSettings.m_videoSubsDelayRange)
      g_stSettings.m_currentVideoSettings.m_SubtitleDelay = -g_advancedSettings.m_videoSubsDelayRange;
    if (g_application.m_pPlayer)
      g_application.m_pPlayer->SetSubTitleDelay(g_stSettings.m_currentVideoSettings.m_SubtitleDelay);
    return true;
    break;
  case ACTION_SUBTITLE_DELAY_PLUS:
    g_stSettings.m_currentVideoSettings.m_SubtitleDelay += 0.1f;
    if (g_stSettings.m_currentVideoSettings.m_SubtitleDelay > g_advancedSettings.m_videoSubsDelayRange)
      g_stSettings.m_currentVideoSettings.m_SubtitleDelay = g_advancedSettings.m_videoSubsDelayRange;
    if (g_application.m_pPlayer)
      g_application.m_pPlayer->SetSubTitleDelay(g_stSettings.m_currentVideoSettings.m_SubtitleDelay);
    return true;
    break;
  case ACTION_AUDIO_DELAY_MIN:
    g_stSettings.m_currentVideoSettings.m_AudioDelay -= 0.1f;
    if (g_stSettings.m_currentVideoSettings.m_AudioDelay < -g_advancedSettings.m_videoAudioDelayRange)
      g_stSettings.m_currentVideoSettings.m_AudioDelay = -g_advancedSettings.m_videoAudioDelayRange;
    if (g_application.m_pPlayer)
      g_application.m_pPlayer->SetAVDelay(g_stSettings.m_currentVideoSettings.m_AudioDelay);
    return true;
    break;
  case ACTION_AUDIO_DELAY_PLUS:
    g_stSettings.m_currentVideoSettings.m_AudioDelay += 0.1f;
    if (g_stSettings.m_currentVideoSettings.m_AudioDelay > g_advancedSettings.m_videoAudioDelayRange)
      g_stSettings.m_currentVideoSettings.m_AudioDelay = g_advancedSettings.m_videoAudioDelayRange;
    if (g_application.m_pPlayer)
      g_application.m_pPlayer->SetAVDelay(g_stSettings.m_currentVideoSettings.m_AudioDelay);
    return true;
    break;
  case ACTION_AUDIO_NEXT_LANGUAGE:
      if (g_application.m_pPlayer->GetAudioStreamCount() == 1)
        return true;

      g_stSettings.m_currentVideoSettings.m_AudioStream++;
      if (g_stSettings.m_currentVideoSettings.m_AudioStream >= g_application.m_pPlayer->GetAudioStreamCount())
        g_stSettings.m_currentVideoSettings.m_AudioStream = 0;
      g_application.m_pPlayer->SetAudioStream(g_stSettings.m_currentVideoSettings.m_AudioStream);    // Set the audio stream to the one selected
    return true;
    break;
  case REMOTE_0:
  case REMOTE_1:
  case REMOTE_2:
  case REMOTE_3:
  case REMOTE_4:
  case REMOTE_5:
  case REMOTE_6:
  case REMOTE_7:
  case REMOTE_8:
  case REMOTE_9:
    ChangetheTimeCode(action.wID);
    return true;
    break;

  case ACTION_ASPECT_RATIO:
    { // toggle the aspect ratio mode (only if the info is onscreen)
      if (m_bShowViewModeInfo)
      {
#ifdef HAS_VIDEO_PLAYBACK
        g_renderManager.SetViewMode(++g_stSettings.m_currentVideoSettings.m_ViewMode);
#endif
      }
      m_bShowViewModeInfo = true;
      m_dwShowViewModeTimeout = timeGetTime();
    }
    return true;
    break;
  case ACTION_SMALL_STEP_BACK:
    {
      int orgpos = (int)g_application.GetTime();
      int triesleft = g_advancedSettings.m_videoSmallStepBackTries;
      int jumpsize = g_advancedSettings.m_videoSmallStepBackSeconds; // secs
      int setpos = (orgpos > jumpsize) ? orgpos - jumpsize : 0; // First jump = 2*jumpsize
      int newpos;
      do
      {
        setpos = (setpos > jumpsize) ? setpos - jumpsize : 0;
        g_application.SeekTime((double)setpos);
        Sleep(g_advancedSettings.m_videoSmallStepBackDelay); // delay to let mplayer finish its seek (in ms)
        newpos = (int)g_application.GetTime();
      }
      while ( (newpos > orgpos - jumpsize) && (setpos > 0) && (--triesleft > 0));

      //Make sure gui items are visible
      g_infoManager.SetDisplayAfterSeek();
    }
    return true;
    break;
  }
  return CGUIWindow::OnAction(action);
}