📄 mined1.c
字号:
*/void RD(){/* Clear screen */#ifdef UNIX tputs(VS, 0, _putchar); tputs(CL, 0, _putchar);#else string_print(enter_string);#endif /* UNIX *//* Print first page */ display(0, 0, top_line, last_y);/* Clear last line */ set_cursor(0, ymax);#ifdef UNIX tputs(CE, 0, _putchar);#else string_print(blank_line);#endif /* UNIX */ move_to(x, y);}/* * Ignore this keystroke. */void I(){}/* * Leave editor. If the file has changed, ask if the user wants to save it. */void XT(){ if (modified == TRUE && ask_save() == ERRORS) return; raw_mode(OFF); set_cursor(0, ymax); putchar('\n'); flush(); (void) unlink(yank_file); /* Might not be necessary */ exit(0);}void (*escfunc(c))()int c;{#if (CHIP == M68000)#ifndef COMPAT int ch;#endif#endif if (c == '[') { /* Start of ASCII escape sequence. */ c = getchar();#if (CHIP == M68000)#ifndef COMPAT if ((c >= '0') && (c <= '9')) ch = getchar(); /* ch is either a tilde or a second digit */#endif#endif switch (c) { case 'H': return(HO); case 'A': return(UP); case 'B': return(DN); case 'C': return(RT); case 'D': return(LF);#if (CHIP == M68000)#ifndef COMPAT /* F1 = ESC [ 1 ~ */ /* F2 = ESC [ 2 ~ */ /* F3 = ESC [ 3 ~ */ /* F4 = ESC [ 4 ~ */ /* F5 = ESC [ 5 ~ */ /* F6 = ESC [ 6 ~ */ /* F7 = ESC [ 17 ~ */ /* F8 = ESC [ 18 ~ */ case '1': switch (ch) { case '~': return(SF); case '7': (void) getchar(); return(MA); case '8': (void) getchar(); return(CTL); } case '2': return(SR); case '3': return(PD); case '4': return(PU); case '5': return(FS); case '6': return(EF);#endif#endif#if (CHIP == INTEL) case 'G': return(FS); case 'S': return(SR); case 'T': return(SF); case 'U': return(PD); case 'V': return(PU); case 'Y': return(EF);#endif } return(I); }#if (CHIP == M68000)#ifdef COMPAT if (c == 'O') { /* Start of ASCII function key escape sequence. */ switch (getchar()) { case 'P': return(SF); case 'Q': return(SR); case 'R': return(PD); case 'S': return(PU); case 'T': return(FS); case 'U': return(EF); case 'V': return(MA); case 'W': return(CTL); } }#endif#endif return(I);}/* * ESC() wants a count and a command after that. It repeats the * command count times. If a ^\ is given during repeating, stop looping and * return to main loop. */void ESC(){ register int count = 0; register void (*func)(); int index; index = getchar(); while (index >= '0' && index <= '9' && quit == FALSE) { count *= 10; count += index - '0'; index = getchar(); } if (count == 0) { count = 1; func = escfunc(index); } else { func = key_map[index]; if (func == ESC) func = escfunc(getchar()); } if (func == I) { /* Function assigned? */ clear_status(); return; } while (count-- > 0 && quit == FALSE) { if (stat_visible == TRUE) clear_status(); (*func)(index); flush(); } if (quit == TRUE) /* Abort has been given */ error("Aborted", NIL_PTR);}/* * Ask the user if he wants to save his file or not. */int ask_save(){ register int c; status_line(file_name[0] ? basename(file_name) : "[buffer]" , " has been modified. Save? (y/n)"); while((c = getchar()) != 'y' && c != 'n' && quit == FALSE) { ring_bell(); flush(); } clear_status(); if (c == 'y') return WT(); if (c == 'n') return FINE; quit = FALSE; /* Abort character has been given */ return ERRORS;}/* * Line_number() finds the line number we're on. */int line_number(){ register LINE *line = header->next; register int count = 1; while (line != cur_line) { count++; line = line->next; } return count;} /* * Display a line telling how many chars and lines the file contains. Also tell * whether the file is readonly and/or modified. */void file_status(message, count, file, lines, writefl, changed)char *message;register long count; /* Contains number of characters in file */char *file;int lines;FLAG writefl, changed;{ register LINE *line; char msg[LINE_LEN + 40];/* Buffer to hold line */ char yank_msg[LINE_LEN];/* Buffer for msg of yank_file */ if (count < 0) /* Not valid. Count chars in file */ for (line = header->next; line != tail; line = line->next) count += length_of(line->text); if (yank_status != NOT_VALID) /* Append buffer info */ build_string(yank_msg, " Buffer: %D char%s.", chars_saved, (chars_saved == 1L) ? "" : "s"); else yank_msg[0] = '\0'; build_string(msg, "%s %s%s%s %d line%s %D char%s.%s Line %d", message, (rpipe == TRUE && *message != '[') ? "standard input" : basename(file), (changed == TRUE) ? "*" : "", (writefl == FALSE) ? " (Readonly)" : "", lines, (lines == 1) ? "" : "s", count, (count == 1L) ? "" : "s", yank_msg, line_number()); if (length_of(msg) + 1 > LINE_LEN - 4) { msg[LINE_LEN - 4] = SHIFT_MARK; /* Overflow on status line */ msg[LINE_LEN - 3] = '\0'; } status_line(msg, NIL_PTR); /* Print the information */}/* * Build_string() prints the arguments as described in fmt, into the buffer. * %s indicates an argument string, %d indicated an argument number. */#if __STDC__void build_string(char *buf, char *fmt, ...){#elsevoid build_string(buf, fmt, va_alist)char *buf, *fmt;va_dcl{#endif va_list argptr; char *scanp;#if __STDC__ va_start(argptr, fmt);#else va_start(argptr);#endif while (*fmt) { if (*fmt == '%') { fmt++; switch (*fmt++) { case 's' : scanp = va_arg(argptr, char *); break; case 'd' : scanp = num_out((long) va_arg(argptr, int)); break; case 'D' : scanp = num_out((long) va_arg(argptr, long)); break; default : scanp = ""; } while (*buf++ = *scanp++) ; buf--; } else *buf++ = *fmt++; } va_end(argptr); *buf = '\0';}/* * Output an (unsigned) long in a 10 digit field without leading zeros. * It returns a pointer to the first digit in the buffer. */char *num_out(number)long number;{ static char num_buf[11]; /* Buffer to build number */ register long digit; /* Next digit of number */ register long pow = 1000000000L; /* Highest ten power of long */ FLAG digit_seen = FALSE; int i; for (i = 0; i < 10; i++) { digit = number / pow; /* Get next digit */ if (digit == 0L && digit_seen == FALSE && i != 9) num_buf[i] = ' '; else { num_buf[i] = '0' + (char) digit; number -= digit * pow; /* Erase digit */ digit_seen = TRUE; } pow /= 10L; /* Get next digit */ } for (i = 0; num_buf[i] == ' '; i++) /* Skip leading spaces */ ; return (&num_buf[i]);}/* * Get_number() read a number from the terminal. The last character typed in is * returned. ERRORS is returned on a bad number. The resulting number is put * into the integer the arguments points to. */int get_number(message, result)char *message;int *result;{ register int index; register int count = 0; status_line(message, NIL_PTR); index = getchar(); if (quit == FALSE && (index < '0' || index > '9')) { error("Bad count", NIL_PTR); return ERRORS; }/* Convert input to a decimal number */ while (index >= '0' && index <= '9' && quit == FALSE) { count *= 10; count += index - '0'; index = getchar(); } if (quit == TRUE) { clear_status(); return ERRORS; } *result = count; return index;}/* * Input() reads a string from the terminal. When the KILL character is typed, * it returns ERRORS. */int input(inbuf, clearfl)char *inbuf;FLAG clearfl;{ register char *ptr; register char c; /* Character read */ ptr = inbuf; *ptr = '\0'; while (quit == FALSE) { flush(); switch (c = getchar()) { case '\b' : /* Erase previous char */ if (ptr > inbuf) { ptr--;#ifdef UNIX tputs(SE, 0, _putchar);#else string_print(normal_video);#endif /* UNIX */ if (is_tab(*ptr)) string_print(" \b\b\b \b\b"); else string_print(" \b\b \b");#ifdef UNIX tputs(SO, 0, _putchar);#else string_print(rev_video);#endif /* UNIX */ string_print(" \b"); *ptr = '\0'; } else ring_bell(); break; case '\n' : /* End of input */ /* If inbuf is empty clear status_line */ return (ptr == inbuf && clearfl == TRUE) ? NO_INPUT :FINE; default : /* Only read ASCII chars */ if ((c >= ' ' && c <= '~') || c == '\t') { *ptr++ = c; *ptr = '\0'; if (c == '\t') string_print("^I"); else putchar(c); string_print(" \b"); } else ring_bell(); } } quit = FALSE; return ERRORS;}/* * Get_file() reads a filename from the terminal. Filenames longer than * FILE_LENGHT chars are truncated. */int get_file(message, file)char *message, *file;{ char *ptr; int ret; if (message == NIL_PTR || (ret = get_string(message, file, TRUE)) == FINE) { if (length_of((ptr = basename(file))) > NAME_MAX) ptr[NAME_MAX] = '\0'; } return ret;}/* ======================================================================== * * UNIX I/O Routines * * ======================================================================== */#ifdef UNIX#undef putcharint _getchar(){ char c; if (read(input_fd, &c, 1) != 1 && quit == FALSE) panic ("Cannot read 1 byte from input"); return c & 0377;}void _flush(){ (void) fflush(stdout);}void _putchar(c)char c;{ (void) write_char(STD_OUT, c);}void get_term(){ static char termbuf[50]; extern char *tgetstr(), *getenv(); char *loc = termbuf; char entry[1024]; if (tgetent(entry, getenv("TERM")) <= 0) { printf("Unknown terminal.\n"); exit(1); } AL = tgetstr("al", &loc); CE = tgetstr("ce", &loc); VS = tgetstr("vs", &loc); CL = tgetstr("cl", &loc); SO = tgetstr("so", &loc); SE = tgetstr("se", &loc); CM = tgetstr("cm", &loc); ymax = tgetnum("li") - 1; screenmax = ymax - 1; if (!CE || !SO || !SE || !CL || !AL || !CM) { printf("Sorry, no mined on this type of terminal\n"); exit(1); }}#endif /* UNIX */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -