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

📄 defaults_put.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
 * create.  If File_Name is NULL, env var DEFAULTS_FILE will be used. */voiddefaults_write_changed(file_name, status)	char	*file_name;	/* Output file name */	int	*status;	/* Status flag */{	node_write("/", file_name, status, 1);}/* * defaults_write_differences(file_name, status) will write out all of the * database entries that differ from the master database.  Out_File is the * string name of the file to create.  If File_Name is NULL, env var  * DEFAULTS_FILE be used. */voiddefaults_write_differences(file_name, status)	char	*file_name;	/* Output file name */	int	*status;	/* Status flag */{	node_write("/", file_name, status, 2);}/* * node_write(path_name, file_name, status, flag) will write Path_Name to * File_Name.  If File_Name is NULL, env var DEFAULTS_FILE will be used. */static voidnode_write(path_name, file_name, status, flag)	char		*path_name;	/* Path name */	char		*file_name;	/* File name */	int		*status;	/* Status flag */	int		flag;		/* Control flag */{	char		name[MAX_STRING]; /* Temporary name */	register Node	node;		/* Node to output */	register FILE	*out_file;	/* Output file */	char		*login_dir;	clear_status(status);	node = path_lookup(path_name, status);	if (node == NULL)		return;	if (file_name == NULL){		if ((file_name = getenv("DEFAULTS_FILE")) == NULL)  {			file_name = name;			if ((login_dir = getlogindir()) != NULL ) {				(void)strcpy(file_name, getlogindir());			}			(void)strcat(file_name, "/.defaults");		}   else   {			strcpy(name,file_name);			file_name = name;		}	}	out_file = fopen(file_name, "w");	if (out_file == NULL){		warn("Could not open %s", file_name);		return;	}	(void)fprintf(out_file, "%s %d\n", VERSION_TAG, VERSION_NUMBER);	node_write1(out_file, node, flag);	(void)fclose(out_file);}/* * node_write1(out_file, node, flag) will write out the contents of Node to * Out_File.  Flag is 0, if the entire database is to be written out. * Flag is 1 if only the changed entries are to be written out.  Flag is 2, * if only differences from the master database are to be written out. */static voidnode_write1(out_file, node, flag)	register FILE	*out_file;	/* Output file */	register Node	node;		/* Node to output */	register int	flag;		/* TRUE => entire database */{	char	temp[MAX_STRING];	/* Temporary name */	if (!node->deleted && ((flag == 0) || ((flag == 2) && node->private)	   	|| !symbol_equal(node->value, node->default_value)	   	|| always_save(node))	   	) {		(void)name_unparse(node->name, temp);		(void)fprintf(out_file, "%s", temp);		if (strcmp(node->value, DEFAULTS_UNDEFINED) != 0){			(void)fprintf(out_file, "\t");			str_write(out_file, node->value);		}		putc('\n', out_file);	}	for (node = node->child; node != NULL; node = node->next)		node_write1(out_file, node, flag);}static intalways_save(node)	register Node	node;	{	char	*buf[29];	/* buffer */	Symbol	*sym;	int	i;		if (node->name == NULL)		return (FALSE);	for (i = 0; node->name[i] != NULL; i++)		buf[i] = node->name[i];	/* copy name */	buf[i++] = symbol_lookup("$Always_Save");	buf[i] = NULL;	return (node_lookup_name(buf, False, (int *)NULL) != NULL);}/* * set(path_name, new_value) will set Full_Name to type * Node_Type with value New_Value. */static voidset(path_name, new_value, status)	char		*path_name;	/* Full node name */	char		*new_value;	/* New value */	int		*status;	/* Status flag */{	Symbol		name[MAX_NAME];	/* Name */	register Node	node;		/* Node to set */	if (defaults == NULL)		defaults_init(True);		/* Get the node assoicated with Full_Name. */	name_quick_parse(path_name, name);	node = node_find_name(name, True, status);	if (node == NULL){		warn("Can not bind node to '%s'", path_name);		return;	}	/* It is not worth the effort to try to deallocate any storage. */	node->value = new_value;	node->private = True;	node->deleted = False;}/* * defaults_special_mode() will cause the database to behave as if the entire * master database has been read into memory prior to reading in the private * database. This is done to insure that the order of nodes that defaultsedit * presents is the same as that in the .D files, regardless of what the user * happens to have set in his private database.  */voiddefaults_special_mode(){	char		*database_dir;	/* Database directory */	register Node	node;		/* Current node to process */	char		*private_dir;	/* Private directory */	/* Create database. */	defaults = NULL;	defaults_create();	/* Read in env var DEFAULTS_FILE to find out where database 	 *directories are. 	 */	read_private_database();	node = node_lookup_path("/Defaults/Directory", False, (int *)NULL);	database_dir = (node == NULL) ? NULL : slash_append(node->value);	node = node_lookup_path("/Defaults/Private_Directory", False, (int *)NULL);	private_dir = (node == NULL) ? NULL : slash_append(node->value);	/*	 * The previous five statements may be superfluous. It appears that	 * read_master_database does this itself. 	 */		/* Drop the entire private database on the floor! */	defaults = NULL;	defaults_create();	defaults->database_dir = database_dir;	defaults->private_dir = private_dir;	/* Read in master database before private database so that node order	 * is preserved in master database order rather than private order. */	read_master_database();	read_private_database();	for (node = defaults->root->child; node != NULL; node = node->next)		if (node->file)			read_master(node->name[0]);	defaults->test_mode =		defaults_get_boolean("/Defaults/Test_Mode", False, (int *)NULL);}/* * str_write(out_file, string) will write String to Out_File as a C-style * string. */static voidstr_write(out_file, string)	register FILE	*out_file;	/* Output file */	register char	*string;	/* String to output */{	register int	chr;		/* Temporary character */	putc('"', out_file);	while (True){		chr = *string++;		if (chr == '\0')			break;		if ((' ' <= chr) && (chr <= '~') &&		    (chr != '\\') && (chr != '"')){			putc(chr, out_file);			continue;		}		putc('\\', out_file);		switch (chr){		    case '\n':			chr = 'n';			break;		    case '\r':			chr = 'r';			break;		    case '\t':			chr = 't';			break;		    case '\b':			chr = 'b';			break;		    case '\\':			chr = '\\';			break;		    case '\f':			chr = 'f';			break;		    case '"':			chr = '"';			break;		}		if ((' ' <= chr) && (chr <= '~'))			putc(chr, out_file);		else	(void)fprintf(out_file, "%03o", chr & 0377);	}	putc('"', out_file);}/* * warn(format, arg1, arg2, arg3) will print out a warning message * to the console using Format, Arg1, Arg2 and Arg3.  This is all provided * the number of errors has not gotten too excessive. *//*VARARGS1*/voidwarn(format, arg1, arg2, arg3, arg4)	char	*format;/* Format string */	long	arg1;	/* First argument */	long	arg2;	/* Second argument */	long	arg3;	/* Third argument */	long	arg4;	/* Fourth argument */{        extern Defaults_pairs warn_error_action[];	register int	action;			/* Action number */	int		errors;			/* Number of errors */	int		max_errors;		/* Maximum errors */	register Node	node;			/* Error action node */	char 		temp[MAX_STRING];	/* Temporary string */	action = 1;	if (defaults == NULL)		errors = 0;	else {	errors = ++defaults->errors;		/* See how many errors to accept. */		(void)strcpy(temp, SEP_STR);		(void)strcat(temp, "Defaults");		(void)strcat(temp, SEP_STR);		(void)strcat(temp, "Maximum_Errors");		node = node_lookup_path(temp, True, (int *)NULL);		if (node == NULL)			max_errors = MAX_ERRORS;		else	max_errors = atoi(node->value);		if (defaults->errors == max_errors)			format = "Suppressing all subsequent errors";		/* See what to do on error action. */		(void)strcpy(temp, SEP_STR);		(void)strcat(temp, "Defaults");		(void)strcat(temp, SEP_STR);		(void)strcat(temp, "Error_Action");		node = node_lookup_path(temp, True, (int *)NULL);		if (node != NULL)			action = defaults_lookup(node->value, warn_error_action);	}	if ((errors <= max_errors) && (action < 3)){		(void)fprintf(stderr, "SunDefaults Error: ");		(void)fprintf(stderr, format, arg1, arg2, arg3, arg4);		(void)fprintf(stderr, "\n");		(void)fflush(stderr);	}	if (action == 2)		bomb();}/*****************************************************************//* Internal routines:                                            *//*****************************************************************//* * bomb() will cause the program to bomb. */static voidbomb(){	(void)fflush(stderr);	usleep(5 << 20);	/* Wait for error message to show up */	abort();}

⌨️ 快捷键说明

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