1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
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;
}
|