Permalink
Browse files

Pass a file to read a line from.

  • Loading branch information...
1 parent d94ad0b commit 682995505f8051664a9c0b82eb59ea91b59bb631 @theory committed Jan 25, 2013
Showing with 3 additions and 3 deletions.
  1. +3 −3 main.c
View
6 main.c
@@ -33,7 +33,7 @@ void parse(const char *commandLine) {
}
// Borrowed from http://stackoverflow.com/a/314422/79202.
-char * get_stdin_line(void) {
+char * getline_from(FILE *fp) {
char * line = malloc(100), * linep = line;
size_t lenmax = 100, len = lenmax;
int c;
@@ -42,7 +42,7 @@ char * get_stdin_line(void) {
return NULL;
for(;;) {
- c = fgetc(stdin);
+ c = fgetc(fp);
if(c == EOF)
break;
@@ -69,7 +69,7 @@ int main(int argc, char** argv) {
void* shellParser = ParseAlloc(malloc);
char *line;
printf("> ");
- while ( line = get_stdin_line() ) {
+ while ( line = getline_from(stdin) ) {
parse(line);
free(line);
printf("> ");

0 comments on commit 6829955

Please sign in to comment.