[mod.sources] v06i024: Patches to fmtr

sources-request@mirror.UUCP (06/26/86)

Submitted by: cca!harvard!hscfvax!popvax!mohamed (Mohamed ellozy)
Mod.sources: Volume 6, Issue 24
Archive-name: fmtr.patch

Here are some patches to my previously posted Fmtr.  They are described in
the file MODS in the following shar.  The other file is a file of context
differences for use with patch.  Copy it into the directory containing the
original files, and enter:
	patch fmtr.c diffs
The files that will be modified are:
	fmtr.c
	fmtr.h
	fmtr.1 (manual page)
	command.c
	lowtext.c
------------------------------ CUT HERE ------------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	MODS
#	diffs
# This archive created: Thu Jun 19 10:24:35 1986
export PATH; PATH=/bin:$PATH
echo shar: extracting "'MODS'" '(1426 characters)'
if test -f 'MODS'
then
	echo shar: will not over-write existing file "'MODS'"
else
sed 's/^	X//' << \SHAR_EOF > 'MODS'
	XThe patches to Fmtr achieve the following:
	X
	X(1)  The few mm macros that switch to nofill mode are now
	X     recognized.  I am not an mm user, but from the manual
	X     this should work.
	X
	X(2)  For both mm and me display macros, Fmtr will now look
	X     to see if the display is in filled mode, as with:
	X     .(l F   (me)
	X     and
	X     .DS F   (mm)
	X
	X(3)  All material between preprocessor statements (e. g.
	X     between .TS and .TE) is in nofill mode, as is all
	X     material within displays that are nofill.  Requests
	X     that return to fill mode are ignored if they occur
	X     within a display or preprocessor material.
	X
	X(4)  A -b flag has been added to begin each sentence on a
	X     new line, as recommended by some books.  I feel that
	X     this defeats the whole idea of having neatly formatted
	X     text to edit, but then editing is a very personal
	X     matter.
	X
	X     As noted at the end of the manual page, the emphasis
	Xhas been on making sure that text should not be accidentally
	Xfilled.  When in doubt, Fmtr leaves the text as it found it.
	XThe real formatter will make the correct decisions at formatting
	Xtime.
	X
	X     Remember also that Fmtr is not a roff emulator.  It
	Xknows nothing about environments, or indeed about the inner
	Xworkings of the macros that it recognizes.  If you have
	Xlarge amounts of unfilled text in sophisticated macros of
	Xyour own, carefully examine the output of Fmtr before
	Xdiscarding the original.
SHAR_EOF
if test 1426 -ne "`wc -c < 'MODS'`"
then
	echo shar: error transmitting "'MODS'" '(should have been 1426 characters)'
fi
chmod +x 'MODS'
fi # end of overwriting check
echo shar: extracting "'diffs'" '(10921 characters)'
if test -f 'diffs'
then
	echo shar: will not over-write existing file "'diffs'"
else
sed 's/^	X//' << \SHAR_EOF > 'diffs'
	X*** fmtr.c	Thu Jun 19 10:22:09 1986
	X--- fmtr.new.c	Thu Jun 19 10:21:12 1986
	X***************
	X*** 35,41
	X  				/* null or not */
	X      sarray = earray = (char *) 0;
	X  
	X!     while ((c = getopt(argc, argv, "zw:s:e:")) != EOF)
	X  	switch (c) {
	X  	    case 'z':
	X  		z_flag = 1;
	X
	X--- 35,41 -----
	X  				/* null or not */
	X      sarray = earray = (char *) 0;
	X  
	X!     while ((c = getopt(argc, argv, "bzw:s:e:")) != EOF)
	X  	switch (c) {
	X  	    case 'b':
	X  		b_flag = 1;
	X***************
	X*** 37,42
	X  
	X      while ((c = getopt(argc, argv, "zw:s:e:")) != EOF)
	X  	switch (c) {
	X  	    case 'z':
	X  		z_flag = 1;
	X  		break;
	X
	X--- 37,45 -----
	X  
	X      while ((c = getopt(argc, argv, "bzw:s:e:")) != EOF)
	X  	switch (c) {
	X+ 	    case 'b':
	X+ 		b_flag = 1;
	X+ 		break;
	X  	    case 'z':
	X  		z_flag = 1;
	X  		break;
	X*** fmtr.h	Thu Jun 19 10:22:16 1986
	X--- fmtr.new.h	Thu Jun 19 10:21:14 1986
	X***************
	X*** 1,6
	X  #include <stdio.h>
	X  #include <ctype.h>
	X  
	X  int z_flag;		/* look behind zero width spaces? */
	X  int nf_val;		/* no fill on or off? */
	X  int ul_val;		/* number of lines to underline */
	X
	X--- 1,7 -----
	X  #include <stdio.h>
	X  #include <ctype.h>
	X  
	X+ int b_flag;		/* begin each sentence on a new line */
	X  int z_flag;		/* look behind zero width spaces? */
	X  
	X  int nf_val;		/* no fill on or off? */
	X***************
	X*** 2,7
	X  #include <ctype.h>
	X  
	X  int z_flag;		/* look behind zero width spaces? */
	X  int nf_val;		/* no fill on or off? */
	X  int ul_val;		/* number of lines to underline */
	X  int ce_val;		/* number of lines to center */
	X
	X--- 3,9 -----
	X  
	X  int b_flag;		/* begin each sentence on a new line */
	X  int z_flag;		/* look behind zero width spaces? */
	X+ 
	X  int nf_val;		/* no fill on or off? */
	X  int ul_val;		/* number of lines to underline */
	X  int ce_val;		/* number of lines to center */
	X***************
	X*** 5,10
	X  int nf_val;		/* no fill on or off? */
	X  int ul_val;		/* number of lines to underline */
	X  int ce_val;		/* number of lines to center */
	X  int llength;
	X  
	X  char outbuf[BUFSIZ];	/* output buffer, ridiculously large */
	X
	X--- 7,15 -----
	X  int nf_val;		/* no fill on or off? */
	X  int ul_val;		/* number of lines to underline */
	X  int ce_val;		/* number of lines to center */
	X+ 
	X+ int in_display;		/* are we inside a display? */
	X+ int in_preproc;		/* are we inside preprocessor commands? */
	X  int llength;
	X  
	X  char outbuf[BUFSIZ];	/* output buffer, ridiculously large */
	X*** fmtr.1	Thu Jun 19 10:21:57 1986
	X--- fmtr.new.1	Thu Jun 19 10:21:09 1986
	X***************
	X*** 1,4
	X! .TH FMTR 1H LOCAL "4th Berkeley Distribution"
	X  .SH NAME
	X  fmtr \- simple formatter for
	X  .I roff
	X
	X--- 1,4 -----
	X! .TH FMTR 1H LOCAL "Harvard"
	X  .SH NAME
	X  fmtr \- simple formatter for
	X  .I roff
	X***************
	X*** 5,11
	X  source files
	X  .SH SYNOPSIS
	X  .B fmtr
	X! [ \-w
	X  .I width
	X  ] [ \-z ] [ \-s
	X  .I .s1.s2.s3 ... .sn
	X
	X--- 5,11 -----
	X  source files
	X  .SH SYNOPSIS
	X  .B fmtr
	X! [ \-b ] [ -z ] [ \-w
	X  .I width
	X  ] [ \-s
	X  .I .s1.s2.s3 ... .sn
	X***************
	X*** 7,13
	X  .B fmtr
	X  [ \-w
	X  .I width
	X! ] [ \-z ] [ \-s
	X  .I .s1.s2.s3 ... .sn
	X  ] [ \-e
	X  .I .e1.e2.e3 ... .en
	X
	X--- 7,13 -----
	X  .B fmtr
	X  [ \-b ] [ -z ] [ \-w
	X  .I width
	X! ] [ \-s
	X  .I .s1.s2.s3 ... .sn
	X  ] [ \-e
	X  .I .e1.e2.e3 ... .en
	X***************
	X*** 84,89
	X  .I \-z
	X  flag it will peek under a zero width character at the start of a line
	X  seeking a command.
	X  .I Fmtr
	X  knows about the
	X  .IR ms (7)
	X
	X--- 84,92 -----
	X  .I \-z
	X  flag it will peek under a zero width character at the start of a line
	X  seeking a command.
	X+ If you specify the
	X+ .I \-b
	X+ flag each sentence will begin on a new line.
	X  .I Fmtr
	X  knows about the
	X  .IR ms (7)
	X*** lowtext.c	Thu Jun 19 10:22:24 1986
	X--- lowtext.new.c	Thu Jun 19 10:21:18 1986
	X***************
	X*** 5,10
	X  #include "fmtr.h"
	X  
	X  int ti_val;
	X  
	X  /*  leadbl() deals with leading blanks, causes break, then sets
	X   *  ti_val to number of blanks, unless line is blank.  Then pulls
	X
	X--- 5,11 -----
	X  #include "fmtr.h"
	X  
	X  int ti_val;
	X+ int e_of_sen;
	X  
	X  /*  leadbl() deals with leading blanks, causes break, then sets
	X   *  ti_val to number of blanks, unless line is blank.  Then pulls
	X***************
	X*** 58,64
	X      }
	X  
	X      while (*pline != ' ' && *pline != '\0') {
	X! 	if (*pline == '\\' && isspace(pline[1])) /* get escaped space in word */
	X  	    *word++ = *pline++;
	X          *word++ = *pline++;
	X      }
	X
	X--- 59,65 -----
	X      }
	X  
	X      while (*pline != ' ' && *pline != '\0') {
	X! 	if (*pline == '\\' && isspace(pline[1])) /* get escaped space */
	X  	    *word++ = *pline++;
	X          *word++ = *pline++;
	X      }
	X***************
	X*** 63,71
	X          *word++ = *pline++;
	X      }
	X  
	X!     /*  get trailing spaces, and guarantee spaces at end of line;
	X!      *  normally one but two at end of sentence.
	X!      */
	X  
	X      if (*pline == '\0') {
	X  	char *cptmp = pline;
	X
	X--- 64,70 -----
	X          *word++ = *pline++;
	X      }
	X  
	X!     /* are we at end of sentence? */
	X  
	X      if (*pline == '\0' || (*pline == ' ' && *(pline + 1) == ' ')) {
	X  	char *cptmp = pline;
	X***************
	X*** 67,73
	X       *  normally one but two at end of sentence.
	X       */
	X  
	X!     if (*pline == '\0') {
	X  	char *cptmp = pline;
	X  
	X  	*word++ = ' ';
	X
	X--- 66,72 -----
	X  
	X      /* are we at end of sentence? */
	X  
	X!     if (*pline == '\0' || (*pline == ' ' && *(pline + 1) == ' ')) {
	X  	char *cptmp = pline;
	X  
	X  	while (any(*--cptmp, "\"']})"))
	X***************
	X*** 70,76
	X      if (*pline == '\0') {
	X  	char *cptmp = pline;
	X  
	X- 	*word++ = ' ';
	X  	while (any(*--cptmp, "\"']})"))
	X  	    ;
	X  	if (any(*cptmp, ".:!?"))
	X
	X--- 69,74 -----
	X      if (*pline == '\0' || (*pline == ' ' && *(pline + 1) == ' ')) {
	X  	char *cptmp = pline;
	X  
	X  	while (any(*--cptmp, "\"']})"))
	X  	    ;
	X  	if (any(*cptmp, ".:!?"))
	X***************
	X*** 74,79
	X  	while (any(*--cptmp, "\"']})"))
	X  	    ;
	X  	if (any(*cptmp, ".:!?"))
	X  	    *word++ = ' ';
	X      }
	X      while (*pline == ' ')
	X
	X--- 72,89 -----
	X  	while (any(*--cptmp, "\"']})"))
	X  	    ;
	X  	if (any(*cptmp, ".:!?"))
	X+ 	    e_of_sen = 1;
	X+ 	else
	X+ 	    e_of_sen = 0;
	X+     }
	X+ 
	X+     /*  if at end of line, add one space (two if end of sentence.
	X+      *  otherwise  get trailing spaces.
	X+      */
	X+ 
	X+     if (*pline == '\0') {
	X+ 	*word++ = ' ';
	X+ 	if (e_of_sen)
	X  	    *word++ = ' ';
	X      }
	X  
	X***************
	X*** 76,81
	X  	if (any(*cptmp, ".:!?"))
	X  	    *word++ = ' ';
	X      }
	X      while (*pline == ' ')
	X  	*word++ = *pline++;
	X      *word = '\0';
	X
	X--- 86,92 -----
	X  	if (e_of_sen)
	X  	    *word++ = ' ';
	X      }
	X+ 
	X      while (*pline == ' ')
	X  	*word++ = *pline++;
	X  
	X***************
	X*** 78,83
	X      }
	X      while (*pline == ' ')
	X  	*word++ = *pline++;
	X      *word = '\0';
	X      return(pline);
	X  }
	X
	X--- 89,95 -----
	X  
	X      while (*pline == ' ')
	X  	*word++ = *pline++;
	X+ 
	X      *word = '\0';
	X      return(pline);
	X  }
	X***************
	X*** 92,98
	X      if (s + t <= llength - ti_val) {
	X  	for (; *word; *outp++ = *word++)
	X  	    ;
	X- 	return;
	X      }
	X      n_brk();
	X      for (; *word; *outp++ = *word++)
	X
	X--- 104,109 -----
	X      if (s + t <= llength - ti_val) {
	X  	for (; *word; *outp++ = *word++)
	X  	    ;
	X      }
	X      else {
	X  	n_brk();
	X***************
	X*** 94,102
	X  	    ;
	X  	return;
	X      }
	X!     n_brk();
	X!     for (; *word; *outp++ = *word++)
	X! 	;
	X  }
	X  
	X  put(line)	/* output routine, separate as is more complex in original */
	X
	X--- 105,120 -----
	X  	for (; *word; *outp++ = *word++)
	X  	    ;
	X      }
	X!     else {
	X! 	n_brk();
	X! 	for (; *word; *outp++ = *word++)
	X! 	    ;
	X!     }
	X! 
	X!     if (e_of_sen && b_flag) {
	X! 	n_brk();
	X! 	e_of_sen = 0;
	X!     }
	X  }
	X  
	X  put(line)	/* output routine, separate as is more complex in original */
	X*** command.c	Thu Jun 19 10:21:39 1986
	X--- command.new.c	Thu Jun 19 10:21:16 1986
	X***************
	X*** 22,28
	X  
	X  enum cmdtype
	X      {
	X!     CE, UL, FI, NF, OTHER
	X      } cmd, getcmd();
	X  
	X  int len;
	X
	X--- 22,39 -----
	X  
	X  enum cmdtype
	X      {
	X! 	CE,		/* center */
	X! 	UL,		/* underline */
	X! 	FI,		/* fill mode */
	X! 	NF,		/* no fill mode */
	X! 	PPS,		/* start preprocessor statements */
	X! 	PPE,		/* end preprocessor statements */
	X! 	PS,		/* start pic statements, special case .PS < file */
	X! 	ME_DS,		/* start display in me macros */
	X! 	MM_DS,		/* start display in mm macros */
	X! 	MS_DS,		/* start display in ms macros */
	X! 	DE,		/* end display (me or mm) */
	X! 	OTHER
	X      } cmd, getcmd();
	X  
	X  int len;
	X***************
	X*** 30,36
	X  struct cmd {
	X      char *name;
	X      enum cmdtype type;
	X! } cmd_table[50] = { "ce", CE,	/* basic nroff requests */
	X  		    "ul", UL,
	X  		    "nf", NF,
	X  		    "fi", FI,
	X
	X--- 41,47 -----
	X  struct cmd {
	X      char *name;
	X      enum cmdtype type;
	X! } cmd_table[50] = { "ce", CE,		/* basic nroff requests */
	X  		    "ul", UL,
	X  		    "nf", NF,
	X  		    "fi", FI,
	X***************
	X*** 34,60
	X  		    "ul", UL,
	X  		    "nf", NF,
	X  		    "fi", FI,
	X! 		    "TS", NF,	/* universal macros */
	X! 		    "TE", FI,
	X! 		    "EQ", NF,
	X! 		    "EN", FI,
	X! 		    "PS", NF,
	X! 		    "PE", FI,
	X! 		    "IS", NF,
	X! 		    "IE", FI,
	X! 		    "DS", NF,	/* ms macros */
	X! 		    "ID", NF,
	X! 		    "CD", NF,
	X! 		    "LD", NF,
	X! 		    "DE", FI,
	X! 		    "(b", NF,	/* me macros */
	X! 		    ")b", FI,
	X! 		    "(c", NF,
	X! 		    ")c", FI,
	X! 		    "(l", NF,
	X! 		    ")l", FI,
	X! 		    "(z", NF,
	X! 		    ")z", FI,
	X  		    (char *) NULL, OTHER
	X  		};
	X  
	X
	X--- 45,73 -----
	X  		    "ul", UL,
	X  		    "nf", NF,
	X  		    "fi", FI,
	X! 		    "TS", PPS,		/* preprocessor start and end */
	X! 		    "TE", PPE,
	X! 		    "EQ", PPS,
	X! 		    "EN", PPE,
	X! 		    "PS", PS,		/* special because of .PS < file */
	X! 		    "PE", PPE,
	X! 		    "IS", PPS,		/* ideal, if you have it! */
	X! 		    "IE", PPE,
	X! 		    "G1", PPS,		/* grap */
	X! 		    "G2", PPE,
	X! 		    "DS", MM_DS,	/* ms macros */
	X! 		    "ID", MM_DS,
	X! 		    "CD", MM_DS,
	X! 		    "LD", MM_DS,
	X! 		    "DE", DE,
	X! 		    "(b", ME_DS,	/* me macros of the display variety */
	X! 		    ")b", DE,
	X! 		    "(c", ME_DS,
	X! 		    ")c", DE,
	X! 		    "(l", ME_DS,
	X! 		    ")l", DE,
	X! 		    "(z", ME_DS,
	X! 		    ")z", DE,
	X  		    (char *) NULL, OTHER
	X  		};
	X  
	X***************
	X*** 88,93
	X  	    nf_val = 1;
	X  	    break;
	X  	case FI:
	X  	    nf_val = 0;
	X  	    break;
	X  	}
	X
	X--- 101,118 -----
	X  	    nf_val = 1;
	X  	    break;
	X  	case FI:
	X+ 	    if (in_preproc == 0 && in_display == 0)
	X+ 		nf_val = 0;
	X+ 	    break;
	X+ 	case ME_DS:
	X+ 	case MM_DS:
	X+ 	    if (index(line, 'F') == NULL) {
	X+ 		in_display = 1;
	X+ 		nf_val = 1;
	X+ 	    }
	X+ 	    break;
	X+ 	case DE:
	X+ 	    in_display = 0;
	X  	    nf_val = 0;
	X  	    break;
	X  	case PPS:
	X***************
	X*** 89,94
	X  	    break;
	X  	case FI:
	X  	    nf_val = 0;
	X  	    break;
	X  	}
	X  
	X
	X--- 114,137 -----
	X  	case DE:
	X  	    in_display = 0;
	X  	    nf_val = 0;
	X+ 	    break;
	X+ 	case PPS:
	X+ 	    in_preproc = 1;
	X+ 	    nf_val = 1;
	X+ 	    break;
	X+ 	case PPE:
	X+ 	    in_preproc = 0;
	X+ 	    if (in_display == 0)
	X+ 		nf_val = 0;
	X+ 	    break;
	X+ 	case PS:
	X+ 	    if (index(line, '<') == NULL) {	/* not .PS < file */
	X+ 		in_preproc = 1;
	X+ 		nf_val = 1;
	X+ 	    }
	X+ 	    break;
	X+ 	default:
	X+ 	    fprintf(stderr, "program bug: got cmd = %d\n", cmd);
	X  	    break;
	X  	}
	X  
SHAR_EOF
if test 10921 -ne "`wc -c < 'diffs'`"
then
	echo shar: error transmitting "'diffs'" '(should have been 10921 characters)'
fi
chmod +x 'diffs'
fi # end of overwriting check
#	End of shell archive
exit 0