home *** CD-ROM | disk | FTP | other *** search
/ Enter 2000 February / Enter2_2.iso / live / usr / X11R6 / lib / X11 / cbb / contrib / importcat.pl < prev    next >
Encoding:
Perl Script  |  1998-10-07  |  2.0 KB  |  93 lines

  1. #!/usr/bin/perl
  2. # importcat.pl - program to convert quicken category
  3. #                files to a cbb format category file.
  4. #                Uses categories.pl.
  5. #
  6. # Usage: importcat.pl <file> [category file]
  7. #
  8. #        where "file" is a Quicken exported .qif file of categories
  9. #        and "category file" is an optional name of the CBB format
  10. #        category file, which defaults to "categories" if omitted.
  11. #
  12. # Written by Brian D. Wright
  13. # Based on:
  14. #     import.pl - functions to implement importing from other formats
  15. #     Written by Curtis Olson.  Started August 25, 1994.
  16. #     Copyright (C) 1994, 1995, 1996  Curtis L. Olson  - curt@sledge.mn.org
  17. #
  18. # v.0.1 9/22/96
  19.  
  20.  
  21. # specify the installed location of the necessary pieces.
  22. $cbb_incl_dir = "..";
  23. unshift(@INC, $cbb_incl_dir);
  24.  
  25. require "common.pl";
  26. require "categories.pl";
  27.  
  28. $infile = $ARGV[0];
  29. $outfile = $ARGV[1];
  30. if ($outfile eq "") {
  31.     $outfile = "categories";
  32. }
  33. &init_cats;
  34. &import_cat($infile);
  35. &save_cats($outfile);
  36.  
  37. # import a quicken category export file (.qif)
  38. sub import_cat {
  39.     # in: file
  40.     # out: result
  41.  
  42.     local($file) = @_;
  43.  
  44.     open(QIF, "<$file");
  45.  
  46.     ($key, $desc, $tax) = ("", "", "");
  47.  
  48.     while ( <QIF> ) {
  49.     chop;            # get rid of that pesky newline.
  50.     s/\r//g;        # strip the dos ^M if needed
  51.     if ( m/^\!/ ) {
  52.         # Type
  53.         # print "$_\n";
  54.     } elsif ( m/^N/ ) {
  55.         # Name
  56.         $key = substr($_,1);
  57.         # print "$key\n";
  58.     } elsif ( m/^D/ ) {
  59.         # Description
  60.         $desc = substr($_,1);
  61.         # print "$desc\n";
  62.     } elsif ( m/^T/ ) {
  63.         # Tax-related
  64.         $tax = "x";
  65.         # print "$tax\n";
  66.     } elsif ( m/^R/ ) {
  67.         # Junk??
  68.     } elsif ( m/^I/ ) {
  69.         # Income
  70.     } elsif ( m/^E/ ) {
  71.         # Expense
  72.     } elsif ( m/^\^/ ) {
  73.         #print "End of record\n";
  74.         $CATS{$key} = "$desc\t$tax";
  75.         ($key, $desc, $tax) = ("", "", "");
  76.     } elsif ( $_ eq "" ) {
  77.         # toss empty lines ...
  78.     } else {
  79.         print "unknown data: $_\n";
  80.     }
  81.     }
  82.  
  83.     close(QIF);
  84.  
  85.     return "ok";
  86. }
  87.  
  88.  
  89. 1;                # need to return a true value
  90.  
  91. # End importcat.pl
  92.  
  93.