From daae918d60f319dbdae18917659e2f104de2b6e3 Mon Sep 17 00:00:00 2001 From: ABevier Date: Mon, 6 Mar 2023 09:42:27 -0500 Subject: [PATCH] +popt --- projects/rpm.org/popt/package.yml | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 projects/rpm.org/popt/package.yml diff --git a/projects/rpm.org/popt/package.yml b/projects/rpm.org/popt/package.yml new file mode 100644 index 00000000..5ddf3e3d --- /dev/null +++ b/projects/rpm.org/popt/package.yml @@ -0,0 +1,72 @@ +distributable: + url: http://ftp.rpm.org/popt/releases/popt-1.x/popt-{{ version.raw }}.tar.gz + strip-components: 1 + +versions: + github: rpm-software-management/popt/releases/tags + strip: + - /^popt-/ + - /-release$/ + +build: + dependencies: + tea.xyz/gx/cc: c99 + tea.xyz/gx/make: '*' + script: | + ./configure --disable-debug --disable-dependency-tracking --prefix={{ prefix }} + make install + +test: + dependencies: + tea.xyz/gx/cc: c99 + script: | + mv $FIXTURE test.c + gcc test.c -lpopt -o test + test "$(./test -a 123 -b 456 -c 789 -f)" = "123::456::789::1::0" + test "$(./test --optiona=987 --optionb=654 --optionc=321 --flag2)" = "987::654::321::0::1" + fixture: | + #include + #include + #include + int main(int argc, char *argv[]) { + int optiona=-1, optionb=-1, optionc=-1, flag1=0, flag2=0; + poptContext pc; + struct poptOption po[] = { + {"optiona", 'a', POPT_ARG_INT, &optiona, 11001, "descrip1", "argDescrip1"}, + {"optionb", 'b', POPT_ARG_INT, &optionb, 11002, "descrip2", "argDescrip2"}, + {"optionc", 'c', POPT_ARG_INT, &optionc, 11003, "descrip3", "argDescrip3"}, + {"flag1", 'f', POPT_ARG_NONE, &flag1, 11004, "descrip4", "argDescrip4"}, + {"flag2", 'g', POPT_ARG_NONE, &flag2, 11005, "descrip5", "argDescrip5"}, + POPT_AUTOHELP + {NULL} + }; + + pc = poptGetContext(NULL, argc, (const char **)argv, po, 0); + poptSetOtherOptionHelp(pc, "[ARG...]"); + if (argc < 2) { + poptPrintUsage(pc, stderr, 0); + exit(1); + } + int val; + while ((val = poptGetNextOpt(pc)) >= 0); + if (val != -1) { + switch(val) { + case POPT_ERROR_NOARG: + printf("Argument missing for an option\\n"); + exit(1); + case POPT_ERROR_BADOPT: + printf("Option's argument could not be parsed\\n"); + exit(1); + case POPT_ERROR_BADNUMBER: + case POPT_ERROR_OVERFLOW: + printf("Option could not be converted to number\\n"); + exit(1); + default: + printf("Unknown error in option processing\\n"); + exit(1); + } + } + printf("%d::%d::%d::%d::%d", optiona, optionb, optionc, flag1, flag2); + return 0; + } +