From c0d698e32ee1c1c23f3af30ffc888ca0f0ea6b4b Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Apr 23 2015 21:36:18 +0000 Subject: Switch base2pem test tool to popt Switch the base2pem test tool, which formats base64-encoded input as PEM output, to use popt. Make the type of data which the output claims to be ("CERTIFICATE") an option, too. --- diff --git a/tests/tools/base2pem.c b/tests/tools/base2pem.c index fbfb5ec..40e7420 100644 --- a/tests/tools/base2pem.c +++ b/tests/tools/base2pem.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Red Hat, Inc. + * Copyright (C) 2011,2015 Red Hat, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,6 @@ #include "../../src/config.h" #include -#include #include #include #include @@ -28,15 +27,29 @@ #include +#include + #include "../../src/submit-u.h" int -main(int argc, char **argv) +main(int argc, const char **argv) { - char buf[LINE_MAX], *p = NULL, *q; + char buf[LINE_MAX], *p = NULL, *q, *type = "CERTIFICATE"; int dos = 1, c; + poptContext pctx; + struct poptOption popts[] = { + {"dos", 'd', POPT_ARG_NONE, NULL, 'd', "output using DOS-style end-of-lines", NULL}, + {"unix", 'u', POPT_ARG_NONE, NULL, 'u', "output using Unix-style end-of-lines", NULL}, + {"type", 't', POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &type, 0, "data type to claim", NULL}, + POPT_AUTOHELP + POPT_TABLEEND + }; - while ((c = getopt(argc, argv, "du")) != -1) { + pctx = poptGetContext("base2pem", argc, argv, popts, 0); + if (pctx == NULL) { + return 1; + } + while ((c = poptGetNextOpt(pctx)) > 0) { switch (c) { case 'd': dos = 1; @@ -46,6 +59,10 @@ main(int argc, char **argv) break; } } + if (c != -1) { + poptPrintUsage(pctx, stdout, 0); + return 1; + } while (fgets(buf, sizeof(buf), stdin) != NULL) { if (p == NULL) { p = strdup(buf); @@ -58,6 +75,6 @@ main(int argc, char **argv) } } } - printf("%s", cm_submit_u_pem_from_base64("CERTIFICATE", dos, p)); + printf("%s", cm_submit_u_pem_from_base64(type, dos, p)); return 0; }