2013-10-09 03:58:35 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-10-09 04:14:48 -04:00
|
|
|
#define LINE_MAX_LENGTH 256
|
|
|
|
|
2013-10-09 03:58:35 -04:00
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
2013-10-09 04:14:48 -04:00
|
|
|
char line[LINE_MAX_LENGTH], last_char;
|
2013-10-09 04:10:32 -04:00
|
|
|
int char_index;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
printf("> ");
|
|
|
|
|
|
|
|
char_index = 0;
|
|
|
|
while ((last_char = getchar()) != '\n') {
|
|
|
|
if (last_char == EOF)
|
|
|
|
goto eof;
|
2013-10-09 04:14:48 -04:00
|
|
|
if (char_index == LINE_MAX_LENGTH)
|
|
|
|
goto overflow;
|
2013-10-09 04:10:32 -04:00
|
|
|
line[char_index++] = last_char;
|
|
|
|
}
|
|
|
|
line[char_index] = '\0';
|
|
|
|
|
|
|
|
/* echo */
|
|
|
|
printf("%s", line);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
eof:
|
|
|
|
puts("");
|
2013-10-09 04:14:48 -04:00
|
|
|
goto exit;
|
|
|
|
|
|
|
|
overflow:
|
|
|
|
puts("** [fatal] line input overflow");
|
|
|
|
goto exit;
|
2013-10-09 04:10:32 -04:00
|
|
|
|
2013-10-09 04:14:48 -04:00
|
|
|
exit:
|
2013-10-09 03:58:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|