@@ -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,15 +1051,19 @@ 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
NULL
1058
1059
};
1059
1060
1060
1061
for (i = 0 ; my_list [i ] != NULL ; i ++ )
1061
- printPsetInfo (my_list [i ], & pset .popt );
1062
+ {
1063
+ char * val = pset_value_string (my_list [i ], & pset .popt );
1064
+ printf ("%-14s %s\n" , my_list [i ], val );
1065
+ free (val );
1066
+ }
1062
1067
1063
1068
success = true;
1064
1069
}
@@ -2199,10 +2204,6 @@ process_file(char *filename, bool single_txn, bool use_relative_path)
2199
2204
2200
2205
2201
2206
2202
- /*
2203
- * do_pset
2204
- *
2205
- */
2206
2207
static const char *
2207
2208
_align2string (enum printFormat in )
2208
2209
{
@@ -2237,6 +2238,10 @@ _align2string(enum printFormat in)
2237
2238
}
2238
2239
2239
2240
2241
+ /*
2242
+ * do_pset
2243
+ *
2244
+ */
2240
2245
bool
2241
2246
do_pset (const char * param , const char * value , printQueryOpt * popt , bool quiet )
2242
2247
{
@@ -2447,146 +2452,135 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
2447
2452
2448
2453
/* show border style/width */
2449
2454
if (strcmp (param , "border" ) == 0 )
2450
- {
2451
- if (!popt -> topt .border )
2452
- printf (_ ("Border style (%s) unset.\n" ), param );
2453
- else
2454
- printf (_ ("Border style (%s) is %d.\n" ), param ,
2455
- popt -> topt .border );
2456
- }
2455
+ printf (_ ("Border style is %d.\n" ), popt -> topt .border );
2457
2456
2458
2457
/* show the target width for the wrapped format */
2459
2458
else if (strcmp (param , "columns" ) == 0 )
2460
2459
{
2461
2460
if (!popt -> topt .columns )
2462
- printf (_ ("Target width (%s) unset.\n" ), param );
2461
+ printf (_ ("Target width is unset.\n" ));
2463
2462
else
2464
- printf (_ ("Target width (%s) is %d.\n" ), param ,
2465
- popt -> topt .columns );
2463
+ printf (_ ("Target width is %d.\n" ), popt -> topt .columns );
2466
2464
}
2467
2465
2468
2466
/* show expanded/vertical mode */
2469
2467
else if (strcmp (param , "x" ) == 0 || strcmp (param , "expanded" ) == 0 || strcmp (param , "vertical" ) == 0 )
2470
2468
{
2471
2469
if (popt -> topt .expanded == 1 )
2472
- printf (_ ("Expanded display (%s) is on.\n" ), param );
2470
+ printf (_ ("Expanded display is on.\n" ));
2473
2471
else if (popt -> topt .expanded == 2 )
2474
- printf (_ ("Expanded display (%s) is used automatically.\n" ), param );
2472
+ printf (_ ("Expanded display is used automatically.\n" ));
2475
2473
else
2476
- printf (_ ("Expanded display (%s) is off.\n" ), param );
2474
+ printf (_ ("Expanded display is off.\n" ));
2477
2475
}
2478
2476
2479
2477
/* show field separator for unaligned text */
2480
2478
else if (strcmp (param , "fieldsep" ) == 0 )
2481
2479
{
2482
2480
if (popt -> topt .fieldSep .separator_zero )
2483
- printf (_ ("Field separator (%s) is zero byte.\n" ), param );
2481
+ printf (_ ("Field separator is zero byte.\n" ));
2484
2482
else
2485
- printf (_ ("Field separator (%s) is \"%s\".\n" ), param ,
2483
+ printf (_ ("Field separator is \"%s\".\n" ),
2486
2484
popt -> topt .fieldSep .separator );
2487
2485
}
2488
2486
2489
2487
else if (strcmp (param , "fieldsep_zero" ) == 0 )
2490
2488
{
2491
- printf (_ ("Field separator (%s) is zero byte.\n" ), param );
2489
+ printf (_ ("Field separator is zero byte.\n" ));
2492
2490
}
2493
2491
2494
2492
/* show disable "(x rows)" footer */
2495
2493
else if (strcmp (param , "footer" ) == 0 )
2496
2494
{
2497
2495
if (popt -> topt .default_footer )
2498
- printf (_ ("Default footer (%s) is on.\n" ), param );
2496
+ printf (_ ("Default footer is on.\n" ));
2499
2497
else
2500
- printf (_ ("Default footer (%s) is off.\n" ), param );
2498
+ printf (_ ("Default footer is off.\n" ));
2501
2499
}
2502
2500
2503
2501
/* show format */
2504
2502
else if (strcmp (param , "format" ) == 0 )
2505
2503
{
2506
- if (!popt -> topt .format )
2507
- printf (_ ("Output format (%s) is aligned.\n" ), param );
2508
- else
2509
- printf (_ ("Output format (%s) is %s.\n" ), param ,
2510
- _align2string (popt -> topt .format ));
2504
+ printf (_ ("Output format is %s.\n" ), _align2string (popt -> topt .format ));
2511
2505
}
2512
2506
2513
2507
/* show table line style */
2514
2508
else if (strcmp (param , "linestyle" ) == 0 )
2515
2509
{
2516
- printf (_ ("Line style (%s) is %s.\n" ), param ,
2510
+ printf (_ ("Line style is %s.\n" ),
2517
2511
get_line_style (& popt -> topt )-> name );
2518
2512
}
2519
2513
2520
2514
/* show null display */
2521
2515
else if (strcmp (param , "null" ) == 0 )
2522
2516
{
2523
- printf (_ ("Null display (%s) is \"%s\".\n" ), param ,
2517
+ printf (_ ("Null display is \"%s\".\n" ),
2524
2518
popt -> nullPrint ? popt -> nullPrint : "" );
2525
2519
}
2526
2520
2527
2521
/* show locale-aware numeric output */
2528
2522
else if (strcmp (param , "numericlocale" ) == 0 )
2529
2523
{
2530
2524
if (popt -> topt .numericLocale )
2531
- printf (_ ("Locale-adjusted numeric output (%s) is on.\n" ), param );
2525
+ printf (_ ("Locale-adjusted numeric output is on.\n" ));
2532
2526
else
2533
- printf (_ ("Locale-adjusted numeric output (%s) is off.\n" ), param );
2527
+ printf (_ ("Locale-adjusted numeric output is off.\n" ));
2534
2528
}
2535
2529
2536
2530
/* show toggle use of pager */
2537
2531
else if (strcmp (param , "pager" ) == 0 )
2538
2532
{
2539
2533
if (popt -> topt .pager == 1 )
2540
- printf (_ ("Pager (%s) is used for long output.\n" ), param );
2534
+ printf (_ ("Pager is used for long output.\n" ));
2541
2535
else if (popt -> topt .pager == 2 )
2542
- printf (_ ("Pager (%s) is always used.\n" ), param );
2536
+ printf (_ ("Pager is always used.\n" ));
2543
2537
else
2544
- printf (_ ("Pager usage (%s) is off.\n" ), param );
2538
+ printf (_ ("Pager usage is off.\n" ));
2545
2539
}
2546
2540
2547
2541
/* show record separator for unaligned text */
2548
2542
else if (strcmp (param , "recordsep" ) == 0 )
2549
2543
{
2550
2544
if (popt -> topt .recordSep .separator_zero )
2551
- printf (_ ("Record separator (%s) is zero byte.\n" ), param );
2545
+ printf (_ ("Record separator is zero byte.\n" ));
2552
2546
else if (strcmp (popt -> topt .recordSep .separator , "\n" ) == 0 )
2553
- printf (_ ("Record separator (%s) is <newline>.\n" ), param );
2547
+ printf (_ ("Record separator is <newline>.\n" ));
2554
2548
else
2555
- printf (_ ("Record separator (%s) is \"%s\".\n" ), param ,
2549
+ printf (_ ("Record separator is \"%s\".\n" ),
2556
2550
popt -> topt .recordSep .separator );
2557
2551
}
2558
2552
2559
2553
else if (strcmp (param , "recordsep_zero" ) == 0 )
2560
2554
{
2561
- printf (_ ("Record separator (%s) is zero byte.\n" ), param );
2555
+ printf (_ ("Record separator is zero byte.\n" ));
2562
2556
}
2563
2557
2564
2558
/* show HTML table tag options */
2565
2559
else if (strcmp (param , "T" ) == 0 || strcmp (param , "tableattr" ) == 0 )
2566
2560
{
2567
2561
if (popt -> topt .tableAttr )
2568
- printf (_ ("Table attributes (%s) are \"%s\".\n" ), param ,
2562
+ printf (_ ("Table attributes are \"%s\".\n" ),
2569
2563
popt -> topt .tableAttr );
2570
2564
else
2571
- printf (_ ("Table attributes (%s) unset.\n" ), param );
2565
+ printf (_ ("Table attributes unset.\n" ));
2572
2566
}
2573
2567
2574
2568
/* show title override */
2575
2569
else if (strcmp (param , "title" ) == 0 )
2576
2570
{
2577
2571
if (popt -> title )
2578
- printf (_ ("Title (%s) is \"%s\".\n" ), param , popt -> title );
2572
+ printf (_ ("Title is \"%s\".\n" ), popt -> title );
2579
2573
else
2580
- printf (_ ("Title (%s) unset.\n" ), param );
2574
+ printf (_ ("Title is unset.\n" ));
2581
2575
}
2582
2576
2583
2577
/* show toggle between full and tuples-only format */
2584
2578
else if (strcmp (param , "t" ) == 0 || strcmp (param , "tuples_only" ) == 0 )
2585
2579
{
2586
2580
if (popt -> topt .tuples_only )
2587
- printf (_ ("Tuples only (%s) is on.\n" ), param );
2581
+ printf (_ ("Tuples only is on.\n" ));
2588
2582
else
2589
- printf (_ ("Tuples only (%s) is off.\n" ), param );
2583
+ printf (_ ("Tuples only is off.\n" ));
2590
2584
}
2591
2585
2592
2586
else
@@ -2599,6 +2593,101 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
2599
2593
}
2600
2594
2601
2595
2596
+ static const char *
2597
+ pset_bool_string (bool val )
2598
+ {
2599
+ return val ? "on" : "off" ;
2600
+ }
2601
+
2602
+
2603
+ static char *
2604
+ pset_quoted_string (const char * str )
2605
+ {
2606
+ char * ret = pg_malloc (strlen (str ) * 2 + 2 );
2607
+ char * r = ret ;
2608
+
2609
+ * r ++ = '\'' ;
2610
+
2611
+ for (; * str ; str ++ )
2612
+ {
2613
+ if (* str == '\n' )
2614
+ {
2615
+ * r ++ = '\\' ;
2616
+ * r ++ = 'n' ;
2617
+ }
2618
+ else if (* str == '\'' )
2619
+ {
2620
+ * r ++ = '\\' ;
2621
+ * r ++ = '\'' ;
2622
+ }
2623
+ else
2624
+ * r ++ = * str ;
2625
+ }
2626
+
2627
+ * r ++ = '\'' ;
2628
+ * r = '\0' ;
2629
+
2630
+ return ret ;
2631
+ }
2632
+
2633
+
2634
+ /*
2635
+ * Return a malloc'ed string for the \pset value.
2636
+ *
2637
+ * Note that for some string parameters, print.c distinguishes between unset
2638
+ * and empty string, but for others it doesn't. This function should produce
2639
+ * output that produces the correct setting when fed back into \pset.
2640
+ */
2641
+ static char *
2642
+ pset_value_string (const char * param , struct printQueryOpt * popt )
2643
+ {
2644
+ Assert (param != NULL );
2645
+
2646
+ if (strcmp (param , "border" ) == 0 )
2647
+ return psprintf ("%d" , popt -> topt .border );
2648
+ else if (strcmp (param , "columns" ) == 0 )
2649
+ return psprintf ("%d" , popt -> topt .columns );
2650
+ else if (strcmp (param , "expanded" ) == 0 )
2651
+ return pstrdup (popt -> topt .expanded == 2
2652
+ ? "auto"
2653
+ : pset_bool_string (popt -> topt .expanded ));
2654
+ else if (strcmp (param , "fieldsep" ) == 0 )
2655
+ return pset_quoted_string (popt -> topt .fieldSep .separator
2656
+ ? popt -> topt .fieldSep .separator
2657
+ : "" );
2658
+ else if (strcmp (param , "fieldsep_zero" ) == 0 )
2659
+ return pstrdup (pset_bool_string (popt -> topt .fieldSep .separator_zero ));
2660
+ else if (strcmp (param , "footer" ) == 0 )
2661
+ return pstrdup (pset_bool_string (popt -> topt .default_footer ));
2662
+ else if (strcmp (param , "format" ) == 0 )
2663
+ return psprintf ("%s" , _align2string (popt -> topt .format ));
2664
+ else if (strcmp (param , "linestyle" ) == 0 )
2665
+ return psprintf ("%s" , get_line_style (& popt -> topt )-> name );
2666
+ else if (strcmp (param , "null" ) == 0 )
2667
+ return pset_quoted_string (popt -> nullPrint
2668
+ ? popt -> nullPrint
2669
+ : "" );
2670
+ else if (strcmp (param , "numericlocale" ) == 0 )
2671
+ return pstrdup (pset_bool_string (popt -> topt .numericLocale ));
2672
+ else if (strcmp (param , "pager" ) == 0 )
2673
+ return psprintf ("%d" , popt -> topt .pager );
2674
+ else if (strcmp (param , "recordsep" ) == 0 )
2675
+ return pset_quoted_string (popt -> topt .recordSep .separator
2676
+ ? popt -> topt .recordSep .separator
2677
+ : "" );
2678
+ else if (strcmp (param , "recordsep_zero" ) == 0 )
2679
+ return pstrdup (pset_bool_string (popt -> topt .recordSep .separator_zero ));
2680
+ else if (strcmp (param , "tableattr" ) == 0 )
2681
+ return popt -> topt .tableAttr ? pset_quoted_string (popt -> topt .tableAttr ) : pstrdup ("" );
2682
+ else if (strcmp (param , "title" ) == 0 )
2683
+ return popt -> title ? pset_quoted_string (popt -> title ) : pstrdup ("" );
2684
+ else if (strcmp (param , "tuples_only" ) == 0 )
2685
+ return pstrdup (pset_bool_string (popt -> topt .tuples_only ));
2686
+ else
2687
+ return pstrdup ("ERROR" );
2688
+ }
2689
+
2690
+
2602
2691
2603
2692
#ifndef WIN32
2604
2693
#define DEFAULT_SHELL "/bin/sh"
0 commit comments