2015-06-12 05:09:05 -04:00
|
|
|
/* vypr's typeprint */
|
|
|
|
/* https://github.com/vypr/typeprint */
|
|
|
|
|
2015-06-13 20:20:25 -04:00
|
|
|
#include <err.h>
|
2015-06-07 04:05:37 -04:00
|
|
|
#include <time.h>
|
2015-06-12 04:19:19 -04:00
|
|
|
#include <errno.h>
|
2015-06-07 04:05:37 -04:00
|
|
|
#include <stdio.h>
|
2015-06-12 04:23:06 -04:00
|
|
|
#include <unistd.h>
|
2015-06-07 04:05:37 -04:00
|
|
|
|
2015-06-07 17:09:03 -04:00
|
|
|
static int process(char *name);
|
2015-06-07 04:54:52 -04:00
|
|
|
|
2015-06-07 04:05:37 -04:00
|
|
|
static int
|
2015-06-07 17:09:03 -04:00
|
|
|
process(char *name)
|
2015-06-07 04:05:37 -04:00
|
|
|
{
|
2015-06-07 04:10:23 -04:00
|
|
|
FILE *file = fopen(name, "r");
|
2015-06-07 17:09:03 -04:00
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 10 * 1000000;
|
2015-06-07 04:05:37 -04:00
|
|
|
|
2015-06-12 04:25:35 -04:00
|
|
|
if (access(name, F_OK) == -1) {
|
2015-06-13 20:20:25 -04:00
|
|
|
errx(ENOENT, "[err] no such file or directory\n");
|
2015-06-07 04:10:23 -04:00
|
|
|
}
|
2015-06-07 04:05:37 -04:00
|
|
|
|
2015-06-12 04:25:35 -04:00
|
|
|
if (access(name, R_OK) == -1) {
|
2015-06-13 20:20:25 -04:00
|
|
|
errx(EACCES, "[err] can't read file, permission denied\n");
|
2015-06-12 04:23:06 -04:00
|
|
|
}
|
|
|
|
|
2015-06-07 04:10:23 -04:00
|
|
|
int x;
|
|
|
|
while ((x = fgetc(file)) != EOF) {
|
2015-06-07 04:54:52 -04:00
|
|
|
printf("%c", x);
|
2015-06-12 05:09:05 -04:00
|
|
|
|
|
|
|
/* flush stdout, because it won't look like typing without. */
|
2015-06-12 04:19:19 -04:00
|
|
|
fflush(stdout);
|
2015-06-12 05:09:05 -04:00
|
|
|
|
2015-06-07 17:09:03 -04:00
|
|
|
nanosleep(&ts, NULL);
|
2015-06-07 04:10:23 -04:00
|
|
|
}
|
2015-06-07 04:05:37 -04:00
|
|
|
|
2015-06-12 04:19:19 -04:00
|
|
|
fclose(file);
|
2015-06-07 04:10:23 -04:00
|
|
|
return 0;
|
2015-06-07 04:05:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2015-06-12 04:19:19 -04:00
|
|
|
return process(argv[1]);
|
2015-06-07 17:09:03 -04:00
|
|
|
}
|