<commit_before>// Copyright 2007-2009 <NAME>.  All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "regexp.h"

struct {
	char *name;
	int (*fn)(ByteProg*, char*, char**, int);
} tab[] = {
	{"recursive", recursiveprog},
	{"recursiveloop", recursiveloopprog},
	{"backtrack", backtrack},
	{"thompson", thompsonvm},
	{"pike", pikevm},
};

void
usage(void)
{
	fprintf(stderr, "usage: re regexp string...\n");
	exit(2);
}

int
main(int argc, char **argv)
{
	int i, j, k, l;
	Regexp *re;
	Prog *prog;
	char *sub[MAXSUB];

	if(argc < 2)
		usage();
	
	re = parse(argv[1]);
	printre(re);
	printf("\n");

	prog = compile(re);
	printprog(prog);
	printf("=============\n");
	ByteProg *code = compile2code(argv[1]);
	dump_code(code);

	for(i=2; i<argc; i++) {
		printf("#%d %s\n", i, argv[i]);
		for(j=0; j<nelem(tab); j++) {
			printf("%s ", tab[j].name);
			memset(sub, 0, sizeof sub);
			if(!tab[j].fn(code, argv[i], sub, nelem(sub))) {
				printf("-no match-\n");
				continue;
			}
			printf("match");
			for(k=MAXSUB; k>0; k--)
				if(sub[k-1])
					break;
			for(l=0; l<k; l+=2) {
				printf(" (");
				if(sub[l] == nil)
					printf("?");
				else<commit_msg>Allocate as much submatch index elements as actually required.<commit_after>// Copyright 2007-2009 <NAME>.  All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "regexp.h"

struct {
	char *name;
	int (*fn)(ByteProg*, char*, char**, int);
} tab[] = {
	{"recursive", recursiveprog},
	{"recursiveloop", recursiveloopprog},
	{"backtrack", backtrack},
	{"thompson", thompsonvm},
	{"pike", pikevm},
};

void
usage(void)
{
	fprintf(stderr, "usage: re regexp string...\n");
	exit(2);
}

int
main(int argc, char **argv)
{
	int i, j, k, l;
	Regexp *re;
	Prog *prog;

	if(argc < 2)
		usage();
	
	re = parse(argv[1]);
	printre(re);
	printf("\n");

	prog = compile(re);
	printprog(prog);
	printf("=============\n");
	ByteProg *code = compile2code(argv[1]);
	dump_code(code);

	int sub_els = (code->sub + 1) * 2;
	char *sub[sub_els];
	for(i=2; i<argc; i++) {
		printf("#%d %s\n", i, argv[i]);
		for(j=0; j<nelem(tab); j++) {
			printf("%s ", tab[j].name);
			memset(sub, 0, sub_els * sizeof sub[0]);
			if(!tab[j].fn(code, argv[i], sub, sub_els)) {
				printf("-no match-\n");
				continue;
			}
			printf("match");
			for(k=sub_els; k>0; k--)
				if(sub[k-1])
					break;
			for(l=0; l<k; l+=2) {
				printf(" (");
				if(sub[l] == nil)
					printf("?");
				else
{'fraction_non_alphanumeric': 0.22672380210362292, 'fraction_numerical': 0.01675107128944293, 'mean_word_length': 3.652173913043478, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '3640608', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1044, 'n_words': 259}