blind-from-text.c - blind - suckless command-line video editing utility | |
git clone git://git.suckless.org/blind | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
blind-from-text.c (1318B) | |
--- | |
1 /* See LICENSE file for copyright and license details. */ | |
2 #ifndef TYPE | |
3 #define INCLUDE_UINT16 | |
4 #include "common.h" | |
5 | |
6 USAGE("") | |
7 | |
8 #define FILE "blind-from-text.c" | |
9 #include "define-functions.h" | |
10 | |
11 int | |
12 main(int argc, char *argv[]) | |
13 { | |
14 struct stream stream; | |
15 size_t size = 0; | |
16 char *line = NULL; | |
17 ssize_t len; | |
18 void (*process)(void); | |
19 | |
20 UNOFLAGS(argc); | |
21 | |
22 len = getline(&line, &size, stdin); | |
23 if (len < 0) { | |
24 if (ferror(stdin)) | |
25 eprintf("getline <stdin>:"); | |
26 else | |
27 eprintf("<stdin>: no input\n"); | |
28 } | |
29 if (len && line[len - 1] == '\n') | |
30 line[--len] = '\0'; | |
31 if ((size_t)len + 6 > sizeof(stream.buf)) | |
32 eprintf("<stdin>: head is too long\n"); | |
33 stream.fd = -1; | |
34 stream.file = "<stdin>"; | |
35 memcpy(stream.buf, line, (size_t)len); | |
36 memcpy(stream.buf + len, "\n\0uivf", 6); | |
37 stream.ptr = (size_t)len + 6; | |
38 free(line); | |
39 ewriteall(STDOUT_FILENO, stream.buf, stream.ptr, "<stdout>"); | |
40 einit_stream(&stream); | |
41 | |
42 SELECT_PROCESS_FUNCTION(&stream); | |
43 process(); | |
44 | |
45 efshut(stdin, "<stdin>"); | |
46 return 0; | |
47 } | |
48 | |
49 #else | |
50 | |
51 static void | |
52 PROCESS(void) | |
53 { | |
54 TYPE buf[BUFSIZ / sizeof(TYPE)]; | |
55 size_t i; | |
56 int r, done = 0; | |
57 while (!done) { | |
58 for (i = 0; i < ELEMENTSOF(buf); i += (size_t)r) { | |
59 r = scanf("%"SCAN_TYPE, buf + i); | |
60 if (r == EOF) { | |
61 done = 1; | |
62 break; | |
63 } | |
64 } | |
65 ewriteall(STDOUT_FILENO, buf, i * sizeof(*buf), "<stdout… | |
66 } | |
67 } | |
68 | |
69 #endif |