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

📄 defaultsedit.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * Create a default panel object of type Enumerate, which represents a defaults * database enumeration node and subtree. */static Defobjcreate_enum_defobj(labelname, nodenamei, ycoord, labeleditflg)	char*	labelname;	/* Label of panel item */	char*	nodenamei;	/* Full defaults database path name */	int	ycoord;		/* Panel item y coordinate */	Bool	labeleditflg;	/* True if label should be editable */{	char*	choicearr[ATTR_STANDARD_SIZE];	/* array of pointers to strings */	int	childcount;		/* number of pointers in choicearr */	char	childname[DE_FULLNAME_MAX_LENGTH];	/* Full name of Enumerate child node */	char	accessname[DE_FULLNAME_MAX_LENGTH];  /* Enumerate node */	int	accesslen;	/* Length of enumerate node name */	char	labelstr[DE_ITEM_MAX_LABEL_LENGTH];	int	valuepos;	Defobj	defobjptr;	char*	nodename;	char	standardchoice[DE_MAX_CHOICE_LENGTH];	if (labeleditflg) {	    defobjptr = create_defobj(nodenamei, Editenumerate);	    defobjptr->ilabel=panel_create_item(treepanel, PANEL_TEXT,		PANEL_ITEM_X, PANEL_CU(0),		PANEL_ITEM_Y, ycoord,		PANEL_VALUE_DISPLAY_LENGTH, DE_STANDARD_DISPLAYLEN, 		PANEL_VALUE_STORED_LENGTH, DE_FULLNAME_MAX_LENGTH, 		PANEL_VALUE, labelname, 		PANEL_NOTIFY_PROC, tree_choice_notifyproc,		PANEL_CLIENT_DATA, defobjptr, 		 0);	}	else {	    defobjptr = create_defobj(nodenamei, Enumerate);	    defobjptr->ilabel=panel_create_item(treepanel, PANEL_MESSAGE,		PANEL_ITEM_X, PANEL_CU(0),		PANEL_ITEM_Y, ycoord,		PANEL_LABEL_STRING,	labelname,		PANEL_LABEL_BOLD,	True,		PANEL_EVENT_PROC, tree_text_eventproc,		PANEL_CLIENT_DATA, defobjptr, 		 0);	}	nodename = defobjptr->nodename;	(void)strcpy(accessname,nodename);	accesslen = strlen(accessname);	choicearr[0] = (char *) PANEL_CHOICE_STRINGS;	deflt_get_fullchild(accessname, childname);	childcount = 0;	while (	! ((childname == NULL) || (strequal(childname, "") ) ) ) {	    if (childname[accesslen+1] != '$') {		if (childcount>=ATTR_STANDARD_SIZE) {			deferror("Too many enum strings\n", False); }		childcount = childcount+1;		choicearr[childcount] = strcpy(getchars(strlen(childname+accesslen+1)), childname+accesslen+1);	    }	    deflt_get_fullsibling(accessname, childname, childname);	}	if (childcount ==0) {		deferror(strcat(accessname, " has no enumeration members."), False);		childcount = 1;		choicearr[childcount] = " ";		}	choicearr[childcount+1] = 0;	/* 0 terminate string list */	choicearr[childcount+2] = 0;	/* 0 terminate argument list */	(void)get_standard_valuestr(nodename, standardchoice);	if (strequal(standardchoice, DEFAULTS_UNDEFINED)) {	    (void)strcpy(labelstr, "  :");	} else {	    (void)strcpy(labelstr, "(");	    (void)strcat(labelstr, standardchoice);	    (void)strcat(labelstr, "):");	}		valuepos = strlen(labelname)+strlen(labelstr)+1;	valuepos = MAX(DE_ITEMLABELPOS, valuepos);	defobjptr->ifill1 = panel_create_item(treepanel, PANEL_MESSAGE, 		PANEL_ITEM_X,		PANEL_CU(valuepos-strlen(labelstr)),		PANEL_ITEM_Y, ycoord,		PANEL_LABEL_STRING, labelstr,		PANEL_EVENT_PROC, tree_text_eventproc,		PANEL_CLIENT_DATA, defobjptr, 		 0); 	defobjptr->ivalue = panel_create_item(treepanel, PANEL_CYCLE,		PANEL_ITEM_Y, ycoord,		PANEL_CHOICE_YS, ycoord, 0,		PANEL_ATTRIBUTE_LIST, choicearr,		PANEL_VALUE,  get_seq_enum_nr(nodename),		PANEL_CLIENT_DATA, defobjptr, 		PANEL_NOTIFY_PROC, tree_choice_notifyproc,		0);	return defobjptr;}/* * defaults_str_unparse(outstring, instring) will convert instring to outstring *  as a C-style string. *  Result will be stored in outstring. *  The conversion is primarily there to convert strings containing *  control characters to textual strings like "\008" */#define STRCPYPLUS(s, t) \	(void)strcpy((s), (t)); \	(s) += strlen((t));	static voiddefaults_str_unparse(instring, outstring)	register char*	instring;	/* Input string */	register char*	outstring;	/* Converted output string */{	register int	chr;		/* Temporary character */	while (True){		chr = *instring++;		if (chr == '\0')			break;		if ((' ' <= chr) && (chr <= '~')){			*outstring++ = chr;			continue;		}		*outstring++ = '\\';				switch (chr){		    case '\n':			*outstring++ = 'n';			break;		    case '\r':			*outstring++ = 'r';			break;		    case '\t':			*outstring++ = 't';			break;		    case '\b':			*outstring++ = 'b';			break;		    case '\\':			*outstring++ = '\\';			break;		    case '\f':			*outstring++ = 'f';			break;		    case '\"':			*outstring++ = '"';			break;		    default:		        if ('\000'<=chr && chr<' ') {                            *outstring++ = '^';                            *outstring++ = chr+'@';                        } else {                            (void)sprintf(outstring, "%03o", chr & 0377);		            outstring = outstring+3;	                }		}	}	*outstring++ = '\0';}/* * Return True if help is defined for node full_name, otherwise False */static Booldeflt_helpdefined(full_name)	char*	full_name;{	char	accessname[DE_FULLNAME_MAX_LENGTH];	(void)strcpy(accessname, full_name);	(void)strcat(accessname, "/$Help");	return defaults_exists(accessname, (int *)NULL);}/* * Return True if the value for this item should always be written out * regardless of whether or not it differs from the default value, otherwise * False  */static Booldeflt_always_save(full_name)	char*	full_name;{	char	accessname[DE_FULLNAME_MAX_LENGTH];	(void)strcpy(accessname, full_name);	(void)strcat(accessname, "/$Always_Save");	/* return defaults_exists(accessname, (int *)NULL); */	if (defaults_exists(accessname, (int *)NULL))		return(True);	else		return(False);}/*  * Return string of help info if it is defined for full_name,  otherwise * return defaulthelp stored in helpstr. * The helpstring is stored into memory pointed to by helpstr */static voiddeflt_get_help(full_name, defaulthelp,  helpstr)	char*	full_name;	char*	defaulthelp;	char* 	helpstr;{	char	accessname[DE_FULLNAME_MAX_LENGTH];	(void)strcpy(accessname, full_name);	(void)strcat(accessname, "/$Help");	(void)strcpy(helpstr,  defaults_get_string(accessname, defaulthelp, (int *)NULL));	return;}/* * Show help text if any, associated with clickeditem. * If there is no help string associated with the node * look for a help string on its parent node and so on up to the highest level. * If no help was found,  return the string "No help available" * If enumspecifichelp is True, first look for specialized help attached * to the specific enumeration value. */static voidshowhelpitem(defobjptr, helpeditflg)	Defobj	defobjptr;	Bool	helpeditflg;{	char*	nodename;	char	accessname[DE_FULLNAME_MAX_LENGTH];	char	accessnameleaf[DE_FULLNAME_MAX_LENGTH];	char	helpstr[DE_HELP_TEXT_ALLOC_LENGTH*2];	int	nch;	if (defobjptr == NULL) return;	nodename = getnodename_defobj(defobjptr);	if (nodename == NULL) {		deferror("Nodename = NULL in showhelpitem", True); return; }	(void)strcpy(accessname, nodename);	if ((defobjptr->nodetype == Enumerate ||	     defobjptr->nodetype == Editenumerate) &&	     (defobjptr->specifichelp || !deflt_helpdefined(accessname))	    )	    { 		(void)strcat(accessname, "/");		(void)get_enum_member_string(nodename, (int)(LINT_CAST(panel_get_value(defobjptr->ivalue))),		    accessname+strlen(accessname));	    }	(void)strcpy(accessnameleaf, accessname);	if (helpeditflg) {	    if (deflt_helpdefined(accessname)) {		deflt_get_help(accessname, "", helpstr);	    } else {		(void)strcpy(helpstr, "");	    }	    goto showhelp;	}	    	(void)strcat(accessname, "/");	for (nch=strlen(accessname)-1; nch>0; nch--) {	    if (accessname[nch]=='/') {		accessname[nch]=0;		if (deflt_helpdefined(accessname)) {			deflt_get_help(accessname, nohelpavail, helpstr);			goto showhelp;		}	    }	};	(void)strcpy(helpstr, nohelpavail);	(void)strcpy(accessname, accessnameleaf);showhelp: show_message(accessname, accessname, helpstr);	}/* * Display a message, usually a help message, in the help window. * The labelname is displayed on the first line and the valuestr * is displayed on the second line. * The nodename is the name of the node where the help text is stored. * If the message is not a help text, then the nodename argument * should be NULL. * A sideeffekt: if nodename in defobj descriptor is not "", then * we assume that the user has previously shown a helpstring which might * have been modified, so we store it in the database. */static voidshow_message(nodename, labelname, valuestr)	char*	nodename;	char*	labelname;	char*	valuestr;{	Defobj	defobjptr;	char	valuestr2[DE_HELP_TEXT_ALLOC_LENGTH];	defobjptr = (Defobj)(LINT_CAST(panel_get(helpdisplayitem, PANEL_CLIENT_DATA)));	/* If previously shown item was a help string, then it might have been	   modified and you may want to save it back into the database *//**** Commented out in order to not allow edits to help strings in defaultsedit	if ( !(    defobjptr->nodename==NULL  		|| strequal(defobjptr->nodename,"")		|| strequal(curvalstr, nohelpavail) )  ) {	    (void)strcpy(helplabel, defobjptr->nodename);	    (void)convert_string(curvalstr, valuestr2);	    (void)strcat(helplabel, "/$Help");	    if (strequal(curvalstr, "") && defaults_exists(helplabel, (int *)NULL)) {		defaults_remove(helplabel, (int *)NULL);	    } else {	    defaults_set_string(helplabel, valuestr2, (int *)NULL);	    (void)strcpy(defobjptr->nodename, "");	    }	}****/	if (nodename != NULL) { (void)strcpy(defobjptr->nodename, nodename);	} else { (void)strcpy(defobjptr->nodename, ""); }	if (strlen(valuestr)>DE_HELP_TEXT_ALLOC_LENGTH-1) {            deferror("Too long helpstring", False);            (void)strcpy(valuestr2, "");            }        else defaults_str_unparse(valuestr, valuestr2);        (void)panel_set(helpdisplayitem, 		PANEL_LABEL_STRING,	labelname,		PANEL_VALUE,		valuestr2,		 0);}/*  * Return sequence number of current enum value, * where first enum always has enumeration value zero */static intget_seq_enum_nr(full_name)	char*	full_name;{	char	accessname[DE_FULLNAME_MAX_LENGTH];	char	childname[DE_FULLNAME_MAX_LENGTH];	char	enumvalue[DE_NAME_ITEM_MAX_LENGTH];	int	accesslen;	int	childcount;		(void)strcpy(enumvalue, defaults_get_string(full_name, "", (int *)NULL));	(void)strcpy(accessname,full_name);	accesslen = strlen(accessname)+1; 	deflt_get_fullchild(accessname, childname);	childcount = 0;	while (childcount<1000 && !strequal(childname, "") && !strequal(childname+accesslen, enumvalue))  {		if (childname[accesslen] != '$') childcount = childcount+1;		deflt_get_fullsibling(accessname, childname, childname);	}	if (childcount>=1000) (void)fprintf(stderr, "Defaultsedit: Missing enumeration value for: %s \n", full_name);	return childcount;}/* * Returns string name of emumeration item nr enumnr with nr zero first. * full_name is the name of the father node of the enumeration items. * Store the enumeration value string in straddress */static char*get_enum_member_string(full_name, enumnr, straddress)	char*	full_name;	int	enumnr;	char*	straddress;		{	char	childname[DE_FULLNAME_MAX_LENGTH];	int	childcount;	int	fullnamelen;	 	deflt_get_fullchild(full_name, childname);	childcount = -1;	fullnamelen = strlen(full_name)+1;	while (	! ((childname == NULL) || (strequal(childname, "") ) ) ) {		if (childname[fullnamelen] != '$')		     childcount = childcount+1;		if (childcount==enumnr) break;		deflt_get_fullsibling(full_name, childname, childname);	}	if (straddress == NULL) { 		straddress = getchars(strlen(childname)-fullnamelen);		}	(void)strcpy(straddress, childname+fullnamelen);	return straddress;}/* * Return the full pathname of the sibling of the node with name fullname. * If node does not exist then return "". * Store the full pathname into result. */static voiddeflt_get_fullsibling(parent, fullname, result)    char* parent;    char* fullname;    char* result;{    int	    parentlen;    char*   child;    if (strequal(fullname, "")) {	deferror("Defaultsedit: null child name in deflt_get_fullsibling", False);	stop();    }    child = defaults_get_sibling(fullname, (int *)NULL);    if (! strequal(parent, "/") ) parentlen = strlen(parent);     else parentlen=0;    if (child==NULL) {	(void)strcpy(result, "");  return;	}    if (fullname != result) (void)strcpy(result, fullname);    (void)strcpy(result+parentlen+1,  child);    return;}/* * Set fullname to the full pathname of the first child to parent if it exists. * The pathname is returned in fullname if it ex

⌨️ 快捷键说明

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