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

📄 mined1.c

📁 MINED文本文件编缉器
💻 C
📖 第 1 页 / 共 4 页
字号:
  if (c < ' ')	{ message2 [1] = '^'; message2 [2] = c + '@'; }  else		{ message2 [1] = ' '; message2 [2] = c; }  error ("Unknown command ", message2);  while (readchar () != ' ' && quit == FALSE) {	ring_bell ();	flush ();  }  clear_status ();}/* * Change working directory. */voidCHDI (){  char new_dir [maxLINE_LEN];	/* Buffer to hold new dir. name */#ifdef pc  build_string (text_buffer, "Drive/Directory: %s, change to:", unnull (getcwd (new_dir, maxLINE_LEN)));#else  build_string (text_buffer, "Directory: %s, change to:", unnull (getcwd (new_dir, maxLINE_LEN)));#endif  if (get_file (text_buffer, new_dir) != FINE)	return;#ifdef msdos  if (new_dir [0] != '\0' && new_dir [1] == ':')	if (new_dir [2] == '\0') {		new_dir [2] = '.';	/* change to current dir. of drive */		new_dir [3] = '\0';	}#endif  if (chdir (new_dir) == 0) {#ifdef msdos	if (new_dir [0] != '\0' && new_dir [1] == ':')		setdisk (((int) new_dir [0] & (int) '\137') - (int) 'A');	RD ();	/* disk error dialog may be on screen after chdir */#endif	clear_status ();	overwriteOK = FALSE;	/* Same file base name ... */	writable = TRUE;/*	if (viewmode == FALSE)	*/	    modified = TRUE;	/* would mean different file now */  }  else	{#ifdef msdos	RD ();	/* disk error dialog may be on screen */#endif	error ("Could not change work dir: ", serror ());  }}/* * Print file status. */voidFS1 (){  fstatus (file_name [0] ? "" : "[buffer]", -1L);}voidFS (){  if (hop_flag > 0)	if (fstat_always == FALSE) fstat_always = TRUE;			else fstat_always = FALSE;  else FS1 ();}/* * Show Help information on screen */voidHELP (){  if (getenv ("MINEDHELP"))	build_string (text_buffer, (char *) getenv ("MINEDHELP"), mined_dir);  else	build_string (text_buffer, helpcommand, mined_dir);  clear_screen ();  status_msg ("Wait for help...");  flush ();  raw_mode (OFF);  system (text_buffer);  sleep (1);  raw_mode (ON);#ifdef pc  status_msg ("help finished, press a key...");  flush ();  (void) readchar ();#endif  clear_status ();  RDwin ();}/* * Print buffer */voidPBUF (){  int fd;  char cmd [maxLINE_LEN];	/* Buffer for print command */  if ((fd = scratch_file (READ, FALSE)) == ERRORS) {	error ("Buffer is empty.", NIL_PTR);	return;  }  close (fd);  build_string (cmd, getenv ("MINEDPRINT") ?		(char *) getenv ("MINEDPRINT") : printcommand, yank_file);/* Turbo-C wants the cast here since getenv must be declared as far * */  clear_status ();  set_cursor (0, YMAX);  flush ();  system (cmd);  sleep (1);  RDwin ();}/* * Pipe buffer */voidCMD (){  int fd;  char cmd [maxLINE_LEN];	/* Buffer for command */  char command [maxLINE_LEN];	/* Buffer for full command */  if ((fd = scratch_file (READ, FALSE)) == ERRORS) {	error ("Buffer is empty.", NIL_PTR);	return;  }  close (fd);  if (get_string ("Command with buffer as input:", cmd, TRUE) != FINE)	return;  build_string (command, "%s < %s", cmd, yank_file);  clear_status ();  set_cursor (0, YMAX);  flush ();  raw_mode (OFF);  system (command);  sleep (1);  raw_mode (ON);  RDwin ();}/* * Called if an operation is not implemented */voidnotimpl (){  error ("Command not implemented", NIL_PTR);}/* * Suspend editor after writing back the file. */voidSUSP (){  if (cansuspendmyself == TRUE) {	if (hop_flag == 0 && modified == TRUE)		if (wrt_text (TRUE) == ERRORS) return;	set_cursor (0, YMAX);	raw_mode (OFF);	suspendmyself ();	raw_mode (ON);	clear_status ();	RDwin ();  }  else notimpl ();}/* * Call an interactive shell. */voidSH (){#ifdef unix  register int w;  int pid, status, waiterr;  switch (pid = vfork ()) {	case -1:			/* Error */		error ("Cannot fork: ", serror ());		return;	case 0:				/* This is the child */		set_cursor (0, YMAX);		putchar ('\n');		raw_mode (OFF);		if (rpipe) {			/* Fix stdin */			close (STD_IN);			if (open ("/dev/tty", O_RDONLY, 0) < 0)				  exit (126);		}		execl (getenv ("SHELL"), getenv ("SHELL"), 0);		_exit (127);	/* Exit with 127 */	default:			/* This is the parent */		do {			w = wait (& status);		} while (w != -1 && w != pid);		waiterr = geterrno ();  }  raw_mode (ON);  RDwin ();  if (w == -1) {	error ("Wait error: ", serrorof (waiterr));	if (((status >> 8) == 127) || ((status >> 8) == 126)) sleep (2);  }  if ((status >> 8) == 127)		/* Child died with 127 */	error (getenv ("SHELL"), ": cannot exec this ${SHELL} (not found / not enough memory ?)");  else if ((status >> 8) == 126)	error ("Cannot open /dev/tty as fd #0", NIL_PTR);#else# ifdef msdos  char old_dir [maxLINE_LEN];	/* Buffer to hold dir. name */  (void) getcwd (old_dir, maxLINE_LEN);  set_cursor (0, YMAX);  raw_mode (OFF);  system ("COMMAND.COM");  raw_mode (ON);  clear_status ();  RDwin ();  if (chdir (old_dir) == 0) {	if (old_dir [0] != '\0' && old_dir [1] == ':')		setdisk (((int) old_dir [0] & (int) '\137') - (int) 'A');	RD ();	/* disk error dialog may be on screen after chdir */  } else {	overwriteOK = FALSE;	/* Same file base name ... */	writable = TRUE;/*	if (viewmode == FALSE)	*/	    modified = TRUE;	/* would mean different file now */	RD ();	/* disk error dialog may be on screen */	error ("Could not reset previous work dir: ", serror ());  }# else#  ifdef vms/* Who can tell me why this hangs the process after return from the CLI ?  set_cursor (0, YMAX);  raw_mode (OFF);  system ("SPAWN");  raw_mode (ON);  clear_status ();  RDwin ();*/  notimpl ();#  else  notimpl ();#  endif# endif#endif}/*  ==================================================================	* *				Main					* *  ==================================================================	*/char * minedopt;voidWordStar_keys (){  int i;  for (i = 0; i < 32; i ++) key_map [i] = ws_key_map [i];  control_prefix = '\020';}FLAGeval_option (){  switch (* minedopt) {	case 'v': viewonly = TRUE; break;	case 'm': multiexit = TRUE; break;	case 'p': proportional = TRUE; break;	case 'r': RET_opt = 'r'; break;	case 'R': RET_opt = 'R'; break;	case 'C': Chinese = TRUE; break;	case 'B': key_map ['\010'] = DPC;		  key_map ['\177'] = DCC;		  break;	case 'W': WordStar_keys (); break;	case 's': page_stay = TRUE; break;	case 'S': page_scroll = TRUE; break;	case 't': minedopt ++;		  if (* minedopt == '\0') {minedopt --; TABchar = TABdefault;}		  else TABchar = * minedopt;		  break;	case 'd': minedopt ++;		  if (* minedopt == '-') display_delay = -1;		  else if (* minedopt >= '0' && * minedopt <= '9')			display_delay = (int) * minedopt - (int) '0';		  else minedopt --;		  break;	default:  return FALSE;  }  return TRUE;}intmain (argc, argv)  int argc;  char * argv [];{  register int index;	/* index in key table */  int initlinenum;  int initlini = 0;  LINE * initline;  char * Mark;  FLAG goon;/* fprot = umask (0); */  build_string (mined_dir, argv [0]);  index = 0;  while (mined_dir [index] != '\0') index ++;  while (index >= 0 && mined_dir [index] != '/'#ifdef msdos		&& mined_dir [index] != '\\' && mined_dir [index] != ':'#endif#ifdef vms		&& mined_dir [index] != ']' && mined_dir [index] != ':'#endif	) index --;  index ++; mined_dir [index] = '\0';  if (getenv ("NoCtrlSQ") || getenv ("NoControlSQ")) {	/* ^S and ^Q may come arbitrarily from terminal, so don't use them */	controlQS = TRUE;	key_map ['\021'] = I;	key_map ['\023'] = I;  }/*  if (getenv ("MINEDMULT")) multiexit = TRUE; */  if (getenv ("MINEDPROP")) proportional = TRUE;  if (getenv ("MINEDCHIN")) Chinese = TRUE;  if (getenv ("MINEDMAC")) RET_opt = 'R';  if (getenv ("MINEDWS")) WordStar_keys ();  Mark = (char *) getenv ("MINEDSHIFT");/* Turbo-C wants the cast here since getenv must be declared as far * */  if (Mark != NIL_PTR) {	SHIFT_MARK = Mark [0];	if (Mark [0] != '\0') SHIFT_BEG = Mark [1];  }  Mark = (char *) getenv ("MINEDTAB");  if (Mark != NIL_PTR) TABchar = (Mark [0] == '\0' ? TABdefault : Mark [0]);  Mark = (char *) getenv ("MINEDRET");  if (Mark != NIL_PTR) {	RET_MARK = Mark [0];	if (RET_MARK) RET_BLANK = Mark [1];	if (RET_BLANK) RET_BLANK2 = Mark [2];  }  get_term ();  if ((minedopt = (char *) getenv ("MINED")) != NIL_PTR)     while (* minedopt != '\0') {	(void) eval_option ();	minedopt ++;  }  fnami = 1;  goon = TRUE;  do {    if (fnami < argc) {      if (* argv [fnami] == '+') {	initlini = fnami;	fnami += 1;      }      else if (* argv [fnami] == '-'#ifdef msdos	      || * argv [fnami] == '/'#endif	      ) {	minedopt = argv [fnami];	minedopt ++;	goon = eval_option ();	fnami += 1;      }      else goon = FALSE;    } else goon = FALSE;  } while (goon == TRUE);  fnami_min = fnami;  fnami_max = argc - 1;  fnami_cnt = argc - fnami_min;  fnamv = argv;	/* Why did this produce a warning? C is such a stupid language! */  if (! (fnami < argc))     fnami = 0;  if (! isatty (STD_IN)) {	/* Reading from pipe */	if (fnami != 0) {		panic ("Cannot read both pipe and file", NIL_PTR);	}	rpipe = TRUE;	modified = TRUE;	/* Set modified flag not to loose buffer */#ifdef msdos	panic ("Cannot edit after input from pipe", "MSDOS C incompatibility");#else	if ((input_fd = open ("/dev/tty", O_RDONLY, 0)) < 0)	   panic ("Cannot open /dev/tty for read", serror ());#endif  }  if (! isatty (STD_OUT)) {	wpipe = TRUE;	modified = TRUE; /* Set modified flag not to ignore buffer on exit */    /*	if ((output_fd = open ("/dev/tty", O_WRONLY, 0)) < 0)	   panic ("Cannot open /dev/tty for write", serror ()); */  }  raw_mode (ON);	/* Set tty to appropriate mode */  clear_screen ();/* * Generate names of paste files and of panic-file */#ifdef unix  temp_dir = getenv ("TMPDIR");  if (temp_dir == NIL_PTR || temp_dir [0] == '\0') temp_dir = "/tmp";  if (getenv ("USER")) {	build_string (yankie_file, "%s/minedbuf.%s.", temp_dir, getenv ("USER"));	build_string (panic_file, "%s/minedpanic.%s.%d", temp_dir, getenv ("USER"), getpid ());  }  else {	build_string (yankie_file, "%s/minedbuf.%d.", temp_dir, geteuid ());	build_string (panic_file, "%s/minedpanic.%d.%d", temp_dir, geteuid (), getpid ());  }#endif#ifdef vms  if (getenv ("SYS$SCRATCH"))	temp_dir = "SYS$SCRATCH";  else	temp_dir = "SYS$LOGIN";  if (getenv ("USER")) {	build_string (yankie_file, "%s:$MINEDBUF$%s.", temp_dir, getenv ("USER"));	build_string (panic_file, "%s:$MINEDPANIC$%s.%d", temp_dir, getenv ("USER"), getpid ());  }  else {	build_string (yankie_file, "%s:$MINEDBUF$%d.", temp_dir, geteuid ());	build_string (panic_file, "%s:$MINEDPANIC$%d.%d", temp_dir, geteuid (), getpid ());  }#endif#ifdef msdos  temp_dir = (char *) getenv ("TEMP");  if (temp_dir == NIL_PTR || temp_dir [0] == '\0') temp_dir = (char *) getenv ("TMP");  if (temp_dir == NIL_PTR || temp_dir [0] == '\0') temp_dir = "\\";  build_string (yankie_file, "%s\\minedbuf.", temp_dir);  build_string (panic_file, "%s\\mined-pa.nic", temp_dir);#endif  header = tail = alloc_header (); /* Make header of list */  if (header == NIL_LINE) panic ("Cannot allocate memory", NIL_PTR);  header->text = NIL_PTR;  header->next = tail->prev = header;/* Load the file (if any) */  if (fnami == 0)	load_file_w_o_display (NIL_PTR);  else {	/* This should be applied to all file names, or better, not at all:	if (length_of (argv [fnami]) > maxLINE_LEN) {		argv [fnami] [maxLINE_LEN] = '\0';	}	*/	load_file_w_o_display (argv [fnami]);  }  loading = TRUE;	/* keep loading flag TRUE until entering main loop */  if (initlini != 0) {     make_number (& initlinenum, argv [initlini] + 1);     if (initlinenum > 0) {	if (initlinenum <= 0 || (initline = proceed (header->next, initlinenum - 1)) == tail)	   error ("Illegal line number: ", num_out ((long) initlinenum));	else {	   move_to (x, find_y_w_o_RD (initline));	   fstatus ("Read", -1L);	}     }  }  if (wpipe) {	file_name [0] = '\0'; /* don't let user believe he's editing a file */	fstatus ("Editing for standard output", -1L);  }  RD ();  flush ();  catch_signals (catch_interrupt);  loading = FALSE;/* Main loop of the editor */  for (;;) {	if (fstat_always == TRUE && stat_visible == FALSE) FS1 ();	index = readchar ();	if (stat_visible == TRUE)		clear_status ();	if (quit == FALSE) {	/* Call the function for the typed key */		(* key_map [index]) (index);		if (hop_flag > 0) hop_flag --;		flush ();	/* Flush output (if any) */	}	if (quit == TRUE) {		CANCEL ();		quit = FALSE;	}  }  /* NOTREACHED */}/*  ==================================================================	* *				End					* *  ==================================================================	*/

⌨️ 快捷键说明

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