home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
lang
/
skel_azt.sha
/
crsm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-07-08
|
3KB
|
113 lines
/* crsm -- CR state machine to force all textedit lines to end with CR
* The intent is to force 4 kinds of end-of-line to become a single CR:
* 1. CR
* 2. LF
* 3. CRLF
* 4. LFCR
*
* There are 4 states:
* 1. examine characters until end
* on CR enter state 2 with next character
* on LF enter state 3 with this character
* on other characters, remain in state 1 with next character
* 2. examine characters
* on end return to state 1 to terminate
* on LF delete a character and remain in state 2 with next
* character (which is in this position after the delete)
* on CR remain in state 2 with next character
* on other characters, return to state 1 with next character
* 3. replace the LF with a CR, examine next character
* on end return to state 1 to terminate
* on CR enter state 4
* on LF remain in state 3
* on other characters, return to state 1 with this character
* 4. delete the extraneous CR, examine next character (which is
* in this position after the delete)
* on end return to state 1 to terminate
* on CR transfer to state 2 with next character
* transfer to LF and other check in state 3 with next character
*/
#include <textedit.h>
void
crsm()
{
char *cp;
extern TEHandle hTE;
Boolean run;
extern Boolean crsmccr(), crsmeof(), crsmfcr();
cp = *((*hTE)->hText);
run = TRUE;
while (run) {
if (*cp == '\r') /* state 1 */
run = crsmfcr(++cp); /* enter state 2 */
else if (*cp == '\n')
run = crsmccr(cp); /* enter state 3 */
else
run = !crsmeof(cp++);
};
} /* end of crsm() */
Boolean
crsmccr(cp) /* state 3 */
char *cp;
{
extern Boolean crsmeof(), crsmfcr();
extern void crsmdch();
while (TRUE) {
*cp++ = '\r';
if (crsmeof(cp))
return(FALSE);
if (*cp == '\r') { /* enter state 4 */
crsmdch(cp); /* state 4 */
if (crsmeof(cp))
return(FALSE); /* return to state 1 to exit */
if (*cp == '\r')
return(crsmfcr(++cp)); /* enter state 2 */
};
if (*cp != '\n')
return(TRUE); /* return to state 1 */
};
} /* end of crsmccr() */
void
crsmdch(cp)
char *cp;
{
extern TEHandle hTE;
(*hTE)->selStart = (short)(cp - *((*hTE)->hText));
(*hTE)->selEnd = (*hTE)->selStart;
TEDelete(hTE);
} /* end of crsmdch() */
Boolean
crsmeof(cp)
char *cp;
{
extern TEHandle hTE;
return(cp >= ((*hTE)->teLength + *((*hTE)->hText)));
} /* end of crsmeof */
Boolean
crsmfcr(cp) /* state 2 */
char *cp;
{
extern Boolean crsmccr(), crsmeof();
extern void crsmdch();
while (TRUE) {
if (crsmeof(cp))
return(FALSE); /* return to state 1 to exit */
if (*cp == '\n')
crsmdch(cp);
else if (*cp++ != '\r')
return(TRUE); /* return to state 1 */
};
} /* end of crsmfcr */