#!/usr/bin/perl -w
# $Id: makeacct,v 1.2 1994/11/14 06:58:52 cbbrowne Exp cbbrowne $
# makeacct: creates a dbm file for the account, as well as inserting an
# entry in the category file so as to provide a transfer account
#  Written by Christopher B. Browne
#
#  Copyright (C) 1994  Christopher B. Browne cbrowne@io.org
#
#  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., 675 Mass Ave, Cambridge, MA 02139, USA.
require "cbbshutils.pl";
# Builds up the outstanding list(s)
$name = shift(@ARGV); $name =~ tr/A-Z/a-z/;
$description = shift (@ARGV);

if (($name eq "") || ($description eq "")) {
  print "error: invalid arguments!\n\n";
  print "createaccount [accountname] [description]\n";
  print "example:\n";
  print "  % createaccount cash 'Cash'\n";
  die -1;
}

dbmopen(%ACCOUNTLIST, $home."acclist", 0666);
if (-e $home."$name.txn.pag")
{
  print "Warning: DBM file already exists for this account; account already exists.\n";
  print "I'm NOT going to blow the old one away, but I will change its name\n";
  print "in the category file.  If you want the old one to disappear, you'll\n";
  print "have to blow it away yourself.\n";
  print "  The command would be something like:\n";
  print "  rm $name.txn.*\n";
}

# Everything is ok; create the account, and put an entry in the "category"
# database
dbmopen(%TXNS, $home.$name.".txn", 0666);
$CATS{"[$name]"} = "$description:";
dbmclose(TXNS);
dbmclose(CATS);

$ACCOUNTLIST{$name} = $description;
