]> arthur.barton.de Git - netatalk.git/blob - bin/psorder/pa.c
Warning fixes.
[netatalk.git] / bin / psorder / pa.c
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 /* This is used with pa.h */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
33
34 #include "pa.h"
35
36 pa_buf_t *pa_init( fd )
37         int fd;
38 {
39         pa_buf_t *h;
40         int rc;
41
42         h = (pa_buf_t *) malloc( sizeof( pa_buf_t ));
43         h->buf = (char *) malloc( PA_BUFBLK * 2 );
44         h->bufsz = PA_BUFBLK * 2;
45
46         if (( rc = read( fd, h->buf, PA_BUFBLK )) < 0 ) {
47                 return( 0 );
48         }
49
50         h->cur = h->buf - 1;
51         h->end = h->buf + rc - 1;
52         h->state = PA_NORMAL;
53         h->fd = fd;
54
55         return( h );
56 }
57
58 char *pa_gettok( h )
59         pa_buf_t *h;
60 {
61         h->state = PA_NORMAL;
62         h->tmp = *(h->cur);
63         *(h->cur) = 0;
64         return( h->mark );
65 }
66
67 char _pa_fixbuf( h )
68         pa_buf_t *h;
69 {
70         int rc;
71         char *t;
72
73         if ( h->state == PA_NORMAL ) {
74                 *(h->buf) = *(h->cur);
75                 h->cur = h->buf;
76         } else {
77                 bcopy( h->mark, h->buf, h->end - h->mark + 1 );
78                 h->cur = h->buf + ( h->cur - h->mark );
79                 h->end = h->buf + ( h->end - h->mark );
80                 h->mark = h->buf;
81         }
82
83         if ( h->bufsz - (( h->cur - h->buf ) + 1 ) < PA_BUFBLK ) {
84                 t = h->buf;
85                 h->buf = (char *) realloc( h->buf, h->bufsz + PA_BUFBLK );
86                 h->bufsz += PA_BUFBLK;
87                 h->mark = h->buf + ( h->mark - t );
88                 h->cur = h->buf + ( h->cur - t );
89                 h->end = h->buf + ( h->end - t );
90         }
91
92         if (( rc = read( h->fd, h->cur + 1, PA_BUFBLK )) <= 0 ) {
93                 return( (char) 0 );
94         }
95
96         h->end = h->cur + rc;
97         return( *(++(h->cur)) );
98 }