@@ -69,6 +69,7 @@ static void minimal_error_message(PGresult *res);
69
69
70
70
static void printSSLInfo (void );
71
71
static bool printPsetInfo (const char * param , struct printQueryOpt * popt );
72
+ static char * pset_value_string (const char * param , struct printQueryOpt * popt );
72
73
73
74
#ifdef WIN32
74
75
static void checkWin32Codepage (void );
@@ -1050,9 +1051,9 @@ exec_command(const char *cmd,
1050
1051
1051
1052
int i ;
1052
1053
static const char * const my_list [] = {
1053
- "border" , "columns" , "expanded" , "fieldsep" ,
1054
+ "border" , "columns" , "expanded" , "fieldsep" , "fieldsep_zero" ,
1054
1055
"footer" , "format" , "linestyle" , "null" ,
1055
- "numericlocale" , "pager" , "recordsep" ,
1056
+ "numericlocale" , "pager" , "recordsep" , "recordsep_zero" ,
1056
1057
"tableattr" , "title" , "tuples_only" ,
1057
1058
"unicode_border_linestyle" ,
1058
1059
"unicode_column_linestyle" ,
@@ -1061,7 +1062,11 @@ exec_command(const char *cmd,
1061
1062
};
1062
1063
1063
1064
for (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
+ }
1065
1070
1066
1071
success = true;
1067
1072
}
@@ -2214,10 +2219,6 @@ process_file(char *filename, bool single_txn, bool use_relative_path)
2214
2219
2215
2220
2216
2221
2217
- /*
2218
- * do_pset
2219
- *
2220
- */
2221
2222
static const char *
2222
2223
_align2string (enum printFormat in )
2223
2224
{
@@ -2287,6 +2288,10 @@ _unicode_linestyle2string(int linestyle)
2287
2288
return "unknown" ;
2288
2289
}
2289
2290
2291
+ /*
2292
+ * do_pset
2293
+ *
2294
+ */
2290
2295
bool
2291
2296
do_pset (const char * param , const char * value , printQueryOpt * popt , bool quiet )
2292
2297
{
@@ -2536,146 +2541,135 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
2536
2541
2537
2542
/* show border style/width */
2538
2543
if (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 );
2546
2545
2547
2546
/* show the target width for the wrapped format */
2548
2547
else if (strcmp (param , "columns" ) == 0 )
2549
2548
{
2550
2549
if (!popt -> topt .columns )
2551
- printf (_ ("Target width (%s) unset.\n" ), param );
2550
+ printf (_ ("Target width is unset.\n" ));
2552
2551
else
2553
- printf (_ ("Target width (%s) is %d.\n" ), param ,
2554
- popt -> topt .columns );
2552
+ printf (_ ("Target width is %d.\n" ), popt -> topt .columns );
2555
2553
}
2556
2554
2557
2555
/* show expanded/vertical mode */
2558
2556
else if (strcmp (param , "x" ) == 0 || strcmp (param , "expanded" ) == 0 || strcmp (param , "vertical" ) == 0 )
2559
2557
{
2560
2558
if (popt -> topt .expanded == 1 )
2561
- printf (_ ("Expanded display (%s) is on.\n" ), param );
2559
+ printf (_ ("Expanded display is on.\n" ));
2562
2560
else if (popt -> topt .expanded == 2 )
2563
- printf (_ ("Expanded display (%s) is used automatically.\n" ), param );
2561
+ printf (_ ("Expanded display is used automatically.\n" ));
2564
2562
else
2565
- printf (_ ("Expanded display (%s) is off.\n" ), param );
2563
+ printf (_ ("Expanded display is off.\n" ));
2566
2564
}
2567
2565
2568
2566
/* show field separator for unaligned text */
2569
2567
else if (strcmp (param , "fieldsep" ) == 0 )
2570
2568
{
2571
2569
if (popt -> topt .fieldSep .separator_zero )
2572
- printf (_ ("Field separator (%s) is zero byte.\n" ), param );
2570
+ printf (_ ("Field separator is zero byte.\n" ));
2573
2571
else
2574
- printf (_ ("Field separator (%s) is \"%s\".\n" ), param ,
2572
+ printf (_ ("Field separator is \"%s\".\n" ),
2575
2573
popt -> topt .fieldSep .separator );
2576
2574
}
2577
2575
2578
2576
else if (strcmp (param , "fieldsep_zero" ) == 0 )
2579
2577
{
2580
- printf (_ ("Field separator (%s) is zero byte.\n" ), param );
2578
+ printf (_ ("Field separator is zero byte.\n" ));
2581
2579
}
2582
2580
2583
2581
/* show disable "(x rows)" footer */
2584
2582
else if (strcmp (param , "footer" ) == 0 )
2585
2583
{
2586
2584
if (popt -> topt .default_footer )
2587
- printf (_ ("Default footer (%s) is on.\n" ), param );
2585
+ printf (_ ("Default footer is on.\n" ));
2588
2586
else
2589
- printf (_ ("Default footer (%s) is off.\n" ), param );
2587
+ printf (_ ("Default footer is off.\n" ));
2590
2588
}
2591
2589
2592
2590
/* show format */
2593
2591
else if (strcmp (param , "format" ) == 0 )
2594
2592
{
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 ));
2600
2594
}
2601
2595
2602
2596
/* show table line style */
2603
2597
else if (strcmp (param , "linestyle" ) == 0 )
2604
2598
{
2605
- printf (_ ("Line style (%s) is %s.\n" ), param ,
2599
+ printf (_ ("Line style is %s.\n" ),
2606
2600
get_line_style (& popt -> topt )-> name );
2607
2601
}
2608
2602
2609
2603
/* show null display */
2610
2604
else if (strcmp (param , "null" ) == 0 )
2611
2605
{
2612
- printf (_ ("Null display (%s) is \"%s\".\n" ), param ,
2606
+ printf (_ ("Null display is \"%s\".\n" ),
2613
2607
popt -> nullPrint ? popt -> nullPrint : "" );
2614
2608
}
2615
2609
2616
2610
/* show locale-aware numeric output */
2617
2611
else if (strcmp (param , "numericlocale" ) == 0 )
2618
2612
{
2619
2613
if (popt -> topt .numericLocale )
2620
- printf (_ ("Locale-adjusted numeric output (%s) is on.\n" ), param );
2614
+ printf (_ ("Locale-adjusted numeric output is on.\n" ));
2621
2615
else
2622
- printf (_ ("Locale-adjusted numeric output (%s) is off.\n" ), param );
2616
+ printf (_ ("Locale-adjusted numeric output is off.\n" ));
2623
2617
}
2624
2618
2625
2619
/* show toggle use of pager */
2626
2620
else if (strcmp (param , "pager" ) == 0 )
2627
2621
{
2628
2622
if (popt -> topt .pager == 1 )
2629
- printf (_ ("Pager (%s) is used for long output.\n" ), param );
2623
+ printf (_ ("Pager is used for long output.\n" ));
2630
2624
else if (popt -> topt .pager == 2 )
2631
- printf (_ ("Pager (%s) is always used.\n" ), param );
2625
+ printf (_ ("Pager is always used.\n" ));
2632
2626
else
2633
- printf (_ ("Pager usage (%s) is off.\n" ), param );
2627
+ printf (_ ("Pager usage is off.\n" ));
2634
2628
}
2635
2629
2636
2630
/* show record separator for unaligned text */
2637
2631
else if (strcmp (param , "recordsep" ) == 0 )
2638
2632
{
2639
2633
if (popt -> topt .recordSep .separator_zero )
2640
- printf (_ ("Record separator (%s) is zero byte.\n" ), param );
2634
+ printf (_ ("Record separator is zero byte.\n" ));
2641
2635
else if (strcmp (popt -> topt .recordSep .separator , "\n" ) == 0 )
2642
- printf (_ ("Record separator (%s) is <newline>.\n" ), param );
2636
+ printf (_ ("Record separator is <newline>.\n" ));
2643
2637
else
2644
- printf (_ ("Record separator (%s) is \"%s\".\n" ), param ,
2638
+ printf (_ ("Record separator is \"%s\".\n" ),
2645
2639
popt -> topt .recordSep .separator );
2646
2640
}
2647
2641
2648
2642
else if (strcmp (param , "recordsep_zero" ) == 0 )
2649
2643
{
2650
- printf (_ ("Record separator (%s) is zero byte.\n" ), param );
2644
+ printf (_ ("Record separator is zero byte.\n" ));
2651
2645
}
2652
2646
2653
2647
/* show HTML table tag options */
2654
2648
else if (strcmp (param , "T" ) == 0 || strcmp (param , "tableattr" ) == 0 )
2655
2649
{
2656
2650
if (popt -> topt .tableAttr )
2657
- printf (_ ("Table attributes (%s) are \"%s\".\n" ), param ,
2651
+ printf (_ ("Table attributes are \"%s\".\n" ),
2658
2652
popt -> topt .tableAttr );
2659
2653
else
2660
- printf (_ ("Table attributes (%s) unset.\n" ), param );
2654
+ printf (_ ("Table attributes unset.\n" ));
2661
2655
}
2662
2656
2663
2657
/* show title override */
2664
2658
else if (strcmp (param , "title" ) == 0 )
2665
2659
{
2666
2660
if (popt -> title )
2667
- printf (_ ("Title (%s) is \"%s\".\n" ), param , popt -> title );
2661
+ printf (_ ("Title is \"%s\".\n" ), popt -> title );
2668
2662
else
2669
- printf (_ ("Title (%s) unset.\n" ), param );
2663
+ printf (_ ("Title is unset.\n" ));
2670
2664
}
2671
2665
2672
2666
/* show toggle between full and tuples-only format */
2673
2667
else if (strcmp (param , "t" ) == 0 || strcmp (param , "tuples_only" ) == 0 )
2674
2668
{
2675
2669
if (popt -> topt .tuples_only )
2676
- printf (_ ("Tuples only (%s) is on.\n" ), param );
2670
+ printf (_ ("Tuples only is on.\n" ));
2677
2671
else
2678
- printf (_ ("Tuples only (%s) is off.\n" ), param );
2672
+ printf (_ ("Tuples only is off.\n" ));
2679
2673
}
2680
2674
2681
2675
/* unicode style formatting */
@@ -2707,6 +2701,107 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
2707
2701
}
2708
2702
2709
2703
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
+
2710
2805
2711
2806
#ifndef WIN32
2712
2807
#define DEFAULT_SHELL "/bin/sh"
0 commit comments