http://www.berklix.org/~jhs/src/bsd/fixes/freebsd/ports/jhs/graphics/tiff/files/patch-jb-tiffsplit.c.diff
For /usr/ports/graphics/tiff/work/tiff-4.2.0/tools/tiffsplit.c

See Also:
 http://www.simplesystems.org/libtiff/
 tiff@lists.osgeo.org
 subscription interface at http://lists.osgeo.org/mailman/listinfo/tiff.

--- tools/tiffsplit.c.orig	Sun Jul 12 19:11:27 2020
+++ tools/tiffsplit.c	Thu Jan  7 13:14:21 2021
***************
*** 1,4 ****
! /*
   * Copyright (c) 1992-1997 Sam Leffler
   * Copyright (c) 1992-1997 Silicon Graphics, Inc.
   *
--- 1,4 ----
! /* + hacks by jhs@, more needed JJLATER
   * Copyright (c) 1992-1997 Sam Leffler
   * Copyright (c) 1992-1997 Silicon Graphics, Inc.
   *
***************
*** 59,69 ****
--- 59,89 ----
  static	int cpStrips(TIFF*, TIFF*);
  static	int cpTiles(TIFF*, TIFF*);
  
+ #ifdef AZ
+ // Original generic pre 2021-01-07.
+ #define  CHAR_OFFSET	'a'
+ #define  CHAR_RANGE		26 
+ // 26 ^ 3 = 17576
+ #else
+ // Make easier to calculate page numbers in big books. by jhs @ berklix . com
+ // (eg for when viewing whole book in xpdf, then going back with tiffsplit,
+ // to splice in picture pages rescanned in gray instead of lineart for text).
+ #define  CHAR_OFFSET	'0'
+ #define  CHAR_RANGE		10 
+ // 10 ^ 3 =  1000
+ #endif
+ // JJLATER we should add 2 more digits to file names to avoid loosing maximum.
+ 
+ char char_offset	= CHAR_OFFSET ;
+ int  char_range		= CHAR_RANGE ;
+ 
  int
  main(int argc, char* argv[])
  {
  	TIFF *in, *out;
  
+ 	// JJLATER optionaly set other values on char_offset & char_range on argv switch.
+ 
  	if (argc < 2) {
                  fprintf(stderr, "%s\n\n", TIFFGetVersion());
  		fprintf(stderr, "usage: tiffsplit input.tif [prefix]\n");
***************
*** 120,127 ****
  		}
  		first = 0;
  	}
! #define	MAXFILES	17576
! 	if (fnum == MAXFILES) {
  		if (!defname || fname[0] == 'z') {
  			fprintf(stderr, "tiffsplit: too many files.\n");
  			exit(EXIT_FAILURE);
--- 140,146 ----
  		}
  		first = 0;
  	}
! 	if (fnum == ( char_range * char_range * char_range ) ) {
  		if (!defname || fname[0] == 'z') {
  			fprintf(stderr, "tiffsplit: too many files.\n");
  			exit(EXIT_FAILURE);
***************
*** 129,146 ****
  		fname[0]++;
  		fnum = 0;
  	}
! 	if (fnum % 676 == 0) {
  		if (fnum != 0) {
  			/*
!                          * advance to next letter every 676 pages
! 			 * condition for 'z'++ will be covered above
                           */
  			fpnt[0]++;
  		} else {
  			/*
!                          * set to 'a' if we are on the very first file
                           */
! 			fpnt[0] = 'a';
  		}
  		/*
                   * set the value of the last turning point
--- 148,166 ----
  		fname[0]++;
  		fnum = 0;
  	}
! 	// JJLATER add fpnt[3] and fpnt[4] code for longer file names
! 	if (fnum % ( char_range * char_range ) == 0) {
  		if (fnum != 0) {
  			/*
!                          * advance to next letter every char_range * char_range  pages
! 			 * condition for 'z'++ or '9'++ will be covered above
                           */
  			fpnt[0]++;
  		} else {
  			/*
!                          * set to char_offset if we are on the very first file
                           */
! 			fpnt[0] = char_offset;
  		}
  		/*
                   * set the value of the last turning point
***************
*** 148,161 ****
  		lastTurn = fnum;
  	}
  	/* 
!          * start from 0 every 676 times (provided by lastTurn)
!          * this keeps us within a-z boundaries
           */
! 	fpnt[1] = (char)((fnum - lastTurn) / 26) + 'a';
  	/* 
!          * cycle last letter every file, from a-z, then repeat
           */
! 	fpnt[2] = (char)(fnum % 26) + 'a';
  	fnum++;
  }
  
--- 168,181 ----
  		lastTurn = fnum;
  	}
  	/* 
!          * start from 0 every char_range * char_range  times (provided by lastTurn)
!          * this keeps us within a-z or 0-9 boundaries
           */
! 	fpnt[1] = (char)((fnum - lastTurn) / char_range) + char_offset;
  	/* 
!          * cycle last letter every file, from a-z or 0-9, then repeat
           */
! 	fpnt[2] = (char)(fnum % char_range) + char_offset;
  	fnum++;
  }
  
