#include "phase.h" #include static int read_line(FILE *input, char *line, size_t size, int *too_long) { size_t used = 0; int character; int seen = 0; *too_long = 0; while ((character = fgetc(input)) != EOF) { seen = 1; if (character == '\n') { break; } if (used + 1 < size) { line[used++] = (char)character; } else { *too_long = 1; } } line[used] = '\0'; if (used > 255) { *too_long = 1; } return seen; } int timer_cli(FILE *input, FILE *output) { TimerBank bank; char line[TIMER_LINE_SIZE]; int too_long; timer_bank_reset(&bank, 0); while (read_line(input, line, sizeof(line), &too_long)) { if (too_long) { fputs("ERR syntax\n", output); } else { (void)timer_wire(&bank, line, output); } } if (ferror(input)) { return 1; } if (fflush(output) != 0) { return 1; } return 0; }