Exemplo n.º 1
0
static int yaz_gets(int (*getbyte)(void *client_data),
                    void (*ungetbyte)(int b, void *client_data),
                    void *client_data,
                    WRBUF w)
{
    size_t sz = 0;
    int ch = getbyte(client_data);

    while (ch != '\0' && ch != '\r' && ch != '\n')
    {
        wrbuf_putc(w, ch);
        sz++;
        ch = getbyte(client_data);
    }
    if (ch == '\r')
    {
        ch = getbyte(client_data);
        if (ch != '\n' && ch != '\0')
            ungetbyte(ch, client_data);
    }
    else if (ch == '\n')
    {
        ch = getbyte(client_data);
        if (ch != '\r' && ch != '\0')
            ungetbyte(ch, client_data);
    }
    if (sz)
    {
        return 1;
    }
    return 0;
}
Exemplo n.º 2
0
static int yaz_marc_line_gets(int (*getbyte)(void *client_data),
                              void (*ungetbyte)(int b, void *client_data),
                              void *client_data,
                              WRBUF w)
{
    int more;

    wrbuf_rewind(w);
    more = yaz_gets(getbyte, ungetbyte, client_data, w);
    if (!more)
        return 0;

    while (more)
    {
        int i;
        for (i = 0; i<4; i++)
        {
            int ch = getbyte(client_data);
            if (ch != ' ')
            {
                if (ch)
                    ungetbyte(ch, client_data);
                return 1;
            }
        }
        if (wrbuf_len(w) > 60 && wrbuf_buf(w)[wrbuf_len(w)-1] == '=')
            wrbuf_cut_right(w, 1);
        else
            wrbuf_puts(w, " ");
        more = yaz_gets(getbyte, ungetbyte, client_data, w);
    }
    return 1;
}
Exemplo n.º 3
0
void
ungetbytes(char *s, int len)
{
    s += len;
    while (len--)
	ungetbyte(*--s);
}
Exemplo n.º 4
0
int
universalargument(char **args)
{
    int digcnt = 0, pref = 0, minus = 1, gotk;
    if (*args) {
	zmod.mult = atoi(*args);
	zmod.flags |= MOD_MULT;
	return 0;
    }
    /*
     * TODO: this is quite tricky to do when trying to maintain
     * compatibility between the old input system and Unicode.
     * We don't know what follows the digits, so if we try to
     * read wide characters we may fail (e.g. we may come across an old
     * \M-style binding).
     *
     * If we assume individual bytes are either explicitly ASCII or
     * not (a la UTF-8), we get away with it; we can back up individual
     * bytes and everything will work.  We may want to relax this
     * assumption later.  ("Much later" - (C) Steven Singer,
     * CSR BlueCore firmware, ca. 2000.)
     *
     * Hence for now this remains byte-by-byte.
     */
    while ((gotk = getbyte(0L, NULL)) != EOF) {
	if (gotk == '-' && !digcnt) {
	    minus = -1;
	    digcnt++;
	} else {
	    int newdigit = parsedigit(gotk);

	    if (newdigit >= 0) {
		pref = pref * zmod.base + newdigit;
		digcnt++;
	    } else {
		ungetbyte(gotk);
		break;
	    }
	}
    }
    if (digcnt)
	zmod.tmult = minus * (pref ? pref : 1);
    else
	zmod.tmult *= 4;
    zmod.flags |= MOD_TMULT;
    prefixflag = 1;
    return 0;
}