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

📄 term.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
string_cost (str)     char *str;{  cost = 0;  if (str)    tputs (str, 0, evalcost);  return cost;}/* Compute cost of sending "str", in characters,   counting any line-dependent padding at one line.  */string_cost_one_line (str)     char *str;{  cost = 0;  if (str)    tputs (str, 1, evalcost);  return cost;}/* Compute per line amount of line-dependent padding,   in tenths of characters.  */per_line_cost (str)     register char *str;{  cost = 0;  if (str)    tputs (str, 0, evalcost);  cost = - cost;  if (str)    tputs (str, 10, evalcost);  return cost;}/* ARGSUSED */calculate_ins_del_char_costs (){  int ins_startup_cost, del_startup_cost;  int ins_cost_per_char, del_cost_per_char;  register int i;  register int *p;  if (TS_ins_multi_chars)    {      ins_cost_per_char = 0;      ins_startup_cost = string_cost_one_line (TS_ins_multi_chars);    }  else if (TS_ins_char || TS_pad_inserted_char	   || (TS_insert_mode && TS_end_insert_mode))    {      ins_startup_cost = (30 * (string_cost (TS_insert_mode) + string_cost (TS_end_insert_mode))) / 100;      ins_cost_per_char = (string_cost_one_line (TS_ins_char)			   + string_cost_one_line (TS_pad_inserted_char));    }  else    {      ins_startup_cost = 9999;      ins_cost_per_char = 0;    }  if (TS_del_multi_chars)    {      del_cost_per_char = 0;      del_startup_cost = string_cost_one_line (TS_del_multi_chars);    }  else if (TS_del_char)    {      del_startup_cost = (string_cost (TS_delete_mode)			  + string_cost (TS_end_delete_mode));      if (delete_in_insert_mode)	del_startup_cost /= 2;      del_cost_per_char = string_cost_one_line (TS_del_char);    }  else    {      del_startup_cost = 9999;      del_cost_per_char = 0;    }  /* Delete costs are at negative offsets */  p = &DCICcost[0];  for (i = screen_width; --i >= 0;)    *--p = (del_startup_cost += del_cost_per_char);  /* Doing nothing is free */  p = &DCICcost[0];  *p++ = 0;  /* Insert costs are at positive offsets */  for (i = screen_width; --i >= 0;)    *p++ = (ins_startup_cost += ins_cost_per_char);}calculate_costs (){  register char *s    = TS_set_scroll_region ? TS_set_scroll_region : TS_set_scroll_region_1;  if (chars_wasted != 0)    chars_wasted = (char *) xrealloc (chars_wasted, screen_height);  else    chars_wasted = (char *) xmalloc (screen_height);  bzero (chars_wasted, screen_height);  if (copybuf != 0)    copybuf = (char *) xrealloc (copybuf, screen_height);  else    copybuf = (char *) xmalloc (screen_height);  if (DC_ICcost != 0)    DC_ICcost = (int *) xrealloc (DC_ICcost,				  (2 * screen_width + 1) * sizeof (int));  else    DC_ICcost = (int *) xmalloc ((2 * screen_width + 1) * sizeof (int));  /* Always call CalcIDCosts because it allocates some vectors.     That function handles dont_calculate_costs.  */  if (s && (!TS_ins_line && !TS_del_line))    CalcIDCosts (TS_rev_scroll, TS_ins_multi_lines,		 TS_fwd_scroll, TS_del_multi_lines,		 s, s);  else    CalcIDCosts (TS_ins_line, TS_ins_multi_lines,		 TS_del_line, TS_del_multi_lines,		 0, 0);  if (dont_calculate_costs)    {      bzero (DC_ICcost, 2 * screen_width * sizeof (int));      return;    }  calculate_ins_del_char_costs ();  /* Don't use TS_repeat if its padding is worse than sending the chars */  if (TS_repeat && per_line_cost (TS_repeat) * baud_rate < 9000)    RPov = string_cost (TS_repeat);  else    RPov = screen_width * 2;  cmcostinit ();		/* set up cursor motion costs */}term_init (terminal_type)     char *terminal_type;{  char *area;  char **address = &area;  char buffer[2044];  register char *p;  int status;  extern char *tgetstr ();  Wcm_clear ();  dont_calculate_costs = 0;  status = tgetent (buffer, terminal_type);  if (status < 0)    fatal ("Cannot open termcap database file.\n");  if (status == 0)    fatal ("Terminal type %s is not defined.\n", terminal_type);#ifdef TERMINFO  area = (char *) malloc (2044);#else  area = (char *) malloc (strlen (buffer));#endif /* not TERMINFO */  if (area == 0)    abort ();  TS_ins_line = tgetstr ("al", address);  TS_ins_multi_lines = tgetstr ("AL", address);  TS_bell = tgetstr ("bl", address);  TS_clr_to_bottom = tgetstr ("cd", address);  TS_clr_line = tgetstr ("ce", address);  TS_clr_screen = tgetstr ("cl", address);  ColPosition = tgetstr ("ch", address);  AbsPosition = tgetstr ("cm", address);  CR = tgetstr ("cr", address);  TS_set_scroll_region = tgetstr ("cs", address);  TS_set_scroll_region_1 = tgetstr ("cS", address);  RowPosition = tgetstr ("cv", address);  TS_del_char = tgetstr ("dc", address);  TS_del_multi_chars = tgetstr ("DC", address);  TS_del_line = tgetstr ("dl", address);  TS_del_multi_lines = tgetstr ("DL", address);  TS_delete_mode = tgetstr ("dm", address);  TS_end_delete_mode = tgetstr ("ed", address);  TS_end_insert_mode = tgetstr ("ei", address);  Home = tgetstr ("ho", address);  TS_ins_char = tgetstr ("ic", address);  TS_ins_multi_chars = tgetstr ("IC", address);  TS_insert_mode = tgetstr ("im", address);  TS_pad_inserted_char = tgetstr ("ip", address);  TS_end_keypad_mode = tgetstr ("ke", address);  TS_keypad_mode = tgetstr ("ks", address);  LastLine = tgetstr ("ll", address);  Right = tgetstr ("nd", address);  Down = tgetstr ("do", address);  if (!Down)    Down = tgetstr ("nl", address); /* Obsolete name for "do" */#ifdef VMS  /* VMS puts a carriage return before each linefeed,     so it is not safe to use linefeeds.  */  if (Down && Down[0] == '\n' && Down[1] == '\0')    Down = 0;#endif /* VMS */  if (tgetflag ("bs"))    Left = "\b";		  /* can't possibly be longer! */  else				  /* (Actually, "bs" is obsolete...) */    Left = tgetstr ("le", address);  if (!Left)    Left = tgetstr ("bc", address); /* Obsolete name for "le" */  TS_pad_char = tgetstr ("pc", address);  TS_repeat = tgetstr ("rp", address);  TS_end_standout_mode = tgetstr ("se", address);  TS_fwd_scroll = tgetstr ("sf", address);  TS_standout_mode = tgetstr ("so", address);  TS_rev_scroll = tgetstr ("sr", address);  Wcm.cm_tab = tgetstr ("ta", address);  TS_end_termcap_modes = tgetstr ("te", address);  TS_termcap_modes = tgetstr ("ti", address);  Up = tgetstr ("up", address);  TS_visible_bell = tgetstr ("vb", address);  TS_end_visual_mode = tgetstr ("ve", address);  TS_visual_mode = tgetstr ("vs", address);  TS_set_window = tgetstr ("wi", address);  AutoWrap = tgetflag ("am");  memory_below_screen = tgetflag ("db");  TF_hazeltine = tgetflag ("hz");  must_write_spaces = tgetflag ("in");  meta_key = tgetflag ("km") || tgetflag ("MT");  TF_insmode_motion = tgetflag ("mi");  TF_standout_motion = tgetflag ("ms");  TF_underscore = tgetflag ("ul");  MagicWrap = tgetflag ("xn");  TF_xs = tgetflag ("xs");  TF_teleray = tgetflag ("xt");  /* Get screen size from system, or else from termcap.  */  get_screen_size (&screen_width, &screen_height);  if (screen_width <= 0)    screen_width = tgetnum ("co");  if (screen_height <= 0)    screen_height = tgetnum ("li");  min_padding_speed = tgetnum ("pb");  TN_standout_width = tgetnum ("sg");  TabWidth = tgetnum ("tw");#ifdef VMS  /* These capabilities commonly use ^J.     I don't know why, but sending them on VMS does not work;     it causes following spaces to be lost, sometimes.     For now, the simplest fix is to avoid using these capabilities ever.  */  if (Down && Down[0] == '\n')    Down = 0;#endif /* VMS */  if (!TS_bell)    TS_bell = "\07";  if (!TS_fwd_scroll)    TS_fwd_scroll = Down;  PC = TS_pad_char ? *TS_pad_char : 0;  if (TabWidth < 0)    TabWidth = 8;  /* Turned off since /etc/termcap seems to have :ta= for most terminals   and newer termcap doc does not seem to say there is a default.  if (!Wcm.cm_tab)    Wcm.cm_tab = "\t";*/  if (TS_standout_mode == 0)    {      TN_standout_width = tgetnum ("ug");      TS_end_standout_mode = tgetstr ("ue", address);      TS_standout_mode = tgetstr ("us", address);    }  if (TF_teleray)    {      Wcm.cm_tab = 0;      /* Teleray: most programs want a space in front of TS_standout_mode,	   but Emacs can do without it (and give one extra column).  */      TS_standout_mode = "\033RD";      TN_standout_width = 1;      /* But that means we cannot rely on ^M to go to column zero! */      CR = 0;      /* LF can't be trusted either -- can alter hpos */      /* if move at column 0 thru a line with TS_standout_mode */      Down = 0;    }  /* Special handling for certain terminal types known to need it */  if (!strcmp (terminal_type, "supdup"))    {      memory_below_screen = 1;      Wcm.cm_losewrap = 1;    }  if (!strncmp (terminal_type, "c10", 3)      || !strcmp (terminal_type, "perq"))    {      /* Supply a makeshift :wi string.	 This string is not valid in general since it works only	 for windows starting at the upper left corner;	 but that is all Emacs uses.	 This string works only if the screen is using	 the top of the video memory, because addressing is memory-relative.	 So first check the :ti string to see if that is true.	 It would be simpler if the :wi string could go in the termcap	 entry, but it can't because it is not fully valid.	 If it were in the termcap entry, it would confuse other programs.  */      if (!TS_set_window)	{	  p = TS_termcap_modes;	  while (*p && strcmp (p, "\033v  "))	    p++;	  if (*p)	    TS_set_window = "\033v%C %C %C %C ";	}      /* Termcap entry often fails to have :in: flag */      must_write_spaces = 1;      /* :ti string typically fails to have \E^G! in it */      /* This limits scope of insert-char to one line.  */      strcpy (area, TS_termcap_modes);      strcat (area, "\033\007!");      TS_termcap_modes = area;      area += strlen (area) + 1;      p = AbsPosition;      /* Change all %+ parameters to %C, to handle	 values above 96 correctly for the C100.  */      while (*p)	{	  if (p[0] == '%' && p[1] == '+')	    p[1] = 'C';	  p++;	}    }  ScreenRows = screen_height;  ScreenCols = screen_width;  specified_window = screen_height;  if (Wcm_init ())	/* can't do cursor motion */#ifdef VMS    fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\It lacks the ability to position the cursor.\n\If that is not the actual type of terminal you have, use either the\n\DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.\n",           terminal_type);#else    fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\It lacks the ability to position the cursor.\n\If that is not the actual type of terminal you have,\n\use the C-shell command `setenv TERM ...' to specify the correct type.\n\It may be necessary to do `unsetenv TERMCAP' as well.\n",	   terminal_type);#endif  delete_in_insert_mode    = TS_delete_mode && TS_insert_mode      && !strcmp (TS_delete_mode, TS_insert_mode);  se_is_so = TS_standout_mode && TS_end_standout_mode    && !strcmp (TS_standout_mode, TS_end_standout_mode);  /* Remove width of standout marker from usable width of line */  if (TN_standout_width > 0)    screen_width -= TN_standout_width;  UseTabs = tabs_safe_p () && TabWidth == 8;  scroll_region_ok = TS_set_window || TS_set_scroll_region    || TS_set_scroll_region_1;  line_ins_del_ok = (((TS_ins_line || TS_ins_multi_lines)		      && (TS_del_line || TS_del_multi_lines))		     || (scroll_region_ok			 && TS_fwd_scroll			 && TS_rev_scroll));  char_ins_del_ok = ((TS_ins_char || TS_insert_mode ||		      TS_pad_inserted_char || TS_ins_multi_chars)		     && (TS_del_char || TS_del_multi_chars));  fast_clear_end_of_line = TS_clr_line != 0;  init_baud_rate ();  if (read_socket_hook)		/* Baudrate is somewhat */				/* meaningless in this case */    baud_rate = 9600;}/* VARARGS 1 */fatal (str, arg1, arg2)     char *str;{  fprintf (stderr, "emacs: ");  fprintf (stderr, str, arg1, arg2);  fflush (stderr);  exit (1);}

⌨️ 快捷键说明

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