📄 minedaux.c
字号:
build_string (yank_msg, ""); /* Empty paste buffer is only an initial condition and thus this would be no significant information; since buffer contents may be appended, the exact count is not available anyway. */ else yank_msg [0] = '\0'; build_string (msg, (textstat == TRUE) ? "%s %s%s%s%s, %d line%s, %ld char%s. Line %d.%s" : "%s %s%s%s%s, %d line%s, %ld char%s.", message, (rpipe == TRUE && * message != '[') ? "standard input" : file, /* previously only basename (file) was printed */ (viewing == TRUE) ? " (View only)" : "", (changed == TRUE) ? " (modified)" : "", (writefl == FALSE) ? " (Readonly)" : "", lines, (lines == 1) ? "" : "s", count, (count == 1L) ? "" : "s", line_number, yank_msg); status_msg (msg); /* Print the information */}/* * Input () reads a string from the terminal. * Return values: * when QUIT character typed => ERRORS * when empty input and clearfl == TRUE: NO_INPUT * else: FINE */intinput (inbuf, clearfl) uchar * inbuf; FLAG clearfl;{ register uchar * ptr; register uchar c; ptr = inbuf; * ptr = '\0'; while (quit == FALSE) { flush (); if (lpos >= XBREAK) pagewrapped = TRUE; switch (c = readchar ()) { case '\b' : /* Erase previous char */ case '\177' /* DEL */ : if (ptr > inbuf) { ptr --; reverse_off (); if (Chinese == TRUE && inmultichar (inbuf, ptr)) { ptr --; putstring (" \b\b\b \b\b"); lpos = lpos - 2; } else if (iscontrol (* ptr)) { putstring (" \b\b\b \b\b"); lpos = lpos - 2; } else { putstring (" \b\b \b"); lpos = lpos - 1; } reverse_on (); putstring (" \b"); * ptr = '\0'; } else ring_bell (); break; case QUITCHAR : case '\033' : quit = TRUE; break; case '\n' : /* End of input */ case '\015' : /* If inbuf is empty clear status_line */ return (ptr == inbuf && clearfl == TRUE) ? NO_INPUT : FINE; default : if (c == control_prefix /* ^V/^P */) { c = readchar (); if (c == ring || c == ',') {c = angstrom (readchar ());} else switch (c) { case '"': {c = diaeresis (readchar ()); break;} case '\'': {c = acute (readchar ()); break;} case '`': {c = grave (readchar ()); break;} case '^': {c = circumflex (readchar ()); break;} case '~': {c = tilde (readchar ()); break;} default: if (c == '?') c = '\177'; if (c != '\177') c = c & '\237'; } } if (Chinese == TRUE && multichar (c)) { if ((ptr - inbuf) + 1 < maxLINE_LEN) { * ptr ++ = c; print_char (c); c = readchar (); * ptr ++ = c; print_char (c); * ptr = '\0'; putstring (" \b"); } else ring_bell (); } else if ((ptr - inbuf) < maxLINE_LEN) { if ((c > '\0')) { * ptr ++ = c; * ptr = '\0'; print_char (c); putstring (" \b"); } else ring_bell (); } else ring_bell (); } } quit = FALSE; return ERRORS;}/* * Show concatenation of s1 and s2 on the status line (bottom of screen) * If revfl is TRUE, turn on reverse video on both strings. Set stat_visible * only if bottom_line is visible. * The return value is FINE except for get_string, where it is taken * from the call to input ().status_line (str1, str2) is (void) bottom_line (ON, (str1), (str2), NIL_PTR, FALSE)status_msg (str) is status_line (str, NIL_PTR)status_beg (str) is (void) bottom_line (ON, (str), NIL_PTR, NIL_PTR, TRUE)error (str1, str2) is (void) bottom_line (ON, (str1), (str2), NIL_PTR, FALSE)clear_status () is (void) bottom_line (OFF, NIL_PTR, NIL_PTR, NIL_PTR, FALSE)get_string (str1, str2, fl) is bottom_line (ON, (str1), NIL_PTR, (str2), fl) */FLAG lastrevfl;char * lastinbuf;FLAG input_active = FALSE;char status_buf [maxLINE_LEN];voidrd_bottom_line (){ set_cursor (0, YMAX); reverse_on (); if (lastinbuf == NIL_PTR) printlim_string (status_buf, XBREAK); else { print_string (status_buf); print_string (lastinbuf); } if (! input_active) { reverse_off (); set_cursor_xy (); /* Set cursor back to old position */ } flush (); /* Perform the actual screen output */}intbottom_line (revfl, s1, s2, inbuf, statfl) FLAG revfl; char * s1, * s2; char * inbuf; FLAG statfl;{ int ret = FINE; if (inbuf != NIL_PTR) * inbuf = '\0'; lastrevfl = revfl; lastinbuf = inbuf; if (pagewrapped == TRUE) { status_buf [0] = '\0'; RD (); pagewrapped = FALSE; } build_string (status_buf, " %s%s ", unnull (s1), unnull (s2)); /* (s1 == NIL_PTR) ? "" : s1, (s2 == NIL_PTR) ? "" : s2); */ if (revfl == ON && stat_visible == TRUE) { set_cursor (0, YMAX); clear_lastline (); } set_cursor (0, YMAX); if (revfl == ON) { /* Print rev. start sequence */ reverse_on (); stat_visible = TRUE; } else { /* Used as clear_status () */ reverse_off (); stat_visible = FALSE; } if (inbuf == NIL_PTR) printlim_string (status_buf, XBREAK); else { print_string (status_buf); input_active = TRUE; ret = input (inbuf, statfl); input_active = FALSE; } /* Print normal video */ reverse_off (); if (can_clear_eol == TRUE) clear_eol (); else { put_blanks (XMAX - 1 - lpos); set_cursor (lpos, YMAX); } if (inbuf != NIL_PTR) { set_cursor (0, YMAX); } else if (statfl == TRUE) reverse_on (); else set_cursor_xy (); /* Set cursor back to old position */ flush (); /* Perform the actual screen output */ if (ret != FINE) clear_status (); return ret;}/* * Get_number () reads a number from the terminal. * The last character typed in is returned. * ERRORS is returned on a bad number or on interrupted input. * The resulting number is put into the integer the arguments points to. */intget_number (message, firstdigit, result) char * message; char firstdigit; int * result;{ register int index; register int count; status_beg (message); if (firstdigit > '\0') index = firstdigit; else index = readchar (); if (index == QUITCHAR) quit = TRUE; if (index == '\033') quit = TRUE; if (quit == FALSE && (index < '0' || index > '9')) { error ("Bad number", NIL_PTR); return ERRORS; }/* Convert input to a decimal number */ count = 0; while (index >= '0' && index <= '9' && quit == FALSE) { print_char (index); flush (); if (lpos >= XBREAK) pagewrapped = TRUE; count *= 10; count += index - '0'; index = readchar (); if (index == QUITCHAR) quit = TRUE; if (index == '\033') quit = TRUE; } clear_status (); if (quit == TRUE) { clear_status (); return ERRORS; } * result = count; return index;}/* * get_digits () reads in a number. In contrast to get_number, it does no * echoing, no messaging, and it does not require any digits at all. * The last character typed in is returned. * The resulting number is put into the integer the arguments points to. */intget_digits (result) int * result;{ register int index; register int count; index = readchar (); if (index == QUITCHAR) quit = TRUE; * result = -1;/* Convert input to a decimal number */ count = 0; while (index >= '0' && index <= '9' && quit == FALSE) { count *= 10; count += index - '0'; * result = count; index = readchar (); if (index == QUITCHAR) quit = TRUE; } if (quit == TRUE) { return QUITCHAR; } return index;}/* * Get_file () reads a filename from the terminal. */intget_file (message, file) char * message, * file;{ int ret = get_string (message, file, TRUE);#ifndef msdos char * filei; char file1 [maxLINE_LEN]; if (file [0] == '~' && file [1] == '/') { filei = file; filei ++; build_string (file1, "%s%s", unnull (getenv ("HOME")), filei); build_string (file, file1); }#endif return ret;}/* ================================================================== * * text modification routines * * ================================================================== */extern void viewonlyerr ();/* * make_line installs the buffer into a LINE structure. * It returns a pointer to the allocated structure. */LINE *make_line (buffer, length) char * buffer; int length;{ register LINE * new_line = alloc_header (); if (new_line == NIL_LINE) { ring_bell (); error ("Cannot allocate more memory for new line header", NIL_PTR); return NIL_LINE; } else { new_line->text = alloc (length + 1); if (new_line->text == NIL_PTR) { ring_bell (); error ("Cannot allocate more memory for new line", NIL_PTR); return NIL_LINE; } else { new_line->shift_count = 0; copy_string (new_line->text, buffer); return new_line; } }}/* * Line_insert () inserts a new line with text pointed to by `string'. * It returns the address of the new line. */LINE *line_insert (line, string, len) register LINE * line; char * string; int len;{ register LINE * new_line;/* Allocate space for LINE structure and text */ new_line = make_line (string, len); if (new_line != NIL_LINE) {/* Install the line into the double linked list */ new_line->prev = line; new_line->next = line->next; line->next = new_line; new_line->next->prev = new_line;/* Increment total_lines */ total_lines ++; } return new_line;}/* * Insert () insert the string `string' at the given line and location. */intinsert (line, location, string) register LINE * line; char * location, * string;{ register char * bufp = text_buffer; /* Buffer for building line */ register char * textp = line->text; char * newtext; if (viewonly == TRUE) {viewonlyerr (); return ERRORS;} if (length_of (textp) + text_length_of (string) >= MAX_CHARS) { error ("Line too long", NIL_PTR); return ERRORS; }/* Copy part of line until `location' has been reached */ while (textp != location) * bufp ++ = * textp ++;/* Insert string at this location */ while (* string != '\0') * bufp ++ = * string ++; * bufp = '\0';/* First, allocate memory for next line contents to make sure the *//* operation succeeds or fails as a whole */ newtext = alloc (length_of (text_buffer) + length_of (location) + 1); if (newtext == NIL_PTR) { ring_bell (); error ("Cannot allocate memory for insertion", NIL_PTR); return ERRORS; } else { /* Install the new text in this line */ if (* (string - 1) == '\n') { /* Insert a new line */ if (line_insert (line, location, length_of (location)) == NIL_LINE) return ERRORS; modified = TRUE; } else /* Append last part of line to text_buffer */ copy_string (bufp, location); free_space (line->text); modified = TRUE; line->text = newtext; copy_string (line->text, text_buffer); return FINE; }}/* * Line_delete () deletes the argument line out of the line list. The pointer * to the next line is returned. */LINE *line_delete (line) register LINE * line;{ register LINE * next_line = line->next;/* Delete the line */ line->prev->next = line->next; line->next->prev = line->prev;/* Free allocated space */ free_space (line->text); free_header (line);/* Decrement total_lines */ total_lines --; return next_line;}/* * Delete_text () deletes all the characters (including newlines) between the * startposition and endposition and fixes the screen accordingly. It * displays the number of lines deleted. */FLAGdelete_text (start_line, start_textp, end_line, end_textp) register LINE * start_line; LINE * end_line; char * start_textp, * end_textp;{ register char * textp = start_line->text; register char * bufp = text_buffer; /* Storage for new line->text */ LINE * line; LINE * after_end = end_line->next; int line_cnt = 0; /* Nr of lines deleted */ int count = 0; int shift = 0; /* Used in shift calculation */ int nx = x; FLAG ret = FINE; char * newtext; if (viewonly == TRUE) {viewonlyerr (); return ret;} modified = TRUE; /* File has been modified *//* Set up new line. Copy first part of start line until start_position. */ while (textp < start_textp) { * bufp ++ = * textp ++; count ++; }/* Check if line doesn't exceed MAX_CHARS */ if (count + length_of (end_textp) >= MAX_CHARS) { error ("Line too long", NIL_PTR); return ret; }/* Copy last part of end_line if end_line is not tail */ copy_string (bufp, (end_textp != NIL_PTR) ? end_textp : "\n");/* Delete all lines between start and end_position (including end_line) */ line = start_line->next; while (line != after_end && line != tail) { /* Here, the original mined compared with end_line->next which has already been discarded when the comparison should become true. This severe error remained undetected until I ported to MSDOS */ line = line_delete (line); line_cnt ++; }/* Check if last line of file should be deleted */ if (end_textp == NIL_PTR && length_of (start_line->text) == 1 && total_lines > 1) { start_line = start_line->prev; (void) line_delete (start_line->next); line_cnt ++; } else { /* Install new text */ newtext = alloc (length_of (text_buffer) + 1); if (newtext == NIL_PTR) { ring_bell (); error ("No more memory after deletion", NIL_PTR); ret = ERRORS; } else { free_space (start_line->text); start_line->text = newtext; copy_string (start_line->text, text_buffer); } }/* Fix screen. First check if line is shifted. Perhaps we should shift it back */#ifdef UNUSED/* !!! This resulted in a positioning error when a line containing TABs *//* !!! was shifted back. So better leave it. */ if (get_shift (start_line->shift_count)) { shift = (XBREAK - count_chars (start_line)) / SHIFT_SIZE; if (shift > 0) { /* Shift line `shift' back */ if (shift >= get_shift (start_line->shift_count)) start_line->shift_count = 0; else start_line->shift_count -= shift; nx += shift * SHIFT_SIZE; /* Reset x value */ } }#endif if (line_cnt == 0) { /* Check if only one line changed */ if (shift > 0) { /* Reprint whole line */ set_cursor (0, y); line_print (start_line); } else { /* Just display last part of line */ set_cursor_xy (); put_line (start_line, x, TRUE, FALSE); } move_to (nx, y); /* Reset cur_text */ return ret; } shift = last_y; /* Save value */ reset (top_line, y); if ((line_cnt <= SCREENMAX - y) && can_delete_line == TRUE) { clear_status (); display (y, start_line, 0, y); line = proceed (start_line, SCREENMAX - y - line_cnt + 1); while (line_cnt -- > 0) { delete_line (y + 1); if (line != tail) { set_cursor (0, SCREENMAX); line_print (line); line = line->next; } } } else display (y, start_line, shift - y, y);/* move_to ((line_cnt == 1) ? nx : 0, y); */ move_to (nx, y); return ret;}/* ================================================================== * * End * * ================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -