📄 tool.c
字号:
#ifndef lint#ifdef sccsstatic char sccsid[] = "@(#)tool.c 1.1 92/07/30 Copyr 1987 Sun Micro";#endif#endif/* * Copyright (c) 1987 by Sun Microsystems, Inc. *//* * Mailtool - tool creation, termination, handling */#include <stdio.h>#include <errno.h>#include <signal.h>#include <ctype.h>#include <sunwindow/window_hs.h>#include <sunwindow/defaults.h>#include <sys/stat.h>#include <sys/wait.h>#include <sys/types.h>#include <suntool/window.h>#include <suntool/frame.h>#include <suntool/panel.h>#include <suntool/text.h>#include <suntool/scrollbar.h>#include <suntool/selection.h>#include <suntool/selection_svc.h>#include <suntool/selection_attributes.h>#include <suntool/walkmenu.h>#include <suntool/icon.h>jobs#include "glob.h"#include "tool.h"#define TOOL_LINES (mt_headerlines + mt_cmdlines + mt_maillines + 3)#define TOOL_COLS 80Frame mt_frame;Textsw mt_headersw; /* the header subwindow */Panel mt_cmdpanel; /* the command panel */Textsw mt_msgsw; /* the message subwindow */Textsw mt_replysw; /* the mail reply subwindow */Panel mt_replypanel; /* the reply subwindow panel */Pixfont *mt_font; /* the default font */static Menu mt_frame_menu;Menu_item mt_open_menu_item;Menu mt_open_menu_pullright;char *mt_namestripe, *mt_namestripe_left, *mt_namestripe_right;int mt_namestripe_width;static int mt_headerlines; /* lines of headers */ int mt_cmdlines; /* command panel height */static int mt_maillines; /* lines for mail item */ int mt_popuplines; /* lines for popup composition window */enum mt_Panel_Style mt_panel_style;enum mt_Load_Messages mt_load_messages;int mt_prevmsg;int mt_idle;int mt_nomail;int mt_retained;int mt_iconic;int mt_system_mail_box; /* true if current folder is system mail box */int mt_3x_compatibility, mt_use_fields, mt_always_use_popup, mt_debugging;int mt_41_features;int mt_use_images;int mt_bells, mt_flashes;int mt_destroying;char *mt_load_from_folder;char *mt_wdir; /* Mail's working directory */time_t mt_msg_time; /* time msgfile was last written */static void mt_msgsw_notify_proc(), mail_load_messages();static void mt_prepare_to_die(), (*cached_mt_msgsw_notify)();static Notify_value mt_signal_func();int charheight, charwidth; /* size of default font */int padding; /* difference between width of window and * width of interior space */int mt_memory_maximum;static Notify_value mt_itimer(), /* mt_itimer1(), */ mt_itimer_doit();static Notify_value mt_frame_event_proc(), mt_destroy();static caddr_t mt_just_open_proc(), mt_open_and_compose_proc(), mt_open_and_read_proc(), mt_switch_folder_action_proc();/* not used - halastatic Menu mt_switch_folder_gen_proc();*/Rect screenrect;u_long last_event_time;/* * Icons */#define static /* XXX - gross kludge */short mt_mail_image[256] = {#include <images/mail.icon>};DEFINE_ICON_FROM_IMAGE(mt_mail_icon, mt_mail_image);short mt_nomail_image[256] = {#include <images/nomail.icon>};DEFINE_ICON_FROM_IMAGE(mt_nomail_icon, mt_nomail_image);short mt_busy_image[256] = {#include <images/mailtool_busy.icon>};DEFINE_ICON_FROM_IMAGE(mt_busy_icon, mt_busy_image);short mt_unknown_image[256] = {#include <images/dead.icon>};DEFINE_ICON_FROM_IMAGE(mt_unknown_icon, mt_unknown_image);short mt_empty_image[256] = {#include <images/empty_letter.icon>};DEFINE_ICON_FROM_IMAGE(mt_empty_letter_icon, mt_empty_image);short mt_reply_image[256] = {#include <images/reply.icon>};DEFINE_ICON_FROM_IMAGE(mt_replying_icon, mt_reply_image);short mt_compose_image[256] = {#include <images/compose.icon>};DEFINE_ICON_FROM_IMAGE(mt_composing_icon, mt_compose_image);#undef staticstruct icon *mt_icon_ptr;voidmt_init_tool_storage(){ /* Dynamically allocate mt_wdir */ mt_wdir = (char *)calloc(256, sizeof (char)); /* Initialize data */ mt_namestripe = (char *)malloc(256); mt_namestripe_left = (char *)malloc(256); mt_namestripe_right = (char *)malloc(256); mt_namestripe[0] = '\0'; mt_idle = TRUE; mt_iconic = TRUE; mt_nomail = TRUE; mt_panel_style = mt_Old; mt_load_messages = mt_When_Opened; mt_3x_compatibility = FALSE; mt_41_features = FALSE;#ifdef USE_IMAGES mt_use_images = TRUE;#else mt_use_images = FALSE;#endif mt_retained = FALSE; mt_use_fields = FALSE; mt_always_use_popup = FALSE; mt_debugging = FALSE; mt_destroying = FALSE; mt_load_from_folder = NULL; mt_icon_ptr = &mt_unknown_icon;}/* * Build and start the tool. */voidmt_start_tool(argc, argv) int argc; char **argv;{/* not used - hala Panel_item item; */ int sigwinched(); int ondeath(); int margin; struct reply_panel_data *ptr; mt_init_mailtool_defaults(); /* * Get the current directory. */ mt_get_mailwd(mt_wdir); (void) chdir(mt_wdir); /* * Initialize the file names menu. */ mt_init_filemenu(); /* * Initialize the folder menu. (Delayed to decrease start-up time * per ecd recommendation - hala) *//* mt_init_folder_menu();*/ /* * Create the tool. */ margin = (int)defaults_get_integer("/Text/Left_margin", 4, 0); padding = 10 + margin + 2 + (int)scrollbar_get(SCROLLBAR, SCROLL_THICKNESS); mt_frame = window_create(0, FRAME, WIN_WIDTH, ATTR_COLS(TOOL_COLS) + padding, WIN_ROWS, TOOL_LINES, WIN_ERROR_MSG, "Unable to create mailtool frame\n", FRAME_LABEL, mt_cmdname, FRAME_SUBWINDOWS_ADJUSTABLE, TRUE, FRAME_CLOSED, (mt_iconic ? TRUE : FALSE), FRAME_ICON, mt_icon_ptr, FRAME_SHOW_LABEL, TRUE, FRAME_ARGC_PTR_ARGV, &argc, argv, 0); if (mt_frame == NULL) { if (mt_debugging) (void)fprintf(stderr, "Unable to create mailtool frame\n"); mt_warn(0, "Unable to create mailtool frame", 0); exit(1); } mt_add_window(mt_frame, mt_Frame); /* enters mt_frame in array of windows */ mt_parse_tool_args(argc, argv); mt_namestripe_width = (int)window_get(mt_frame, WIN_COLUMNS); mt_font = (Pixfont *)window_get(mt_frame, WIN_FONT); charwidth = mt_font->pf_defaultsize.x; charheight = mt_font->pf_defaultsize.y; screenrect = *((Rect *)window_get(mt_frame, WIN_SCREEN_RECT));/*** mt_idle = (mt_load_messages == mt_When_Opened);***/ /* catch going from icon to window */ notify_interpose_event_func(mt_frame, mt_frame_event_proc, NOTIFY_SAFE); mt_frame_menu = window_get(mt_frame, WIN_MENU); if (!mt_3x_compatibility && (mt_open_menu_item = menu_find(mt_frame_menu, MENU_STRING, "Open", 0)) ) { mt_open_menu_pullright = menu_create( MENU_ITEM, MENU_STRING, "Read New Mail", MENU_ACTION_PROC, mt_open_and_read_proc, 0, MENU_ITEM, MENU_STRING, "Read Folder", MENU_GEN_PULLRIGHT, mt_folder_menu_gen_proc, 0, MENU_ITEM, MENU_STRING, "Compose Message", MENU_ACTION_PROC, mt_open_and_compose_proc, 0, MENU_ITEM, MENU_STRING, "Just Open", MENU_ACTION_PROC, mt_just_open_proc, 0, MENU_INITIAL_SELECTION_EXPANDED, FALSE, 0); menu_set(mt_open_menu_item, MENU_PULLRIGHT, mt_open_menu_pullright, 0); } /* catch when being destroyed */ (void) notify_interpose_destroy_func(mt_frame, mt_destroy); /* * Create the header textsubwindow. */ mt_headersw = (Textsw)window_create(mt_frame, TEXT, WIN_ROWS, mt_headerlines, WIN_ERROR_MSG, "mailtool: Unable to create header window\n", TEXTSW_MEMORY_MAXIMUM, mt_memory_maximum, TEXTSW_AUTO_INDENT, FALSE, TEXTSW_DISABLE_LOAD, TRUE, TEXTSW_READ_ONLY, TRUE, 0); if (mt_headersw == NULL) { if (mt_debugging) (void)fprintf(stderr,"Unable to create header subwindow\n"); mt_warn(mt_frame, "Unable to create header subwindow", 0); exit(1); } mt_add_window(mt_headersw, mt_Text); (void) window_set(mt_headersw, TEXTSW_LINE_BREAK_ACTION, TEXTSW_CLIP, 0); /* * Create the command panel. */ if (mt_panel_style == mt_3DImages) mt_create_3Dimages_panel(); else if (mt_panel_style == mt_New) mt_create_new_style_panel(); else if (mt_panel_style == mt_Old) mt_create_old_style_panel(); else fprintf(stderr, "unrecognized value for mt_panel_style\n"); last_event_time = mt_current_time(); if (mt_load_from_folder)/* allows user to set folder name from * command line */ panel_set_value(mt_file_item, mt_load_from_folder); /* * Create the mail message textsubwindow. */ mt_msgsw = (Textsw)window_create(mt_frame, TEXT, WIN_ERROR_MSG, "mailtool: unable to create message window\n", WIN_X, 0, WIN_BELOW, mt_cmdpanel, TEXTSW_MEMORY_MAXIMUM, mt_memory_maximum, TEXTSW_CONFIRM_OVERWRITE, 0, TEXTSW_STORE_SELF_IS_SAVE, 1, TEXTSW_DISABLE_LOAD, 1, 0); if (mt_msgsw == NULL) { if (mt_debugging) (void)fprintf(stderr,"Unable to create message textsw\n"); mt_warn(mt_frame, "Unable to create message textsw", 0); exit(1); } mt_add_window(mt_msgsw, mt_Text); cached_mt_msgsw_notify = (void (*) ())window_get( mt_msgsw, TEXTSW_NOTIFY_PROC); (void) window_set(mt_msgsw, TEXTSW_NOTIFY_PROC, mt_msgsw_notify_proc, 0); if (mt_3x_compatibility || !mt_always_use_popup) { /* * Create the mail reply textsubwindow and its control panel. */ ptr = mt_create_reply_panel(mt_frame); if (ptr == NULL) /* unable to create reply panel */ { fprintf(stderr, "Unable to create reply panel in mt_start_tool\n"); exit(1); } mt_replypanel = ptr->reply_panel; mt_replysw = ptr->replysw; panel_set(mt_cmdpanel, PANEL_CLIENT_DATA, ptr, 0); /* * store ptr here to be able to find the first * replysw in mt_get_replysw */ } else { mt_replypanel = NULL; mt_replysw = NULL; } /* * Catch signals, install tool. */ (void)notify_set_signal_func(&mt_mailclient, mt_signal_func, SIGTERM, NOTIFY_ASYNC); (void)notify_set_signal_func(&mt_mailclient, mt_signal_func, SIGXCPU, NOTIFY_ASYNC); /* * Kludge - we want the notifier to harvest all dead children * so we tell it to wait for its own death. */ (void)notify_set_wait3_func(&mt_mailclient, notify_default_wait3, getpid()); /* start up with correct icon */ mt_check_mail_box(); /* set timer intervals */ mt_start_timer(); window_main_loop(mt_frame); mt_stop_mail(mt_aborting);}/* * resetting these variables after reading .mailrc will immediately affect * behavior of mailtool, so this procedure is called from both mt_start_tool * and from mt_mailrc_proc */voidmt_init_mailtool_defaults(){ int i; char *p; mt_3x_compatibility = !defaults_get_boolean( "/Compatibility/New_Mailtool_features", TRUE, 0); mt_retained = (int)defaults_get_boolean("/Text/Retained", FALSE, 0); mt_cmdlines = 4; /* only used for oldstyle panel */ if (mt_3x_compatibility) { if ((p = mt_value("cmdlines")) && (i = atoi(p)) > 0) mt_cmdlines = i; } else { while ((p = index(mt_cmdname, '/')) != NULL) mt_cmdname = ++p; /* strip off directories in * name of command in order * to conserve space in * namestripe */ mt_use_fields = (mt_value("disablefields") ? FALSE : TRUE); mt_always_use_popup = (mt_value("alwaysusepopup") ? TRUE : FALSE); mt_41_features = (mt_value("4.1features") ? TRUE : FALSE); if (!mt_41_features) mt_panel_style = mt_New; /* * only if 4.1features is TRUE can you experiment with * different panel styles */ else { if (!mt_value("panelstyle") || (strcmp(mt_value("panelstyle"), "New") == 0) ) mt_panel_style = mt_New; else if (strcmp(mt_value("panelstyle"), "Old") == 0) mt_panel_style = mt_Old; else if (strcmp(mt_value("panelstyle"), "ThreeDImages") == 0) { mt_panel_style = mt_3DImages; if (!mt_use_images) { fprintf(stderr,"*****3DImage panel style has been specified in user's defaults!\nMailtool must be compiled with -DUSE_IMAGES in order to use this feature!\nUsing default panel style instead.\n"); mt_panel_style = mt_New; } } else { fprintf(stderr, "unrecognized default setting for panelstyle: %s\n", mt_value("panelstyle")); mt_panel_style = mt_New; } } }/*** following implemented defaults options that controlled the behavior of the tool with respect to retrieving new mail. if (!mt_value("loadmessages")) mt_load_messages = mt_When_Opened; else if (strcmp(mt_value("loadmessages"), "Startup") == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -