diff options
| author | hachem <im@hachem.wtf> | 2026-09-02 01:29:46 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-02 01:29:46 +0200 |
| commit | 0699f07fb537d108a513a90ce44332138b5570ed (patch) | |
| tree | b1c900f4b3dc5bd7674164d46ae1447ba827865b | |
| parent | 5a1d0b1dcd07933cbcedbecf7ffbc90aa28935f8 (diff) | |
feat: search manpages location
| -rw-r--r-- | src/main.c | 40 |
1 files changed, 38 insertions, 2 deletions
@@ -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; } |
