diff options
author | horchi <vdr@jwendel.de> | 2017-03-05 16:48:30 +0100 |
---|---|---|
committer | horchi <vdr@jwendel.de> | 2017-03-05 16:48:30 +0100 |
commit | bf558fd824c7ab8c794448f718b364ad403a706a (patch) | |
tree | e0ba2269c08ccc9c9bd9c336df06b1fa6fce5ec6 /rep.c | |
download | vdr-plugin-pin-bf558fd824c7ab8c794448f718b364ad403a706a.tar.gz vdr-plugin-pin-bf558fd824c7ab8c794448f718b364ad403a706a.tar.bz2 |
git init0.1.16
Diffstat (limited to 'rep.c')
-rw-r--r-- | rep.c | 77 |
1 files changed, 77 insertions, 0 deletions
@@ -0,0 +1,77 @@ +/* + * pin.c: A plugin for the Video Disk Recorder + * + * See the README file for copyright information and how to reach the author. + * + * Date: 29.01.2006, horchi + */ + +#include <stdio.h> +#include <sys/types.h> +#include <regex.h> + +#include "rep.h" +#include "def.h" + +//************************************************************************** +// Regular Expression Searching +//************************************************************************** + +int rep(const char* string, const char* expression, Option options) +{ + const char* tmpA; + const char* tmpB; + + return rep( string, expression, tmpA, tmpB, options); +} + + +int rep(const char* string, const char* expression, const char*& s_location, + Option options) +{ + const char* tmpA; + + return rep( string, expression, s_location, tmpA, options); +} + + +int rep(const char* string, const char* expression, const char*& s_location, + const char*& e_location, Option options) +{ + regex_t reg; + regmatch_t rm; + int status; + int opt = 0; + + // Vorbereiten von reg fuer die Expressionsuche mit regexec + // Flags: REG_EXTENDED = Use Extended Regular Expressions + // REG_ICASE = Ignore case in match. + + reg.re_nsub = 0; + + // Options umwandeln + if (options & repUseRegularExpression) + opt = opt | REG_EXTENDED; + if (options & repIgnoreCase) + opt = opt | REG_ICASE; + + if (regcomp( ®, expression, opt) != 0) + return fail; + + // Suchen des ersten Vorkommens von reg in string + + status = regexec( ®, string, 1, &rm, 0); + regfree(®); + + if (status != 0) + return fail; + + // Suche erfolgreich => + // Setzen der ermittelten Start- und Endpositionen + + s_location = (char*)(string + rm.rm_so); + e_location = (char*)(string + rm.rm_eo); + + return success; +} + |