Esempio n. 1
0
ajuint ensKaryotypebandGetMemSize(const EnsPKaryotypeband kb)
{
    ajuint size = 0;
    
    if(!kb)
	return 0;
    
    size += sizeof (EnsOKaryotypeband);
    
    size += ensFeatureGetMemSize(kb->Feature);
    
    if(kb->Name)
    {
	size += sizeof (AjOStr);
	
	size += ajStrGetRes(kb->Name);
    }
    
    if(kb->Stain)
    {
	size += sizeof (AjOStr);
	
	size += ajStrGetRes(kb->Stain);
    }
    
    return size;
}
Esempio n. 2
0
size_t ensGvsynonymCalculateMemsize(const EnsPGvsynonym gvs)
{
    size_t size = 0;

    if (!gvs)
        return 0;

    size += sizeof (EnsOGvsynonym);

    size += ensGvsourceCalculateMemsize(gvs->Gvsource);

    if (gvs->Name)
    {
        size += sizeof (AjOStr);

        size += ajStrGetRes(gvs->Name);
    }

    if (gvs->Moleculetype)
    {
        size += sizeof (AjOStr);

        size += ajStrGetRes(gvs->Moleculetype);
    }

    return size;
}
Esempio n. 3
0
static ajint dbiblast_ncblreadhdr(AjPStr* hdrline, PBlastDb db, ajint start,
				  ajint end)
{
    ajint size;
    ajint llen;
    PMemFile hfp;

    size = ajStrGetRes(*hdrline);
    hfp  = db->HFile;

    if(end)
    {
	llen = end - start;

	if(db->IsBlast2)
	    llen += 1;

	if(llen > size)
	    llen = size;
    }
    else
	llen = size;

    /*ajDebug("ncblreadhdr start %d end %d llen %d\n", start, end, llen);*/

    if(db->IsBlast2)
    {
	dbiblast_memfseek(hfp,start,0);
	dbiblast_memfreadS(hdrline,(size_t)1,(size_t)(llen-1),hfp);
    }
    else
    {
	dbiblast_memfseek(hfp,start+1,0); /* skip the '>' character */
	dbiblast_memfreadS(hdrline,(size_t)1,(size_t)(llen-1),hfp);
    }

    ajStrSetValidLen(hdrline, (llen-1));

    return llen;
}
Esempio n. 4
0
AjBool ajReadlinePos(AjPFile file, AjPStr* Pdest, ajlong* Ppos)
{
    const char *cp;
    char *buff;
    ajint isize;
    ajint ilen;
    ajint jlen;
    ajint ipos;
    ajuint buffsize;
    size_t iread;
    const char* pnewline = NULL;
 
    MAJSTRDEL(Pdest);

    if(file->Buffsize)
        buffsize = file->Buffsize;
    else
        buffsize = ajFileValueBuffsize();

    if(!file->Buff)
      ajStrAssignResC(&file->Buff, buffsize, "");
    else if(buffsize > MAJSTRGETRES(file->Buff))
      ajStrSetRes(&file->Buff, buffsize);

    if(MAJSTRGETUSE(file->Buff) == 1)
      buff = MAJSTRGETPTR(file->Buff);
    else
      buff  = ajStrGetuniquePtr(&file->Buff);

    isize = MAJSTRGETRES(file->Buff);
    ilen  = 0;
    ipos  = 0;
    
    if(!file->fp)
	ajWarn("ajFileGets file not found");
    
    *Ppos = file->Filepos;

    while(buff)
    {
	if(file->End)
	{
	    ajStrAssignClear(Pdest);
	    ajDebug("at EOF: File already read to end %F\n", file);

	    return ajFalse;
	}
	

#ifndef __ppc__
        if(file->Readblock)
        {
            if(file->Blockpos >= file->Blocklen)
            {
                iread = fread(file->Readblock,
                              1, file->Blocksize,
                              file->fp);

                if(!iread && ferror(file->fp))
                    ajFatal("fread failed with error:%d '%s'",
                            ferror(file->fp), strerror(ferror(file->fp)));

                file->Blockpos = 0;
                file->Blocklen = iread;
                file->Readblock[iread] = '\0';
                /*ajDebug("++ fread %u Ppos:%Ld\n", iread, *Ppos);*/
             }

            if(file->Blockpos < file->Blocklen)
            {

                /* we know we have something in Readblock to process */

                pnewline = strchr(&file->Readblock[file->Blockpos], '\n');

                if(pnewline)
                    jlen = pnewline - &file->Readblock[file->Blockpos] + 1;
                else
                    jlen = file->Blocklen - file->Blockpos;

                /*ajDebug("ipos:%d jlen:%d pnewline:%p "
                          "Readblock:%p blockpos:%d blocklen:%d\n",
                          ipos, jlen, pnewline, file->Readblock,
                          file->Blockpos, file->Blocklen);*/
                memmove(&buff[ipos], &file->Readblock[file->Blockpos], jlen);
                buff[ipos+jlen]='\0';
                cp = &buff[ipos];
                file->Blockpos += jlen;
            }
            else
            {
                jlen = 0;
                cp = NULL;
            }
        }
        else
        {
            cp = fgets(&buff[ipos], isize, file->fp);
            jlen = strlen(&buff[ipos]);
        }
        
#else
	cp = ajSysFuncFgets(&buff[ipos], isize, file->fp);
	jlen = strlen(&buff[ipos]);
#endif

        if(!cp && !ipos)
	{
	    if(feof(file->fp))
	    {
		file->End = ajTrue;
		ajStrAssignClear(Pdest);
		ajDebug("EOF ajFileGetsL file %F\n", file);

		return ajFalse;
	    }
	    else
		ajFatal("Error reading from file '%S'\n", ajFileGetNameS(file));
	}

	ilen += jlen;
        file->Filepos += jlen;

	/*
	 ** We need to read again if:
	 ** We have read the entire buffer
	 ** and we don't have a newline at the end
	 ** (must be careful about that - we may just have read enough)
	 */

	if(((file->Readblock && !pnewline) ||(jlen == (isize-1))) &&
	   (buff[ilen-1] != '\n'))
	{
            MAJSTRSETVALIDLEN(&file->Buff, ilen); /* fix before resizing! */
	    ajStrSetResRound(&file->Buff, ilen+buffsize+1);
	    /*ajDebug("more to do: jlen: %d ipos: %d isize: %d ilen: %d "
		    "Size: %d\n",
		    jlen, ipos, isize, ilen, ajStrGetRes(file->Buff));*/
	    ipos += jlen;
	    buff = ajStrGetuniquePtr(&file->Buff);
	    isize = ajStrGetRes(file->Buff) - ipos;
	    /*ajDebug("expand to: ipos: %d isize: %d Size: %d\n",
              ipos, isize, ajStrGetRes(file>Buff));*/
	}
	else
	    buff = NULL;
    }
    
    MAJSTRSETVALIDLEN(&file->Buff, ilen);
    if (ajStrGetCharLast(file->Buff) != '\n')
    {
	/*ajDebug("Appending missing newline to '%S'\n", file->Buff);*/
	ajStrAppendK(&file->Buff, '\n');
    }
    ajStrAssignRef(Pdest, file->Buff);

/*
  if(file->Readblock)
        ajDebug("ajFileGetsL done blocklen:%d blockpos:%d readlen:%u\n",
                file->Blocklen, file->Blockpos, ajStrGetLen(file->Buff));
*/
    return ajTrue;
}
Esempio n. 5
0
ajint ajUserGet(AjPStr* pthis, const char* fmt, ...)
{
    AjPStr thys;
    const char *cp;
    char *buff;
    va_list args;
    ajint ipos;
    ajint isize;
    ajint ilen;
    ajint jlen;
    ajint fileBuffSize = ajFileValueBuffsize();

    va_start(args, fmt);
    ajFmtVError(fmt, args);
    va_end(args);

    if(ajFileValueRedirectStdin())
    {
	ajUser("(Standard input in use: using default)");
	ajStrAssignC(pthis, "");

	return ajStrGetLen(*pthis);
    }

    ajStrSetRes(pthis, fileBuffSize);
    buff  = ajStrGetuniquePtr(pthis);
    thys = *pthis;
    isize = ajStrGetRes(thys);
    ilen  = 0;
    ipos  = 0;
    

    /*ajDebug("ajUserGet buffer len: %d res: %d ptr: %x\n",
	     ajStrGetLen(thys), ajStrGetRes(thys), thys->Ptr);*/

    while(buff)
    {

#ifndef __ppc__
	cp = fgets(&buff[ipos], isize, stdin);
#else
	cp = ajSysFuncFgets(&buff[ipos], isize, stdin);
#endif

        if(!cp && !ipos)
	{
	    if(feof(stdin))
	    {
		ajErr("Unable to get reply from user - end of standard input");
		ajExitBad();
	    }
	    else
		ajFatal("Error reading from user: '******'\n",
			strerror(errno));
	}

	jlen = strlen(&buff[ipos]);
	ilen += jlen;

	/*
	 ** We need to read again if:
	 ** We have read the entire buffer
	 ** and we don't have a newline at the end
	 ** (must be careful about that - we may just have read enough)
	 */
	ajStrSetValidLen(pthis, ilen);
	thys = *pthis;

	if((jlen == (isize-1)) &&
	   (ajStrGetCharLast(thys) != '\n'))
	{
	    ajStrSetRes(pthis, ajStrGetRes(thys)+fileBuffSize);
	    thys = *pthis;
	    /*ajDebug("more to do: jlen: %d ipos: %d isize: %d ilen: %d "
		    "Size: %d\n",
		    jlen, ipos, isize, ilen, ajStrGetRes(thys));*/
	    ipos += jlen;
	    buff = ajStrGetuniquePtr(pthis);
	    isize = ajStrGetRes(thys) - ipos;
	    /* ajDebug("expand to: ipos: %d isize: %d Size: %d\n",
		    ipos, isize, ajStrGetRes(thys)); */

	}
	else
	    buff = NULL;
    }
    
    ajStrSetValidLen(pthis, ilen);

    if(ajStrGetCharLast(*pthis) == '\n')
	ajStrCutEnd(pthis, 1);

    /* PC files have \r\n Macintosh files have just \r : this fixes both */

    if(ajStrGetCharLast(*pthis) == '\r')
    {
	/*ajDebug("Remove carriage-return characters from PC-style files\n");*/
	ajStrCutEnd(pthis, 1);
    }

    ajStrTrimWhite(pthis);

    return ajStrGetLen(*pthis);
}
Esempio n. 6
0
static CachePNode cacheNodeNew(const EnsPCache cache, void* key, void* value)
{
    ajuint *Puintkey = NULL;

    CachePNode node = NULL;

    if(!cache)
        return NULL;

    if(!key)
        return NULL;

    if(!value)
        return NULL;

    AJNEW0(node);

    /* Add the size of the Ensembl Cache Node itself. */

    node->Bytes += (ajuint) sizeof (CacheONode);

    switch(cache->Type)
    {
        case ensECacheTypeNumeric:

            /* Reference AJAX unsigned integer key data. */

            AJNEW0(Puintkey);

            *Puintkey = *((ajuint *) key);

            node->Key = (void *) Puintkey;

            /* Add the size of unsigned integer key data. */

            node->Bytes += (ajuint) sizeof (ajuint);

            break;

        case ensECacheTypeAlphaNumeric:

            /* Reference AJAX String key data. */

            node->Key = (void *) ajStrNewS((AjPStr) key);

            /* Add the size of AJAX String key data. */

            node->Bytes += (ajuint) sizeof (AjOStr);

            node->Bytes += ajStrGetRes((AjPStr) node->Key);

            break;

        default:

            ajWarn("cacheNodeNew got unexpected Cache type %d.\n",
                   cache->Type);
    }

    /* Reference the value data. */

    if(cache->Reference && value)
        node->Value = (*cache->Reference)(value);

    /* Calculate the size of the value data. */

    if(cache->Size && node->Value)
        node->Bytes += (*cache->Size)(node->Value);

    node->Dirty = ajFalse;

    return node;
}