test/test-automation/xml.c
author Markus Kauppila <markus.kauppila@gmail.com>
Sun, 03 Jul 2011 10:54:21 +0300
changeset 5737 303be71c64aa
parent 5732 1da5af48b964
child 5771 3f908b34b645
permissions -rw-r--r--
Fixed XML logger. EscapeString didn't from strings properly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     1
/*
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     2
  Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     3
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     4
  This software is provided 'as-is', without any express or implied
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     6
  arising from the use of this software.
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     7
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    10
  freely, subject to the following restrictions:
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    11
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    12
  1. The origin of this software must not be misrepresented; you must not
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    13
     claim that you wrote the original software. If you use this software
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    14
     in a product, an acknowledgment in the product documentation would be
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    15
     appreciated but is not required.
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    16
  2. Altered source versions must be plainly marked as such, and must not be
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    17
     misrepresented as being the original software.
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    18
  3. This notice may not be removed or altered from any source distribution.
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    19
*/
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    20
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    21
#include <stdio.h>
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    22
#include <string.h>
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    23
#include <assert.h>
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    24
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    25
#include <SDL/SDL.h>
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    26
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    27
#include "xml.h"
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    28
#include "logger_helpers.h"
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    29
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    30
/*! Size for xml element buffer */
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    31
#define bufferSize 1024
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    32
/*! Buffer for storing the xml element under construction */
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    33
static char buffer[bufferSize];
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    34
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    35
/*! Pointer to XML root element's tag */
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    36
static const char *root;
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    37
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    38
/*!
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    39
 * Defines structure used for "counting" open XML-tags
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    40
 */
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    41
typedef struct TagList {
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    42
	const char *tag;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    43
	struct TagList *next;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    44
} TagList;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    45
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    46
static TagList *openTags = NULL;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    47
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    48
/*!
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    49
 * Prepend the open tags list
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    50
 *
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    51
 * \return On error returns non-zero value, otherwise zero will returned
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    52
 */
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    53
static int
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    54
AddOpenTag(const char *tag)
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    55
{
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    56
	TagList *openTag = SDL_malloc(sizeof(TagList));
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    57
	if(openTag == NULL) {
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    58
		return 1;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    59
	}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    60
	memset(openTag, 0, sizeof(TagList));
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    61
5712
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
    62
	const int tagSize = SDL_strlen(tag) + 1;
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
    63
	openTag->tag = SDL_malloc(tagSize);
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    64
	if(openTag->tag == NULL) {
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    65
		SDL_free(openTag);
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    66
		return 1;
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    67
	}
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    68
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
    69
	strncpy((char *)openTag->tag, (char *)tag, tagSize);
5712
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
    70
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    71
	openTag->next = openTags;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    72
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    73
	openTags = openTag;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    74
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    75
	return 0;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    76
}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    77
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    78
/*!
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    79
 * Removes the first tag from the open tag list
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    80
 *
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    81
 * \return On error returns non-zero value, otherwise zero will returned
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    82
 */
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    83
static int
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    84
RemoveOpenTag(const char *tag)
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    85
{
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    86
	if(openTags == NULL || ValidateString(tag) == 0) {
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    87
		return 1;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    88
	}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    89
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    90
	int retVal = 0;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    91
5712
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
    92
	const int size = SDL_strlen(tag);
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
    93
	char *tempTag = SDL_malloc(size);
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
    94
	strncpy(tempTag, tag, size);
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
    95
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    96
	// Tag should always be the same as previously opened tag
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    97
	// It prevents opening and ending tag mismatch
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    98
	if(SDL_strncmp(tempTag, tag, size) == 0) {
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    99
		TagList *openTag = openTags;
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
   100
		SDL_free((char *)openTag->tag);
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   101
5712
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   102
		openTags  = openTags->next;
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   103
		SDL_free(openTag);
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   104
	} else {
5712
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   105
		//printf("Debug | xml.c:RemoveOpenTag(): open/end tag mismatch");
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   106
		retVal = 1;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   107
	}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   108
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   109
	return retVal;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   110
}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   111
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   112
/*!
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   113
 * Debug function. Prints the contents of the open tags list.
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   114
 */
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   115
static void
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   116
PrintOpenTags()
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   117
{
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   118
	printf("\nOpen tags:\n");
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   119
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   120
	TagList *openTag = NULL;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   121
	for(openTag = openTags; openTag; openTag = openTag->next) {
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   122
		printf("\ttag: %s\n", openTag->tag);
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   123
	}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   124
}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   125
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   126
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   127
/*!
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   128
 * Converts the special characters ', ", <, >, and & to
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   129
 * corresponding entities: &apos; &quot; &lt; &gt; and &amp;
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   130
 *
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   131
 * \param string String to be escaped
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   132
 * \return Newly allocated escaped string
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   133
 */
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   134
const char *
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   135
EscapeString(const char *string)
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   136
{
5732
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   137
	// Calculate the size of the escaped string
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   138
	int totalSize = 0;
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   139
5732
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   140
	const int maxCount = SDL_strlen(string);
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   141
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   142
	int counter = 0;
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   143
	for(; counter < maxCount; ++counter) {
5732
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   144
		char character = string[counter];
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   145
5732
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   146
		switch(character) {
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   147
		case '&': totalSize +=  5; //SDL_strlen("&amp;");
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   148
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   149
		case '\'': totalSize += 6; //SDL_strlen("&apos;");
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   150
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   151
		case '"': totalSize += 6; //SDL_strlen("&quot;");
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   152
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   153
		case '<': totalSize += 4; //SDL_strlen("&lt;");
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   154
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   155
		case  '>': totalSize += 4; //SDL_strlen("&gt;");
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   156
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   157
		default:
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   158
			totalSize += 1;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   159
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   160
		}
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   161
	}
5737
303be71c64aa Fixed XML logger. EscapeString didn't from strings properly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5732
diff changeset
   162
	totalSize += 1; // for '\0'
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   163
5732
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   164
	char *retBuffer = SDL_malloc(totalSize * sizeof(char));
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   165
	if(retBuffer == NULL) {
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   166
		return NULL;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   167
	}
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   168
5732
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   169
	// escape the string
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   170
	int retBufferCounter = 0;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   171
	for(counter = 0; counter < maxCount; ++counter) {
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   172
		char character = string[counter];
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   173
		switch(character) {
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   174
		case '&':
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   175
			retBuffer[retBufferCounter++] = '&';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   176
			retBuffer[retBufferCounter++] = 'a';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   177
			retBuffer[retBufferCounter++] = 'm';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   178
			retBuffer[retBufferCounter++] = 'p';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   179
			retBuffer[retBufferCounter++] = ';';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   180
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   181
		case '\'':
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   182
			retBuffer[retBufferCounter++] = '&';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   183
			retBuffer[retBufferCounter++] = 'a';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   184
			retBuffer[retBufferCounter++] = 'p';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   185
			retBuffer[retBufferCounter++] = 'o';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   186
			retBuffer[retBufferCounter++] = 's';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   187
			retBuffer[retBufferCounter++] = ';';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   188
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   189
		case '"':
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   190
			retBuffer[retBufferCounter++] = '&';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   191
			retBuffer[retBufferCounter++] = 'q';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   192
			retBuffer[retBufferCounter++] = 'u';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   193
			retBuffer[retBufferCounter++] = 'o';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   194
			retBuffer[retBufferCounter++] = 't';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   195
			retBuffer[retBufferCounter++] = ';';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   196
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   197
		case '<':
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   198
			retBuffer[retBufferCounter++] = '&';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   199
			retBuffer[retBufferCounter++] = 'l';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   200
			retBuffer[retBufferCounter++] = 't';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   201
			retBuffer[retBufferCounter++] = ';';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   202
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   203
		case  '>': totalSize += SDL_strlen("&gt;");
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   204
			retBuffer[retBufferCounter++] = '&';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   205
			retBuffer[retBufferCounter++] = 'g';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   206
			retBuffer[retBufferCounter++] = 't';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   207
			retBuffer[retBufferCounter++] = ';';
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   208
			break;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   209
		default:
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   210
			retBuffer[retBufferCounter++] = character;
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   211
			break;
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   212
		}
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   213
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   214
	}
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   215
5737
303be71c64aa Fixed XML logger. EscapeString didn't from strings properly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5732
diff changeset
   216
	retBuffer[retBufferCounter] = '\0';
303be71c64aa Fixed XML logger. EscapeString didn't from strings properly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5732
diff changeset
   217
5732
1da5af48b964 Added better function for escaping strings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   218
	return retBuffer;
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   219
}
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   220
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   221
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   222
/*
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   223
===================
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   224
5707
67940bee217e XML elements now support single attribute. Fixes here and there.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5706
diff changeset
   225
	Functions to handle creation of XML elements
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   226
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   227
===================
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   228
*/
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   229
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   230
char *
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5722
diff changeset
   231
XMLOpenDocument(const char *rootTag, const char *xslStyle)
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   232
{
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
   233
	const char *doctype = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   234
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   235
	//! \todo refactor this mess
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   236
	char *style = NULL;
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   237
	if(xslStyle) {
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   238
		const char *styleStart = "<?xml-stylesheet type=\"text/xsl\" href=\"";
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   239
		const char *styleEnd = "\"?>\n";
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5722
diff changeset
   240
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   241
		const int sizeStyleStart = SDL_strlen(styleStart);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   242
		const int sizeStyleEnd = SDL_strlen(styleEnd);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   243
		const int sizeStyleSheetName = SDL_strlen(xslStyle);
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5722
diff changeset
   244
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   245
		const int tempSize = sizeStyleStart + sizeStyleEnd + sizeStyleSheetName + 1;
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   246
		style = SDL_malloc(tempSize);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   247
		memset(style, 0, tempSize);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   248
		SDL_snprintf(style, tempSize, "%s%s%s", styleStart, xslStyle, styleEnd);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   249
	}
5722
c464d563e3eb Fixed a few mistakes from XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5721
diff changeset
   250
5708
41235b5cb4ea Changed XML-generator to use static buffer instead of dynamically
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5707
diff changeset
   251
	memset(buffer, 0, bufferSize);
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   252
	SDL_snprintf(buffer, bufferSize, "<%s>", rootTag);
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   253
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   254
	AddOpenTag(rootTag);
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5705
diff changeset
   255
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5705
diff changeset
   256
	root = rootTag; // it's fine, as long as rootTag points to static memory?
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   257
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   258
	char *retBuf = NULL;
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   259
	if(xslStyle) {
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   260
		const int doctypeSize = SDL_strlen(doctype);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   261
		const int styleSize = SDL_strlen(style);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   262
		const int tagSize = SDL_strlen(buffer);
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   263
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   264
		const int size = doctypeSize + styleSize + tagSize + 1; // extra byte for '\0'
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   265
		retBuf = SDL_malloc(size);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   266
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   267
		SDL_snprintf(retBuf, size, "%s%s%s", doctype, style, buffer);
5722
c464d563e3eb Fixed a few mistakes from XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5721
diff changeset
   268
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   269
		SDL_free(style);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   270
	} else {
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   271
		const int doctypeSize = SDL_strlen(doctype);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   272
		const int tagSize = SDL_strlen(buffer);
5722
c464d563e3eb Fixed a few mistakes from XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5721
diff changeset
   273
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   274
		const int size = doctypeSize + tagSize + 1; // extra byte for '\0'
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   275
		retBuf = SDL_malloc(size);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   276
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   277
		SDL_snprintf(retBuf, size, "%s%s", doctype, buffer);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   278
	}
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5722
diff changeset
   279
5722
c464d563e3eb Fixed a few mistakes from XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5721
diff changeset
   280
	return retBuf;
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   281
}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   282
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   283
char *
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   284
XMLCloseDocument() {
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   285
	return XMLCloseElement(root);
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   286
}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   287
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   288
char *
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   289
XMLOpenElement(const char *tag)
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   290
{
5708
41235b5cb4ea Changed XML-generator to use static buffer instead of dynamically
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5707
diff changeset
   291
	memset(buffer, 0, bufferSize);
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   292
	SDL_snprintf(buffer, bufferSize, "<%s>", tag);
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   293
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   294
	AddOpenTag(tag);
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   295
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   296
	const int size = SDL_strlen(buffer);
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   297
	char *ret = SDL_malloc(size + 1);
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   298
	strncpy(ret, buffer, size);
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   299
	ret[size] = '\0';
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   300
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   301
	return ret;
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   302
}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   303
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   304
char *
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   305
XMLAddContent(const char *content)
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   306
{
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   307
	if(ValidateString(content) == 0) {
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   308
		return NULL;
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   309
	}
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   310
5709
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   311
	const char *escapedContent = EscapeString(content);
2e5e43552878 Added escaping special characters to their corresponding
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5708
diff changeset
   312
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   313
	if(SDL_strlen(escapedContent) >= bufferSize) {
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   314
		return NULL;
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   315
	}
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   316
5708
41235b5cb4ea Changed XML-generator to use static buffer instead of dynamically
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5707
diff changeset
   317
	memset(buffer, 0, bufferSize);
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   318
	SDL_snprintf(buffer, bufferSize, "%s", escapedContent);
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   319
	SDL_free((char *)escapedContent);
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   320
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   321
	const int size = SDL_strlen(buffer);
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   322
	char *ret = SDL_malloc(size + 1);
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   323
	strncpy(ret, buffer, size);
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   324
	ret[size] = '\0';
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   325
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   326
	return ret;
5708
41235b5cb4ea Changed XML-generator to use static buffer instead of dynamically
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5707
diff changeset
   327
}
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   328
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   329
char *
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   330
XMLCloseElement(const char *tag)
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   331
{
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   332
	if(ValidateString(tag) == 0) {
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   333
		return NULL;
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   334
	}
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   335
5721
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   336
	int retBufferSize = 150;
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   337
	char *ret = SDL_malloc(retBufferSize);
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   338
	memset(ret, 0, retBufferSize);
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   339
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   340
	// \todo check that element we're trying to close is actually open,
8e5f0a26f967 Fixes based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   341
	// otherwise it'll cause nesting problems
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   342
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   343
	// Close the open tags with proper nesting. Closes tags until it finds
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   344
	// the given tag which is the last tag that will be closed
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   345
	TagList *openTag = openTags;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   346
	while(openTag) {
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   347
		TagList *temp = openTag->next;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   348
5712
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   349
		char *lowOpenTag = ToLowerCase(openTag->tag);
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   350
		char *lowTag = ToLowerCase(tag);
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   351
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   352
		const int openTagSize = SDL_strlen(lowOpenTag);
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   353
		const int tagSize = SDL_strlen(lowTag);
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   354
		const int compSize = (openTagSize > tagSize) ? openTagSize : tagSize;
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   355
5708
41235b5cb4ea Changed XML-generator to use static buffer instead of dynamically
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5707
diff changeset
   356
		memset(buffer, 0, bufferSize);
5712
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   357
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   358
		int breakOut = 0;
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   359
		if(SDL_strncmp(lowOpenTag, lowTag, compSize) == 0) {
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   360
			breakOut = 1;
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   361
			SDL_snprintf(buffer, bufferSize, "</%s>", tag);
5712
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   362
		} else {
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   363
			SDL_snprintf(buffer, bufferSize, "</%s>", openTag->tag);
5712
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   364
		}
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   365
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   366
		SDL_free(lowOpenTag);
dabff57811e4 Added case insensitivity to XML elements.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5711
diff changeset
   367
		SDL_free(lowTag);
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   368
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
   369
		int bytesLeft = bufferSize - SDL_strlen(ret);
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
   370
		if(bytesLeft) {
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
   371
			strncat(ret, buffer, bytesLeft);
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
   372
		} else {
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
   373
			// \! todo there's probably better way to report an error?
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
   374
			fprintf(stderr, "xml.c | XMLCloseElement: Buffer is full");
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
   375
		}
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   376
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   377
		RemoveOpenTag(openTag->tag);
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   378
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   379
		openTag = temp;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   380
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   381
		if(breakOut) {
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   382
			break;
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   383
		}
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   384
	}
5711
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   385
63487fb415ee XML component no longer outputs the generated XML.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5710
diff changeset
   386
	return ret;
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5705
diff changeset
   387
}
5705
b320f7a66ac4 Creating flexible logging system which supports XML and plain
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   388