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

📄 defaultsedit.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifndef lint#ifdef sccsstatic  char sccsid[] = "@(#)defaultsedit.c 1.1 92/07/30 Copyr 1985 Sun Micro";#endif#endif/* *      Copyright (c) 1985 by Sun Microsystems Inc. *//* File:  defaultsedit.c *//* Master default directory:  /pe/usr/lib/defaults  *//* Source code in /pe/usr/src/sun/usr.bin/suntool/defaults  */#include <stdio.h>#include <strings.h>#include <sys/types.h>#include <sys/wait.h>#include <vfork.h>#include <sunwindow/sun.h>#include <sunwindow/defaults.h>#include <sunwindow/notify.h>#include <suntool/alert.h>#include <suntool/frame.h>#include <suntool/tool_hs.h>#include <suntool/panel.h>#include <suntool/scrollbar.h>#include <suntool/textsw.h>#include <suntool/walkmenu.h>static short defaults_ic_image[256]={#include <images/defaultsedit.icon>};DEFINE_ICON_FROM_IMAGE(defaults_icon, defaults_ic_image);static char	demo_msg[] ="Press the left mouse button to confirm starting  \the Demo/Setup program. (If you do confirm, all changes \done to default values will be saved before starting \the Demo program). \To cancel, press the right mouse button now.";static short    hg_data[] = {#include <images/hglass.cursor>};mpr_static(defed_hourglass_cursor_pr, 16, 16, 1, hg_data);struct cursor    defaultsedit_hourglass_cursor = 	{ 8, 8, PIX_SRC | PIX_DST, &defed_hourglass_cursor_pr };/* New defines: */#define	DE_TEXT_HEIGHT TOOL_SWEXTENDTOEDGE#define DE_DEFAULTS_COLUMNS 90	    /* The defaults programs width */#define DE_STANDARD_DISPLAYLEN 25	    /* Show at most 25 initial chars of					standard value */#define DE_MIN_VALUE_STOREDLEN 100	    /* Have minimum 100 chars string initial				length	allocated in panel text items */#define DE_NAME_ITEM_MAX_LENGTH 1500    /* Max initiallength of string values */#define DE_NAME_ITEM_DISPLAY_LENGTH 1500 /* Max displayed length of string values */#define DE_MAX_CHOICE_LENGTH 100	    /* Max length of choice in a choice item */#define DE_HELP_TEXT_ALLOC_LENGTH 191   /* Max help text length */				    /* Max str length of 80 takes 81 bytes  */#define DE_FULLNAME_MAX_LENGTH 90    /* Max fullname defaults node name length */#define DE_ITEM_MAX_LABEL_LENGTH   DE_NAME_ITEM_MAX_LENGTH+DE_FULLNAME_MAX_LENGTH#define DE_MAX_SCREENS		100     /* Max sum of length of standard defaults */   /* node values and full node names,  used to create labels of panel items*/#define	DE_ITEMLABELPOS 40	     /* minimum end position of labels in tree panel */	/* New data types and decls: */typedef enum {	Undefined,	/* May be used to mark special objects */	String,		/* Text node */	Enumerate,	/* Enumeration node */	Editstring,	/* Text node whose label has been edited by user */	Editenumerate, 	/* Enumeration node whose label has been edited */	Helpstring,	/* Marks the help string object in the help panel */	Message,	/* Message object for header text to be displayed */} Defaulttype;typedef struct _defobj* Defobj;struct _defobj{	Defaulttype	nodetype;   /* String, enumeration or Labeledit node */	char*		nodename;   /* Full defaults name of node */	Panel_item	ilabel;	    /* tree panel item for Label */	Panel_item	ivalue;	    /* tree panel item containing value */	Panel_item	ifill1;	    /* fill text  - type Enumerate */	Defobj		nodenext;	Bool		specifichelp;	/* This field is set to true for				an enumeration defobject if the last				displayed help was enumeration value				specific. */};typedef struct rect*	Recttype;static struct tool *tool;	/* Tool to use */static Panel menupanel;		/* Panel containing choice items */static Panel treepanel;		/* Panel of nodenames */static Panel helppanel;static Textsw textwindow;	/* Text subwindow for editing */static Defobj last_clicked_defobj; /* Used for indicating last object					    clicked with left mouse button */static	Defobj	firstdefobj;	/* NULL or ptr to first tree panel default				 object */static	Defobj	lastinserteddefobj;	/* NULL or ptr to last tree panel				  default object */static char	*prog_names[DE_MAX_SCREENS];static int	cur_progvalue;		/* Item for currently selected program */static Panel_item helpdisplayitem;	/* Item for displaying help text in help window */static int	cur_ylinenr;	/* current line nr in treepanel. 1st line is nr 0 */static char nohelpavail[] = "No help available";static char **tool_attrs = NULL;    	/* May point to vector of tool					   attributes */static char *tool_name;/* Overview:<  The basic datastructure is a linked list of Defobj structs. Defobj  is short for defaults object, and can be displayed in the treepanel.  New defaults objects can be either inserted of deleted from this list.  A defobj is either a text object, to which you can type in textual values  or an enumeration, which is displayed as a panel choice item.     Often several panel-items are required to implement a single Defobj.  Recently created defaults objects (created by the insert button)  have their nodename field either NULL or "".  In this way they can  be distinguished from defaults objects which are created from and   corresponds to nodes in the defaults database ( a tree-structured database)*/  /*  * specformatnames is a list of namerecords of accessed subtrees in the * defaults database which have their own special file format, * like mail having a file .mailrc  etc. * If a subtree in the defaults database has a node called *  $Specialformat_to_defaults, * then the value of this node is the * name of a conversion program which will be invoked before reading in * the defaults database subtree. * In the mail case, this conversion program would convert the appropriate * part of .mailrc and write it out into an appropriate portion of the * .defaults file.  The name of this subtree would be saved in a namerec * record in the NULL-terminated list specformatnames. * If defaultsedit fails to invoke the conversion program an error message * will be printed. * * After saving the defaults database, defaultsedit will try to invoke * another set of conversion programs to convert from the .defaults file * format to specially formated files like .mailrc * Such a conversion program will be invoked for each subtree which name * is on the namerec in the list specformatnames and the changed field * of the namerec is True,  indicating that the user has made edits * that changed some defaults database values * For each subtree, the name of the conversion program will be found * in the node: *  $Defaults_to_specialformat * defaultsedit will print an error message if it fails invoking the  * conversion program.  */#ifdef DEBUG#define Debug(x) x#else#define Debug(x)#endiftypedef struct {    char*	name;		/*  The name of a program with conversion */    Bool	changed;	/*  True if user edited defaults values  */} namerec;static namerec*  specformatnames[200];		/*  New function forward decls: */static void sigwinched();static void deferror();static void init_items();static char* get_cur_progname();static int menu_swinit();static int prog_swinit();static int tree_swinit();static int help_swinit();static int text_swinit();static void prog_notifyproc();static void menu_save_notifyproc();static void menu_quit_notifyproc();static void menu_reset_notifyproc();static void menu_labeledit_notifyproc();static void menu_insert_notifyproc();static void menu_delete_notifyproc();static void edit_menuproc();static Bool nothing_dirty();static void tree_runsetup_notifyproc(); 	/* (item, value, event)  */static void tree_text_eventproc();static void tree_choice_notifyproc();static void help_text_eventproc();		/* (item, event) */static void subtree_show();static void subtree_showitems();static void subtree_clearitems();static Bool subtree_extractinfo();		/* ret. T if any item changed */static char* get_enum_member_string();static void showitem();static void showhelpitem();static int get_enum_member();static Notify_value demo_child_wait3();static void show_message();		/* (nodename, labelname, valuestr) */static void run_setup_prog();static char* get_standard_valuestr(); 	/* (nodename, standardval) */static Defobj create_defobj();static Defobj create_message_defobj();static Defobj create_text_defobj();static Defobj create_enum_defobj();static void freemem_defobj();static Bool check_clicked_defobj();static char* getnodename_defobj(); 	/* (defobjptr) */static Bool deflt_helpdefined();	/* (full_name) */static Bool deflt_always_save();	/* (full_name) */static void deflt_get_help();		/* (full_name, defaulthelp, helpstr) */static void deflt_get_fullchild();	/* */static void deflt_get_fullsibling();	/* */static char* getchars();		/* (nchars) */static Defaulttype get_nodetype();	/* (fullname) */static char* get_memory();		/* (size) */static void bomb();			/* */static Bool displayable_node();	/* (nodename) */static Bool specialformat_to_defaults(); /* (subtreename) */static void dump_default_trees();static int start_child_proc();		/* (childforkname, waitflg) */static void wait_child_finish();	/* (childpid) */static int member_pos();		/* (name, namelist) */static void insert_new_member();	/* (name, namelist) */static Bool start_possible_demos();	/* (nargs, namevec) */static void defaults_str_unparse();	/* (instring, outstring) */static char* convert_string();static int convert_backslash_chr();	/* (instrptr, outstrptr) */static void tree_scrollup();static void subtree_copy();/* * Generate a fault in order to get a core dump. * Use division by zero to generate a fault */static voidstop(){	int i;	i = 0;	i = 1/i;}/* New function decls and bodies: */void#ifdef STANDALONEmain(argc, argv)#elsedefaultsedit_main(argc, argv)#endif int argc; char* argv[];{	int	toolheight;	int	menuheight;	int	helpheight;	int	textheight;	char	*tool_get_attribute();	defaults_special_mode();    /* Special mode to read master defaults					database first to preserve order					between nodes. */	specformatnames[0] = (namerec *)NULL;	argc--;	tool_name = *argv++;	/*	 * Pick up command line arguments to modify tool behavior	 */	if (tool_parse_all(&argc, argv, &tool_attrs, tool_name) == -1) {	    /* Failed to parse it,  do nothing  */	} else {	    if (start_possible_demos(argc, argv))		 return;	}	tool = tool_begin(	WIN_LABEL,		"defaultsedit",	WIN_ICON,		&defaults_icon,	WIN_COLUMNS,		DE_DEFAULTS_COLUMNS, 	WIN_BOUNDARY_MGR, 	True,        WIN_ATTR_LIST,		tool_attrs,	0);	if (tool==NULL) deferror("Can't make tool", True);	toolheight=(int) tool_get_attribute(tool, (int)WIN_HEIGHT);	menuheight=menu_swinit();	/* Create menu panel subwindow */	helpheight=help_swinit();	/* Create help text subwindow */	textheight=helpheight*2;	(void)tree_swinit(toolheight-menuheight-helpheight-textheight);	    	/* Create tree display panel subwindow */	(void)text_swinit(DE_TEXT_HEIGHT);	(void)tool_install(tool);	(void)notify_start();	exit(0);}/* * Fork off special setup programs if defaults is invoked with an argument. * If defaults is invoked with an argument:    defaults  -DScrollbar * then the scrollbar setup will be started immediately from the defaults * tool, if the node /Scrollbar/$Setup_program has a startable program name * as its value. */static Boolstart_possible_demos(nargs, namevec)    int	    nargs;    char*   namevec[];{    int	    nr;    char    accessname[DE_FULLNAME_MAX_LENGTH];    char    progname[DE_FULLNAME_MAX_LENGTH];    char    message[150];    Bool    startedflg;    if (nargs<=0) return False;    startedflg = False;    for (nr=0; nr<nargs; nr++) {	if(! (namevec[nr][0]=='-' && namevec[nr][1]=='D') ) continue;	(void)strcpy(accessname, "/");	(void)strcat(accessname, namevec[nr]+2);	(void)strcat(accessname, "/$Setup_program");	if ( defaults_exists(accessname, (int *)NULL) 	     && !strequal(defaults_get_string(accessname, "", (int *)NULL), "") )	    {	    (void)strcpy(progname, defaults_get_string(accessname, "", (int *)NULL));	    (void)start_child_proc(progname, False, True, (union wait *)NULL);	    startedflg = True;	}	else {	    (void)strcpy(message, "No specialized defaults program name exists for node with spelling: ");    	    deferror(strcat(message, accessname), False);	    continue;	}    }	    return startedflg;}/* * Initialize panel items for menu panel subwindow. * This menu currently contains 3 buttons: * Save - will save the user-changed defaults in the .defaults file * Quit - will quit the program * Reset - will reset the current panel to its state when it was opened */static intmenu_swinit(){	menupanel = panel_begin(tool, 0);	if (menupanel == NULL) deferror("Can't create menu panel",  True);	prog_swinit();	(void)panel_create_item(menupanel, PANEL_BUTTON,	    PANEL_LABEL_IMAGE,	    panel_button_image(menupanel,"Save",0,(Pixfont *)NULL),	    PANEL_NOTIFY_PROC,  menu_save_notifyproc,	    0);	(void)panel_create_item(menupanel, PANEL_BUTTON,	    PANEL_LABEL_IMAGE,	    panel_button_image(menupanel,"Quit",0,(Pixfont *)NULL),	    PANEL_NOTIFY_PROC,  menu_quit_notifyproc,	    0);	(void)panel_create_item(menupanel, PANEL_BUTTON,	    PANEL_LABEL_IMAGE,	    panel_button_image(menupanel,"Reset",0,(Pixfont *)NULL),	    PANEL_NOTIFY_PROC,  menu_reset_notifyproc,	    0);	(void)panel_create_item(menupanel, PANEL_MESSAGE,	    PANEL_LABEL_IMAGE, 	    panel_button_image(menupanel,"Edit Item",0,(Pixfont *)NULL),	    PANEL_LABEL_X, ATTR_COL(70),	    	    PANEL_EVENT_PROC, edit_menuproc,	    0);	(void)panel_set(menupanel, PANEL_HEIGHT, PANEL_FIT_ITEMS, 0);	return (int)panel_get(menupanel, PANEL_HEIGHT);}/* * Event proc for the "Edit Item" item in the menu panel. * Presents a menu of edit commands when the user right-buttons down. *//* ARGSUSED */static voidedit_menuproc(item, event)	Panel_item	item;	struct inputevent *event;{	static Menu menu;		/*	 * create the menu the first time through 	 */	if (menu == NULL)		    menu = menu_create(		MENU_ACTION_ITEM, "Copy Item", menu_insert_notifyproc,		MENU_ACTION_ITEM, "Delete Item",menu_delete_notifyproc,		MENU_ACTION_ITEM, "Edit Label",menu_labeledit_notifyproc,		0);	/*	 * translate event to panel space and show the menu 	 */	if (event_action(event) == MS_RIGHT && event_is_down(event)) 	    (void) menu_show_using_fd(menu, win_get_fd(menupanel),				panel_window_event(menupanel, event));

⌨️ 快捷键说明

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