home *** CD-ROM | disk | FTP | other *** search
/ Chip: Linux Special / CorelLinux_CHIP.iso / live / usr / X11R6 / lib / X11 / cbb / wrapper.pl < prev   
Encoding:
Perl Script  |  1998-10-07  |  12.9 KB  |  354 lines

  1. #!/usr/bin/perl
  2. #  wrapper.pl - a command parsing wrapper for the CBB 'engine'.
  3. #
  4. #  Written by Curtis Olson.  Started August 22, 1994.
  5. #
  6. #  Copyright (C) 1994 - 1997  Curtis L. Olson  - curt@sledge.mn.org
  7. #
  8. #  This program is free software; you can redistribute it and/or modify
  9. #  it under the terms of the GNU General Public License as published by
  10. #  the Free Software Foundation; either version 2 of the License, or
  11. #  (at your option) any later version.
  12. #
  13. #  This program is distributed in the hope that it will be useful,
  14. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #  GNU General Public License for more details.
  17. #
  18. #  You should have received a copy of the GNU General Public License
  19. #  along with this program; if not, write to the Free Software
  20. #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. # $Id: wrapper.pl,v 2.11 1998/08/14 14:28:43 curt Exp $
  23. # (Log is kept at end of this file)
  24.  
  25.  
  26. package CBB;
  27.  
  28. use strict;    # don't take no guff
  29.  
  30.  
  31. # specify the installed location of the necessary pieces.
  32. $CBB::cbb_incl_dir = "/usr/X11R6/lib/X11/cbb";
  33. unshift(@INC, $CBB::cbb_incl_dir);
  34.  
  35. require "engine.pl";
  36. require "categories.pl";
  37. require "file.pl";
  38. require "memorized.pl";
  39. require "import.pl";
  40. require "export.pl";
  41.  
  42.  
  43. sub BEGIN {
  44.     $CBB::logging = 1;        # 0 = off,  1 = on
  45.     $CBB::debug = 0;        # 0 = off,  1 = on
  46.  
  47.     if ( $ENV{"OS"} ne "Windows_NT" ) {
  48.         # get user name
  49.         @CBB::pw = getpwuid($<);
  50.  
  51.         $CBB::user_name = $CBB::pw[0]
  52.         || $ENV{LOGNAME} || die "No user name!";
  53.     } else {
  54.     $CBB::user_name = "ruut";
  55.     }
  56.  
  57.     $CBB::current_file = "";
  58.  
  59.     $CBB::encrypt = "";
  60.     $CBB::decrypt = "";
  61.  
  62.     # set umask to 066 (only owner should be able to read this)
  63.     umask(066);
  64. }
  65.  
  66.  
  67. &main_loop();
  68.  
  69.  
  70. # main command parsing loop
  71. sub main_loop {
  72.     my($arg, $command, $full_command);
  73.  
  74.     while (<>) {
  75.     chop;
  76.  
  77.     $full_command = $_;
  78.     print DEBUG "Command string:  '$full_command'\n" if $CBB::debug;
  79.  
  80.     if ( m/ / ) {
  81.         ($command, $arg) = split(/ /, $full_command, 2);
  82.     } else {
  83.         ($command, $arg) = ($full_command, "");
  84.     }
  85.  
  86.     if ($command eq "create_trans") {
  87.         print DEBUG "calling create_trans($arg)\n" if $CBB::debug;
  88.         print &create_trans($arg)."\n";
  89.         &log_txn($full_command) if $CBB::logging;
  90.     } elsif ($command eq "create_xfer") {
  91.         print DEBUG "calling create_xfer($arg)\n" if $CBB::debug;
  92.         print &create_xfer($arg)."\n";
  93.         &log_txn($full_command) if $CBB::logging;
  94.     } elsif ($command eq "update_trans") {
  95.         print DEBUG "calling update_trans($arg)\n" if $CBB::debug;
  96.         print &update_trans($arg)."\n";
  97.         &log_txn($full_command) if $CBB::logging;
  98.     } elsif ($command eq "update_xfer") {
  99.         print DEBUG "calling update_xfer($arg)\n" if $CBB::debug;
  100.         print &update_xfer($arg)."\n";
  101.         &log_txn($full_command) if $CBB::logging;
  102.     } elsif ($command eq "delete_trans") {
  103.         print DEBUG "calling delete_trans($arg)\n" if $CBB::debug;
  104.         print &delete_trans($arg)."\n";
  105.         &log_txn($full_command) if $CBB::logging;
  106.     } elsif ($command eq "delete_xfer") {
  107.         print DEBUG "calling delete_xfer($arg)\n" if $CBB::debug;
  108.         print &delete_xfer($arg)."\n";
  109.         &log_txn($full_command) if $CBB::logging;
  110.     } elsif ($command eq "next_trans") {
  111.         print DEBUG "next_trans()\n" if $CBB::debug;
  112.         print &next_trans()."\n";
  113.     } elsif ($command eq "prev_trans") {
  114.         print "prev_trans()\n";
  115.     } elsif ($command eq "find_trans") {
  116.         print DEBUG "find_trans($arg)\n" if $CBB::debug;
  117.         print &find_trans($arg)."\n";
  118.     } elsif ($command eq "get_current_index") {
  119.         print DEBUG "get_current_index()\n" if $CBB::debug;
  120.         print &get_current_index()."\n";
  121.     } elsif ($command eq "first_trans") {
  122.         print DEBUG "first_trans()\n" if $CBB::debug;
  123.         print &first_trans()."\n";
  124.     } elsif ($command eq "all_trans") {
  125.         print DEBUG "all_trans($arg)\n" if $CBB::debug;
  126.         print &all_trans($arg)."\n";
  127.     } elsif ($command eq "part_trans") {
  128.         print DEBUG "part_trans($arg)\n" if $CBB::debug;
  129.         print &part_trans($arg)."\n";
  130.     } elsif ($command eq "last_trans") {
  131.         print "last_trans()\n";
  132.     } elsif ($command eq "first_uncleared_trans") {
  133.         print DEBUG "first_uncleared_trans()\n" if $CBB::debug;
  134.         print &first_uncleared_trans()."\n";
  135.     } elsif ($command eq "last_uncleared_trans") {
  136.         print "last_uncleared_trans()\n";
  137.     } elsif ($command eq "next_uncleared_trans") {
  138.         print DEBUG "next_uncleared_trans()\n" if $CBB::debug;
  139.         print &next_uncleared_trans()."\n";
  140.     } elsif ($command eq "prev_uncleared_trans") {
  141.         print "prev_uncleared_trans()\n";
  142.     } elsif ($command eq "select_trans") {
  143.         print DEBUG "select_trans()\n" if $CBB::debug;
  144.         print &select_trans($arg)."\n";
  145.         &log_txn($full_command) if $CBB::logging;
  146.     } elsif ($command eq "unselect_trans") {
  147.         print DEBUG "unselect_trans()\n" if $CBB::debug;
  148.         print &unselect_trans($arg)."\n";
  149.         &log_txn($full_command) if $CBB::logging;
  150.     } elsif ($command eq "clear_trans") {
  151.         print DEBUG "clear_trans()\n" if $CBB::debug;
  152.         print &clear_trans()."\n";
  153.         &log_txn($full_command) if $CBB::logging;
  154.     } elsif ($command eq "get_cleared_bal") {
  155.         print DEBUG "get_cleared_bal()\n" if $CBB::debug;
  156.         print &get_cleared_bal()."\n";
  157.     } elsif ($command eq "sort_trans") {
  158.         print "sort_trans()\n";
  159.     } elsif ($command eq "init_trans") {
  160.         print DEBUG "calling init_trans()\n" if $CBB::debug;
  161.         print &init_trans()."\n";
  162.     } elsif ($command eq "make_acct") {
  163.         print DEBUG "calling make_acct($arg)\n" if $CBB::debug;
  164.         print &make_acct($arg)."\n";
  165.         &log_txn($full_command) if $CBB::logging;
  166.     } elsif ($command eq "load_trans") {
  167.         print DEBUG "calling load_trans($arg)\n" if $CBB::debug;
  168.         print &load_trans($arg)."\n";
  169.         &log_txn($full_command) if $CBB::logging;
  170.     } elsif ($command eq "load_cbb") {
  171.         print DEBUG "calling load_cbb($arg)\n" if $CBB::debug;
  172.         print &load_cbb($arg)."\n";
  173.         &log_txn($full_command) if $CBB::logging;
  174.     } elsif ($command eq "import_qif") {
  175.         print DEBUG "calling import_qif($arg)\n" if $CBB::debug;
  176.         print &import_qif($arg)."\n";
  177.         &log_txn($full_command) if $CBB::logging;
  178.     } elsif ($command eq "save_cbb") {
  179.         print DEBUG "calling save_cbb($arg)\n" if $CBB::debug;
  180.         print &save_cbb($arg)."\n";
  181.         &log_txn($full_command) if $CBB::logging;
  182.     } elsif ($command eq "export_qif") {
  183.         print DEBUG "calling export_qif($arg)\n" if $CBB::debug;
  184.         print &export_qif($arg)."\n";
  185.         &log_txn($full_command) if $CBB::logging;
  186.     } elsif ($command eq "save_trans") {
  187.         print DEBUG "calling save_trans($arg)\n" if $CBB::debug;
  188.         print &save_trans($arg)."\n";
  189.         &log_txn($full_command) if $CBB::logging;
  190.     } elsif ($command eq "auto_save_trans") {
  191.         print DEBUG "calling auto_save_trans($arg)\n" if $CBB::debug;
  192.         &save_trans($arg);
  193.     } elsif ($command eq "rehash_mems") {
  194.         print DEBUG "calling rehash_mems()\n" if $CBB::debug;
  195.         print &rehash_mems()."\n";
  196.     } elsif ($command eq "find_mem") {
  197.         print DEBUG "calling find_mem($arg)\n" if $CBB::debug;
  198.         print &find_mem($arg)."\n";
  199.     } elsif ($command eq "init_cats") {
  200.         print DEBUG "calling init_cats()\n" if $CBB::debug;
  201.         print &init_cats()."\n";
  202.     } elsif ($command eq "edit_cat") {
  203.         print DEBUG "calling edit_cat($arg)\n" if $CBB::debug;
  204.         print &edit_cat($arg)."\n";
  205.         &log_txn($full_command) if $CBB::logging;
  206.     } elsif ($command eq "insert_cat") {
  207.         print DEBUG "calling insert_cat($arg)\n" if $CBB::debug;
  208.         print &insert_cat($arg)."\n";
  209.         &log_txn($full_command) if $CBB::logging;
  210.     } elsif ($command eq "delete_cat") {
  211.         print DEBUG "calling delete_cat($arg)\n" if $CBB::debug;
  212.         print &delete_cat($arg)."\n";
  213.         &log_txn($full_command) if $CBB::logging;
  214.     } elsif ($command eq "all_cats") {
  215.         print DEBUG "calling all_cats()\n";
  216.         print &all_cats()."\n";
  217.     } elsif ($command eq "find_cat") {
  218.         print DEBUG "calling find_cat($arg)\n";
  219.         print &find_cat($arg)."\n";
  220.     } elsif ($command eq "get_cat_info") {
  221.         print DEBUG "calling get_cat_info($arg)\n";
  222.         print &get_cat_info($arg)."\n";
  223.     } elsif ($command eq "load_cats") {
  224.         print DEBUG "calling load_cats($arg)\n" if $CBB::debug;
  225.         print &load_cats($arg)."\n";
  226.     } elsif ($command eq "load_dbm_cats") {
  227.         print DEBUG "calling load_dbm_cats($arg)\n" if $CBB::debug;
  228.         print &load_dbm_cats($arg)."\n";
  229.     } elsif ($command eq "save_cats") {
  230.         print DEBUG "calling save_cats($arg)\n" if $CBB::debug;
  231.         print &save_cats($arg)."\n";
  232.     } elsif ($command eq "rep_txn_list") {
  233.         print DEBUG "calling rep_txn_list($arg)\n" if $CBB::debug;
  234.         print &rep_txn_list($arg)."\n";
  235.     } elsif ($command eq "rep_txn_by_cat") {
  236.         print DEBUG "calling rep_txn_by_cat($arg)\n" if $CBB::debug;
  237.         print &rep_txn_by_cat($arg)."\n";
  238.     } elsif ($command eq "rep_txn_by_cat_short") {
  239.         print DEBUG "calling rep_txn_by_cat_short($arg)\n" if $CBB::debug;
  240.         print &rep_txn_by_cat_short($arg)."\n";
  241.     } elsif ($command eq "nice_date") {
  242.         print DEBUG "calling nice_date($arg)\n" if $CBB::debug;
  243.         print &nice_date($arg)."\n";
  244.     } elsif ($command eq "raw_date") {
  245.         print DEBUG "calling raw_date()\n" if $CBB::debug;
  246.         print &raw_date()."\n";
  247.     } elsif ($command eq "start_date") {
  248.         print DEBUG "calling start_date()\n" if $CBB::debug;
  249.         print &start_date($arg)."\n";
  250.     } elsif ($command eq "century") {
  251.         print DEBUG "calling century()\n" if $CBB::debug;
  252.         print ¢ury()."\n";
  253.     } elsif ($command eq "get_files") {
  254.         print DEBUG "get_files($arg)\n" if $CBB::debug;
  255.         print &get_files($arg)."\n";
  256.     } elsif ($command eq "debug") {
  257.         print DEBUG "debug($arg)\n" if $CBB::debug;
  258.         print &debug($arg)."\n";
  259.     } elsif ($command eq "cache") {
  260.         print DEBUG "cache($arg)\n" if $CBB::debug;
  261.         $CBB::cache = int($arg);
  262.         print $CBB::cache . "\n";
  263.     } elsif ($command eq "encrypt") {
  264.         print DEBUG "encrypt($arg)\n" if $CBB::debug;
  265.         $CBB::encrypt = $arg;
  266.         print $CBB::encrypt . "\n";
  267.     } elsif ($command eq "decrypt") {
  268.         print DEBUG "decrypt($arg)\n" if $CBB::debug;
  269.         $CBB::decrypt = $arg;
  270.         print $CBB::decrypt . "\n";
  271.     } elsif ($command eq "logging") {
  272.         print DEBUG "logging($arg)\n" if $CBB::debug;
  273.         $CBB::logging = int($arg);
  274.         print $CBB::logging . "\n";
  275.     } elsif ($command eq "quit") {
  276.         print DEBUG "exiting\n" if $CBB::debug;
  277.         exit(0);
  278.     } else {
  279.         # unknown command ... return error
  280.         print DEBUG "unknown command\n" if $CBB::debug;
  281.         print "error\n";
  282.     }
  283.     }
  284. }
  285.  
  286.  
  287. 1;                # need to return a true value
  288.  
  289.  
  290. # ----------------------------------------------------------------------------
  291. # $Log: wrapper.pl,v $
  292. # Revision 2.11  1998/08/14 14:28:43  curt
  293. # Added desc-pie graph.
  294. # Added option to eliminate splash screen.
  295. # Other misc. tweaks and bug fixes.
  296. #
  297. # Revision 2.10  1997/05/06 01:00:29  curt
  298. # Added patches contributed by Martin Schenk <schenkm@ping.at>
  299. # - Default to umask of 066 so .CBB files get created rw by owner only
  300. # - Added support for pgp encrypting data files
  301. # - Added support for displaying only recent parts of files (avoids
  302. #   waiting to load in lots of old txns you don't currently need.)
  303. # - Added a feature to "cache" whole accounts in the perl engine so
  304. #   that switching between accounts can be faster.
  305. # - The above options can be turned on/off via the preferrences menu.
  306. #
  307. # Revision 2.9  1997/01/18 03:28:46  curt
  308. # Added "use strict" pragma to enforce good scoping habits.
  309. #
  310. # Revision 2.8  1997/01/10 22:03:33  curt
  311. # Transfer fixups and a few other misc. fixes contributed by
  312. #   Lionel Mallet <Lionel.Mallet@sophia.inria.fr>
  313. #
  314. # Revision 2.7  1996/12/17 14:54:04  curt
  315. # Updated copyright date.
  316. #
  317. # Revision 2.6  1996/10/03 04:49:01  curt
  318. # Fixed an inconsistency in &raw_date() in common.pl (with how it was
  319. # called.)
  320. #
  321. # Version now is 0.67-beta-x
  322. #
  323. # Revision 2.5  1996/10/03 03:52:59  curt
  324. # CBB now determines the current century automatically ... no need for it
  325. # to be hard coded.  Removed all hardcoded instances of the century (especially
  326. # in reports.pl and recur.pl)
  327. #
  328. # Added an optional --debug flag to the invocation of CBB.
  329. #
  330. # Revision 2.4  1996/10/02 19:37:20  curt
  331. # Replaced instances of hardcoded century (19) with a variable.  We need to
  332. # know the current century in cases where it is not provided and it is
  333. # assumed to be the current century.  Someday I need to figure out how
  334. # to determine the current century, but I have a couple of years to do it. :-)
  335. #
  336. # I still need to fix conf-reports and reports.pl
  337. #
  338. # Revision 2.3  1996/07/13 02:57:53  curt
  339. # Version 0.65
  340. # Packing Changes
  341. # Documenation changes
  342. # Changes to handle a value in both debit and credit fields.
  343. #
  344. # Revision 2.2  1996/03/03  00:16:11  curt
  345. # Modified Files:  cbb categories.pl wrapper.pl file.tk main.tk menu.tk
  346. #   Added an account list at the bottom of the screen.  Thanks to:
  347. #   Cengiz Alaettinoglu <cengiz@ISI.EDU> for this great addition.
  348. #
  349. # Revision 2.1  1996/02/27  05:35:52  curt
  350. # Just stumbling around a bit with cvs ... :-(
  351. #
  352. # Revision 2.0  1996/02/27  04:43:06  curt
  353. # Initial 2.0 revision.  (See "Log" files for old history.)
  354.