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
|
|
|
|
;; 59 Temple Place - Suite 330 Fax: +1-617-542-2652
|
|
|
|
;; Boston, MA 02111-1307, USA gnu@gnu.org
|
|
|
|
|
2000-10-23 04:41:51 -05:00
|
|
|
;; A list of things to do when in batch mode after the initial
|
|
|
|
;; startup. List items may be strings, in wich case they're read and
|
|
|
|
;; evaluated or procedures, in which case they're just executed.
|
|
|
|
;; The items will be done in reverse order.
|
|
|
|
(define gnc:*batch-mode-things-to-do* '())
|
2000-08-07 13:30:25 -05:00
|
|
|
|
1998-11-04 00:14:45 -06:00
|
|
|
(define (gnc:startup)
|
|
|
|
(gnc:debug "starting up.")
|
1998-11-19 21:42:06 -06:00
|
|
|
(if (not (gnc:handle-command-line-args))
|
|
|
|
(gnc:shutdown 1))
|
1999-12-30 18:05:41 -06:00
|
|
|
|
2000-03-13 00:56:27 -06:00
|
|
|
(gnc:setup-debugging)
|
|
|
|
|
1999-12-30 18:05:41 -06:00
|
|
|
;; Load the srfis
|
|
|
|
(gnc:load "srfi/srfi-8.guile.scm")
|
|
|
|
(gnc:load "srfi/srfi-1.unclear.scm")
|
|
|
|
(gnc:load "srfi/srfi-1.r5rs.scm")
|
|
|
|
|
1998-11-19 21:42:06 -06:00
|
|
|
;; Now we can load a bunch of files.
|
1999-12-30 18:05:41 -06:00
|
|
|
|
|
|
|
(gnc:depend "doc.scm")
|
2000-02-27 16:14:58 -06:00
|
|
|
(gnc:depend "extensions.scm")
|
1999-12-30 18:05:41 -06:00
|
|
|
(gnc:depend "text-export.scm")
|
|
|
|
(gnc:depend "report.scm")
|
2000-10-23 04:41:51 -05:00
|
|
|
(gnc:depend "commodity-import.scm")
|
2000-03-05 18:17:25 -06:00
|
|
|
(gnc:depend "report/report-list.scm")
|
2000-03-31 03:41:07 -06:00
|
|
|
(gnc:depend "qif-import/qif-import.scm")
|
|
|
|
(gnc:depend "printing/print-check.scm")
|
2000-03-16 01:12:49 -06:00
|
|
|
|
2000-02-06 23:27:35 -06:00
|
|
|
;; Load the system configs
|
1998-11-19 21:42:06 -06:00
|
|
|
(if (not (gnc:load-system-config-if-needed))
|
|
|
|
(gnc:shutdown 1))
|
1999-12-30 18:05:41 -06:00
|
|
|
|
2000-02-06 23:27:35 -06:00
|
|
|
;; Load the user configs
|
|
|
|
(gnc:load-user-config-if-needed)
|
|
|
|
|
|
|
|
;; Clear the change flags caused by loading the configs
|
|
|
|
(gnc:global-options-clear-changes)
|
1998-12-01 03:02:47 -06:00
|
|
|
|
1998-11-19 21:42:06 -06:00
|
|
|
(gnc:hook-run-danglers gnc:*startup-hook*)
|
1999-12-30 18:05:41 -06:00
|
|
|
|
2000-10-03 04:40:53 -05:00
|
|
|
;; Initialize the C side options code. Must come after the scheme
|
|
|
|
;; options are loaded.
|
|
|
|
(gnc:c-options-init)
|
|
|
|
|
|
|
|
;; Initialize the expresion parser. Must come after the C side
|
|
|
|
;; options initialization.
|
2000-09-11 06:09:49 -05:00
|
|
|
(gnc:exp-parser-init)
|
|
|
|
|
1999-12-30 18:05:41 -06:00
|
|
|
(if (gnc:config-var-value-get gnc:*arg-show-version*)
|
|
|
|
(begin
|
|
|
|
(gnc:prefs-show-version)
|
|
|
|
(gnc:shutdown 0)))
|
|
|
|
|
1998-11-19 21:42:06 -06:00
|
|
|
(if (or (gnc:config-var-value-get gnc:*arg-show-usage*)
|
|
|
|
(gnc:config-var-value-get gnc:*arg-show-help*))
|
|
|
|
(begin
|
|
|
|
(gnc:prefs-show-usage)
|
2000-06-05 01:18:20 -05:00
|
|
|
(gnc:shutdown 0)))
|
|
|
|
|
|
|
|
(if (gnc:config-var-value-get gnc:*loglevel*)
|
|
|
|
(gnc:set-log-level-global (gnc:config-var-value-get gnc:*loglevel*))))
|
1998-11-04 00:14:45 -06:00
|
|
|
|
2000-02-06 23:27:35 -06:00
|
|
|
|
1998-11-04 00:14:45 -06:00
|
|
|
(define (gnc:shutdown exit-status)
|
|
|
|
(gnc:debug "Shutdown -- exit-status: " exit-status)
|
1999-10-17 22:18:20 -05:00
|
|
|
|
|
|
|
(cond ((gnc:ui-is-running?)
|
|
|
|
(if (not (gnc:ui-is-terminating?))
|
|
|
|
(begin
|
2000-03-19 19:16:00 -06:00
|
|
|
(gnc:ui-destroy-all-subwindows)
|
|
|
|
(if (gnc:file-query-save)
|
|
|
|
(begin
|
|
|
|
(gnc:hook-run-danglers gnc:*ui-shutdown-hook*)
|
|
|
|
(gnc:ui-shutdown))))))
|
|
|
|
(else
|
1999-10-17 22:18:20 -05:00
|
|
|
(gnc:ui-destroy)
|
2000-02-27 16:14:58 -06:00
|
|
|
(gnc:hook-run-danglers gnc:*shutdown-hook*)
|
2000-12-12 04:51:53 -06:00
|
|
|
(gnc:engine-shutdown)
|
1999-10-17 22:18:20 -05:00
|
|
|
(exit exit-status))))
|
|
|
|
|
|
|
|
(define (gnc:ui-finish)
|
|
|
|
(gnc:debug "UI Shutdown hook.")
|
|
|
|
(gnc:file-quit))
|
1998-11-04 00:14:45 -06:00
|
|
|
|
2000-12-11 17:05:54 -06:00
|
|
|
(define (gnc:load-account-file)
|
|
|
|
(let ((ok (not (gnc:config-var-value-get gnc:*arg-no-file*)))
|
|
|
|
(file (if (pair? gnc:*command-line-remaining*)
|
|
|
|
(car gnc:*command-line-remaining*)
|
|
|
|
(gnc:history-get-last))))
|
|
|
|
(if (and ok (string? file))
|
|
|
|
(gnc:ui-open-file file))))
|
|
|
|
|
1998-11-19 21:42:06 -06:00
|
|
|
(define (gnc:main)
|
1999-10-17 22:18:20 -05:00
|
|
|
|
1998-11-19 21:42:06 -06:00
|
|
|
;; Now the fun begins.
|
|
|
|
(gnc:startup)
|
2000-10-03 04:40:53 -05:00
|
|
|
|
1999-05-29 18:46:49 -05:00
|
|
|
(if (not (= (gnc:lowlev-app-init) 0))
|
1998-11-19 21:42:06 -06:00
|
|
|
(gnc:shutdown 0))
|
2000-09-11 06:09:49 -05:00
|
|
|
|
|
|
|
;; add a hook to shut down the expression parser
|
|
|
|
(gnc:hook-add-dangler gnc:*shutdown-hook* gnc:exp-parser-shutdown)
|
|
|
|
|
2000-02-06 23:27:35 -06:00
|
|
|
;; add a hook to save the user configs on shutdown
|
|
|
|
(gnc:hook-add-dangler gnc:*shutdown-hook* gnc:save-global-options)
|
2000-08-07 13:30:25 -05:00
|
|
|
|
2000-11-29 13:00:33 -06:00
|
|
|
;; add a hook to shut down the C side options code
|
2000-10-03 04:40:53 -05:00
|
|
|
(gnc:hook-add-dangler gnc:*shutdown-hook* gnc:c-options-shutdown)
|
|
|
|
|
2000-10-23 04:41:51 -05:00
|
|
|
(if (null? gnc:*batch-mode-things-to-do*)
|
2000-08-07 13:30:25 -05:00
|
|
|
;; We're not in batch mode; we can go ahead and do the normal thing.
|
2000-12-11 17:05:54 -06:00
|
|
|
(begin
|
|
|
|
;; (gnc:load-account-file)
|
2000-08-07 13:30:25 -05:00
|
|
|
(gnc:hook-add-dangler gnc:*ui-shutdown-hook* gnc:ui-finish)
|
|
|
|
(gnc:ui-main)
|
|
|
|
(gnc:hook-remove-dangler gnc:*ui-shutdown-hook* gnc:ui-finish))
|
|
|
|
|
|
|
|
;; else: we're in batch mode. Just do what the user said on the
|
|
|
|
;; command line
|
2000-10-23 04:41:51 -05:00
|
|
|
(map handle-batch-mode-item (reverse gnc:*batch-mode-things-to-do*)))
|
2000-08-07 13:30:25 -05:00
|
|
|
|
1998-11-19 21:42:06 -06:00
|
|
|
(gnc:shutdown 0))
|