summaryrefslogtreecommitdiff
path: root/pkgrel.c
diff options
context:
space:
mode:
Diffstat (limited to 'pkgrel.c')
-rw-r--r--pkgrel.c30
1 files changed, 27 insertions, 3 deletions
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);
}