Allow multiple --table options to be specified on the command-line.
Per Issue #18. SimpleStringList code borrowed from pg_dump and a pending patch to add similar functionality to pg_restore, clusterdb, vacuumdb, and reindexdb. The error handling in reorg_one_table() could still be much improved, so that an error processing a single table doesn't cause pg_reorg to necessarily bail out and skip further tables, but I'll leave that for another day.
This commit is contained in:
committed by
Daniele Varrazzo
parent
ad00eb181d
commit
ad75dcfbb1
@ -144,9 +144,12 @@ pgut_setopt(pgut_option *opt, const char *optarg, pgut_optsrc src)
|
||||
/* high prior value has been set already. */
|
||||
return;
|
||||
}
|
||||
else if (src >= SOURCE_CMDLINE && opt->source >= src)
|
||||
else if (src >= SOURCE_CMDLINE && opt->source >= src && opt->type != 'l')
|
||||
{
|
||||
/* duplicated option in command line */
|
||||
/* duplicated option in command line -- don't worry if the option
|
||||
* type is 'l' i.e. SimpleStringList, since we are allowed to have
|
||||
* multiples of these.
|
||||
*/
|
||||
message = "specified only once";
|
||||
}
|
||||
else
|
||||
@ -177,6 +180,10 @@ pgut_setopt(pgut_option *opt, const char *optarg, pgut_optsrc src)
|
||||
return;
|
||||
message = "a 32bit signed integer";
|
||||
break;
|
||||
case 'l':
|
||||
message = "a List";
|
||||
simple_string_list_append(opt->var, optarg);
|
||||
return;
|
||||
case 'u':
|
||||
if (parse_uint32(optarg, opt->var))
|
||||
return;
|
||||
|
@ -25,13 +25,14 @@ typedef enum pgut_optsrc
|
||||
* type:
|
||||
* b: bool (true)
|
||||
* B: bool (false)
|
||||
* f: pgut_optfn
|
||||
* f: pgut_optfn
|
||||
* i: 32bit signed integer
|
||||
* l: StringList
|
||||
* u: 32bit unsigned integer
|
||||
* I: 64bit signed integer
|
||||
* U: 64bit unsigned integer
|
||||
* s: string
|
||||
* t: time_t
|
||||
* t: time_t
|
||||
* y: YesNo (YES)
|
||||
* Y: YesNo (NO)
|
||||
*/
|
||||
|
@ -384,6 +384,40 @@ parse_time(const char *value, time_t *time)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Append the given string `val` to the `list` */
|
||||
void
|
||||
simple_string_list_append(SimpleStringList *list, const char *val)
|
||||
{
|
||||
SimpleStringListCell *cell;
|
||||
|
||||
/* this calculation correctly accounts for the null trailing byte */
|
||||
cell = (SimpleStringListCell *)
|
||||
pgut_malloc(sizeof(SimpleStringListCell) + strlen(val));
|
||||
cell->next = NULL;
|
||||
strcpy(cell->val, val);
|
||||
|
||||
if (list->tail)
|
||||
list->tail->next = cell;
|
||||
else
|
||||
list->head = cell;
|
||||
list->tail = cell;
|
||||
}
|
||||
|
||||
/* Test whether `val` is in the given `list` */
|
||||
bool
|
||||
simple_string_list_member(SimpleStringList *list, const char *val)
|
||||
{
|
||||
SimpleStringListCell *cell;
|
||||
|
||||
for (cell = list->head; cell; cell = cell->next)
|
||||
{
|
||||
if (strcmp(cell->val, val) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
prompt_for_password(void)
|
||||
{
|
||||
|
@ -171,6 +171,23 @@ extern bool parse_time(const char *value, time_t *time);
|
||||
#define ToLower(c) (tolower((unsigned char)(c)))
|
||||
#define ToUpper(c) (toupper((unsigned char)(c)))
|
||||
|
||||
/* linked list of string values and helper functions, stolen from pg_dump. */
|
||||
typedef struct SimpleStringListCell
|
||||
{
|
||||
struct SimpleStringListCell *next;
|
||||
char val[1]; /* VARIABLE LENGTH FIELD */
|
||||
} SimpleStringListCell;
|
||||
|
||||
typedef struct SimpleStringList
|
||||
{
|
||||
SimpleStringListCell *head;
|
||||
SimpleStringListCell *tail;
|
||||
} SimpleStringList;
|
||||
|
||||
extern void simple_string_list_append(SimpleStringList *list, const char *val);
|
||||
extern bool simple_string_list_member(SimpleStringList *list, const char *val);
|
||||
|
||||
|
||||
/*
|
||||
* socket operations
|
||||
*/
|
||||
|
Reference in New Issue
Block a user