casefix Version 1.1

Jeff Beadles jeff at onion.pdx.com
Fri Dec 14 07:25:14 AEST 1990


Well, there was a bug on some systems with the original version of casefix that
I posted last week.  Some system's don't handle toupper/tolower properly if the
character is not alpha to be begin with.  So, I've changed things like
	ch = tolower(ch) to...

	if (isupper(ch))
		ch = tolower(ch);

Also, I've added the provision for '\n\n' to also be considered the end
of a sentence.

I decided not to post a patch, as the entire source listing is <5k.


Have fun, and remember to always post follow-up's to alt.sources.d :-)

	-Jeff

#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive.  Save this into a file, edit it
# and delete all lines above this comment.  Then give this
# file to sh by executing the command "sh file".  The files
# will be extracted into the current directory owned by
# you with default permissions.
#
# The files contained herein are:
#
# -rw-r--r--  1 jeff          601 Dec 13 12:15 README
# -rw-r--r--  1 jeff         2549 Dec 13 12:19 casefix.c
#
echo 'x - README'
if test -f README; then echo 'shar: not overwriting README'; else
sed 's/^X//' << '________This_Is_The_END________' > README
Xcasefix.c - Copyright 1990, Jeff Beadles.  All rights reserved.
X
XPermission is granted to copy this at NO charge, as long as the copyright
Xmessage remains intact.
X
XThis program will take all all upper/lower case text, and attempt to convert it
Xto mixed case.  It is not 100% accurate.  It doesn't know about things
Xlike proper nouns.  (But what do you expect for free? :-)
X
XTo compile:  cc -o casefix casefix.c  (Simple enough.)
X
XTo use:  casefix < ifile > ofile
X
XHave fun!  Feel free to send constructive comments or patches.
X
X	-Jeff
X-- 
XJeff Beadles	jeff at onion.pdx.com (or) uunet!onion.pdx.com!jeff
________This_Is_The_END________
if test `wc -c < README` -ne 601; then
	echo 'shar: README was damaged during transit (should have been 601 bytes)'
fi
fi		; : end of overwriting check
echo 'x - casefix.c'
if test -f casefix.c; then echo 'shar: not overwriting casefix.c'; else
sed 's/^X//' << '________This_Is_The_END________' > casefix.c
X/*
X * Submittor: Jeff Beadles	jeff at onion.pdx.com
X * Date: Thu Dec 13 12:11:39 PST 1990
X * Name: casefix
X * Version: 1.1
X * Machine: Unix
X * Synopsis: Fixes all upper/lower case text into mixed case.
X * Category: utils
X */
X
X/* casefix.c - Copyright 1990, Jeff Beadles.  All rights reserved.
X * Permission is granted to copy this at NO charge, as long as the copyright
X * message remains intact.
X *
X * This is not 100% accurate.  It doesn't know about things like proper nouns.
X * (But what do you expect for free? :-)
X *
X * To compile:  cc -o casefix casefix.c  (Simple enough.)
X *
X * To use:  casefix < ifile > ofile
X *
X *  Have fun!  Feel free to send constructive comments or patches to:
X *	jeff at onion.pdx.com    (or)
X *	uunet!onion.pdx.com!jeff
X *
X * Version 1.1: Fixed a bug on some machines where if you use toupper/tolower
X *		on a non-alpha character, it scrambles it.  Grr....
X *		Also, '\n\n' marks the end of a sentence.
X */
X
X#include <stdio.h>
X#include <ctype.h>
X
X/* ARGSUSED */
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X
X{
X    int ch;			/* Tmp character holder */
X    int lastch;			/* Last char displayed */
X    int nextch;			/* Next character to be displayed (For I') */
X    int newsent;		/* Start of sentence flag */
X
X    newsent = 1;		/* Start file with a new sentence */
X    nextch = lastch = -1;	/* Nothing in them yet. */
X
X    while(1) {
X    	/* if readahead buffer is empty, then get another char */
X    	if ( nextch == -1) {
X    		if ( (ch = getc(stdin)) == EOF )
X    			exit(0);
X    	} else {
X    		ch = nextch;
X    		nextch = -1;
X    	}
X    	/* Default, is to make it lower case. */
X    	if(isupper(ch))
X		ch = tolower(ch);
X
X    	/* Cap "(For example...)" */
X    	if ( (lastch == '(') && (islower(ch)))
X    		ch = toupper(ch);
X
X    	/* Cap "I will, I've */
X    	if ( (isspace(lastch)) && (ch == 'i') ) {
X    		if ( (nextch = getchar()) == EOF) {
X    			putchar(ch);
X    			exit(0);
X    		}
X		/* Don't ungetc nextch, as it will be used next.  */
X    		if ((isspace(nextch)) || (nextch == '\'')) {
X			if(islower(ch)) {
X    				ch = toupper(ch);
X			}
X    		}
X    	}
X
X    	/* Cap 1st word of a new sentence. */
X    	if ( (newsent) && isalpha(ch)) {
X    		newsent = 0;
X		if(islower(ch)) {
X	    		ch = toupper(ch);
X		}
X    	}
X
X    	/* Sentences end with '.', '!', ':', '?', or ';'. or '\n\n' */
X    	if ( (ch == '.') || (ch == '!') ||
X	     (ch == ':') || (ch == ';') || (ch == '?') ||
X	     ( (ch == '\n') && (lastch == '\n')) )
X    		newsent = 1;
X
X    	/* Finally, display the character */
X    	putchar(ch);
X    	lastch = ch;
X    }
X}
________This_Is_The_END________
if test `wc -c < casefix.c` -ne 2549; then
	echo 'shar: casefix.c was damaged during transit (should have been 2549 bytes)'
fi
fi		; : end of overwriting check
exit 0



More information about the Alt.sources mailing list