Select Git revision
regex-match.c
Per Cederqvist authored
regex-match.c 3.11 KiB
/*
* $Id: regex-match.c,v 1.7 1993/10/14 09:11:33 ceder Exp $
* Copyright (C) 1992 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
*
* LysKOM is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* LysKOM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with LysKOM; see the file COPYING. If not, write to
* Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
* or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA.
*
* Please mail bug reports to bug-lyskom@lysator.liu.se.
*/
/*
* Regexp matching
*/
static char *rcsid = "$Id: regex-match.c,v 1.7 1993/10/14 09:11:33 ceder Exp $";
#include "rcs.h"
USE(rcsid);
#include <stdio.h>
#include <setjmp.h>
#include <sys/types.h>
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#include "s-string.h"
#include "misc-types.h"
#include "kom-types.h"
#include "services.h"
#include "regex.h"
#include "server/smalloc.h"
#include "cache.h"
#include "kom-errno.h"
#include "com.h"
#include "connections.h"
#include "manipulate.h"
#include "log.h"
static Success
lookup_regexp (const String regexp,
Conf_no_list *result,
Bool want_persons)
{
struct re_pattern_buffer pat_buf;
Conf_no conf_no;
String name = EMPTY_STRING;
const char *errmsg;
/* +++ Unnecessary to allocate this much if only one conference matches. */
result->conf_nos = tmp_alloc (cached_no_of_existing_conferences()
* sizeof(Conf_no));
result->no_of_confs = 0;
re_syntax_options = RE_SYNTAX_GREP;
pat_buf.translate = swedish_collate_tab;
pat_buf.translate = NULL;
pat_buf.fastmap = 0;
pat_buf.allocated = 0;
pat_buf.buffer = 0;
if ((errmsg =
re_compile_pattern(regexp.string, s_strlen(regexp), &pat_buf))
!= NULL)
{
regfree(&pat_buf);
kom_errno = KOM_REGEX_ERROR;
return FAILURE;
}
for (conf_no = 0; (conf_no = traverse_conference(conf_no)) != 0;)
{
if (cached_get_conf_type(conf_no).letter_box == want_persons
&& fast_access_perm (conf_no, ACTPERS, ACT_P) > none )
{
name = cached_get_name(conf_no);
switch ( re_search (&pat_buf, name.string, s_strlen(name), 0,
s_strlen(name), NULL) )
{
case -1:
break;
case -2:
log("Internal error in regex.");
break;
default:
/* It matched. (Ignore where it matched). */
result->conf_nos[result->no_of_confs++] = conf_no;
break;
}
}
}
regfree(&pat_buf);
return OK;
}
Success
re_lookup_person (const String regexp,
Conf_no_list *result)
{
return lookup_regexp(regexp, result, TRUE);
}
Success
re_lookup_conf (const String regexp,
Conf_no_list *result)
{
return lookup_regexp(regexp, result, FALSE);
}