#include #include #include #include void preprocess_line(char *s) { int i; for (i = 0; s[i] != '\0'; i++) { if (s[i] <= 'z' && s[i] >= 'a') s[i] += ('A'-'a'); } } void postprocess_line(char *s) { int i; char buf[500]; if (strlen(s) > 490) return; sprintf(buf, "Output: %s", s); strcpy(s, buf); return; } main() { char line[500]; int p1[2], p2[2]; FILE *fin, *fout; pipe(p1); pipe(p2); if (fork() == 0) { dup2(p1[0], 0); dup2(p2[1], 1); close(p1[0]); close(p1[1]); close(p2[0]); close(p2[1]); execl("./chpmnk", "chpmnk", NULL); perror("execl chpmnk"); exit(1); } close(p1[0]); close(p2[1]); fin = fdopen(p2[0], "r"); fout = fdopen(p1[1], "w"); while (fgets(line, 500, stdin) != NULL) { preprocess_line(line); fputs(line, fout); fflush(fout); if (fgets(line, 500, fin) == NULL) { fprintf(stderr, "Alvin, Simon and Theodore messed up again.\n"); exit(1); } postprocess_line(line); fputs(line, stdout); } exit(0); }