#ifndef lint
static char rcsid[] = "$Header: /ful/chris/ctex_dist/lib/RCS/findpost.c,v 1.1 84/05/20 23:11:57 chris Exp $";
#endif

/* FindPostAmble - Find the postamble of a DVI file */

#include <stdio.h>
#include "types.h"
#include "dvicodes.h"
#include "fio.h"

long ftell ();

FindPostAmble (f)
register FILE *f;
{
    register long   offset;

    {
	unsigned char ch;

	fseek (f, 0L, 2);
	if (ftell (f) == 0)
	    return -1;

	fseek (f, -1L, 2);
	for (;;) {
	    offset = ftell (f);
	    if (offset == 0)
	        return -1;

	    ch = fgetc (f);

	    if (ch == DVI_VERSION)
	        goto foundit;
	    if (ch != DVI_FILLER)
	        return -1;

	    fseek (f, -2L, 1);
	}
    }


foundit: 
    {
	register i32    n;

	fseek (f, offset - 4L, 0);
	fGetLong (f, n);
	offset = n;
	fseek (f, offset, 0);
	return 0;		/* success */
    }
}
