Esempio n. 1
0
void handleSetFlywheelBool(char const *request, FlywheelBoolAcceptor accept)
{
	if (stringStartsWith("true", request))
	{
		accept(flywheel, true);
	}
	else if (stringStartsWith("false", request))
	{
		accept(flywheel, false);
	}
}
Esempio n. 2
0
bool parseArgs(AcceptArgs& args, int argc, char** argv)
{

	bool hasOutName = false, hasInName = false;

	for(int i = 1;i < argc;++i)
	{
		if(strcmp(argv[i], "-a") == 0)
		{
			args.convertAll = true;
			break;
		}
		else if(strcmp(argv[i], "-t") == 0)
		{
			args.convertAscii = true;
		}
		else if(stringStartsWith(argv[i], "in:"))
		{
			hasInName = true;
			args.src_file = argv[i];
			args.src_file = args.src_file.substr(3,std::string::npos);
		}
		else if(stringStartsWith(argv[i], "out:"))
		{
			hasOutName = true;
			args.dst_file = argv[i];
			args.dst_file = args.dst_file.substr(4,std::string::npos);
		}
	}
	if(args.convertAll || hasInName)
	{
		if(!hasOutName)
		{
			if(stringEndsWith(args.src_file, ".fbx"))
				args.dst_file = args.src_file.substr(0,args.src_file.length() - 4);
		}
		else
		{
			//titan binary mesh, titan ascii mesh
			if(stringEndsWith(args.dst_file, ".tbm") || stringEndsWith(args.dst_file, ".tam"))
				args.dst_file = args.dst_file.substr(0,args.dst_file.length() - 4);
		}
	}
	else
		return false;

	return true;

}
Esempio n. 3
0
void handleRequest(const HandlerMap *api, const size_t apiSize, char const *request)
{
	size_t requestLength = strlen(request);
	size_t keyLength;
	for (int i = 0; i < apiSize; i++)
	{
		keyLength = strlen(api[i].key);
		if (!(stringStartsWith(api[i].key, request) && requestLength > keyLength))
		{
			//printf("Debug Not a %s request.\n", api[i].key);
			continue;
		}
		if (!isspace((unsigned char)request[keyLength]))
		{
			//printf("Debug Not a %s request.\n", api[i].key);
			continue;
		}
		//printf("Debug %s request.\n", api[i].key);
		int spaces = 0;
		while (isspace((unsigned char)request[keyLength + spaces]))
		{
			++spaces;
		}
		//printf("Debug Gottit, passing the request down.\n");
		api[i].handler(request + keyLength + spaces);
		break;
	}
}
/*
 * Given the user command line input of either a number or a plan name,
 * decide what the proper power plan to run should be.
 */
static int planFromOptArg(char *const arg)
{
	const std::string convertedArg(arg);
	int plan;
	if (convertedArg.compare("1") == 0
			|| stringStartsWith("powersave",
				convertedArg)) {
		if (Log::isDebug()) {
			std::cout << "[Debug] Plan is powersave"
				<< std::endl;
		}
		plan = Values::POWER_PLAN_POWERSAVE;
	} else if (convertedArg.compare("2") == 0
			|| stringStartsWith("performance",
			convertedArg)) {
		if (Log::isDebug()) {
			std::cout << "[Debug] Plan is performance"
				<< std::endl;
		}
		plan = Values::POWER_PLAN_PERFORMANCE;
	} else if (convertedArg.compare("3") == 0
			|| stringStartsWith("max-performance",
				convertedArg)) {
		if (Log::isDebug()) {
			std::cout << "[Debug] Plan is max-performance"
				<< std::endl;
		}
		plan = Values::POWER_PLAN_MAX_PERFORMANCE;
	} else if (convertedArg.compare("0") == 0
		|| stringStartsWith("auto", convertedArg)) {
		if (Log::isDebug()) {
			std::cout << "[Debug] Plan is auto"
				<< std::endl;
		}
		plan = Values::POWER_PLAN_AUTO;
	} else {
		if (!Log::isAllQuiet()) {
			printPlanHelp();
		}
		return Values::POWER_PLAN_NONE;
	}
	return plan;
}
Esempio n. 5
0
void handleSetController(char const *request)
{
	ControllerType controllerType;
	if (stringStartsWith("PID", request))
	{
		controllerType = CONTROLLER_TYPE_PID;
	}
	else if (stringStartsWith("TBH", request))
	{
		controllerType = CONTROLLER_TYPE_TBH;
	}
	else if (stringStartsWith("Bang-bang", request))
	{
		controllerType = CONTROLLER_TYPE_BANG_BANG;
	}
	else
	{
		return;
	}
	flywheelSetController(flywheel, controllerType);
}
/*
 * Given the user input which is a governor name, and the list of currently
 * available governors, decide on the governor to set or none if the user
 * requested input is a value which does not exist on the system.
 */
static const std::string governorFromOptArg(char *const arg,
		const std::vector<std::string> &availableGovernors)
{
	const std::string convertedArg(arg);
	std::string governor;
	for (unsigned int i = 0; i < availableGovernors.size(); ++i) {
		if (stringStartsWith(availableGovernors[i],
				convertedArg)) {
			if (Log::isDebug()) {
				std::cout << "[Debug] valid governor found: "
					<< availableGovernors[i]
					<< std::endl;
			}
			governor = availableGovernors[i];
			break;
		}
	}
	if (governor == UNINITIALIZED_STR) {
		for (unsigned int i = 0; i < availableGovernors.size(); ++i) {
			if (convertedArg.compare(numberToString(i))
						== 0) {
				if (Log::isDebug()) {
					std::cout << "[Debug] valid governor "
						<< "found: "
						<< availableGovernors[i]
						<< std::endl;
				}
				governor = availableGovernors[i];
				break;
			}
		}
	}
	if (governor == UNINITIALIZED_STR) {
		if (!Log::isAllQuiet()) {
			printGovernorHelp(availableGovernors);
		}
		return UNINITIALIZED_STR;
	} else {
		return governor;
	}
}
// function to serialise AnyType and return pointer to buffer 
// containing data in serial form
void *serialiseAnyType(AnyTypePNTR data, int *size){
	void *serial_buffer;
	FunctionPairPNTR funcs = mapGet(serialiserMap, data->type);
	if (funcs == NULL || funcs->ser == NULL){
		DAL_error(SERIALISATION_ERROR);
		PRINTF("serAny:%s \n", (char *) data->type);
		return NULL;
	}
	//PRINTF(" serany: %s \n", data->type);
	if(stringStartsWith(data->type, "i") || stringStartsWith(data->type, "e"))
		serial_buffer = (*(funcs->ser))(&(data->value.int_value), size);
	else if(stringStartsWith(data->type, "u"))
		serial_buffer = (*(funcs->ser))(&(data->value.unsigned_value), size);
	else if(stringStartsWith(data->type, "r"))
		serial_buffer = (*(funcs->ser))(&(data->value.real_value), size);
	else if(stringStartsWith(data->type, "b"))
		serial_buffer = (*(funcs->ser))(&(data->value.bool_value), size);
	else if(stringStartsWith(data->type, "8"))
		serial_buffer = (*(funcs->ser))(&(data->value.byte_value), size);
	else
		serial_buffer = (*(funcs->ser))(data->value.pointer_value, size);
	return serial_buffer;
}
Esempio n. 8
0
char * ChannelReceivingThread::processFlags (char *inMessageID,
                                             char *inFromAddress,
                                             char *inOldFlags,
                                             char *outIgnoreUC,
                                             char *outDropMessage,
                                             char *inLoggerName)
{
    
    char *flags = stringDuplicate (inOldFlags);
    
    *outIgnoreUC = false;
    *outDropMessage = false;
    
    
    // first, check if message should be signed
    // addresses starting with PKH are hashes of sender's public key
    if (stringStartsWith (inFromAddress, "PKH"))
    {
        
        // make sure hash in address matches attatched public key
        
        // get public key
        char *pubKey = getFlagData (flags, "PUBLIC_KEY_");
        
        if (pubKey == NULL)
        {
            
            AppLog::detail (inLoggerName,
                            "Message from a PKH address does not have a PUBLIC_KEY flag."
                            "  Dropping.");
            
            *outDropMessage = true;
            return flags;
        }
        
        // get signature
        char *signedID = getFlagData (flags, "SIGNED_ID_");
        
        if (pubKey == NULL)
        {
            
            AppLog::detail (inLoggerName,
                            "Message from a PKH address does not have a SIGNED_ID flag."
                            "  Dropping.");
            
            delete[]pubKey;
            
            *outDropMessage = true;
            return flags;
        }
        
        
        char *trueKeyHash = computeSHA1Digest (pubKey);
        
        // skip "PKH" in address to get to key hash
        char *hashInAddress = &(inFromAddress[3]);
        
        int trueHashToAddressHashCompare = strcmp (trueKeyHash, hashInAddress);
        
        delete[]trueKeyHash;
        
        if (trueHashToAddressHashCompare != 0)
        {
            AppLog::detail (inLoggerName,
                            "PUBLIC_KEY hash does not match hash from PKH address."
                            "  Dropping.");
            
            delete[]pubKey;
            
            *outDropMessage = true;
            return flags;
        }
        
        // we have a pubkey that matches the from address
        // and we have already extracted the signature above
        
        // check the signature
        char signatureCorrect = CryptoUtils::rsaVerify (pubKey,
                                                        (unsigned char *)
                                                        inMessageID,
                                                        strlen (inMessageID),
                                                        signedID);
        delete[]pubKey;
        delete[]signedID;
        
        if (!signatureCorrect)
        {
            AppLog::detail (inLoggerName,
                            "Bad signature on message from a PKH address."
                            "  Dropping.");
            
            *outDropMessage = true;
            return flags;
        }
    }
    
    
    
    // process a FORWARD flag
    char *pointerToForwardFlag = strstr (flags, "FORWARD_");
    
    if (pointerToForwardFlag != NULL)
    {
        // message has forward flag
        
        // extract the hash from the forward flag
        char *oldForwardFlag = stringDuplicate (pointerToForwardFlag);
        char *pointerToFlagSeparator = strstr (oldForwardFlag, "|");
        
        if (pointerToFlagSeparator != NULL)
        {
            // terminate string at separator
            pointerToFlagSeparator[0] = '\0';
        }
        
        // skip FORWARD_ to get to the hash
        char *pointerToHash = &(oldForwardFlag[strlen ("FORWARD_")]);
        
        
        // re-hash the hash to produce a new hash
        char *newHash = muteComputeNewForwardHash (pointerToHash);
        
        if (newHash != NULL)
        {
            // continue forwarding
            *outIgnoreUC = true;
            
            char *newForwardFlag = autoSprintf ("FORWARD_%s", newHash);
            
            
            // replace old flag with new one
            
            char *tempFlags = muteRemoveFlag (flags,
                                              oldForwardFlag);
            
            char *newFlags = muteAddFlag (tempFlags,
                                          newForwardFlag);
            delete[]tempFlags;
            delete[]flags;
            delete[]newForwardFlag;
            
            flags = newFlags;
            
            
            delete[]newHash;
        }
        else
        {
            // we're breaking the forward tree
            *outIgnoreUC = false;
            
            // remove the forward flag
            char *newFlags = muteRemoveFlag (flags,
                                             oldForwardFlag);
            delete[]flags;
            flags = newFlags;
            
            AppLog::detail (inLoggerName, "Breaking the FORWARD tree.");
        }
        
        delete[]oldForwardFlag;
    }
    
    
    
    // process a DROP_TTL flag
    char *pointerToDropTTLFlag = strstr (flags, "DROP_TTL_");
    
    if (pointerToDropTTLFlag != NULL)
    {
        // message has drop TTL flag
        
        // extract the hash from the dropTTL flag
        char *oldDropTTLFlag = stringDuplicate (pointerToDropTTLFlag);
        char *pointerToFlagSeparator = strstr (oldDropTTLFlag, "|");
        
        if (pointerToFlagSeparator != NULL)
        {
            // terminate string at separator
            pointerToFlagSeparator[0] = '\0';
        }
        
        // skip DROP_TTL_ to get to the TTL value
        char *pointerToTTLValue = &(oldDropTTLFlag[strlen ("DROP_TTL_")]);
        
        
        int ttlValue;
        
        int numRead = sscanf (pointerToTTLValue, "%d", &ttlValue);
        
        if (numRead == 1)
        {
            
            ttlValue--;
            
            if (ttlValue <= 0)
            {
                *outDropMessage = true;
                
                AppLog::detail (inLoggerName,
                                "Breaking the DROP_TTL tree, since the TTL reached 0.");
            }
            else
            {
                char *newDropTTLFlag = autoSprintf ("DROP_TTL_%d", ttlValue);
                
                // replace old flag with new one
                
                char *tempFlags = muteRemoveFlag (flags,
                                                  oldDropTTLFlag);
                
                char *newFlags = muteAddFlag (tempFlags,
                                              newDropTTLFlag);
                delete[]tempFlags;
                delete[]flags;
                delete[]newDropTTLFlag;
                
                flags = newFlags;
            }
            
            // ignore the UC in drop mode
            *outIgnoreUC = true;
        }
        
        delete[]oldDropTTLFlag;
    }
    
    
    // process a DROP_CHAIN flag
    char *pointerToDropChainFlag = strstr (flags, "DROP_CHAIN");
    
    if (pointerToDropChainFlag != NULL)
    {
        // message has drop chain flag
        
        // ignore UCs on all DROP tail messages
        *outIgnoreUC = true;
        
        if (muteShouldDropTailChainMessages ())
        {
            *outDropMessage = true;
            
            AppLog::detail (inLoggerName, "Breaking the DROP_CHAIN.");
        }
    }
    
    
    return flags;
}
Esempio n. 9
0
File: Reader.c Progetto: denji/mdr
char * getHTML()
{
    bstring html = bfromcstr("<!DOCTYPE html>\n<html>\n");
    balloc(html, style_css_len);
    bcatcstr(html, "<head>");
    bcatcstr(html, "<title>mdr</title>");
    bcatcstr(html, "<style type='text/css'>");
    bcatcstr(html, (char *)style_css);
    bcatcstr(html, "</style>");
    bcatcstr(html, "</head>");
    bcatcstr(html, "<body>\n<table cellpadding='0'>\n");

    // Read from stdin
    bstring stdinContents = bread ((bNread) fread, stdin);
    if (stdinContents == NULL)
    {
        return "There was an error reading from stdin.";
    }

    // Split into lines
    struct bstrList * inputLines;
    if ((inputLines = bsplit(stdinContents, '\n')) != NULL)
    {

        // We are going to build a map showing which lines in the input belong
        // in which lines in the output and how they should be displayed. We'll
        // allocate the left and right maps to be big enough to each hold all
        // the input data, which is more than enough.
        lineData * lineMapL = malloc(inputLines->qty * sizeof(lineData));
        if (lineMapL == NULL)
        {
            free(lineMapL);
            printf("Memory allocation error.\n");
            exit(-1);
        }
        lineData * lineMapR = malloc(inputLines->qty * sizeof(lineData));
        if (lineMapR == NULL)
        {
            free(lineMapR);
            printf("Memory allocation error.\n");
            exit(-1);
        }
        int lineMapPosL = 0;
        int lineMapPosR = 0;

        int useL;
        int useR;
        enum lineType type;
        int padding;
        int lineNoL = 0;
        int lineNoR = 0;
        int firstInfoLine = TRUE;
        int startNewFileOk = TRUE;
        int startOldFileOk = TRUE;

        // Map input lines to their output column (left, right, or both)
        int i;
        for (i = 0; i < inputLines->qty; i++) {

            useL = 0;
            useR = 0;
            type = SHARED;
            padding = 1;

            if (startOldFileOk && stringStartsWith(inputLines->entry[i], "---"))
            {
                type = OLD_FILE;
                useL = 1;
                padding = 4;
                lineNoL = -1;
                lineNoR = -1;
                startOldFileOk = FALSE;
            }
            else if (startNewFileOk && stringStartsWith(inputLines->entry[i], "+++"))
            {
                type = NEW_FILE;
                useR = 1;
                padding = 4;
                lineNoL = -1;
                lineNoR = -1;
                startNewFileOk = FALSE;
            }
            else if (stringStartsWith(inputLines->entry[i], "@@"))
            {
                syncLineNumbers(inputLines->entry[i], &lineNoL, &lineNoR);
                if (firstInfoLine)
                {
                    // Don't print the info row but still increment the line
                    // numbers normally.
                    // TODO: Might be better to mark the row as the first and
                    // hide it with CSS instead of just not printing it.
                    lineNoL++;
                    lineNoR++;
                }
                else
                {
                    type = INFO;
                    useR = 1;
                    useL = 1;
                    padding = 1;
                }
                firstInfoLine = FALSE;
            }
            else if (bdata(inputLines->entry[i])[0] == '-')
            {
                type = OLD;
                useL = 1;
            }
            else if (bdata(inputLines->entry[i])[0] == '+')
            {
                type = NEW;
                useR = 1;
            }
            else if (bdata(inputLines->entry[i])[0] == ' ')
            {
                type = SHARED;
                useL = 1;
                useR = 1;
            }
            else
            {
                type = HEADER;
                lineNoL = 0;
                lineNoR = 0;
                firstInfoLine = TRUE;
                startNewFileOk = TRUE;
                startOldFileOk = TRUE;
            }

            // Balance.
            if (type == HEADER ||
                (type == SHARED && (useL || useR)) ||
                i == inputLines->qty - 1)
            {
                int difference = lineMapPosL - lineMapPosR;
                int j;

                if (difference > 0)
                {
                    for (j = 0; j < difference; j++)
                    {
                        lineMapR[lineMapPosR].type = EMPTY;
                        lineMapPosR++;
                    }
                }
                else if (difference < 0)
                {
                    for (j = 0; j < (difference * -1); j++)
                    {
                        lineMapL[lineMapPosL].type = EMPTY;
                        lineMapPosL++;
                    }
                }
            }

            if (useL)
            {
                lineMapL[lineMapPosL].inputPos = i;
                lineMapL[lineMapPosL].type = type;
                lineMapL[lineMapPosL].padding = padding;
                lineMapL[lineMapPosL].lineNo = lineNoL - 1;
                lineMapL[lineMapPosL].leadingSpaces = 0;
                lineMapPosL++;
                lineNoL++;
            }

            if (useR)
            {
                lineMapR[lineMapPosR].inputPos = i;
                lineMapR[lineMapPosR].type = type;
                lineMapR[lineMapPosR].padding = padding;
                lineMapR[lineMapPosR].lineNo = lineNoR - 1;
                lineMapR[lineMapPosR].leadingSpaces = 0;
                lineMapPosR++;
                lineNoR++;
            }

        }

        // Mapping complete. Quick sanity check that both L and R cols have the
        // same length.
        if (lineMapPosL != lineMapPosR)
        {
            return "Error displaying diff (generated columns not equal in length).";
        }

        // Now we do the formatting work based on the map.
        for (i = 0; i < lineMapPosL; i++)
        {
            int * highlightMaskA = NULL;
            int * highlightMaskB = NULL;
            bstring contentL;
            bstring contentR;
            int leadingSpacesL = 0;
            int leadingSpacesR = 0;

            if (lineMapL[i].type != EMPTY)
            {
                contentL = getContentFromLine(
                    inputLines->entry[lineMapL[i].inputPos],
                    lineMapL[i].padding,
                    &leadingSpacesL
                );
                lineMapL[i].leadingSpaces = leadingSpacesL;
            }

            if (lineMapR[i].type != EMPTY)
            {
                contentR = getContentFromLine(
                    inputLines->entry[lineMapR[i].inputPos],
                    lineMapR[i].padding,
                    &leadingSpacesR
                );
                lineMapR[i].leadingSpaces = leadingSpacesR;
            }

            // Compare changed lines
            if (lineMapL[i].type == OLD && lineMapR[i].type == NEW) {

                lineMapL[i].type = CHANGE;
                lineMapR[i].type = CHANGE;

                determineLineHighlighting(
                    contentL,
                    contentR,
                    &highlightMaskA,
                    &highlightMaskB
                );

            }

            // Format output
            bcatcstr(html, "<tr>\n");

            if (lineMapL[i].type == EMPTY)
            {
                createEmptyLine(html);
            }
            else
            {
                createLine(LEFT, html, contentL, lineMapL[i], highlightMaskA);
                bdestroy(contentL);
            }

            if (lineMapR[i].type == EMPTY)
            {
                createEmptyLine(html);
            }
            else
            {
                createLine(RIGHT, html, contentR, lineMapR[i], highlightMaskB);
                bdestroy(contentR);
            }

            bcatcstr(html, "</tr>\n");

            free(highlightMaskA);
            free(highlightMaskB);
        }

        bcatcstr(html, "</table>\n</body>\n</html>\n");

        free(lineMapL);
        free(lineMapR);
    }

    bdestroy(stdinContents);
    bstrListDestroy(inputLines);

    char * result = bstr2cstr(html, '-');
    bdestroy(html);

    return result; // Caller should free()
}
Esempio n. 10
0
static int turboFromOptArg(const Cpu &cpu, char *const arg)
{
	const std::string convertedArg(arg);
	int turbo;
	if (cpu.hasPstate()) {
		if (Log::isDebug()) {
			std::cout << "[Debug] System has intel_pstate"
				<< std::endl;
		}
		if (convertedArg.compare("0") == 0
				|| stringStartsWith("on",
					convertedArg)) {
			if (Log::isDebug()) {
				std::cout << "[Debug] Turbo On"
					<< std::endl;
			}
			turbo = Values::PSTATE_TURBO;
		} else if (convertedArg.compare("1") == 0
				|| stringStartsWith("off",
				convertedArg)) {
			if (Log::isDebug()) {
				std::cout << "[Debug] Turbo Off"
					<< std::endl;
			}
			turbo = Values::PSTATE_NO_TURBO;
		} else {
			if (Log::isDebug()) {
				std::cout << "[Debug] Turbo is insane"
					<< std::endl;
			}
			turbo = Values::TURBO_INSANE;
		}
	} else {
		if (Log::isDebug()) {
			std::cout << "[Debug] System does not have "
				<< "intel_pstate" << std::endl;
		}
		if (convertedArg.compare("0") == 0
				|| stringStartsWith("off",
					convertedArg)) {
			if (Log::isDebug()) {
				std::cout << "[Debug] Turbo Off"
					<< std::endl;
			}
			turbo = Values::CPUFREQ_NO_TURBO;
		} else if (convertedArg.compare("1") == 0
				|| stringStartsWith("on",
				convertedArg)) {
			if (Log::isDebug()) {
				std::cout << "[Debug] Turbo On"
					<< std::endl;
			}
			turbo = Values::CPUFREQ_TURBO;
		} else {
			if (Log::isDebug()) {
				std::cout << "[Debug] Turbo is insane"
					<< std::endl;
			}
			turbo = Values::TURBO_INSANE;
		}
	}
	return turbo;
}
Esempio n. 11
0
void ReadVectorFile(char* s)
{
	char buff[256];
	WCHAR wcFileInfo[512];
	char* token;
	FILE* F = fopen(s, "rb");
	while (fgets(buff, 255, F))
		if (stringStartsWith(buff, "<!DOCTYPE CurveSetXML"))
		{
			StringCchPrintf(wcFileInfo, 512,
				L"(INFO) : This seems to be a diffusion curves file.\n");
			OutputDebugString(wcFileInfo);
			break;
		}
		fgets(buff, 255, F);
		token = strtok(buff, " \"\t");
		while (!stringStartsWith(token, "image_width="))
		{
			token = strtok(NULL, " \"\t");
		}
		token = strtok(NULL, " \"\t");
		m_fWidth = atof(token);
		while (!stringStartsWith(token, "image_height="))
		{
			token = strtok(NULL, " \"\t");
		}
		token = strtok(NULL, " \"\t");
		m_fHeight = atof(token);
		while (!stringStartsWith(token, "nb_curves="))
		{
			token = strtok(NULL, " \"\t");
		}
		token = strtok(NULL, " \"\t");
		m_cNum = atof(token);
		StringCchPrintf(wcFileInfo, 512, L"(INFO) : %d curves found in file.\n",
			m_cNum);
		OutputDebugString(wcFileInfo);
		m_curve.resize(m_cNum);
		m_cSegNum = 0;
		D3DXVECTOR2 maxBound = D3DXVECTOR2(-1000000, -1000000);
		D3DXVECTOR2 minBound = D3DXVECTOR2(1000000, 1000000);
		for (int i1 = 0; i1 < m_cNum; i1++)
		{
			while (!stringStartsWith(buff, " <curve nb_control_points"))
			{
				fgets(buff, 255, F);
			}
			token = strtok(buff, " \"\t");
			while (!stringStartsWith(token, "nb_control_points="))
			{
				token = strtok(NULL, " \"\t");
			}
			token = strtok(NULL, " \"\t");
			m_curve[i1].pNum = atof(token);
			m_cSegNum += ((m_curve[i1].pNum - 1) / 3);
			while (!stringStartsWith(token, "nb_left_colors="))
			{
				token = strtok(NULL, " \"\t");
			}
			token = strtok(NULL, " \"\t");
			m_curve[i1].clNum = atof(token);
			while (!stringStartsWith(token, "nb_right_colors="))
			{
				token = strtok(NULL, " \"\t");
			}
			token = strtok(NULL, " \"\t");
			m_curve[i1].crNum = atof(token);
			while (!stringStartsWith(token, "nb_blur_points="))
			{
				token = strtok(NULL, " \"\t");
			}
			token = strtok(NULL, " \"\t");
			m_curve[i1].bNum = atof(token);
			// read in individual curve data
			m_curve[i1].p.resize(m_curve[i1].pNum);
			for (int i2 = 0; i2 < m_curve[i1].pNum; i2++)
			{
				while (!stringStartsWith(buff, "   <control_point "))
				{
					fgets(buff, 255, F);
				}
				token = strtok(buff, " \"\t");
				while (!stringStartsWith(token, "x="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].p[i2].y = atof(token);
				while (!stringStartsWith(token, "y="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].p[i2].x = atof(token);
				fgets(buff, 255, F);
				//extend the bounds if necessary
				if (m_curve[i1].p[i2].y < minBound.y)
				{
					minBound.y = m_curve[i1].p[i2].y;
				}
				if (m_curve[i1].p[i2].y > maxBound.y)
				{
					maxBound.y = m_curve[i1].p[i2].y;
				}
				if (m_curve[i1].p[i2].x < minBound.x)
				{
					minBound.x = m_curve[i1].p[i2].x;
				}
				if (m_curve[i1].p[i2].x > maxBound.x)
				{
					maxBound.x = m_curve[i1].p[i2].x;
				}
			}
			m_curve[i1].cl.resize(m_curve[i1].clNum);
			for (int i2 = 0; i2 < m_curve[i1].clNum; i2++)
			{
				while (!stringStartsWith(buff, "   <left_color "))
				{
					fgets(buff, 255, F);
				}
				token = strtok(buff, " \"\t");
				while (!stringStartsWith(token, "G="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].cl[i2].col.y = atof(token) / 256.0;
				while (!stringStartsWith(token, "R="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].cl[i2].col.z  = atof(token) / 256.0;
				while (!stringStartsWith(token, "globalID="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].cl[i2].off = atof(token);
				while (!stringStartsWith(token, "B="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].cl[i2].col.x  = atof(token) / 256.0;
				fgets(buff, 255, F);
			}
			m_curve[i1].cr.resize(m_curve[i1].crNum);
			for (int i2 = 0; i2 < m_curve[i1].crNum; i2++)
			{
				while (!stringStartsWith(buff, "   <right_color "))
				{
					fgets(buff, 255, F);
				}
				token = strtok(buff, " \"\t");
				while (!stringStartsWith(token, "G="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].cr[i2].col.y = atof(token) / 256.0;
				while (!stringStartsWith(token, "R="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].cr[i2].col.z  = atof(token) / 256.0;
				while (!stringStartsWith(token, "globalID="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].cr[i2].off = atof(token);
				while (!stringStartsWith(token, "B="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].cr[i2].col.x  = atof(token) / 256.0;
				fgets(buff, 255, F);
			}
			m_curve[i1].b.resize(m_curve[i1].bNum);
			for (int i2 = 0; i2 < m_curve[i1].bNum; i2++)
			{
				while (!stringStartsWith(buff, "   <best_scale"))
				{
					fgets(buff, 255, F);
				}
				token = strtok(buff, " \"\t");
				while (!stringStartsWith(token, "value="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].b[i2].blurr = atof(token);
				while (!stringStartsWith(token, "globalID="))
				{
					token = strtok(NULL, " \"\t");
				}
				token = strtok(NULL, " \"\t");
				m_curve[i1].b[i2].off = atof(token);
				fgets(buff, 255, F);
			}
		}
		fclose(F);
		//scale the whole image between -1 and 1
		D3DXVECTOR2 middlePan = D3DXVECTOR2(0.5 * (maxBound.x + minBound.x),
			0.5 * (maxBound.y + minBound.y));
		for (int i1 = 0; i1 < m_cNum; i1++)
			for (int i2 = 0; i2 < m_curve[i1].pNum; i2++)
			{
				m_curve[i1].p[i2].x = 2.0f * (m_curve[i1].p[i2].x - middlePan.x) / m_fWidth;
				m_curve[i1].p[i2].y = 2.0f * (m_curve[i1].p[i2].y - middlePan.y) / m_fHeight;
			}
			StringCchPrintf(wcFileInfo, 512, L"(INFO) : %d curve segments found in file.\n",
				m_cSegNum);
			OutputDebugString(wcFileInfo);
}