From: Eric S. Raymond Date: Sat, 19 Aug 2000 16:23:58 +0000 (+0000) Subject: Ready to release 1.7. X-Git-Tag: 1.7 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=4979b43645a8567fa234831cc24cb82127d2d4e1;p=imgsizer.git Ready to release 1.7. --- diff --git a/Makefile b/Makefile index ab64cb9..f649571 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Makefile for the imgsizer distribution -VERS=1.6 +VERS=1.7 # These choices are correct for Linux. Season to taste. BINDIR = /usr/bin diff --git a/imgsizer b/imgsizer index 9ffda60..8d9e364 100755 --- a/imgsizer +++ b/imgsizer @@ -4,7 +4,14 @@ # imgsizer -- correct image sizes in WWW pages # # by Eric S. Raymond 30 Jul 1996 -# modified by Erik Rossen 15 May 1999 +# +# Modified by Erik Rossen 15 May 1999 +# +# Modified by Michael C. Toren 18 Aug 2000; +# Fixed bug where the SRC attribute needed to be in quotes, improved +# command line argument parsing (but it could still use some work), +# added -q switch to omit quotes when generating tags, and -l switch +# to generate lowercase tags. # # Fix up IMG tags in given documents to contain correct sizes. # No longer requires the identify(1) program from the ImageMagick suite if @@ -15,21 +22,51 @@ # clearly mark an altered version. Fixes and enhancements cheerfully # accepted. # -# This is version 1.6pre. +# This is version 1.6pre+mct # # Anything that can fetch a URL defined on the command line # and dump it to stdout will do here. $fetcher = 'httpget'; +# Output uppercase tags, surrounded by quotes, by default +$lower = 0; +$quotes = 1; + $out = "imgsizer-out$$"; $dir = "."; # NOTE: if you are doing '; # define INPUT_RECORD_SEPARATOR to split on HTML marker boundaries -if ("$ARGV[0]" =~ /^(--nomagick|-m)$/i) { - $magick=0; - shift; +while ($i = shift @ARGV) +{ + last if ($i eq "--"); + + unless ($i =~ /^-/) + { + unshift @ARGV, $i; + last; + } + + if ($i =~ /^(--nomagick|-m)$/i) + { + $magick = 0; + next; + } + + if ($i =~ /^(--lower-?(case)?|-l)$/i) + { + $lower = 1; + next; + } + + if ($i =~ /^(--no-?quotes?|-q)$/i) + { + $quotes = 0; + next; + } + + warn "Warning: Ignoring unknown option: $i\n"; } if (@ARGV) { @@ -94,12 +131,15 @@ sub error sub attrfix # fix up a space-separated sequence of image attributes { - $attribs = $_[0]; + $attribs = $_[0]; - if ($attribs !~ /SRC\s*=\s*\"([^"]*)\"/is) { + unless ( ($attribs =~ /SRC=([^\s]+)/is) + || ($attribs =~ /SRC\s*=\s*\"([^"]*)\"/is) ) + { &error("image \"${attribs}\"' has no SRC attribute"); return $attribs; } + $url = $1; # fetch the image @@ -170,14 +210,28 @@ sub attrfix } if ($attribs =~ /WIDTH\s*=\s*["0123456789]+/is) { - $attribs = "$`WIDTH=\"${xc}\"$'"; + $attribs = $` . &widthstring . $'; } else { - $attribs .= " WIDTH=\"${xc}\""; + $attribs .= " " . &widthstring; } + if ($attribs =~ /HEIGHT\s*=\s*["0123456789]+/is) { - $attribs = "$`HEIGHT=\"${yc}\"$'"; + $attribs = $` . &heightstring . $'; } else { - $attribs .= " HEIGHT=\"${yc}\""; + $attribs .= " " . &heightstring; } + return $attribs; } + +sub widthstring +{ + return ($lower ? "width=" : "WIDTH=") + . ($quotes ? '"' : '') . $xc . ($quotes ? '"' : ''); +} + +sub heightstring +{ + return ($lower ? "height=" : "HEIGHT=") + . ($quotes ? '"' : '') . $yc . ($quotes ? '"' : ''); +} diff --git a/imgsizer.xml b/imgsizer.xml index 0d56773..9623fc4 100644 --- a/imgsizer.xml +++ b/imgsizer.xml @@ -3,7 +3,7 @@ .SH NAME imgsizer \- automatically splice in height and width params for HTML IMG tags .SH SYNOPSIS -.B imgsizer [--nomagick] [file...] +.B imgsizer [--nomagick] [-q] [-l] [file...] .PP .SH DESCRIPTION The @@ -28,6 +28,9 @@ arguments, it will attempt to transform each file in place. Each argument file is not actually modified until the script completes a successful conversion pass. .PP +The -q option suppresses generation of string quotes in generated +attributes. The -l option generates attributes in lower case. +.PP This script is written on Perl, and thus requires a Perl interpreter on the host system. It also requires either the .IR identify (1)