Re: [PATCH 3/3] Replace all popt use with glib's option parsing code.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, 17 Nov 2009, Jeremy Katz wrote:

On Tue, Nov 17, 2009 at 10:11 PM, David Cantrell <dcantrell@xxxxxxxxxx> wrote:
We have glib for other things, so we can use it for option parsing and
dump another library dependency.

Are glib's option parsing semantics the same as popt, especially in
terms of --long=foo vs --long foo and the like?  I *think* so, but if
not, then it could cause problems for people's existing kickstart
configs.

Looks like --long=foo and --long foo will work.  Example:

    #include <stdio.h>
    #include <stdlib.h>
    #include <glib.h>

    int main(int argc, char **argv) {
        gchar *firstopt = NULL;
        gboolean secondopt = FALSE;
        GOptionContext *optCon = g_option_context_new(NULL);
        GError *optErr = NULL;
        GOptionEntry options[] = {
            { "firstopt", 'f', 0, G_OPTION_ARG_STRING, &firstopt,
              NULL, NULL },
            { "secondopt", 's', 0, G_OPTION_ARG_NONE, &secondopt,
              NULL, NULL },
            { NULL },
        };

        g_option_context_add_main_entries(optCon, options, NULL);

        if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
            fprintf(stderr, "error: %s\n", optErr->message);
            g_error_free(optErr);
            g_option_context_free(optCon);
            return EXIT_FAILURE;
        }

        g_option_context_free(optCon);

        printf("firstopt: %s\n", firstopt);
        printf("secondopt: %s\n", (secondopt ? "TRUE" : "FALSE"));
        return EXIT_SUCCESS;
    }



Compiled and run:

dcantrel@mitre ~$ gcc -O0 -Wall -g $(pkg-config --cflags glib-2.0) test2.c \
                                   $(pkg-config --libs glib-2.0)
dcantrel@mitre ~$ ./a.out
firstopt: (null)
secondopt: FALSE
dcantrel@mitre ~$ ./a.out --firstopt=thing
firstopt: thing
secondopt: FALSE
dcantrel@mitre ~$ ./a.out --firstopt thing
firstopt: thing
secondopt: FALSE
dcantrel@mitre ~$ ./a.out -f thing
firstopt: thing
secondopt: FALSE
dcantrel@mitre ~$ ./a.out -f thing -s
firstopt: thing
secondopt: TRUE
dcantrel@mitre ~$ ./a.out -f thing --secondopt
firstopt: thing
secondopt: TRUE
dcantrel@mitre ~$ ./a.out --firstopt thing --secondopt
firstopt: thing
secondopt: TRUE

- -- David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAksEI/IACgkQ5hsjjIy1VkkYtgCdEKVDsZ9nMCsUjLKpC2nERCga
KTYAnj3GaysjOzVzFySXeWaEUQ4kuG2j
=Rc0S
-----END PGP SIGNATURE-----

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux