File: pa.c

package info (click to toggle)
netatalk 2.0.3-4%2Betch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 9,012 kB
  • ctags: 6,109
  • sloc: ansic: 67,633; sh: 8,424; perl: 1,187; makefile: 1,001
file content (102 lines) | stat: -rw-r--r-- 2,329 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * $Id: pa.c,v 1.4 2001/06/29 14:14:46 rufustfirefly Exp $
 *
 * Copyright (c) 1990,1991 Regents of The University of Michigan.
 * All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software and
 * its documentation for any purpose and without fee is hereby granted,
 * provided that the above copyright notice appears in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation, and that the name of The University
 * of Michigan not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior
 * permission. This software is supplied as is without expressed or
 * implied warranties of any kind.
 *
 *	Research Systems Unix Group
 *	The University of Michigan
 *	c/o Mike Clark
 *	535 W. William Street
 *	Ann Arbor, Michigan
 *	+1-313-763-0525
 *	netatalk@itd.umich.edu
 */

/* This is used with pa.h */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */

#include "pa.h"

pa_buf_t *pa_init( fd )
	int fd;
{
	pa_buf_t *h;
	int rc;

	h = (pa_buf_t *) malloc( sizeof( pa_buf_t ));
	h->buf = (char *) malloc( PA_BUFBLK * 2 );
	h->bufsz = PA_BUFBLK * 2;

	if (( rc = read( fd, h->buf, PA_BUFBLK )) < 0 ) {
		return( 0 );
	}

	h->cur = h->buf - 1;
	h->end = h->buf + rc - 1;
	h->state = PA_NORMAL;
	h->fd = fd;

	return( h );
}

char *pa_gettok( h )
	pa_buf_t *h;
{
	h->state = PA_NORMAL;
	h->tmp = *(h->cur);
	*(h->cur) = 0;
	return( h->mark );
}

char _pa_fixbuf( h )
	pa_buf_t *h;
{
	int rc;
	char *t;

	if ( h->state == PA_NORMAL ) {
		*(h->buf) = *(h->cur);
		h->cur = h->buf;
	} else {
		bcopy( h->mark, h->buf, h->end - h->mark + 1 );
		h->cur = h->buf + ( h->cur - h->mark );
		h->end = h->buf + ( h->end - h->mark );
		h->mark = h->buf;
	}

	if ( h->bufsz - (( h->cur - h->buf ) + 1 ) < PA_BUFBLK ) {
		t = h->buf;
		h->buf = (char *) realloc( h->buf, h->bufsz + PA_BUFBLK );
		h->bufsz += PA_BUFBLK;
		h->mark = h->buf + ( h->mark - t );
		h->cur = h->buf + ( h->cur - t );
		h->end = h->buf + ( h->end - t );
	}

	if (( rc = read( h->fd, h->cur + 1, PA_BUFBLK )) <= 0 ) {
		return( (char) 0 );
	}

	h->end = h->cur + rc;
	return( *(++(h->cur)) );
}