RE: [HACKERS] [OT] flex, yacc, and bison
Dmitry Samersoff <dms@wplus.net>
From: Dmitry Samersoff <dms@wplus.net>
To: Vince Vielhaber <vev@michvhf.com>
Cc: pgsql-hackers@postgreSQL.org, Jackson@woland.wplus.net, DeJuan <djackson@cpsgroup.com>
Date: 1999-08-19T09:43:49Z
Lists: pgsql-hackers
On 18-Aug-99 Vince Vielhaber wrote:
>
> On 18-Aug-99 Jackson, DeJuan wrote:
>> I'm trying to write a ncftp_auth deamon that will utilize PostgreSQL. The
>> base SDK is in C. I'm adapting it to C++ because I feel like it, but Perl
>> would be a slightly steeper learning curve (sockets and all that). I'm
>> trying to get a conf file parser such that the login's can be in multiple
>> database and/or on different machines.
>
> If you're into C/C++ (like I am), it's almost trivial to parse that into
> individual strings. I was under the impression from your first note that
> C/C++ wasn't an option. At the minimum, think strtok(). There's also
> strsep() but it's not been one of my favorites. If you still need actual
> code let me know and I can send you something.
It's my bestst:
int split(char delem, char *str, ... )
{
char *tmp, *_src, *t, **s;
int fields = 0;
_src = str;
va_list ap;
va_start(ap, str);
if (! (tmp=new char[2048]) )
return -1;
while(_src)
{ t = _src;
while (*t && ((*t) != delem) ) ++t;
s = va_arg(ap, char **);
if (!s || !*t)
break;
*s = ( t-_src-1 > 0) ? strndup(_src,t-_src-1) : 0 ;
_src = t+1;
++ fields;
}
return fields;
}
---
Dmitry Samersoff, dms@wplus.net, ICQ:3161705
http://devnull.wplus.net
* There will come soft rains ...