Sorry, been a busy day, but here is a little something that can be used.
add the -o option to the getopt() line. (note the 'o:' at the end)
> *while* ((c = getopt(argc, argv,
> "a:p:s:U:m:Mc:khirvdl:u:P:f:s:n:t:D:LR:Cb:o:")) != -1) {
>
>
Add the -o option to the switch.
> *case* 'o' :
> parse_options(optarg);
> *break*;
>
>
And we have this function which separates out the fields and uses them.
> static void parse_options(char *str)
> {
> char *copy;
> char *argument;
> char *next;
> char *key, *value;
>
> assert(str);
> copy = strdup(str);
> *if* (copy) {
> argument = copy;
> next = argument;
> *while* (next != NULL && *next != '\0') {
> argument = strsep(&next, ",");
>
> value = argument;
> key = strsep(&value, "=");
> *if* (value == NULL) *return*;
>
> *// remove spaces from the begining of the key*
> *while*(*key==' ' && *key!='\0') { key++; }
>
> *if* (strlen(key) > 0 && strlen(value) > 0) {
>
> *// now we do actions on the parameters.*
> *if* (strcmp(key, "SomeOption") == 0) {
> *// settings.someoption = atoi(value);*
> }
> *else* *if* (strcmp(key, "AnotherOption") == 0)
> {
> *// settings.anotheroption =
> strdup(value); /* careful, copy of a string, should free this when not
> needed, for completeness. */*
> }
> *else* {
> fprintf(stderr, "Unknown option: %s\n",
> key);
> }
> }
> }
>
> free(copy);
> }
> }
>
>
Please note, that I haven't yet actually compiled and run it yet, am a bit
too busy with work at the moment. But it should be enough to go with.
I'll check it better later. I've actually got a branch on github which has
the changes committed to it:
http://github.com/hyper/memcached/tree/options_param
It is branched from dustins master (as of a few hours ago)
Ok, I've compiled it now, and seems ok.
On Tue, Mar 17, 2009 at 9:34 AM, Clint Webb <[email protected]> wrote:
> I've found my old code, and its rather ugly and not very portable. So I'd
> rather start from scratch. I've learnt a better way of parsing
> multi-delimited strings now anyway, so I'll whip something up.
>
>
>
> On Tue, Mar 17, 2009 at 9:23 AM, Dustin <[email protected]> wrote:
>
>>
>>
>> On Mar 16, 5:05 pm, Clint Webb <[email protected]> wrote:
>> > Actually that is a good point. I hadn't thought of that. I have some
>> > services that I wrote a long time ago that take a -o options setting,
>> which
>> > is for those odd options that are rarely used, but occassionaly needed
>> for
>> > fine-tuning...
>> >
>> > so I would have something like:
>> > webservice -v -a 127.0.0.1 -p 14077 -o
>> > "pre-fetch=1,fetch-fail-delay=15,lib-preload=0"
>> >
>> > If you're interested I could dig out the old code that does this... or
>> might
>> > not be difficult to start from scratch. That might be a good way of
>> > handling these kinds of rarely used settings.
>>
>> -o isn't taken yet, but that could be good. There are a few other
>> hard-coded values I've found in there that might be interesting to
>> adjust on a really rare base (e.g. how deep to walk the LRU when
>> looking for something eligible to evict).
>>
>> I don't know that it's *urgent* now. I like the idea that rarely-
>> used tweakability can be added, though.
>>
>
>
>
> --
> "Be excellent to each other"
>
--
"Be excellent to each other"