Matt Armstrong wrote:
> On Mon, 3 May 1999, Steve Varadi wrote:
> 
> > I try to import from my Quicken99 file. I got error:
> 
> What version of gnucash are you testing this with?
> 
> 
> > QIF Parse: Unsupported account type 401(k)
> > 
> > Error: Internal Error: SplitRebalance(): no common split currencies
> > Error:  account=Discover Card currency=(null) security=(null)
> > Error:  account=Home Improvm currency=(null) security=(null)
> > gnucash: Transaction.c:748: xaccSplitRebalance: Assertion `0' failed.
> > Aborted
> > bash-2.02# 
> > 
> > Is it any solution for this??
> 
> I think the assertion failure in Transaction.c should be fixed in the
> lastest version from CVS.  If you're feeling persistent, you could use the
> instructions on http://www.gnucash.org/?content=Source%20Code to get that
> source.
> 
> But, if you tested with gnucash-1.1.27 (from ftp.gnucash.org/pub/gnucash)
> and still got the "Assertion '0' failed" please let me know.  I'm the one
> that supposedly fixed that bug.  :-)
> 
> As for the "QIF Parse: Unsupported account type 401(k)" -- this is a bug
> in the QIF import.  GnuCash simply hasn't been told what to do with
> Quicken 401(k) accounts yet.
> 
> It is a personal mission of mine to get the QIF imports working well in
> GnuCash.  However, I haven't been able to spend any time on it, so I have
> failed my mission so far.

This, along with the diverse set of problems, as well as diverse .QIF formats, 
suggest to me that the QIF handling should probably *not* be hardcoded in C.

The following script is the beginnings of my thoughts of a way of
Scheming a converter up.   Using a scripting language for this task,
which can readily involve:
a) A need to customize the code;
b) Overflows of one sort or another;
c) Oddball requirements;
all suggests that Scheme is a good pick.

;;; Parse QIF

(load "c:/home/code/scheme/pltstd.scm")  ;;; Stuff for PLT Scheme.
(load "c:/home/code/scheme/substr.scm") ;;;  Load substring handler
                                        ;;; An efficient substring searcher...

(define (reload)
  (load "/home/cbbrowne/code/scheme/parseqif.scm"))

(define srcdir "/home/cbbrowne/")
(define destdir "/home/cbbrowne/qif/")
(define indir (directory-list srcdir))

(define fullname 
  (lambda (file)
    (string-append srcdir file)))

(define qifs (substring-search-maker ".qif"))

(define (processfile file)
  (let
      ((fullfilename (fullname file)))
    ;;    (write-line file)
    (if
     (eof-object? file)         ; Have we hit the end of the directory?
     #f
     (if (qifs file)  ; Is it a .qif file?
         (begin
           (write-line "Found QIF File")
           (rewrite-file file))))))

(define tlist '())
(define atrans '())
(define rewrite-file
  (lambda (file)    ; Opens file, rewrites all the lines, closes files
    (write-line "rewriting file:")
    (write-line file)
    (set! tlist '())   ; Reset the transaction list...
    (set! atrans '())
    (let*
        ((infile (open-input-file (string-append srcdir file)))
         (outfile (open-output-file (string-append destdir file) 'replace)))
      (begin
        (let loop
            ((line (read-line infile)))
              (cond
               ((eof-object? line) #f)
               (else
                (write-line line)
                (let
                    ((newline (rewrite-line line)))
                  (write-line newline)
                  (write newline outfile))
                (loop (read-line infile)))))
        (write "\n" outfile)
        (write tlist outfile)  ;  Output full transaction list to outfile
        (close-input-port infile)
        (close-output-port outfile)))))

;;; Rewrite a line
(define (fef filelist)
  (write-line (car filelist))
  (if
   (processfile (car filelist))  ; Handle the file
   (fef (cdr filelist))))

(define qifstate '())

(define rewrite-line 
  (lambda (line)
    (if
     (string=? (substring line 0 1) "!")   ;;; Starts with a !
     (newstate line))                      ;;; Jump to a new state...
    (if (equal? qifstate 'txn)             ;;; If it's a transaction
        (rewrite-txn-line (striptrailingwhitespace line)))))   ;;; Rewrite it
       ;;; otherwise, do nothing...

(define QIFstates       
  '(("!Type:Cat" . 'category)
    ("!Option:AutoSwitch" . 'accounts)
    ("!Clear:AutoSwitch"  . 'account)
    ("!Account" . 'accounts)
    ("!Type:Memorized" . 'memorized)
    ("!Type:Bank" . 'txn)
    ("!Type:CCard" . 'txn)
    ("!Type:Oth A" . 'txn)))


;;;;   Strip off trailing whitespace
(define (striptrailingwhitespace line)
  (let
      ((stringsize (string-length line)))
    (if
   (< stringsize 1)
    ""
    (let*
        ((lastchar (string-ref line (- stringsize 1))))
      (if
       (char-whitespace? lastchar)
       (striptrailingwhitespace (substring line 0  (- stringsize 1)))
       line)))))

(define (newstate line)
  (let*
       ((statepair (assoc (striptrailingwhitespace line) QIFstates)))
    (begin
      (if
       (pair? statepair)
       (begin
         (set! qifstate (car (cddr statepair)))
         ;       (write statepair)(write "Got new state:") (write qifstate)(write "\n")
         )
       (begin
         ;       (write "No state found - keep") (write qifstate)
         #f)))))

(define rewrite-txn-line 
  (lambda (line)
    (let*
        ((fchar (substring line 0 1))
         (first-char-matches? (lambda (x) (string=? fchar x))))
      (cond
       ((first-char-matches? "!") (write line)                      line)
       ((first-char-matches? "^") (write line) (transend line)      line)
       ((first-char-matches? "D") (write line) (transdate line)     line)
       ((first-char-matches? "T") (write line) (transamt line)      line)
       ((first-char-matches? "N") (write line) (transid line)       line)
       ((first-char-matches? "C") (write line) (transstatus line)   line)
       ((first-char-matches? "P") (write line) (transpayee line)    line)
       ((first-char-matches? "L") (write line) (transcategory line) line)
       ((first-char-matches? "U") (write "skip U\n") "")   ; Get rid of "U" lines
       (else line)))))

(define (transend line)   ; End of transaction
  (set! tlist (cons atrans tlist))
  (set! atrans '()))

(define (transdate line)
  (let*
      ((linelen (string-length line))
       (date    (substring line 1 linelen)))
    (set! atrans (cons (cons 'date (cons date '())) atrans ))))

(define (transamt line)
  (let*
      ((linelen (string-length line))
       (amount    (substring line 1 linelen)))
    (set! atrans (cons (cons 'amount (cons amount '())) atrans ))))

(define (transid line)
  (let*
      ((linelen (string-length line))
       (id    (substring line 1 linelen)))
    (set! atrans (cons (cons 'id (cons id '())) atrans ))))

(define (transstatus line)
  (let*
      ((linelen (string-length line))
       (status    (substring line 1 linelen)))
    (set! atrans (cons (cons 'status (cons status '())) atrans ))))

(define (transpayee line)
  (let*
      ((linelen (string-length line))
       (payee    (substring line 1 linelen)))
    (set! atrans (cons (cons 'payee (cons payee '())) atrans ))))
  
(define (transcategory line)
  (let*
      ((linelen (string-length line))
       (category    (substring line 1 linelen)))
    (set! atrans (cons (cons 'category (cons category '())) atrans ))))
  
(fef indir)
;;;; What should come  after this is something that walks
;;;; through tlist, and inserts transactions based on it.
--
Christopher B. Browne, [EMAIL PROTECTED], [EMAIL PROTECTED]
Web: http://www.ntlug.org/~cbbrowne  SAP Basis Consultant, UNIX Guy
Windows NT - How to make a 100 MIPS Linux workstation perform like an 8 MHz 286
----- %< -------------------------------------------- >% ------
The GnuCash / X-Accountant Mailing List
To unsubscribe, send mail to [EMAIL PROTECTED] and
put "unsubscribe gnucash-devel [EMAIL PROTECTED]" in the body

Reply via email to