Re: .cthumbrc behavior

Terry Gliedt <[email protected]> Sat, 17 May 2003 10:44:43 -0400
Newsgroups gmane.comp.web.cthumb.devel
Message-ID <[email protected]>
Attached you'll find a patch (to my previous patch) which does what I 
think should happen. It also corrects a problem I had with the CthumbDir 
implementation (mkdir should occur in create_page_html, not at the top 
where I had it).

To repeat, I think cthumbrc should only be applied with the -c option. 
 This requires the created album file has fewer comments, and a lot more 
keywords that are "active".  Take a look and see what you think.

On to the documentation now.

Carlos Puchol wrote:

>hi terry,
>
>makes sense. i have not sued my .cthumbrc for a while,
>so i don't remember the semantics of it.
>
>looking at the code, it seems like the priorities are
>
>  - album has the highest priorities
>  - then command line
>  - then cthumbrc
>  - and then the program defaults.
>
>i.e.:
>
>    init_options ();
>
>    ....
>
>    do_cthumbrc();
>
>    if ($opt{c}) {	# create a plain album
>	&cmd_line_options();
>	do_album(\@ARGV);
>	exit 0;
>    }
>
>
>i.e. the album gets processed the last, thus it has the highest
>priority, then command line gets set the last before, thus it has the second
>highest. and so forth.
>
>the fact that some things are set forth as comments in the creation of
>the albums is pretty much static, i.e. it is not tracked down which will
>be the most interesting features to turn on for a user. the idea is to
>have a template.
>
>i do agree with you that if the user has things set in .cthumbrc, then it
>probably would make sense to put them in generated albums, if they differ
>from the default i guess.
>
>whatever is the most useful...
>
>  
>


-- 
================================================================ 
Terry Gliedt        [email protected]       http://www.hps.com/~tpg/ 
Software Toolsmiths      Solving Software Development Problems
cthumb.patch.2 (text/plain, 29.4 KB)
*** /usr/local/bin/cthumb	2003-05-11 15:29:51.000000000 -0400
--- c	2003-05-17 10:10:00.000000000 -0400
***************
*** 23,28 ****
--- 23,29 ----
  
  use URI::Escape;
  use HTML::Entities;
+ use File::Basename;
  use IO::Handle;
  use POSIX;
  
***************
*** 34,152 ****
  ############################
  # public variables
  ############################
  my @options = (
  	# variable name                 type       command line argument    not allowed in file
  	# |                             |          |    default value       cthumbrc  theme
  	# |                             |          |    |                   |    album|    comment
  	# 0                             1          2    3                   4    5    6    7
! 	["Theme"                      , "string" , "" , "neat-round.theme", " ", " ", "x", "theme"],
! 	["AlbumTitle"                 , "string" , "" , "Undefined Title" , " ", " ", " ", "title of album"],
! 	["Languages"                  , "array"  , "" , "English"         , " ", " ", " ", "languages"],
! 	["NLanguages"                 , "integer", "l", "1"               , " ", " ", " ", "number of languages to use"],
! 	["SlidePictureGeometry"       , "array"  , "" , "0x0"             , " ", "x", " ", "sizes to generate, 0x0 is original size"],
! 	["DefaultSlidePictureGeometry", "string" , "" , "0x0"             , " ", "x", " ", "default size to start with"],
! 	["DefaultSlidePictureQuality" , "integer", "" , "80"              , " ", "x", " ", "quality of pictures in slides (1-100). High quality -> large file!"],
! 	["PicturesPerRow"             , "integer", "f", "4"               , " ", " ", " ", "Number of Pictures Per Row"],
  	["BGColor"                    , "string" , "" , "#000033"         , " ", "t", " ", "background"],
! 	["DecorBGColor"               , "string" , "" , "#000000"         , " ", "t", " ", "background for decorations"],
! 	["TextColor"                  , "string" , "" , "#00FFFF"         , " ", "t", " ", "text color"],
  	["CommentColor"               , "string" , "" , "#00AAAA"         , " ", "t", " ", "'click on the tumbnails' comment color"],
! 	["NoThumbBGColor"             , "string" , "" , "#322207"         , " ", "t", " ", "film bg color if there is no thumbnail available"],
  	["LinkColor"                  , "string" , "" , "#009900"         , " ", "t", " ", "link color"],
- 	["VLinkColor"                 , "string" , "" , "#000000"         , " ", "t", " ", "vlink color"],
- 	["ALinkColor"                 , "string" , "" , "#000000"         , " ", "t", " ", "alink color"],
  	["LinkSize"                   , "integer", "" , "1"               , " ", "t", " ", "thumbnail link size, in pixels"],
! 	["ThumbWidth"                 , "integer", "x", "120"             , " ", "t", " ", "icon width"],
  	["ThumbHeight"                , "integer", "y", "100"             , " ", "t", " ", "icon height"],
! 	["ThumbSmoothing"             , "integer", "" , "20"              , " ", "t", " ", "icon smoothing strength (1-100)"],
! 	["ThumbQuality"               , "integer", "" , "80"              , " ", "t", " ", "icon quality (1-100)"],
! 	["SlidePictureSmoothing"      , "integer", "" , "0"               , " ", "c", " ", "slide picture smoothing strength (1-100)"],
! 	["NoMainIndex"                , "boolean", "m", "0"               , " ", "c", " ", "generate a main index"],
! 	["TextCaptions"               , "boolean", "" , "0"               , " ", " ", " ", "generate text captions"],
! 	["StoryOn"                    , "boolean", "" , "0"               , " ", "c", " ", "generate story in slide show"],
! 	["MainIndexName"              , "string" , "" , "index.shtml"     , " ", " ", " ", "name for the main index file - careful in overwriting!"],
! 	["InlineFiles"                , "string" , "s", ""                , " ", " ", " ", "path to inline files instead server side include"],
! 	["CheckThumbnails"            , "boolean", "t", "0"               , " ", "c", " ", "should it re-check the thumbnails for width/height? (time consuming)"],
! 	["DisplayKbytes"              , "boolean", "" , "0"               , " ", "c", " ", "display the size in kb along with the alt comments"],
! 	["DisplayGeometry"            , "boolean", "" , "0"               , " ", "c", " ", "display the X x Y geometry in the alt comments"],
! 	["DisplayFileDate"            , "boolean", "" , "0"               , " ", "c", " ", "display the file date in the comments"],
! 	["LocaleFileDate"             , "boolean", "" , "0"               , " ", "c", " ", "use locale for file date in the comments"],
! 	["AutoSlideShow"              , "boolean", "" , "0"               , " ", "c", " ", "generate automatic slide show"],
! 	["AutoSlideTime"              , "integer", "" , "2"               , " ", "c", " ", "delay time (in seconds) for automatic slide show"],
! 	["TitleBgColor"               , "string" , "" , "#bbddff",          " ", "t", " ", "title font"],
! 	["TitleFont"                  , "string" , "" , "Arial,Sans Serif", " ", "t", " ", "title font"],
! 	["TitleFontSize"              , "string" , "" , "+2"              , " ", "t", " ", "title font size"],
! 	["TitleFontColor"             , "string" , "" , "#FFFFFF"         , " ", "t", " ", "title font color"],
! 	["StoryFont"                  , "string" , "" , "Arial,Sans Serif", " ", "t", " ", "story font"],
! 	["StoryFontSize"              , "string" , "" , "+0"              , " ", "t", " ", "story font size"],
! 	["StoryFontColor"             , "string" , "" , "#FFFFFF"         , " ", "t", " ", "story font color"],
! 	["CaptionFont"                , "string" , "" , "Arial,Sans Serif", " ", "t", " ", "caption font"],
! 	["CaptionFontSize"            , "string" , "" , "-1"              , " ", "t", " ", "caption font size"],
! 	["ThemeDir"                   , "string" , "" , "."               , " ", "c", "x", "theme directory"],
! 	["Decorations"                , "array"  , "" , "0 0 0 0"         , "x", "t", " ", "theme measurement"],
! 	["InsertExif"                 , "boolean", "" , "0"               , " ", "c", " ", "generate automatic Exif info"],
! 	["UseMogrify"                 , "boolean", "" , "0"               , " ", "c", " ", "use mogrify for scaling and rotating - required for image rotation"],
! 	["RecursiveCP"                , "string" , "" , "rsync -avqC"           , " ", "x", "x", "'cp -a' for gnu cp, set to 'cp -r' for bsd, else 'rsync -avq'"],
! 	["ImageDir"                   , "string" , "" , "${prefix}/share/images/cthumb"      , " ", "c", "x", "directory where themes are found"],
! 	["HtmlExtension"              , "string" , "" , "html"            , " ", " ", "x", "files to create - typically html, shtml or php"],
! 	["CthumbDir"                  , "string",  "" , "."               , " ", " ", "x", "directory where thumbnails and html are created"],
  	);
  
  ############################
  # private variables
  ############################
  my $AlbumTitle = '';
  my @Languages = ();
  my $NLanguages = 0;
  my $PageNumber = 0;
- my @SlidePictureGeometry = ();
- my $DefaultSlidePictureGeometry = '';
- my $DefaultSlidePictureQuality = '';
  my $PicturesPerRow = 0;         
! my $BGColor = '';
! my $DecorBGColor = '';
  my $TextColor = '';
! my $CommentColor = '';
! my $NoThumbBGColor = '';
! my $LinkColor = '';
! my $VLinkColor = '';
! my $ALinkColor = '';
! my $LinkSize = 0;
! my $ThumbWidth = 0;
  my $ThumbHeight = 0;
- my $ThumbSmoothing = 0;
  my $ThumbQuality = 80;
! my $SlidePictureSmoothing = 0;
! my $NoMainIndex = 0;
! my $TextCaptions = 0;
! my $StoryOn = 0;
! my $MainIndexName = '';
! my $InlineFiles = '';
! my $CheckThumbnails = 0;
! my $DisplayKbytes = 0;
! my $DisplayGeometry = 0;
! my $DisplayFileDate = 0;
! my $LocaleFileDate = 0;
! my $AutoSlideShow = 0;
! my $AutoSlideTime = 0;
  my $TitleBgColor = '';
  my $TitleFont = '';
- my $TitleFontSize = '';
  my $TitleFontColor = '';
! my $StoryFont = '';
! my $StoryFontSize = 0;
! my $StoryFontColor = '';
! my $CaptionFont = '';
! my $CaptionFontSize = -1;
! my $Theme = '';
! my $ThemeDir = '';
! my @Decorations = ();
! my $InsertExif = 0;
  my $UseMogrify = 0;
! my $RecursiveCP = '';
! my $ImageDir = '';
! my $HtmlExtension = '';
! my $CthumbDir = '.';
  
  my %opt = ();			# Option flags saved here
  my $InsertExifUrl = '';		# For broken InsertExif code
--- 35,170 ----
  ############################
  # public variables
  ############################
+ 
+ #   Columns 4-6 control whether a keyword can be included in certain files
+ #   and just how it shows up in the album file.  The rules are:
+ #
+ #   Column 4 - rules about .cthumbrc file
+ #       non-blank - not allowed in rc file
+ #   Column 5 - rules about album files
+ #       x - not added as comment or otherwise to album file
+ #       c - added as a comment
+ #       t - add as comment and commend this is used in themes only
+ #   Column 6 - rules about themes
+ #       non-blank - not allowed in theme
+ #
+ #   Replacing @options with a hash of hashes would make the code
+ #   far simpler and avoid all of the array bookeeping currently needed.
+ #   It would also eliminate the "private variables" found below.
  my @options = (
  	# variable name                 type       command line argument    not allowed in file
  	# |                             |          |    default value       cthumbrc  theme
  	# |                             |          |    |                   |    album|    comment
  	# 0                             1          2    3                   4    5    6    7
! 	["AlbumTitle"                 , "string" , "" , "Undefined Title" , " ", " ", "x", "title of album"],
! 	["ALinkColor"                 , "string" , "" , "#000000"         , " ", "t", " ", "alink color"],
! 	["AutoSlideShow"              , "boolean", "" , "0"               , " ", " ", "x", "generate automatic slide show"],
! 	["AutoSlideTime"              , "integer", "" , "2"               , " ", " ", "x", "delay time (in seconds) for automatic slide show"],
  	["BGColor"                    , "string" , "" , "#000033"         , " ", "t", " ", "background"],
! 	["CaptionFontSize"            , "string" , "" , "-1"              , " ", "t", "x", "caption font size"],
! 	["CaptionFont"                , "string" , "" , "Arial,Sans Serif", " ", "t", "x", "caption font"],
! 	["CheckThumbnails"            , "boolean", "t", "0"               , " ", "c", "x", "should it re-check the thumbnails for width/height? (time consuming)"],
  	["CommentColor"               , "string" , "" , "#00AAAA"         , " ", "t", " ", "'click on the tumbnails' comment color"],
! 	["CthumbDir"                  , "string",  "" , ""                , " ", " ", "x", "directory where thumbnails and html are created"],
! 	["Decorations"                , "array"  , "" , "0 0 0 0"         , "x", "t", " ", "theme measurement"],
! 	["DecorBGColor"               , "string" , "" , "#000000"         , "x", "t", "x", "background for decorations"],
! 	["DefaultSlidePictureGeometry", "string" , "" , "0x0"             , " ", "x", "x", "default size to start with"],
! 	["DefaultSlidePictureQuality" , "integer", "" , "80"              , " ", "x", "x", "quality of pictures in slides (1-100). High quality -> large file!"],
! 	["DisplayFileDate"            , "boolean", "" , "0"               , " ", " ", "x", "display the file date in the comments"],
! 	["DisplayGeometry"            , "boolean", "" , "0"               , " ", " ", "x", "display the X x Y geometry in the alt comments"],
! 	["DisplayKbytes"              , "boolean", "" , "0"               , " ", " ", "x", "display the size in kb along with the alt comments"],
! 	["FilmBGColor"                , "string",  "" , "#000033"         , "x", " ", " ", "No idea really, used in various themes"],
! 	["HtmlExtension"              , "string" , "" , "html"            , " ", " ", "x", "files to create - typically html, shtml or php"],
! 	["ImageDir"                   , "string" , "" , "${prefix}/share/images/cthumb", " ", " ", "x", "directory where themes are found"],
! 	["InlineFiles"                , "string" , "s", ""                , " ", " ", "x", "path to inline files instead server side include"],
! 	["InsertExif"                 , "boolean", "" , "0"               , " ", " ", "x", "generate automatic Exif info"],
! 	["Languages"                  , "array"  , "" , "English"         , " ", " ", "x", "languages"],
  	["LinkColor"                  , "string" , "" , "#009900"         , " ", "t", " ", "link color"],
  	["LinkSize"                   , "integer", "" , "1"               , " ", "t", " ", "thumbnail link size, in pixels"],
! 	["LocaleFileDate"             , "boolean", "" , "0"               , " ", " ", "x", "use locale for file date in the comments"],
! 	["MainIndexName"              , "string" , "" , "index.html"      , " ", " ", "x", "name for the main index file - careful in overwriting!"],
! 	["NLanguages"                 , "integer", "l", "1"               , " ", " ", "x", "number of languages to use"],
! 	["NoMainIndex"                , "boolean", "m", "0"               , " ", " ", "x", "generate a main index"],
! 	["NoThumbBGColor"             , "string" , "" , "#322207"         , " ", "t", " ", "film bg color if there is no thumbnail available"],
! 	["PicturesPerRow"             , "integer", "f", "4"               , " ", " ", " ", "Number of Pictures Per Row"],
! 	["RecursiveCP"                , "string" , "" , "rsync -avqC"     , " ", "x", "x", "'cp -a' for gnu cp, set to 'cp -r' for bsd, else 'rsync -avq'"],
! 	["SlidePictureGeometry"       , "array"  , "" , "0x0"             , " ", "x", "x", "sizes to generate, 0x0 is original size"],
! 	["SlidePictureSmoothing"      , "integer", "" , "0"               , " ", "c", "x", "slide picture smoothing strength (1-100)"],
! 	["StoryFontColor"             , "string" , "" , "#FFFFFF"         , " ", "t", "x", "story font color"],
! 	["StoryFontSize"              , "string" , "" , "+0"              , " ", "t", "x", "story font size"],
! 	["StoryFont"                  , "string" , "" , "Arial,Sans Serif", " ", "t", "x", "story font"],
! 	["StoryOn"                    , "boolean", "" , "0"               , " ", " ", "x", "generate story in slide show"],
! 	["TextCaptions"               , "boolean", "" , "0"               , " ", " ", "x", "generate text captions"],
! 	["TextColor"                  , "string" , "" , "#00FFFF"         , " ", "t", " ", "text color"],
! 	["ThemeDir"                   , "string" , "" , "."               , " ", " ", "x", "theme directory"],
! 	["Theme"                      , "string" , "" , "neat-round.theme", " ", " ", "x", "theme"],
  	["ThumbHeight"                , "integer", "y", "100"             , " ", "t", " ", "icon height"],
! 	["ThumbQuality"               , "integer", "" , "80"              , " ", "t", "x", "icon quality (1-100)"],
! 	["ThumbSmoothing"             , "integer", "" , "20"              , " ", "t", "x", "icon smoothing strength (1-100)"],
! 	["ThumbWidth"                 , "integer", "x", "120"             , " ", "t", " ", "icon width"],
! 	["TitleBgColor"               , "string" , "" , "#bbddff",          " ", "t", "x", "title font"],
! 	["TitleFontColor"             , "string" , "" , "#FFFFFF"         , " ", "t", "x", "title font color"],
! 	["TitleFontSize"              , "string" , "" , "+2"              , " ", "t", "x", "title font size"],
! 	["TitleFont"                  , "string" , "" , "Arial,Sans Serif", " ", "t", "x", "title font"],
! 	["UseMogrify"                 , "boolean", "" , "0"               , " ", " ", "x", "use mogrify for scaling and rotating - required for image rotation"],
! 	["VLinkColor"                 , "string" , "" , "#000000"         , " ", "t", " ", "vlink color"],
  	);
  
  ############################
  # private variables
  ############################
  my $AlbumTitle = '';
+ my $ALinkColor = '';
+ my $AutoSlideShow = 0;
+ my $AutoSlideTime = 0;
+ my $BGColor = '';
+ my $CaptionFont = '';
+ my $CaptionFontSize = -1;
+ my $CheckThumbnails = 0;
+ my $CommentColor = '';
+ my $CthumbDir = '';
+ my @Decorations = ();
+ my $DecorBGColor = '';
+ my $DefaultSlidePictureGeometry = '';
+ my $DefaultSlidePictureQuality = '';
+ my $DisplayFileDate = 0;
+ my $DisplayGeometry = 0;
+ my $DisplayKbytes = 0;
+ my $HtmlExtension = '';
+ my $ImageDir = '';
+ my $InlineFiles = '';
+ my $InsertExif = 0;
  my @Languages = ();
+ my $LinkColor = '';
+ my $LinkSize = 0;
+ my $LocaleFileDate = 0;
+ my $MainIndexName = '';
  my $NLanguages = 0;
+ my $NoMainIndex = 0;
+ my $NoThumbBGColor = '';
  my $PageNumber = 0;
  my $PicturesPerRow = 0;         
! my $RecursiveCP = '';
! my @SlidePictureGeometry = ();
! my $SlidePictureSmoothing = 0;
! my $StoryFont = '';
! my $StoryFontColor = '';
! my $StoryFontSize = 0;
! my $StoryOn = 0;
! my $TextCaptions = 0;
  my $TextColor = '';
! my $Theme = '';
! my $ThemeDir = '';
  my $ThumbHeight = 0;
  my $ThumbQuality = 80;
! my $ThumbSmoothing = 0;
! my $ThumbWidth = 0;
  my $TitleBgColor = '';
  my $TitleFont = '';
  my $TitleFontColor = '';
! my $TitleFontSize = '';
  my $UseMogrify = 0;
! my $VLinkColor = '';
  
  my %opt = ();			# Option flags saved here
  my $InsertExifUrl = '';		# For broken InsertExif code
***************
*** 171,179 ****
  
  my $themeprefix = "neat-round.theme";
  
- # flag to indicate if we're parsing a theme
- my $parsingTheme = 0;
- 
  # get the name of the file
  my $cthumb = $0;
  
--- 189,194 ----
***************
*** 190,203 ****
  
      if (exists($opt{H})) {	    # Show synopsis of cthumb keywords
          print "These are valid cthumb keywords:\n";
!         foreach my $o (@options) {
              print "  $o->[0]: $o->[7]\n";
              print "    Data type: '$o->[1]'  Default value: '$o->[3]'\n";
              my $allowed = '';
              my $notallowed = '';
              if ($o->[4] eq ' ') { $allowed .= '.cthumbrc, '; }
              else { $notallowed .= '.cthumbrc, '; }
!             if ($o->[5] eq ' ') { $allowed .= '.album files, '; }
              else { $notallowed .= '.album files, '; }
              if ($o->[6] eq ' ') { $allowed .= 'theme files,'; }
              else { $notallowed .= 'theme files,'; }
--- 205,218 ----
  
      if (exists($opt{H})) {	    # Show synopsis of cthumb keywords
          print "These are valid cthumb keywords:\n";
!         foreach my $o (sort { lc($a->[0]) cmp lc($b->[0]) } @options) {
              print "  $o->[0]: $o->[7]\n";
              print "    Data type: '$o->[1]'  Default value: '$o->[3]'\n";
              my $allowed = '';
              my $notallowed = '';
              if ($o->[4] eq ' ') { $allowed .= '.cthumbrc, '; }
              else { $notallowed .= '.cthumbrc, '; }
!             if ($o->[5] ne 'x') { $allowed .= '.album files, '; }
              else { $notallowed .= '.album files, '; }
              if ($o->[6] eq ' ') { $allowed .= 'theme files,'; }
              else { $notallowed .= 'theme files,'; }
***************
*** 221,236 ****
  	print "\t-s <dir>: inline header.html and footer.html from directory\n";
  	print "\t-t: check the thumbnail width/height? time consuming. (def: $CheckThumbnails)\n";
  	print "\n\tcthumb $version. cpg+cthumb\@nospam.puchol.com\n";
! 	print "\thttp://puchol.com/cpg/software/cthumb/\n";
  	exit -1;
      }
  
-     do_cthumbrc();
- 
      if ($opt{c}) {	# create a plain album
! 	&cmd_line_options();
! 	do_album(\@ARGV);
! 	exit 0;
      }
  
      my $pwd = `pwd`;
--- 236,250 ----
  	print "\t-s <dir>: inline header.html and footer.html from directory\n";
  	print "\t-t: check the thumbnail width/height? time consuming. (def: $CheckThumbnails)\n";
  	print "\n\tcthumb $version. cpg+cthumb\@nospam.puchol.com\n";
! 	print "\thttp://www.sourceforge.com/projects/cthumb/\n";
  	exit -1;
      }
  
      if ($opt{c}) {	# create a plain album
! 	    cmd_line_options();
!         do_cthumbrc();              # Take user defaults from rc file
! 	    do_album(\@ARGV);           # Create album file from existing values
! 	    exit 0;
      }
  
      my $pwd = `pwd`;
***************
*** 241,257 ****
  
      print "cthumb $version, running in $pwd\n";
  
-     if ($CthumbDir eq '') { $CthumbDir = '.'; }     # Null means the CWD
-     else {                          # Else create this directory if specified
-         if (! -d $CthumbDir) {
-             if (! mkdir($CthumbDir,0755)) {
-                 warn "Unable to create CthumbDir dir '$CthumbDir': $!\n";
-                 $CthumbDir = '.';             # Reset this option
-             }
-             else { print "Created subdirectory '$CthumbDir'\n"; }
-         }
-     }
- 
      if ($opt{i}) {	# image dir
  	$ImageDir = $opt{i};
      }
--- 255,260 ----
***************
*** 277,289 ****
  sub do_cthumbrc {
      my $rc = $ENV{HOME} . "/.cthumbrc";
  
!     if (open (RC, $rc)) {
! 	while (<RC>) {
!         if (/^#/) { next; }                 # Skip comments
! 	    &parse_option();
  	}
! 	close (RC);
!     }
  }
  
  sub cmd_line_options {
--- 280,291 ----
  sub do_cthumbrc {
      my $rc = $ENV{HOME} . "/.cthumbrc";
  
!     if (! open (RC, $rc)) { return; }
!     while (<RC>) {
!         if (/^#/) { next; }         # Skip comments
!         parse_option('rc', $_);
  	}
!     close (RC);
  }
  
  sub cmd_line_options {
***************
*** 363,438 ****
  
  # =========================================================================
  # Description:
! #	Update variables listed in the @options array with the value set in the
! #	various files.
  # In:
! #	$_
  # Out:
  #	-
  # Return:
! #	1 found
! #	0 not found
  #
  sub parse_option {
!     my $i = 0;
!     my $found = 0;
!     my $pattern = "";
  
!     # loop all options and reset them with value found
!   LOOP:
!     for my $opt (@options) {
! 	$pattern = $options[$i][0];
! 	my $cmdopt = "opt{$options[$i][2]}";
! 	my $allowedInTheme = $options[$i][6] eq " ";
! 
! 	if (/^($pattern):/i) {
! 	    $found = 1;
! 
! 	    if ($parsingTheme && (!$allowedInTheme)) {
! 		# ignore setting not allowed in theme
! 		return 1;
! 	    }
! 
! #	    if ($cmdopt ne "" && $$cmdopt) {
! #		# do not override command line argument
! #		last LOOP;
! #	    }
! 
! 	    # reset the variable
! 	    if (($options[$i][1] eq "integer" ||
! 		 $options[$i][1] eq "boolean") &&
! 		/^$pattern:\s*(\d+)/i) { # integer/boolean w/ or w/o comment
! 		eval "\$$options[$i][0] = int($1)";
! 			last LOOP;
! 	    }
! 	    if ($options[$i][1] eq "string" &&
! 		/^$pattern:\s*(.*)\s*?$/i) { # string w/o comment
! 		eval "\$$options[$i][0] = \"$1\"";
! 			last LOOP;
! 	    }
! 	    if ($options[$i][1] eq "array" &&
! 		/^$pattern:\s*(.*)\s*?$/i) { # array w/o comment
! 		eval "\@$options[$i][0] = (split (' ', \$1))";
! 		# if the Languages variable has been assigned -> NLanguages
! 		if ($options[$i][0] eq "Languages") {
! 		    $NLanguages = $#Languages + 1;
! 		    # print "DEBUG: NLanguages: $NLanguages\n";
! 		}
! 			last LOOP;
! 	    }
! 	    # print "DEBUG: $pattern = $1 ($cmdopt)\n";
! 	    last LOOP;
! 	}
! 
! 	$i++;
!     }
  
!     if ($found && ($pattern =~ /^Theme$/i)) {
! 	# if a new theme has been assigned, read it now.
! 	&read_theme($Theme);
      }
! 
!     return $found;
  }
  
  sub read_theme {
--- 365,433 ----
  
  # =========================================================================
  # Description:
! #	Update variables listed in the @options array with the value
! #   as read from various sources.
! #
  # In:
! #	type - type of data being read, 'rc', 'theme', 'album'
! #   line - line from file to parse
  # Out:
  #	-
  # Return:
! #	boolean if found
  #
  sub parse_option {
!     my ($type, $line) = @_;
  
!     #   Loop through options and reset them with value found
!     my $i = 0;
!     foreach my $opt (@options) {
!         my $pattern = $options[$i][0];
!         if ($line !~ /^($pattern):/i) { $i++; next; }
!         #   We now have found a match to an option
!         #   Check if this field is valid here. 
!         #   See comments at top of @options for the rules
!         if (($type eq 'rc' && $options[$i][4] ne ' ') ||
!             (($type eq 'theme' && $options[$i][6] ne ' '))) {
!             warn "Ignoring keyword in '$type' file:\n" .
!                 "  Line=$line";
!             $i++;
!             next;
!         }
!         #   Now we have a valid keyword for this source
!         #   Set the new value in @options
!         if (($options[$i][1] eq "integer" ||
!             $options[$i][1] eq "boolean") &&
!             /^$pattern:\s*(\d+)/i) { # integer/boolean w/ or w/o comment
!             eval "\$$pattern = int($1)";
!             #print "#    Source=$type $pattern=int($1)\n";
!             return 1;
!         }
  
!         if ($options[$i][1] eq "string" &&
!             /^$pattern:\s*(.*)\s*?$/i) { # string w/o comment
!             eval "\$$pattern = '$1'";
!             #print "#    Source=$type $pattern='$1'\n";
!             #   If we just set a new theme, read it in now
!             if ($pattern eq 'Theme') {
!                 read_theme($Theme);
!                 return 1;
!             }
!         }
!         if ($options[$i][1] eq "array" &&
!             /^$pattern:\s*(.*)\s*?$/i) { # array w/o comment
!             eval "\@$pattern = qw($1)";
!             #print "#    Source=$type $pattern=qw($1)\n";
!             #   If Languages was set, assign NLanguages
!             if ($pattern eq 'Languages') {
!                 $NLanguages = $#Languages + 1;
!                 #print "#    \@Languages is now: " . join(',',@Languages) . "\n";
!             }
!             return 1;
!         }
!         $i++;
      }
!     return 0;
  }
  
  sub read_theme {
***************
*** 467,479 ****
      my $conf = $themeprefix . "/theme.conf";
  
      if (!open (THEME, "<$conf")) {
! 	print "WARNING: cannot read \"$conf\" ... proceeding with defaults..\n";
!     } else {
! 	$parsingTheme = 1;
! 	while (<THEME>) {
! 	    &parse_option();
! 	}
! 	$parsingTheme = 0;
      }
      $backarrow = "" unless (-e "$themeprefix/$backarrow");
  }
--- 462,474 ----
      my $conf = $themeprefix . "/theme.conf";
  
      if (!open (THEME, "<$conf")) {
!         print "WARNING: cannot read \"$conf\" ... proceeding with defaults..\n";
!     }
!     else {
!         while (<THEME>) {
!             parse_option('theme', $_);
!         }
!         close(THEME);
      }
      $backarrow = "" unless (-e "$themeprefix/$backarrow");
  }
***************
*** 505,512 ****
      my $npics;
      my $theme;
  
!     /^(.*?)(\.desc|\.txt|\.album)?$/;
!     $descindex = $1;
      if ($MainIndexName eq "") {
  	$MainIndexName = $descindex . "-index.$HtmlExtension";
      }
--- 500,506 ----
      my $npics;
      my $theme;
  
!     if (/^(.*?)(\.desc|\.txt|\.album)?$/) { $descindex = $1; }
      if ($MainIndexName eq "") {
  	$MainIndexName = $descindex . "-index.$HtmlExtension";
      }
***************
*** 517,541 ****
      }
      open HTMLINDEX, ">$indextmp" || print "cthumb warning: cannot open $indextmp for writing: $!\n";
      while (<ALBUM>) {
! 	next if (&parse_option());
! 	if (/^Page/i) {
! 	    my $line = $_;
! 	    # all the options are processed: begin the show!
! 	    &initial_checks();
! 
! 	    # for debugging purposes, to dump the variable settings
! 	    # do_album(());
! 
! 	    print HTMLINDEX index_html_header($AlbumTitle);
! 
! 	    $maintheme = $Theme;
! 	    $theme = $Theme;
! 	    $captionattrs .= " face=\"$CaptionFont\"" if ($CaptionFont ne "");
! 	    $captionattrs .= " size=\"$CaptionFontSize\"" if ($CaptionFontSize);
  
! 	    $_ = $line;
! 	    goto RESTART;
! 	}
      }
      exit 0;
  
--- 511,535 ----
      }
      open HTMLINDEX, ">$indextmp" || print "cthumb warning: cannot open $indextmp for writing: $!\n";
      while (<ALBUM>) {
! 	    if (parse_option('album', $_)) { next; }
!             if (/^Page/i) {
!                 my $line = $_;
!                 # all the options are processed: begin the show!
!                 &initial_checks();
! 
!                 # for debugging purposes, to dump the variable settings
!                 # do_album(());
! 
!                 print HTMLINDEX index_html_header($AlbumTitle);
! 
!                 $maintheme = $Theme;
!                 $theme = $Theme;
!                 $captionattrs .= " face=\"$CaptionFont\"" if ($CaptionFont ne "");
!                 $captionattrs .= " size=\"$CaptionFontSize\"" if ($CaptionFontSize);
  
!                 $_ = $line;
!                 goto RESTART;
!         }
      }
      exit 0;
  
***************
*** 787,793 ****
  	}
  	next unless /^\s*([-<>]) \s*(.*?)(:)?\s*$/; # found the next picture
  	$picname[$npics] = $2;
! 	$picrotate[$npics]=$1;
  	$npics++;
  
  	# fill picture description with default values
--- 781,800 ----
  	}
  	next unless /^\s*([-<>]) \s*(.*?)(:)?\s*$/; # found the next picture
  	$picname[$npics] = $2;
! 	$picrotate[$npics] = $1;
! 
!     #   $picname[$npics] is the jpg. If CthumbDir was provided
!     #   then see if that subdirectory needs to be created.
!     if ($CthumbDir ne '') {
!         my $dir = dirname($picname[$npics]) . '/' . $CthumbDir;
!         if (! -d $dir) {
!             if (! mkdir($dir,0755)) {
!                 warn "Unable to create CthumbDir dir '$dir': $!\n";
!                 $CthumbDir = '';              # Reset this option
!             }
!             else { print "Created subdirectory '$dir'\n"; }
!         }
!     }
  	$npics++;
  
  	# fill picture description with default values
***************
*** 927,933 ****
              split_filename($originalPictureURL);
  
          my $outputPath = $path;
!         if ($CthumbDir ne '.') { $outputPath .= '/' . $CthumbDir; }
  
          my $originalPictureGeometry =
              $originalPictureGeometryArray[$pictureNumber];
--- 934,940 ----
              split_filename($originalPictureURL);
  
          my $outputPath = $path;
!         if ($CthumbDir ne '') { $outputPath .= '/' . $CthumbDir; }
  
          my $originalPictureGeometry =
              $originalPictureGeometryArray[$pictureNumber];