summaryrefslogtreecommitdiff
path: root/utils/cli
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-11-02 06:18:13 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-11-02 06:18:13 +0000
commitbfd87158e4e0689ffc8759459fd24386b56ab8eb (patch)
tree04dbd4d7eb34393c9a9d9360d26582516d839cdb /utils/cli
parent5986bee212e6e15328b6b9fc24072c40864b35d1 (diff)
Mostly working CLI script host.
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@461 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'utils/cli')
-rw-r--r--utils/cli/ledgersmb_cli.pl34
-rw-r--r--utils/cli/sample.lsmb13
2 files changed, 30 insertions, 17 deletions
diff --git a/utils/cli/ledgersmb_cli.pl b/utils/cli/ledgersmb_cli.pl
index 995682b1..d279e958 100644
--- a/utils/cli/ledgersmb_cli.pl
+++ b/utils/cli/ledgersmb_cli.pl
@@ -30,12 +30,12 @@ $form = new Form;
$syntax = << '_END_SYNTAX_';
KEY : /\w[a-z0-9_]*/i
- FNKEY : /\w[a-z0-9_]*/i
- MODSTR: /\w[a-z0-9_:]*/i
+ MODSTR : /\w[a-z0-9_]*/i
+ FNKEY : /(?:\w|:)+/
OP : m([-+*/%])
NUMBER : /[+-]?\d*\.?\d+/
- ARGSTR : /\w[a-z0-9_,\s]*/i
+ ARGS : /(\w[a-z0-9_]*,?\s?)+/i
expression : NUMBER OP expression
{ return main::expression(@item) }
@@ -45,13 +45,13 @@ $syntax = << '_END_SYNTAX_';
| KEY
assign_instruction : KEY "=" expression
- { ${main::stackref}->{$item{key}} = $item{expression} }
+ { main::assignval($item{KEY}, $item{expression}) }
- call_and_assign : /call/i FNKEY(ARGSTR) /into/i KEY
+ call_and_assign : /call/i FNKEY '(' ARGS ')' /into/i KEY
{ main::call_and_assign($item{FNKEY}, $item{ARGSTR}, $item{KEY}) }
- call : /call/i FNKEY(ARGSTR)
- { main::call($item{FNKEY}, $item{ARGSTR}) }
+ FUNCTIONCALL : /call/i FNKEY '(' ARGS ')'
+ { main::call($item{FNKEY}, $item{ARGS})}
for : /for/i KEY
{ main::push_loop($item{KEY}) }
@@ -60,7 +60,7 @@ $syntax = << '_END_SYNTAX_';
{ main::pop_loop() }
if : /^\s*if/i KEY
- { main::if_handler($item{KEY} }
+ { main::if_handler($item{KEY}) }
# IF is terminated by END IF or FI on its own line
@@ -68,11 +68,11 @@ $syntax = << '_END_SYNTAX_';
{ main::login() }
module : /module/i MODSTR
- { main::load_mod($item{MODSTR} }
+ { main::load_mod($item{MODSTR}) }
instruction : assign_instruction
| call_and_assign
- | call
+ | FUNCTIONCALL
| for
| done
| if
@@ -85,9 +85,21 @@ _END_SYNTAX_
$::RD_HINT = 1;
$::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
$::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c.`
+#$::RD_TRACE = 1;
my $stackref;
my @loopstack;
+push @loopstack, $form;
+
+sub assignval {
+ my ($key, $value) = @_;
+ if ($key =~ /^ENV:/i){
+ $ENV{$key} = $value;
+ } else {
+ %{$loopstack[$#loopstack - 1]}->{$key} = $value;
+ }
+}
+
sub expression {
shift;
my ($lhs,$op,$rhs) = @_;
@@ -131,6 +143,7 @@ sub if_handler {
sub login {
$myconfig = new LedgerSMB::User
"${LedgerSMB::Sysconfig::memberfile}", "$form->{login}";
+ $form->db_init($myconfig);
}
sub load_mod {
@@ -142,6 +155,7 @@ sub load_mod {
my $scriptparse = new Parse::RecDescent($syntax);
while ($line = <>){
+ $line =~ s/#.*$//; # strip comments
$scriptparse->startrule($line);
}
diff --git a/utils/cli/sample.lsmb b/utils/cli/sample.lsmb
index 62b67fb0..6344c89f 100644
--- a/utils/cli/sample.lsmb
+++ b/utils/cli/sample.lsmb
@@ -1,7 +1,6 @@
-# THe below line shows how to set the PGUSER environment variable
-ENV:PGUSER=postgres
-login=demo # set username
-password=demo # set password
-LOGIN
-MODULE AR # load AR
-CALL AR::transactions(\%$form);
+ENV:PGUSER = postgres # how to set an environment variable
+login = demo # How to set a form variable
+password = demo
+LOGIN # Log in
+MODULE AR # Load a module
+CALL AR::transactions(form, user) # call a function