diff --git a/Makefile b/Makefile index a2854106..017eeb50 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -linenoise_example: linenoise.h linenoise.c +all: linenoise.h linenoise.c -linenoise_example: linenoise.c example.c +all: linenoise.c example.c $(CC) -Wall -W -Os -g -o linenoise_example linenoise.c example.c clean: diff --git a/example.c b/example.c index 3a7f8b37..8fb919c2 100644 --- a/example.c +++ b/example.c @@ -6,13 +6,13 @@ void completion(const char *buf, linenoiseCompletions *lc) { if (buf[0] == 'h') { - linenoiseAddCompletion(lc,"hello"); - linenoiseAddCompletion(lc,"hello there"); + linenoiseAddCompletion(lc, "hello"); + linenoiseAddCompletion(lc, "hello there"); } } char *hints(const char *buf, int *color, int *bold) { - if (!strcasecmp(buf,"hello")) { + if (!strcasecmp(buf, "hello")) { *color = 35; *bold = 0; return " World"; @@ -26,16 +26,16 @@ int main(int argc, char **argv) { int async = 0; /* Parse options, with --multiline we enable multi line editing. */ - while(argc > 1) { + while (argc > 1) { argc--; argv++; - if (!strcmp(*argv,"--multiline")) { + if (!strcmp(*argv, "--multiline")) { linenoiseSetMultiLine(1); printf("Multi-line mode enabled.\n"); - } else if (!strcmp(*argv,"--keycodes")) { + } else if (!strcmp(*argv, "--keycodes")) { linenoisePrintKeyCodes(); exit(0); - } else if (!strcmp(*argv,"--async")) { + } else if (!strcmp(*argv, "--async")) { async = 1; } else { fprintf(stderr, "Usage: %s [--multiline] [--keycodes] [--async]\n", prgname); @@ -59,7 +59,7 @@ int main(int argc, char **argv) { * The typed string is returned as a malloc() allocated string by * linenoise, so the user needs to free() it. */ - while(1) { + while (1) { if (!async) { line = linenoise("hello> "); if (line == NULL) break; @@ -69,34 +69,34 @@ int main(int argc, char **argv) { * using the select(2) timeout. */ struct linenoiseState ls; char buf[1024]; - linenoiseEditStart(&ls,-1,-1,buf,sizeof(buf),"hello> "); - while(1) { - fd_set readfds; - struct timeval tv; - int retval; + linenoiseEditStart(&ls, -1, -1, buf, sizeof(buf), "hello> "); + while (1) { + fd_set readfds; + struct timeval tv; + int retval; - FD_ZERO(&readfds); - FD_SET(ls.ifd, &readfds); - tv.tv_sec = 1; // 1 sec timeout - tv.tv_usec = 0; + FD_ZERO(&readfds); + FD_SET(ls.ifd, &readfds); + tv.tv_sec = 1; // 1 sec timeout + tv.tv_usec = 0; - retval = select(ls.ifd+1, &readfds, NULL, NULL, &tv); - if (retval == -1) { - perror("select()"); + retval = select(ls.ifd + 1, &readfds, NULL, NULL, &tv); + if (retval == -1) { + perror("select()"); exit(1); - } else if (retval) { - line = linenoiseEditFeed(&ls); + } else if (retval) { + line = linenoiseEditFeed(&ls); /* A NULL return means: line editing is continuing. * Otherwise the user hit enter or stopped editing * (CTRL+C/D). */ if (line != linenoiseEditMore) break; - } else { - // Timeout occurred + } else { + // Timeout occurred static int counter = 0; linenoiseHide(&ls); - printf("Async output %d.\n", counter++); + printf("Async output %d.\n", counter++); linenoiseShow(&ls); - } + } } linenoiseEditStop(&ls); if (line == NULL) exit(0); /* Ctrl+D/C. */ @@ -107,9 +107,9 @@ int main(int argc, char **argv) { printf("echo: '%s'\n", line); linenoiseHistoryAdd(line); /* Add to the history. */ linenoiseHistorySave("history.txt"); /* Save the history on disk. */ - } else if (!strncmp(line,"/historylen",11)) { + } else if (!strncmp(line, "/historylen", 11)) { /* The "/historylen" command will change the history len. */ - int len = atoi(line+11); + int len = atoi(line + 11); linenoiseHistorySetMaxLen(len); } else if (!strncmp(line, "/mask", 5)) { linenoiseMaskModeEnable();