# HG changeset patch # User viric@llimona # Date 1191841167 -7200 # Node ID 7d316733d4b1f7e0c5723be481eb920ed7aa7f58 # Parent 56f491e63466408608b9e3197714700f3a321821 Added filterdes. diff -r 56f491e63466 -r 7d316733d4b1 filter_tildes.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filter_tildes.c Mon Oct 08 12:59:27 2007 +0200 @@ -0,0 +1,84 @@ +/* + Terminal Mixer - multi-point multi-user access to terminal applications + Copyright (C) 2007 LluĂ­s Batlle i Rossell + + Please find the license in the provided COPYING file. +*/ +#include +#include +#include "filter.h" +#include "main.h" + +struct FTildes +{ + struct FFilter base; +}; + +static void ftildes_reset(struct FFilter *ff) +{ + ff->matched = 0; +} + +static int ftildes_function(struct FFilter *ff, unsigned char c) +{ + struct FTildes *fs = (struct FTildes *) ff; + + dump_line("ftildes: base.matched: %i\n", fs->base.matched); + switch(fs->base.matched) + { + case 0: + if (c == '~') + fs->base.matched++; + else + fs->base.matched = 0; + break; + case 1: + if (c == '~') + fs->base.matched++; + else + fs->base.matched = 0; + break; + case 2: + if (c == '.') + { + fs->base.matched++; + return 1; + } + else if (c == '~') + { + fs->base.matched++; + return 1; + } else + fs->base.matched = 0; + break; + default: + fs->base.matched = 0; + } + return 0; +} + +struct FFilter *new_ftildes(char *p) +{ + struct FTildes *fs; + fs = (struct FTildes *) malloc(sizeof(*fs)); + + fs->base.matched = 0; + fs->base.function = ftildes_function; + fs->base.reset = ftildes_reset; + fs->base.callback = 0; + + return (struct FFilter *) fs; +} + +struct FFilter *new_ftildes_len(char *p, int len) +{ + struct FTildes *fs; + fs = (struct FTildes *) malloc(sizeof(*fs)); + + fs->base.matched = 0; + fs->base.function = ftildes_function; + fs->base.reset = ftildes_reset; + fs->base.callback = 0; + + return (struct FFilter *) fs; +}