Skip to content

Commit 46ccdf8

Browse files
authored
Merge pull request #16 from yhirose/clang-format
Format source files with clang-format
2 parents bdb9356 + 6af68dd commit 46ccdf8

File tree

4 files changed

+859
-715
lines changed

4 files changed

+859
-715
lines changed

example.cpp

+43-35
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,54 @@
22
#include <stdlib.h>
33
#include <string.h>
44
#include <sys/select.h>
5+
56
#include "linenoise.h"
67

7-
static void completion(const char *buf, linenoiseCompletions *lc) {
8+
static void completion(const char * buf, linenoiseCompletions * lc) {
89
if (buf[0] == 'h') {
9-
linenoiseAddCompletion(lc,"hello");
10-
linenoiseAddCompletion(lc,"hello there");
11-
linenoiseAddCompletion(lc,"hello 😀");
10+
linenoiseAddCompletion(lc, "hello");
11+
linenoiseAddCompletion(lc, "hello there");
12+
linenoiseAddCompletion(lc, "hello 😀");
1213
}
1314

1415
const auto こ = "";
1516
if (!strncmp(buf, こ, strlen(こ))) {
16-
linenoiseAddCompletion(lc,"こんにちは hello");
17-
linenoiseAddCompletion(lc,"こんにちは hello there");
18-
linenoiseAddCompletion(lc,"こんにちは hello 😀");
17+
linenoiseAddCompletion(lc, "こんにちは hello");
18+
linenoiseAddCompletion(lc, "こんにちは hello there");
19+
linenoiseAddCompletion(lc, "こんにちは hello 😀");
1920
}
2021
}
2122

22-
static const char *hints(const char *buf, int *color, int *bold) {
23-
if (!strcasecmp(buf,"hello")) {
23+
static const char * hints(const char * buf, int * color, int * bold) {
24+
if (!strcasecmp(buf, "hello")) {
2425
*color = 35;
25-
*bold = 0;
26+
*bold = 0;
2627
return " World";
2728
}
28-
if (!strcasecmp(buf,"こんにちは")) {
29+
if (!strcasecmp(buf, "こんにちは")) {
2930
*color = 35;
30-
*bold = 0;
31+
*bold = 0;
3132
return " 世界";
3233
}
3334
return NULL;
3435
}
3536

36-
int main(int argc, char **argv) {
37-
const char *line;
38-
char *prgname = argv[0];
39-
int async = 0;
37+
int main(int argc, char ** argv) {
38+
const char * line;
39+
char * prgname = argv[0];
40+
int async = 0;
4041

4142
/* Parse options, with --multiline we enable multi line editing. */
42-
while(argc > 1) {
43+
while (argc > 1) {
4344
argc--;
4445
argv++;
45-
if (!strcmp(*argv,"--multiline")) {
46+
if (!strcmp(*argv, "--multiline")) {
4647
linenoiseSetMultiLine(1);
4748
printf("Multi-line mode enabled.\n");
48-
} else if (!strcmp(*argv,"--keycodes")) {
49+
} else if (!strcmp(*argv, "--keycodes")) {
4950
linenoisePrintKeyCodes();
5051
exit(0);
51-
} else if (!strcmp(*argv,"--async")) {
52+
} else if (!strcmp(*argv, "--async")) {
5253
async = 1;
5354
} else {
5455
fprintf(stderr, "Usage: %s [--multiline] [--keycodes] [--async]\n", prgname);
@@ -72,28 +73,30 @@ int main(int argc, char **argv) {
7273
* The typed string is returned as a malloc() allocated string by
7374
* linenoise, so the user needs to free() it. */
7475

75-
while(1) {
76+
while (1) {
7677
if (!async) {
7778
line = linenoise("😀 \033[32mhello\x1b[0m> ");
78-
if (line == NULL) break;
79+
if (line == NULL) {
80+
break;
81+
}
7982
} else {
8083
/* Asynchronous mode using the multiplexing API: wait for
8184
* data on stdin, and simulate async data coming from some source
8285
* using the select(2) timeout. */
8386
struct linenoiseState ls;
84-
char buf[1024];
85-
linenoiseEditStart(&ls,-1,-1,buf,sizeof(buf),"hello> ");
86-
while(1) {
87-
fd_set readfds;
87+
char buf[1024];
88+
linenoiseEditStart(&ls, -1, -1, buf, sizeof(buf), "hello> ");
89+
while (1) {
90+
fd_set readfds;
8891
struct timeval tv;
89-
int retval;
92+
int retval;
9093

9194
FD_ZERO(&readfds);
9295
FD_SET(ls.ifd, &readfds);
93-
tv.tv_sec = 1; // 1 sec timeout
96+
tv.tv_sec = 1; // 1 sec timeout
9497
tv.tv_usec = 0;
9598

96-
retval = select(ls.ifd+1, &readfds, NULL, NULL, &tv);
99+
retval = select(ls.ifd + 1, &readfds, NULL, NULL, &tv);
97100
if (retval == -1) {
98101
perror("select()");
99102
exit(1);
@@ -102,7 +105,9 @@ int main(int argc, char **argv) {
102105
/* A NULL return means: line editing is continuing.
103106
* Otherwise the user hit enter or stopped editing
104107
* (CTRL+C/D). */
105-
if (line != linenoiseEditMore) break;
108+
if (line != linenoiseEditMore) {
109+
break;
110+
}
106111
} else {
107112
// Timeout occurred
108113
static int counter = 0;
@@ -112,17 +117,19 @@ int main(int argc, char **argv) {
112117
}
113118
}
114119
linenoiseEditStop(&ls);
115-
if (line == NULL) exit(0); /* Ctrl+D/C. */
120+
if (line == NULL) {
121+
exit(0); /* Ctrl+D/C. */
122+
}
116123
}
117124

118125
/* Do something with the string. */
119126
if (line[0] != '\0' && line[0] != '/') {
120127
printf("echo: '%s'\n", line);
121-
linenoiseHistoryAdd(line); /* Add to the history. */
128+
linenoiseHistoryAdd(line); /* Add to the history. */
122129
linenoiseHistorySave("history.txt"); /* Save the history on disk. */
123-
} else if (!strncmp(line,"/historylen",11)) {
130+
} else if (!strncmp(line, "/historylen", 11)) {
124131
/* The "/historylen" command will change the history len. */
125-
int len = atoi(line+11);
132+
int len = atoi(line + 11);
126133
linenoiseHistorySetMaxLen(len);
127134
} else if (!strncmp(line, "/mask", 5)) {
128135
linenoiseMaskModeEnable();
@@ -131,7 +138,8 @@ int main(int argc, char **argv) {
131138
} else if (line[0] == '/') {
132139
printf("Unrecognized command: %s\n", line);
133140
}
134-
free((void*) line);
141+
free((void *) line);
135142
}
136143
return 0;
137144
}
145+

0 commit comments

Comments
 (0)