2 * $Id: gettok.c,v 1.6 2009-10-13 22:55:37 didg Exp $
4 * Copyright (c) 1990,1994 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
12 #include <sys/param.h>
17 #else /* STDC_HEADERS */
21 #endif /* HAVE_STRCHR */
22 char *strchr (), *strrchr ();
24 #define memcpy(d,s,n) bcopy ((s), (d), (n))
25 #define memmove(d,s,n) bcopy ((s), (d), (n))
26 #endif /* ! HAVE_MEMCPY */
27 #endif /* STDC_HEADERS */
32 #include <atalk/globals.h>
37 void initline( int len, char *line)
48 parseline(int len, char *token)
58 if ( l_curr > l_end ) { /* end of line */
65 if ( state == ST_QUOTE ) {
76 if ( state == ST_WORD ) {
80 if ( state != ST_QUOTE ) {
86 if ( state == ST_BEGIN ) {
89 if ( p > e ) { /* end of token */
102 void parseline(char *token, char *user)
104 char *p = pos, *t = token, *u, *q, buf[ MAXPATHLEN ];
105 struct passwd *pwent;
108 while ( isspace( *p )) {
113 * If we've reached the end of the line, or a comment,
114 * don't return any more tokens.
116 if ( *p == '\0' || *p == '#' ) {
125 while ( *p != '\0' && ( quoted || !isspace( *p ))) {
141 * We got to the end of the line without closing an open quote
143 if ( *p == '\0' && quoted ) {
151 if ( *t == '\0' || *t == '/' ) {
158 if (( q = strchr( t, '/' )) == NULL ) {
165 if ( u == NULL || ( pwent = getpwnam( u )) == NULL ) {
169 strcpy( buf, pwent->pw_dir );
174 strcpy( token, buf );