/***************************************************************************
 *   nipper - The network infrastructure parser                            *
 *   Copyright (C) 2006 - 2008 by Ian Ventura-Whiting (Fizz)               *
 *   fizz@titania.co.uk                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program. If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/


void preProcessSonicOSConfig(char *inputString)
{
	// Variables...
	int readPos = 0;
	int writePos = 0;
	int equalsReplaced = false;

	for (readPos = 0; readPos < strlen(inputString); readPos++)
	{
		// If it is the first equals...
		if ((inputString[readPos] == '=') && (equalsReplaced == false))
		{
			equalsReplaced = true;
			inputString[writePos] = ' ';
		}

		// If it is a sperator character...
		else if (inputString[readPos] == '&')
		{
			equalsReplaced = false;
			inputString[writePos] = '\n';
		}

		// If it is an space character...
		else if (strncmp(inputString + readPos, "%20", 3) == 0)
		{
			inputString[writePos] = ' ';
			readPos += 2;
		}

		// If it is an & character...
		else if (strncmp(inputString + readPos, "%26", 3) == 0)
		{
			inputString[writePos] = '&';
			readPos += 2;
		}

		// If it is an : character...
		else if (strncmp(inputString + readPos, "%3a", 3) == 0)
		{
			inputString[writePos] = ':';
			readPos += 2;
		}

		// If it is an ? character...
		else if (strncmp(inputString + readPos, "%3f", 3) == 0)
		{
			inputString[writePos] = '?';
			readPos += 2;
		}

		else
			inputString[writePos] = inputString[readPos];

		writePos++;
	}

	// Set string terminator...
	inputString[writePos] = 0;
}
