Introduction
Introduction Statistics Contact Development Disclaimer Help
cli.c - frontends - front-ends for some sites (experiment)
Log
Files
Refs
README
LICENSE
---
cli.c (1418B)
---
1 #include <sys/types.h>
2
3 #include <ctype.h>
4 #include <err.h>
5 #include <errno.h>
6 #include <locale.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <wchar.h>
12
13 #include "duckduckgo.h"
14 #include "https.h"
15 #include "util.h"
16
17 #define OUT(s) fputs((s), stdout)
18 #define OUTESCAPE(s) printescape((s))
19
20 /* print: ignore control-characters */
21 void
22 printescape(const char *s)
23 {
24 for (; *s; ++s)
25 if (!iscntrl((unsigned char)*s))
26 fputc(*s, stdout);
27 }
28
29 int
30 main(int argc, char *argv[])
31 {
32 struct duckduckgo_results *results;
33 struct duckduckgo_result *result;
34 char buf[512];
35 size_t i;
36
37 setlocale(LC_CTYPE, "");
38
39 if (pledge("stdio dns inet rpath unveil", NULL) == -1) {
40 fprintf(stderr, "pledge: %s\n", strerror(errno));
41 exit(1);
42 }
43 if (unveil(TLS_CA_CERT_FILE, "r") == -1) {
44 fprintf(stderr, "unveil: %s\n", strerror(errno));
45 exit(1);
46 }
47 if (unveil(NULL, NULL) == -1) {
48 fprintf(stderr, "unveil: %s\n", strerror(errno));
49 exit(1);
50 }
51
52 if (argc != 2) {
53 fprintf(stderr, "usage: %s <search>\n", argv[0]);
54 exit(1);
55 }
56
57 results = duckduckgo_search(argv[1]);
58 if (pledge("stdio", NULL) == -1)
59 err(1, "pledge");
60
61 if (results) {
62 for (i = 0; i < results->nitems; i++) {
63 result = &(results->items[i]);
64
65 if (utf8pad(buf, sizeof(buf), result->title, 70,…
66 OUTESCAPE(buf);
67 OUT(" ");
68 OUTESCAPE(result->urldecoded);
69 OUT("\n");
70 }
71 }
72
73 return 0;
74 }
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.