File: flex_mail.lex

package info (click to toggle)
bow 19991122-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,544 kB
  • ctags: 2,987
  • sloc: ansic: 38,660; lisp: 1,072; makefile: 594; perl: 492; yacc: 149; sh: 91
file content (67 lines) | stat: -rw-r--r-- 1,600 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
%{
#include <ctype.h>
#include "bow/archer.h"

static long pos = 0;

%}

%option noyywrap
%x BODY BINARY

ANUM		[A-Za-z0-9]+
PUNCT		[^A-Za-z0-9 \t\f\r\n]
WS		[ \t\f\r\n]
CTYPE		Content-Type:{WS}+
NONWS		[^ \t\f\r\n]
PS		%!PS

%%

^{WS}*$		bow_reset_labels(); BEGIN(BODY); pos += flex_mail_leng;
^{NONWS}+/:     bow_reset_labels(); bow_push_label(flex_mail_text); pos += flex_mail_leng;
{ANUM}		pos += flex_mail_leng; return 1;
.               pos += flex_mail_leng;
\n              pos += flex_mail_leng;
<BODY>^{CTYPE}application[/]	BEGIN(BINARY); pos += flex_mail_leng;
<BODY>^{CTYPE}image[/]		BEGIN(BINARY); pos += flex_mail_leng;
<BODY>^{PS}			BEGIN(BINARY); pos += flex_mail_leng;
<BODY>{ANUM}			pos += flex_mail_leng; return 1;
<BODY>.                         pos += flex_mail_leng;
<BODY>\n                        pos += flex_mail_leng;
<BINARY>^{CTYPE}text[/]         BEGIN(BODY); pos += flex_mail_leng;
<BINARY>.                       pos += flex_mail_leng;
<BINARY>\n                      pos += flex_mail_leng;
 
%%

void flex_mail_open(FILE *fp, const char * name)
{
  flex_mail_in = fp;
  pos = 0;
  BEGIN(INITIAL);
}

int flex_mail_get_word_extended(char buf[], int bufsz, long *start, long *end)
{
  int i;

  if (!flex_mail_lex())
    return 0;

  strncpy(buf, flex_mail_text, bufsz);
  buf[bufsz-1] = 0;
  for (i = 0; i < flex_mail_leng; ++i)
    buf[i] = tolower(buf[i]);

  if(start != NULL) {
    *end = pos - 1;
    *start = pos - flex_mail_leng;
  }

  return 1;
}

int flex_mail_get_word(char buf[], int bufsz) {
  return flex_mail_get_word_extended(buf, bufsz, NULL, NULL);
}