//
// aegis - project change supervisor
// Copyright (C) 2001, 2002, 2004-2006, 2008, 2014 Peter Miller
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
#include
#include
#include
#include
#include
#include
#include
struct table_t
{
const char *name;
format::pointer (*create)(void);
};
static format::pointer list(void); // forward
static const table_t table[] =
{
{ "sccs", &format_sccs::create },
{ "bitkeeper", &format_sccs::create },
{ "bitsccs", &format_sccs::create },
{ "bk", &format_sccs::create },
{ "cssc", &format_sccs::create },
{ "rcs", &format_rcs::create },
{ "cvs", &format_rcs::create },
{ "list", &list },
{ "help", &list },
};
format::pointer
format::factory(const nstring &name)
{
//
// The default is RCS format (I'm guessing most folks are
// importing a CVS archive).
//
if (name.empty())
return format_rcs::create();
nstring lc_name = name.downcase();
//
// Walk the table looking for a match
//
for (const table_t *tp = table; tp < ENDOF(table); ++tp)
{
if (nstring(tp->name) == lc_name)
return tp->create();
}
//
// fuzzy match for better error message
//
{
double best_weight = 0.6;
const table_t *best_tp = 0;
for (const table_t *tp = table; tp < ENDOF(table); ++tp)
{
double w = fstrcmp(tp->name, lc_name.c_str());
if (best_weight < w)
{
best_weight = w;
best_tp = tp;
}
}
if (best_tp)
{
sub_context_ty sc;
sc.var_set_string("Name", name);
sc.var_set_charstar("Guess", best_tp->name);
nstring msg =
sc.substitute
(
change::pointer(),
nstring("history format \"$name\" unknown, "
"did you mean \"$guess\" instead?")
);
fatal_raw("%s", msg.c_str());
}
}
//
// Oops.
//
sub_context_ty sc;
sc.var_set_string("Name", name);
sc.fatal_intl("history format \"$name\" unknown");
// NOTREACHED
return format::pointer();
}
format::pointer
list(void)
{
for (const table_t *tp = table; tp < ENDOF(table); ++tp)
{
if (list == tp->create)
continue;
printf("%s\n", tp->name);
// avoid synonyms
while (tp + 1 < ENDOF(table) && tp->create == tp[1].create)
++tp;
}
exit(EXIT_SUCCESS);
// NOTREACHED
return format::pointer();
}
// vim: set ts=8 sw=4 et :