79
|
1 |
/*
|
|
2 |
Terminal Mixer - multi-point multi-user access to terminal applications
|
|
3 |
Copyright (C) 2007 LluĂs Batlle i Rossell
|
|
4 |
|
|
5 |
Please find the license in the provided COPYING file.
|
|
6 |
*/
|
|
7 |
#include <stdlib.h>
|
|
8 |
#include <string.h>
|
|
9 |
#include "filter.h"
|
|
10 |
#include "main.h"
|
|
11 |
|
|
12 |
struct FTildes
|
|
13 |
{
|
|
14 |
struct FFilter base;
|
|
15 |
};
|
|
16 |
|
|
17 |
static void ftildes_reset(struct FFilter *ff)
|
|
18 |
{
|
|
19 |
ff->matched = 0;
|
|
20 |
}
|
|
21 |
|
|
22 |
static int ftildes_function(struct FFilter *ff, unsigned char c)
|
|
23 |
{
|
|
24 |
struct FTildes *fs = (struct FTildes *) ff;
|
|
25 |
|
|
26 |
dump_line("ftildes: base.matched: %i\n", fs->base.matched);
|
|
27 |
switch(fs->base.matched)
|
|
28 |
{
|
|
29 |
case 0:
|
|
30 |
if (c == '~')
|
|
31 |
fs->base.matched++;
|
|
32 |
else
|
|
33 |
fs->base.matched = 0;
|
|
34 |
break;
|
|
35 |
case 1:
|
|
36 |
if (c == '~')
|
|
37 |
fs->base.matched++;
|
|
38 |
else
|
|
39 |
fs->base.matched = 0;
|
|
40 |
break;
|
|
41 |
case 2:
|
|
42 |
if (c == '.')
|
|
43 |
{
|
|
44 |
fs->base.matched++;
|
|
45 |
return 1;
|
|
46 |
}
|
|
47 |
else if (c == '~')
|
|
48 |
{
|
|
49 |
fs->base.matched++;
|
|
50 |
return 1;
|
|
51 |
} else
|
|
52 |
fs->base.matched = 0;
|
|
53 |
break;
|
|
54 |
default:
|
|
55 |
fs->base.matched = 0;
|
|
56 |
}
|
|
57 |
return 0;
|
|
58 |
}
|
|
59 |
|
|
60 |
struct FFilter *new_ftildes(char *p)
|
|
61 |
{
|
|
62 |
struct FTildes *fs;
|
|
63 |
fs = (struct FTildes *) malloc(sizeof(*fs));
|
|
64 |
|
|
65 |
fs->base.matched = 0;
|
|
66 |
fs->base.function = ftildes_function;
|
|
67 |
fs->base.reset = ftildes_reset;
|
|
68 |
fs->base.callback = 0;
|
|
69 |
|
|
70 |
return (struct FFilter *) fs;
|
|
71 |
}
|
|
72 |
|
|
73 |
struct FFilter *new_ftildes_len(char *p, int len)
|
|
74 |
{
|
|
75 |
struct FTildes *fs;
|
|
76 |
fs = (struct FTildes *) malloc(sizeof(*fs));
|
|
77 |
|
|
78 |
fs->base.matched = 0;
|
|
79 |
fs->base.function = ftildes_function;
|
|
80 |
fs->base.reset = ftildes_reset;
|
|
81 |
fs->base.callback = 0;
|
|
82 |
|
|
83 |
return (struct FFilter *) fs;
|
|
84 |
}
|