src/bin/psql/command.c
printQueryOpt *
savePsetInfo(const printQueryOpt *popt)
{
	printQueryOpt *save;

	save = (printQueryOpt *) pg_malloc(sizeof(printQueryOpt));

	/* Flat-copy all the scalar fields, then duplicate sub-structures. */
	memcpy(save, popt, sizeof(printQueryOpt));

	/* topt.line_style points to const data that need not be duplicated */
	if (popt->topt.fieldSep.separator)
		save->topt.fieldSep.separator = pg_strdup(popt->topt.fieldSep.separator);
	if (popt->topt.recordSep.separator)
		save->topt.recordSep.separator = pg_strdup(popt->topt.recordSep.separator);
	if (popt->topt.tableAttr)
		save->topt.tableAttr = pg_strdup(popt->topt.tableAttr);
	if (popt->nullPrint)
		save->nullPrint = pg_strdup(popt->nullPrint);
	if (popt->title)
		save->title = pg_strdup(popt->title);

	/*
	 * footers and translate_columns are never set in psql's print settings,
	 * so we needn't write code to duplicate them.
	 */
	Assert(popt->footers == NULL);
	Assert(popt->translate_columns == NULL);

	return save;
}
/*
 * savePsetInfo: make a malloc'd copy of the data in *popt.
 *
 * Possibly this should be somewhere else, but it's a bit specific to psql.
 */
make a malloc'd copy of the data in *popt.
Possibly this should be somewhere else, but it's a bit specific to psql.
make a malloc ' d copy of the data in * popt . Possibly this should be somewhere else but it ' s a bit specific to psql .
printQueryOpt *
savePsetInfo(const printQueryOpt *popt)
{
	printQueryOpt *save;
	save = (printQueryOpt *) pg_malloc(sizeof(printQueryOpt));
	memcpy(save, popt, sizeof(printQueryOpt));
	if (popt->topt.fieldSep.separator)
		save->topt.fieldSep.separator = pg_strdup(popt->topt.fieldSep.separator);
	if (popt->topt.recordSep.separator)
		save->topt.recordSep.separator = pg_strdup(popt->topt.recordSep.separator);
	if (popt->topt.tableAttr)
		save->topt.tableAttr = pg_strdup(popt->topt.tableAttr);
	if (popt->nullPrint)
		save->nullPrint = pg_strdup(popt->nullPrint);
	if (popt->title)
		save->title = pg_strdup(popt->title);
	Assert(popt->footers == NULL);
	Assert(popt->translate_columns == NULL);
	return save;
}
printQueryOpt * savePsetInfo ( const printQueryOpt * popt ) { printQueryOpt * save ; save = ( printQueryOpt * ) pg_malloc ( sizeof ( printQueryOpt ) ) ; memcpy ( save , popt , sizeof ( printQueryOpt ) ) ; if ( popt -> topt . fieldSep . separator ) save -> topt . fieldSep . separator = pg_strdup ( popt -> topt . fieldSep . separator ) ; if ( popt -> topt . recordSep . separator ) save -> topt . recordSep . separator = pg_strdup ( popt -> topt . recordSep . separator ) ; if ( popt -> topt . tableAttr ) save -> topt . tableAttr = pg_strdup ( popt -> topt . tableAttr ) ; if ( popt -> nullPrint ) save -> nullPrint = pg_strdup ( popt -> nullPrint ) ; if ( popt -> title ) save -> title = pg_strdup ( popt -> title ) ; Assert ( popt -> footers == NULL ) ; Assert ( popt -> translate_columns == NULL ) ; return save ; }
savePsetInfo: make a malloc'd copy of the data in *popt.
savePsetInfo : make a malloc ' d copy of the data in * popt .
/* Flat-copy all the scalar fields, then duplicate sub-structures. */ /* topt.line_style points to const data that need not be duplicated */ /*
	 * footers and translate_columns are never set in psql's print settings,
	 * so we needn't write code to duplicate them.
	 */