summaryrefslogtreecommitdiff
path: root/utils/cli/ledgersmb_cli.pl
blob: 82a9785bb91fb4d918ee4c80293008907d01de8a (plain)
  1. #!/usr/bin/perl
  2. #===========================================================================
  3. #
  4. # LedgerSMB Command-line script host
  5. #
  6. #
  7. # LedgerSMB
  8. # Small Medium Business Accounting software
  9. # http://www.ledgersmb.org/
  10. #
  11. #
  12. # Copyright (C) 2006
  13. # This work contains copyrighted information from a number of sources all used
  14. # with permission. It is released under the GNU General Public License
  15. # Version 2 or, at your option, any later version. See COPYRIGHT file for
  16. # details.
  17. #
  18. # This is a simple wrapper that allows you to write simple scripts with LSMB
  19. # See sample for the file format.
  20. #
  21. # THIS IS EXPERIMENTAL AND THE INTERFACE IS SUBJECT TO CHANGE
  22. use LedgerSMB::User;
  23. use LedgerSMB::Form;
  24. use LedgerSMB::Sysconfig;
  25. $form = new Form;
  26. while ($line = <>){
  27. $line =~ s/#.*//; # strip out comments
  28. if ($line =~ /^\s*CALL\s+(.+)\s+INTO\s+(.+)/i){
  29. $form->{$2} = &{$1}(\%$form);
  30. } elsif ($line =~ /^\s*MODULE (.+)/i){
  31. $module = $1;
  32. $module =~ s/::/\//;
  33. eval { require $module; };
  34. } elsif ($line =~ /^\s*ENV:(.+)\s*=\s*(.*)/i){
  35. my ($key, $value) = ($1, $2);
  36. $key =~ s/\s?(.*)\s?/$1/;
  37. $value =~ s/\s?(.*)\s?/$1/;
  38. $ENV{$1} = $2;
  39. } elsif ($line =~ /^\s*(.+)\s*=\s*(.+)/){
  40. $form->{$1} = $2;
  41. } elsif ($line =~ /^\s*CALL\s+(.+)/i){
  42. {$1};
  43. } elsif ($line =~ /^\s*LOGIN\s*/i){
  44. $myconfig = new LedgerSMB::User
  45. "${LedgerSMB::Sysconfig::memberfile}", "$form->{login}";
  46. } elsif ($line !~ /^\s*$/) {
  47. die "Parse error in script file: $line";
  48. }
  49. }
  50. delete $form->{password};
  51. for (keys %$form){
  52. print "$_ = $form->{$_}\n";
  53. }