示例#1
0
static void init_path(char *argv0, char *path_specified)
{//=====================================================

	if(path_specified)
	{
		sprintf(path_home,"%s/espeak-data",path_specified);
		return;
	}

#ifdef PLATFORM_WINDOWS
	HKEY RegKey;
	unsigned long size;
	unsigned long var_type;
	char *p;
	char *env;
	unsigned char buf[sizeof(path_home)-12];

	if(((env = getenv("ESPEAK_DATA_PATH")) != NULL) && ((strlen(env)+12) < sizeof(path_home)))
	{
		sprintf(path_home,"%s\\espeak-data",env);
		if(GetFileLength(path_home) == -2)
			return;   // an espeak-data directory exists in the directory specified by environment variable
	}

	strcpy(path_home,argv0);
	if((p = strrchr(path_home,'\\')) != NULL)
	{
		strcpy(&p[1],"espeak-data");
		if(GetFileLength(path_home) == -2)
			return;   // an espeak-data directory exists in the same directory as the espeak program
	}

	// otherwise, look in the Windows Registry
	buf[0] = 0;
	RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Speech\\Voices\\Tokens\\eSpeak", 0, KEY_READ, &RegKey);
	size = sizeof(buf);
	var_type = REG_SZ;
	RegQueryValueEx(RegKey, "path", 0, &var_type, buf, &size);

	sprintf(path_home,"%s\\espeak-data",buf);
#else
#ifdef PLATFORM_DOS
		strcpy(path_home,PATH_ESPEAK_DATA);
#else
	char *env;
	if((env = getenv("ESPEAK_DATA_PATH")) != NULL)
	{
		snprintf(path_home,sizeof(path_home),"%s/espeak-data",env);
		if(GetFileLength(path_home) == -2)
			return;   // an espeak-data directory exists 
	}

	snprintf(path_home,sizeof(path_home),"%s/espeak-data",getenv("HOME"));
	if(access(path_home,R_OK) != 0)
	{
		strcpy(path_home,PATH_ESPEAK_DATA);
	}
#endif
#endif
}
示例#2
0
static void init_path(const char *path)
{//====================================
#ifdef PLATFORM_WINDOWS
	HKEY RegKey;
	unsigned long size;
	unsigned long var_type;
	char *env;
	unsigned char buf[sizeof(path_home)-13];

	if(path != NULL)
	{
		sprintf(path_home,"%s/espeak-data",path);
		return;
	}

	if((env = getenv("ESPEAK_DATA_PATH")) != NULL)
	{
		sprintf(path_home,"%s/espeak-data",env);
		if(GetFileLength(path_home) == -2)
			return;   // an espeak-data directory exists 
	}
	
#if defined (PATH_ESPEAK_DATA)
	sprintf(path_home,"%s/espeak-data",PATH_ESPEAK_DATA);
	if (GetFileLength(path_home) == -2)
		return;		// espeak-data is a valid directory
#endif

	buf[0] = 0;
	RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Speech\\Voices\\Tokens\\eSpeak", 0, KEY_READ, &RegKey);
	size = sizeof(buf);
	var_type = REG_SZ;
	RegQueryValueExA(RegKey, "path", 0, &var_type, buf, &size);

	sprintf(path_home,"%s\\espeak-data",buf);

#else
	char *env;

	if(path != NULL)
	{
		snprintf(path_home,sizeof(path_home),"%s/espeak-data",path);
		return;
	}

	// check for environment variable
	if((env = getenv("ESPEAK_DATA_PATH")) != NULL)
	{
		snprintf(path_home,sizeof(path_home),"%s/espeak-data",env);
		if(GetFileLength(path_home) == -2)
			return;   // an espeak-data directory exists 
	}

	snprintf(path_home,sizeof(path_home),"%s/espeak-data",getenv("HOME"));
	if(access(path_home,R_OK) != 0)
	{
		strcpy(path_home,PATH_ESPEAK_DATA);
	}
#endif
}
示例#3
0
文件: speech.c 项目: rhdunn/espeak
static int check_data_path(const char *path, int allow_directory)
{
	if (!path) return 0;

	snprintf(path_home, sizeof(path_home), "%s/espeak-ng-data", path);
	if (GetFileLength(path_home) == -EISDIR)
		return 1;

	if (!allow_directory)
		return 0;

	snprintf(path_home, sizeof(path_home), "%s", path);
	return GetFileLength(path_home) == -EISDIR;
}
示例#4
0
bool MD5Model::LoadModel( const std::string &filename )
{
    if ( !fs::exists(filename) )
    {
        std::cerr << "MD5Model::LoadModel: Failed to find file: " << filename << std::endl;
        return false;
    }

    fs::path filePath = filename;
    // store the parent path used for loading images relative to this file.
    fs::path parent_path = filePath.parent_path();

    std::string param;
    std::string junk;   // Read junk from the file

    fs::ifstream file(filename);
    int fileLength = GetFileLength( file );
    assert( fileLength > 0 );

    m_Joints.clear();
    m_Meshes.clear();

    file >> param;

    while ( !file.eof() )
    {
        if ( param == "MD5Version" )
        {
            file >> m_iMD5Version;
            assert( m_iMD5Version == 10 );
        }
        else if ( param == "commandline" )
示例#5
0
static wad_file_t *W_Win32_OpenFile(char *path)
{
    win32_wad_file_t    *result;
    wchar_t             wpath[MAX_PATH + 1];
    HANDLE              handle;

    // Open the file:
    MultiByteToWideChar(CP_OEMCP, 0, path, strlen(path) + 1, wpath, sizeof(wpath));

    handle = CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL, NULL);

    if (handle == INVALID_HANDLE_VALUE)
        return NULL;

    // Create a new win32_wad_file_t to hold the file handle.
    result = Z_Malloc(sizeof(win32_wad_file_t), PU_STATIC, NULL);
    result->wad.file_class = &win32_wad_file;
    result->wad.length = GetFileLength(handle);
    result->handle = handle;

    // Try to map the file into memory with mmap:
    MapFile(result);

    return &result->wad;
}
示例#6
0
static espeak_ng_STATUS ReadPhFile(void **ptr, const char *fname, int *size, espeak_ng_ERROR_CONTEXT *context)
{
	if (!ptr) return EINVAL;

	FILE *f_in;
	unsigned int length;
	char buf[sizeof(path_home)+40];

	sprintf(buf, "%s%c%s", path_home, PATHSEP, fname);
	length = GetFileLength(buf);

	if ((f_in = fopen(buf, "rb")) == NULL)
		return create_file_error_context(context, errno, buf);

	if (*ptr != NULL)
		Free(*ptr);

	if ((*ptr = Alloc(length)) == NULL) {
		fclose(f_in);
		return ENOMEM;
	}
	if (fread(*ptr, 1, length, f_in) != length) {
		int error = errno;
		fclose(f_in);
		Free(*ptr);
		return create_file_error_context(context, error, buf);
	}

	fclose(f_in);
	if (size != NULL)
		*size = length;
	return ENS_OK;
}
示例#7
0
static wad_file_t *W_POSIX_OpenFile(char *path)
{
    posix_wad_file_t *result;
    int handle;

    handle = open(path, 0);

    if (handle < 0)
    {
        return NULL;
    }

    // Create a new posix_wad_file_t to hold the file handle.

    result = Z_Malloc(sizeof(posix_wad_file_t), PU_STATIC, 0);
    result->wad.file_class = &posix_wad_file;
    result->wad.length = GetFileLength(handle);
    result->handle = handle;

    // Try to map the file into memory with mmap:

    MapFile(result, path);

    return &result->wad;
}
示例#8
0
int LoadShaderSource(const char* filename, GLchar** source, unsigned long* len)
{
   FILE *file;
   unsigned int i=0;
   GLchar *txt;
   unsigned long size;

   file = fopen(filename, "rb"); // opens as Binary
   if(!file) 
	   return -1;
   *len = GetFileLength(file);
   fclose(file);
   if(*len <= 0)
	   return -2;
   size = *len;
   file = fopen(filename, "r"); //Opens as ASCII
   *source = (GLchar*)malloc(sizeof(GLchar)*(*len));
   txt = *source;
   if (*source == 0) return -3;   // can't reserve memory
   
    // len isn't always strlen cause some characters are stripped in ascii read...
    // it is important to 0-terminate the real length later, len is just max possible value... 
   txt[size-1] = 0; 

   
   while ((txt[i] = fgetc(file)) != EOF)
        i++;
    
   txt[i] = 0;  // 0-terminate it at the correct position
   fclose(file);
      
   return 0; // No Error
}
示例#9
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool LoadTextFileToExistingBuffer( const std::string& filePath, char* existingBuffer, const size_t& existingBufferSize )
{
    FILE* file;
    fopen_s( &file, filePath.c_str(), "rb" );

    if (!file)
    {
        // freak out
        return false;
    }

    size_t numBytes = GetFileLength( file );

    if (numBytes > existingBufferSize)
        return false;

    size_t numberOfElementsRead = fread( existingBuffer, sizeof( char ), existingBufferSize - 1, file );
    fclose( file );

    existingBuffer[numberOfElementsRead] = '\0';

    // buffer is bigger than data read
    if (numberOfElementsRead < numBytes)
        return false; 

    return true;

}
示例#10
0
void Ide::BuildAndDebug0(const String& srcfile)
{
	if(Build()) {
		One<Host> h = CreateHostRunDir();
		h->ChDir(GetFileFolder(target));
		VectorMap<String, String> bm = GetMethodVars(method);
		String dbg = bm.Get("DEBUGGER", Null);
		if(IsNull(dbg)) {
			if(bm.Get("BUILDER", Null) == "MSC71") {
				String sln = ForceExt(target, ".sln");
				if(GetFileLength(sln) > 0)
					h->Launch("devenv \"" + h->GetHostPath(sln) + "\" "
					// + "\"" + h->GetHostPath(srcfile) + "\"" //TRC, 2011/09/26: wrong devenv argument
					);
				else
					h->Launch("devenv \"" + h->GetHostPath(target)
					//+ "\" \"" + h->GetHostPath(srcfile) //TRC, 2011/09/26: wrong devenv argument
					+ "\" /debugexe "
					);
				return;
			}
			dbg = "gdb";
		}
		else
			h->Launch('\"' + dbg + "\" \""
//			          + h->GetHostPath(srcfile) + ' '
			          + h->GetHostPath(target) + "\"", true);
	}
}
示例#11
0
文件: zi.c 项目: 709889989/unispim
int LoadHZData(const TCHAR *hz_data_name)
{
	int file_length;

	assert(hz_data_name);

	if (share_segment->hz_data_loaded)
		return 1;

	file_length = GetFileLength(hz_data_name);
	if (file_length <= 0)
		return 0;

	hz_data = AllocateSharedMemory(hz_data_share_name, file_length);
	if (!hz_data)
		return 0;

	if ((file_length = LoadFromFile(hz_data_name, hz_data, file_length)) == -1)
	{
		FreeSharedMemory(hz_data_share_name, hz_data);
		Log(LOG_ID, L"汉字信息表文件打开失败。name=%s", hz_data_name);
		return 0;
	}

	if (!file_length)
		return 0;

	share_segment->hz_data_loaded = 1;

	return 1;
}
示例#12
0
int main(int argc, char **argv) {
	int i;

	for (i = 1; i < argc; i++) {
		size_t filesize = GetFileLength(argv[i]);
		FILE *stream = fopen(argv[i], "r");
		unsigned char *text = NULL;
		if (stream == NULL) {
			perror(argv[i]);
			exit(EXIT_FAILURE);
		}

		text = (unsigned char *) malloc(filesize + 1);
		if (text == NULL) {
			espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL);
			exit(EXIT_FAILURE);
		}

		fread(text, 1, filesize, stream);
		text[filesize] = 0;
		fclose(stream);

		LLVMFuzzerTestOneInput(text, filesize);
		free(text);
	}

	return EXIT_SUCCESS;
}
示例#13
0
void DisplayErrorFile(const char *fname)
{//=====================================
	int len;
	FILE *f;
	char *msg;
	wxString msg_string;

	len = GetFileLength(fname);
	if(len > 0)
	{
		if(len > 1500)
			len = 1500;   // restrict length to prevent crash in wxLogMessage()
		msg = (char *)malloc(len+1);
		if(msg != NULL)
		{
			f = fopen(fname,"r");
			len = fread(msg,1, len, f);
			fclose(f);
			msg[len] = 0;
			msg_string = wxString(msg,wxConvUTF8);
			wxLogMessage(msg_string);
			free(msg);
		}
	}
}  // end of DisplayErrorFile
示例#14
0
 FLAC__bool FLACInputStream::eof_callback(
   const FLAC__SeekableStreamDecoder* decoder,
   void* client_data)
 {
   File* file = getFile(client_data);
   return (file->tell() == GetFileLength(file));
 }
示例#15
0
// --------------
// File position
// --------------
TFilePos::TFilePos(const KString& SFileName)
{
	m_FileName		= SFileName;
	m_szOffset		= 0;
	m_szLength		= GetFileLength(m_FileName);
	m_bPlainFile	= true;
}
static int ReadPhFile(char **ptr, const char *fname)
{//=================================================
	FILE *f_in;
	char *p;
	unsigned int  length;
	char buf[200];

	sprintf(buf,"%s%c%s",path_home,PATHSEP,fname);
	length = GetFileLength(buf);
	
	if((f_in = fopen(buf,"rb")) == NULL)
	{
		fprintf(stderr,"Can't read data file: '%s'\n",buf);
		return(1);
	}

	if(*ptr != NULL)
		Free(*ptr);
		
	if((p = Alloc(length)) == NULL)
	{
		fclose(f_in);
		return(-1);
	}
	if(fread(p,1,length,f_in) != length)
	{
		fclose(f_in);
		return(-1);
	}
	*ptr = p;
	fclose(f_in);
	return(0);
}  //  end of ReadPhFile
示例#17
0
int TXTFAM::Cardinality(PGLOBAL g)
  {
  if (g) {
    int card = -1;
    int len = GetFileLength(g);

    if (len >= 0) {
      if (Padded && Blksize) {
        if (!(len % Blksize))
          card = (len / Blksize) * Nrec;
        else
          sprintf(g->Message, MSG(NOT_FIXED_LEN), To_File, len, Lrecl);

      } else {
        if (!(len % Lrecl))
          card = len / (int)Lrecl;           // Fixed length file
        else
          sprintf(g->Message, MSG(NOT_FIXED_LEN), To_File, len, Lrecl);

      } // endif Padded

      if (trace)
        htrc(" Computed max_K=%d Filen=%d lrecl=%d\n", 
              card, len, Lrecl);

    } else
      card = 0;

    // Set number of blocks for later use
    Block = (card > 0) ? (card + Nrec - 1) / Nrec : 0;
    return card;
  } else
    return 1;

  } // end of Cardinality
示例#18
0
static char *ReadPhFile(void *ptr, const char *fname, int *size)
{//=============================================================
	FILE *f_in;
	char *p;
	unsigned int  length;
	char buf[sizeof(path_home)+40];

	sprintf(buf,"%s%c%s",path_home,PATHSEP,fname);
	length = GetFileLength(buf);

	if((f_in = fopen(buf,"rb")) == NULL)
	{
		fprintf(stderr,"Can't read data file: '%s'\n",buf);
		return(NULL);
	}

	if(ptr != NULL)
		Free(ptr);

	if((p = Alloc(length)) == NULL)
	{
		fclose(f_in);
		return(NULL);
	}
	if(fread(p,1,length,f_in) != length)
	{
		fclose(f_in);
		return(NULL);
	}

	fclose(f_in);
	if(size != NULL)
		*size = length;
	return(p);
}  //  end of ReadPhFile
示例#19
0
//+------------------------------------------------------------------+
//| Cut the file                                                     |
//+------------------------------------------------------------------+
void CLogger::Cut(void)
  {
   FILE *in,*out;
   char *buf,*cp,tmp[256];
   int   len;
//---- закроем файл на всякий случай
   m_sync.Lock();
   FinalizeDay();
//---- откроем файл заново, проверим размер
   _snprintf(tmp,sizeof(tmp)-1,"%s.log",ExtProgramPath);
   if((in=fopen(tmp,"rb"))==NULL)        {             m_sync.Unlock(); return; }
   len=GetFileLength(in);
   if(len<300000)                        { fclose(in); m_sync.Unlock(); return; }
//---- allocate 100 Kb for last messages and read them
   if((buf=(char*)malloc(102401))==NULL) { fclose(in); m_sync.Unlock(); return; }
   fseek(in,len-102400,SEEK_SET);
   fread(buf,102400,1,in); buf[102400]=0;
   fclose(in);
//---- reopen log-file and write last messages
   if((out=fopen(tmp,"wb"))!=NULL)
     {
      if((cp=strstr(buf,"\n"))!=NULL) fwrite(cp+1,strlen(cp+1),1,out);
      fclose(out);
     }
   free(buf);
//----
   m_sync.Unlock();
  }
示例#20
0
bool MD5Animation::LoadAnimation( const std::string& filename )
{
    if ( !fs::exists(filename) )
    {
        std::cerr << "MD5Animation::LoadAnimation: Failed to find file: " << filename << std::endl;
        return false;
    }

    fs::path filePath = filename;

    std::string param;
    std::string junk;   // Read junk from the file

    fs::ifstream file(filename);
    int fileLength = GetFileLength( file );
    assert( fileLength > 0 );

    m_JointInfos.clear();
    m_Bounds.clear();
    m_BaseFrames.clear();
    m_Frames.clear();
    m_AnimatedSkeleton.m_Joints.clear();
    m_iNumFrames = 0;

    file >> param;

    while( !file.eof() )
    {
        if ( param == "MD5Version" )
        {
            file >> m_iMD5Version;
            assert( m_iMD5Version == 10 );
        }
        else if ( param == "commandline" )
示例#21
0
static int SetVoiceScores(espeak_VOICE *voice_select, espeak_VOICE **voices, int control)
{
	// control: bit0=1  include mbrola voices
	int ix;
	int score;
	int nv; // number of candidates
	int n_parts = 0;
	int lang_len = 0;
	espeak_VOICE *vp;
	char language[80];
	char buf[sizeof(path_home)+80];

	// count number of parts in the specified language
	if ((voice_select->languages != NULL) && (voice_select->languages[0] != 0)) {
		n_parts = 1;
		lang_len = strlen(voice_select->languages);
		for (ix = 0; (ix <= lang_len) && ((unsigned)ix < sizeof(language)); ix++) {
			if ((language[ix] = tolower(voice_select->languages[ix])) == '-')
				n_parts++;
		}
	}

	if ((n_parts == 1) && (control & 1)) {
		if (strcmp(language, "mbrola") == 0) {
			language[2] = 0; // truncate to "mb"
			lang_len = 2;
		}

		sprintf(buf, "%s/voices/%s", path_home, language);
		if (GetFileLength(buf) == -2) {
			// A subdirectory name has been specified.  List all the voices in that subdirectory
			language[lang_len++] = PATHSEP;
			language[lang_len] = 0;
			n_parts = -1;
		}
	}

	// select those voices which match the specified language
	nv = 0;
	for (ix = 0; ix < n_voices_list; ix++) {
		vp = voices_list[ix];

		if (((control & 1) == 0) && (memcmp(vp->identifier, "mb/", 3) == 0))
			continue;

		if ((score = ScoreVoice(voice_select, language, n_parts, lang_len, voices_list[ix])) > 0) {
			voices[nv++] = vp;
			vp->score = score;
		}
	}
	voices[nv] = NULL; // list terminator

	if (nv == 0)
		return 0;

	// sort the selected voices by their score
	qsort(voices, nv, sizeof(espeak_VOICE *), (int(__cdecl *)(const void *, const void *))VoiceScoreSorter);

	return nv;
}
void CClientScriptTransfer::Send(SystemAddress systemAddress)
{
	/*char file[128];
	strcpy(file, "C:\\Users\\JeNkStA\\Desktop\\jessicac.jpg");*/
	m_pNetGame->GetRakServer()->GetRakPeer()->SetSplitMessageProgressInterval(9);
	m_pNetGame->GetRakServer()->GetRakPeer()->AttachPlugin(&m_fileListTransfer);
	m_fileListTransfer.SetCallback(this);
	char szPath[MAX_PATH];
	StringList::iterator iter;
	for(iter = m_pClientScripts.begin(); iter != m_pClientScripts.end(); iter++)
	{
		sprintf(szPath, ".\\clientscripts\\%s", (char*)(*iter));
		struct stat stFileInfo;
		if(stat(szPath, &stFileInfo) == 0)
		{
			unsigned int fileLength = GetFileLength(szPath);
			m_fileList.AddFile((*iter), szPath, 0, fileLength, fileLength, FileListNodeContext(0, 0), true);
		}
		else
		{
			LogPrintf("Warning: Clientscript %s does not exist.", (char*)(*iter));
		}
	}
	m_fileListTransfer.Send(&m_fileList, m_pNetGame->GetRakServer()->GetRakPeer(), systemAddress, 0, HIGH_PRIORITY, 0, false, &m_incrementalReadInterface, 50000);
}
示例#23
0
 FLAC__SeekableStreamDecoderLengthStatus FLACInputStream::length_callback(
   const FLAC__SeekableStreamDecoder* decoder,
   FLAC__uint64* stream_length,
   void* client_data)
 {
   *stream_length = GetFileLength(getFile(client_data));
   return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
 }
示例#24
0
long LogOpenQuiet( char *filename, __int64 *filelen )
{
	char	rawfileName[256];
	long	hnd = 0;

	DateFixFilename( filename, rawfileName );

	// Check if we trying to open a shortcut
	if ( IsShortCut( rawfileName ) ){
		char linkpath[256];
		mystrcpy( linkpath, rawfileName );
#if DEF_WINDOWS
		GetShortCut( linkpath, rawfileName );
#endif
	}

	// Now see if the we want to open a short cut to a URL
	if ( IsURLShortCut( rawfileName ) ){
		char linkpath[256];
		mystrcpy( linkpath, rawfileName );
#if DEF_WINDOWS
		GetURLShortCut( linkpath, rawfileName );
#endif
	}

	// Check for a just a plain URL
	if ( IsURL( rawfileName ) ){
		StatusSetID( IDS_REMOTELOG , strrchr( rawfileName,'/' ) );
		hnd = (long)INetOpen( rawfileName, filelen );
		return hnd;
	}

	// Check other types
	char format[100];
	// determine if its PKZIP file and if so... dont open it, YET
	if ( IsFileInvalid( rawfileName, format ) )
		return 0;

#ifndef DEF_MAC
	if ( IsPKZIP( rawfileName ) )
		hnd = (long)UnzipOpen( rawfileName, NULL );
	else
#ifdef _BZLIB_H
	if ( aIsBzFile( rawfileName ) )		// PLEASE DO THIS SOON FOR MAC.... at least for manual completeness, hey OSX people will love it.
		hnd = (long)BZ2_bzopen( rawfileName, "rb" );
	else 
#endif
#endif
	{
		hnd = (long)gzopen( rawfileName, "rb" );
	}

	if ( filelen && hnd )
		*filelen = GetFileLength( rawfileName );

	return hnd;
}
示例#25
0
i64 TFILEPtr::length() const {
#ifdef _win32_
    FHANDLE fd = (FHANDLE)_get_osfhandle(fileno(m_file));
#else
    FHANDLE fd = fileno(m_file);
#endif
    i64 rv = GetFileLength(fd);
    if (rv < 0)
        ythrow yexception() << "TFILEPtr::length() " <<  ~Name << ": " << LastSystemErrorText();
    return rv;
}
示例#26
0
Lux::Core::FileInfo* Lux::Core::FileHandler::LoadFileInMemory(const String a_Path)
{
    FileInfo* retInfo = nullptr;

    OpenedFile* filePtr = OpenFile(a_Path, FILE_OPEN_READ);
    int64 fileSize = GetFileLength(filePtr);

    retInfo = new FileInfo((unsigned int)fileSize);
    LoadFileDataInto(filePtr, retInfo);
    CloseOpenedFile(filePtr);
    return retInfo;
}
示例#27
0
long GetLastPage( char *filename, long fpos, char *data, long numlines )
{
	long fp;
	long length, len;
	long lines = 0;

	length = (long)GetFileLength( filename );

	if ( (fp = (long)gzopen( filename, "r" )) ){
		char c, *p, *start;
		char *mem;
		long count=0;
		lines = numlines;

		mem = (char*)malloc( (2+numlines)*LINELEN );
		memset( mem, 0, (2+numlines)*LINELEN );

		if ( fpos < 0 )
			fpos = 0;

		gzseek( (gzFile)fp, fpos, SEEK_SET );
		
		//OutDebugs( "In GetLastPage() at fpos %d trying to read %d bytes from %s", fpos, numlines*LINELEN, filename );
		if( (len = gzread( (gzFile)fp, mem, numlines*LINELEN ) ) )
		{
			//OutDebugs( "Read %d bytes", len );
			mem[len] = 0;
			if ( fpos == 0 ) // Last Page is the first page too, only 1 page...
				start = mem;
			else
			{
				p = mem + len -1;
				start = p;
				lines++;
				while( lines>0 && p>mem && (c=*p) ){
					if( c=='\r' || c=='\n' ){
						lines--;
						start = p+1;
						p--;
						if( *p=='\r' ) p--;
					} else
						p--;
				}
			}
			len = (mem+len) - start;
			memcpy( data, start, len+1 );
		}
		gzclose( (gzFile)fp );
		free( mem );
	}
	return length;
}
示例#28
0
文件: ide.cpp 项目: kolyden/mirror
void Ide::IdePaste(String& data)
{
	data.Clear();
	if(AcceptFiles(Clipboard())) {
		Vector<String> s = GetFiles(Clipboard());
		for(int i = 0; i < s.GetCount(); i++)
			if(FileExists(s[i]) && IsTextFile(s[i], 10000)) {
				int64 len = GetFileLength(s[i]);
				if(len > 5000000 || data.GetLength() + len < 5000000)
					data.Cat(LoadFile(s[i]));
			}
	}
}
示例#29
0
文件: BZDoc.cpp 项目: tnzk/bz
void CBZDoc::Serialize(CArchive& ar)
{
    MEMORYSTATUS ms;
    GlobalMemoryStatus(&ms);

    CFile *pFile = ar.GetFile();
    ar.Flush();

    if (ar.IsLoading())	{
        // TODO: add loading code here
        m_dwTotal = GetFileLength(pFile);
#ifdef FILE_MAPPING
        if(IsFileMapping()) {
            if(!MapView()) return;
        } else
#endif //FILE_MAPPING
        {
            if(!(m_pData = (LPBYTE)MemAlloc(m_dwTotal))) {
                AfxMessageBox(IDS_ERR_MALLOC);
                return;
            }
            DWORD len = pFile->Read(m_pData, m_dwTotal);
            if(len < m_dwTotal) {
                AfxMessageBox(IDS_ERR_READFILE);
                MemFree(m_pData);	// ###1.61
                m_pData = NULL;
                return;
            }
            m_bReadOnly = options.bReadOnlyOpen;
        }
    } else {
        // TODO: add storing code here
#ifdef FILE_MAPPING
        if(IsFileMapping()) {
            BOOL bResult = (m_pMapStart) ? ::FlushViewOfFile(m_pMapStart, m_dwMapSize) : ::FlushViewOfFile(m_pData, m_dwTotal);
            if(!bResult) {
                ErrorMessageBox();
            }
        } else
#endif //FILE_MAPPING
            pFile->Write(m_pData, m_dwTotal);
        m_dwUndoSaved = m_dwUndo;		// ###1.54
        TouchDoc();
        /*		if(m_pUndo) {
        			MemFree(m_pUndo);
        			m_pUndo = NULL;
        		}
        */
    }
}
示例#30
0
bool Player_impl::PlayFrom(long pos)
{
    TStreamTime start_time;
    start_time.ms = pos;

    TStreamTime end_time;
    end_time.ms = GetFileLength();
    
    int ret = player_->PlayLoop(tfMillisecond, &start_time, tfMillisecond, &end_time, 1, 0);
    if( ret == 1){return true;}
    else{
        LOG(logERROR) << "libzplay::PlayLoop failed error info:" << player_->GetError() << std::endl;
        return false;
    }
}