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

📄 defaults_put.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lint#ifdef sccsstatic  char sccsid[] = "@(#)defaults_put.c 1.1 92/07/30";#endif#endif/* * Copyright (c) 1985, 1988 by Sun Microsystems, Inc. */ #include <stdio.h>		/* Standard I/O library */#include <pwd.h>		/* Password file stuff */#include <sys/types.h>		/* Get u_long defined for dir.h */#include <sys/dir.h>		/* Directory access routines */#include <sys/stat.h>		/* File status information */#include <sunwindow/sun.h>	/* Define True, False, etc... */#include <sunwindow/hash.h>	/* Hash table definitions */#include <sunwindow/parse.h>	/* Parsing routine */#include <strings.h>#include <sunwindow/defaults.h>#include <sunwindow/defaults_impl.h>/* Externally used routines: */extern void	bomb();extern void	clear_status();extern void	defaults_create();extern char	*getlogindir();extern Name	name_copy();extern void	name_quick_parse();extern char	*name_unparse();extern void	node_delete();extern void	node_delete_private();extern Node	node_find_name();extern Node	node_lookup_name();extern Node	node_lookup_path();extern void	node_write();extern void	node_write1();extern Node	path_lookup();extern void	read_master();extern void	read_master_database();extern void	read_private_database();extern void	set();extern char	*slash_append();extern void	str_write();extern Symbol	symbol_copy();extern Bool	symbol_equal();extern Symbol	symbol_lookup();extern void	warn();extern char	*hash_get_memory();extern char	*getenv();extern Defaults defaults; /* * defaults_move(to_path_name, from_path_name, before_flag, status) will * rearrange the defaults database so that From_Path_Name will internally * be next to To_Path_Name.  If Before_Flag is True, a call to * defaults_get_sibling(To_Path_Name) will return From_Path_Name. * If Before_Flag is False, a call to defaults_get_child(From_Path_Name) * will return To_Path_Name. */voiddefaults_move(to_path_name, from_path_name, before_flag, status)	char		*to_path_name;		/* Destination path name */	char		*from_path_name;	/* Source path_name */	Bool		before_flag;		/* True => Insert before */	int		*status;		/* Status flag */{	Node		anchor;			/* Node behind last one */	Node		from_node;		/* From node */	Node		parent;			/* Parent node */	Node		temp;			/* Temporay node */	Node		to_node;		/* To node */	/* Check to be sure the nodes can be moved. */	clear_status(status);	from_node = node_lookup_path(from_path_name, False, status);	if (from_node == NULL)		return;	to_node = node_lookup_path(to_path_name, False, status);	if (to_node == NULL)		return;	if (from_node == to_node){		warn("%s and %s are the same node",			to_path_name, from_path_name);		return;	}	if (from_node->parent != to_node->parent){		warn("%s and %s are not siblings of one another",			to_path_name, from_path_name);		return;	}	parent = from_node->parent;	/* Remove from node from database tree. */	if (parent->child == from_node)		parent->child = from_node->next;	else {		temp = parent->child;		do {	anchor = temp;			temp = temp->next;		} while ((temp != NULL) && (temp != from_node));		if (temp == NULL){			warn("Data structure around %s and %s is messed up",				to_path_name, from_path_name);			return;		}		anchor->next = temp->next;	}	from_node->next = NULL;	/* Re-insert the node. */	if (!before_flag){		from_node->next = to_node->next;		to_node->next = from_node;		return;	}	if (parent->child == to_node)		parent->child = from_node;	else {		temp = parent->child;		do {	anchor = temp;			temp = temp->next;		} while ((temp != NULL) && (temp != to_node));		if (temp == NULL){			warn("Data structure around %s and %s is messed up",				to_path_name, from_path_name);			return;			}		anchor->next = from_node;	}	from_node->next = to_node;}/* * defaults_remove(path_name, status) will remove Path_Name and its children * from the defaults database. */voiddefaults_remove(path_name, status)	char		*path_name;	/* Full path name of node to remove */	int		*status;	/* Status flag */{	register Node	node;		/* Node to delete */	clear_status(status);	node = path_lookup(path_name, status);	if (node != NULL)		node_delete(node);}/* * defaults_remove_private(path_name, status) will remove Path_Name and its * children from the defaults database. */voiddefaults_remove_private(path_name, status)	char		*path_name;	/* Full path name of node to remove */	int		*status;	/* Status flag */{	register Node	node;		/* Node to delete */	clear_status(status);	node = path_lookup(path_name, status);	if (node != NULL)		node_delete_private(node);}/* * defaults_set_character(path_name, value, status) will set Path_name to * Value.  Value is a character. */voiddefaults_set_character(path_name, value, status)	char		*path_name;	/* Name to look up */	char		value;		/* Character to set */	int		*status;	/* Status flag */{	register char	*new_value;	/* New value */	clear_status(status);	new_value = hash_get_memory(2);	new_value[0] = value;	new_value[1] = '\0';	set(path_name, new_value, status);}/* * defaults_set_enumeration(path_name, value, status) will set Path_Name to * Value.  Value is a pointer to a string. */voiddefaults_set_enumeration(path_name, value, status)	char		*path_name;	/* Full node name */	char		*value;		/* Enumeration value */	int		*status;	/* Status flag */{	Symbol		name[MAX_NAME];	/* Temporary name */	register Symbol	*name_pointer;	/* Name pointer */	register Node	node;		/* Temporary Node */	register int	size;		/* Name size */ 	register Node	temp_node;	/* Temporary node */	clear_status(status);	name_pointer = name;	name_quick_parse(path_name, name_pointer);	node = node_find_name(name_pointer, True, status);	if (node == NULL){		warn("Can not insert '%s' into database", path_name);		return;	}	/* type check the enum if we've got the master database */	if (defaults->database_dir){		size = name_length(name_pointer);		/* is it an enum? */		name_pointer[size] = symbol_lookup("$Enumeration");		name_pointer[size + 1] = NULL;		temp_node = node_lookup_name(name_pointer, True, status);		if (temp_node == NULL){			warn("'%s' is not an enumeration node", path_name);			return;		}		/* is it a valid one? */		name_pointer[size] = symbol_lookup(value);		temp_node = node_lookup_name(name_pointer, True, status);		if (temp_node == NULL){			warn("%s can not have %s assigned as its value",							path_name, value);			return;		}	}	node->value = symbol_copy(value);	node->deleted = False;	node->private = True;}/* * defaults_set_integer(path_name, value, status) will set Path_Name to Value. * Value is an integer. */voiddefaults_set_integer(path_name, value, status)	char	*path_name;	/* Full node name */	int	value;		/* Integer value */	int	*status;	/* Status flag */{	char	temp_value[MAX_STRING];	/* Temporary string value */	clear_status(status);	(void)sprintf(temp_value, "%d", value);	set(path_name, symbol_copy(temp_value), status);}/* * defaults_set_prefix(prefix, status) will cause all subsequent node lookup * to first a node under Prefix first.  For example, if the prefix has been * set to "/Mumble/Frotz" and the user accesses "/Fee/Fie/Fo", first * "/Mumble/Frotz/Fee/Fie/Fo" will looked at and then if it is not available * "/Fee/Fie/Fo" will be looked at.  This is used to permit individual programs * to permit overriding of defaults.  If Prefix is NULL, the prefix will be * cleared. */voiddefaults_set_prefix(prefix, status)	register char	*prefix;	/* Prefix to use */	int		*status;	/* Status flag */{	Symbol		name[MAX_NAME];	/* Temporary name */	clear_status(status);	if (defaults == NULL)		defaults_init(True);	if (prefix == NULL){		defaults->prefix = NULL;		return;	}	name_quick_parse(prefix, name);	defaults->prefix = name_copy(name);	defaults->test_mode =		defaults_get_boolean("/Defaults/Test_Mode", False, (int *)NULL);}/* * defaults_set_string(path_name, value, status) will set Path_Name to Value. * Value is a poitner to a string. */voiddefaults_set_string(path_name, value, status)	char	*path_name;	/* Full node name */	char	*value;		/* New string value */	int	*status;	/* Status flag */{	set(path_name, symbol_copy(value), status);}/* * defaults_write_all(path_name, file_name, status) will write the all of the * database nodes from Path_Name and below into File_Name.  Out_File is the * string name of the file to create.  If File_Name is NULL, env var  * DEFAULTS_FILE will be used. */voiddefaults_write_all(path_name, file_name, status)	char	*path_name;	/* Path name */	char	*file_name;	/* Output file name */	int	*status;	/* Status flag */{	node_write(path_name, file_name, status, 0);}/* * defaults_write_changed(file_name, status) will write out all of the private * database entries to File_Name.  Any time a database node is set it becomes * part of the private database.  Out_File is the string  name of the file to

⌨️ 快捷键说明

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