%{ /* rich_l.l definition of lexical box for rich text parser. */ #if 0 #define RICH_L_DEBUG 1 #endif #undef output #undef input #define output(c) #define YY_INPUT(buf,result,max_size) \ { \ int c = rich_getc(); \ result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \ } #if 0 #define input() (\ (\ (\ yytchar=\ yysptr>yysbuf?\ U(*--yysptr)\ :rich_getc()\ ) == 10?\ (yylineno++,yytchar)\ :yytchar\ ) == (unsigned char) EOF?\ 0\ :yytchar\ ) #endif %} %START LINK_FIRST IN_BOLD_LINE IN_ITALIC_LINE R_JUSTIFY_LINE %% \\[lL][a-zA-Z0-9]+" " { /* first half of LINK */ int len; BEGIN LINK_FIRST; len = strlen(yytext); yytext[len-1] = '\0'; strcpy(return_lnk,&yytext[2]); } [^\n\\]*\\[lL] { /* second half of LINK */ int len; BEGIN 0; len = strlen(yytext); strcpy(return_string,yytext); return_string[len-2] = '\0'; return LINK; } \\s....\\s { /* SYMBOL */ BEGIN 0; strcpy(return_string,&yytext[2]); return_string[4] = '\0'; return SYMBOL; } \\f\[[0-9]+\] { /* parses upto /f[#] */ BEGIN R_JUSTIFY_LINE; strcpy(return_string,&yytext[2]); /* leave off the \f */ } [^\n\\]*\\f { int len; BEGIN 0; len = strlen(yytext); yytext[len-2] = '\0'; /* leave off the trailing \f */ strcat(return_string,yytext); /* append the rest */ return R_JUSTIFY; } " " { /* force a division in text at space. */ BEGIN IN_BOLD_LINE; } " " { /* force a division in text at space. */ BEGIN IN_ITALIC_LINE; } "\\n" { /* force a division in text at space. */ BEGIN 0; return LINEFEED; } " " { /* force a division in text at space. */ BEGIN 0; } \\b[^ \\\n]* { /* bold start */ BEGIN IN_BOLD_LINE; strcpy(return_string,&yytext[2]); #ifdef RICH_L_DEBUG printf("%s\n",return_string); #endif return BOLD; } [^ \\\n]* { /* bold until next space */ BEGIN IN_BOLD_LINE; strcpy(return_string,yytext); #ifdef RICH_L_DEBUG printf("%s\n",return_string); #endif return BOLD; } [^ \\\n]*\\b { /* bold end */ int len; BEGIN 0; len = strlen(yytext); strcpy(return_string,yytext); return_string[len-2] = '\0'; #ifdef RICH_L_DEBUG printf("%s\n",return_string); #endif return BOLD; } \\i[^ \\\n]* { /* italic start */ BEGIN IN_ITALIC_LINE; strcpy(return_string,&yytext[2]); #ifdef RICH_L_DEBUG printf("%s\n",return_string); #endif return ITALIC; } [^ \\\n]* { /* italic until next space */ BEGIN IN_ITALIC_LINE; strcpy(return_string,yytext); #ifdef RICH_L_DEBUG printf("%s\n",return_string); #endif return ITALIC; } [^ \\\n]*\\i { /* italic end */ int len; BEGIN 0; len = strlen(yytext); strcpy(return_string,yytext); return_string[len-2] = '\0'; #ifdef RICH_L_DEBUG printf("%s\n",return_string); #endif return ITALIC; } [^ \\\n]+ { /* normal text on a line */ BEGIN 0; strcpy(return_string,yytext); return NORMAL; } \n { /* Force a break on linefeed */ /* ... if line was recently too long, ignore */ BEGIN IN_BOLD_LINE; } \n { /* Force a break on linefeed */ /* ... if line was recently too long, ignore */ BEGIN IN_ITALIC_LINE; } \n { /* Force a break on linefeed */ /* ... if line was recently too long, ignore */ BEGIN 0; } %% extern int yyprevious; yywrap() { /* re_initialize lex globals */ // yylineno =1; // yysptr = yysbuf; // yyprevious = YYNEWLINE; return 1; }