hachem.wtf
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-02 01:29:46 +0200
committerhachem <im@hachem.wtf>2026-09-02 01:29:46 +0200
commit0699f07fb537d108a513a90ce44332138b5570ed (patch)
treeb1c900f4b3dc5bd7674164d46ae1447ba827865b
parent5a1d0b1dcd07933cbcedbecf7ffbc90aa28935f8 (diff)
feat: search manpages location
-rw-r--r--src/main.c40
1 files 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 <stdio.h>
+#include <string.h>
-int main(void)
+int main(int argc, char** argv)
{
- (void) puts("type shi");
+ if (argc != 2)
+ {
+ (void) fprintf(stderr, "usage: %s <symbol>\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;
}