@@ -69,6 +69,7 @@ static void minimal_error_message(PGresult *res);
6969
7070static void printSSLInfo (void );
7171static bool printPsetInfo (const char * param ,struct printQueryOpt * popt );
72+ static char * pset_value_string (const char * param ,struct printQueryOpt * popt );
7273
7374#ifdef WIN32
7475static void checkWin32Codepage (void );
@@ -1050,9 +1051,9 @@ exec_command(const char *cmd,
10501051
10511052int i ;
10521053static const char * const my_list []= {
1053- "border" ,"columns" ,"expanded" ,"fieldsep" ,
1054+ "border" ,"columns" ,"expanded" ,"fieldsep" ,"fieldsep_zero" ,
10541055"footer" ,"format" ,"linestyle" ,"null" ,
1055- "numericlocale" ,"pager" ,"recordsep" ,
1056+ "numericlocale" ,"pager" ,"recordsep" ,"recordsep_zero" ,
10561057"tableattr" ,"title" ,"tuples_only" ,
10571058"unicode_border_linestyle" ,
10581059"unicode_column_linestyle" ,
@@ -1061,7 +1062,11 @@ exec_command(const char *cmd,
10611062};
10621063
10631064for (i = 0 ;my_list [i ]!= NULL ;i ++ )
1064- printPsetInfo (my_list [i ],& pset .popt );
1065+ {
1066+ char * val = pset_value_string (my_list [i ],& pset .popt );
1067+ printf ("%-24s %s\n" ,my_list [i ],val );
1068+ free (val );
1069+ }
10651070
10661071success = true;
10671072}
@@ -2214,10 +2219,6 @@ process_file(char *filename, bool single_txn, bool use_relative_path)
22142219
22152220
22162221
2217- /*
2218- * do_pset
2219- *
2220- */
22212222static const char *
22222223_align2string (enum printFormat in )
22232224{
@@ -2287,6 +2288,10 @@ _unicode_linestyle2string(int linestyle)
22872288return "unknown" ;
22882289}
22892290
2291+ /*
2292+ * do_pset
2293+ *
2294+ */
22902295bool
22912296do_pset (const char * param ,const char * value ,printQueryOpt * popt ,bool quiet )
22922297{
@@ -2536,146 +2541,135 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
25362541
25372542/* show border style/width */
25382543if (strcmp (param ,"border" )== 0 )
2539- {
2540- if (!popt -> topt .border )
2541- printf (_ ("Border style (%s) unset.\n" ),param );
2542- else
2543- printf (_ ("Border style (%s) is %d.\n" ),param ,
2544- popt -> topt .border );
2545- }
2544+ printf (_ ("Border style is %d.\n" ),popt -> topt .border );
25462545
25472546/* show the target width for the wrapped format */
25482547else if (strcmp (param ,"columns" )== 0 )
25492548{
25502549if (!popt -> topt .columns )
2551- printf (_ ("Target width(%s) unset.\n" ), param );
2550+ printf (_ ("Target widthis unset.\n" ));
25522551else
2553- printf (_ ("Target width (%s) is %d.\n" ),param ,
2554- popt -> topt .columns );
2552+ printf (_ ("Target width is %d.\n" ),popt -> topt .columns );
25552553}
25562554
25572555/* show expanded/vertical mode */
25582556else if (strcmp (param ,"x" )== 0 || strcmp (param ,"expanded" )== 0 || strcmp (param ,"vertical" )== 0 )
25592557{
25602558if (popt -> topt .expanded == 1 )
2561- printf (_ ("Expanded display(%s) is on.\n" ), param );
2559+ printf (_ ("Expanded display is on.\n" ));
25622560else if (popt -> topt .expanded == 2 )
2563- printf (_ ("Expanded display(%s) is used automatically.\n" ), param );
2561+ printf (_ ("Expanded display is used automatically.\n" ));
25642562else
2565- printf (_ ("Expanded display(%s) is off.\n" ), param );
2563+ printf (_ ("Expanded display is off.\n" ));
25662564}
25672565
25682566/* show field separator for unaligned text */
25692567else if (strcmp (param ,"fieldsep" )== 0 )
25702568{
25712569if (popt -> topt .fieldSep .separator_zero )
2572- printf (_ ("Field separator(%s) is zero byte.\n" ), param );
2570+ printf (_ ("Field separator is zero byte.\n" ));
25732571else
2574- printf (_ ("Field separator(%s) is \"%s\".\n" ), param ,
2572+ printf (_ ("Field separator is \"%s\".\n" ),
25752573popt -> topt .fieldSep .separator );
25762574}
25772575
25782576else if (strcmp (param ,"fieldsep_zero" )== 0 )
25792577{
2580- printf (_ ("Field separator(%s) is zero byte.\n" ), param );
2578+ printf (_ ("Field separator is zero byte.\n" ));
25812579}
25822580
25832581/* show disable "(x rows)" footer */
25842582else if (strcmp (param ,"footer" )== 0 )
25852583{
25862584if (popt -> topt .default_footer )
2587- printf (_ ("Default footer(%s) is on.\n" ), param );
2585+ printf (_ ("Default footer is on.\n" ));
25882586else
2589- printf (_ ("Default footer(%s) is off.\n" ), param );
2587+ printf (_ ("Default footer is off.\n" ));
25902588}
25912589
25922590/* show format */
25932591else if (strcmp (param ,"format" )== 0 )
25942592{
2595- if (!popt -> topt .format )
2596- printf (_ ("Output format (%s) is aligned.\n" ),param );
2597- else
2598- printf (_ ("Output format (%s) is %s.\n" ),param ,
2599- _align2string (popt -> topt .format ));
2593+ printf (_ ("Output format is %s.\n" ),_align2string (popt -> topt .format ));
26002594}
26012595
26022596/* show table line style */
26032597else if (strcmp (param ,"linestyle" )== 0 )
26042598{
2605- printf (_ ("Line style(%s) is %s.\n" ), param ,
2599+ printf (_ ("Line style is %s.\n" ),
26062600get_line_style (& popt -> topt )-> name );
26072601}
26082602
26092603/* show null display */
26102604else if (strcmp (param ,"null" )== 0 )
26112605{
2612- printf (_ ("Null display(%s) is \"%s\".\n" ), param ,
2606+ printf (_ ("Null display is \"%s\".\n" ),
26132607popt -> nullPrint ?popt -> nullPrint :"" );
26142608}
26152609
26162610/* show locale-aware numeric output */
26172611else if (strcmp (param ,"numericlocale" )== 0 )
26182612{
26192613if (popt -> topt .numericLocale )
2620- printf (_ ("Locale-adjusted numeric output(%s) is on.\n" ), param );
2614+ printf (_ ("Locale-adjusted numeric output is on.\n" ));
26212615else
2622- printf (_ ("Locale-adjusted numeric output(%s) is off.\n" ), param );
2616+ printf (_ ("Locale-adjusted numeric output is off.\n" ));
26232617}
26242618
26252619/* show toggle use of pager */
26262620else if (strcmp (param ,"pager" )== 0 )
26272621{
26282622if (popt -> topt .pager == 1 )
2629- printf (_ ("Pager(%s) is used for long output.\n" ), param );
2623+ printf (_ ("Pager is used for long output.\n" ));
26302624else if (popt -> topt .pager == 2 )
2631- printf (_ ("Pager(%s) is always used.\n" ), param );
2625+ printf (_ ("Pager is always used.\n" ));
26322626else
2633- printf (_ ("Pager usage(%s) is off.\n" ), param );
2627+ printf (_ ("Pager usage is off.\n" ));
26342628}
26352629
26362630/* show record separator for unaligned text */
26372631else if (strcmp (param ,"recordsep" )== 0 )
26382632{
26392633if (popt -> topt .recordSep .separator_zero )
2640- printf (_ ("Record separator(%s) is zero byte.\n" ), param );
2634+ printf (_ ("Record separator is zero byte.\n" ));
26412635else if (strcmp (popt -> topt .recordSep .separator ,"\n" )== 0 )
2642- printf (_ ("Record separator(%s) is <newline>.\n" ), param );
2636+ printf (_ ("Record separator is <newline>.\n" ));
26432637else
2644- printf (_ ("Record separator(%s) is \"%s\".\n" ), param ,
2638+ printf (_ ("Record separator is \"%s\".\n" ),
26452639popt -> topt .recordSep .separator );
26462640}
26472641
26482642else if (strcmp (param ,"recordsep_zero" )== 0 )
26492643{
2650- printf (_ ("Record separator(%s) is zero byte.\n" ), param );
2644+ printf (_ ("Record separator is zero byte.\n" ));
26512645}
26522646
26532647/* show HTML table tag options */
26542648else if (strcmp (param ,"T" )== 0 || strcmp (param ,"tableattr" )== 0 )
26552649{
26562650if (popt -> topt .tableAttr )
2657- printf (_ ("Table attributes(%s) are \"%s\".\n" ), param ,
2651+ printf (_ ("Table attributes are \"%s\".\n" ),
26582652popt -> topt .tableAttr );
26592653else
2660- printf (_ ("Table attributes(%s) unset.\n" ), param );
2654+ printf (_ ("Table attributes unset.\n" ));
26612655}
26622656
26632657/* show title override */
26642658else if (strcmp (param ,"title" )== 0 )
26652659{
26662660if (popt -> title )
2667- printf (_ ("Title(%s) is \"%s\".\n" ), param ,popt -> title );
2661+ printf (_ ("Title is \"%s\".\n" ),popt -> title );
26682662else
2669- printf (_ ("Title(%s) unset.\n" ), param );
2663+ printf (_ ("Titleis unset.\n" ));
26702664}
26712665
26722666/* show toggle between full and tuples-only format */
26732667else if (strcmp (param ,"t" )== 0 || strcmp (param ,"tuples_only" )== 0 )
26742668{
26752669if (popt -> topt .tuples_only )
2676- printf (_ ("Tuples only(%s) is on.\n" ), param );
2670+ printf (_ ("Tuples only is on.\n" ));
26772671else
2678- printf (_ ("Tuples only(%s) is off.\n" ), param );
2672+ printf (_ ("Tuples only is off.\n" ));
26792673}
26802674
26812675/* unicode style formatting */
@@ -2707,6 +2701,107 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
27072701}
27082702
27092703
2704+ static const char *
2705+ pset_bool_string (bool val )
2706+ {
2707+ return val ?"on" :"off" ;
2708+ }
2709+
2710+
2711+ static char *
2712+ pset_quoted_string (const char * str )
2713+ {
2714+ char * ret = pg_malloc (strlen (str )* 2 + 2 );
2715+ char * r = ret ;
2716+
2717+ * r ++ = '\'' ;
2718+
2719+ for (;* str ;str ++ )
2720+ {
2721+ if (* str == '\n' )
2722+ {
2723+ * r ++ = '\\' ;
2724+ * r ++ = 'n' ;
2725+ }
2726+ else if (* str == '\'' )
2727+ {
2728+ * r ++ = '\\' ;
2729+ * r ++ = '\'' ;
2730+ }
2731+ else
2732+ * r ++ = * str ;
2733+ }
2734+
2735+ * r ++ = '\'' ;
2736+ * r = '\0' ;
2737+
2738+ return ret ;
2739+ }
2740+
2741+
2742+ /*
2743+ * Return a malloc'ed string for the \pset value.
2744+ *
2745+ * Note that for some string parameters, print.c distinguishes between unset
2746+ * and empty string, but for others it doesn't. This function should produce
2747+ * output that produces the correct setting when fed back into \pset.
2748+ */
2749+ static char *
2750+ pset_value_string (const char * param ,struct printQueryOpt * popt )
2751+ {
2752+ Assert (param != NULL );
2753+
2754+ if (strcmp (param ,"border" )== 0 )
2755+ return psprintf ("%d" ,popt -> topt .border );
2756+ else if (strcmp (param ,"columns" )== 0 )
2757+ return psprintf ("%d" ,popt -> topt .columns );
2758+ else if (strcmp (param ,"expanded" )== 0 )
2759+ return pstrdup (popt -> topt .expanded == 2
2760+ ?"auto"
2761+ :pset_bool_string (popt -> topt .expanded ));
2762+ else if (strcmp (param ,"fieldsep" )== 0 )
2763+ return pset_quoted_string (popt -> topt .fieldSep .separator
2764+ ?popt -> topt .fieldSep .separator
2765+ :"" );
2766+ else if (strcmp (param ,"fieldsep_zero" )== 0 )
2767+ return pstrdup (pset_bool_string (popt -> topt .fieldSep .separator_zero ));
2768+ else if (strcmp (param ,"footer" )== 0 )
2769+ return pstrdup (pset_bool_string (popt -> topt .default_footer ));
2770+ else if (strcmp (param ,"format" )== 0 )
2771+ return psprintf ("%s" ,_align2string (popt -> topt .format ));
2772+ else if (strcmp (param ,"linestyle" )== 0 )
2773+ return psprintf ("%s" ,get_line_style (& popt -> topt )-> name );
2774+ else if (strcmp (param ,"null" )== 0 )
2775+ return pset_quoted_string (popt -> nullPrint
2776+ ?popt -> nullPrint
2777+ :"" );
2778+ else if (strcmp (param ,"numericlocale" )== 0 )
2779+ return pstrdup (pset_bool_string (popt -> topt .numericLocale ));
2780+ else if (strcmp (param ,"pager" )== 0 )
2781+ return psprintf ("%d" ,popt -> topt .pager );
2782+ else if (strcmp (param ,"recordsep" )== 0 )
2783+ return pset_quoted_string (popt -> topt .recordSep .separator
2784+ ?popt -> topt .recordSep .separator
2785+ :"" );
2786+ else if (strcmp (param ,"recordsep_zero" )== 0 )
2787+ return pstrdup (pset_bool_string (popt -> topt .recordSep .separator_zero ));
2788+ else if (strcmp (param ,"tableattr" )== 0 )
2789+ return popt -> topt .tableAttr ?pset_quoted_string (popt -> topt .tableAttr ) :pstrdup ("" );
2790+ else if (strcmp (param ,"title" )== 0 )
2791+ return popt -> title ?pset_quoted_string (popt -> title ) :pstrdup ("" );
2792+ else if (strcmp (param ,"tuples_only" )== 0 )
2793+ return pstrdup (pset_bool_string (popt -> topt .tuples_only ));
2794+ else if (strcmp (param ,"unicode_border_linestyle" )== 0 )
2795+ return pstrdup (_unicode_linestyle2string (popt -> topt .unicode_border_linestyle ));
2796+ else if (strcmp (param ,"unicode_column_linestyle" )== 0 )
2797+ return pstrdup (_unicode_linestyle2string (popt -> topt .unicode_column_linestyle ));
2798+ else if (strcmp (param ,"unicode_header_linestyle" )== 0 )
2799+ return pstrdup (_unicode_linestyle2string (popt -> topt .unicode_header_linestyle ));
2800+ else
2801+ return pstrdup ("ERROR" );
2802+ }
2803+
2804+
27102805
27112806#ifndef WIN32
27122807#define DEFAULT_SHELL "/bin/sh"