🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #21435

Re: What do you use to remove Paragraph Returns from your Text?

#21435
From: dave
Date: Tue, 10 Nov 1987 21:30
85 lines
2519 bytes
Well, here is what we use.  It's a program called "macfmt" that massages
the file on the UNIX machine before it is sent to the Mac.  Basically,
it turns trailing newlines into blank space, but does understand that
there should be two blanks after a period.

This probably ought to be a "lex" program, but it is such a simple problem
that it's coded directly as a finite state machine.

Macfmt is a pure filter - it takes no arguments.  It is usually called
by a shell script called "macsend" that runs macfmt first, then does
the transfer to the Mac using macput.

(this isn't big enough to be worth submitting to the moderated source group)

--------------------------------------------------------------------
#include <stdio.h>

#define	S_TEXT		0	/* in normal text */
#define	S_PERIOD	1	/* just saw a period */
#define	S_ENDWORD	2	/* found newline preceded by text character */
#define	S_ENDSENT	3	/* found newline preceded by period */
#define	S_ENDPARA	4	/* newline followed by newline */

main()
{
	register int	c, state = S_TEXT;

	while ((c=getchar()) != EOF) {
		switch (c) {

		default:
			switch (state) {
			case S_ENDWORD:
				putchar(' ');
				break;
			case S_ENDSENT:
				putchar(' ');
				putchar(' ');
				break;
			}
			putchar(c);
			state = S_TEXT;
			break;

		case '.':
		case '!':
			switch (state) {
			case S_ENDWORD:
				putchar(' ');
				break;
			case S_ENDSENT:
				putchar(' ');
				putchar(' ');
				break;
			}
			putchar(c);
			state = S_PERIOD;
			break;

		case '\n':
			switch (state) {
			case S_TEXT:
				state = S_ENDWORD;
				break;
			case S_PERIOD:
				state = S_ENDSENT;
				break;
			case S_ENDWORD:
			case S_ENDSENT:
			case S_ENDPARA:
				putchar(c);
				state = S_ENDPARA;
				break;
			}
			break;
		}
	}

	switch (state) {
	case S_TEXT:
	case S_ENDWORD:
	case S_ENDSENT:
		putchar ('\n');
	}
}
Technical Details
Message-ID: <15460@onfcanim.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!onfcanim!dave
References: <2089@sputnik.COM> <272@nikhefk.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!onfcanim!dave
From: dave@onfcanim.UUCP
Newsgroups: comp.sys.mac
Subject: Re: What do you use to remove Paragraph Returns from your Text?
Message-ID: <15460@onfcanim.UUCP>
Date: Tue, 10-Nov-87 16:30:42 EST
Article-I.D.: onfcanim.15460
Posted: Tue Nov 10 16:30:42 1987
Date-Received: Thu, 12-Nov-87 06:11:58 EST
References: <2089@sputnik.COM> <272@nikhefk.UUCP>
Reply-To: dave@onfcanim.UUCP (Dave Martindale)
Organization: National Film Board / Office national du film, Montreal
Lines: 85