2 * $Id: pa.c,v 1.5 2009-10-13 22:55:36 didg Exp $
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
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.
17 * Research Systems Unix Group
18 * The University of Michigan
20 * 535 W. William Street
23 * netatalk@itd.umich.edu
26 /* This is used with pa.h */
30 #endif /* HAVE_CONFIG_H */
36 #endif /* HAVE_UNISTD_H */
40 pa_buf_t *pa_init(int fd)
45 h = (pa_buf_t *) malloc( sizeof( pa_buf_t ));
46 h->buf = (char *) malloc( PA_BUFBLK * 2 );
47 h->bufsz = PA_BUFBLK * 2;
49 if (( rc = read( fd, h->buf, PA_BUFBLK )) < 0 ) {
54 h->end = h->buf + rc - 1;
61 char *pa_gettok(pa_buf_t *h)
69 char _pa_fixbuf(pa_buf_t *h)
74 if ( h->state == PA_NORMAL ) {
75 *(h->buf) = *(h->cur);
78 bcopy( h->mark, h->buf, h->end - h->mark + 1 );
79 h->cur = h->buf + ( h->cur - h->mark );
80 h->end = h->buf + ( h->end - h->mark );
84 if ( h->bufsz - (( h->cur - h->buf ) + 1 ) < PA_BUFBLK ) {
86 h->buf = (char *) realloc( h->buf, h->bufsz + PA_BUFBLK );
87 h->bufsz += PA_BUFBLK;
88 h->mark = h->buf + ( h->mark - t );
89 h->cur = h->buf + ( h->cur - t );
90 h->end = h->buf + ( h->end - t );
93 if (( rc = read( h->fd, h->cur + 1, PA_BUFBLK )) <= 0 ) {
98 return( *(++(h->cur)) );