⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mined2.c

📁 MINED文本文件编缉器
💻 C
📖 第 1 页 / 共 4 页
字号:
find_y_RD (match_line, redrawflag)  LINE * match_line;  FLAG redrawflag;{  register LINE * line;  register int count = 0;/* Check if match_line is on the same page as currently displayed. */  for (line = top_line; line != match_line && line != bot_line->next;						      line = line->next)	count ++;  if (line != bot_line->next)	return count;/* Display new page, with match_line in center. */  if ((line = proceed (match_line, - (SCREENMAX >> 1))) == header) {  /* Can't display in the middle. Make first line of file top_line */	count = 0;	for (line = header->next; line != match_line; line = line->next)		count ++;	line = header->next;  }  else	/* New page is displayed. Set cursor to middle of page */	count = SCREENMAX >> 1;/* Reset pointers and redraw the screen */  reset (line, 0);  if (redrawflag == TRUE) RD_y (count);  return count;}intfind_y (match_line)  LINE * match_line;{  return find_y_RD (match_line, TRUE);}intfind_y_w_o_RD (match_line)  LINE * match_line;{  return find_y_RD (match_line, FALSE);}/* * Dummy_line () adds an empty line at the end of the file. This is  * sometimes useful in combination with the EFILE and MDN command in  * combination with the Yank command set. * !!! I see no use for this and I don't consider such autonomous  * !!! modifications of the text (without user request) acceptable. TW. */#ifdef UNUSEDvoiddummy_line (){	(void) line_insert (tail->prev, "\n", 1);	tail->prev->shift_count = DUMMY;	if (last_y != SCREENMAX) {		last_y ++;		bot_line = bot_line->next;	}}#endif /* UNUSED *//*  ==================================================================	* *				Modify Commands				* *  ==================================================================	*//* * DCC deletes the character under the cursor. If this character is a '\n' the * current line is joined with the next one. * If this character is the only character of the line, the current line will * be deleted. */voidDCC (){  if (* cur_text == '\n')	if (cur_line->next == tail)	   return;	else	   (void) delete_text (cur_line, cur_text, cur_line->next, cur_line->next->text);  else {	if (Chinese == TRUE && multichar (* cur_text))		(void) delete_text (cur_line, cur_text, cur_line, cur_text + 2);	else		(void) delete_text (cur_line, cur_text, cur_line, cur_text + 1);  }}/* * DPC deletes the character on the left side of the cursor.  If the cursor * is at the beginning of the line, the last character if the previous line * is deleted. With hop flag, delete left part of line from current point. */voidDPC (){  char * delete_pos;  if (x == 0 && cur_line->prev == header)	return;			/* Top of file */  if (viewonly == TRUE)	{viewonlyerr (); return;}  if (hop_flag > 0) {	hop_flag = 0;	if (cur_text != cur_line->text) {	  delete_pos = cur_text;	  BLINE ();	  (void) delete_text (cur_line, cur_line->text, cur_line, delete_pos);	}  }  else {	MLF ();			/* Move one left */	DCC ();			/* Delete character under cursor */  }}/* * DLINE delete the whole current line. */voidDLINE (){  if (viewonly == TRUE)	{viewonlyerr (); return;}  if (hop_flag > 0) {    hop_flag = 0;    if (* cur_text != '\n')	(void) delete_text (cur_line, cur_text, cur_line, cur_text + length_of (cur_text) - 1);  }  else {    (void) delete_text (cur_line, cur_line->text, cur_line->next, cur_line->next->text);    BLINE ();  }}/* * DLN deletes all characters until the end of the line. If the current * character is a '\n', then delete that char. */voidDLN (){  if (* cur_text == '\n')	DCC ();  else if (hop_flag > 0) {	hop_flag = 0;	DLINE ();  }  else	(void) delete_text (cur_line, cur_text, cur_line, cur_text + length_of (cur_text) - 1);}/* * DNW () deletes the next word (as defined in MNW ()) */voidDNW (){  if (* cur_text == '\n')	DCC ();  else	move_next_word (DELETE);}/* * DPW () deletes the previous word (as defined in MPW ()) */voidDPW (){  if (cur_text == cur_line->text)	DPC ();  else	move_previous_word (DELETE);}/* * Insert character `character' at current location. */voidSNL (){  S ('\n');}voidS (character)  register uchar character;{  static uchar buffer [3];  static uchar firstbyte;  static int width = 1;  if (Chinese == TRUE) {	if (firstbyte != '\0') {		buffer [0] = firstbyte;		buffer [1] = character;		width = 2;	} else if (multichar (character)) {		firstbyte = character;		return;	} else {		buffer [0] = character;		buffer [1] = '\0';		width = 1;	}	firstbyte = '\0';  } else	buffer [0] = character;/* Insert the character */  if (insert (cur_line, cur_text, buffer) == ERRORS)	return;/* Fix screen */  if (character == '\n') {	set_cursor (0, y);	if (y == SCREENMAX) {		/* Can't use display () */		line_print (cur_line);		(void) forward_scroll (TRUE);		move_to (0, y);	}	else {		reset (top_line, y);	/* Reset pointers */		if (can_add_line == TRUE) {			add_line (y + 1);			clear_status ();			display (y, cur_line, 1, y + 1);		}		else	display (y, cur_line, last_y - y, y + 1);		move_to (0, y + 1);	}  }  else if (x + width == XBREAK) /* If line must be shifted, just call move_to */	move_to (x + width, y);  else {			/* else display rest of line */	put_line (cur_line, x, FALSE, FALSE);	move_to (x + width, y);  }}/* * Replace current character with its hex representation. */uchar hexdig (c)  uchar c;{  if (c < 10) return c + '0';	else  return c - 10 + 'A';}voidinsertcode (c, radix)  uchar c;  int radix;{  int radix2;  if (radix == 8) {	S (hexdig ((c >> 6) & 007));	S (hexdig ((c >> 3) & 007));	S (hexdig ((c) & 007));  } else if (radix == 16) {	S (hexdig ((c >> 4) & 017));	S (hexdig ((c) & 017));  } else {	/* assume radix = 10 or, at least, three digits suffice */	radix2 = radix * radix;	S (hexdig (c / radix2));	S (hexdig ((c % radix2) / radix));	S (hexdig (c % radix));  }}voidchangetocode (radix)  int radix;{  uchar c = * cur_text;  if (c == '\n') {#ifdef msdos	insertcode ('\r', radix);#endif	insertcode ('\n', radix);  } else {	DCC ();	insertcode (c, radix);  }}/* * insert_accent inserts accented character */voidinsert_accent (name, routine)  char * name;  uchar (* routine) ();{  register uchar letter;  build_string (text_buffer, "Enter character to place %s on...", name);  status_msg (text_buffer);  letter = (* routine) (readchar ());  clear_status ();  S (letter);}/* * CTRl inserts a control-char at the current location. A message that this * function is called is displayed at the status line. */voidCTRl (){  register uchar ctrl;  status_msg ("Enter control character (or accent)...");  ctrl = readchar ();  if (ctrl == ring || ctrl == ',')	{insert_accent ("angstrom/cedilla", angstrom); return;}  else switch (ctrl) {	case '"':	{insert_accent ("diaeresis", diaeresis); return;}	case '\'':	{insert_accent ("acute (d'aigu)", acute); return;}	case '`':	{insert_accent ("grave", grave); return;}	case '^':	{insert_accent ("circumflex", circumflex); return;}	case '~':	{insert_accent ("tilde", tilde); return;}  }  clear_status ();  if ((ctrl == '\177') || (ctrl == '?')) {S ('\177'); return;}  ctrl = ctrl & '\237';  if (ctrl == '\0') error ("Can't handle NULL char - not inserted", NIL_PTR);  else S (ctrl);}/* * LIB insert a line at the current position and moves back to the end of * the previous line. */voidLIB (){  hop_flag = 0;  if (viewonly == TRUE)	{viewonlyerr (); return;}  S ('\n');			/* Insert the line */  MUP ();			/* Move one line up */  move_to (LINE_END, y);	/* Move to end of this line */}/*  ==================================================================	* *				Yank Commands				* *  ==================================================================	*/LINE * mark_line = NIL_LINE;		/* For marking position. */char * mark_text = NIL_PTR;LINE * mark_n_line [10] = {NIL_LINE, NIL_LINE, NIL_LINE, NIL_LINE, NIL_LINE, 			   NIL_LINE, NIL_LINE, NIL_LINE, NIL_LINE, NIL_LINE};char * mark_n_text [10] = {NIL_PTR, NIL_PTR, NIL_PTR, NIL_PTR, NIL_PTR, 			   NIL_PTR, NIL_PTR, NIL_PTR, NIL_PTR, NIL_PTR};int lines_saved;			/* Nr of lines in buffer *//* * PT () inserts the buffer at the current location. */voidPT (){  register int fd;		/* File descriptor for buffer */  if (viewonly == TRUE)	{viewonlyerr (); return;}  if (hop_flag > 0) {	if ((fd = open (yankie_file, O_RDONLY | O_BINARY, 0)) < 0) {		error ("No inter window buffer present", NIL_PTR);		return;	}  }  else if ((fd = scratch_file (READ, FALSE)) == ERRORS) {	error ("Buffer is empty", NIL_PTR);	return;  }  /* Insert the buffer *//*	file_insert (fd, FALSE); => positioning error when TAB in last line */	file_insert (fd, TRUE);}/* * INSFILE () prompt for a filename and inserts the file at the current location * in the file. */voidINSFILE (){  register int fd;		/* File descriptor of file */  char name [maxLINE_LEN];	/* Buffer for file name */  if (viewonly == TRUE)	{viewonlyerr (); return;}/* Get the file name */  if (get_file ("Get and insert file:", name) != FINE)	return;  clear_status ();  if ((fd = open (name, O_RDONLY | O_BINARY, 0)) < 0)	error ("Cannot open file: " /*, name */, serror ());  else {	/* Insert the file */	file_insert (fd, TRUE);	/* leave cursor at begin of insertion */  }}/* * File_insert () inserts the contents of an opened file (as given by * filedescriptor fd) at the current location. * After the insertion, if old_pos is TRUE, the cursor remains at the * start of the inserted text, if old_pos is FALSE, it is placed to * its end. If old_pos is FALSE, this works erroneously if the last line * inserted contains a TAB character!! */voidfile_insert (fd, old_pos)  int fd;  FLAG old_pos;{  char line_buffer [MAX_CHARS];		/* Buffer for next line */  register LINE * line = cur_line;  register int line_count = total_lines;	/* Nr of lines inserted */  LINE * page = cur_line;  int ret = ERRORS;  get_l_err1 = NIL_PTR;  get_l_err2 = NIL_PTR;/* Get the first piece of text (might be ended with a '\n') from fd */  if (get_line (fd, line_buffer) == ERRORS)	return;				/* Empty file *//* Insert this text at the current location */  if (insert (line, cur_text, line_buffer) == ERRORS)	return;/* Repeat getting lines (and inserting lines) until EOF is reached */  while (line != NIL_LINE	 && (ret = get_line (fd, line_buffer)) != ERRORS && ret != NO_LINE)	line = line_insert (line, line_buffer, ret);  if (line == NIL_LINE) sleep (2) /* show memory allocation error msg */;  else if (ret == NO_LINE) {	/* Last line read not ended by a '\n' */	line = line->next;	if (insert (line, line->text, line_buffer) == ERRORS)		sleep (2) /* give time to read error msg */;  }  (void) close (fd);/* If illegal lines were input, report */  if ((get_l_err1 != NIL_PTR) || (get_l_err2 != NIL_PTR)) {	ring_bell ();	error (get_l_err1, get_l_err2);	sleep (1);  }/* Calculate nr of lines added */  line_count = total_lines - line_count;/* Fix the screen */  if (line_count == 0) {		/* Only one line changed */	set_cursor (0, y);	line_print (line);	move_to ((old_pos == TRUE) ? x : x + length_of (line_buffer), y);  }  else {				/* Several lines changed */	reset (top_line, y);	/* Reset pointers */	while (page != line && page != bot_line->next)		page = page->next;	if (page != bot_line->next || old_pos == TRUE)		display (y, cur_line, SCREENMAX - y, y);		/* screen display style parameter (last) may be inaccurate */	if (old_pos == TRUE)		move_to (x, y);	else if (ret == NO_LINE)		move_to (length_of (line_buffer), find_y (line));	else		move_to (0, find_y (line->next));  }/* If nr of added line >= REPORT, print the count */  if (line_count >= REPORT)	status_line (num_out ((long) line_count), " lines added");}/* * WB () writes the buffer (yank_file) into another file, which * is prompted for. */voidWB (){  register int new_fd;		/* Filedescriptor to copy file */  int yank_fd;			/* Filedescriptor to buffer */  register int cnt;		/* Count check for read/write */  int ret = FINE;		/* Error check for write */  char file_name [maxLINE_LEN];	/* Output file name */  char * msg_doing; char * msg_done;/* Checkout the buffer */  if ((yank_fd = scratch_file (READ, FALSE)) == ERRORS) {	error ("Buffer is empty", NIL_PTR);	return;  }/* Get file name */  if (get_file ((hop_flag > 0) ? "Append buffer to file:"			       : "Write buffer to file:", file_name) != FINE)	return;/* Create the new file or open previous file for appending */  if (hop_flag > 0) {    if ((new_fd = open (file_name, O_WRONLY | O_CREAT | O_APPEND | O_BINARY, fprot)) < 0) {	error ("Cannot append to file: ", serror ());	return;    }    msg_doing = "Appending "; msg_done = "Appended";  }  else {    if (checkoverwrite (file_name) != TRUE)	return;    else if ((new_fd = open (file_name, O_WRONLY | O_CREAT | O_BINARY, fprot)) < 0) {	error ("Cannot create file: ", serror ());	return;    }    msg_doing = "Writing "; msg_done = "Wrote";  }  status_line (msg_doing, file_name);/* Copy buffer into file */  while ((cnt = read (yank_fd, text_buffer, sizeof (text_buffer))) > 0)	if (write (new_fd, text_buffer, cnt) != cnt) {		bad_write (new_fd);		ret = ERRORS;		break;	}/* Clean up open files and status_line */  (void) close (new_fd);  (void) close (yank_fd);  if (ret != ERRORS)			/* Bad write */	file_status (msg_done, chars_saved, file_name, lines_saved, 			FALSE, TRUE, FALSE, FALSE);}/* * MARK sets mark_line / mark_text to the current line / current text pointer. */voidMARK (){  if (hop_flag > 0) GOMA ();  else {	mark_line = cur_line;	mark_text = cur_text;	status_msg ("Mark set");  }}/* * GOMA moves to the marked position */voidGOMA (){  if (checkmark (mark_line, mark_text) == NOT_VALID)	error ("Mark not set", NIL_PTR);  else	move_address (mark_text, find_y (mark_line));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -