X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Fgettok.c;h=6c9d473b34379f4741060826197e542dbf56b462;hb=b3460c7a91a95c030b1019621f1efd73a260ee64;hp=2dd55a0d026a6cb882c5104eb7e9e87963289d69;hpb=4b777c7af436135108b2391c6d5a230a5d69e480;p=netatalk.git diff --git a/etc/afpd/gettok.c b/etc/afpd/gettok.c index 2dd55a0d..6c9d473b 100644 --- a/etc/afpd/gettok.c +++ b/etc/afpd/gettok.c @@ -1,5 +1,5 @@ /* - * $Id: gettok.c,v 1.4 2001-09-06 20:00:59 rufustfirefly Exp $ + * $Id: gettok.c,v 1.6 2009-10-13 22:55:37 didg Exp $ * * Copyright (c) 1990,1994 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -29,14 +29,12 @@ char *strchr (), *strrchr (); #include #include -#include "globals.h" +#include static char *l_curr; static char *l_end; -void initline( len, line ) - int len; - char *line; +void initline( int len, char *line) { l_curr = line; l_end = line + len; @@ -46,10 +44,8 @@ void initline( len, line ) #define ST_WORD 1 #define ST_BEGIN 2 - int -parseline( len, token ) - int len; - char *token; +int +parseline(int len, char *token) { char *p, *e; int state; @@ -59,59 +55,58 @@ parseline( len, token ) e = token + len; for (;;) { - if ( l_curr > l_end ) { /* end of line */ - *token = '\0'; - return( -1 ); - } - - switch ( *l_curr ) { - case '"' : - if ( state == ST_QUOTE ) { - state = ST_WORD; - } else { - state = ST_QUOTE; - } - break; - - case '\0' : - case '\t' : - case '\n' : - case ' ' : - if ( state == ST_WORD ) { - *p = '\0'; - return( p - token ); - } - if ( state != ST_QUOTE ) { - break; - } - /* FALL THROUGH */ - - default : - if ( state == ST_BEGIN ) { - state = ST_WORD; - } - if ( p > e ) { /* end of token */ - *token = '\0'; - return( -1 ); - } - *p++ = *l_curr; - break; - } - - l_curr++; + if ( l_curr > l_end ) { /* end of line */ + *token = '\0'; + return( -1 ); + } + + switch ( *l_curr ) { + case '"' : + if ( state == ST_QUOTE ) { + state = ST_WORD; + } else { + state = ST_QUOTE; + } + break; + + case '\0' : + case '\t' : + case '\n' : + case ' ' : + if ( state == ST_WORD ) { + *p = '\0'; + return( p - token ); + } + if ( state != ST_QUOTE ) { + break; + } + /* FALL THROUGH */ + + default : + if ( state == ST_BEGIN ) { + state = ST_WORD; + } + if ( p > e ) { /* end of token */ + *token = '\0'; + return( -1 ); + } + *p++ = *l_curr; + break; + } + + l_curr++; } } #ifdef notdef -void parseline( token, user ) - char *token, *user; +void parseline(char *token, char *user) { char *p = pos, *t = token, *u, *q, buf[ MAXPATHLEN ]; struct passwd *pwent; int quoted = 0; while ( isspace( *p )) { - p++; + p++; } /* @@ -119,25 +114,25 @@ void parseline( token, user ) * don't return any more tokens. */ if ( *p == '\0' || *p == '#' ) { - *token = '\0'; - return; + *token = '\0'; + return; } if ( *p == '"' ) { - p++; - quoted = 1; + p++; + quoted = 1; } while ( *p != '\0' && ( quoted || !isspace( *p ))) { - if ( *p == '"' ) { - if ( quoted ) { - *t = '\0'; - break; - } - quoted = 1; - p++; - } else { - *t++ = *p++; - } + if ( *p == '"' ) { + if ( quoted ) { + *t = '\0'; + break; + } + quoted = 1; + p++; + } else { + *t++ = *p++; + } } pos = p; *t = '\0'; @@ -146,37 +141,37 @@ void parseline( token, user ) * We got to the end of the line without closing an open quote */ if ( *p == '\0' && quoted ) { - *token = '\0'; - return; + *token = '\0'; + return; } t = token; if ( *t == '~' ) { - t++; - if ( *t == '\0' || *t == '/' ) { - u = user; - if ( *t == '/' ) { - t++; - } - } else { - u = t; - if (( q = strchr( t, '/' )) == NULL ) { - t = ""; - } else { - *q = '\0'; - t = q + 1; - } - } - if ( u == NULL || ( pwent = getpwnam( u )) == NULL ) { - *token = '\0'; - return; - } - strcpy( buf, pwent->pw_dir ); - if ( *t != '\0' ) { - strcat( buf, "/" ); - strcat( buf, t ); - } - strcpy( token, buf ); + t++; + if ( *t == '\0' || *t == '/' ) { + u = user; + if ( *t == '/' ) { + t++; + } + } else { + u = t; + if (( q = strchr( t, '/' )) == NULL ) { + t = ""; + } else { + *q = '\0'; + t = q + 1; + } + } + if ( u == NULL || ( pwent = getpwnam( u )) == NULL ) { + *token = '\0'; + return; + } + strcpy( buf, pwent->pw_dir ); + if ( *t != '\0' ) { + strcat( buf, "/" ); + strcat( buf, t ); + } + strcpy( token, buf ); } return; }