Commit feb0e084199fb46a40a769d11a23843969deb0e8
Make config file configurable
Charles Lehner committed on 4/13/2016, 7:19:05 PMParent: 3ba59a872b934d08858db3732c17e2ed208b5b4b
Files changed
freecheck | changed |
freecheck | |||
---|---|---|---|
@@ -31,12 +31,8 @@ | |||
31 | 31 … | use Getopt::Long; | |
32 | 32 … | use File::Copy qw(copy); | |
33 | 33 … | ||
34 | 34 … | ||
35 | -if ( ! -e $ConfigFile ) { | ||
36 | - copy $systemConfigFile, $ConfigFile; | ||
37 | -} | ||
38 | - | ||
39 | 35 … | # This tells us how to format the strings from the cfg file | |
40 | 36 … | # so we can print it as a PostScript definition | |
41 | 37 … | # The key read will replace "value" for each of these | |
42 | 38 … | # Strings are enclosed in parentheses (String) (Foobar) | |
@@ -113,9 +109,10 @@ | |||
113 | 109 … | ); | |
114 | 110 … | ||
115 | 111 … | # Parse command line options and deal with them: | |
116 | 112 … | ||
117 | -GetOptions ("account:s", # Account definition file | ||
113 … | +GetOptions ("config:s", # Config file | ||
114 … | + "account:s", # Account definition name | ||
118 | 115 … | "checknum:i", # Check number optional (overrides acct file) | |
119 | 116 … | "pages:i", # Number of pages to print | |
120 | 117 … | "checkstyle:s", # Check style (defaults to "normal_style.ps" | |
121 | 118 … | "checktype:s", # Check blank definition | |
@@ -134,8 +131,14 @@ | |||
134 | 131 … | if ($opt_help) { | |
135 | 132 … | Show_Usage(); | |
136 | 133 … | } | |
137 | 134 … | ||
135 … | +if ($opt_config) { | ||
136 … | + $ConfigFile = $opt_config; | ||
137 … | +} elsif ( ! -e $ConfigFile ) { | ||
138 … | + copy $systemConfigFile, $ConfigFile; | ||
139 … | +} | ||
140 … | + | ||
138 | 141 … | # Some defaults... | |
139 | 142 … | if (!$opt_cgi) { | |
140 | 143 … | $opt_account = "sample" unless defined $opt_account; | |
141 | 144 … | $opt_checktype = "MVG3001" unless defined $opt_checktype; | |
@@ -609,9 +612,9 @@ | |||
609 | 612 … | + ($Definitions{"NumPages"} * $Definitions{"ChecksPerPage"}); | |
610 | 613 … | ||
611 | 614 … | $config_file = Replace_Val($config_file, "Account", $opt_account, | |
612 | 615 … | "CheckNumber", $next_check_number); | |
613 | - write_file ($ENV{"HOME"} . "/.freecheck.cfg", $config_file); | ||
616 … | + write_file ($ConfigFile, $config_file); | ||
614 | 617 … | } | |
615 | 618 … | ||
616 | 619 … | ############### | |
617 | 620 … | # Subroutines # | |
@@ -732,9 +735,10 @@ | |||
732 | 735 … | print "\nFreeCheck v.$version - a Free Check printing Utility\n\n"; | |
733 | 736 … | print "Usage: freecheck <options>:\n"; | |
734 | 737 … | print "\n"; | |
735 | 738 … | print "options:\n"; | |
736 | - print " --account <filename> account to use (default \"$opt_account\")\n"; | ||
739 … | + print " --config <filename> config file (default \"~/.freecheck.cfg\")\n"; | ||
740 … | + print " --account <name> account to use (default \"$opt_account\")\n"; | ||
737 | 741 … | print " --checknum <integer> starting check number (overrides cfg)\n"; | |
738 | 742 … | print " --pages <integer> number of pages to print (overrides cfg)\n"; | |
739 | 743 … | print " --checkstyle <filename> check style to use (default \"$opt_checkstyle\")\n"; | |
740 | 744 … | print " --checktype <filename> blank check type to use (default \"$opt_checktype\")\n"; | |
@@ -747,9 +751,8 @@ | |||
747 | 751 … | print " --preserve print but don't increment check number\n"; | |
748 | 752 … | print " --test print but don't increment check number\n"; | |
749 | 753 … | print " and print VOID on the check\n"; | |
750 | 754 … | print " --cgi accept string from CGI script (see docs)\n"; | |
751 | - print "\nconfig file \"~/.freecheck.cfg\"\n"; | ||
752 | 755 … | die "\n"; | |
753 | 756 … | } | |
754 | 757 … | ||
755 | 758 … | sub Print_Defs { |
Built with git-ssb-web