@@ -697,7 +697,7 @@ static char **complete_from_variables(char *text,
697
697
const char * prefix , const char * suffix );
698
698
static char * complete_from_files (const char * text , int state );
699
699
700
- static char * pg_strdup_same_case (const char * s , const char * ref );
700
+ static char * pg_strdup_keyword_case (const char * s , const char * ref );
701
701
static PGresult * exec_query (const char * query );
702
702
703
703
static void get_previous_words (int point , char * * previous_words , int nwords );
@@ -3125,7 +3125,7 @@ create_or_drop_command_generator(const char *text, int state, bits32 excluded)
3125
3125
{
3126
3126
if ((pg_strncasecmp (name , text , string_length ) == 0 ) &&
3127
3127
!(words_after_create [list_index - 1 ].flags & excluded ))
3128
- return pg_strdup_same_case (name , text );
3128
+ return pg_strdup_keyword_case (name , text );
3129
3129
}
3130
3130
/* if nothing matches, return NULL */
3131
3131
return NULL ;
@@ -3412,9 +3412,9 @@ complete_from_list(const char *text, int state)
3412
3412
if (completion_case_sensitive )
3413
3413
return pg_strdup (item );
3414
3414
else
3415
- /* If case insensitive matching was requested initially, return
3416
- * it in the case of what was already entered . */
3417
- return pg_strdup_same_case (item , text );
3415
+ /* If case insensitive matching was requested initially, adjust
3416
+ * the case according to setting . */
3417
+ return pg_strdup_keyword_case (item , text );
3418
3418
}
3419
3419
}
3420
3420
@@ -3451,9 +3451,9 @@ complete_from_const(const char *text, int state)
3451
3451
if (completion_case_sensitive )
3452
3452
return pg_strdup (completion_charp );
3453
3453
else
3454
- /* If case insensitive matching was requested initially, return it
3455
- * in the case of what was already entered . */
3456
- return pg_strdup_same_case (completion_charp , text );
3454
+ /* If case insensitive matching was requested initially, adjust the
3455
+ * case according to setting . */
3456
+ return pg_strdup_keyword_case (completion_charp , text );
3457
3457
}
3458
3458
else
3459
3459
return NULL ;
@@ -3561,27 +3561,48 @@ complete_from_files(const char *text, int state)
3561
3561
3562
3562
3563
3563
/*
3564
- * Make a pg_strdup copy of s and convert it to the same case as ref.
3564
+ * Make a pg_strdup copy of s and convert the case according to
3565
+ * COMP_KEYWORD_CASE variable, using ref as the text that was already entered.
3565
3566
*/
3566
3567
static char *
3567
- pg_strdup_same_case (const char * s , const char * ref )
3568
+ pg_strdup_keyword_case (const char * s , const char * ref )
3568
3569
{
3569
3570
char * ret , * p ;
3570
3571
unsigned char first = ref [0 ];
3572
+ int tocase ;
3573
+ const char * varval ;
3574
+
3575
+ varval = GetVariable (pset .vars , "COMP_KEYWORD_CASE" );
3576
+ if (!varval )
3577
+ tocase = 0 ;
3578
+ else if (strcmp (varval , "lower" ) == 0 )
3579
+ tocase = -2 ;
3580
+ else if (strcmp (varval , "preserve-lower" ) == 0 )
3581
+ tocase = -1 ;
3582
+ else if (strcmp (varval , "preserve-upper" ) == 0 )
3583
+ tocase = +1 ;
3584
+ else if (strcmp (varval , "upper" ) == 0 )
3585
+ tocase = +2 ;
3586
+ else
3587
+ tocase = 0 ;
3571
3588
3572
- if (isalpha (first ))
3573
- {
3574
- ret = pg_strdup (s );
3575
- if (islower (first ))
3576
- for (p = ret ; * p ; p ++ )
3577
- * p = pg_tolower ((unsigned char ) * p );
3578
- else
3579
- for (p = ret ; * p ; p ++ )
3580
- * p = pg_toupper ((unsigned char ) * p );
3581
- return ret ;
3582
- }
3589
+ /* default */
3590
+ if (tocase == 0 )
3591
+ tocase = +1 ;
3592
+
3593
+ ret = pg_strdup (s );
3594
+
3595
+ if (tocase == -2
3596
+ || ((tocase == -1 || tocase == +1 ) && islower (first ))
3597
+ || (tocase == -1 && !isalpha (first ))
3598
+ )
3599
+ for (p = ret ; * p ; p ++ )
3600
+ * p = pg_tolower ((unsigned char ) * p );
3583
3601
else
3584
- return pg_strdup (s );
3602
+ for (p = ret ; * p ; p ++ )
3603
+ * p = pg_toupper ((unsigned char ) * p );
3604
+
3605
+ return ret ;
3585
3606
}
3586
3607
3587
3608
0 commit comments