#include <u.h>
#include <libc.h>
#include <regexp.h>
#include "utils.h"

Resub match[MSZ];

char * 
copymatch(int i)
{
	int len;
	char * s_match;
	if(match[i].ep && match[i].sp && match[i].ep > match[i].sp){
		len = (long long)match[i].ep - (long long)match[i].sp;
		s_match = malloc(len+1);
		strncpy(s_match,match[i].sp, len);
		s_match[len] = 0;
		for(int i = len -1 ; s_match[i] == ' ' || s_match[i] == '	'; i--)
			s_match[i] = 0;
		return s_match;
	}
	return nil;
}

int
mcuistrcmp(char* a, char* b){
	int ret;
	char * at = malloc(strlen(a) + 1);
	char * bt = malloc(strlen(b) + 1);
	for(int i = strlen(a) ; i >= 0; i--){
		at[i] = ( (a[i] == '_') ? ' ': ( (a[i] > 'Z' && a[i] < '{' ) ? (a[i]-' '):a[i]) );
	}
	for(int i = strlen(b) ; i >= 0; i--){
		bt[i] = ( (b[i] == '_') ? ' ': ( (b[i] > 'Z' && b[i] < '{' ) ? (b[i]-' '):b[i]) );
	}
	ret = strcmp(at,bt);
	free(at);
	free(bt);
	return ret;
}





