Example #1
0
int main(int args, char **argv){
    printf("------------------------\n");
    if (args != 2) {
        printf("Help: Missed parameter introduce an integer, eg: array 8\n");
        return -1;
    }
    // Otherwise parsing the parameter
    int i = 0; // This variables exist in the stack
    for (i=0;i<args;i++){
        printf("-> %s\n", argv[i]);
    }

    // Then allocating memory for argv[1] items
    int size = charSize(argv[1]);
    int *array = (int*) malloc (size * sizeof(int));

    if (!array){
        printf("%s :Fatal Error not available memory\n",argv[0]);
        return -1;
    }

    for (i=0;i<size;i++){
        printf("-> %p : %d \n", array+i,*(array+i));
    }
    
    // So what to do with that memory?
    free(array);

    return 0;
}
Example #2
0
Font* Font::load(std::string path)
{
  std::unique_ptr<Font> font(new Font());

  //Debug::log("Loading font from '" + path + "'");
  font->texture.reset(Texture2d::load(path));

  std::ifstream file(path + ".font");

  if(file.is_open() == false)
  {
    Debug::logError("Failed to open font");
    throw std::exception();
  }

  std::vector<std::string> characters;
  int maxChars = 0;

  while(file.eof() == false)
  {
    std::string line;
    getline(file, line);

    if(line.length() < 1)
    {
      break;
    }

    if(line.length() > maxChars)
    {
      maxChars = line.length();
    }

    characters.push_back(line);
  }

  Vector2 charSize((float)font->texture->getWidth() / (float)maxChars, (float)font->texture->getHeight() / (float)characters.size());

  //std::cout << charSize.x << " " << charSize.y << std::endl;

  for(int y = 0; y < characters.size(); y++)
  {
    for(int x = 0; x < characters[y].length(); x++)
    {
      CharacterInfo info;
      info.index = characters[y][x];
      info.vert = Rect(0, 0, charSize.x, charSize.y);
      info.uv.x = ((float)x * charSize.x) / (float)font->texture->getWidth();
      info.uv.y = ((float)y * charSize.y) / (float)font->texture->getHeight();
      info.uv.width = ((float)x * charSize.x + charSize.x) / (float)font->texture->getWidth();
      info.uv.height = ((float)y * charSize.y + charSize.y) / (float)font->texture->getHeight();
      font->characterInfo.push_back(info);
    }
  }

  return font.release();
}
void Minitel::refreshSettings() {
  // Common parameters
  serialprint7(_currentMode);
  textColor(_currentTextColor);
  bgColor(_currentBgColor); // Only in graphic mode ?
  blink(_currentBlink);
  cursor(_currentShowCursor);
  // Graphic mode specific parameters
  if (_currentMode == GRAPHIC_MODE) {
    pixelate(_currentUnderline);
  }
  // Text mode specific parameters
  if (_currentMode == TEXT_MODE) {
    video(_currentVideo);
    charSize(_currentSize);
  }
}
int mIntCharArrayPair::byteEncode2(char * buffer) {
	int ptr = 0;
	int tmp;
	tmp = tag.byteEncode2(&buffer[ptr + 1]);
	buffer[ptr] = ((char) tmp);
	ptr = ptr + tmp + 1;

	mInt charSize(dataValue.getSize());
	tmp = charSize.byteEncode2(&buffer[ptr + 1]);
	buffer[ptr] = ((char) tmp);
	ptr = ptr + tmp + 1;

	tmp = dataValue.byteEncode2(&buffer[ptr]);
	ptr = ptr + tmp;

	return ptr;
}
Example #5
0
Font* Font::load(std::string path)
{
    // TODO:
    //arc<Font> font = arc<Font>::alloc();
    Font* font = new Font();

    //Debug::log("Loading font from '" + path + "'");
    font->texture.reset(Texture2d::load(path));

    std::vector<std::string> characters;
    int maxChars = 0;
    std::string chars;

    for(int i = 32; i < 127; i++)
    {
        chars += (char)i;
    }

    maxChars = chars.length();
    characters.push_back(chars);

    //Debug::log(chars);

    Vector2 charSize((float)font->texture->getWidth() / (float)maxChars, (float)font->texture->getHeight() / (float)characters.size());

    for(int y = 0; y < characters.size(); y++)
    {
        for(int x = 0; x < characters[y].length(); x++)
        {
            CharacterInfo info;
            info.index = characters[y][x];
            info.vert = Rect(0, 0, charSize.x, charSize.y);
            info.uv.x = ((float)x * charSize.x) / (float)font->texture->getWidth();
            info.uv.y = ((float)y * charSize.y) / (float)font->texture->getHeight();
            info.uv.width = ((float)x * charSize.x + charSize.x) / (float)font->texture->getWidth();
            info.uv.height = ((float)y * charSize.y + charSize.y) / (float)font->texture->getHeight();
            font->characterInfo.push_back(info);
        }
    }

    return font;
}
Example #6
0
NativeString Clipboard::pasteString()
{
	// 1
    XEvent e = checkEvent();

	// If we're being given a list of targets (possible conversions)
	if( e.xselection.target != XA_TARGETS ) {
		log::error("Target ", e.xselection.target, " should be XA_TARGETS ", XA_TARGETS);
		return {};
	}
    auto prop = readPropertyFromSel(e);
    if( ! prop ) {
		return {};
    }

	// request the STRING type
	Atom targetToBeRequested = prop.get("STRING");
	if( targetToBeRequested == None ) {
		log::error("No matching datatypes for clipboard!");
		return {};
	}
	DEBUG_CLIP("Now requesting type " << resourceManager.getAtomName(targetToBeRequested));
	XConvertSelection(resourceManager->dpy, sel, targetToBeRequested, sel, window.get(), CurrentTime);
	XFlush(resourceManager->dpy);

	// 2
    XEvent e2 = checkEvent();

    NativeString result;
	if( e2.xselection.target == targetToBeRequested ) {
	    if( auto prop = readPropertyFromSel(e2) ) {
			result.str.resize(prop.charSize());
			std::copy_n(prop.charData(),result.str.size(),result.str.begin());
	    }
	}
	return result;
}
Example #7
0
 CPack& I64(const int64_t val) {charSize(val);}
Example #8
0
 CPack& I32(const int32_t val) {charSize(val);}
Example #9
0
 CPack& I16(const int16_t val) {charSize(val);}
Example #10
0
 CPack& I8(const  int8_t val) {charSize(val);}
Example #11
0
 CPack& U64(const uint64_t val) {charSize(val);}
Example #12
0
 CPack& U32(const uint32_t val) {charSize(val);}
Example #13
0
 CPack& U16(const uint16_t val) {charSize(val);}
Example #14
0
 CPack& U8(const uint8_t val) {charSize(val);}