Jelajahi Sumber

Small cleanups

Morten Brix Pedersen 24 tahun lalu
induk
melakukan
2dc1034cfc
2 mengubah file dengan 26 tambahan dan 45 penghapusan
  1. 9 7
      modules/Pisg.pm
  2. 17 38
      pisg.pl

+ 9 - 7
modules/Pisg.pm

@@ -64,21 +64,21 @@ sub run
     $self->get_default_config_settings();
     $self->get_default_config_settings();
 
 
     print "pisg $self->{cfg}->{version} - Perl IRC Statistics Generator\n\n"
     print "pisg $self->{cfg}->{version} - Perl IRC Statistics Generator\n\n"
-    unless ($self->{cfg}->{silent});
+        unless ($self->{cfg}->{silent});
 
 
     # Init the configuration file (aliases, ignores, channels, etc)
     # Init the configuration file (aliases, ignores, channels, etc)
     my $r = $self->init_config()
     my $r = $self->init_config()
-    if ($self->{use_configfile});
+        if ($self->{use_configfile});
 
 
     print "Using config file: $self->{cfg}->{configfile}\n\n"
     print "Using config file: $self->{cfg}->{configfile}\n\n"
-    if ($r && !$self->{cfg}->{silent});
+        if ($r && !$self->{cfg}->{silent});
 
 
     $self->init_words()       # Init words. (Foulwords, ignorewords, etc.)
     $self->init_words()       # Init words. (Foulwords, ignorewords, etc.)
-    if ($self->{use_configfile});
+        if ($self->{use_configfile});
 
 
     # Init the debugging file.
     # Init the debugging file.
     $self->init_debug()
     $self->init_debug()
-    unless ($self->{cfg}->{debugstarted});
+        if (!$self->{cfg}->{debugstarted});
 
 
     # Get translations from langfile
     # Get translations from langfile
     $self->get_language_templates();
     $self->get_language_templates();
@@ -88,7 +88,7 @@ sub run
 
 
     # Optionaly parse the channel we were given in override_cfg.
     # Optionaly parse the channel we were given in override_cfg.
     $self->do_channel()
     $self->do_channel()
-    unless ($self->{cfg}->{chan_done}{$self->{cfg}->{channel}});
+        if (!$self->{cfg}->{chan_done}{$self->{cfg}->{channel}});
 
 
     # Close the debugging file.
     # Close the debugging file.
     $self->close_debug();
     $self->close_debug();
@@ -206,7 +206,9 @@ sub get_default_config_settings
 
 
     # Parse the optional overriden configuration variables
     # Parse the optional overriden configuration variables
     foreach my $key (keys %{$self->{override_cfg}}) {
     foreach my $key (keys %{$self->{override_cfg}}) {
-        $self->{cfg}->{$key} = $self->{override_cfg}->{$key};
+        if ($self->{override_cfg}->{$key}) {
+            $self->{cfg}->{$key} = $self->{override_cfg}->{$key};
+        }
     }
     }
 }
 }
 
 

+ 17 - 38
pisg.pl

@@ -66,9 +66,8 @@ sub get_cmdline_options
         modules_dir => "$script_dir/modules/",     # Module search path
         modules_dir => "$script_dir/modules/",     # Module search path
     };
     };
 
 
-    my $tmp;
     # Commandline options
     # Commandline options
-    my ($moduledir, $channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help, $silent);
+    my ($tmp, $help, $silent, $option);
 
 
 my $usage = <<END_USAGE;
 my $usage = <<END_USAGE;
 Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
 Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
@@ -76,15 +75,15 @@ Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
 
 
 -ch --channel=xxx      : Set channel name
 -ch --channel=xxx      : Set channel name
 -l  --logfile=xxx      : Log file to parse
 -l  --logfile=xxx      : Log file to parse
--o  --outfile=xxx      : Name of html file to create
+-o  --outfile=xxx      : Name of HTML file to create
 -ma --maintainer=xxx   : Channel/statistics maintainer
 -ma --maintainer=xxx   : Channel/statistics maintainer
 -f  --format=xxx       : Logfile format [see FORMATS file]
 -f  --format=xxx       : Logfile format [see FORMATS file]
--n  --network=xxx      : IRC Network this channel is on.
+-n  --network=xxx      : IRC Network for the channel.
 -d  --dir=xxx          : Analyze all files in this dir. Ignores logfile.
 -d  --dir=xxx          : Analyze all files in this dir. Ignores logfile.
--p  --prefix=xxx       : Analyse only files starting with xxx in dir.
+-p  --prefix=xxx       : Analyse only files prefixed by xxx in dir.
                          Only works with --dir
                          Only works with --dir
--mo --moduledir=xxx    : Directory containing pisg's modules.
--co --configfile=xxx   : Config file
+-mo --moduledir=xxx    : Directory containing pisg modules.
+-co --configfile=xxx   : Configuration file
 -s  --silent           : Suppress output (except error messages)
 -s  --silent           : Suppress output (except error messages)
 -h  --help             : Output this message and exit (-? also works).
 -h  --help             : Output this message and exit (-? also works).
 
 
@@ -96,19 +95,19 @@ All options may also be defined by editing the configuration file and
 calling pisg without arguments.
 calling pisg without arguments.
 
 
 END_USAGE
 END_USAGE
-#'
-    if (GetOptions('channel=s'    => \$channel,
-                   'logfile=s'    => \$logfile,
-                   'format=s'     => \$format,
-                   'network=s'    => \$network,
-                   'maintainer=s' => \$maintainer,
-                   'outfile=s'    => \$outputfile,
-                   'dir=s'        => \$logdir,
-                   'prefix=s'     => \$prefix,
+
+    if (GetOptions('channel=s'    => \$cfg->{channel},
+                   'logfile=s'    => \$cfg->{logfile},
+                   'format=s'     => \$cfg->{format},
+                   'network=s'    => \$cfg->{network},
+                   'maintainer=s' => \$cfg->{maintainer},
+                   'outfile=s'    => \$cfg->{outputfile},
+                   'dir=s'        => \$cfg->{logdir},
+                   'prefix=s'     => \$cfg->{prefix},
+                   'moduledir=s'  => \$cfg->{moduledir},
+                   'configfile=s' => \$cfg->{configfile},
                    'ignorefile=s' => \$tmp,
                    'ignorefile=s' => \$tmp,
                    'aliasfile=s'  => \$tmp,
                    'aliasfile=s'  => \$tmp,
-                   'moduledir=s'  => \$moduledir,
-                   'configfile=s' => \$configfile,
                    'silent'       => \$silent,
                    'silent'       => \$silent,
                    'help|?'       => \$help
                    'help|?'       => \$help
                ) == 0 or $help) {
                ) == 0 or $help) {
@@ -120,26 +119,6 @@ END_USAGE
         pisg.cfg, please use that instead [look in pisg.cfg]\n");
         pisg.cfg, please use that instead [look in pisg.cfg]\n");
     }
     }
 
 
-    if ($channel) { $cfg->{channel} = $channel; }
-
-    if ($logfile) { $cfg->{logfile} = $logfile; }
-
-    if ($format) { $cfg->{format} = $format; }
-
-    if ($network) { $cfg->{network} = $network; }
-
-    if ($maintainer) { $cfg->{maintainer} = $maintainer; }
-
-    if ($outputfile) { $cfg->{outputfile} = $outputfile; }
-
-    if ($logdir) { $cfg->{logdir} = $logdir; }
-
-    if ($prefix) { $cfg->{prefix} = $prefix; }
-
-    if ($moduledir) { $cfg->{modules_dir} = $moduledir; }
-
-    if ($configfile) { $cfg->{configfile} = $configfile; }
-
     if ($silent) { $cfg->{silent} = 1; }
     if ($silent) { $cfg->{silent} = 1; }
 
 
     return $cfg;
     return $cfg;