Sun Unix Source Code for Application Module 1sp.c
1sp.c converts strings of consecutive ASCII spaces to a single ASCII space.
This Sun Unix code, 1sp.c, is the filter module for a file filter.
It receives data from an input file and creates data for the output
file. The transfer function is to convert any nmber of consecutive ASCII
spaces (20h) to a single space. This module was written to create input
files for the unix cut text filter.
There are no EOF bytes in the output file.
Unix portability is an issue, so source is given here. It was written to be
called by gcore.c. That module performs all the file management aspects,
such as opening the input file, creating an output file, etc.
There are no HTML tags in the source code below.
/* Filespec= 1sp.c, 1 space. This module converts any string of space chars
(0x20) to one space. No other changes are made. */
/* In comments, BHM=Being Here Means */
#include
#include "stdio.h"
#include
#include
/* PURPOSE: This module contains the transfer function of a file
filter, where an existing input file is read, and a new output
file is created.
This module reads and modifies an ASCII input data stream.
Changes made are:
--Any occurrences of more that one consecutive space are converted to
a single space.
--The transfer function for this activity is in subroutine
"genotp()". */
typedef enum {True, False} template;
template SP_string=False;
template Cr_sensed=False; /* True here means input file is MS-DOS */
#define cr 0x0d /* Carriage return */
#define lf 0x0a /* Line feed */
#define eof 0x1a /* End of file */
#define sp 0x20 /* Space */
/* Module Globals */
extern void ship(); /* Declaration */
extern char getnc(); /* Declaration */
char nc; /* nc is the latest input char */
genotp() /* BEGIN GENOTP */
{
while(2) /* Use '2' instead of '1' to make it more obvious */
{ /* Start of while(2) */
nc=getnc();
if (nc==cr) Cr_sensed=True;
if (nc==sp)
{
if (SP_string==False) ship(sp);
SP_string=True;
}
else
{
SP_string=False;
ship(nc);
}
} /* end of while (2) */
} /* END GENOTP */
void final_wryte() /* BEGIN FINAL_WRYTE */
{
extern void wryte();
/* The final invoking of wryte() and any special activities relating to
the end of the program are performed here */
if (Cr_sensed == True) ship(eof); /* True here means input file is MS-DOS
ASCII */
wryte();
} /* END FINAL_WRYTE */
/* End of Module */