long
SeekResFile (uio_Stream *fp, long offset, int whence)
{
	long retval;

	retval = uio_fseek (fp, offset, whence);

	return (retval);
}
示例#2
0
int
sdluio_seek (SDL_RWops *context, int offset, int whence) {
	if (uio_fseek ((uio_Stream *) context->hidden.unknown.data1, offset,
				whence) == -1)
	{
		SDL_SetError ("Error seeking in uio_Stream: %s",
				strerror(errno));
		return -1;
	}
	return uio_ftell ((uio_Stream *) context->hidden.unknown.data1);
}
示例#3
0
static uint32
wava_Seek (THIS_PTR, uint32 pcm_pos)
{
	TFB_WaveSoundDecoder* wava = (TFB_WaveSoundDecoder*) This;

	if (pcm_pos > wava->max_pcm)
		pcm_pos = wava->max_pcm;
	wava->cur_pcm = pcm_pos;
	uio_fseek (wava->fp,
			wava->data_ofs + pcm_pos * wava->FmtHdr.BlockAlign,
			SEEK_SET);

	return pcm_pos;
}
示例#4
0
static bool
wava_Open (THIS_PTR, uio_DirHandle *dir, const char *filename)
{
	TFB_WaveSoundDecoder* wava = (TFB_WaveSoundDecoder*) This;
	WAVFileHdr_Struct FileHdr;
	WAVChunkHdr_Struct ChunkHdr;

	wava->fp = uio_fopen (dir, filename, "rb");
	if (!wava->fp)
	{
		wava->last_error = errno;
		return false;
	}

	wava->data_size = 0;
	wava->data_ofs = 0;

	// read wave header
	if (!wava_readFileHeader (wava, &FileHdr))
	{
		wava->last_error = errno;
		wava_Close (This);
		return false;
	}
	if (FileHdr.Id != RIFF || FileHdr.Type != WAVE)
	{
		log_add (log_Warning, "wava_Open(): "
				"not a wave file, ID 0x%08x, Type 0x%08x",
				FileHdr.Id, FileHdr.Type);
		wava_Close (This);
		return false;
	}

	for (FileHdr.Size = ((FileHdr.Size + 1) & ~1) - 4; FileHdr.Size != 0;
			FileHdr.Size -= (((ChunkHdr.Size + 1) & ~1) + 8))
	{
		if (!wava_readChunkHeader (wava, &ChunkHdr))
		{
			wava->last_error = errno;
			wava_Close (This);
			return false;
		}

		if (ChunkHdr.Id == FMT)
		{
			if (!wava_readFormatHeader (wava, &wava->FmtHdr))
			{
				wava->last_error = errno;
				wava_Close (This);
				return false;
			}
			uio_fseek (wava->fp, ChunkHdr.Size - 16, SEEK_CUR);
		}
		else
		{
			if (ChunkHdr.Id == DATA)
			{
				wava->data_size = ChunkHdr.Size;
				wava->data_ofs = uio_ftell (wava->fp);
			}
			uio_fseek (wava->fp, ChunkHdr.Size, SEEK_CUR);
		}

		uio_fseek (wava->fp, ChunkHdr.Size & 1, SEEK_CUR);
	}

	if (!wava->data_size || !wava->data_ofs)
	{
		log_add (log_Warning, "wava_Open(): bad wave file,"
				" no DATA chunk found");
		wava_Close (This);
		return false;
	}

	if (wava->FmtHdr.Format == 0x0001)
	{
		This->format = (wava->FmtHdr.Channels == 1 ?
				(wava->FmtHdr.BitsPerSample == 8 ?
					wava_formats->mono8 : wava_formats->mono16)
				:
				(wava->FmtHdr.BitsPerSample == 8 ?
					wava_formats->stereo8 : wava_formats->stereo16)
				);
		This->frequency = wava->FmtHdr.SamplesPerSec;
	} 
	else
	{
		log_add (log_Warning, "wava_Open(): unsupported format %x",
				wava->FmtHdr.Format);
		wava_Close (This);
		return false;
	}

	uio_fseek (wava->fp, wava->data_ofs, SEEK_SET);
	wava->max_pcm = wava->data_size / wava->FmtHdr.BlockAlign;
	wava->cur_pcm = 0;
	This->length = (float) wava->max_pcm / wava->FmtHdr.SamplesPerSec;
	wava->last_error = 0;

	return true;
}
示例#5
0
void *
_GetCelData (uio_Stream *fp, DWORD length)
{
	int cel_total, cel_index, n;
	DWORD opos;
	char CurrentLine[1024], filename[PATH_MAX];
	TFB_Canvas *img;
	AniData *ani;
	DRAWABLE Drawable;
	uio_MountHandle *aniMount = 0;
	uio_DirHandle *aniDir = 0;
	uio_Stream *aniFile = 0;
	
	opos = uio_ftell (fp);

	{
		char *s1, *s2;
		char aniDirName[PATH_MAX];			
		const char *aniFileName;
		uint8 buf[4] = { 0, 0, 0, 0 };
		uint32 header;

		if (_cur_resfile_name == 0
				|| (((s2 = 0), (s1 = strrchr (_cur_resfile_name, '/')) == 0)
						&& (s2 = strrchr (_cur_resfile_name, '\\')) == 0))
		{
			n = 0;
		}
		else
		{
			if (s2 > s1)
				s1 = s2;
			n = s1 - _cur_resfile_name + 1;
		}

		uio_fread(buf, 4, 1, fp);
		header = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
 		if (_cur_resfile_name && header == 0x04034b50)
		{
			// zipped ani file
			if (n)
			{
				strncpy (aniDirName, _cur_resfile_name, n - 1);
				aniDirName[n - 1] = 0;
				aniFileName = _cur_resfile_name + n;
			}
			else
			{
				strcpy(aniDirName, ".");
				aniFileName = _cur_resfile_name;
			}
			aniDir = uio_openDir (repository, aniDirName, 0);
			aniMount = uio_mountDir (repository, aniDirName, uio_FSTYPE_ZIP,
							aniDir, aniFileName, "/", autoMount,
							uio_MOUNT_RDONLY | uio_MOUNT_TOP,
							NULL);
			aniFile = uio_fopen (aniDir, aniFileName, "r");
			opos = 0;
			n = 0;
		}
		else
		{
			// unpacked ani file
			strncpy (filename, _cur_resfile_name, n);
			aniFile = fp;
			aniDir = contentDir;
		}
	}

	cel_total = 0;
	uio_fseek (aniFile, opos, SEEK_SET);
	while (uio_fgets (CurrentLine, sizeof (CurrentLine), aniFile))
	{
		++cel_total;
	}

	img = HMalloc (sizeof (TFB_Canvas) * cel_total);
	ani = HMalloc (sizeof (AniData) * cel_total);
	if (!img || !ani)
	{
		log_add (log_Warning, "Couldn't allocate space for '%s'", _cur_resfile_name);
		if (aniMount)
		{
			uio_fclose(aniFile);
			uio_closeDir(aniDir);
			uio_unmountDir(aniMount);
		}
		HFree (img);
		HFree (ani);
		return NULL;
	}

	cel_index = 0;
	uio_fseek (aniFile, opos, SEEK_SET);
	while (uio_fgets (CurrentLine, sizeof (CurrentLine), aniFile) && cel_index < cel_total)
	{
		sscanf (CurrentLine, "%s %d %d %d %d", &filename[n], 
			&ani[cel_index].transparent_color, &ani[cel_index].colormap_index, 
			&ani[cel_index].hotspot_x, &ani[cel_index].hotspot_y);
	
		img[cel_index] = TFB_DrawCanvas_LoadFromFile (aniDir, filename);
		if (img[cel_index] == NULL)
		{
			const char *err;

			err = TFB_DrawCanvas_GetError ();
			log_add (log_Warning, "_GetCelData: Unable to load image!");
			if (err != NULL)
				log_add (log_Warning, "Gfx Driver reports: %s", err);
		}
		else
		{
			++cel_index;
		}

		if ((int)uio_ftell (aniFile) - (int)opos >= (int)length)
			break;
	}

	Drawable = NULL;
	if (cel_index && (Drawable = AllocDrawable (cel_index)))
	{
		if (!Drawable)
		{
			while (cel_index--)
				TFB_DrawCanvas_Delete (img[cel_index]);

			HFree (Drawable);
			Drawable = NULL;
		}
		else
		{
			FRAME FramePtr;

			Drawable->Flags = WANT_PIXMAP;
			Drawable->MaxIndex = cel_index - 1;

			FramePtr = &Drawable->Frame[cel_index];
			while (--FramePtr, cel_index--)
				process_image (FramePtr, img, ani, cel_index);
		}
	}

	if (Drawable == NULL)
		log_add (log_Warning, "Couldn't get cel data for '%s'",
				_cur_resfile_name);

	if (aniMount)
	{
		uio_fclose(aniFile);
		uio_closeDir(aniDir);
		uio_unmountDir(aniMount);
	}

	HFree (img);
	HFree (ani);
	return Drawable;
}
示例#6
0
static BOOL
moda_uioReader_Seek (MREADER* reader, long offset, int whence)
{
    return uio_fseek (((MUIOREADER*)reader)->file, offset, whence);
}
示例#7
0
static bool
wava_Open (THIS_PTR, uio_DirHandle *dir, const char *filename)
{
	TFB_WaveSoundDecoder* wava = (TFB_WaveSoundDecoder*) This;
	wave_FileHeader fileHdr;
	wave_ChunkHeader chunkHdr;

	wava->fp = uio_fopen (dir, filename, "rb");
	if (!wava->fp)
	{
		wava->last_error = errno;
		return false;
	}

	wava->data_size = 0;
	wava->data_ofs = 0;

	// read wave header
	if (!wava_readFileHeader (wava, &fileHdr))
	{
		wava->last_error = errno;
		wava_Close (This);
		return false;
	}
	if (fileHdr.id != wave_RiffID || fileHdr.type != wave_WaveID)
	{
		log_add (log_Warning, "wava_Open(): "
				"not a wave file, ID 0x%08x, Type 0x%08x",
				fileHdr.id, fileHdr.type);
		wava_Close (This);
		return false;
	}

	for (fileHdr.size = ((fileHdr.size + 1) & ~1) - 4; fileHdr.size != 0;
			fileHdr.size -= (((chunkHdr.size + 1) & ~1) + 8))
	{
		if (!wava_readChunkHeader (wava, &chunkHdr))
		{
			wava_Close (This);
			return false;
		}

		if (chunkHdr.id == wave_FmtID)
		{
			if (!wava_readFormatHeader (wava, &wava->fmtHdr))
			{
				wava_Close (This);
				return false;
			}
			uio_fseek (wava->fp, chunkHdr.size - 16, SEEK_CUR);
		}
		else
		{
			if (chunkHdr.id == wave_DataID)
			{
				wava->data_size = chunkHdr.size;
				wava->data_ofs = uio_ftell (wava->fp);
			}
			uio_fseek (wava->fp, chunkHdr.size, SEEK_CUR);
		}

		// 2-align the file ptr
		// XXX: I do not think this is necessary in WAVE files;
		//   possibly a remnant of ported AIFF reader
		uio_fseek (wava->fp, chunkHdr.size & 1, SEEK_CUR);
	}

	if (!wava->data_size || !wava->data_ofs)
	{
		log_add (log_Warning, "wava_Open(): bad wave file,"
				" no DATA chunk found");
		wava_Close (This);
		return false;
	}

	if (wava->fmtHdr.format != 0x0001)
	{	// not a PCM format
		log_add (log_Warning, "wava_Open(): unsupported format %x",
				wava->fmtHdr.format);
		wava_Close (This);
		return false;
	}
	if (wava->fmtHdr.channels != 1 && wava->fmtHdr.channels != 2)
	{
		log_add (log_Warning, "wava_Open(): unsupported number of channels %u",
				(unsigned)wava->fmtHdr.channels);
		wava_Close (This);
		return false;
	}

	This->format = (wava->fmtHdr.channels == 1 ?
			(wava->fmtHdr.bitsPerSample == 8 ?
				wava_formats->mono8 : wava_formats->mono16)
			:
			(wava->fmtHdr.bitsPerSample == 8 ?
				wava_formats->stereo8 : wava_formats->stereo16)
			);
	This->frequency = wava->fmtHdr.samplesPerSec;

	uio_fseek (wava->fp, wava->data_ofs, SEEK_SET);
	wava->max_pcm = wava->data_size / wava->fmtHdr.blockAlign;
	wava->cur_pcm = 0;
	This->length = (float) wava->max_pcm / wava->fmtHdr.samplesPerSec;
	wava->last_error = 0;

	return true;
}
示例#8
0
static int
debugCmdFwriteTest(DebugContext *debugContext, int argc, char *argv[]) {
    uio_Stream *stream;
    const char testString[] = "0123456789\n";

    if (argc != 2) {
        fprintf(debugContext->err, "Invalid number of arguments.\n");
        return 1;
    }

    stream = uio_fopen(debugContext->cwd, argv[1], "w+b");
    if (stream == NULL) {
        fprintf(debugContext->err, "Could not open file: %s\n",
                strerror(errno));
        goto err;
    }

    if (uio_fwrite(testString, strlen(testString), 1, stream) != 1) {
        fprintf(debugContext->err, "uio_fwrite() failed: %s\n",
                strerror(errno));
        goto err;
    }
    if (uio_fputs(testString, stream) == EOF) {
        fprintf(debugContext->err, "uio_fputs() failed: %s\n",
                strerror(errno));
        goto err;
    }
    if (uio_fseek(stream, 15, SEEK_SET) != 0) {
        fprintf(debugContext->err, "uio_fseek() failed: %s\n",
                strerror(errno));
        goto err;
    }
    if (uio_fputc('A', stream) != 'A') {
        fprintf(debugContext->err, "uio_fputc() failed: %s\n",
                strerror(errno));
        goto err;
    }
    if (uio_fseek(stream, 0, SEEK_SET) != 0) {
        fprintf(debugContext->err, "uio_fseek() failed: %s\n",
                strerror(errno));
        goto err;
    }
    {
        char buf[6];
        char *ptr;
        int i;
        i = 1;
        while (1) {
            ptr = uio_fgets(buf, sizeof buf, stream);
            if (ptr == NULL)
                break;
            fprintf(debugContext->out, "%d: [%s]\n", i, ptr);
            i++;
        }
        if (uio_ferror(stream)) {
            fprintf(debugContext->err, "uio_fgets() failed: %s\n",
                    strerror(errno));
            goto err;
        }
        uio_clearerr(stream);
    }
    if (uio_fseek(stream, 4, SEEK_END) != 0) {
        fprintf(debugContext->err, "uio_fseek() failed: %s\n",
                strerror(errno));
        goto err;
    }
    {
        char buf[2000];
        memset(buf, 'Q', sizeof buf);
        if (uio_fwrite(buf, 100, 20, stream) != 20) {
            fprintf(debugContext->err, "uio_fwrite() failed: %s\n",
                    strerror(errno));
            goto err;
        }
    }
    if (uio_fseek(stream, 5, SEEK_SET) != 0) {
        fprintf(debugContext->err, "uio_fseek() failed: %s\n",
                strerror(errno));
        goto err;
    }
    if (uio_fputc('B', stream) != 'B') {
        fprintf(debugContext->err, "uio_fputc() failed: %s\n",
                strerror(errno));
        goto err;
    }
    uio_fclose(stream);
    return 0;
err:
    uio_fclose(stream);
    return 1;
}