📄 cooledit.c
字号:
/* cooledit.c - main file of cooledit Copyright (C) 1996-2000 Paul Sheer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */#include <config.h>#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <sys/types.h>#if HAVE_SYS_WAIT_H# include <sys/wait.h>#endif#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/Xatom.h>#include "lkeysym.h"#include "stringtools.h"#include "coolwidget.h"#include "edit.h"#include "editcmddef.h"#include "loadfile.h"#include "editoptions.h"#include "cmdlineopt.h"#include "shell.h"#include "igloo.h"#include "widget/pool.h"#if HAVE_DIRENT_H#include <dirent.h>#define NAMLEN(dirent) strlen((dirent)->d_name)#else#define dirent direct#define NAMLEN(dirent) (dirent)->d_namlen#if HAVE_SYS_NDIR_H#include <sys/ndir.h>#endif#if HAVE_SYS_DIR_H#include <sys/dir.h>#endif#if HAVE_NDIR_H#include <ndir.h>#endif#endif#ifdef HAVE_LANGINFO_H#include <langinfo.h>#endif#include "mad.h"extern struct look *look;void do_mail (CWidget *edit);int start_width = 80;int start_height = 30;char *option_look = "gtk";/* error handler */#ifdef DEBUGint er_handler (Display * c, XErrorEvent * e){/* NLS ? */ char err[128]; XGetErrorText (c, e->error_code, err, 128); if (e->request_code == 42) /* input focus errors are skipped */ return 0; fprintf (stderr, "cooledit: Error detected.\n %s\n", err); fprintf (stderr, " Protocal request: %d\n", e->request_code); fprintf (stderr, " Resource ID: 0x%x\n", (unsigned int) e->resourceid); fprintf (stderr, "Ignoring error.\n"); return 0;}#endif#if (RETSIGTYPE==void)#define handler_return return#else#define handler_return return 1#endifextern Atom ATOM_WM_PROTOCOLS, ATOM_WM_DELETE_WINDOW, ATOM_WM_NAME, ATOM_WM_NORMAL_HINTS;char *argv_nought = "cooledit";Window main_window;int display_dnd_protocol_change_message = 0;/* {{{ signal handling */static void main_loop (void);static RETSIGTYPE userone_handler (int x){ CErrorDialog (main_window, 20, 20, \/* heads the dialog box for when a SIGUSR1 Signal is recieved: SIGUSR1 */ _(" Signal SIGUSR1 Recieved "), _("%s: SIGUSR1 recieved\n" \ "You may have interrupted Cooledit because a search was taking too\n" \ "long, or because you executed a recursive macro. In the latter\n" \ "case, you should exit ASAP. Otherwise, if nothing peculiar was happening\n" \ "Cooledit is probably still stable. Cooledit will now continue executing"), \ argv_nought); signal (SIGUSR1, userone_handler); CEnable ("*"); XUngrabPointer (CDisplay, CurrentTime); main_loop (); /* continue */ exit (0); handler_return;}static RETSIGTYPE quit_handler (int x){/* %s = cooledit */ fprintf (stderr, _("%s: quiting without saving\n"), argv_nought);#if 0 CShutdown (); /* needed just to close the connection to the display */#else XCloseDisplay (CDisplay);#endif exit (0); handler_return;}void set_to_kill (pid_t p);void shell_output_set_to_kill (pid_t p);static void set_signals (void){ signal (SIGPIPE, SIG_IGN); signal (SIGUSR1, userone_handler);#if 1 signal (SIGQUIT, quit_handler); signal (SIGINT, quit_handler); signal (SIGTERM, quit_handler);#else signal (SIGQUIT, SIG_DFL); signal (SIGINT, SIG_DFL); signal (SIGTERM, SIG_DFL);#endif}/* }}} signal handling *//* {{{ NLS support */struct linguas { char *name; char *abbr;} languages[] = { {"Chinese", "zh"}, {"Czech", "cs"}, {"Danish", "da"}, {"Dutch", "nl"}, {"English", "en"}, {"Esperanto", "eo"}, {"Finnish", "fi"}, {"French", "fr"}, {"German", "de"}, {"Hungarian", "hu"}, {"Irish", "ga"}, {"Italian", "it"}, {"Indonesian", "id"}, {"Japanese", "ja"}, {"Korean", "ko"}, {"Latin", "la"}, {"Norwegian", "no"}, {"Persian", "fa"}, {"Polish", "pl"}, {"Portuguese", "pt"}, {"Russian", "ru"}, {"Slovenian", "sl"}, {"Spanish", "es"}, {"Swedish", "sv"}, {"Turkish", "tr"}};/* }}} NLS support *//* {{{ hint message on title bar */void get_next_hint_message (void){ static int i = -1; static int n; char label[128]; static char *hints[] = {/* HINTSTART *//* The following are hints that go on the title bar: eg "Cooledit - Hint: Undo key-for-key with Ctrl-Backspace" */ gettext_noop("To drag and drop, highlight text, then click and drag from within the selection"), gettext_noop("Dragging with the right mouse button will move text"), gettext_noop("Goto http://www.icon.co.za/~psheer - Paul Sheer Consulting IT Services"), gettext_noop("Dragging with the left mouse button will copy text"), gettext_noop("Use Shift-Insert to copy text from other applications"), gettext_noop("Use Alt-Insert to bring up a history of selected text"), gettext_noop("Function keys F11-F20 mean Shift with a function key F1-F10"), gettext_noop("Do not email the author with generic questions, goto your local LUG instead"), gettext_noop("See how to do regular expression substring replacements in the man page"), gettext_noop("Use Shift-Up/Down in input widgets to get a history of inputs"), gettext_noop("Run frequently used apps from a hot key: see the Scripts menu"), gettext_noop("Get your keypad to work by redefining keys in the Options menu"), gettext_noop("Drag a file name from the 'File browser' in the Window menu to insert it"), gettext_noop("Use a macro to record repeatedly used key sequences"), gettext_noop("Get a list of demo fonts with: cooledit -font h"), gettext_noop("Undo key-for-key with Ctrl-Backspace"), gettext_noop("Drag function prototypes and other info from the man page browser"), gettext_noop("Double click on words in the man page browser to search for new man pages"), gettext_noop("Goto http://www.icon.co.za/~psheer - Paul Sheer Consulting IT Services"), gettext_noop("Search for [Options] in ~/.cedit/.cooledit.ini and change settings"), gettext_noop("Edit the example Scripts to see how to create your own"), gettext_noop("Double click on gcc error messages after running Make or Cc"), gettext_noop("Turn off these messages from the Options menu: 'Hint time...' = 0"), gettext_noop("Do not email the author with generic questions, goto your local LUG instead"), gettext_noop("See how to do regular expression substring replacements in the man page"), gettext_noop("See cooledit.1 for a list of the many extended editing/movement keys"), gettext_noop("Compose international characters with Right-Control"), gettext_noop("Set the LC_ALL and LANG environment variables - see the FAQ"), gettext_noop("For new international character support see the FAQ"), gettext_noop("Insert (hexa)decimal literals with Control-q and the (hexa)decimal digits"), gettext_noop("Try out proportional fonts like Times or Helvetica"), gettext_noop("Read all these hint messages in editor/cooledit.c in the source distribution"), gettext_noop("See the file INTERNATIONAL for composing international characters"), gettext_noop("Edit/move at high speed with the many Ctrl/Meta-Arrow combinations"), gettext_noop("Goto http://www.icon.co.za/~psheer - Paul Sheer Consulting IT Services"), gettext_noop("Use drag-and-drop to and from input widgets"), gettext_noop("Open a file by dragging its name from the 'File browser' onto the background"), gettext_noop("Use Shift-Ins to paste into input widgets"), gettext_noop("If Cooledit halts, restore by sending SIGUSR1: kill -1 <pid>"), gettext_noop("For fun, hit Ctrl-Shift-Alt-~ to see how text is redrawn"), gettext_noop("Turn off the toolbar from the 'Options' menu"), gettext_noop("Goto the Python web page: http://www.python.org/"), gettext_noop("Disable the 'Window' menu from the 'Options' menu"), gettext_noop("If a macro is defined to an unused key, it will execute without having to use Ctrl-A"), gettext_noop("Use smalledit if you would like a smaller, cut down version of cooledit"), gettext_noop("Select *columns* of text by holding the control key down through mouse highlighting"), gettext_noop("Use Ctrl-Tab to complete the start of string, C-function or LaTeX-macro"), gettext_noop("Turn off tool hints from the Options menu"), gettext_noop("Use `Auto paragraph...' and `Word wrap...' to edit paragraphs like a WP"), gettext_noop("See how to get a rotating shaded 3D `e' when recieving mail - read coolicon.1"), gettext_noop("See how to do regular expression substring replacements in the man page"), gettext_noop("Try your hand at adding new Cooledit features with Python"), gettext_noop("Mark locations in files with the book mark commands in the Edit menu"), gettext_noop("Debug programs with Meta-F5"), gettext_noop("Goto http://www.icon.co.za/~psheer - Paul Sheer Consulting IT Services"), gettext_noop("Execute explicit debugger commands with Meta-F1"), gettext_noop("Turn off spell checking from the Options menu"), gettext_noop("File files containing regular expressions with Ctrl-Meta-F"), gettext_noop("Delete debugger variables with Del in the variable dialog"), gettext_noop("Add debugger watches with Ins in the variable dialog"), gettext_noop("Make a variable watch point by marking it with Ins in the variable dialog"), gettext_noop("Change the default size of the undo stack in ~/.cedit/.cooledit.ini"), gettext_noop("Bookmark all matching strings with the `Bookmarks' switch in the `Search' dialog"), gettext_noop("Create a printable postscript manual with man -t cooledit > cooledit.ps"), gettext_noop("Read the Python online tutorials: http://www.python.org/"), gettext_noop("Enable \"Smooth scrolling\" option if you have a fast graphics card"), gettext_noop("Start internal XTerms with \"Terminal\" in the command menu"), gettext_noop("Use the coolproject command to start projects"), gettext_noop("Goto http://www.icon.co.za/~psheer - Paul Sheer Consulting IT Services"), gettext_noop("Display Unicode text - See FAQ"), gettext_noop("All colours can have their RGB values set - see COLOURS in the man page"), gettext_noop("Try different looks with the \"--look\" command line option"), gettext_noop("Press Escape to enter shell commands"), gettext_noop("Select text then use Escape to pipe through a shell command"), };/* HINTEND */ if (i < 0) { n = sizeof (hints) / sizeof (char *); i = time (0) % n; } else i = (i + 1) % n; strcpy (label, _("Cooledit - Hint: ")); strcat (label, gettext (hints[i])); XChangeProperty (CDisplay, main_window, ATOM_WM_NAME, XA_STRING, 8, PropModeReplace, (unsigned char *) label, strlen (label));}/* }}} hint message on title bar */void edit_change_directory (void){ char *new_dir; new_dir = CGetDirectory (main_window, 40, 40, current_dir, "", /* heads the 'Change Directory' dialog box */ _(" Change Directory ")); if (new_dir) { if (change_directory (new_dir) < 0) { /* which should never happen *//* heads the 'Change Directory' dialog box */ CErrorDialog(main_window, 20, 20, _(" Change directory "), get_sys_error (_(" Error return from chdir. "))); } }}/* {{{ command-line options */int load_setup (const char *file);int save_setup (const char *file);static char **command_line_files;char *editor_options_file = 0;extern char *option_preferred_visual;extern int option_force_own_colormap;extern int option_force_default_colormap;extern int option_invert_colors;extern int option_invert_crome;extern int option_invert_red_green;extern int option_invert_green_blue;extern int option_invert_red_blue;int option_suppress_load_files = 0;int option_suppress_load_files_cmdline = 0;int option_suppress_load_options = 0;int option_save_setup_on_exit = 1;int option_hint_messages = 120;int option_cursor_blink_rate = 7;int option_pull_down_window_list = 1;int option_toolbar = 1;int option_minimal_main_window = 0;extern int option_utf_interpretation;extern int option_no_font_set;extern char *option_geometry;extern int option_use_xim;int option_aa_font = -1;extern int option_rgb_order;extern int option_interchar_spacing;int option_new_window_ask_for_file = 1;char *option_display = 0;char *option_geometry = 0;char *option_background_color = "igloo";char *option_foreground_red = 0;char *option_foreground_green = 0;char *option_foreground_blue = 0;char *option_font = 0;char *option_widget_font = 0;static int option_command_line_doesnt_override = 0;static int get_help = 0;static int get_version = 0;static int option_verbose = 0;void usage (void){ printf ( \/* Translate only the description of what the options does, not the option itself */ _("Cooledit version %s\n" \ "A user friendly text editor for the X Window System.\n" \ "Usage:\n" \ "%s [-AabCEhiPsSUVv?] [options] [[+<line>] <file>] [[+<line>] <file>] ...\n"), \ VERSION, PACKAGE); printf (_("-d, -display <display> the X server to display on\n"));#ifdef GUESS_VISUAL printf (_("-vis, --visual <visual-class> use cooledit -vis h for help\n" \ "-C, -cmap, --own-colormap force use of own colormap\n" \ "-defcmap, --default-colormap force use of default colormap\n"));#endif printf (_("-g, -geom, -geometry <geometry> window size and position\n" \ "-m, --minimal-main-window main window border only\n" \ "-lines <n> number of text lines\n" \ "-columns <n> number of text columns\n" \ "--edit-bg <nn> <nn> 0-26 (rather edit .cooledit.ini)\n" \ "-bg, --background-color <color> eg blue for solid blue, default: igloo\n" \ "-R, --foreground-red <value> red component, default: 0.9\n" \ "-G, --foreground-green <value> green component, default: 1.1\n" \ "-B, --foreground-blue <value> blue component, default: 1.4\n" \ "-f, -fn, -font <font-name> use cooledit -font h for help\n" \ "--widget-font <font-name> font of widgets and controls\n" \ "-S, --suppress-load-files don't load saved desktop\n" \ "-U, --suppress-load-options don't load saved options\n" \ "-E, -no-override command line doesn't override init file\n" \ "-I, --use-initialisation-file <file> default: ~/.cedit/.cooledit.ini\n" \ "-wordwrap, --word-wrap <length> default: 72\n" \ "-typew, --type-writer type-writer word wrap\n" \ "-autop, --auto-paragraph word processor paragraphing\n" \ "-i, --all-characters display characters outside of locale\n" \ "-noi --no-international-characters default\n" \ "-t, -tab, --tab-spacing <spacing> set tab spacing\n" \ "-s, -space, --space-filled-tabs fill tabs with ascii 32 (a space)\n" \ "-nospace, --no-space-filled-tabs default\n" \ "-a, --auto-indent return does an auto indent (default)\n" \ "-noautoi, --no-auto-indent turn off auto indent\n" \ "-b, --backspace-through-tabs backspace deletes to right margin\n" \ "-noback, --no-backspace-through-tabs default\n" \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -