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
2001-12-04 17:21:02 -06:00
( define-module ( gnucash main ) )
( use-modules ( ice-9 slib ) )
2002-01-09 16:12:03 -06:00
( use-modules ( g-wrap gw-wct ) )
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 ) )
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" )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Exports
;; from main.scm
2001-12-04 17:21:02 -06:00
( export gnc:version )
( export gnc:debugging? )
( export gnc:warn )
( export gnc:error )
( export gnc:msg )
( export gnc:debug )
( export build-path )
( export gnc:use-module-here! )
( export hash-fold )
( export item-list->hash! )
( export string-split )
( export string-join )
( export gnc:backtrace-if-exception )
2001-12-11 10:48:01 -06:00
( export gnc:find-file )
( export gnc:find-localized-file )
2001-12-04 17:21:02 -06:00
( 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
;; from path.scm
( export gnc:make-home-dir )
( export gnc:current-config-auto )
2004-06-18 11:45:10 -05:00
( export gnc:current-saved-reports )
2001-12-04 17:21:02 -06:00
;; from command-line.scm
2001-12-11 10:48:01 -06:00
( export gnc:*config-path* )
( export gnc:*share-path* )
( export gnc:*doc-path* )
2003-07-03 17:40:18 -05:00
( export gnc:*namespace-regexp* )
2001-12-04 17:21:02 -06:00
;; from doc.scm
( export gnc:find-doc-file )
( export gnc:load-help-topics )
;; from main-window.scm
( export gnc:find-acct-tree-window-options )
( export gnc:make-new-acct-tree-window )
( export gnc:free-acct-tree-window )
( export gnc:main-window-save-state )
2004-06-21 15:25:12 -05:00
( export gnc:main-window-save-report )
2001-12-04 17:21:02 -06:00
;; from printing/print-check.scm
( export make-print-check-format )
( export gnc:print-check )
;; from tip-of-the-day.scm
( export gnc:get-current-tip )
( export gnc:increment-tip-number )
( export gnc:decrement-tip-number )
;; 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 )
( debug-set! stack 2000000 )
2001-10-14 12:53:23 -05:00
;;(use-modules (ice-9 statprof))
2003-02-07 09:19:03 -06:00
;;
;; A flag: is this a development version? This will flag whether or not
;; to print out various 'development version' strings throughout the code.
;; #t == development version, #f == stable version
;;
;; NOTE: You still need to comment out the message in tip-list.scm by hand!
;;
( define gnc:*is-development-version?* #t )
2000-10-23 04:41:51 -05:00
;; A list of things to do when in batch mode after the initial
2001-08-07 18:29:04 -05:00
;; startup. List items may be strings, in which case they're read and
2000-10-23 04:41:51 -05:00
;; evaluated or procedures, in which case they're just executed.
;; The items will be done in reverse order.
2001-12-04 17:21:02 -06:00
2000-10-23 04:41:51 -05:00
( define gnc:*batch-mode-things-to-do* ' ( ) )
2000-08-07 13:30:25 -05:00
2001-12-04 17:21:02 -06:00
;; These will be converted to config vars later (see command-line.scm)
( define gnc:*debugging?* ( if ( getenv "GNC_DEBUG" ) #t #f ) )
( define gnc:*develmode* ( if ( getenv "GNC_DEVEL_MODE" ) #t #f ) )
;; Function to get debugging
( define ( gnc:debugging? )
( if ( boolean? gnc:*debugging?* )
gnc:*debugging?*
( gnc:config-var-value-get gnc:*debugging?* ) ) )
( 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 ) ) )
( define gnc:use-guile-module-here!
;; FIXME: this should be a temporary fix. We need to check to see
;; if there's a more approved way to do this. As I recall, there's
;; not, but I belive a better way will be added to Guile soon.
;; module arg must be something like '(ice-9 slib)
( cond
( ( or ( string=? "1.3" ( version ) )
( string=? "1.3.4" ( version ) )
2002-11-21 14:34:36 -06:00
( string=? "1.4" ( substring ( version ) 0 3 ) ) )
2001-12-04 17:21:02 -06:00
( lambda ( module )
( process-use-modules ( list module ) ) ) )
( else
( lambda ( module )
( process-use-modules ( list ( list module ) ) ) ) ) ) )
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 ( item-list->hash! lst hash
getkey getval
hashref hashset
list-duplicates? )
;; Takes a list of the form (item item item item) and returns a hash
;; formed by traversing the list, and getting the key and val from
;; each item using the supplied get-key and get-val functions, and
;; building a hash table from the result using the given hashref and
;; hashset functions. list-duplicates? determines whether or not in
;; the resulting hash, the value for a given key is a list of all
;; the values associated with that key in the input or just the
;; first one encountered.
( define ( handle-item item )
( let* ( ( key ( getkey item ) )
( val ( getval item ) )
( existing-val ( hashref hash key ) ) )
( if ( not list-duplicates? )
;; ignore if not first value.
( if ( not existing-val ) ( hashset hash key val ) )
;; else result is list.
( if existing-val
( hashset hash key ( cons val existing-val ) )
( hashset hash key ( list val ) ) ) ) ) )
2001-12-11 10:48:01 -06:00
2001-12-04 17:21:02 -06:00
( for-each handle-item lst )
hash )
( 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
( define ( gnc:flatten tree )
( let ( ( result ' ( ) ) )
( let loop ( ( remaining-items tree ) )
( cond
( ( null? remaining-items ) #t )
( ( list? remaining-items )
( loop ( car remaining-items ) )
( loop ( cdr remaining-items ) ) )
( else
( set! result ( cons remaining-items result ) ) ) ) )
( reverse! result ) ) )
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 ) ) )
2001-12-11 10:48:01 -06:00
( define ( build-path . elements )
( string-join elements "/" ) )
2001-12-04 17:21:02 -06:00
2001-12-11 10:48:01 -06:00
( define ( gnc:find-file file directories )
2001-12-04 17:21:02 -06:00
" Find file named 'file ' anywhere in 'directories ' . 'file ' must be a
string and 'directories ' must be a list of strings . "
2001-12-11 10:48:01 -06:00
( gnc:debug "gnc:find-file looking for " file " in " directories )
2001-12-04 17:21:02 -06:00
( do ( ( rest directories ( cdr rest ) )
( finished? #f )
( result #f ) )
( ( or ( null? rest ) finished? ) result )
( let ( ( file-name ( build-path ( car rest ) file ) ) )
( gnc:debug " checking for " file-name )
( if ( access? file-name F_OK )
( begin
( gnc:debug "found file " file-name )
( set! finished? #t )
( set! result file-name ) ) ) ) ) )
2001-12-11 10:48:01 -06:00
( define ( gnc:find-localized-file file base-directories )
;; Find file in path in base directories, or in any localized subdir
;; thereof.
( define ( locale-prefixes )
2002-05-18 15:32:22 -05:00
;; Mac OS X. 10.1 and earlier don't have LC_MESSAGES. Fall back to
;; LC_ALL for those systems.
( let* ( ( locale ( or ( false-if-exception ( setlocale LC_MESSAGES ) )
( setlocale LC_ALL ) ) )
2003-04-03 10:15:34 -06:00
( strings ( cond ( ( not ( string? locale ) ) ' ( ) )
( ( equal? locale "C" ) ' ( ) )
2002-04-05 02:00:43 -06:00
( ( <= ( string-length locale ) 4 ) ( list locale ) )
( else ( list ( substring locale 0 2 )
( substring locale 0 5 )
locale ) ) ) ) )
2001-12-11 10:48:01 -06:00
( reverse ( cons "C" strings ) ) ) )
( let loop ( ( prefixes ( locale-prefixes ) )
( dirs base-directories ) )
( if ( null? dirs )
#f
( or ( gnc:find-file file ( map ( lambda ( prefix )
2001-12-12 02:38:35 -06:00
( build-path ( car dirs ) prefix ) )
2001-12-11 10:48:01 -06:00
prefixes ) )
2001-12-12 02:38:35 -06:00
( gnc:find-file file ( list ( car dirs ) ) )
2001-12-11 10:48:01 -06:00
( loop prefixes ( cdr dirs ) ) ) ) ) )
2001-09-15 02:03:55 -05:00
( define ( gnc:print-unstable-message )
2003-02-07 09:19:03 -06:00
( if
gnc:*is-development-version?*
( display
( string-append
"\n\n"
( _ "This is a development version. It may or may not work.\n" )
( _ "Report bugs and other problems to gnucash-devel@gnucash.org.\n" )
( _ "You can also lookup and file bug reports at http://bugzilla.gnome.org\n" )
2004-04-13 01:10:27 -05:00
( _ "The last stable version was " ) "GnuCash 1.8.9" "\n"
2003-05-11 09:25:44 -05:00
( _ "The next stable version will be " ) "GnuCash 1.10 or 2.0"
2003-02-07 09:19:03 -06:00
"\n\n" ) ) ) )
2001-09-15 02:03:55 -05:00
2002-09-14 13:10:42 -05:00
( define ( gnc:startup-pass-1 )
( gnc:debug "starting up (1)." )
2000-03-13 00:56:27 -06:00
( gnc:setup-debugging )
2002-10-03 12:39:03 -05:00
;; before doing ANYTHING, set the locale!
2002-12-28 03:52:09 -06:00
( false-if-exception ( setlocale LC_ALL "" ) )
2002-10-03 12:39:03 -05:00
2001-08-07 18:29:04 -05:00
;; initialize the gnucash module system
( gnc:module-system-init )
2001-11-16 14:53:52 -06:00
;; SUPER UGLY HACK -- this should go away when I come back for the
;; second cleanup pass...
( let ( ( original-module ( current-module ) )
2001-12-04 17:21:02 -06:00
( bootstrap ( resolve-module ' ( gnucash main ) ) ) )
2001-11-16 14:53:52 -06:00
( set-current-module bootstrap )
( gnc:module-load "gnucash/app-utils" 0 )
2001-11-28 16:40:35 -06:00
( gnc:setup-gettext )
2002-09-14 13:10:42 -05:00
;; Now we can load a bunch of files.
( load-from-path "path.scm" )
( load-from-path "command-line.scm" ) ;; depends on app-utils (N_, etc.)...
)
( gnc:initialize-config-vars )
( if ( not ( gnc:handle-command-line-args ) )
( gnc:shutdown 1 ) )
( if ( gnc:config-var-value-get gnc:*arg-show-version* )
( begin
( gnc:prefs-show-version )
( gnc:shutdown 0 ) ) )
( 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 )
( gnc:shutdown 0 ) ) ) )
( define ( gnc:startup-pass-2 )
( gnc:debug "starting up (2)." )
;; initialize the gnucash module system
( gnc:module-system-init )
;; SUPER UGLY HACK -- this should go away when I come back for the
;; second cleanup pass...
( let ( ( original-module ( current-module ) )
( bootstrap ( resolve-module ' ( gnucash main ) ) ) )
2002-09-14 13:24:15 -05:00
( define ( load-module name vers optional? )
2002-09-17 02:47:15 -05:00
( let ( ( str ( string-append ( _ "Loading modules... " ) name ) ) )
2002-09-14 13:24:15 -05:00
( gnc:update-splash-screen str )
( if optional?
( gnc:module-load-optional name vers )
( gnc:module-load name vers ) ) ) )
2002-09-14 13:10:42 -05:00
( set-current-module bootstrap )
;; right now we have to statically load all these at startup time.
;; Hopefully we can gradually make them autoloading.
2002-09-14 13:24:15 -05:00
( load-module "gnucash/engine" 0 #f )
( load-module "gnucash/app-file" 0 #f )
( load-module "gnucash/register/ledger-core" 0 #f )
( load-module "gnucash/register/register-core" 0 #f )
( load-module "gnucash/register/register-gnome" 0 #f )
( load-module "gnucash/import-export/binary-import" 0 #f )
( load-module "gnucash/import-export/qif-import" 0 #f )
( load-module "gnucash/import-export/ofx" 0 #t )
2003-09-16 16:50:24 -05:00
( load-module "gnucash/import-export/mt940" 0 #t )
2003-05-28 23:47:54 -05:00
( load-module "gnucash/import-export/log-replay" 0 #t )
2002-09-14 13:24:15 -05:00
( load-module "gnucash/import-export/hbci" 0 #t )
( load-module "gnucash/report/report-system" 0 #f )
( load-module "gnucash/report/stylesheets" 0 #f )
( load-module "gnucash/report/standard-reports" 0 #f )
( load-module "gnucash/report/utility-reports" 0 #f )
( load-module "gnucash/report/locale-specific/us" 0 #f )
( load-module "gnucash/report/report-gnome" 0 #f )
( load-module "gnucash/business-gnome" 0 #t )
2001-11-16 14:53:52 -06:00
2001-12-11 10:48:01 -06:00
;; files we should be able to load from the top-level because
;; they're "well behaved" (these should probably be in modules
;; eventually)
( load-from-path "main-window.scm" ) ;; depends on app-utils (N_, etc.)...
( load-from-path "tip-of-the-day.scm" ) ;; depends on app-utils (config-var...)
( load-from-path "printing/print-check.scm" ) ;; depends on simple-obj...
2002-07-11 00:17:04 -05:00
;; +jsled - 2002.07.08
( load-from-path "fin.scm" )
2001-12-11 10:48:01 -06:00
2002-12-07 18:21:25 -06:00
( gnc:update-splash-screen ( _ "Checking Finance::Quote..." ) )
( gnc:use-guile-module-here! ' ( gnucash price-quotes ) )
( let ( ( sources ( gnc:fq-check-sources ) ) )
( if ( list? sources )
2003-07-01 22:35:20 -05:00
( gnc:quote-source-set-fq-installed sources ) ) )
2002-12-07 18:21:25 -06:00
2002-09-17 02:47:15 -05:00
( gnc:update-splash-screen ( _ "Loading tip-of-the-day..." ) )
2001-12-11 10:48:01 -06:00
( gnc:initialize-tip-of-the-day )
2001-11-16 14:53:52 -06:00
( set-current-module original-module ) )
2001-08-07 18:29:04 -05:00
2001-09-21 06:46:50 -05:00
( gnc:hook-add-dangler gnc:*book-opened-hook*
2002-07-07 19:13:12 -05:00
( lambda ( session )
2001-09-21 06:46:50 -05:00
( if ( ( gnc:option-getter
( gnc:lookup-global-option
"Scheduled Transactions"
"Run on GnuCash start" ) ) )
2002-07-07 19:13:12 -05:00
( gnc:sx-since-last-run-wrapper
( gnc:session-get-url session ) ) ) ) )
2001-09-21 06:46:50 -05:00
( gnc:hook-add-dangler gnc:*new-book-hook*
( lambda ( )
( let ( ( option ( gnc:lookup-global-option
"General"
"No account list setup on new file" ) ) )
( if ( and option ( not ( gnc:option-value option ) ) )
( gnc:ui-hierarchy-druid ) ) ) ) )
2000-02-06 23:27:35 -06:00
;; Load the system configs
2002-09-17 02:47:15 -05:00
( gnc:update-splash-screen ( _ "Loading 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
2001-09-13 05:02:03 -05:00
( gnc:report-menu-setup )
2001-12-20 05:04:44 -06:00
;; add the menu option to edit style sheets
( gnc:add-extension
( gnc:make-menu-item
2002-09-30 18:59:34 -05:00
( N_ "_Style Sheets..." )
( N_ "Edit report style sheets." )
2002-12-01 18:19:45 -06:00
( list gnc:window-name-main "_Edit" "_Preferences..." )
2001-12-20 05:04:44 -06:00
( lambda ( )
( gnc:style-sheet-dialog-open ) ) ) )
2002-10-06 12:28:53 -05:00
;; the Welcome to GnuCash "extravaganza" report
2001-12-20 05:04:44 -06:00
( gnc:add-extension
( gnc:make-menu-item
2002-10-06 12:28:53 -05:00
( N_ "Welcome Sample Report" )
( N_ "Welcome-to-GnuCash report screen" )
2002-09-01 21:52:26 -05:00
( list gnc:window-name-main gnc:menuname-reports gnc:menuname-utility "" )
2001-12-20 05:04:44 -06:00
( lambda ( )
( gnc:main-window-open-report ( gnc:make-welcome-report ) #f ) ) ) )
2004-06-21 15:25:12 -05:00
;; The "save current report" entry
( gnc:add-extension
( gnc:make-menu-item
( N_ "_Save all current reports" )
( N_ "Save all the current report in ~/.gnucash/saved-reports-1.8 so that they are accessible as menu entries in the report menu. Effects are only visible at next startup of gnucash." )
( list gnc:window-name-main "_File" "_Export" )
( lambda ( )
( gnc:main-window-save-report ) ) ) )
1998-11-19 21:42:06 -06:00
( gnc:hook-run-danglers gnc:*startup-hook* )
1999-12-30 18:05:41 -06:00
2000-06-05 01:18:20 -05:00
( 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? ) )
2001-04-15 18:07:30 -05:00
( if ( gnc:file-query-save )
( begin
( gnc:hook-run-danglers gnc:*ui-shutdown-hook* )
2001-12-21 01:45:32 -06:00
( gnc:gui-shutdown ) ) ) ) )
2000-03-19 19:16:00 -06:00
( else
2001-12-21 01:45:32 -06:00
( gnc:gui-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 ) ) ) )
2001-12-21 01:45:32 -06:00
( define ( gnc:gui-finish )
1999-10-17 22:18:20 -05:00
( gnc:debug "UI Shutdown hook." )
( gnc:file-quit ) )
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 ) "/" ) ) )
( define ( gnc:normalize-path file )
( let* ( ( parts-in ( string-split file #\/ ) )
( parts-out ' ( ) ) )
;; Convert to a path based at the root. If the filename starts
;; with a '/' then the first component of the list is a null
;; string. If the path starts with foo:// then the first
;; component will contain a ':' and the second will be null.
( cond ( ( string-null? ( car parts-in ) )
( gnc:strip-path file ) )
( ( and ( string=? ( car parts-in ) "file:" )
( string-null? ( cadr parts-in ) ) )
( gnc:strip-path file ) )
( ( and ( string-index ( car parts-in ) #\: )
( string-null? ( cadr parts-in ) ) )
file )
( else
2002-12-09 00:44:09 -06:00
( gnc:strip-path ( string-append ( getenv "PWD" ) "/" file ) ) ) )
2002-12-04 01:31:53 -06:00
)
)
2001-04-25 02:46:13 -05:00
( define ( gnc:account-file-to-load )
2000-12-11 17:05:54 -06:00
( 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 ) ) ) )
2002-12-04 01:31:53 -06:00
( and ok ( string? file ) ( gnc:normalize-path file ) ) ) )
2001-04-25 02:46:13 -05:00
( define ( gnc:load-account-file )
( let ( ( file ( gnc:account-file-to-load ) ) )
2002-09-17 02:47:15 -05:00
( if file
( begin
( gnc:update-splash-screen ( _ "Loading data..." ) )
( and ( not ( gnc:file-open-file file ) )
( gnc:hook-run-danglers gnc:*book-opened-hook* #f ) ) )
2001-04-24 18:11:15 -05:00
( gnc:hook-run-danglers gnc:*book-opened-hook* #f ) ) ) )
2000-12-11 17:05:54 -06:00
1998-11-19 21:42:06 -06:00
( define ( gnc:main )
1999-10-17 22:18:20 -05:00
2000-12-13 19:49:10 -06:00
( define ( handle-batch-mode-item item )
2003-05-24 18:39:50 -05:00
( let ( ( old-eval? ( or ( string=? "1.3" ( version ) )
( string=? "1.3.4" ( version ) )
( string=? "1.4" ( substring ( version ) 0 3 ) ) ) ) )
( cond
( ( procedure? item ) ( item ) )
( ( string? item )
( call-with-input-string
item
( lambda ( port )
( let loop ( ( next-form ( read port ) ) )
( if ( not ( eof-object? next-form ) )
( begin
;; FIXME: is this where we want to eval these?
;; should we perhaps have a (gnucash user)?
( if old-eval?
( eval next-form )
( eval next-form ( resolve-module ' ( gnucash main ) ) ) )
( loop ( read port ) ) ) ) ) ) ) )
( else
( display "gnucash: unknown batch-mode item - ignoring." )
( newline ) ) ) ) )
2000-12-13 19:49:10 -06: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.
2002-09-14 13:10:42 -05:00
( gnc:startup-pass-1 )
2001-09-15 02:03:55 -05:00
( gnc:print-unstable-message )
2002-09-14 13:10:42 -05:00
( if ( null? gnc:*batch-mode-things-to-do* )
( begin
( gnc:hook-add-dangler gnc:*ui-shutdown-hook* gnc:gui-finish )
( set! gnc:*command-line-remaining*
( gnc:gui-init-splash gnc:*command-line-remaining* ) ) ) )
( gnc:startup-pass-2 )
2000-09-11 06:09:49 -05:00
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
2001-12-21 01:45:32 -06:00
( gnc:hook-add-dangler gnc:*ui-shutdown-hook* gnc:gui-finish )
( set! gnc:*command-line-remaining*
( gnc:gui-init gnc:*command-line-remaining* ) )
2001-01-11 16:32:22 -06:00
( if ( and
2001-04-25 02:46:13 -05:00
( not ( gnc:account-file-to-load ) )
2001-01-11 16:32:22 -06:00
( not ( string? ( gnc:history-get-last ) ) )
2001-06-17 01:35:54 -05:00
( gnc:option-value
( gnc:lookup-global-option "__new_user" "first_startup" ) ) )
2002-10-05 12:11:04 -05:00
( begin
( gnc:destroy-splash-screen )
( gnc:new-user-dialog ) )
2002-09-17 02:47:15 -05:00
( begin
( gnc:load-account-file )
( gnc:destroy-splash-screen ) ) )
2003-01-19 22:18:39 -06:00
( gnc:hook-run-danglers gnc:*ui-post-startup-hook* )
2001-09-21 06:46:50 -05:00
( gnc:start-ui-event-loop )
2001-12-21 01:45:32 -06:00
( gnc:hook-remove-dangler gnc:*ui-shutdown-hook* gnc:gui-finish ) )
2001-04-25 02:46:13 -05:00
2000-08-07 13:30:25 -05:00
;; 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* ) ) )
2001-04-25 02:46:13 -05:00
1998-11-19 21:42:06 -06:00
( gnc:shutdown 0 ) )