On Mon, 15 Dec 2014, Jeroen Ooms wrote:
The goal is to create a list of all available options (name and integer)
during compile-time, so that the user in the scripting language can name an
arbitrary option as a string (say "ACCEPT_ENCODING") at run-time.
I assume you'll be fine with only supporting the particular names this release
supports theb? I mean, the symbols-in-versions document for example also
includes names that no longer are in use.
Then we can use this list to (1) check if this option exists in the current
version, and (2) use the list to map that the string to the appropriate
integer that we need to feed to curl_easy_setopt. All at runtime.
To get the full set of strings, you need to extract them from either
inlude/curl/curl.h - which means relying on the CINIT lines to remain there as
they have for the last decade or so, or parsing and converting data from
docs/libcurl/symbols-in-versions which has a guaranteed format and is also
made sure to be accurate and updated by the test suite.
I would probably suggest something like the attached script. Run it in the
docs/libcurl directory and it'll generate a list with all known current
CURLOPT_ options. It also uses the LIBCURL_HAS() macro to make sure the
generated list also is possible to compile with older libcurl installations.
--
/ daniel.haxx.se
#!/usr/bin/perl
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 2011 - 2014, Daniel Stenberg, <[email protected]>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://curl.haxx.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
###########################################################################
#
# This generates a list of all known CURLOPT_ options that haven't been
# deprecated.
#
# This script assumes first run the symbols.pl script to generate the defines
# and the LIBCURL_HAS() macro so that this list will work even if you build
# with older libcurl headers present.
#
open F, "<symbols-in-versions";
print <<EOS
#include <curl/curl.h>
struct curloptarg {
char *name;
int value;
};
struct curloptarg list[] = {
EOS
;
while(<F>) {
if(/^(CURLOPT_[^ ]*)[ \t]*(.*)/) {
my ($sym, $vers)=($1, $2);
my $intr;
my $rm="";
my $dep;
# is there removed info?
if($vers =~ /([\d.]+)[ \t-]+([\d.-]+)[ \t]+([\d.]+)/) {
($intr, $dep, $rm)=($1, $2, $3);
}
# is it a dep-only line?
elsif($vers =~ /([\d.]+)[ \t-]+([\d.]+)/) {
($intr, $dep)=($1, $2);
}
else {
$intr = $vers;
}
if(!$rm) {
print <<EOS
#if LIBCURL_HAS($sym)
{ "${sym}", ${sym} },
#endif
EOS
;
}
}
}
print <<EOS
};
EOS
;
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html