From 8997cc9cfca46c31d20a8e91372d63536f19ef0c Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 19 Dec 2024 09:08:31 +0100 Subject: add rpmexpand, rpmexpandnumeric to retrieve rpm macro value add rpmdefine to set rpm macro value --- rpminfo.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'rpminfo.c') diff --git a/rpminfo.c b/rpminfo.c index 55a5351..17d08b4 100644 --- a/rpminfo.c +++ b/rpminfo.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "php_rpminfo.h" @@ -867,6 +868,64 @@ PHP_FUNCTION(rpmgetsymlink) } /* }}} */ +/* {{{ proto array rpmexpand(string $text): string + Expand macro in text */ +PHP_FUNCTION(rpmexpand) +{ + char *text, *result; + size_t len; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &text, &len) == FAILURE) { + RETURN_THROWS(); + } + + (void)rpminfo_getts(); // read config files + + result = rpmExpand(text, NULL); + RETVAL_STRING(result); + free(result); +} +/* }}} */ + +/* {{{ proto array rpmexpandnumeric(string $text): int + Expand macro in text */ +PHP_FUNCTION(rpmexpandnumeric) +{ + char *text; + size_t len; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &text, &len) == FAILURE) { + RETURN_THROWS(); + } + + (void)rpminfo_getts(); // read config files + + result = rpmExpandNumeric(text); + + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto array rpmdefine(string $macro): bool + Define a new macro */ +PHP_FUNCTION(rpmdefine) +{ + char *macro; + size_t len; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", ¯o, &len) == FAILURE) { + RETURN_THROWS(); + } + + (void)rpminfo_getts(); // read config files + + result = rpmDefineMacro(NULL, macro, RMIL_GLOBAL); + + RETURN_BOOL(result == 0); +} +/* }}} */ /* {{{ PHP_MINIT_FUNCTION */ -- cgit