Exemple #1
0
void decompressHelper(ibitstream& input, map<int, int>& freqTable, string value, string freq, bool switched){
    //Ta ut första byten och gör den till en char
    char tempChar = buildCharFromByte(input);
    //Om s**t av par lägg in i freqTable och första rekursera
    if(tempChar == ','){
        int intValue = stringToInteger(value);
        int intFreq = stringToInteger(freq);
        freqTable.insert(make_pair(intValue,intFreq));
        decompressHelper(input, freqTable, value, freq, switched);
    }else if(tempChar == ':'){  //Om semikolon, byt till att bygga frekvensen
        switched = true;
        decompressHelper(input, freqTable, value, freq, switched);
    }else if (tempChar == ' '){ //Reseta värden
        value = "";
        freq = "";
        switched = false;
        decompressHelper(input, freqTable, value, freq, switched);
    }else if(tempChar == '{'){  //Om början av tabell, gör inget
        decompressHelper(input, freqTable, value, freq, switched);
    }else if(tempChar == '}'){  //Om slutet av tabell, lägg in sista värdet och avsluta loop
        int intValue = stringToInteger(value);
        int intFreq = stringToInteger(freq);
        freqTable.insert(make_pair(intValue,intFreq));
        return;
    }
    else{
        if(switched){           //Om efter semikolon, öka frekvensen
            freq += tempChar;
            decompressHelper(input, freqTable, value, freq, switched);
        }else{                  //Annars öka värdet
            value += tempChar;
            decompressHelper(input, freqTable, value, freq, switched);
        }
    }
}
void GBufferedImage::load(const std::string& filename) {
    // for efficiency, let's at least check whether the file exists
    // and throw error immediately rather than contacting the back-end
    if (!fileExists(filename)) {
        error("GBufferedImage::load: file not found: " + filename);
    }
    
    std::string result = pp->gbufferedimage_load(this, filename);
    result = Base64::decode(result);
    std::istringstream input(result);
    std::string line;
    if (!getline(input, line)) {
        error("GBufferedImage::load: image data does not contain valid width");
    }
    m_width = stringToInteger(line);
    if (!getline(input, line)) {
        error("GBufferedImage::load: image data does not contain valid height");
    }
    m_height = stringToInteger(line);
    for (int y = 0; y < m_height; y++) {
        for (int x = 0; x < m_width; x++) {
            if (!getline(input, line)) {
                error("GBufferedImage::load: image data does not contain valid pixel (x="
                      + integerToString(x) + ", y=" + integerToString(y) + ")");
            }
            int px = convertColorToRGB(line);
            m_pixels[y][x] = px;
        }
    }
}
Exemple #3
0
void test_stringToInteger()
{
    std::cout << "########################################" << std::endl;
    std::cout << __FUNCTION__ << std::endl;
    std::cout << "########################################" << std::endl;

    const char * a1 = "-1";
    std::cout << "The string " << a1 << " is the integer " << stringToInteger(a1) << std::endl;
    const char * a2 = "0";
    std::cout << "The string " << a2 << " is the integer " << stringToInteger(a2) << std::endl;
    const char * a3 = "1";
    std::cout << "The string " << a3 << " is the integer " << stringToInteger(a3) << std::endl;
    const char * a4 = "-367";
    std::cout << "The string " << a4 << " is the integer " << stringToInteger(a4) << std::endl;
    const char * a5 = "36";
    std::cout << "The string " << a5 << " is the integer " << stringToInteger(a5) << std::endl;
//    const char * a6 = 0;
//    std::cout << "The string " << a6 << " is the integer " << stringToInteger(a6) << std::endl;
//    const char * a7 = "";
//    std::cout << "The string " << a7 << " is the integer " << stringToInteger(a7) << std::endl;
//    const char * a8 = "-3A7";
//    std::cout << "The string " << a8 << " is the integer " << stringToInteger(a8) << std::endl;

    std::cout << std::endl;
}
Exemple #4
0
void ConfigMgr::loadTilesConfig(const std::string& configFilePath) {
    // Datei öffnen
    rapidxml::file<> xmlFile(configFilePath.c_str());

    rapidxml::xml_document<>* xmlDocument = new rapidxml::xml_document<>();
    xmlDocument->parse<0>(xmlFile.data());

    rapidxml::xml_node<>* tilesConfigNode = xmlDocument->first_node("tiles-config", 12, true);
    rapidxml::xml_node<>* tilesNode = tilesConfigNode->first_node("tiles", 5, true);

    // Tiles auslesen
    for (rapidxml::xml_node<>* tileNode = tilesNode->first_node("tile", 4, true); tileNode != nullptr;
         tileNode = tileNode->next_sibling("tile", 4, true)) {

        const char* tileName = tileNode->first_attribute("name", 4, true)->value();

        const char* mapTileTypeName = tileNode->first_attribute("type", 4, true)->value();
        const MapTileType mapTileType = getMapTileTypeByName(mapTileTypeName);

        MapTileConfig& mapTileConfig = mapTileConfigs[tileName];
        mapTileConfig.tileName = std::string(tileName);
        mapTileConfig.mapTileType = mapTileType;

        // TODO konfigurierbar machen
        if (mapTileConfig.tileName == "grass") {
            mapTileConfig.goodToHarvest = getGood("grass");
        }

        for (rapidxml::xml_node<>* tmxTileNode = tileNode->first_node("tmx-tile", 8, true); tmxTileNode != nullptr;
             tmxTileNode = tmxTileNode->next_sibling("tmx-tile", 8, true)) {

            int tmxTileIndex = stringToInteger(tmxTileNode->first_attribute("tmx-tile-index", 14, true)->value());
            const char* tileViewName = tmxTileNode->first_attribute("view", 4, true)->value();
            int xOffsetInTileset = stringToInteger(tmxTileNode->first_attribute("x", 1, true)->value());
            int yOffsetInTileset = stringToInteger(tmxTileNode->first_attribute("y", 1, true)->value());

            FourthDirection tileView = Direction::fromString(tileViewName);
            if (tileView == Direction::NONE) {
                Log::error(_("Illegal dirName '%s'."), tileViewName);
                throw std::runtime_error("Illegal dirName");
            }

            mapTileConfig.mapTileViewsOffsetXYInTileset[tileView] =
                std::make_pair(xOffsetInTileset, yOffsetInTileset);

            // Zuordnung zu Tiled-Kachel-ID und View-Offset merken
            tiledIdToMapTileConfig[tmxTileIndex] = &mapTileConfig;
            tiledIdToViewOffset[tmxTileIndex] = tileView / 2;
        }

        // Den Ozean separat merken
        // TODO Was, wenn mehrere Ozean-Kacheln in der tiles.xml stehen?
        if (mapTileType == MapTileType::OCEAN) {
            mapTileConfigOcean = &mapTileConfig;
        }
    }

    delete xmlDocument;
}
void Settings::settingsLoadVector(vector<string> &existingData) {
    int i = 0;

    _textFileName = existingData[i];
    _saveDirectory = existingData[i+1];
    _viewType = stringToInteger(existingData[i+2]);
    _width = stringToInteger(existingData[i+3]);
    _length = stringToInteger(existingData[i+4]);

}
Exemple #6
0
/**
 * Get the current flash mode value and displays it into a label.
 */
void SettingsScreen::getFlashModeValue()
{
	char buf[MAX_BUF_SIZE];
	int syscallResult = maCaptureGetProperty(
		MA_CAPTURE_FLASH,
		buf,
		MAX_BUF_SIZE);
	if (syscallResult != MA_CAPTURE_RES_OK)
	{
		maMessageBox("Error", "Cannot get the flash mode value");
		return;
	}

	int flashModeInt = stringToInteger(buf);
	MAUtil::String flashModeString;
	switch (flashModeInt)
	{
	case MA_CAPTURE_FLASH_AUTO:
		flashModeString = FLASH_MODE_AUTO_TEXT;
		break;
	case MA_CAPTURE_FLASH_ON:
		flashModeString = FLASH_MODE_ON_TEXT;
		break;
	case MA_CAPTURE_FLASH_OFF:
		flashModeString = FLASH_MODE_OFF_TEXT;
		break;
	default:
		maMessageBox("Error", "Invalid flash mode value");
	}

	mFlashModeLabel->setText(flashModeString);
}
void test_stringToInteger_should_get_1234(void) {

    Text *text = textNew("1234");
    String *string = stringNew(text);

    TEST_ASSERT_EQUAL(1234,stringToInteger(string));
}
hostMessage Host::parse(string message)
{
  hostMessage result;
  string token;
  istringstream iss(message);
  unsigned int i = 0;

  while(getline(iss, token, ','))
  {
    switch(i)
    {
      case 0:
        result.hostID = stringToInteger(token);
        break;
      case 1:
        result.type = token;
        break;
      case 2:
        result.value = token;
        break;
    }
    i++;
  }

  return result;
}
ZLBoolean3 ZLBoolean3Option::value() const {
	if (!myIsSynchronized) {
		myValue = (ZLBoolean3)stringToInteger(getConfigValue(), myDefaultValue);
		myIsSynchronized = true;
	}
	return myValue;
}
ZLColor ZLColorOption::value() const {
	if (!myIsSynchronized) {
		myIntValue = stringToInteger(getConfigValue(), myDefaultIntValue);
		myIsSynchronized = true;
	}
	return ZLColor(myIntValue);
}
long ZLIntegerRangeOption::value() const {
	if (!myIsSynchronized) {
		myValue = stringToInteger(getConfigValue(), myDefaultValue, myMinValue, myMaxValue);
		myIsSynchronized = true;
	}
	return myValue;
}
Exemple #12
0
/**
 * Get the current video quality value and displays it into a label.
 */
void SettingsScreen::getVideoQualityValue()
{
	char buf[MAX_BUF_SIZE];
	int syscallResult = maCaptureGetProperty(
		MA_CAPTURE_VIDEO_QUALITY, buf, MAX_BUF_SIZE);
	if (syscallResult != MA_CAPTURE_RES_OK)
	{
		maMessageBox("Error", "Cannot get the video duration value");
		return;
	}

	int videoQualityInt = stringToInteger(buf);
	MAUtil::String videoQualityString;
	switch (videoQualityInt)
	{
	case MA_CAPTURE_VIDEO_QUALITY_LOW:
		videoQualityString = VIDEO_QUALITY_LOW_TEXT;
		break;
	case MA_CAPTURE_VIDEO_QUALITY_MEDIUM:
		videoQualityString = VIDEO_QUALITY_MEDIUM_TEXT;
		break;
	case MA_CAPTURE_VIDEO_QUALITY_HIGH:
		videoQualityString = VIDEO_QUALITY_HIGH_TEXT;
		break;
	default:
		maMessageBox("Error", "Invalid video quality value");
	}

	mVideoQualityLabel->setText(videoQualityString);
}
	/**
	 * Implementation of standard API exposed to JavaScript
	 * This function is used to detect different messages from JavaScript
	 * and call the respective function in MoSync.
	 *
	 * @return true if stream was handled, false if not.
	 */
	bool ResourceMessageHandler::handleMessage(Wormhole::MessageStream& stream)
	{
		char buffer[512];

		const char * action = stream.getNext();

		if (0 == strcmp("loadImage", action))
		{
			const char* imagePath = stream.getNext();
			const char* imageID = stream.getNext();

			// Load the Image resource.
			MAHandle imageHandle = loadImageResource(imagePath);
			if (imageHandle > 0)
			{
				sprintf(buffer,
						"mosync.resource.imageLoaded(\"%s\", %d)",
						imageID,
						imageHandle);
				mWebView->callJS(buffer);
			}
			else
			{
				// TODO: Better way to inform about the error?
				// Call JS function with error code?
				// mosync.resource.imageLoaded(<imageID>, -1) ??
				char errorMessage[1024];
				sprintf(errorMessage,
					"@@@ MoSync: ResourceMessageHandler could not load image: %s",
					imagePath);
				maWriteLog(errorMessage, strlen(errorMessage));
			}
		}
		else if (0 == strcmp("loadRemoteImage", action))
		{
			const char* imageURL = stream.getNext();
			const char* imageID = stream.getNext();
			MAHandle imageHandle = maCreatePlaceholder();
			mImageDownloader->beginDownloading(imageURL,imageHandle);
			sprintf(buffer,
					"mosync.resource.imageDownloadStarted(\"%s\", %d)",
					imageID,
					imageHandle);
			mWebView->callJS(buffer);
		}
		else if (0 == strcmp("DestroyPlaceholder", action))
		{
			MAHandle handle =  stringToInteger(stream.getNext());
			maDestroyPlaceholder(handle);
		}
		else if (0 == strcmp("sendRemoteLogMessage", action))
		{
			const char* url = stream.getNext();
			const char* message = stream.getNext();
			sendRemoteLogMessage(message, url);
		}

		return true;
	}
Exemple #14
0
// expects the current token to be an integer
Expression *ASTBuilder::parseIntegerExpression() {
	Token *t = getNextToken(); // eat the number token

	IntExpression *expr = new IntExpression(stringToInteger(t->getData()));
	getNextToken();

	return expr;
}
void test_stringToInteger_should_get_23(void) {

    Text *text = textNew("1234");
    String *string = stringNew(text);
    string->start++;
    string->length-=2;

    TEST_ASSERT_EQUAL(23,stringToInteger(string));
}
void test_stringToInteger_should_get_5555(void) {

    Text *text = textNew("dsfggggv5555FDG");
    String *string = stringNew(text);
    string->start = 8;
    string->length = 8;

    TEST_ASSERT_EQUAL(5555,stringToInteger(string));
}
Exemple #17
0
std::vector<int> Solution::parseString(std::string inputString)
{
	std::vector<int> resultVector;
	for (unsigned int iterator = 0; iterator < inputString.length();)
	{
		if (iterator == inputString.length() - 1)
			resultVector.push_back(stringToInteger(inputString));
		if (inputString[iterator] == ' ')
		{
			resultVector.push_back(stringToInteger(inputString.substr(0, iterator)));
			inputString = inputString.substr(iterator + 1);
			iterator = 0;
		}
		else
			iterator++;
	}
	return resultVector;
}
Exemple #18
0
    bool parseNameIntegerPair(const std::string& token, std::string& name, int& value)
    {
        const auto mid = token.find_first_of('=');
        if (mid != std::string::npos)
        {
            name = token.substr(0, mid);
            return stringToInteger(token.substr(mid + 1), value);
        }

        return false;
    }
Exemple #19
0
void encodeData(istream& input, const map<int, string> &encodingMap, obitstream& output) {
    while(input){
        //Ta ut första byten
        int tempByte = input.get();
        string tempCode;
        //Hämta ut bitsekvensen som hör till bokstaven
        if(tempByte == -1){
            tempCode = encodingMap.at(PSEUDO_EOF);
        }else{
            tempCode = encodingMap.at(tempByte);
        }

        while(tempCode.size() > 0){
            //Ta ut första biten från sekvensen
            int tempBit = stringToInteger(string(1,tempCode.front()));
            //Skriv ut den till output
            output.writeBit(tempBit);
            //Ta bort den från sekvensen
            tempCode.erase(tempCode.begin());
        }
    }
}
// line = "ZNK6VectorIiE3getEi at vector.h:587"
//         <FUNCTION> at <LINESTR>
void injectAddr2lineInfo(entry& ent, const std::string& line) {
    ent.line     = 0;
    int atIndex = stringIndexOf(line, " at ");
    if (atIndex >= 0) {
        if (ent.function.empty()) {
            ent.function = line.substr(0, atIndex);
        }
        ent.lineStr  = line.substr(atIndex + 4);

        int colonIndex = stringIndexOf(ent.lineStr, ":");
        if (colonIndex >= 0) {
            ent.file = ent.lineStr.substr(0, colonIndex);
            std::string rest = ent.lineStr.substr(colonIndex + 1);
            if (stringIsInteger(rest)) {
                ent.line = stringToInteger(rest);
            }
        }
    } else {
        if (ent.function.empty()) {
            ent.function = line;
        }
    }

    // demangle function name if necessary
    if (startsWith(ent.function, "Z")) {
        ent.function = "_" + ent.function;
    }

    if (startsWith(ent.function, "_Z")) {
        int status;
        char* demangled = abi::__cxa_demangle(ent.function.c_str(), NULL, 0, &status);
        if (status == 0 && demangled) {
            ent.function = demangled;
        }
    }
}
XMPPData XMPP::fetchSettings(mySQLData dbData)
{
  XMPPData xmpp;

  Database db(dbData);
  if(db.initConnection())
  {
    const char* getSettingsSQL = "SELECT xmpp_enabled, xmpp_server, xmpp_port,"
      "xmpp_user, xmpp_pass, xmpp_resource FROM settings";
    if(mysql_real_query(db.getHandle(), getSettingsSQL, strlen(getSettingsSQL)) == 0)
    {
      MYSQL_RES* res;
      if((res = mysql_store_result(db.getHandle())) != NULL)
      {
        MYSQL_ROW row;
        row = mysql_fetch_row(res);
        stringstream result;
        if(mysql_num_rows(res) > 0)
        {

          // xmpp_enabled
          if(row[0] != NULL)
          {
            if(strcmp(row[0], "1") == 0)
            {
              xmpp.doXMPP = 1;
            }
            else
            {
              xmpp.doXMPP = 0;
            }
          }

          // xmpp_server
          if(row[1] != NULL)
          {
            xmpp.xmppServer = row[1];
          }

          // xmpp_port
          if(row[2] != NULL)
          {
            xmpp.xmppPort = stringToInteger(row[2]);
          }

          // xmpp_user
          if(row[3] != NULL)
          {
            xmpp.xmppUser = row[3];
          }

          // xmpp_pass
          if(row[4] != NULL)
          {
            xmpp.xmppPass = row[4];
          }

          // xmpp_resource
          if(row[5] != NULL)
          {
            xmpp.xmppResource = row[5];
          }

        }
        else
        {
          // Nothing fetched. Disable mailing.
          xmpp.doXMPP = 0;
        }
      }
      else
      {
        // Error. Disable mailing.
        xmpp.doXMPP = 0;
      }
      mysql_free_result(res);
    }
    else
    {
      // Query failed. Disable mailing.
      xmpp.doXMPP = 0;
    }
    mysql_close(db.getHandle());
  }
  else
  {
    // Could not connect to DB. Diable mailing.
    xmpp.doXMPP = 0;
  }

  return xmpp;
}
static long stringToInteger(const std::string &value, long defaultValue, long minValue, long maxValue) {
	return std::max(minValue, std::min(maxValue, stringToInteger(value, defaultValue)));
}
Exemple #23
0
/**
 * Replaces special characters.
 * @param The buffer that needs to be parsed.
 */
void formatToUnicode(String& input)
{
  /* If the string is less than 4 characters, there is nothing to be replaced.
   */
  if (input.length() <= 4) {
	  return;
  }

  // Just in case there is nothing to replace.
  if (input.findFirstOf('&') == input.npos) {
	  return;
  }

  // Replace the punctuation characters.
  replaceString(input, "&euro;", "€");
  replaceString(input, "&pound;", "£");
  replaceString(input, "&laquo;", "«");
  replaceString(input, "&raquo;", "»");
  replaceString(input, "&bull;", "•");
  replaceString(input, "&dagger;", "†");
  replaceString(input, "&copy;", "©");
  replaceString(input, "&reg;", "®");
  replaceString(input, "&deg;", "°");
  replaceString(input, "&micro;", "µ");
  replaceString(input, "&middot;", "·");
  replaceString(input, "&ndash;", "–");
  replaceString(input, "&mdash;", "—");
  replaceString(input, "&iexcl;", "¡");
  replaceString(input, "&iquest;", "¿");
  replaceString(input, "&nbsp;", " ");

  replaceString(input, "&amp;", "&");
  replaceString(input, "&quot;", "\"");
  replaceString(input, "&lt;", "<");
  replaceString(input, "&gt;", ">");
  replaceString(input, "&rdquo;", "”");

  char* p = (char*)input.c_str();

  int ccstart = input.find("&#");
  int ccend;
  int ccode;
  char com[2];
  com[1] = 0;
  char* compointer = com;
  while(ccstart != input.npos)
  {
    ccend = ccstart + 2;
    while(isdigit(input.c_str()[ccend]))ccend++;

    ccode = stringToInteger(input.substr(ccstart + 2, ccend - ccstart -2));
    if(ccode < 255)
      com[0] = (char)ccode;
    else
      com[0] = 0;

    // Remove semicolons.
    if(input.c_str()[ccend] == ';')
      {
        ccend++;
      }

    /*
	 * replaceString(input, input.substr(ccstart, ccend - ccstart), String(com));
	 * the above might be faster than the bellow one
	 */
    strReplace(p, input.substr(ccstart, ccend - ccstart).c_str(), compointer);

    input = p;
    ccstart = input.find("&#");
  }
}
ZLIntegerRangeOption::ZLIntegerRangeOption(const ZLCategoryKey &category, const std::string &groupName, const std::string &optionName, long minValue, long maxValue, long defaultValue) : ZLOption(category, groupName, optionName), myMinValue(minValue), myMaxValue(maxValue), myDefaultValue(stringToInteger(getDefaultConfigValue(), defaultValue, minValue, maxValue)) {
}
Exemple #25
0
	/**
	 * Implementation of standard API exposed to JavaScript
	 * This function is used to detect different messages from JavaScript
	 * and call the respective function in MoSync.
	 *
	 * @return true if stream was handled, false if not.
	 */
	bool NativeUIMessageHandler::handleMessage(Wormhole::MessageStream& stream)
	{
		char buffer[1024];
		printf("Getting the next action \n");
		char * action = (char*)stream.getNext();
		printf("action: %s\n", action);
		// Widget Handling Calls
		if(0 == strcmp("maWidgetCreate", action))
		{
			char* widgetType = (char*)stream.getNext();
			char* widgetID = (char*)stream.getNext();
			char* callbackID = (char*)stream.getNext();
			printf("maWidgetCreate: %s, %s, %s\n", widgetType, widgetID, callbackID);
			int numParams = stringToInteger(stream.getNext());

			MAWidgetHandle widget = maWidgetCreate(widgetType);
			if(widget <= 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, widget);
				sendNativeUIError(buffer);
			}
			else
			{
				if(numParams > 0)
				{
					for(int i = 0; i < numParams/2; i++)
					{
						char* property = (char*)stream.getNext();
						char* value = (char*)stream.getNext();
						printf("maWidgetSetProperty %s, %s\n", property, value);
						int res = maWidgetSetProperty(widget, property, value);
						if(res < 0)
						{
							printf("could not set property\n");
						}
						else
						{
							printf("set property done\n");
						}
					}
				}
				//We use a special callback for widget creation
				printf("calling CallBack \n");
				sprintf(
					buffer,
					"mosync.nativeui.createCallback('%s', '%s', %d)",
					callbackID,
					widgetID,
					widget);
				printf("Done creatign the script %s\n", buffer);
				mWebView->callJS(buffer);
				printf("done Calling Callback");
			}

		}
		else if(0 == strcmp("maWidgetDestroy", action))
		{
			MAWidgetHandle widget = stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();

			int res = maWidgetDestroy(widget);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetAddChild", action) )
		{
			MAWidgetHandle parent = stringToInteger(stream.getNext());
			MAWidgetHandle child = stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetAddChild(parent, child);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetInsertChild", action))
		{
			MAWidgetHandle parent = stringToInteger((char*)stream.getNext());
			MAWidgetHandle child = stringToInteger((char*)stream.getNext());
			int index = stringToInteger((char*)stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetInsertChild(parent, child, index);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetRemoveChild", action))
		{
			MAWidgetHandle child = stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();

			int res = maWidgetRemoveChild(child);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetModalDialogShow", action))
		{
			MAWidgetHandle dialogHandle =
				stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetModalDialogShow(dialogHandle);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetModalDialogHide", action))
		{
			MAWidgetHandle dialogHandle =
					stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetModalDialogHide(dialogHandle);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetScreenShow", action))
		{
			MAWidgetHandle screenHandle =
					stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetScreenShow(screenHandle);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetStackScreenPush", action))
		{
			MAWidgetHandle stackScreen =
					stringToInteger(stream.getNext());
			MAWidgetHandle newScreen =
					stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetStackScreenPush(stackScreen, newScreen);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetStackScreenPop", action))
		{
			MAWidgetHandle stackScreen =
					stringToInteger(stream.getNext());
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetStackScreenPop(stackScreen);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetSetProperty", action))
		{
			MAWidgetHandle widget =
					stringToInteger(stream.getNext());
			char *property = (char*)stream.getNext();
			char *value = (char*)stream.getNext();
			char* callbackID = (char*)stream.getNext();
			int res = maWidgetSetProperty(widget, property, value);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUISuccess(buffer);
			}
		}
		else if(0 == strcmp("maWidgetGetProperty", action))
		{
			char value[1024];
			MAWidgetHandle widget =
					stringToInteger(stream.getNext());
			char* property = (char*)stream.getNext();
			char* callbackID = (char*)stream.getNext();

			int res = maWidgetGetProperty(widget, property, value, 1024);
			if(res < 0)
			{
				sprintf(buffer,"'%s', %d", callbackID, res);
				sendNativeUIError(buffer);
			}
			else
			{
				sprintf(buffer,"'%s', '%s', '%s'", callbackID, property, value);
				sendNativeUISuccess(buffer);
			}
		}

		// Tell the WebView that we have processed the stream, so that
		// it can send the next one.

		char replyScript[1024];
		char * mosyncCallBackId = (char*)stream.getNext();
		if(mosyncCallBackId != NULL)
		{
			sprintf(
					replyScript,
					"mosync.bridge.reply(%s)",
					mosyncCallBackId);
			printf("calling general callback %s\n", replyScript);
			mWebView->callJS(replyScript);
		}

		return true;
	}
ZLColorOption::ZLColorOption(const ZLCategoryKey &category, const std::string &groupName, const std::string &optionName, ZLColor defaultValue) : ZLOption(category, groupName, optionName), myDefaultIntValue(stringToInteger(getDefaultConfigValue(), defaultValue.intValue())) {
}
Exemple #27
0
 inline
 bool parseNameIntegerPair(const std::string& token, std::string& name, int& value)
 {
     std::string strValue;
     return parseNameValuePair(token, name, strValue, '=') && stringToInteger(strValue, value);
 }
ZLBoolean3Option::ZLBoolean3Option(const ZLCategoryKey &category, const std::string &groupName, const std::string &optionName, ZLBoolean3 defaultValue) : ZLSimpleOption(category, groupName, optionName), myDefaultValue((ZLBoolean3)stringToInteger(getDefaultConfigValue(), defaultValue)) {
}
// 8
void setConstant(FILE* file, DynamicTable* symbols, Token token) {
	printf("semantic: constant\n");fflush(stdout);
	constant = stringToInteger(token->value, 2);
}
Exemple #30
0
/**
 * Return the one token from the String. The String is updated.
 * If the string is empty, NULL is return.
 *
 * Input:
 *   str  is the String object
 *
 * Possible returned token:
 *    Number, Operator, and Identifier tokens
 */
Token *getToken(String *str) {
	//1 trim left
	//2 check first character
	//	a	-if a number then extract the number string
	//		-convert into integer
	//		-create number token
	//	b	-if alphabetSet then extract the identifier
	//		-create identifier token
	//	c	-if operator set then extract operator symbol
	//		-create operator token

	char charReturn[3];
	Token *tokenReturn = NULL;
	String *strReturn = NULL;
	Number *number = NULL;
	Identifier *identifier = NULL;
	Operator *operator = NULL;

	stringTrimLeft(str);
	if(stringLength(str) == 0)
		return NULL;


	//Number
	if(stringIsCharAtInSet(str,0,numberSet)){
		strReturn = stringRemoveWordContaining(str,numberSet);
		if(stringIsCharAtInSet(str,0,alphabetSet)){
			Throw(ERR_NUMBER_NOT_WELL_FORMED);
		}
		else{
			number = numberNew(stringToInteger(strReturn));
			tokenReturn = (Token *)number;
			stringDel(strReturn);
		}
	}

	//Identifier
	else if(stringIsCharAtInSet(str,0,alphabetSet)){
		strReturn = stringRemoveWordContaining(str,alphaNumericSet);
		identifier = identifierNew(stringSubstringInText(strReturn,0,strReturn->length));
		tokenReturn = (Token *)identifier;
		stringDel(strReturn);
	}

	//Operator
	else if(stringIsCharAtInSet(str,0,operatorSet)){
		charReturn[0] = (char )stringRemoveChar(str);
		charReturn[1] = 0;

		if(stringCharAt(str,0) == charReturn[0] && stringLength(str) != 0){
			if(charReturn[0] == '&'){
				charReturn[0] = '&';
				charReturn[1] = '&';
				charReturn[2] = 0;
				str->start++;
				str->length--;
			}
			else if(charReturn[0] == '|'){
				charReturn[0] = '|';
				charReturn[1] = '|';
				charReturn[2] = 0;
				str->start++;
				str->length--;
			}
		}

		operator = operatorNewBySymbol(charReturn);
		tokenReturn = (Token *)operator;

	}
	else
		Throw(ERR_ILLEGAL_ARGUMENT);


	return tokenReturn;
}