<commit_before>/**
 * Melo Melo Search!
 * Search a byte sequence in sequence file by melody.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <time.h>

#define APP_NAME	"Melo Melo Search"
#define APP_VER		"[2013-12-05]"
#define APP_AUTHOR	"[loveemu](http://loveemu.googlecode.com/)"

#define COUNT(a)	(sizeof(a) / sizeof(a[0]))

#define MELO_MAX_NOTE_DIST_DEFAULT	6

// make sure it is greater than (maxNotes * maxMeloDist * 2) bytes
#define MELO_SEARCH_BLOCK_SIZE	0x10000

// Command path (set by main)
char *glCommandPath = NULL;
// Input filename
char glInFilename[512] = { '\0' };
// ...
bool glQuiet = false;

// define byte
typedef unsigned char byte;

// define generic note structure
typedef struct
{
	int time;
	int key;
	int duration;
} SeqNote;

#define NOTE_KEY_REST	0x1000
#define NOTE_KEY_TIE	0x1001

// simple mml parser, returns an array of notes
bool parseMML(SeqNote *notes, int &noteCount, int maxNotes, const char *mml)
{
	if (notes == NULL || mml == NULL)
	{
		return false;
	}

	int i = 0;
	int time = 0;
	int octave = 4;
	int timebase = 48;
	int defaultLength = 4;
	char *endp = NULL;
	noteCount = 0;
	while (mml[i] != '\0')
	{
		char c = tolower(mml[i]);

		if (isspace(c))
		{
			// do nothing
		}
		else if (c == 't')
		{
			i++;
			double tempo = strtod(&mml[i], &endp);
			if (endp == &mml[i])
			{
				fprintf(stderr, "Error: Illegal tempo number '%c'\n", mml[i]);
				return false;
			}
			if (tempo <= 0.0)
			{
				fprintf(stderr, "Error: Illegal tempo '%.1f'\n", tempo);
				return false;
			}
			i += (endp - &mml[i]);
		}
		else if (c == 'o')
		{
			i++;
			octave = strtol(&mml[i], &endp, 10);
			if (endp == &mml[i])
			{
				fprintf(stderr, "Error: Illegal octave number '%c'\n", mml[i]);
				return false;
			}
			i += (endp - &mml[i]);
		}
		else if (c == 'l')
		{
			i++;
			defaultLength = strtol(&mml[i], &endp, 10);
			if (endp == &mml[i])
			{
				fprintf(stderr, "Error: Illegal default length '%c'\n", mml[i]);
				return false;
			}
			if (defaultLength <= 0)
			{
				fprintf(stderr, "Error: Illegal default length '%d'\n", defaultLength);
				return false;
			}
			i += (endp - &mml[i]);
		}
		else if (c == '<')
		{
			octave++;
			i++;
		}
		else if (c == '>')
		{
			octave--;
			i++;
		}
		else if ((c >= 'a' && c <= 'g') || c == 'r' || c == '^')
		{
			int key = 0;
			if (c >= 'a' && c <= 'g')
			{
				int keys[] = { 9, 11, 0, 2, 4, 5, 7 };
				key = keys[c - 'a'] + (octave * 12);
			}
			else if (c == 'r')
			{
				key = NOTE_KEY_REST;
			}
			else if (c == '^')
			{
				key = NOTE_KEY_TIE;
			}
			i++;

			while (mml[i] == '+' || mml[i] == '-')
			{
				if (mml[i] == '+')
				{
					key++;
				}
				else if (mml[i] == '-')
				{
					key++;
				}
				i++;<commit_msg>Fix MML '-' operator<commit_after>/**
 * Melo Melo Search!
 * Search a byte sequence in sequence file by melody.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <time.h>

#define APP_NAME	"Melo Melo Search"
#define APP_VER		"[2015-11-16]"
#define APP_AUTHOR	"[loveemu](http://loveemu.googlecode.com/)"

#define COUNT(a)	(sizeof(a) / sizeof(a[0]))

#define MELO_MAX_NOTE_DIST_DEFAULT	6

// make sure it is greater than (maxNotes * maxMeloDist * 2) bytes
#define MELO_SEARCH_BLOCK_SIZE	0x10000

// Command path (set by main)
char *glCommandPath = NULL;
// Input filename
char glInFilename[512] = { '\0' };
// ...
bool glQuiet = false;

// define byte
typedef unsigned char byte;

// define generic note structure
typedef struct
{
	int time;
	int key;
	int duration;
} SeqNote;

#define NOTE_KEY_REST	0x1000
#define NOTE_KEY_TIE	0x1001

// simple mml parser, returns an array of notes
bool parseMML(SeqNote *notes, int &noteCount, int maxNotes, const char *mml)
{
	if (notes == NULL || mml == NULL)
	{
		return false;
	}

	int i = 0;
	int time = 0;
	int octave = 4;
	int timebase = 48;
	int defaultLength = 4;
	char *endp = NULL;
	noteCount = 0;
	while (mml[i] != '\0')
	{
		char c = tolower(mml[i]);

		if (isspace(c))
		{
			// do nothing
		}
		else if (c == 't')
		{
			i++;
			double tempo = strtod(&mml[i], &endp);
			if (endp == &mml[i])
			{
				fprintf(stderr, "Error: Illegal tempo number '%c'\n", mml[i]);
				return false;
			}
			if (tempo <= 0.0)
			{
				fprintf(stderr, "Error: Illegal tempo '%.1f'\n", tempo);
				return false;
			}
			i += (endp - &mml[i]);
		}
		else if (c == 'o')
		{
			i++;
			octave = strtol(&mml[i], &endp, 10);
			if (endp == &mml[i])
			{
				fprintf(stderr, "Error: Illegal octave number '%c'\n", mml[i]);
				return false;
			}
			i += (endp - &mml[i]);
		}
		else if (c == 'l')
		{
			i++;
			defaultLength = strtol(&mml[i], &endp, 10);
			if (endp == &mml[i])
			{
				fprintf(stderr, "Error: Illegal default length '%c'\n", mml[i]);
				return false;
			}
			if (defaultLength <= 0)
			{
				fprintf(stderr, "Error: Illegal default length '%d'\n", defaultLength);
				return false;
			}
			i += (endp - &mml[i]);
		}
		else if (c == '<')
		{
			octave++;
			i++;
		}
		else if (c == '>')
		{
			octave--;
			i++;
		}
		else if ((c >= 'a' && c <= 'g') || c == 'r' || c == '^')
		{
			int key = 0;
			if (c >= 'a' && c <= 'g')
			{
				int keys[] = { 9, 11, 0, 2, 4, 5, 7 };
				key = keys[c - 'a'] + (octave * 12);
			}
			else if (c == 'r')
			{
				key = NOTE_KEY_REST;
			}
			else if (c == '^')
			{
				key = NOTE_KEY_TIE;
			}
			i++;

			while (mml[i] == '+' || mml[i] == '-')
			{
				if (mml[i] == '+')
				{
					key++;
				}
				else if (mml[i] == '-')
				{
					key--;
				}
				i++;
{'fraction_non_alphanumeric': 0.1973566708340775, 'fraction_numerical': 0.020717985354527593, 'mean_word_length': 2.5510462904248574, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, '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': '5130366', 'n_tokens_mistral': 2792, 'n_tokens_neox': 2317, 'n_words': 623}