📄 window.c
字号:
in this window. */ return (window_get_cursor_column (window));}/* Get and return the printed column offset of the cursor in this window. */intwindow_get_cursor_column (window) WINDOW *window;{ int i, hpos, end; char *line; i = window_line_of_point (window); if (i < 0) return (-1); line = window->line_starts[i]; end = window->point - (line - window->node->contents); for (hpos = 0, i = 0; i < end; i++) hpos += character_width (line[i], hpos); return (hpos);}/* Count the number of characters in LINE that precede the printed column offset of GOAL. */intwindow_chars_to_goal (line, goal) char *line; int goal;{ register int i, check, hpos; for (hpos = 0, i = 0; line[i] != '\n'; i++) { check = hpos + character_width (line[i], hpos); if (check > goal) break; hpos = check; } return (i);}/* Create a modeline for WINDOW, and store it in window->modeline. */voidwindow_make_modeline (window) WINDOW *window;{ register int i; char *modeline; char location_indicator[4]; int lines_remaining; /* Only make modelines for those windows which have one. */ if (window->flags & W_InhibitMode) return; /* Find the number of lines actually displayed in this window. */ lines_remaining = window->line_count - window->pagetop; if (window->pagetop == 0) { if (lines_remaining <= window->height) strcpy (location_indicator, "All"); else strcpy (location_indicator, "Top"); } else { if (lines_remaining <= window->height) strcpy (location_indicator, "Bot"); else { float pt, lc; int percentage; pt = (float)window->pagetop; lc = (float)window->line_count; percentage = 100 * (pt / lc); sprintf (location_indicator, "%2d%%", percentage); } } /* Calculate the maximum size of the information to stick in MODELINE. */ { int modeline_len = 0; char *parent = (char *)NULL, *filename = "*no file*"; char *nodename = "*no node*"; char *update_message = (char *)NULL; NODE *node = window->node; if (node) { if (node->nodename) nodename = node->nodename; if (node->parent) { parent = filename_non_directory (node->parent); modeline_len += strlen ("Subfile: ") + strlen (node->filename); } if (node->filename) filename = filename_non_directory (node->filename); if (node->flags & N_UpdateTags) update_message = _("--*** Tags out of Date ***"); } if (update_message) modeline_len += strlen (update_message); modeline_len += strlen (filename); modeline_len += strlen (nodename); modeline_len += 4; /* strlen (location_indicator). */ /* 10 for the decimal representation of the number of lines in this node, and the remainder of the text that can appear in the line. */ modeline_len += 10 + strlen (_("-----Info: (), lines ----, ")); modeline_len += window->width; modeline = (char *)xmalloc (1 + modeline_len); /* Special internal windows have no filename. */ if (!parent && !*filename) sprintf (modeline, _("-%s---Info: %s, %d lines --%s--"), (window->flags & W_NoWrap) ? "$" : "-", nodename, window->line_count, location_indicator); else sprintf (modeline, _("-%s%s-Info: (%s)%s, %d lines --%s--"), (window->flags & W_NoWrap) ? "$" : "-", (node && (node->flags & N_IsCompressed)) ? "zz" : "--", parent ? parent : filename, nodename, window->line_count, location_indicator); if (parent) sprintf (modeline + strlen (modeline), _(" Subfile: %s"), filename); if (update_message) sprintf (modeline + strlen (modeline), "%s", update_message); i = strlen (modeline); if (i >= window->width) modeline[window->width] = '\0'; else { while (i < window->width) modeline[i++] = '-'; modeline[i] = '\0'; } strcpy (window->modeline, modeline); free (modeline); }}/* Make WINDOW start displaying at PERCENT percentage of its node. */voidwindow_goto_percentage (window, percent) WINDOW *window; int percent;{ int desired_line; if (!percent) desired_line = 0; else desired_line = (int) ((float)window->line_count * ((float)percent / 100.0)); window->pagetop = desired_line; window->point = window->line_starts[window->pagetop] - window->node->contents; window->flags |= W_UpdateWindow; window_make_modeline (window);}/* Get the state of WINDOW, and save it in STATE. */voidwindow_get_state (window, state) WINDOW *window; WINDOW_STATE *state;{ state->node = window->node; state->pagetop = window->pagetop; state->point = window->point;}/* Set the node, pagetop, and point of WINDOW. */voidwindow_set_state (window, state) WINDOW *window; WINDOW_STATE *state;{ if (window->node != state->node) window_set_node_of_window (window, state->node); window->pagetop = state->pagetop; window->point = state->point;}/* **************************************************************** *//* *//* Manipulating Home-Made Nodes *//* *//* **************************************************************** *//* A place to buffer echo area messages. */static NODE *echo_area_node = (NODE *)NULL;/* Make the node of the_echo_area be an empty one. */static voidfree_echo_area (){ if (echo_area_node) { maybe_free (echo_area_node->contents); free (echo_area_node); } echo_area_node = (NODE *)NULL; window_set_node_of_window (the_echo_area, echo_area_node);} /* Clear the echo area, removing any message that is already present. The echo area is cleared immediately. */voidwindow_clear_echo_area (){ free_echo_area (); display_update_one_window (the_echo_area);}/* Make a message appear in the echo area, built from FORMAT, ARG1 and ARG2. The arguments are treated similar to printf () arguments, but not all of printf () hair is present. The message appears immediately. If there was already a message appearing in the echo area, it is removed. */voidwindow_message_in_echo_area (format, arg1, arg2) char *format; void *arg1, *arg2;{ free_echo_area (); echo_area_node = build_message_node (format, arg1, arg2); window_set_node_of_window (the_echo_area, echo_area_node); display_update_one_window (the_echo_area);}/* Place a temporary message in the echo area built from FORMAT, ARG1 and ARG2. The message appears immediately, but does not destroy any existing message. A future call to unmessage_in_echo_area () restores the old contents. */static NODE **old_echo_area_nodes = (NODE **)NULL;static int old_echo_area_nodes_index = 0;static int old_echo_area_nodes_slots = 0;voidmessage_in_echo_area (format, arg1, arg2) char *format; void *arg1, *arg2;{ if (echo_area_node) { add_pointer_to_array (echo_area_node, old_echo_area_nodes_index, old_echo_area_nodes, old_echo_area_nodes_slots, 4, NODE *); } echo_area_node = (NODE *)NULL; window_message_in_echo_area (format, arg1, arg2);}voidunmessage_in_echo_area (){ free_echo_area (); if (old_echo_area_nodes_index) echo_area_node = old_echo_area_nodes[--old_echo_area_nodes_index]; window_set_node_of_window (the_echo_area, echo_area_node); display_update_one_window (the_echo_area);}/* A place to build a message. */static char *message_buffer = (char *)NULL;static int message_buffer_index = 0;static int message_buffer_size = 0;/* Ensure that there is enough space to stuff LENGTH characters into MESSAGE_BUFFER. */static voidmessage_buffer_resize (length) int length;{ if (!message_buffer) { message_buffer_size = length + 1; message_buffer = (char *)xmalloc (message_buffer_size); message_buffer_index = 0; } while (message_buffer_size <= message_buffer_index + length) message_buffer = (char *) xrealloc (message_buffer, message_buffer_size += 100 + (2 * length));}/* Format MESSAGE_BUFFER with the results of printing FORMAT with ARG1 and ARG2. */static voidbuild_message_buffer (format, arg1, arg2) char *format; void *arg1, *arg2;{ register int i, len; void *args[2]; int arg_index = 0; args[0] = arg1; args[1] = arg2; len = strlen (format); message_buffer_resize (len); for (i = 0; format[i]; i++) { if (format[i] != '%') { message_buffer[message_buffer_index++] = format[i]; len--; } else { char c; c = format[++i]; switch (c) { case '%': /* Insert a percent sign. */ message_buffer_resize (len + 1); message_buffer[message_buffer_index++] = '%'; break; case 's': /* Insert the current arg as a string. */ { char *string; int string_len; string = (char *)args[arg_index++]; string_len = strlen (string); message_buffer_resize (len + string_len); sprintf (message_buffer + message_buffer_index, "%s", string); message_buffer_index += string_len; } break; case 'd': /* Insert the current arg as an integer. */ { long long_val; int integer; long_val = (long)args[arg_index++]; integer = (int)long_val; message_buffer_resize (len + 32); sprintf (message_buffer + message_buffer_index, "%d", integer); message_buffer_index = strlen (message_buffer); } break; case 'c': /* Insert the current arg as a character. */ { long long_val; int character; long_val = (long)args[arg_index++]; character = (int)long_val; message_buffer_resize (len + 1); message_buffer[message_buffer_index++] = character; } break; default: abort (); } } } message_buffer[message_buffer_index] = '\0';}/* Build a new node which has FORMAT printed with ARG1 and ARG2 as the contents. */NODE *build_message_node (format, arg1, arg2) char *format; void *arg1, *arg2;{ NODE *node; message_buffer_index = 0; build_message_buffer (format, arg1, arg2); node = message_buffer_to_node (); return (node);}/* Convert the contents of the message buffer to a node. */NODE *message_buffer_to_node (){ NODE *node; node = (NODE *)xmalloc (sizeof (NODE)); node->filename = (char *)NULL; node->parent = (char *)NULL; node->nodename = (char *)NULL; node->flags = 0; /* Make sure that this buffer ends with a newline. */ node->nodelen = 1 + strlen (message_buffer); node->contents = (char *)xmalloc (1 + node->nodelen); strcpy (node->contents, message_buffer); node->contents[node->nodelen - 1] = '\n'; node->contents[node->nodelen] = '\0'; return (node);}/* Useful functions can be called from outside of window.c. */voidinitialize_message_buffer (){ message_buffer_index = 0;}/* Print FORMAT with ARG1,2 to the end of the current message buffer. */voidprintf_to_message_buffer (format, arg1, arg2) char *format; void *arg1, *arg2;{ build_message_buffer (format, arg1, arg2);}/* Return the current horizontal position of the "cursor" on the most recently output message buffer line. */intmessage_buffer_length_this_line (){ register int i; if (!message_buffer_index) return (0); for (i = message_buffer_index; i && message_buffer[i - 1] != '\n'; i--); return (string_width (message_buffer + i, 0));}/* Pad STRING to COUNT characters by inserting blanks. */intpad_to (count, string) int count; char *string;{ register int i; i = strlen (string); if (i >= count) string[i++] = ' '; else { while (i < count) string[i++] = ' '; } string[i] = '\0'; return (i);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -