Return-Path: <tiff-bounces@lists.maptools.org>
Received: from mailgate002.isp.belgacom.be (mailgate002.isp.belgacom.be [195.238.6.87])
        by maildelivery007.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-IN-2.32) with ESMTP id l6BNfP9M027819
        for <joris.at.lebbeke@skynet.be>; Thu, 12 Jul 2007 01:41:26 +0200
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from r153.dmsolutions.ca (HELO duke.maptools.org) ([209.217.116.153])
  by in.mx.skynet.be with ESMTP; 12 Jul 2007 01:41:22 +0200
Received: from duke.maptools.org (duke.maptools.org [127.0.0.1])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l6BNPsHN017681;
	Wed, 11 Jul 2007 19:26:43 -0400
Received: from mail804.megamailservers.com
	(mail804.carrierinternetsolutions.com [69.49.106.14])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l6BNO78K017640
	for <tiff@lists.maptools.org>; Wed, 11 Jul 2007 19:24:08 -0400
X-Authenticated-User: kmyers1.clearwire.net
Received: from gateway (mobile-166-217-047-063.mycingular.net [166.217.47.63])
	(authenticated bits=0)
	by mail804.megamailservers.com (8.13.6.20060614/8.13.1) with ESMTP id
	l6BNNxLX022408
	for <tiff@lists.maptools.org>; Wed, 11 Jul 2007 19:24:03 -0400
Message-ID: <0b5501c7c412$908b9270$6a08d9a6@gateway>
From: "Kevin Myers" <kmyers1@clearwire.net>
To: <tiff@lists.maptools.org>
References: <0b3901c7c40d$2712a220$6a08d9a6@gateway>
	<Pine.SOC.4.60.0707111803080.922@blade.simplesystems.org>
Subject: Re: [Tiff] Re: Enhancements for tiffdump and tiffset
Date: Wed, 11 Jul 2007 18:23:57 -0500
MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_0B52_01C7C3E8.A531C5C0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.3138
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.4
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org
X-UIDL: 000000000023ceae.000025fd
X-MSP-STORE: Thu, 12 Jul 2007 01:41:38 --21-99
Status:   

This is a multi-part message in MIME format.

------=_NextPart_000_0B52_01C7C3E8.A531C5C0
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
	reply-type=response
Content-Transfer-Encoding: 7bit

> On Wed, 11 Jul 2007, Kevin Myers wrote:
>>
>> I located a version of diff that can be run under Windows to prepare 
>> patches for the enhancements that I implemented for tiffdump and tiffset. 
>> However, the changes that I made include a lot of white space changes due 
>> to greater indentation of pre-existing blocks of code within new if 
>> statement blocks. Do you want to see all of these white space changes in 
>> the diff output, or should I tell diff to ignore whitespace or 
>> indentation differences?
>
> I recommend using the diff option '-u'.  The most important concern is how 
> easy it is is to automatically apply the patch.  White space is cheap. 
> The person who applies the patch can re-indent the code (after the patch 
> is applied) as they see fit. The -u option selects a "unified context" 
> diff.
>
> Bob

Thanks Bob.  diff output files are attached to this message using only 
the -u option per your recommendation.  I probably have a lot to learn with 
regard to submitting patches in this manner, so let me know of anything that 
I need to do differently.  The code changes that I made for these 
enhancements were really quite simple.  The diff output seems to make them 
look more involved than they really are, due to all of the trivial 
differences.  I have not yet made corresponding entries in bugzilla, but 
hope to do that shortly.

Kevin M.


------=_NextPart_000_0B52_01C7C3E8.A531C5C0
Content-Type: application/octet-stream;
	name="tiffset.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="tiffset.diff"

--- tiffset_old.c	2007-06-30 14:37:20.968125000 -0500
+++ tiffset.c	2007-07-04 11:35:54.984375000 -0500
@@ -1,5 +1,5 @@
 =
/************************************************************************=
******
- * $Id: tiffset.c,v 1.11 2005/09/13 14:13:42 dron Exp $
+ * $Id: tiffset.c,v 1.20 2007/07/04 09:12:00 kmyers Exp $
  *
  * Project:  libtiff tools
  * Purpose:  Mainline for setting metadata in existing TIFF files.
@@ -29,6 +29,9 @@
  =
*************************************************************************=
*****
  *
  * $Log: tiffset.c,v $
+ * Revision 1.20  2007/07/04 09:12:00  kmyers
+ * Add handling for unrecognized tags.
+ *
  * Revision 1.11  2005/09/13 14:13:42  dron
  * Avoid warnings.
  *
@@ -46,14 +49,30 @@
=20
 #include "tiffio.h"
=20
+#define	TRUE	1
+#define	FALSE	0
+
+#define TIFFTAG_UNDEFINED 0
+
+
+static ttag_t			user_tag =3D TIFFTAG_UNDEFINED;	/* user specified TIFF =
tag data type */
+static TIFFDataType		user_field_type =3D TIFF_NOTYPE;	/* user specified =
TIFF tag data type */
+static TIFFExtendProc	_ParentExtender =3D NULL;
+
+static TIFFFieldInfo xtiffFieldInfo[] =3D {
+    {TIFFTAG_UNDEFINED, TIFF_VARIABLE, TIFF_VARIABLE, TIFF_NOTYPE, =
FIELD_CUSTOM, TRUE, FALSE, "Tag CUSTOM"}
+};
+
 static char* usageMsg[] =3D {
-"usage: tiffset [options] filename",
+"usage: tiffset [options] tiff-filename",
 "where options are:",
+" -t <data type>   set data type for unknown tags, precedes -s or -sf =
if used",
 " -s <tagname> [count] <value>...   set the tag value",
-" -sf <tagname> <filename>  read the tag value from file (for ASCII =
tags only)",
+" -sf <tagname> <data filename>   read tag value from file (ASCII tags =
only)",
 NULL
 };
=20
+
 static void
 usage(void)
 {
@@ -63,6 +82,43 @@
 	exit(-1);
 }
=20
+
+/* KAM - almost straight from the AddingTags documentation */
+static void
+_XTIFFDefaultDirectory(TIFF *tif)
+{
+	/* update our extended tag field info */
+	xtiffFieldInfo[0].field_tag =3D user_tag;
+	xtiffFieldInfo[0].field_type =3D user_field_type;
+	sprintf(xtiffFieldInfo[0].field_name, "Tag %d", (int) user_tag);
+
+	/* Install the extended Tag field info */
+    TIFFMergeFieldInfo(tif, xtiffFieldInfo, 1);
+
+    /* Since an XTIFF client module may have overridden
+     * the default directory method, we call it now to
+     * allow it to set up the rest of its own methods.
+     */
+
+    if (_ParentExtender)=20
+        (*_ParentExtender)(tif);
+}
+
+
+/* KAM - straight from the AddingTags documentation */
+static
+void _XTIFFInitialize(void)
+{
+    static int first_time=3D1;
+=09
+    if (! first_time) return; /* Been there. Done that. */
+    first_time =3D 0;
+=09
+    /* Grab the inherited method and install */
+    _ParentExtender =3D TIFFSetTagExtender(_XTIFFDefaultDirectory);
+}
+
+
 static const TIFFFieldInfo *
 GetField(TIFF *tiff, const char *tagname)
 {
@@ -74,43 +130,53 @@
         fip =3D TIFFFieldWithName(tiff, tagname);
=20
     if (!fip) {
-        fprintf( stderr, "Field name %s not recognised.\n", tagname );
+        fprintf( stderr, "Field name %s not recognized.\n", tagname );
         return (TIFFFieldInfo *)NULL;
     }
=20
     return fip;
 }
=20
+
 int
 main(int argc, char* argv[])
 {
     TIFF *tiff;
-    int  arg_index;
+    int arg_index;
+	char* tiffName;
=20
     if (argc < 2)
         usage();
=20
-    tiff =3D TIFFOpen(argv[argc-1], "r+");
-    if (tiff =3D=3D NULL)
-        return 2;
+	tiffName =3D argv[argc-1];
+	_XTIFFInitialize(); /* KAM - initialize custom tag extender */
=20
-    for( arg_index =3D 1; arg_index < argc-1; arg_index++ ) {
+	for( arg_index =3D 1; arg_index < argc-1; arg_index++ ) {
         if (strcmp(argv[arg_index],"-s") =3D=3D 0 && arg_index < =
argc-3) {
             const TIFFFieldInfo *fip;
             const char *tagname;
+            //char* tag_data;
=20
             arg_index++;
             tagname =3D argv[arg_index];
-            fip =3D GetField(tiff, tagname);
+			user_tag =3D (ttag_t) atoi(tagname);
+
+			tiff =3D TIFFOpen(argv[argc-1], "r+");
+		    if (tiff =3D=3D NULL)
+				return 2;
=20
-            if (!fip)
+			fip =3D GetField(tiff, tagname);
+			if (!fip)
                 return 3;
=20
             arg_index++;
-            if (fip->field_type =3D=3D TIFF_ASCII) {
-                if (TIFFSetField(tiff, fip->field_tag, argv[arg_index]) =
!=3D 1)
+			//tag_data=3Dargv[arg_index];
+			if (fip->field_type =3D=3D TIFF_ASCII) {
+
+				if (TIFFSetField(tiff, fip->field_tag, argv[arg_index]) !=3D 1)
                     fprintf( stderr, "Failed to set %s=3D%s\n",
                              fip->field_name, argv[arg_index] );
+
             } else if (fip->field_writecount > 0) {
                 int     ret =3D 1;
                 short   wc;
@@ -257,19 +323,28 @@
                     fprintf(stderr, "Failed to set %s\n", =
fip->field_name);
                 arg_index +=3D wc;
             }
-        } else if (strcmp(argv[arg_index],"-sf") =3D=3D 0 && arg_index =
< argc-3) {
-            FILE    *fp;
+
+		} else if (strcmp(argv[arg_index],"-sf") =3D=3D 0 && arg_index < =
argc-3) {
             const TIFFFieldInfo *fip;
-            char    *text;
-            int     len;
+            const char *tagname;
+            char	*text;
+            FILE	*fp;
+            long	len; /* KAM - change to long allowing larger files */
=20
             arg_index++;
-            fip =3D GetField(tiff, argv[arg_index]);
+            tagname =3D argv[arg_index];
+			user_tag =3D (ttag_t) atoi(tagname);
+
+			tiff =3D TIFFOpen(argv[argc-1], "r+");
+		    if (tiff =3D=3D NULL)
+				return 2;
=20
-            if (!fip)
+			fip =3D GetField(tiff, tagname);
+			if (!fip)
                 return 3;
=20
-            if (fip->field_type !=3D TIFF_ASCII) {
+			/* TODO: add support for all field types */
+			if (fip->field_type !=3D TIFF_ASCII) {
                 fprintf( stderr,
                          "Only ASCII tags can be set from file. "
                          "%s is not ASCII tag.\n", fip->field_name );
@@ -283,7 +358,24 @@
                 continue;
             }
=20
-            text =3D (char *) malloc(1000000);
+			/* KAM - Should consider fixing this old kludge                  */
+			/* Following code limits max data size to approximately 1 MB.    */
+			/* Should allow up to 4 GB for classic TIFF (in extreme case).   */
+			/* Since file name is specified on the command line (not a pipe) */
+			/* should know file size in advance and be able to attempt       */
+			/* allocation accordingly.  However, there really ought to be    */
+			/* a version of TIFFSetField that would let us set the tag value */
+			/* incrementally rather than needing to allocate all of this     */
+			/* memory at one time.                                           */
+
+			/* TODO: get file size here, how? */
+
+			/* check that file size is integer multiple of data type size    */
+			/* for non-ASCII data types.                                     */
+			/* Use TIFFDataWidth() to get the individual field width.        */
+
+			/* TODO: change memory allocation to match file size */
+			text =3D (char *) malloc(1000000);
             len =3D fread( text, 1, 999999, fp );
             text[len] =3D '\0';
=20
@@ -294,10 +386,14 @@
                         fip->field_name, argv[arg_index]);
             }
=20
-            _TIFFfree( text );
+			_TIFFfree( text );
             arg_index++;
+        } else if (strcmp(argv[arg_index],"-t") =3D=3D 0 && arg_index < =
argc-5) {
+			/* KAM - add option to force data type and handling of unrecognized =
tags */
+			arg_index++;
+			user_field_type =3D atoi(argv[arg_index]);
         } else {
-            fprintf(stderr, "Unrecognised option: %s\n",
+            fprintf(stderr, "Unrecognized option: %s\n",
                     argv[arg_index]);
             usage();
         }
@@ -308,4 +404,4 @@
     return 0;
 }
=20
-/* vim: set ts=3D8 sts=3D8 sw=3D8 noet: */
+/* vim: set ts=3D8 sts=3D8 sw=3D8 noet: */
\ No newline at end of file

------=_NextPart_000_0B52_01C7C3E8.A531C5C0
Content-Type: application/octet-stream;
	name="tiffdump.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="tiffdump.diff"

--- tiffdump_old.c	2007-06-29 15:56:01.608852900 -0500
+++ tiffdump.c	2007-07-11 18:09:47.281250000 -0500
@@ -1,6 +1,11 @@
-/* $Id: tiffdump.c,v 1.13 2005/11/21 03:35:06 fwarmerdam Exp $ */
-
-/*
+/***********************************************************************=
*******
+ * $Id: tiffdump.c,v 1.20 2007/07/04 09:12:00 kmyers Exp $
+ *
+ * Project:  libtiff tools
+ * Purpose:  Mainline for dumping metadata from existing TIFF files.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ =
*************************************************************************=
*****
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
@@ -22,8 +27,18 @@
  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY =
THEORY OF=20
  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR =
PERFORMANCE=20
  * OF THIS SOFTWARE.
+ =
*************************************************************************=
*****
+ *
+ * $Log: tiffset.c,v $
+ * Revision 1.20  2007/07/04 09:12:00  kmyers
+ * New -b, -r, -e, and -i command line options.
+ * Updated header.
+ *
  */
=20
+
+
+
 #include "tif_config.h"
=20
 #include <stdio.h>
@@ -63,6 +78,10 @@
 int	typeshift[14];		/* data type shift counts */
 long	typemask[14];		/* data type masks */
 uint32	maxitems =3D 24;		/* maximum indirect data items to print */
+int	full =3D 1;			/* KAM - full output format (vs. bare or raw) */
+long	tagId =3D -1;			/* KAM - tag id number */
+int	eol =3D 0;			/* KAM - bare format end of line handling */
+int	bare =3D 0;			/* KAM - bare output format (vs. raw) */
=20
 char*	bytefmt =3D "%s%#02x";		/* BYTE */
 char*	sbytefmt =3D "%s%d";		/* SBYTE */
@@ -83,7 +102,11 @@
 void
 usage()
 {
-	fprintf(stderr, "usage: %s [-h] [-o offset] [-m maxitems] file.tif =
...\n", appname);
+	fprintf(stderr, "Usage: %s [options] file.tif ...\n", appname);
+	fprintf(stderr, "  Data selection options: [-i <tagId>] [-o <offset>] =
[-m <maxitems>]\n");
+	fprintf(stderr, "  Output formatting options: [-b]=3Dbare, [-r]=3Draw, =
[-e]=3DEOL fixup, [-h]=3Dhex\n");
+	fprintf(stderr, "  Tag headers always printed if tagId (-i) option not =
specified.\n");
+	fprintf(stderr, "  File headers always printed for multiple input =
files.\n");
 	exit(-1);
 }
=20
@@ -91,40 +114,57 @@
 main(int argc, char* argv[])
 {
 	int one =3D 1, fd;
-	int multiplefiles =3D (argc > 1);
+//	int multiplefiles =3D (argc > 1);
+	int multiplefiles; /* KAM */
 	int c;
 	uint32 diroff =3D (uint32) 0;
 	bigendian =3D (*(char *)&one =3D=3D 0);
=20
 	appname =3D argv[0];
-	while ((c =3D getopt(argc, argv, "m:o:h")) !=3D -1) {
+	while ((c =3D getopt(argc, argv, "brehi:m:o:")) !=3D -1) {
 		switch (c) {
+		case 'b':			/* KAM - bare format, tag values only */
+			full =3D 0;
+			bare =3D 1;
+			break;
+		case 'r':			/* KAM - raw binary format, tag values only */
+			full =3D 0;
+			bare =3D 0;
+			break;
 		case 'h':			/* print values in hex */
 			shortfmt =3D "%s%#x";
 			sshortfmt =3D "%s%#x";
 			longfmt =3D "%s%#lx";
 			slongfmt =3D "%s%#lx";
 			break;
-		case 'o':
-			diroff =3D (uint32) strtoul(optarg, NULL, 0);
+		case 'i':			/* KAM - specify tag by id */
+			tagId =3D strtoul(optarg, NULL, 0);
 			break;
 		case 'm':
 			maxitems =3D strtoul(optarg, NULL, 0);
 			break;
+		case 'o':
+			diroff =3D (uint32) strtoul(optarg, NULL, 0);
+			break;
+		case 'e':			/* KAM - end of line fixup for bare format */
+			eol =3D 1;
+			break;
 		default:
 			usage();
 		}
 	}
 	if (optind >=3D argc)
 		usage();
+	/* KAM - fix multiple files determination */
+	multiplefiles =3D (argc > optind + 1);
 	for (; optind < argc; optind++) {
 		fd =3D open(argv[optind], O_RDONLY|O_BINARY, 0);
 		if (fd < 0) {
 			perror(argv[0]);
 			return (-1);
 		}
-		if (multiplefiles)
-			printf("%s:\n", argv[optind]);
+		if (full || multiplefiles)
+			printf("%s:\n", argv[optind]); /* KAM */
 		curfile =3D argv[optind];
 		swabflag =3D 0;
 		dump(fd, diroff);
@@ -222,10 +262,10 @@
 	if (hdr.tiff_version !=3D TIFF_VERSION)
 		Fatal("Not a TIFF file, bad version number %u (%#x)",
 		    hdr.tiff_version, hdr.tiff_version);=20
-	printf("Magic: %#x <%s-endian> Version: %#x\n",
+	if (full) printf("Magic: %#x <%s-endian> Version: %#x\n",
 	    hdr.tiff_magic,
 	    hdr.tiff_magic =3D=3D TIFF_BIGENDIAN ? "big" : "little",
-	    hdr.tiff_version);
+	    hdr.tiff_version); /* KAM */
 	if (diroff =3D=3D 0)
 	    diroff =3D hdr.tiff_diroff;
 	for (i =3D 0; diroff !=3D 0; i++) {
@@ -304,7 +344,7 @@
 		nextdiroff =3D 0;
 	if (swabflag)
 		TIFFSwabLong(&nextdiroff);
-	printf("Directory %u: offset %lu (%#lx) next %lu (%#lx)\n", ix,
+	if (full || tagId<0) printf("Directory %u: offset %lu (%#lx) next %lu =
(%#lx)\n", ix,
 	    (unsigned long)off, (unsigned long)off,
 	    (unsigned long)nextdiroff, (unsigned long)nextdiroff);
 	for (dp =3D dir, n =3D dircount; n > 0; n--, dp++) {
@@ -312,74 +352,82 @@
 			TIFFSwabArrayOfShort(&dp->tdir_tag, 2);
 			TIFFSwabArrayOfLong(&dp->tdir_count, 2);
 		}
-		PrintTag(stdout, dp->tdir_tag);
-		putchar(' ');
-		PrintType(stdout, dp->tdir_type);
-		putchar(' ');
-		printf("%lu<", (unsigned long) dp->tdir_count);
-		if (dp->tdir_type >=3D NWIDTHS) {
-			printf(">\n");
-			continue;
-		}
-		space =3D dp->tdir_count * datawidth[dp->tdir_type];
-		if (space <=3D 0) {
-			printf(">\n");
-			Error("Invalid count for tag %u", dp->tdir_tag);
-			continue;
-                }
-		if (space >=3D 0 && space <=3D 4) {
-			switch (dp->tdir_type) {
-			case TIFF_FLOAT:
-			case TIFF_UNDEFINED:
-			case TIFF_ASCII: {
-				unsigned char data[4];
-				_TIFFmemcpy(data, &dp->tdir_offset, 4);
-				if (swabflag)
-					TIFFSwabLong((uint32*) data);
-				PrintData(stdout,
-				    dp->tdir_type, dp->tdir_count, data);
-				break;
+		if (tagId<0 || dp->tdir_tag=3D=3DtagId) {
+			if (full || tagId<0) {
+				PrintTag(stdout, dp->tdir_tag);
+				putchar(' ');
+				PrintType(stdout, dp->tdir_type);
+				putchar(' ');
+				printf("%lu", (unsigned long) dp->tdir_count); /* KAM - full */
+				if (full) {
+					printf("<");
+					if (dp->tdir_type >=3D NWIDTHS) {
+						printf(">\n");
+						continue;
+					}
+				} /* KAM - full */
+				else if (tagId<0) printf("\n");
+			} /* KAM - full */
+			space =3D dp->tdir_count * datawidth[dp->tdir_type];
+			if (space <=3D 0) {
+				if (full) printf(">\n"); /* KAM - full */
+				Error("Invalid count for tag %u", dp->tdir_tag);
+				continue;
 			}
-			case TIFF_BYTE:
-				PrintByte(stdout, bytefmt, dp);
-				break;
-			case TIFF_SBYTE:
-				PrintByte(stdout, sbytefmt, dp);
-				break;
-			case TIFF_SHORT:
-				PrintShort(stdout, shortfmt, dp);
-				break;
-			case TIFF_SSHORT:
-				PrintShort(stdout, sshortfmt, dp);
-				break;
-			case TIFF_LONG:
-				PrintLong(stdout, longfmt, dp);
-				break;
-			case TIFF_SLONG:
-				PrintLong(stdout, slongfmt, dp);
-				break;
-			case TIFF_IFD:
-				PrintLong(stdout, ifdfmt, dp);
-				break;
+			if (space >=3D 0 && space <=3D 4) {
+				switch (dp->tdir_type) {
+					case TIFF_FLOAT:
+					case TIFF_UNDEFINED:
+					case TIFF_ASCII: {
+						unsigned char data[4];
+						_TIFFmemcpy(data, &dp->tdir_offset, 4);
+						if (swabflag)
+							TIFFSwabLong((uint32*) data);
+						PrintData(stdout,
+							dp->tdir_type, dp->tdir_count, data);
+						break;
+					}
+					case TIFF_BYTE:
+						PrintByte(stdout, bytefmt, dp);
+						break;
+					case TIFF_SBYTE:
+						PrintByte(stdout, sbytefmt, dp);
+						break;
+					case TIFF_SHORT:
+						PrintShort(stdout, shortfmt, dp);
+						break;
+					case TIFF_SSHORT:
+						PrintShort(stdout, sshortfmt, dp);
+						break;
+					case TIFF_LONG:
+						PrintLong(stdout, longfmt, dp);
+						break;
+					case TIFF_SLONG:
+						PrintLong(stdout, slongfmt, dp);
+						break;
+					case TIFF_IFD:
+						PrintLong(stdout, ifdfmt, dp);
+						break;
+				}
+			} else {
+				unsigned char *data =3D (unsigned char *)_TIFFmalloc(space);
+				if (data) {
+					if (TIFFFetchData(fd, dp, data)) {
+						if (dp->tdir_count > maxitems) {
+							PrintData(stdout, dp->tdir_type,
+								maxitems, data);
+							printf(" ...");
+						} else
+							PrintData(stdout, dp->tdir_type,
+								dp->tdir_count, data);
+									}
+					_TIFFfree(data);
+				} else
+					Error("No space for data for tag %u",dp->tdir_tag);
 			}
-		} else {
-			unsigned char *data =3D (unsigned char *)_TIFFmalloc(space);
-			if (data) {
-				if (TIFFFetchData(fd, dp, data)) {
-					if (dp->tdir_count > maxitems) {
-						PrintData(stdout, dp->tdir_type,
-						    maxitems, data);
-						printf(" ...");
-					} else
-						PrintData(stdout, dp->tdir_type,
-						    dp->tdir_count, data);
-                                }
-				_TIFFfree(data);
-			} else
-				Error("No space for data for tag %u",
-				    dp->tdir_tag);
-		}
-		printf(">\n");
+			if (full) printf(">"); /* KAM */
+			if (full || (bare && dp->tdir_type!=3DTIFF_ASCII)) printf("\n"); /* =
KAM */
+		} /* KAM - tagId<0 or tagID matches */
 	}
 done:
 	if (dir)
@@ -514,8 +562,9 @@
 	    "SLONG",
 	    "SRATIONAL",
 	    "FLOAT",
-	    "DOUBLE"
-	};
+	    "DOUBLE",
+		"IFD"
+	}; /* KAM - added IFD */
 #define	NTYPES	(sizeof (typenames) / sizeof (typenames[0]))
=20
 	if (type < NTYPES)
@@ -584,121 +633,199 @@
 static void
 PrintASCII(FILE* fd, uint32 cc, const unsigned char* cp)
 {
+
+	char prev1=3D0x00;
+	char prev2=3D0x00;
+	const char CR=3D0x0d;
+	const char LF=3D0x0a;
+	const char null=3D0x00;
+
 	for (; cc > 0; cc--, cp++) {
 		const char* tp;
=20
-		if (isprint(*cp)) {
-			fputc(*cp, fd);
-			continue;
-		}
-		for (tp =3D "\tt\bb\rr\nn\vv"; *tp; tp++)
-			if (*tp++ =3D=3D *cp)
-				break;
-		if (*tp)
-			fprintf(fd, "\\%c", *tp);
-		else if (*cp)
-			fprintf(fd, "\\%03o", *cp);
-		else
-			fprintf(fd, "\\0");
-	}
-}
+		if (full) {
+
+			if (isprint(*cp)) {
+				fputc(*cp, fd);
+				continue;
+			}
+			for (tp =3D "\tt\bb\rr\nn\vv"; *tp; tp++)
+				if (*tp++ =3D=3D *cp)
+					break;
+			if (*tp)
+				fprintf(fd, "\\%c", *tp);
+			else if (*cp)
+				fprintf(fd, "\\%03o", *cp);
+			else
+				fprintf(fd, "\\0");
+
+		} /* if full */
+
+		else {	/* KAM - bare format handling */
+
+			if (eol) {
+
+				/* KAM - bare format ASCII end of line handling */=20
+
+				/* This section replaces nulls, carriage returns, and carriage =
return - line feed combinations */
+				/* with end of line characters appropriate for the target host.  =
This is done to facilitate    */
+				/* viewing the output and piping the results into subsequent =
filters.                          */
+				/* Line feeds are only replaced when immediately preceded by a =
carriage return.                */
+				/* Nulls are only replaced when immediately preceded by CR or CRLF. =
                           */
+				/* Carriage returns are always replaced.                            =
                           */
+				/* EOL characters are appended if there is no null, CR, or CRLF at =
end of the tag data.        */
+
+				if (*cp=3D=3Dnull) {
+					if (prev1=3D=3DCR || (prev2=3D=3DCR && prev1=3D=3DLF)) {
+						/* skip null, already have eol */
+					}
+					else {
+						/* don't yet have eol, replace null with eol */
+						fprintf(fd,"\n");
+					}
+				}
+				else if (*cp=3D=3DLF) {
+					if (prev1=3D=3DCR) {
+						/* skip LF, already have eol */
+					}
+					else {
+						/* treat LF without CR as normal character */
+						fputc(*cp, fd);
+						/* append trailing eol if omitted at eod */
+						if (cc=3D=3D1) fprintf(fd,"\n");
+					}
+				}
+				else if (*cp=3D=3DCR) {
+					/* replace CR with eol */
+					fprintf(fd,"\n");
+				}
+				else {
+					fputc(*cp, fd);
+					/* append trailing eol if omitted at eod */
+					if (cc=3D=3D1) fprintf(fd,"\n");
+				}
+
+				prev2=3Dprev1;
+				prev1=3D*cp;
+
+			}
+			else {
+				fputc(*cp, fd);
+			}
+
+		} /* else if not full */
+
+	} /* for */
+
+} /* PrintASCII */
=20
 static void
 PrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data)
 {
-	char* sep =3D "";
=20
-	switch (type) {
-	case TIFF_BYTE:
-		while (count-- > 0)
-			fprintf(fd, bytefmt, sep, *data++), sep =3D " ";
-		break;
-	case TIFF_SBYTE:
-		while (count-- > 0)
-			fprintf(fd, sbytefmt, sep, *(char *)data++), sep =3D " ";
-		break;
-	case TIFF_UNDEFINED:
-		while (count-- > 0)
-			fprintf(fd, bytefmt, sep, *data++), sep =3D " ";
-		break;
-	case TIFF_ASCII:
-		PrintASCII(fd, count, data);
-		break;
-	case TIFF_SHORT: {
-		uint16 *wp =3D (uint16*)data;
-		while (count-- > 0)
-			fprintf(fd, shortfmt, sep, *wp++), sep =3D " ";
-		break;
-	}
-	case TIFF_SSHORT: {
-		int16 *wp =3D (int16*)data;
-		while (count-- > 0)
-			fprintf(fd, sshortfmt, sep, *wp++), sep =3D " ";
-		break;
-	}
-	case TIFF_LONG: {
-		uint32 *lp =3D (uint32*)data;
-		while (count-- > 0) {
-			fprintf(fd, longfmt, sep, (unsigned long) *lp++);
-			sep =3D " ";
-		}
-		break;
-	}
-	case TIFF_SLONG: {
-		int32 *lp =3D (int32*)data;
-		while (count-- > 0)
-			fprintf(fd, slongfmt, sep, (long) *lp++), sep =3D " ";
-		break;
-	}
-	case TIFF_RATIONAL: {
-		uint32 *lp =3D (uint32*)data;
-		while (count-- > 0) {
-			if (lp[1] =3D=3D 0)
-				fprintf(fd, "%sNan (%lu/%lu)", sep,
-				    (unsigned long) lp[0],
-				    (unsigned long) lp[1]);
-			else
-				fprintf(fd, rationalfmt, sep,
-				    (double)lp[0] / (double)lp[1]);
-			sep =3D " ";
-			lp +=3D 2;
-		}
-		break;
-	}
-	case TIFF_SRATIONAL: {
-		int32 *lp =3D (int32*)data;
-		while (count-- > 0) {
-			if (lp[1] =3D=3D 0)
-				fprintf(fd, "%sNan (%ld/%ld)", sep,
-				    (long) lp[0], (long) lp[1]);
-			else
-				fprintf(fd, srationalfmt, sep,
-				    (double)lp[0] / (double)lp[1]);
-			sep =3D " ";
-			lp +=3D 2;
+	if (full || bare) {
+
+		char* sep =3D "";
+
+		switch (type) {
+			case TIFF_BYTE:
+				while (count-- > 0)
+					fprintf(fd, bytefmt, sep, *data++), sep =3D " ";
+				break;
+			case TIFF_SBYTE:
+				while (count-- > 0)
+					fprintf(fd, sbytefmt, sep, *(char *)data++), sep =3D " ";
+				break;
+			case TIFF_UNDEFINED:
+				while (count-- > 0)
+					fprintf(fd, bytefmt, sep, *data++), sep =3D " ";
+				break;
+			case TIFF_ASCII:
+				PrintASCII(fd, count, data);
+				break;
+			case TIFF_SHORT: {
+				uint16 *wp =3D (uint16*)data;
+				while (count-- > 0)
+					fprintf(fd, shortfmt, sep, *wp++), sep =3D " ";
+				break;
+			}
+			case TIFF_SSHORT: {
+				int16 *wp =3D (int16*)data;
+				while (count-- > 0)
+					fprintf(fd, sshortfmt, sep, *wp++), sep =3D " ";
+				break;
+			}
+			case TIFF_LONG: {
+				uint32 *lp =3D (uint32*)data;
+				while (count-- > 0) {
+					fprintf(fd, longfmt, sep, (unsigned long) *lp++);
+					sep =3D " ";
+				}
+				break;
+			}
+			case TIFF_SLONG: {
+				int32 *lp =3D (int32*)data;
+				while (count-- > 0)
+					fprintf(fd, slongfmt, sep, (long) *lp++), sep =3D " ";
+				break;
+			}
+			case TIFF_RATIONAL: {
+				uint32 *lp =3D (uint32*)data;
+				while (count-- > 0) {
+					if (lp[1] =3D=3D 0)
+						fprintf(fd, "%sNan (%lu/%lu)", sep,
+							(unsigned long) lp[0],
+							(unsigned long) lp[1]);
+					else
+						fprintf(fd, rationalfmt, sep,
+							(double)lp[0] / (double)lp[1]);
+					sep =3D " ";
+					lp +=3D 2;
+				}
+				break;
+			}
+			case TIFF_SRATIONAL: {
+				int32 *lp =3D (int32*)data;
+				while (count-- > 0) {
+					if (lp[1] =3D=3D 0)
+						fprintf(fd, "%sNan (%ld/%ld)", sep,
+							(long) lp[0], (long) lp[1]);
+					else
+						fprintf(fd, srationalfmt, sep,
+							(double)lp[0] / (double)lp[1]);
+					sep =3D " ";
+					lp +=3D 2;
+				}
+				break;
+			}
+			case TIFF_FLOAT: {
+				float *fp =3D (float *)data;
+				while (count-- > 0)
+					fprintf(fd, floatfmt, sep, *fp++), sep =3D " ";
+				break;
+			}
+			case TIFF_DOUBLE: {
+				double *dp =3D (double *)data;
+				while (count-- > 0)
+					fprintf(fd, doublefmt, sep, *dp++), sep =3D " ";
+				break;
+			}
+			case TIFF_IFD: {
+				uint32 *lp =3D (uint32*)data;
+				while (count-- > 0) {
+					fprintf(fd, ifdfmt, sep, (unsigned long) *lp++);
+					sep =3D " ";
+				}
+				break;
+			}
 		}
-		break;
 	}
-	case TIFF_FLOAT: {
-		float *fp =3D (float *)data;
-		while (count-- > 0)
-			fprintf(fd, floatfmt, sep, *fp++), sep =3D " ";
-		break;
-	}
-	case TIFF_DOUBLE: {
-		double *dp =3D (double *)data;
-		while (count-- > 0)
-			fprintf(fd, doublefmt, sep, *dp++), sep =3D " ";
-		break;
-	}
-	case TIFF_IFD: {
-		uint32 *lp =3D (uint32*)data;
-		while (count-- > 0) {
-			fprintf(fd, ifdfmt, sep, (unsigned long) *lp++);
-			sep =3D " ";
+
+	else {
+		/* raw binary format */
+		for (; count > 0; count--, data++) {
+			fputc(*data, fd);
 		}
-		break;
-	}
 	}
 }
=20

------=_NextPart_000_0B52_01C7C3E8.A531C5C0
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
------=_NextPart_000_0B52_01C7C3E8.A531C5C0--
