Пример #1
0
/* the position of the trailer */
int pdf_trailer(char *pdf, int len)
{
	int pos = prevline(pdf, len, len);		/* %%EOF */
	while (!startswith(pdf + pos, "trailer"))
		if ((pos = prevline(pdf, len, pos)) < 0)
			return -1;
	return nextline(pdf, len, pos);			/* skip trailer\n */
}
Пример #2
0
/* the position of the last xref table */
static int pdf_xref(char *pdf, int len)
{
	int pos = prevline(pdf, len, len);		/* %%EOF */
	if ((pos = prevline(pdf, len, pos)) < 0)
		return -1;
	/* read startxref offset */
	if (sscanf(pdf + pos, "%d", &pos) != 1 || pos >= len || pos < 0)
		return -1;
	return nextline(pdf, len, pos);			/* skip xref\n */
}
Пример #3
0
void
Buffer::update(int ch)
{
    switch (ch) {
    case KEY_UP:
        prevline();
        break;
    case KEY_DOWN:
        nextline();
        break;
    case KEY_RIGHT:
        nextchar();
        break;
    case KEY_LEFT:
        prevchar();
        break;
    case KEY_HOME:
        begofline();
        break;
    case KEY_END:
        endofline();
        break;
    case 127:
        delchar();
        break;
    case '\n':
    case '\r':
        newline();
        break;
    default:
        addchar(ch);
    }
}
Пример #4
0
/*
 * gotoline(n) - return a pointer to line 'n' 
 *
 * Returns a pointer to the last line of the file if n is zero, or beyond the
 * end of the file. 
 */
LPtr           *
gotoline(int n)
{
    static LPtr     l;

    l.index = 0;

    if (n == 0)
	l = *prevline(Fileend);
    else {
	LPtr           *p;

	for (l = *Filemem; --n > 0; l = *p)
	    if ((p = nextline(&l)) == NULL)
		break;
    }
    return &l;
}
Пример #5
0
void
cursupdate()
{
        LPTR *p;
        int inc, c, nlines;
        int i;
        int didinc;

        if (bufempty()) {                /* special case - file is empty */
                *Topchar  = *Filemem;
                *Curschar = *Filemem;
        } else if ( LINEOF(Curschar) < LINEOF(Topchar) ) {
                nlines = cntllines(Curschar,Topchar);
                /* if the cursor is above the top of */
                /* the screen, put it at the top of the screen.. */
                *Topchar = *Curschar;
                Topchar->index = 0;
                /* ... and, if we weren't very close to begin with, */
                /* we scroll so that the line is close to the middle. */
                if ( nlines > Rows/3 ) {
                        for (i=0, p = Topchar; i < Rows/3 ;i++, *Topchar = *p)
                                if ((p = prevline(p)) == NULL)
                                        break;
                } else
                        s_ins(0, nlines-1);
                updatescreen();
        }
        else if (LINEOF(Curschar) >= LINEOF(Botchar)) {
                nlines = cntllines(Botchar,Curschar);
                /* If the cursor is off the bottom of the screen, */
                /* put it at the top of the screen.. */
                /* ... and back up */
                if ( nlines > Rows/3 ) {
                        p = Curschar;
                        for (i=0; i < (2*Rows)/3 ;i++)
                                if ((p = prevline(p)) == NULL)
                                        break;
                        *Topchar = *p;
                } else {
                        scrollup(nlines);
                }
                updatescreen();
        }

        Cursrow = Curscol = Cursvcol = 0;
        for ( p=Topchar; p->linep != Curschar->linep ;p = nextline(p) )
                Cursrow += plines(p);

        Cline_row = Cursrow;
        Cline_size = plines(p);

        for (i=0; i <= Curschar->index ;i++) {
                c = Curschar->linep->s[i];
                /* A tab gets expanded, depending on the current column */
                if ( c == TAB && !P(P_LS) )
                        inc = P(P_TS) - (Curscol % P(P_TS));
                else
                        inc = chars[(unsigned)(c & 0xff)].ch_size;
                Curscol += inc;
                Cursvcol += inc;
                if ( Curscol >= Columns ) {
                        Curscol -= Columns;
                        Cursrow++;
                        didinc = TRUE;
                }
                else
                        didinc = FALSE;
        }
        if (didinc)
                Cursrow--;

        if (c == TAB && State == NORMAL && !P(P_LS)) {
                Curscol--;
                Cursvcol--;
        } else {
                Curscol -= inc;
                Cursvcol -= inc;
        }
        if (Curscol < 0)
                Curscol += Columns;

        if (set_want_col) {
                Curswant = Cursvcol;
                set_want_col = FALSE;
        }
}