From 0699f07fb537d108a513a90ce44332138b5570ed Mon Sep 17 00:00:00 2001 From: hachem Date: Wed, 2 Sep 2026 01:29:46 +0200 Subject: feat: search manpages location --- src/main.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 45f759c..bb435bc 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,42 @@ #include +#include -int main(void) +int main(int argc, char** argv) { - (void) puts("type shi"); + if (argc != 2) + { + (void) fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + const char* query = argv[1]; + + (void) printf("searching for: %s\n", query); + + FILE* pipe = popen("manpath", "r"); + if (pipe == NULL) + { + (void) fprintf(stderr, "jafm: failed to run manpath\n"); + return 1; + } + + char buffer[4096]; + if (fgets(buffer, sizeof(buffer), pipe) == NULL) + { + (void) fprintf(stderr, "jafm: failed to read manpath\n"); + (void) pclose(pipe); + return 1; + } + + (void) pclose(pipe); + + buffer[strcspn(buffer, "\n")] = '\0'; + + char* saveptr = NULL; + for (char* dir = strtok_r(buffer, ":", &saveptr); + dir != NULL; + dir = strtok_r(NULL, ":", &saveptr)) + (void) printf("man dir: %s\n", dir); + + return 0; } -- cgit v1.3