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