<commit_before>/*
 * Copyright (c) 2000 <NAME> <<EMAIL>>
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include "../configure.h"

#include <stdio.h>
#include <string.h>

#include "../include/aftersteplib.h"
#include "../include/afterstep.h"
#include "../include/regexp.h"

/************************************************************************/
/************************************************************************/
/*			regexp compiler and datastructures		*/
/************************************************************************/

typedef struct reg_exp_multichar_part
{
	unsigned char code[254];
	unsigned char size;
}
reg_exp_multichar_part;


typedef struct reg_exp_sym
{
	unsigned char negate;					   /* if we have [!blahblah] */
	/* in worst case scenario code should not occupy more then 2*255 characters */
	unsigned char code[512];
	unsigned short size;
}
reg_exp_sym;

typedef struct reg_exp
{
	struct reg_exp *prev, *next;

	short int     left_offset, right_offset;   /* min number of characters that we have to 
											      leave on each size of the string in question
											      for other patterns to be able to match */
	short int     left_fixed, right_fixed;	   /* indicates if we have a * on left or 
											      right side and therefore flexible
											      with our position */

	short int     lead_len;					   /* -1 for '*' */
	/* number of symbols : */
	unsigned char size;						   /* upto 255 characters in regexp */
	/* symbol can be:
	   - single character    : c
	   - set of characters   : [ccccccc]
	   - range of characters : [r-r]
	   more then that, it can be negated : [!cccccc] or [!r-r]
	   or it can be combined         : [cccc,r-r] or [!ccccc,r-r]

	   methinks we should pack them all together like so:

	   ccccc0x01rr0x01rr0x01rrccccc0x00.....
	   where ccccc - are single characters that are compared one-to-one
	   and rr - represent range on characters like r-r.
	   0x01 denotes range
	   0x00 denotes end of the symbol. 
	   so we'll store them in single character array,
	   plus another array will store negation indicators.
	 */

	unsigned char *symbols;
	unsigned char *negation;

	/* in Booer-Moor algorithm we need to use a skip table  - 
	   indicating where we should go if character mismatches any symbol 
	   (skip offset for each character in alphabeth)
	 */
	unsigned char skip[256];				   /* skip table */

}
reg_exp;

unsigned char
parse_singlechar (unsigned char **data, unsigned char *reserved)
{
	register unsigned char c = **data;

	while (*reserved)
		if ((c == *(reserved++)))
			return 0x00;

	if (c == '\\')
		c = *(++(*data));

	(*data)++;
	return c;
}

reg_exp_multichar_part *
parse_multichar_part (unsigned char **data)
{
	static reg_exp_multichar_part part;
	unsigned char c;

	if ((c = parse_singlechar (data, "],")) == 0x00)
		return NULL;
	if (**data == '-')
	{										   /* range */<commit_msg>added feature (lib/global.c) allowing for levels of verbose output Added database printing functions Added database building code into InitDatabase Fixed few stupid bugs in regexp compilation code.<commit_after>/*
 * Copyright (c) 2000 <NAME> <<EMAIL>>
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include "../configure.h"

#include <stdio.h>
#include <string.h>

#include "../include/aftersteplib.h"
#include "../include/afterstep.h"
#include "../include/regexp.h"

/************************************************************************/
/************************************************************************/
/*			regexp compiler and datastructures		*/
/************************************************************************/

typedef struct reg_exp_multichar_part
{
	unsigned char code[254];
	unsigned char size;
}
reg_exp_multichar_part;


typedef struct reg_exp_sym
{
	unsigned char negate;					   /* if we have [!blahblah] */
	/* in worst case scenario code should not occupy more then 2*255 characters */
	unsigned char code[512];
	unsigned short size;
}
reg_exp_sym;

typedef struct reg_exp
{
	struct reg_exp *prev, *next;

	short int     left_offset, right_offset;   /* min number of characters that we have to
											      leave on each size of the string in question
											      for other patterns to be able to match */
	short int     left_fixed, right_fixed;	   /* indicates if we have a * on left or
											      right side and therefore flexible
											      with our position */

	short int     lead_len;					   /* -1 for '*' */
	/* number of symbols : */
	unsigned char size;						   /* upto 255 characters in regexp */
	/* symbol can be:
	   - single character    : c
	   - set of characters   : [ccccccc]
	   - range of characters : [r-r]
	   more then that, it can be negated : [!cccccc] or [!r-r]
	   or it can be combined         : [cccc,r-r] or [!ccccc,r-r]

	   methinks we should pack them all together like so:

	   ccccc0x01rr0x01rr0x01rrccccc0x00.....
	   where ccccc - are single characters that are compared one-to-one
	   and rr - represent range on characters like r-r.
	   0x01 denotes range
	   0x00 denotes end of the symbol.
	   so we'll store them in single character array,
	   plus another array will store negation indicators.
	 */

	unsigned char *symbols;
	unsigned char *negation;

	/* in Booer-Moor algorithm we need to use a skip table  -
	   indicating where we should go if character mismatches any symbol
	   (skip offset for each character in alphabeth)
	 */
	unsigned char skip[256];				   /* skip table */

}
reg_exp;

unsigned char
parse_singlechar (unsigned char **data, unsigned char *reserved)
{
	register unsigned char c = **data;

    if( c != '\0' )
    {
        while (*reserved)
            if ((c == *(reserved++)))
                return 0x00;

        if (c == '\\')
            c = *(++(*data));

        (*data)++;
    }
	return c;
}

reg_exp_multichar_part *
parse_multichar_part (unsigned char **data)
{
	static reg_exp_multichar_part part;
	unsigned char c;

	if ((c = parse_singlechar (data, "],")) == 0x00)
		return NULL;
	if (**data == '-')
	{										   /* range */
{'fraction_non_alphanumeric': 0.14824834302718787, 'fraction_numerical': 0.014743676450696606, 'mean_word_length': 3.042646254784035, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7281212', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2066, 'n_words': 859}