mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
James LewisMoss's patch to pass unused command-line args to gnome_init.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3284 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
a50ed7498a
commit
3adc7c3cb2
@ -27,6 +27,7 @@
|
||||
#include <gnome.h>
|
||||
#include <gtkhtml/gtkhtml.h>
|
||||
#include <guile/gh.h>
|
||||
#include <popt.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "AccWindow.h"
|
||||
@ -38,6 +39,7 @@
|
||||
#include "Refresh.h"
|
||||
#include "SplitLedger.h"
|
||||
#include "TransLog.h"
|
||||
#include "argv-list-converters.h"
|
||||
#include "combocell.h"
|
||||
#include "date.h"
|
||||
#include "dialog-account.h"
|
||||
@ -134,6 +136,23 @@ gnc_get_ui_data(void)
|
||||
return app;
|
||||
}
|
||||
|
||||
static const char* gnc_scheme_remaining_var = "gnc:*command-line-remaining*";
|
||||
|
||||
static char**
|
||||
gnc_get_remaining_argv(int prelen, const char **prependargv)
|
||||
{
|
||||
SCM rem = gh_lookup(gnc_scheme_remaining_var);
|
||||
return gnc_scheme_list_to_nulltermcharpp(prelen, prependargv, rem);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_set_remaining_argv(int len, const char **rest)
|
||||
{
|
||||
SCM toput = gnc_argvarr_to_scheme_list(len, rest);
|
||||
gh_define(gnc_scheme_remaining_var, toput);
|
||||
}
|
||||
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
/* These gnucash_ui_init and gnucash_ui functions are just hacks to get
|
||||
@ -141,11 +160,19 @@ gnc_get_ui_data(void)
|
||||
what they should do soon, and expect that the open/select functions
|
||||
will be merged with the code in FMB_OPEN in MainWindow.c */
|
||||
|
||||
static const char *default_argv[] = {"gnucash", 0};
|
||||
|
||||
static const struct poptOption nullPoptTable[] = {
|
||||
{ NULL, 0, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
int
|
||||
gnucash_ui_init(void)
|
||||
{
|
||||
int fake_argc = 1;
|
||||
char *fake_argv[] = {"gnucash"};
|
||||
int restargc;
|
||||
char **restargv;
|
||||
char **restargv2;
|
||||
poptContext returnedPoptContext;
|
||||
|
||||
ENTER ("\n");
|
||||
|
||||
@ -153,9 +180,27 @@ gnucash_ui_init(void)
|
||||
specific args... */
|
||||
if (!gnome_is_initialized)
|
||||
{
|
||||
gnome_init("GnuCash", NULL, fake_argc, fake_argv);
|
||||
restargv = gnc_get_remaining_argv(1, default_argv);
|
||||
if(restargv == NULL)
|
||||
{
|
||||
restargv = g_new(char*, 2);
|
||||
restargv[0] = g_strdup(default_argv[0]);
|
||||
restargv[1] = NULL;
|
||||
}
|
||||
|
||||
restargc = argv_length(restargv);
|
||||
|
||||
gnome_init_with_popt_table("GnuCash", NULL, restargc, restargv,
|
||||
nullPoptTable, 0, &returnedPoptContext);
|
||||
gnome_is_initialized = TRUE;
|
||||
|
||||
restargv2 = (char**)poptGetArgs(returnedPoptContext);
|
||||
gnc_set_remaining_argv(argv_length(restargv2), (const char**)restargv2);
|
||||
gh_eval_str("(gnc:load-account-file)");
|
||||
|
||||
/* this must come after using the poptGetArgs return value */
|
||||
gnc_free_argv(restargv);
|
||||
|
||||
gnc_component_manager_init ();
|
||||
|
||||
/* initialization required for gtkhtml */
|
||||
|
@ -17,7 +17,70 @@
|
||||
|
||||
;; also "-c"
|
||||
|
||||
(define gnc:*command-line-files* #f)
|
||||
(define gnc:*command-line-remaining* #f)
|
||||
|
||||
;;(use-modules (ice-9 getopt-long))
|
||||
|
||||
;;(define (gnc:is-boolean-arg? arg)
|
||||
;; (if (or (string=? arg "true") (string=? arg "false")) #t #f))
|
||||
|
||||
;;(define (gnc:is-integer-arg? arg)
|
||||
;; (if (string->number arg) #t #f))
|
||||
|
||||
;;(define (gnc:convert-arg-to-boolean arg)
|
||||
;; (if (string=? arg "true")
|
||||
;; #t
|
||||
;; (if (string=? arg "false")
|
||||
;; #f
|
||||
;; 'abort)))
|
||||
|
||||
;;(define (gnc:convert-arg-to-integer arg)
|
||||
;; (let ((value (string->number arg)))
|
||||
;; (if (and (not value) (not (exact? value)))
|
||||
;; 'abort
|
||||
;; value)))
|
||||
|
||||
;;(define (gnc:convert-arg-defs-to-opt-args arg-defs)
|
||||
;; (letrec ((return '())
|
||||
;; (decide-single-char
|
||||
;; (let ((single-char-cache '()))
|
||||
;; (lambda (name)
|
||||
;; (let ((possible (string-ref name 0)))
|
||||
;; (if (eq? (assv possible single-char-cache) #f)
|
||||
;; (begin
|
||||
;; (set! single-char-cache (acons possible #t
|
||||
;; single-char-cache))
|
||||
;; possible)
|
||||
;; #f)))))
|
||||
;; (create-arg-list
|
||||
;; (lambda (name-sym value pred sc)
|
||||
;; (let ((ret `(,name-sym (value ,value))))
|
||||
;; (if (not (eq? pred #f))
|
||||
;; (set! ret (append ret (cons 'predicate pred))))
|
||||
;; (if (not (eq? sc #f))
|
||||
;; (set! ret (append ret (cons 'single-char sc))))
|
||||
;; ret)))
|
||||
;; (helper
|
||||
;; (lambda (arg-defs ret)
|
||||
;; (if (not (pair? arg-defs))
|
||||
;; ret
|
||||
;; (helper
|
||||
;; (cdr arg-defs)
|
||||
;; (cons
|
||||
;; (let* ((one-arg (car arg-defs))
|
||||
;; (arg-name (car one-arg))
|
||||
;; (arg-sym (string->symbol arg-name))
|
||||
;; (arg-oc (decide-single-char arg-name)))
|
||||
;; (case (cadr one-arg)
|
||||
;; ((boolean) (create-arg-list arg-sym 'optional
|
||||
;; gnc:is-boolean-arg?
|
||||
;; arg-oc))
|
||||
;; ((integer) (create-arg-list arg-sym #t
|
||||
;; gnc:is-integer-arg?
|
||||
;; arg-oc))
|
||||
;; ((string) (create-arg-list arg-sym #t #f arg-oc))))
|
||||
;; ret))))))
|
||||
;; (helper arg-defs return)))
|
||||
|
||||
(define gnc:*arg-defs*
|
||||
(list
|
||||
@ -150,11 +213,41 @@
|
||||
(define (gnc:prefs-show-usage)
|
||||
(display "usage: gnucash [ option ... ] [ datafile ]") (newline))
|
||||
|
||||
;;(define (gnc:handle-command-line-args)
|
||||
;; (letrec ((internal
|
||||
;; (lambda ()
|
||||
;; (getopt-long (program-arguments)
|
||||
;; (gnc:convert-arg-defs-to-opt-args gnc:*arg-defs*))))
|
||||
;; (arg-handler
|
||||
;; (lambda (args)
|
||||
;; (if (pair? args)
|
||||
;; (begin
|
||||
;; (let ((one-arg (car args)))
|
||||
;; (if (eq? (car one-arg) '())
|
||||
;; (set! gnc:*command-line-remaining* (cdr one-arg))
|
||||
;; (let* ((arg-name (symbol->string (car one-arg)))
|
||||
;; (arg-stuff (assoc-ref gnc:*arg-defs* arg-name)))
|
||||
;; (case (car arg-stuff)
|
||||
;; ((string)
|
||||
;; ((cdr arg-stuff) (cdr one-arg)))
|
||||
;; ((integer)
|
||||
;; ((cdr arg-stuff) (gnc:convert-arg-to-integer
|
||||
;; (cdr one-arg))))
|
||||
;; ((boolean)
|
||||
;; ((cdr arg-stuff) (gnc:convert-arg-to-boolean
|
||||
;; (cdr one-arg))))))))
|
||||
;; (arg-handler (cdr args)))))))
|
||||
;; (display "Converted") (newline)
|
||||
;; (display (gnc:convert-arg-defs-to-opt-args gnc:*arg-defs*)) (newline)
|
||||
;; (flush-all-ports)
|
||||
;; (arg-handler (internal)))
|
||||
;; #t)
|
||||
|
||||
|
||||
(define (gnc:handle-command-line-args)
|
||||
(gnc:debug "handling command line arguments" (program-arguments))
|
||||
|
||||
(let ((files-to-open '())
|
||||
(let ((remaining-arguments '())
|
||||
(result #t))
|
||||
|
||||
(do ((rest (cdr (program-arguments))) ; initial cdr skips argv[0]
|
||||
@ -172,7 +265,7 @@
|
||||
(begin
|
||||
(gnc:debug "non-option " item ", assuming file")
|
||||
(set! rest (cdr rest))
|
||||
(set! files-to-open (cons item files-to-open)))
|
||||
(set! remaining-arguments (cons item remaining-arguments)))
|
||||
|
||||
(if (string=? "--" item)
|
||||
;; ignore --
|
||||
@ -188,6 +281,8 @@
|
||||
;;(set! quit? #t))
|
||||
(display "Ignoring unused option ")(display arg-string)
|
||||
(newline)
|
||||
(set! remaining-arguments
|
||||
(cons item remaining-arguments))
|
||||
(set! rest (cdr rest)))
|
||||
|
||||
(let* ((arg-type (car arg-def))
|
||||
@ -210,8 +305,8 @@
|
||||
((cdr arg-def) parsed-value)
|
||||
(set! rest remaining-args)))))))))
|
||||
(if result
|
||||
(gnc:debug "files to open: " files-to-open))
|
||||
(gnc:debug "files to open: " remaining-arguments))
|
||||
|
||||
(set! gnc:*command-line-files* files-to-open)
|
||||
(set! gnc:*command-line-remaining* remaining-arguments)
|
||||
|
||||
result))
|
||||
|
@ -99,6 +99,14 @@
|
||||
(gnc:debug "UI Shutdown hook.")
|
||||
(gnc:file-quit))
|
||||
|
||||
(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))))
|
||||
|
||||
(define (gnc:main)
|
||||
|
||||
;; Now the fun begins.
|
||||
@ -118,12 +126,8 @@
|
||||
|
||||
(if (null? gnc:*batch-mode-things-to-do*)
|
||||
;; We're not in batch mode; we can go ahead and do the normal thing.
|
||||
(let ((ok (not (gnc:config-var-value-get gnc:*arg-no-file*)))
|
||||
(file (if (pair? gnc:*command-line-files*)
|
||||
(car gnc:*command-line-files*)
|
||||
(gnc:history-get-last))))
|
||||
(if (and ok (string? file))
|
||||
(gnc:ui-open-file file))
|
||||
(begin
|
||||
;; (gnc:load-account-file)
|
||||
(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))
|
||||
|
Loading…
Reference in New Issue
Block a user