2000-05-10 04:32:00 -05:00
|
|
|
;; 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, contact:
|
|
|
|
;;
|
|
|
|
;; Free Software Foundation Voice: +1-617-542-5942
|
2005-11-16 23:35:02 -06:00
|
|
|
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
|
|
|
;; Boston, MA 02110-1301, USA gnu@gnu.org
|
2000-05-10 04:32:00 -05:00
|
|
|
|
2001-12-04 17:21:02 -06:00
|
|
|
(define-module (gnucash main))
|
|
|
|
|
2006-05-09 20:53:24 -05:00
|
|
|
;; This is to silence warnings with guile-1.8:
|
|
|
|
(if (and (>= (string->number (major-version)) 1)
|
|
|
|
(>= (string->number (minor-version)) 8))
|
|
|
|
(default-duplicate-binding-handler 'last))
|
2001-12-04 17:21:02 -06:00
|
|
|
(use-modules (ice-9 slib))
|
2002-01-09 16:12:03 -06:00
|
|
|
|
|
|
|
(use-modules (g-wrap gw-wct))
|
2005-11-01 21:32:36 -06:00
|
|
|
(use-modules (g-wrapped gw-core-utils))
|
2001-12-04 17:21:02 -06:00
|
|
|
(use-modules (g-wrapped gw-gnc))
|
|
|
|
|
2001-05-15 11:27:55 -05:00
|
|
|
;; Load the srfis (eventually, we should see where these are needed
|
|
|
|
;; and only have the use-modules statements in those files).
|
|
|
|
(use-modules (srfi srfi-1))
|
|
|
|
(use-modules (srfi srfi-8))
|
2001-12-04 17:21:02 -06:00
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
(use-modules (gnucash gnc-module))
|
2006-01-20 21:59:22 -06:00
|
|
|
|
2001-09-15 02:03:55 -05:00
|
|
|
(use-modules (ice-9 slib))
|
|
|
|
(require 'printf)
|
2001-05-15 11:27:55 -05:00
|
|
|
|
2001-12-11 10:48:01 -06:00
|
|
|
;; files we can load from the top-level because they're "well behaved"
|
|
|
|
;; (these should probably be in modules eventually)
|
|
|
|
(load-from-path "doc.scm")
|
2006-01-23 11:38:13 -06:00
|
|
|
(load-from-path "main-window.scm") ;; depends on app-utils (N_, etc.)...
|
|
|
|
(load-from-path "fin.scm")
|
2001-12-11 10:48:01 -06:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Exports
|
|
|
|
|
|
|
|
;; from main.scm
|
2001-12-04 17:21:02 -06:00
|
|
|
(export gnc:version)
|
|
|
|
(export gnc:warn)
|
|
|
|
(export gnc:error)
|
|
|
|
(export gnc:msg)
|
|
|
|
(export gnc:debug)
|
|
|
|
(export string-join)
|
|
|
|
(export gnc:backtrace-if-exception)
|
|
|
|
(export gnc:main)
|
2002-01-09 16:12:03 -06:00
|
|
|
(export gnc:safe-strcmp) ;; only used by aging.scm atm...
|
2001-12-04 17:21:02 -06:00
|
|
|
|
2004-06-26 10:30:04 -05:00
|
|
|
(re-export hash-fold)
|
|
|
|
(re-export string-split)
|
|
|
|
|
2001-12-04 17:21:02 -06:00
|
|
|
;; from command-line.scm
|
2001-12-11 10:48:01 -06:00
|
|
|
(export gnc:*doc-path*)
|
2001-12-04 17:21:02 -06:00
|
|
|
|
|
|
|
;; from doc.scm
|
|
|
|
(export gnc:find-doc-file)
|
|
|
|
|
|
|
|
;; from main-window.scm
|
2005-11-01 21:32:36 -06:00
|
|
|
(export gnc:main-window-properties-cb)
|
2001-12-04 17:21:02 -06:00
|
|
|
|
|
|
|
;; from printing/print-check.scm
|
|
|
|
(export make-print-check-format)
|
|
|
|
(export gnc:print-check)
|
|
|
|
|
|
|
|
;; Get the Makefile.am/configure.in generated variables.
|
|
|
|
(load-from-path "build-config.scm")
|
|
|
|
|
|
|
|
;; Do this stuff very early -- but other than that, don't add any
|
|
|
|
;; executable code until the end of the file if you can help it.
|
|
|
|
;; These are needed for a guile 1.3.4 bug
|
|
|
|
(debug-enable 'debug)
|
|
|
|
(read-enable 'positions)
|
|
|
|
|
|
|
|
(debug-set! maxdepth 100000)
|
2006-03-13 10:54:14 -06:00
|
|
|
(debug-set! stack 200000)
|
2001-12-04 17:21:02 -06:00
|
|
|
|
2001-10-14 12:53:23 -05:00
|
|
|
;;(use-modules (ice-9 statprof))
|
|
|
|
|
2001-12-04 17:21:02 -06:00
|
|
|
(define (gnc:setup-debugging)
|
|
|
|
(if (gnc:debugging?)
|
|
|
|
(debug-enable 'backtrace)))
|
|
|
|
|
|
|
|
;; various utilities
|
|
|
|
|
|
|
|
;; Test for simple-format
|
|
|
|
(if (not (defined? 'simple-format))
|
|
|
|
(begin
|
|
|
|
(require 'format)
|
|
|
|
(export simple-format)
|
|
|
|
(define simple-format format)))
|
|
|
|
|
2002-01-09 16:12:03 -06:00
|
|
|
(define (gnc:safe-strcmp a b)
|
|
|
|
(cond
|
|
|
|
(if (and a b)
|
|
|
|
(cond
|
|
|
|
((string<? a b) -1)
|
|
|
|
((string>? a b) 1)
|
|
|
|
(else 0))
|
|
|
|
(cond
|
|
|
|
(a 1)
|
|
|
|
(b -1)
|
|
|
|
(else 0)))))
|
|
|
|
|
2001-12-04 17:21:02 -06:00
|
|
|
(if (not (defined? 'hash-fold))
|
|
|
|
(define (hash-fold proc init table)
|
|
|
|
(for-each
|
|
|
|
(lambda (bin)
|
|
|
|
(for-each
|
|
|
|
(lambda (elt)
|
|
|
|
(set! init (proc (car elt) (cdr elt) init)))
|
|
|
|
bin))
|
|
|
|
(vector->list table))))
|
|
|
|
|
|
|
|
(define (string-join lst joinstr)
|
|
|
|
;; This should avoid a bunch of unnecessary intermediate string-appends.
|
|
|
|
;; I'm presuming those are more expensive than cons...
|
|
|
|
(if (or (not (list? lst)) (null? lst))
|
|
|
|
""
|
|
|
|
(apply string-append
|
|
|
|
(car lst)
|
|
|
|
(let loop ((remaining-elements (cdr lst)))
|
|
|
|
(if (null? remaining-elements)
|
|
|
|
'()
|
|
|
|
(cons joinstr (cons (car remaining-elements)
|
|
|
|
(loop (cdr remaining-elements)))))))))
|
|
|
|
|
|
|
|
(define (string-split str char)
|
|
|
|
(let ((parts '())
|
|
|
|
(first-char #f))
|
|
|
|
(let loop ((last-char (string-length str)))
|
|
|
|
(set! first-char (string-rindex str char 0 last-char))
|
|
|
|
(if first-char
|
|
|
|
(begin
|
|
|
|
(set! parts (cons (substring str (+ 1 first-char) last-char)
|
|
|
|
parts))
|
|
|
|
(loop first-char))
|
|
|
|
(set! parts (cons (substring str 0 last-char) parts))))
|
|
|
|
parts))
|
|
|
|
|
2001-12-11 10:48:01 -06:00
|
|
|
|
2001-12-04 17:21:02 -06:00
|
|
|
(define (gnc:backtrace-if-exception proc . args)
|
|
|
|
(define (dumper key . args)
|
|
|
|
(let ((stack (make-stack #t dumper)))
|
|
|
|
(display-backtrace stack (current-error-port))
|
|
|
|
(apply display-error stack (current-error-port) args)
|
|
|
|
(throw 'ignore)))
|
|
|
|
|
|
|
|
(catch
|
2001-12-11 10:48:01 -06:00
|
|
|
'ignore
|
|
|
|
(lambda ()
|
|
|
|
(lazy-catch #t
|
|
|
|
(lambda () (apply proc args))
|
|
|
|
dumper))
|
|
|
|
(lambda (key . args)
|
|
|
|
#f)))
|
2001-12-04 17:21:02 -06:00
|
|
|
|
|
|
|
;;;; Status output functions.
|
|
|
|
|
|
|
|
(define (gnc:warn . items)
|
|
|
|
(display "gnucash: [W] ")
|
|
|
|
(for-each (lambda (i) (write i)) items)
|
|
|
|
(newline))
|
|
|
|
|
|
|
|
(define (gnc:error . items)
|
|
|
|
(display "gnucash: [E] ")
|
|
|
|
(for-each (lambda (i) (write i)) items)
|
|
|
|
(newline))
|
|
|
|
|
|
|
|
(define (gnc:msg . items)
|
|
|
|
(display "gnucash: [M] ")
|
|
|
|
(for-each (lambda (i) (write i)) items)
|
|
|
|
(newline))
|
|
|
|
|
|
|
|
(define (gnc:debug . items)
|
|
|
|
(if (gnc:debugging?)
|
|
|
|
(begin
|
|
|
|
(display "gnucash: [D] ")
|
|
|
|
(for-each (lambda (i) (write i)) items)
|
|
|
|
(newline))))
|
|
|
|
|
|
|
|
|
|
|
|
;; Set up timing functions
|
|
|
|
|
|
|
|
(define gnc:*last-time* (gettimeofday))
|
|
|
|
|
|
|
|
(define (gnc:timestamp . stuff)
|
|
|
|
(let* ((now (gettimeofday))
|
|
|
|
(delta (+ (- (car now) (car gnc:*last-time*))
|
|
|
|
(/ (- (cdr now) (cdr gnc:*last-time*)) 1000000))))
|
|
|
|
(gnc:msg stuff "-- Elapsed time: " delta "seconds.")
|
|
|
|
(set! gnc:*last-time* now)))
|
|
|
|
|
1998-11-04 00:14:45 -06:00
|
|
|
(define (gnc:shutdown exit-status)
|
|
|
|
(gnc:debug "Shutdown -- exit-status: " exit-status)
|
2006-01-24 19:36:28 -06:00
|
|
|
(exit exit-status)) ;; Temporary Stub until command-line.scm dies
|
1998-11-04 00:14:45 -06:00
|
|
|
|
2002-12-08 04:54:42 -06:00
|
|
|
(define (gnc:strip-path path)
|
|
|
|
(let* ((parts-in (string-split path #\/))
|
2002-12-04 01:31:53 -06:00
|
|
|
(parts-out '()))
|
|
|
|
|
|
|
|
;; Strip out "." and ".." components
|
2002-12-08 04:54:42 -06:00
|
|
|
;; Strip out // components
|
2002-12-04 01:31:53 -06:00
|
|
|
(for-each
|
|
|
|
(lambda (part)
|
|
|
|
(cond ((string=? part ".") #f)
|
|
|
|
((string=? part "..") (set! parts-out (cdr parts-out)))
|
2002-12-08 04:54:42 -06:00
|
|
|
((and (string-null? part) (not (= (length parts-out) 0))) #f)
|
2002-12-04 01:31:53 -06:00
|
|
|
(else (set! parts-out (cons part parts-out)))))
|
|
|
|
parts-in)
|
|
|
|
|
|
|
|
;; Put it back together
|
2002-12-08 04:54:42 -06:00
|
|
|
(string-join (reverse parts-out) "/")))
|
|
|
|
|
1998-11-19 21:42:06 -06:00
|
|
|
(define (gnc:main)
|
1999-10-17 22:18:20 -05:00
|
|
|
|
2001-12-11 10:48:01 -06:00
|
|
|
;; (statprof-reset 0 50000) ;; 20 times/sec
|
|
|
|
;; (statprof-start)
|
2001-10-14 12:53:23 -05:00
|
|
|
|
1998-11-19 21:42:06 -06:00
|
|
|
;; Now the fun begins.
|
2006-01-22 21:43:55 -06:00
|
|
|
(gnc:debug "starting up (1).")
|
|
|
|
(gnc:setup-debugging)
|
|
|
|
|
|
|
|
;; Now we can load a bunch of files.
|
|
|
|
(load-from-path "command-line.scm") ;; depends on app-utils (N_, etc.)...
|
2006-01-24 22:54:12 -06:00
|
|
|
(load-from-path "printing/print-check.scm") ;; depends on simple-obj...
|
2006-01-22 21:43:55 -06:00
|
|
|
|
|
|
|
(gnc:initialize-config-vars) ;; in command-line.scm
|
|
|
|
;; handle unrecognized command line args
|
|
|
|
(if (not (gnc:handle-command-line-args))
|
|
|
|
(gnc:shutdown 1))
|
2006-01-12 19:25:12 -06:00
|
|
|
|
2006-01-18 23:54:16 -06:00
|
|
|
;;return to C
|
2006-01-22 21:56:10 -06:00
|
|
|
)
|