Example #1
0
bool Text_File::Buffer_To_List()
{
	char *buffer_ptr = buffer; //position buffer pointer to start of buffer

	while (true)
	{
		//seek for char not space (if not end of buffer)
		while (*buffer_ptr != '\0' && isspace(*buffer_ptr))
			++buffer_ptr;

		//reached end (end of buffer, comment or newline)
		if (*buffer_ptr == '\0' || *buffer_ptr == '#' || *buffer_ptr == '\n')
			break;

		//
		//ok got start of new word
		//

		//there are two kinds of "words"
		if (*buffer_ptr == '\"') //quotation: "word" begins after " and ends at " (or \0)
		{
			//go one step more (don't want " in word)
			++buffer_ptr;

			//wery unusual error (line ends after quotation mark)
			if (*buffer_ptr == '\0')
			{
				printlog(0, "WARNING: Text_File line ended just after quotation mark (not counted)...");
				break;
			}

			//ok
			Append_To_List(buffer_ptr);

			//find next " or end of line
			while (*buffer_ptr!='\"' && *buffer_ptr!='\0')
				++buffer_ptr;

			if (*buffer_ptr=='\0') //end of line before end of quote
				printlog(0, "WARNING: Text_File reached end of line before end of quote...");
			else
			{
				*buffer_ptr = '\0'; //make this end (instead of ")
				++buffer_ptr; //jump over this "local" end
			}
		}
		else //normal: word begins after space and ends at space (or \0)
		{
			Append_To_List(buffer_ptr);

			//look for end of word (space or end of buffer)
			++buffer_ptr;
			while (*buffer_ptr != '\0' && !isspace(*buffer_ptr))
				++buffer_ptr;

			//if word ended by end of buffer, do nothing. else
			if (*buffer_ptr != '\0')
			{
				*buffer_ptr = '\0'; //mark as end of word
				++buffer_ptr; //jump over local end
			}
		}
	}

	//in case no words were read from buffer
	if (word_count==0)
		return false;
	
	return true;
}
Example #2
0
void List_Test()
{
    List *list, *temp, *nomemleak;
    int *start, *prepend, *append;

    printf( "\n#### List test ####\n" );

    start = C_New( int, 1 );
    *start = 5;
    prepend = C_New( int, 1 );
    *prepend = 0;
    append = C_New( int, 1 );
    *append = 9;

    printf( "start: %i\n", *start );
    printf( "prepend: %i\n", *prepend );
    printf( "append: %i\n", *append );

    /* New_List test */
    list = New_List( start );
    if( !list )
    {
	printf( "NULL list" );
	exit( -1 );
    }
    if( list->next )
    {
	printf( "next in the list isn't NULL" );
    }
    if( list->data )
    {
	printf( "start data: %i\n", *( int* )( list->data ) );
    }

    /* Length_Of_List test */
    printf( "length: %i\n", ( int )( Length_Of_List( list ) ) );

    /* Prepend_To_List test */
    temp = Prepend_To_List( list, prepend );
    if( temp ) list = temp;
    temp = Prepend_To_List( list, prepend );
    if( temp ) list = temp;

    /* Append_To_List test */
    temp = Append_To_List( list, append );
    if( temp ) list = temp;
    temp = Append_To_List( list, append );
    if( temp ) list = temp;

    /* Length_Of_List test */
    printf( "length: %i\n", ( int )( Length_Of_List( list ) ) );


    /* Find_In_List test */
    temp = Find_In_List( list, start );
    if( temp ) printf( "found: %i\n", *( int* )( temp->data ) );
    temp = Find_In_List( list, prepend );
    if( temp ) printf( "found: %i\n", *( int* )( temp->data ) );
    temp = Find_In_List( list, append );
    if( temp ) printf( "found: %i\n", *( int* )( temp->data ) );
    temp = Find_In_List( list, NULL );
    if( temp ) printf( "found: %i\n", *( int* )( temp->data ) );

    /* Remove_From_List test */
    list = Remove_From_List( list, start, FALSE );
    list = Remove_From_List( list, append, TRUE );

    /* End_Of_List test */
    temp = End_Of_List( list );
    printf( "last: %i\n", *( int* )( temp->data ) );
    
    /* Duplicate_List test */
    temp = Duplicate_List( list );
    nomemleak = temp;
    while( temp )
    {
	printf( "dup: %i\n", *( int* )( temp->data ) );
	temp = temp->next;
    }

    /* print values in the List */
    printf( "data in the list\n" );
    temp = list;
    while( temp )
    {
	printf( "data: %i\n", *( int* )( temp->data ) );
	temp = temp->next;
    }

    /* Free_List test */
    temp = NULL;
    Free_List( &nomemleak );
    Free_List( &list );
}