/* The 'pa' executable entry point. */
/* $Id: pa.c,v 1.6 2003/07/30 22:59:05 pasky Exp $ */

/*
 * PaVS - Pasky's Version System, advanced version control system
 * Copyright (C) 2003  Petr Baudis
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include <stdio.h>
#include <string.h>


#include <libpavs/backsel.h>
#include <librev/inode.h>
#include <librev/list.h>

#include "args.h"
#include "cmds.h"
#include "error.h"


static enum pa_errcode do_main (struct args *args);

int
main (int argc, char *argv[])
{
	struct args args;
	enum pa_errcode error;

	args.argc = argc; args.argv = argv;
	args_shift (&args); /* Program name is not important right now. */
	error = do_main (&args);

	if ((error & PE_MASK) && ! (error & PEF_SILENT)) {
		fprintf (stderr, "%s\n", pa_errmsg (error));
	}

	return (error & PE_MASK);
}


enum pa_errcode
do_main (struct args *args)
{
	pa_cmd_t handler;

	if (args->argc < 1) return PEARGMISSING;

	handler = pa_cmd_handler (args->argv [0]);
	return handler ? handler (args) : PEARGINVAL;
}
