src/bin/psql/command.c
int
process_file(char *filename, bool use_relative_path)
{
	FILE	   *fd;
	int			result;
	char	   *oldfilename;
	char		relpath[MAXPGPATH];

	if (!filename)
	{
		fd = stdin;
		filename = NULL;
	}
	else if (strcmp(filename, "-") != 0)
	{
		canonicalize_path(filename);

		/*
		 * If we were asked to resolve the pathname relative to the location
		 * of the currently executing script, and there is one, and this is a
		 * relative pathname, then prepend all but the last pathname component
		 * of the current script to this pathname.
		 */
		if (use_relative_path && pset.inputfile &&
			!is_absolute_path(filename) && !has_drive_prefix(filename))
		{
			strlcpy(relpath, pset.inputfile, sizeof(relpath));
			get_parent_directory(relpath);
			join_path_components(relpath, relpath, filename);
			canonicalize_path(relpath);

			filename = relpath;
		}

		fd = fopen(filename, PG_BINARY_R);

		if (!fd)
		{
			pg_log_error("%s: %m", filename);
			return EXIT_FAILURE;
		}
	}
	else
	{
		fd = stdin;
		filename = "<stdin>";	/* for future error messages */
	}

	oldfilename = pset.inputfile;
	pset.inputfile = filename;

	pg_logging_config(pset.inputfile ? 0 : PG_LOG_FLAG_TERSE);

	result = MainLoop(fd);

	if (fd != stdin)
		fclose(fd);

	pset.inputfile = oldfilename;

	pg_logging_config(pset.inputfile ? 0 : PG_LOG_FLAG_TERSE);

	return result;
}
/*
 * process_file
 *
 * Reads commands from filename and passes them to the main processing loop.
 * Handler for \i and \ir, but can be used for other things as well.  Returns
 * MainLoop() error code.
 *
 * If use_relative_path is true and filename is not an absolute path, then open
 * the file from where the currently processed file (if any) is located.
 */
process_file
Reads commands from filename and passes them to the main processing loop.
Handler for \i and \ir, but can be used for other things as well.  Returns
MainLoop() error code.

If use_relative_path is true and filename is not an absolute path, then open
the file from where the currently processed file (if any) is located.
process_file Reads commands from filename and passes them to the main processing loop . Handler for \ i and \ ir but can be used for other things as well . Returns MainLoop () error code . If use_relative_path is true and filename is not an absolute path then open the file from where the currently processed file ( if any ) is located .
int
process_file(char *filename, bool use_relative_path)
{
	FILE	   *fd;
	int			result;
	char	   *oldfilename;
	char		relpath[MAXPGPATH];
	if (!filename)
	{
		fd = stdin;
		filename = NULL;
	}
	else if (strcmp(filename, "-") != 0)
	{
		canonicalize_path(filename);
		if (use_relative_path && pset.inputfile &&
			!is_absolute_path(filename) && !has_drive_prefix(filename))
		{
			strlcpy(relpath, pset.inputfile, sizeof(relpath));
			get_parent_directory(relpath);
			join_path_components(relpath, relpath, filename);
			canonicalize_path(relpath);
			filename = relpath;
		}
		fd = fopen(filename, PG_BINARY_R);
		if (!fd)
		{
			pg_log_error("%s: %m", filename);
			return EXIT_FAILURE;
		}
	}
	else
	{
		fd = stdin;
		filename = "<stdin>";	
	}
	oldfilename = pset.inputfile;
	pset.inputfile = filename;
	pg_logging_config(pset.inputfile ? 0 : PG_LOG_FLAG_TERSE);
	result = MainLoop(fd);
	if (fd != stdin)
		fclose(fd);
	pset.inputfile = oldfilename;
	pg_logging_config(pset.inputfile ? 0 : PG_LOG_FLAG_TERSE);
	return result;
}
int process_file ( char * filename , bool use_relative_path ) { FILE * fd ; int result ; char * oldfilename ; char relpath [ MAXPGPATH ] ; if ( ! filename ) { fd = stdin ; filename = NULL ; } else if ( strcmp ( filename , " " ) != 0 ) { canonicalize_path ( filename ) ; if ( use_relative_path && pset . inputfile && ! is_absolute_path ( filename ) && ! has_drive_prefix ( filename ) ) { strlcpy ( relpath , pset . inputfile , sizeof ( relpath ) ) ; get_parent_directory ( relpath ) ; join_path_components ( relpath , relpath , filename ) ; canonicalize_path ( relpath ) ; filename = relpath ; } fd = fopen ( filename , PG_BINARY_R ) ; if ( ! fd ) { pg_log_error ( " " , filename ) ; return EXIT_FAILURE ; } } else { fd = stdin ; filename = " " ; } oldfilename = pset . inputfile ; pset . inputfile = filename ; pg_logging_config ( pset . inputfile ? 0 : PG_LOG_FLAG_TERSE ) ; result = MainLoop ( fd ) ; if ( fd != stdin ) fclose ( fd ) ; pset . inputfile = oldfilename ; pg_logging_config ( pset . inputfile ? 0 : PG_LOG_FLAG_TERSE ) ; return result ; }
process_file
 Reads commands from filename and passes them to the main processing loop.
process_file Reads commands from filename and passes them to the main processing loop .
/*
		 * If we were asked to resolve the pathname relative to the location
		 * of the currently executing script, and there is one, and this is a
		 * relative pathname, then prepend all but the last pathname component
		 * of the current script to this pathname.
		 */ /* for future error messages */