Ejemplo n.º 1
0
AjBool ajReadlineTrimPos(AjPFile file, AjPStr* Pdest, ajlong* Ppos)
{
    AjBool ok;

    ok = ajReadlinePos(file, Pdest, Ppos);

    if(!ok)
	return ajFalse;

    MAJSTRDEL(Pdest);

    /* trim any trailing newline */


    /*ajDebug("Remove carriage-return characters from PC-style files\n");*/
    if(ajStrGetCharLast(file->Buff) == '\n')
	ajStrCutEnd(&file->Buff, 1);

    /* PC files have \r\n Macintosh files have just \r : this fixes both */
    if(ajStrGetCharLast(file->Buff) == '\r')
	ajStrCutEnd(&file->Buff, 1);

    ajStrAssignRef(Pdest, file->Buff);

    return ajTrue;
}
Ejemplo n.º 2
0
AjBool ajBuffreadLineTrim(AjPFilebuff buff, AjPStr* Pdest)
{
    AjBool ret;
    ajlong fpos = 0;
    AjPStr dest;

    ret = ajBuffreadLinePos(buff, Pdest, &fpos);
    
    /* trim any trailing newline */

    dest = *Pdest;

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

    /* PC files have \r\n Macintosh files have just \r : this fixes both */
    if(ajStrGetCharLast(dest) == '\r')
	ajStrCutEnd(Pdest, 1);

    return ret;
}
Ejemplo n.º 3
0
static void dbiblast_dbname(AjPStr* dbname,
			    const AjPStr oname, const char *suff)
{
    AjPStr suffix = NULL;

    ajFmtPrintS(&suffix, ".%s", suff);

    ajStrAssignS(dbname, oname);

    if(ajStrGetCharFirst(oname)=='@')
	ajStrCutStart(dbname, 1);

    if(!ajStrSuffixS(*dbname, suffix))
    {
	ajStrDel(&suffix);
	return;
    }

    ajStrCutEnd(dbname, ajStrGetLen(suffix));

    ajStrDel(&suffix);

    return;
}
Ejemplo n.º 4
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);
}