From 080d76ce2cbe6883941b01fb46b5dbee3b0d72c9 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 6 Jan 2024 02:42:16 +0100 Subject: Added prefix and -d option --- pkgrel.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'pkgrel.c') diff --git a/pkgrel.c b/pkgrel.c index ecbfcea..961ecbd 100644 --- a/pkgrel.c +++ b/pkgrel.c @@ -112,11 +112,35 @@ match_line(const git_diff_delta* delta, const git_diff_hunk* hunk, const git_dif } +/// Parses an optional output prefix from *args* and returns it. +const char* +parse_args(const int argc, char* argv[]) +{ + int opt; + const char* prefix = NULL; + while (-1 != (opt = getopt(argc, argv, ":d"))) { + switch (opt) { + case 'd': + prefix = "pkgrel="; + break; + default: + break; // Accept anything but -d without prior -- + } + } + if (NULL == prefix) { + if (argc > optind) + prefix = argv[optind]; + else + prefix = ""; + } + return prefix; +} + + int main(int argc, char* argv[]) { - (void) argc; - (void) argv; + const char* prefix = parse_args(argc, argv); FILE* file = fopen("PKGBUILD", "r"); if (NULL == file) { dprintf(2, "PKGBUILD not found or cannot be opened\n"); @@ -176,5 +200,5 @@ main(int argc, char* argv[]) exit(1); } else - printf("%d\n", relpkg); + printf("%s%d\n", prefix, relpkg); } -- cgit v1.1