int get_next_line(const int fd, char **line) { static char *save = NULL; static char *todel = NULL; int check; int i; check = 1; if (!save || !strchr(save, '\n')) { check = readnl(fd, &save); todel = save; } if (check == -1) return (-1); if (check == 0) save = NULL; i = find_and_replace(save); *line = ft_strdup(save); if (i == 1) save += ft_strlen(save) + 1; else { free(todel); save = NULL; } return (check); }
int bug_d(MENU_ARGS) { int i; char result; /* Make the bug appear */ do { cup(14, 1); /* The original code in the article says * PRINT ESC$; "[13;1H"; CHR$(10%); * but I guess a cup(14,1); would do. * (To output a pure LF might be tricky). */ deccolm(TRUE); /* Make the bug visible */ cup(1, 9); decdwl(); println("You should see blinking text at the bottom line."); cup(3, 9); decdwl(); println("Enter 0 to exit, 1 to try to invoke the bug again."); cup(max_lines, 9); decdwl(); sgr("1;5;7"); printf("If you can see this then the bug did not appear."); sgr(""); cup(4, 9); decdwl(); result = inchar(); readnl(); deccolm(FALSE); } while (result == '1'); decsclm(TRUE); /* Syrup scroll */ cup(max_lines - 1, 1); for (i = 1; i <= 5; i++) println("If the bug is present, this should make things much worse!"); holdit(); decsclm(FALSE); /* Jump scroll */ return MENU_NOHOLD; }