int prompt(void) { off_t len, pos; /* * if nothing is displayed yet, display starting from line 1; * if search string provided, go there instead. */ if (position(TOP) == NULL_POSITION) { if (forw_line((off_t)0) == NULL_POSITION) return(0); if (!firstsearch || !search(1, firstsearch, 1, 1)) jump_back(1); } else if (screen_trashed) repaint(); /* if no -e flag and we've hit EOF on the last file, quit. */ if ((!quit_at_eof || short_file) && hit_eof && curr_ac + 1 >= ac) quit(); /* select the proper prompt and display it. */ lower_left(); clear_eol(); if (longprompt) { so_enter(); printf("%s:", current_name); if (!ispipe) printf(" file %d/%d", curr_ac + 1, ac); if (linenums) printf(" line %d", currline(BOTTOM)); if ((pos = position(BOTTOM)) != NULL_POSITION) { printf(" byte %qd", pos); if (!ispipe && (len = ch_length())) printf("/%qd pct %qd%%", len, ((100 * pos) / len)); } so_exit(); longprompt = 0; } else { so_enter(); printf("%s", current_name); if (hit_eof) if (next_name) printf(": END (next file: %s)", next_name); else printf(": END"); else if (!ispipe && (pos = position(BOTTOM)) != NULL_POSITION && (len = ch_length())) printf(" (%qd%%)", ((100 * pos) / len)); so_exit(); } return(1); }
void ierror(char *s) { lower_left(); clear_eol(); so_enter(); printf("%s ... (interrupt to abort)", s); so_exit(); fflush(stdout); }
void thread1(int arg) { printf("1: Thread started with argument %d.\n", arg); int i; for (i=0; i<3; i++) { printf("1\n"); so_yield(); } printf("1: Finished with so_exit(23).\n"); so_exit(23); }
/* * Output a message in the lower left corner of the screen * and wait for carriage return. */ void error(const char *s) { int ch; ++errmsgs; if (!any_display) { /* * Nothing has been displayed yet. Output this message on * error output (file descriptor 2) and don't wait for a * keystroke to continue. * * This has the desirable effect of producing all error * messages on error output if standard output is directed * to a file. It also does the same if we never produce * any real output; for example, if the input file(s) cannot * be opened. If we do eventually produce output, code in * edit() makes sure these messages can be seen before they * are overwritten or scrolled away. */ if (s != NULL) fprintf(stderr, "%s\n", s); return; } lower_left(); clear_eol(); so_enter(); if (s != NULL) printf("%s ", s); fputs(return_to_continue, stdout); so_exit(); if ((ch = getchr()) != '\n') { if (ch == 'q') quit(); cmdstack = ch; } lower_left(); if ((s != NULL ? strlen(s) : 0) + sizeof(return_to_continue) + so_width + se_width + 1 > (size_t)sc_width) /* * Printing the message has probably scrolled the screen. * {{ Unless the terminal doesn't have auto margins, * in which case we just hammered on the right margin. }} */ repaint(); fflush(stdout); }
void thread3(int arg) { printf("2: Thread started with argument %d.\n", arg); int i, status; for (i=0; i<7; i++) { if (i==2) { printf("3: Waiting for %d to finish.\n", arg); so_join(arg, &status); printf("3: Gotten status %d.\n", status); } else { printf("3\n"); } so_yield(); } printf("3: Finished with so_exit(69).\n"); so_exit(69); }