diff options
Diffstat (limited to 'pkg/mpv/file2string.c')
| -rw-r--r-- | pkg/mpv/file2string.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/mpv/file2string.c b/pkg/mpv/file2string.c new file mode 100644 index 00000000..84f31ce1 --- /dev/null +++ b/pkg/mpv/file2string.c @@ -0,0 +1,34 @@ +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +static const char safe[] = + "][ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#%&'()*+,./:;<=>^_{|}~ -"; + +int main(int argc, char *argv[]) { + FILE *f; + char *line = NULL, *s; + size_t size = 0; + ssize_t n; + + f = fopen(argv[1], "r"); + if (!f) { + fprintf(stderr, "fopen %s: %s\n", argv[1], strerror(errno)); + return 1; + } + + printf("/* Generated from %s */\n", argv[1]); + while ((n = getline(&line, &size, f)) >= 0) { + printf("\""); + for (s = line; s < line + n; ++s) { + if (memchr(safe, *s, sizeof(safe) - 1)) + fputc(*s, stdout); + else + printf("\\%03hho", *s); + } + printf("\"\n"); + } + + return 0; +} |
