Created
November 11, 2013 18:22
-
-
Save Softwave/7417801 to your computer and use it in GitHub Desktop.
Typer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/* | |
* RetroTerm | |
*/ | |
static void prnt(char ch); | |
int mode = 0; | |
int cdelay = 10 * 1000; | |
int ldelay = 10 * 1000; | |
int i = 0; | |
//char* strng; | |
int main(int argc, char **argv) { | |
for (i = 2; i < argc; i++) { | |
//Go through the arguments | |
if (strcmp(argv[1], "f") == 0) { | |
//load file | |
char *file_contents; | |
long f_size; | |
FILE* f = fopen(argv[2], "rb"); | |
fseek(f, 0, SEEK_END); | |
f_size = ftell(f); | |
rewind(f); | |
file_contents = malloc(f_size * (sizeof(char))); | |
fread(file_contents, sizeof(char), f_size,f); | |
fclose(f); | |
//file_contents is the file | |
prnt('\n'); | |
for (i = 0; i<=strlen(file_contents);i++) { | |
prnt(file_contents[i]); | |
} | |
} else if (strcmp(argv[1], "i") == 0) { | |
if (!*argv[2]) { | |
prnt('\n'); | |
} | |
int j = 0; | |
char* strng = argv[2]; | |
for (j = 0; j<=strlen(strng);j++) { | |
prnt(strng[j]); | |
} | |
}//end if stdin | |
}//end for | |
return 0; | |
}//end main | |
static void prnt(char ch) { | |
write(1, &ch, 1); | |
system("cat beep.txt"); //play beeping sound | |
usleep(ch == '\n' ? ldelay : cdelay); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment