Exemplo n.º 1
0
void getBackgroundStatus(char *url)
/* fetch status as the latest complete html block available */
{
char *html = NULL;
if (fileSize(url)==0)
    {
    htmlOpen("Background Status");
    errAbort("No output found. Expecting output in [%s].", url);
    htmlClose();
    return;
    }

readInGulp(url, &html, NULL);
int numLines = chopString(html, "\n", NULL, 1000000);
char **lines = NULL;
AllocArray(lines, numLines);
chopString(html, "\n", lines, numLines);
int end;
for (end=numLines-1; end >= 0 && ! (endsWith(lines[end], "</html>") || endsWith(lines[end], "</HTML>")) ; --end)
    /* do nothing */ ;
if (end < 0)
    {
    htmlOpen("Background Status");
    errAbort("No complete html found");
    htmlClose();
    return;
    }
int start;
for (start=end; start >= 0 && ! (startsWith("<html>", lines[start]) || startsWith("<HTML>", lines[start])) ; --start)
    /* do nothing */ ;
if (start < 0)
    {
    htmlOpen("Background Status");
    errAbort("No html start tag found");
    htmlClose();
    return;
    }
puts("Content-Type: text/html\n");
int line;
boolean autoRefreshFound = FALSE;
boolean successfullyUploaded = FALSE;
for (line=start; line <= end; line++)
    {
    puts(lines[line]);
    if (startsWith("setTimeout(\"location = location;", lines[line]))
	autoRefreshFound = TRUE;
    if (startsWith("Output has been successfully uploaded", lines[line]))
	successfullyUploaded = TRUE;
    }
// if it looks like the background is no longer running, 
// include the .err stdout output for more informative problem message
char urlErr[512];
char *textErr = NULL;
safef(urlErr, sizeof urlErr, "%s.err", url);
if (!autoRefreshFound && !successfullyUploaded && (fileSize(urlErr) > 0))
    {
    readInGulp(urlErr, &textErr, NULL);
    printf("%s", textErr);
    }
}
Exemplo n.º 2
0
main(int argc, char *argv[])
{
    register char *p1;
    register char *p2;
    register int i, count;
    int f1, f2;
    int l1, l2;
    int n1, n2, n;
    int xval, base, len;
    char buf1[BUFSIZ];
    char buf2[BUFSIZ];

    if (argc != 3) {
	fprintf(stderr, "Usage: %s <file1> <file2>\n", argv[0]);
	exit(1);
    }

    f1 = openF(argv[1]);
    f2 = openF(argv[2]);

    l1 = fileSize(f1);
    l2 = fileSize(f2);
    if (l1 < l2) {
	len = l1;
	base = l2;
	count = l2 - l1;
    } else {
	len = l2;
	base = l1;
	count = l1 - l2;
    }

    i = 0;
    while (i < len) {
	n1 = read(f1, buf1, BUFSIZ);
	n2 = read(f2, buf2, BUFSIZ);
	if (n1 < n2)
	    n = i + n1;
	else
	    n = i + n2;
	p1 = buf1;
	p2 = buf2;
	while (i < n) {
	    if (*p1++ != *p2++)
		count++;
	    i++;
	}
    }

    if (count) {
	printf("%d/%d(%f)\n", count, base, ((double) count) / base);
	xval = 2;
    } else
	xval = 0;

    exit(xval);

}
Exemplo n.º 3
0
void QXmppTransferOutgoingJob::_q_disconnected()
{
    if (d->state == QXmppTransferJob::FinishedState)
        return;

    if (fileSize() && d->done != fileSize())
        terminate(QXmppTransferJob::ProtocolError);
    else
        terminate(QXmppTransferJob::NoError);
}
static boolean verifySeqExtFile(struct seqFields *seq,
                                struct extFileTbl* extFileTbl,
                                boolean checkExtSeqRecs,
                                char* gbdbMapToCurrent)
/* verify a seq table information with it's extFile entry. return true
 * if found in extFile table. */
{
#if 0 /* FIXME: for disabled code below */
int mapLen = (gbdbMapToCurrent != NULL) ? strlen(gbdbMapToCurrent) : 0;
#endif
char* extPath;
boolean badSeq = FALSE;
struct extFile* extFile = getExtFile(seq->acc, extFileTbl, seq->gbExtFile);
if (extFile == NULL)
    return FALSE; /* all that can be checked */

/* now, sanity check seq with extFile */
if ((seq->file_offset+seq->file_size) > extFile->size)
    {
    gbError("%s: gbSeq.file_offset+gbSeq.file_size > gbExtFile.size", seq->acc);
    badSeq = TRUE;
    }

/* map path to local directory if requested */
extPath = extFile->path;
#if 0 /* FIXME: load stores full path when redirected */
if ((gbdbMapToCurrent != NULL) && startsWith(gbdbMapToCurrent, extPath)
    && (extPath[mapLen] == '/'))
    extPath += mapLen+1;
#endif

/* check readability and size of file. if found unreadable before, don't repeat
 * message or rest of tests. */
if (alreadyReported(missingExtFiles, extPath))
    return TRUE;  /* already reported, nothing more to do */

if (access(extPath, R_OK) < 0)
    {
    gbError("%s: extFile does not exist or is not readable: %s",
            seq->acc, extPath);
    flagReported(missingExtFiles, extPath);
    badSeq = TRUE;
    }
else if (fileSize(extPath) != extFile->size)
    {
    gbError("%s: disk file size (%lld) does not match ext.size (%lld): %s",
            seq->acc, (long long)fileSize(extPath), (long long)extFile->size, extPath);
    flagReported(missingExtFiles, extPath);
    badSeq = TRUE;
    }

if (!badSeq && checkExtSeqRecs)
    checkExtRecord(seq, extPath);
return TRUE;
}
Exemplo n.º 5
0
int main(int argc, char* argv[]){
	FILE * open_file;
	
	open_file = fopen(argv[1], "rb");
	
	
	splitFiles(open_file, fileSize(open_file) , findSizeofPieces(fileSize(open_file)));
	fclose(open_file);
	return 0;

}
Exemplo n.º 6
0
void loadLinux(void){
	u32 size = fileSize(LINUXIMAGE_FILENAME);
	if(!size){
		shutdown();
	}
	fileRead((u8 *)ZIMAGE_ADDR, LINUXIMAGE_FILENAME, size);
	
	size = fileSize(DTB_FILENAME);
	if(!size){
		shutdown();
	}
	fileRead((u8 *)PARAMS_ADDR, DTB_FILENAME, size);
}
Exemplo n.º 7
0
void QXmppTransferIncomingJob::_q_receiveData()
{
    if (d->state != QXmppTransferJob::TransferState)
        return;

    // receive data block
    if (d->direction == QXmppTransferJob::IncomingDirection)
    {
        writeData(d->socksSocket->readAll());

        // if we have received all the data, stop here
        if (fileSize() && d->done >= fileSize())
            checkData();
    }
}
Exemplo n.º 8
0
quint64 ClientTransfer::transferred() const
{
    if (status() == Status::Completed)
        return fileSize();

    return _file ? _file->size() : 0;
}
// ----------------------------------------------------------------------------
// CIpsPlgNewChildPartFromFileOperation::InitAttachmentManagerL
// ----------------------------------------------------------------------------
//
void CIpsPlgNewChildPartFromFileOperation::InitAttachmentManagerL()
    {
    iEntry = NULL;
    iMessage = NULL;
    RFile file;
    TInt fileSize( 0 );

    // Read attachment size
    User::LeaveIfError(
        file.Open( iMsvSession.FileSession(), iFilePath->Des(), EFileShareReadersOnly )
        );
 
    //in rare case that file has disappeared while sending
    //we just won't get the size for it
    file.Size( fileSize );
    file.Close();    

    // Initialize CMsvAttachment instance for the attachment creation
    CMsvAttachment* info = CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
    CleanupStack::PushL( info );

    info->SetAttachmentNameL( iFilePath->Des() );
    info->SetSize( fileSize );

    // Create/acquire Symbian message entry objects
    GetMessageEntryL( iMessageId.Id(), iEntry, iMessage );

    // Start attachment creation
    iMessage->AttachmentManager().AddAttachmentL( 
        iFilePath->Des(), info, iStatus );
    CleanupStack::Pop( info ); // attachment manager takes ownership
    iStep = EPrepareMsvEntry; // Next step
    SetActive();
    }
Exemplo n.º 10
0
int main(void) {
	const char *filename = "/tmp/file.txt";
	char c;
	FILE *fp;

	fp = fopen(filename, "r");
	if (fp == NULL) {
		perror("fopen() failed");
		exit(EXIT_FAILURE);
	} else {
		printf("Displaying the contents of file...\n");
		while((c = fgetc(fp)) != EOF) {
			fputc(c, stdout);
		}

		//diplay i/o information about the text file
		printf("\nFile descriptor is 	%d\n",getFileDescriptor(fp));
		printf("File size is 		%d bytes\n", getFileSize(fp));
		printf("Size of file is 	%d bytes\n", fileSize(fp));
		printf("Size of buffer is 	%d bytes\n", getFileBufSize(fp));
		getFileBufMode(fp);

		//display i/o information about stdout
		printf("\n"); //put a character to stdout
		printf("File descriptor is 	%d\n",getFileDescriptor(stdout));
		printf("Size of buffer is 	%d bytes\n", getFileBufSize(stdout));
		getFileBufMode(stdout);
	}

	fclose(fp);
	return EXIT_SUCCESS;
}
Exemplo n.º 11
0
uint64_t FileSystem::dirSize(const char* path) {
	std::size_t sum = 0;
	DIR *d = opendir(path);
	size_t path_len = strlen(path);
	if (d) {
		struct dirent *p;
		while (p = readdir(d)) {
			char *buf;
			size_t len;
			/* Skip the names "." and ".." as we don't want to recurse on them. */
			if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) {
				continue;
			}
			len = path_len + strlen(p->d_name) + 2;
			buf = (char*) malloc(len);
			if (buf) {
				struct stat statbuf;
				snprintf(buf, len, "%s/%s", path, p->d_name);
				if (!stat(buf, &statbuf)) {
					if (S_ISDIR(statbuf.st_mode)) {
						sum += dirSize(buf);
					} else if (S_ISREG(statbuf.st_mode)) {
						sum += fileSize(buf);
					}
				}
				free(buf);
			}
		}
		closedir(d);
	}
	return sum;
}
Exemplo n.º 12
0
/////////////////////////////////////////////////////////////////////////////
// Reads shader source code from file fileName. 
// It allocates memory for the null-terminated text string, 
// pointed to by *shaderSource.
// Returns 0 on error, otherwise return 1.
/////////////////////////////////////////////////////////////////////////////
int readShaderSource( const char *fileName, GLchar **shaderSource )
{
    // Allocate memory to hold the source of the shader.

    int fsize = fileSize(fileName);

    if (fsize == -1)
    {
		printf("ERROR: Cannot determine size of the shader %s.\n", fileName);
        return 0;
    }

    *shaderSource = (GLchar *) malloc(fsize + 1);  // Extra byte for null character.
    if (*shaderSource == NULL)
    {
        printf("ERROR: Cannot allocate memory for shader source.\n");
        return 0;
    }

    // Read the source code.

    if (!readShader(fileName, *shaderSource, fsize + 1))
    {
        printf("ERROR: Cannot read the file %s.\n", fileName);
        return 0;
    }

    return 1;
}
Exemplo n.º 13
0
	FSDirectory::FSIndexInput::FSIndexInput(const char* path, int32_t __bufferSize):
		BufferedIndexInput(__bufferSize)	
    {
	//Func - Constructor.
	//       Opens the file named path
	//Pre  - path != NULL
	//Post - if the file could not be opened  an exception is thrown.

	  CND_PRECONDITION(path != NULL, "path is NULL");

	  handle = _CLNEW SharedHandle();
	  strcpy(handle->path,path);

	  //Open the file
	  handle->fhandle  = _open(path, O_BINARY | O_RDONLY | O_RANDOM, _S_IREAD );
	  
	  //Check if a valid handle was retrieved
	  if (handle->fhandle < 0){
		int err = errno;
        if ( err == ENOENT )
		    _CLTHROWA(CL_ERR_IO, "File does not exist");
        else if ( err == EACCES )
            _CLTHROWA(CL_ERR_IO, "File Access denied");
        else if ( err == EMFILE )
            _CLTHROWA(CL_ERR_IO, "Too many open files");
	  }

	  //Store the file length
	  handle->_length = fileSize(handle->fhandle);
	  handle->_fpos = 0;
	  this->_pos = 0;
  }
Exemplo n.º 14
0
boolean gffOpen(struct gff *gff, char *fileName)
/* Initialize gff structure and open file for it. */
{
    dnaUtilOpen();

    /* Initialize structure and open file. */
    zeroBytes(gff, sizeof(*gff));
    gff->memPool = lmInit(16*1024);
    gff->fileSize = fileSize(fileName);
    if (gff->fileSize < 0 ||
       (gff->file = fopen(fileName, "rb")) == NULL)
	    {
            warn("Couldn't find the file named %s\n", fileName);
	    return FALSE;
	    }
    strcpy(gff->fileName, fileName);
    gff->bufSize = ArraySize(gff->buf);

    /* Make sure it's a gff file. */
    _gffSeekDoubleSharpLine(gff);
    if (strncmp(gff->buf, _gffIdent, strlen(_gffIdent)) != 0)
	{
	warn("%s doesn't appear to be a .gff file\n", fileName);
	return FALSE;
	}

    return TRUE;
}
static void rollupPsl(char *pslName, char *table, struct sqlConnection *conn, char *db)
{
char cmd[256];
char dbTbl[256];

if (fileSize(pslName)==0)
    return;

safef(dbTbl,sizeof(dbTbl),"%s.%s",db,table);
if (!sqlTableExists(conn, dbTbl))
    {
    verbose(1,"FYI: Table %s does not exist\n",dbTbl);
    safef(cmd,sizeof(cmd),"rm -f %s.psl; touch %s.psl",table,table); /* make empty file */
    verbose(1,"%s\n",cmd); system(cmd);
    }
else
    {
    dumpPslTable(conn, db, table);
    }

safef(cmd,sizeof(cmd),"cat %s %s.psl | sort -u | sort -k 10,10 > %sNew.psl", pslName, table, table);
verbose(1,"%s\n",cmd); system(cmd);

safef(cmd,sizeof(cmd),"hgLoadPsl %s %sNew.psl -table=%s",db,table,table);
verbose(1,"%s\n",cmd); system(cmd);

safef(cmd,sizeof(cmd),"rm %s %s.psl %sNew.psl",pslName,table,table);
verbose(1,"%s\n",cmd); 
//system(cmd);

}
Exemplo n.º 16
0
char *getTempDir(void)
/* get temporary directory to use for programs.  This first checks TMPDIR environment
 * variable, then /data/tmp, /scratch/tmp, /var/tmp, /tmp.  Return is static and
 * only set of first call */
{
static char *checkTmpDirs[] = {"/data/tmp", "/scratch/tmp", "/var/tmp", "/tmp", NULL};

static char* tmpDir = NULL;
if (tmpDir == NULL)
    {
    tmpDir = getenv("TMPDIR");
    if (tmpDir != NULL)
        tmpDir = cloneString(tmpDir);  // make sure it's stable
    else
        {
        int i;
        for (i = 0; (checkTmpDirs[i] != NULL) && (tmpDir == NULL); i++)
            {
            if (fileSize(checkTmpDirs[i]) >= 0)
                tmpDir = checkTmpDirs[i];
            }
        }
    }
if (tmpDir == NULL)
    errAbort("BUG: can't find a tmp directory");
return tmpDir;
}
Exemplo n.º 17
0
int WriteDbGovStatitrics( void )
{
  FILE *dbgov_stats;
  char file[ 256 ], file_ts[ 256 ];
  int _size;

  time_t timestamp = time( NULL );
  sprintf( file, "%sgovernor_%d.incomplete", PATH_TO_GOVERNOR_STATS, timestamp );
  sprintf( file_ts, "%sgovernor.%d", PATH_TO_GOVERNOR_STATS, timestamp );

  dbgov_stats = fopen( file, "w" );
  
  if( dbgov_stats != NULL )
  {
    g_hash_table_foreach( DbGovStatitrics, (GHFunc)dbstat_print_table, dbgov_stats );
    _size = fileSize( dbgov_stats );
    fclose( dbgov_stats );

    if( _size > 0 )
    {
      if( rename( file, file_ts ) == 0 ) return 1;
    }
    else 
      unlink( file );
  }
  
  return 0;
}
Exemplo n.º 18
0
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    setAcceptDrops(true);


    mReceiveFile = NULL;

    //m_ndnWidget = NULL;
    ui->setupUi(this);

    ui->comboBox->insertItem(0,tr("Send File"));
    ui->comboBox->insertItem(1,tr("Send Folder"));

    m_bFolder = false;

    clipboard = QApplication::clipboard();
    //connect(clipboard,SIGNAL(dataChanged()),this,)
    //connect()

    sendBytes = 0;
    blockNumber = 0;
    maxBytes = 0;
    cleanQuit = true;
    m_iFileType = 0;

    ser = new nfServer();
    //connect(ser, SIGNAL(elapsedTime(qint64,double)), this, SLOT(onTcpElapseTime(int,double)));
    connect(ser, SIGNAL(elapsedTime(qint64,double)), this, SLOT(onTcpElapseTime(qint64,double)));
    connect(ser, SIGNAL(fileSize(qint64)), this, SLOT(onTcpFileSize(qint64)));
}
Exemplo n.º 19
0
uint8_t* readFileToBuffer ( FILE * file )
{
    uint8_t * buffer = NULL;
    
    if ( file )
    {
        uint32_t fileLen = fileSize(file);
        
        FILEPRINT_ASSERT(fileLen!=0U);
        
        buffer = file_memAlloc( fileLen * sizeof(uint8_t) );

        if ( buffer )
        {
            uint32_t bytesRead = (uint32_t)fread(buffer, 1, fileLen, file);

            if ( bytesRead != fileLen )
            {
                FILEPRINT_DBG_E("Warning whole buffer not read %u!=%u",bytesRead,fileLen);
            }
        }
        else
        {
            FILEPRINT_DBG_E("Malloc failure: %s:%d",__FUNCTION__,__LINE__);
        }
    }
    else
    {
        FILEPRINT_DBG_E("Null handle to %s:%d",__FUNCTION__,__LINE__);
    }
    
    FILEPRINT_DBG_I("Returning buffer: %p\n",buffer);
 
    return buffer;
}
Exemplo n.º 20
0
void QXmppTransferJob::disconnected()
{
    if (m_state == QXmppTransferJob::FinishedState)
        return;

    // terminate transfer
    if (m_direction == QXmppTransferJob::IncomingDirection)
    {
        checkData();
    } else {
        if (fileSize() && m_done != fileSize())
            terminate(QXmppTransferJob::ProtocolError);
        else
            terminate(QXmppTransferJob::NoError);
    }
}
Exemplo n.º 21
0
sFont6 loadFont6(FILE * pFile, int position)
{
    int backup = ftell(pFile);
    // Start at position:
    fseek(pFile,position,SEEK_SET);

    // Get size:
    int pointer = ftell(pFile);
    int sz = fileSize(pFile);

    // Restart position:
    fseek(pFile,pointer,SEEK_SET);

    // Check how much letters there are in this font:
    sz -= pointer;
    sz /= sizeof(font6Letter);

    // Allocate memory:
    sFont6 result;
    result.f = (font6Letter*)malloc(sizeof(font6Letter)*sz);
    result.size = sz;

    // Read letters:
    int r = fread(result.f,sizeof(font6Letter),sz,pFile);
    if (r != sz)
    {
        fprintf(stderr, "Error: couldn't read the font.\n");
        exit(0);
    }

    // return file to position:
    fseek(pFile,backup,SEEK_SET);

    return result;
}
Exemplo n.º 22
0
static void ficlFileSize(FICL_VM *pVM) /* ( fileid -- ud ior ) */
{
    ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
    long ud = fileSize(ff->f);
    stackPushINT(pVM->pStack, ud);
    pushIor(pVM, ud != -1);
}
SuffixArray::SuffixArray(const std::string& base_name, bool print) :
  ok(false),
  data(0), sa(0), original_sa(0), ranks(0), data_size(0),
  sequences(0)
{
  std::ifstream data_file(base_name.c_str(), std::ios_base::binary);
  if(!data_file)
  {
    std::cerr << "Error: Cannot open data file " << base_name << std::endl;
    return;
  }
  this->data_size = fileSize(data_file);
  this->data = new uchar[this->data_size];
  data_file.read((char*)(this->data), data_size);
  data_file.close();

  std::string sa_name = base_name + SA_EXTENSION;
  std::ifstream sa_file(sa_name.c_str(), std::ios_base::binary);
  if(!sa_file)
  {
    std::cerr << "Error: Cannot open suffix array file " << sa_name << std::endl;
    return;
  }
  sa_file.read((char*)&(this->sequences), sizeof(uint));
  this->sa = new uint[this->data_size];
  sa_file.read((char*)(this->sa), this->data_size * sizeof(uint));
  sa_file.close();

  this->original_sa = this->sa; this->sa += this->sequences;
  this->ok = true;
}
Exemplo n.º 24
0
std::string LAMEFile::readAll() {
	std::string s;
	size_t size = fileSize();
	s.resize(size);
	read(&s[0], size);
	return s;
}
CResourceFile* CSsmCommandListResourceReaderImpl::CInitialiser::OpenResourceFileL(const TDesC& aFileName)
	{
	// open the resource file
	RFile file;
	CleanupClosePushL(file);
	User::LeaveIfError(file.Open(iFs, aFileName, EFileRead | EFileShareReadersOnly));

	// read entire resource file into a buffer
	TInt fileSize(0);
	User::LeaveIfError(file.Size(fileSize));
	RBuf8 buf;
	buf.CreateL(fileSize);
	CleanupClosePushL(buf);
	User::LeaveIfError(file.Read(buf));

	// create a CResourceFile from the buffer and add it to array (the CResourceFile takes its own copy of the buffer)
	CResourceFile* const resourceFile = CResourceFile::NewL(buf);
	CleanupStack::PushL(resourceFile);
	iResourcePool.AppendL(resourceFile);
	CleanupStack::Pop(resourceFile);
	iResourcePool.AppendL(aFileName);
	CleanupStack::PopAndDestroy(&buf);
	CleanupStack::PopAndDestroy(&file);
	return resourceFile;
	}
Exemplo n.º 26
0
void CBspMapResourceProvider::LoadShaders(CPakFile& pakFile)
{
	CPakFile::FileNameList shaderFileNames = pakFile.GetFileNamesMatching(".shader");
	for(CPakFile::FileNameList::const_iterator fileNameIterator(shaderFileNames.begin());
		fileNameIterator != shaderFileNames.end(); fileNameIterator++)
	{
		const std::string& shaderFileName(*fileNameIterator);

		uint8* fileData(NULL);
		uint32 fileSize(0);
		if(!pakFile.ReadFile(shaderFileName.c_str(), &fileData, &fileSize))
		{
			continue;
		}

		std::string shaderString(fileData, fileData + fileSize);

		delete fileData;

		QuakeShaderList shaders = CQuakeShaderParser::ParseShaders(shaderString.c_str());
		for(QuakeShaderList::const_iterator shaderIterator(shaders.begin());
			shaderIterator != shaders.end(); shaderIterator++)
		{
			m_shaders[shaderIterator->name] = *shaderIterator;
		}
	}
}
Exemplo n.º 27
0
static void printProfilingDataHeader(FILE *fout, DATA *data) {
  char *filename;
  int i;

  filename = malloc(strlen(data->modelData.modelFilePrefix) + 15);
  sprintf(filename, "%s_prof.data", data->modelData.modelFilePrefix);
  indent(fout, 2); fprintf(fout, "<filename>");printStrXML(fout,filename);fprintf(fout,"</filename>\n");
  indent(fout, 2); fprintf(fout, "<filesize>%ld</filesize>\n", (long) fileSize(filename));
  free(filename);

  indent(fout, 2); fprintf(fout, "<format>\n");
  indent(fout, 4); fprintf(fout, "<uint32>step</uint32>\n");
  indent(fout, 4); fprintf(fout, "<double>time</double>\n");
  indent(fout, 4); fprintf(fout, "<double>cpu time</double>\n");
  for(i = 0; i < data->modelData.modelDataXml.nFunctions; i++) {
    const char *name = modelInfoXmlGetFunction(&data->modelData.modelDataXml,i).name;
    indent(fout, 4); fprintf(fout, "<uint32>");printStrXML(fout,name);fprintf(fout, " (calls)</uint32>\n");
  }
  for(i = 0; i < data->modelData.modelDataXml.nProfileBlocks; i++) {
    const char *name = modelInfoXmlGetEquationIndexByProfileBlock(&data->modelData.modelDataXml,i).name;
    indent(fout, 4); fprintf(fout, "<uint32>");printStrXML(fout,name);fprintf(fout, " (calls)</uint32>\n");
  }
  for(i = 0; i < data->modelData.modelDataXml.nFunctions; i++) {
    const char *name = modelInfoXmlGetFunction(&data->modelData.modelDataXml,i).name;
    indent(fout, 4); fprintf(fout, "<double>");printStrXML(fout,name);fprintf(fout, " (cpu time)</double>\n");
  }
  for(i = 0; i < data->modelData.modelDataXml.nProfileBlocks; i++) {
    const char *name = modelInfoXmlGetEquationIndexByProfileBlock(&data->modelData.modelDataXml,i).name;
    indent(fout, 4); fprintf(fout, "<double>");printStrXML(fout,name);fprintf(fout, " (cpu time)</double>\n");
  }
  indent(fout, 2); fprintf(fout, "</format>\n");
}
Exemplo n.º 28
0
void QXmppTransferOutgoingJob::_q_sendData()
{
    if (d->state != QXmppTransferJob::TransferState)
        return;

    // don't saturate the outgoing socket
    if (d->socksSocket->bytesToWrite() > 2 * d->blockSize)
        return;

    // check whether we have written the whole file
    if (d->fileInfo.size() && d->done >= d->fileInfo.size())
    {
        if (!d->socksSocket->bytesToWrite())
            terminate(QXmppTransferJob::NoError);
        return;
    }

    char *buffer = new char[d->blockSize];
    qint64 length = d->iodevice->read(buffer, d->blockSize);
    if (length < 0)
    {
        delete [] buffer;
        terminate(QXmppTransferJob::FileAccessError);
        return;
    }
    if (length > 0)
    {
        d->socksSocket->write(buffer, length);
        delete [] buffer;
        d->done += length;
        emit progress(d->done, fileSize());
    }
}
Exemplo n.º 29
0
int eDVBMetaParser::parseRecordings(const std::string &filename)
{
	std::string::size_type slash = filename.rfind('/');
	if (slash == std::string::npos)
		return -1;
	
	std::string recordings = filename.substr(0, slash) + "/recordings.epl";
	
	FILE *f = fopen(recordings.c_str(), "r");
	if (!f)
	{
//		eDebug("no recordings.epl found: %s: %m", recordings.c_str());
		return -1;
	}
	
	std::string description;
	eServiceReferenceDVB ref;
	
//	eDebug("parsing recordings.epl..");
	
	while (1)
	{
		char line[1024];
		if (!fgets(line, 1024, f))
			break;
		
		size_t len = strlen(line);
		if (len < 2)
			// Lines with less than one char aren't meaningful
			continue;
		// Remove trailing \r\n
		--len;
		line[len] = 0;
		if (line[len-1] == '\r')
			line[len-1] = 0;
		
		if (strncmp(line, "#SERVICE: ", 10) == 0)
			ref = eServiceReferenceDVB(line + 10);
		else if (strncmp(line, "#DESCRIPTION: ", 14) == 0)
			description = line + 14;
		else if ((line[0] == '/') && (ref.path.substr(ref.path.find_last_of('/')) == filename.substr(filename.find_last_of('/'))))
		{
//			eDebug("hit! ref %s descr %s", m_ref.toString().c_str(), m_name.c_str());
			m_ref = ref;
			m_name = description;
			m_description = "";
			m_time_create = getctime(filename);
			m_length = 0;
			m_filesize = fileSize(filename);
			m_data_ok = 1;
			m_scrambled = 0;
			fclose(f);
			updateMeta(filename);
			return 0;
		}
	}
	fclose(f);
	return -1;
}
Exemplo n.º 30
0
bool PAKFile::loadFile(const char *file, const bool isAmiga) {
	_isAmiga = isAmiga;
	if (!file)
		return true;

	delete _fileList;
	_fileList = 0;

	FILE *pakfile = fopen(file, "rb");
	if (!pakfile)
		return false;

	uint32 filesize = fileSize(pakfile);

	// TODO: get rid of temp. buffer
	uint8 *buffer = new uint8[filesize];
	assert(buffer);

	fread(buffer, filesize, 1, pakfile);

	fclose(pakfile);

	const char *currentName = 0;

	uint32 startoffset = _isAmiga ? READ_BE_UINT32(buffer) : READ_LE_UINT32(buffer);
	uint32 endoffset = 0;
	uint8* position = buffer + 4;

	while (true) {
		uint32 strlgt = strlen((const char*)position);
		currentName = (const char*)position;

		if (!(*currentName))
			break;

		position += strlgt + 1;
		endoffset = _isAmiga ? READ_BE_UINT32(position) : READ_LE_UINT32(position);
		if (endoffset > filesize) {
			endoffset = filesize;
		} else if (endoffset == 0) {
			endoffset = filesize;
		}
		position += 4;

		uint8 *data = new uint8[endoffset - startoffset];
		assert(data);
		memcpy(data, buffer + startoffset, endoffset - startoffset);
		addFile(currentName, data, endoffset - startoffset);
		data = 0;

		if (endoffset == filesize)
			break;

		startoffset = endoffset;
	}

	delete[] buffer;
	return true;
}