/******************************************************************
unpinyin.c
Description: Convert text between and into
image references.
Revision History:
Date Pgmr / Modification notes
1997 02 21 ETH - first release
Programmer Notes:
None.
*****************************************************************/
/* Include Files */
#include /* strcat, strlen, etc. prototypes */
#include /* contains needed types */
#include
#include
#include
# define TRUE (1)
# define FALSE (0)
typedef enum
{
eBYPASS,
eIN_TRANSLATE_MODE,
eIN_TAG
} state_e;
int next_char;
int next_char_already_gotten = FALSE;
int get_next_char (
void
)
{
if (next_char_already_gotten)
next_char_already_gotten = FALSE;
else
next_char = getchar();
return next_char;
}
/******************** End of get_next_char *************************/
void unget_next_char (
void
)
{
next_char_already_gotten = TRUE;
}
/******************** End of unget_next_char ***********************/
void OutputPicture(
int ch
)
{
if (isalpha(ch))
{
int tone;
fputs("", stdout);
}
else
putchar(ch);
}
/******************* End of OutputPicture ************************/
int main (
int argc, /* number of arguments to main */
char *argv[] /* list of arguments to main */
/* This routine "returns" EXIT_SUCCESS or EXIT_FAILURE */
)
{
int tagbuffer_index = 0;
char tagbuffer[256];
int ch;
state_e state = eBYPASS;
state_e saved_state = eBYPASS;
while ((ch = get_next_char()) != EOF)
switch (state)
{
case eIN_TRANSLATE_MODE:
if (ch == '<')
{
state = eIN_TAG;
saved_state = eIN_TRANSLATE_MODE;
}
else
OutputPicture(ch);
break;
case eIN_TAG:
if (ch == '>')
{
if (strcasecmp(tagbuffer, "pinyin") == 0)
state = eIN_TRANSLATE_MODE;
else if (strcasecmp(tagbuffer, "/pinyin") == 0)
state = eBYPASS;
else
{
putchar('<');
fputs(tagbuffer, stdout);
putchar('>');
state = saved_state;
}
tagbuffer_index = 0;
}
else
{
tagbuffer[tagbuffer_index] = ch;
tagbuffer_index++;
}
tagbuffer[tagbuffer_index] = '\0';
break;
case eBYPASS:
if (ch == '<')
{
state = eIN_TAG;
saved_state = eBYPASS;
}
else
putchar(ch);
break;
default:
fputs("error", stderr);
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
/************************* End of main *******************/
/************************* End of unpinyin.c *************/