diff --git a/README.md b/README.md index f64b7c0..0807133 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # typeprint -A quick script to print text files as if it was being typed. +A quick program to print text files as if it was being typed. diff --git a/c/typeprint.c b/c/typeprint.c new file mode 100644 index 0000000..608c4bc --- /dev/null +++ b/c/typeprint.c @@ -0,0 +1,36 @@ +#include +#include +#include + +static int +process(char *name, struct timespec *ts) +{ + FILE *file = fopen(name, "r"); + + if (file == 0){ + fprintf(stderr, "[err] you either gave me an invalid file, or no file at all"); + return -1; + } + + int x; + while ((x = fgetc(file)) != EOF) { + printf("%c", x); + nanosleep(ts, NULL); + } + + return 0; +} + +int +main(int argc, char *argv[]) +{ + char *argv0; + + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 10 * 1000000; + + process(argv[1], &ts); + + return 0; +} \ No newline at end of file diff --git a/go/bin.go b/go/bin.go new file mode 100644 index 0000000..55ce46d --- /dev/null +++ b/go/bin.go @@ -0,0 +1,36 @@ +package main + +import ( + "os" + "io/ioutil" + "fmt" + "time" +) + +func processFile(filename string) { + file, err := ioutil.ReadFile(filename) + + if err != nil { + panic(err) + } + + for _, j := range file { + if string(j) == "\n" { + fmt.Printf("\n") + } else { + fmt.Printf("%c", j) + } + + time.Sleep(time.Millisecond * time.Duration(10)) + } +} + +func main() { + args := os.Args[1:] + + if len(args) == 1 { + processFile(args[0]) + } else { + fmt.Println("needs a file to process") + } +} diff --git a/typeprint.go b/typeprint.go deleted file mode 100644 index 8b13789..0000000 --- a/typeprint.go +++ /dev/null @@ -1 +0,0 @@ -