1/*
2 * $Id: pa.h,v 1.3 2009-10-13 22:55:36 didg Exp $
3 *
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
5 * All Rights Reserved.
6 *
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appears in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation, and that the name of The University
12 * of Michigan not be used in advertising or publicity pertaining to
13 * distribution of the software without specific, written prior
14 * permission. This software is supplied as is without expressed or
15 * implied warranties of any kind.
16 *
17 *	Research Systems Unix Group
18 *	The University of Michigan
19 *	c/o Mike Clark
20 *	535 W. William Street
21 *	Ann Arbor, Michigan
22 *	+1-313-763-0525
23 *	netatalk@itd.umich.edu
24 */
25
26/*
27 * Functions to aid in parsing:
28 *
29 *	pa_init( fd )		Allocate and return a handle. Reads
30 *				from fd. Call this first, always.
31 *	pa_getchar( h )		Return a single character or nul, 0,
32 *				to indicate end-of-file.
33 *	pa_match( h )		Mark the character last read as the start
34 *				of a match.
35 *	pa_gettok( h )		The match up to but excluding the last
36 *				character is returned.
37 *	pa_cont( h )		Continue match with previous match. Call
38 *				immediately after pa_gettok() to get
39 *				correct behavior.
40 *	pa_cancel( h )		Cancel previous match start.
41 */
42
43#ifndef _PA_H
44#define _PA_H 1
45
46#ifndef FILE_H
47#include <stdio.h>
48#endif /* FILE_H */
49
50#define PA_BUFBLK	1024
51
52#define PA_NORMAL	0
53#define PA_MATCHING	1
54
55typedef struct pa_buf_t {
56	char *buf;
57	char *cur;
58	char *mark;
59	char *end;
60	int fd;
61	int state;
62	unsigned bufsz;
63	char tmp;
64} pa_buf_t;
65
66extern pa_buf_t *pa_init(int fd);
67extern char _pa_fixbuf(pa_buf_t *h);
68extern char *pa_gettok(pa_buf_t *h);
69
70#define pa_getchar(h)	(((h)->cur==(h)->end)?(_pa_fixbuf(h)):\
71			(*(++((h)->cur))))
72#define pa_match(h)	((h)->state=PA_MATCHING,(h)->mark=(h)->cur)
73#define pa_cont(h)	(*((h)->cur)=(h)->tmp,(h)->state=PA_MATCHING)
74#define pa_cancel(h)	((h)->state=PA_NORMAL)
75#define pa_back(h)	(--((h)->cur))
76
77#endif /* _PA_H */
78