// File: gersteinlab[P]MUSIC/src/ms_ansi_string.cpp
// Function: t_string::get_first_n_tokens(char*, int, char const*, int&)
vector<t_string*>* t_string::get_first_n_tokens(char* string, int n_tokens, const char* delimiter_list, int& i_next_char)
{
	vector<t_string*>* first_tokens = new vector<t_string*>();
	
	// This is the pointer to the next character in the string.
	int i_s = 0;

	// Process the next character.
	t_string* next_token = new t_string();
	while((int)first_tokens->size() != n_tokens &&
		string[i_s] != 0)
	{
		bool is_delim = false;
		int n_delimiters = t_string::string_length(delimiter_list);
		for(int i_d = 0; 
			!is_delim && i_d < n_delimiters; 
			i_d++)
		{
			if(delimiter_list[i_d] == string[i_s])
			{
				is_delim = true;
			}
		} // i_d loop.

		// This is not a delimiter.
		if(!is_delim)
		{
			next_token->concat_char(string[i_s]);
		} // delimiter check.
		else
		{
			// If this token contains characters, add it.
			if(next_token->length() > 0)
			{
				// Add the next token.
				first_tokens->push_back(next_token);

				// Reallocate the next token.
				next_token = new t_string();
			}
			else
			{
				delete(next_token);
				next_token = new t_string();
			}
		}

		//fprintf(stderr, "Procesing %d: %d. tokens: %s\n", i_s, first_tokens->size(), next_token->str());
		i_s++;
	} // token addition loop.

	// If the next token was generated for the last string in the string, add it to the list of tokens.
	// This is not added because the token adding is done per delimiter character.
	if(next_token->length() > 0)
	{
		first_tokens->push_back(next_token);
	}
	else
	{
		delete(next_token);
	}

	// Skip over all the delimiters.	
	bool is_delim = true;
	while(is_delim && string[i_s] != 0)
	{
		is_delim = false;

		int n_delimiters = t_string::string_length(delimiter_list);
		for(int i_d = 0; 
			!is_delim && i_d < n_delimiters; 
			i_d++)
		{
			if(delimiter_list[i_d] == string[i_s])
			{
				is_delim = true;
			}
		} // i_d loop.

		if(is_delim)
		{
			i_s++;
		}
	} // delimiter skipping loop.

	// Next character is the index of next character in the string, which is a delimiter.
	i_next_char = i_s;

	return(first_tokens);
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movl %esi, 0x9c(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x4b800
movq 0x38(%rsp), %rax
movq %rax, 0x80(%rsp)
movl $0x0, 0x7c(%rsp)
movl $0x8, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x40(%rsp)
callq 0x474d0
jmp 0x4937c
movq 0x40(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x80(%rsp), %rdi
callq 0x45c40
movl %eax, %ecx
xorl %eax, %eax
cmpl 0x9c(%rsp), %ecx
movb %al, 0x37(%rsp)
je 0x493bf
movq 0xa0(%rsp), %rax
movslq 0x7c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0x37(%rsp)
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x493cc
jmp 0x4958b
movb $0x0, 0x63(%rsp)
movq 0x90(%rsp), %rdi
callq 0x47640
movl %eax, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
xorl %eax, %eax
testb $0x1, 0x63(%rsp)
movb %al, 0x36(%rsp)
jne 0x49406
movl 0x58(%rsp), %eax
cmpl 0x5c(%rsp), %eax
setl %al
movb %al, 0x36(%rsp)
movb 0x36(%rsp), %al
testb $0x1, %al
jne 0x49410
jmp 0x49471
movq 0x90(%rsp), %rax
movslq 0x58(%rsp), %rcx
movsbl (%rax,%rcx), %eax
movq 0xa0(%rsp), %rcx
movslq 0x7c(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x4945f
movb $0x1, 0x63(%rsp)
jmp 0x4945f
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
movl $0x8, %esi
callq 0x21a0
jmp 0x496c6
jmp 0x49461
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x493ea
testb $0x1, 0x63(%rsp)
jne 0x49498
movq 0x70(%rsp), %rdi
movq 0xa0(%rsp), %rax
movslq 0x7c(%rsp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x481d0
jmp 0x4957b
movq 0x70(%rsp), %rdi
callq 0x481a0
cmpl $0x0, %eax
jle 0x49506
movq 0x80(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x4b810
movl $0x8, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x28(%rsp)
callq 0x474d0
jmp 0x494d5
movq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x49579
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
movl $0x8, %esi
callq 0x21a0
jmp 0x496c6
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
je 0x4952f
movq 0x20(%rsp), %rdi
callq 0x47f70
movq 0x20(%rsp), %rdi
movl $0x8, %esi
callq 0x21a0
movl $0x8, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
callq 0x474d0
jmp 0x4954b
movq 0x18(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x49579
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
movl $0x8, %esi
callq 0x21a0
jmp 0x496c6
jmp 0x4957b
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x49386
movq 0x70(%rsp), %rdi
callq 0x481a0
cmpl $0x0, %eax
jle 0x495ae
movq 0x80(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x4b810
jmp 0x495d9
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x495d7
movq 0x10(%rsp), %rdi
callq 0x47f70
movq 0x10(%rsp), %rdi
movl $0x8, %esi
callq 0x21a0
jmp 0x495d9
movb $0x1, 0x57(%rsp)
xorl %eax, %eax
testb $0x1, 0x57(%rsp)
movb %al, 0xf(%rsp)
je 0x49606
movq 0xa0(%rsp), %rax
movslq 0x7c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x49613
jmp 0x496a8
movb $0x0, 0x57(%rsp)
movq 0x90(%rsp), %rdi
callq 0x47640
movl %eax, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
xorl %eax, %eax
testb $0x1, 0x57(%rsp)
movb %al, 0xe(%rsp)
jne 0x4964d
movl 0x4c(%rsp), %eax
cmpl 0x50(%rsp), %eax
setl %al
movb %al, 0xe(%rsp)
movb 0xe(%rsp), %al
testb $0x1, %al
jne 0x49657
jmp 0x49691
movq 0x90(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
movq 0xa0(%rsp), %rcx
movslq 0x7c(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x49682
movb $0x1, 0x57(%rsp)
jmp 0x49684
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x49631
testb $0x1, 0x57(%rsp)
je 0x496a3
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x495de
movl 0x7c(%rsp), %ecx
movq 0x88(%rsp), %rax
movl %ecx, (%rax)
movq 0x80(%rsp), %rax
addq $0xa8, %rsp
retq
movq 0x68(%rsp), %rdi
callq 0x2300