Ejemplo n.º 1
0
sdef(bool, ToMultiByte, int c, String *res) {
    if (c <= 0x7F) {
		String_Append(res, c);
    } else if (c <= 0x7FF) {
		String_Append(res, 0xC0 | (c >> 6));
		String_Append(res, 0x80 | (c & 0x3F));
    } else if (c <= 0xFFFF) {
Ejemplo n.º 2
0
static void login_CharacterDataHandler (void *userData,
						  const XML_Char *s,
						  int len)
{
  loginArg *rp = (loginArg*)userData;
  if(rp->m_parsing_username==0) return;

  String_Append(rp->m_username,s,len);
}
Ejemplo n.º 3
0
static void getListPhoto_CharacterDataHandler (void *userData,
				      const XML_Char *s,
				      int len)
{
  getListPhotoArg *args = (getListPhotoArg*)userData;
  if(args->m_parsing_tag==0) return;

  String_Append(&args->m_tag.m_tagbody,s,len);
}
Ejemplo n.º 4
0
void String_AppendL(String *str, long value) {
    if (!str)
        return;

    String temp;
    String_InitL(&temp, value);
    String_Append(str, temp.buf, 0);
    String_Clear(&temp);
}
Ejemplo n.º 5
0
const char *concatenateStrings(const unsigned int sz,
			       const String *items,
			       String *scratch)
{
  unsigned int i=0;
  for(;i<sz;i++) {
    String_AppendOther(scratch, &items[i]);
    if(i+1<sz)
      String_Append(scratch, ",", 1);
  }
  return scratch->m_start;
}
Ejemplo n.º 6
0
Archivo: httpd.c Proyecto: tindzk/Jivai
def(void, OnRespond, bool persistent) {
	this->resp.len = 0;

	if (this->method == HTTP_Method_Get) {
		String_Append(&this->resp, $("Page requested via GET."));
	} else if (this->method == HTTP_Method_Post) {
		String_Append(&this->resp, $("Page requested via POST."));
	} else if (this->method == HTTP_Method_Head) {
		String_Append(&this->resp, $("Page requested via HEAD."));
	}

	if (this->method != HTTP_Method_Head) {
		String_Append(&this->resp,
			FmtString($(
				"<form action=\"/\" method=\"post\">"
				"<input type=\"text\" name=\"test\" /><br />"
				"<input type=\"text\" name=\"test2\" /><br />"
				"<input type=\"submit\" />"
				"</form>"
				"<br />"
				"You requested: %<br />"
				"test=%<br />"
				"test2=%<br />"
			),

			this->path.rd,
			this->paramTest.rd,
			this->paramTest2.rd));
	}

	String strLength = Integer_ToString(this->resp.len);

	String envelope = String_Format(
		$(
			"% 200 OK\r\n"
			"Content-Type: text/html; charset=utf-8\r\n"
			"%\r\n"
			"Content-Length: %\r\n"
			"\r\n"
		),

		HTTP_Version_ToString(this->version),

		persistent
			? $("Connection: Keep-Alive")
			: $("Connection: Close"),

		strLength.rd);

	String_Destroy(&strLength);

	SocketConnection_Write(this->conn, envelope.rd);

	size_t written = SocketConnection_Write(this->conn, this->resp.rd);
	String_Crop(&this->resp, written);

	SocketConnection_Flush(this->conn);

	String_Destroy(&envelope);

	this->paramTest.len  = 0;
	this->paramTest2.len = 0;

	/* You may want to change the value of this variable when the
	 * content length is unknown. If that's the case, you won't have
	 * no choice to indicate the end of the response but to close
	 * the connection.
	 */
	this->persistent = persistent;
}
Ejemplo n.º 7
0
void ShaderGen2D_CreateShader2D(ShaderGen2D *gen, int index, DWORD id)
{
    STRING tmp;
    DWORD rop;
    tmp.ptr = NULL;
    BOOL intproc = FALSE;
    BOOL usedest = FALSE;
    gen->genshaders2D[index].shader.vsrc.ptr = NULL;
    gen->genshaders2D[index].shader.fsrc.ptr = NULL;
    char idstring[22];
    _snprintf(idstring, 21, "%0.8I32X\n", id);
    idstring[21] = 0;
    // Create vertex shader
    // Header
    STRING *vsrc = &gen->genshaders2D[index].shader.vsrc;
    String_Append(vsrc, revheader);
    if (id & DDBLT_ROP)
    {
        rop = UnpackROPBits(id);
        if (gen->ext->glver_major >= 3)
        {
            String_Append(vsrc, version_130);
            intproc = TRUE;
        }
        else if (gen->ext->GLEXT_EXT_gpu_shader4)
        {
            String_Append(vsrc, version_110);
            String_Append(vsrc, ext_shader4);
            intproc = TRUE;
        }
        else String_Append(vsrc, version_110);
    }
    else String_Append(vsrc, version_110);
    String_Append(vsrc, idheader);
    String_Append(vsrc, idstring);

    // Attributes
    String_Append(vsrc, attr_xy);
    if (!(id & DDBLT_COLORFILL)) String_Append(vsrc, attr_srcst);
    if (id & DDBLT_ROP)
    {
        if (rop_texture_usage[rop] & 2) usedest = TRUE;
    }
    if (id & DDBLT_KEYDEST) usedest = TRUE;
    if (usedest) String_Append(vsrc, attr_destst);
    if (id & 0x10000000) String_Append(vsrc, attr_stencilst);

    // Uniforms
    String_Append(vsrc, unif_view);

    // Main
    String_Append(vsrc, mainstart);
    String_Append(vsrc, op_vertex);
    if (!(id & DDBLT_COLORFILL)) String_Append(vsrc, op_texcoord0);
    if(usedest) String_Append(vsrc, op_texcoord1);
    if (id & 0x10000000) String_Append(vsrc, op_texcoord3);
    String_Append(vsrc, mainend);
#ifdef _DEBUG
    OutputDebugStringA("2D blitter vertex shader:\n");
    OutputDebugStringA(vsrc->ptr);
    OutputDebugStringA("\nCompiling 2D blitter vertex shader:\n");
    TRACE_STRING("2D blitter vertex shader:\n");
    TRACE_STRING(vsrc->ptr);
    TRACE_STRING("\nCompiling 2D blitter vertex shader:\n");
#endif
    gen->genshaders2D[index].shader.vs = gen->ext->glCreateShader(GL_VERTEX_SHADER);
    GLint srclen = strlen(vsrc->ptr);
    gen->ext->glShaderSource(gen->genshaders2D[index].shader.vs, 1, &vsrc->ptr, &srclen);
    gen->ext->glCompileShader(gen->genshaders2D[index].shader.vs);
    GLint result;
    char *infolog = NULL;
    gen->ext->glGetShaderiv(gen->genshaders2D[index].shader.vs, GL_COMPILE_STATUS, &result);
#ifdef _DEBUG
    GLint loglen;
    if (!result)
    {
        gen->ext->glGetShaderiv(gen->genshaders2D[index].shader.vs, GL_INFO_LOG_LENGTH, &loglen);
        infolog = (char*)malloc(loglen);
        gen->ext->glGetShaderInfoLog(gen->genshaders2D[index].shader.vs, loglen, &result, infolog);
        OutputDebugStringA("Compilation failed. Error messages:\n");
        OutputDebugStringA(infolog);
        TRACE_STRING("Compilation failed. Error messages:\n");
        TRACE_STRING(infolog);
        free(infolog);
    }
#endif
    usedest = FALSE;
    // Create fragment shader
    STRING *fsrc = &gen->genshaders2D[index].shader.fsrc;
    String_Append(fsrc, revheader);
    if (id & DDBLT_ROP)
    {
        if (gen->ext->glver_major >= 3)
        {
            String_Append(fsrc, version_130);
            intproc = true;
        }
        else if (gen->ext->GLEXT_EXT_gpu_shader4)
        {
            String_Append(fsrc, version_110);
            String_Append(fsrc, ext_shader4);
            intproc = true;
        }
        else String_Append(fsrc, version_110);
    }
    else String_Append(fsrc, version_110);
    String_Append(fsrc, idheader);
    String_Append(fsrc, idstring);

    // Uniforms
    if (id & DDBLT_COLORFILL) String_Append(fsrc, unif_fillcolor);
    else String_Append(fsrc, unif_srctex);
    if (id & DDBLT_KEYDEST) usedest = TRUE;
    if (id & DDBLT_ROP)
    {
        if (rop_texture_usage[rop] & 2) usedest = TRUE;
        if (rop_texture_usage[rop] & 4)
        {
            String_Append(fsrc, unif_patterntex);
            String_Append(fsrc, unif_patternsize);
        }
    }
    if (usedest) String_Append(fsrc, unif_desttex);
    if (id & 0x10000000) String_Append(fsrc, unif_stenciltex);
    if (id & DDBLT_KEYSRC)
    {
        String_Append(fsrc, unif_ckeysrc);
        if (id & 0x20000000) String_Append(fsrc, unif_ckeysrchigh);
        String_Append(fsrc, unif_colorsizesrc);
    }
    String_Append(fsrc, unif_colorsizedest);
    if (id & DDBLT_KEYDEST)
    {
        String_Append(fsrc, unif_ckeydest);
        if (id & 0x40000000) String_Append(fsrc, unif_ckeydesthigh);
    }

    // Variables
    String_Append(fsrc, var_pixel);
    if (id & DDBLT_KEYSRC) String_Append(fsrc, var_src);
    if (id & DDBLT_ROP)
    {
        if (rop_texture_usage[rop] & 4)
        {
            String_Append(fsrc, var_pattern);
            String_Append(fsrc, var_patternst);
        }
    }
    if (usedest) String_Append(fsrc, var_dest);

    // Main
    String_Append(fsrc, mainstart);
    if (id & 0x10000000) String_Append(fsrc, op_clip);
    if (id & DDBLT_COLORFILL) String_Append(fsrc, op_color);
    else String_Append(fsrc, op_pixel);
    if (id & DDBLT_KEYSRC) String_Append(fsrc, op_src);
    if (usedest) String_Append(fsrc, op_dest);
    if (id & DDBLT_KEYSRC)
    {
        if (id & 0x20000000) String_Append(fsrc, op_ckeysrcrange);
        else String_Append(fsrc, op_ckeysrc);
    }
    if (id & DDBLT_KEYDEST)
    {
        if (id & 0x40000000) String_Append(fsrc, op_ckeydestrange);
        else String_Append(fsrc, op_ckeydest);
    }
    if (id & DDBLT_ROP)
    {
        if (rop_texture_usage[rop] & 4) String_Append(fsrc, op_pattern);
        if (intproc) String_Append(fsrc, op_ROP[rop]);
        else String_Append(fsrc, op_ROP_float[rop]);
    }

    String_Append(fsrc, op_destout);
    String_Append(fsrc, mainend);
#ifdef _DEBUG
    OutputDebugStringA("2D blitter fragment shader:\n");
    OutputDebugStringA(fsrc->ptr);
    OutputDebugStringA("\nCompiling 2D blitter fragment shader:\n");
    TRACE_STRING("2D blitter fragment shader:\n");
    TRACE_STRING(fsrc->ptr);
    TRACE_STRING("\nCompiling 2D blitter fragment shader:\n");
#endif
    gen->genshaders2D[index].shader.fs = gen->ext->glCreateShader(GL_FRAGMENT_SHADER);
    srclen = strlen(fsrc->ptr);
    gen->ext->glShaderSource(gen->genshaders2D[index].shader.fs, 1, &fsrc->ptr, &srclen);
    gen->ext->glCompileShader(gen->genshaders2D[index].shader.fs);
    gen->ext->glGetShaderiv(gen->genshaders2D[index].shader.fs, GL_COMPILE_STATUS, &result);
#ifdef _DEBUG
    if (!result)
    {
        gen->ext->glGetShaderiv(gen->genshaders2D[index].shader.fs, GL_INFO_LOG_LENGTH, &loglen);
        infolog = (char*)malloc(loglen);
        gen->ext->glGetShaderInfoLog(gen->genshaders2D[index].shader.fs, loglen, &result, infolog);
        OutputDebugStringA("Compilation failed. Error messages:\n");
        OutputDebugStringA(infolog);
        TRACE_STRING("Compilation failed. Error messages:\n");
        TRACE_STRING(infolog);
        free(infolog);
    }
#endif
    gen->genshaders2D[index].shader.prog = gen->ext->glCreateProgram();
    gen->ext->glAttachShader(gen->genshaders2D[index].shader.prog, gen->genshaders2D[index].shader.vs);
    gen->ext->glAttachShader(gen->genshaders2D[index].shader.prog, gen->genshaders2D[index].shader.fs);
    gen->ext->glLinkProgram(gen->genshaders2D[index].shader.prog);
    gen->ext->glGetProgramiv(gen->genshaders2D[index].shader.prog, GL_LINK_STATUS, &result);
#ifdef _DEBUG
    if (!result)
    {
        gen->ext->glGetProgramiv(gen->genshaders2D[index].shader.prog, GL_INFO_LOG_LENGTH, &loglen);
        infolog = (char*)malloc(loglen);
        gen->ext->glGetProgramInfoLog(gen->genshaders2D[index].shader.prog, loglen, &result, infolog);
        OutputDebugStringA("Program link failed. Error messages:\n");
        OutputDebugStringA(infolog);
        TRACE_STRING("Program link failed. Error messages:\n");
        TRACE_STRING(infolog);
        free(infolog);
    }
#endif
    gen->genshaders2D[index].shader.attribs[0] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "xy");
    gen->genshaders2D[index].shader.attribs[1] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "rgb");
    gen->genshaders2D[index].shader.attribs[2] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "rgba");
    gen->genshaders2D[index].shader.attribs[3] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "srcst");
    gen->genshaders2D[index].shader.attribs[4] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "destst");
    gen->genshaders2D[index].shader.attribs[5] = gen->ext->glGetAttribLocation(gen->genshaders2D[index].shader.prog, "stencilst");
    gen->genshaders2D[index].shader.uniforms[0] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "view");
    gen->genshaders2D[index].shader.uniforms[1] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "srctex");
    gen->genshaders2D[index].shader.uniforms[2] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "desttex");
    gen->genshaders2D[index].shader.uniforms[3] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "patterntex");
    gen->genshaders2D[index].shader.uniforms[4] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "stenciltex");
    gen->genshaders2D[index].shader.uniforms[5] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeysrc");
    gen->genshaders2D[index].shader.uniforms[6] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeydest");
    gen->genshaders2D[index].shader.uniforms[7] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeysrchigh");
    gen->genshaders2D[index].shader.uniforms[8] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeydesthigh");
    gen->genshaders2D[index].shader.uniforms[9] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "patternsize");
    gen->genshaders2D[index].shader.uniforms[10] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "colorsizesrc");
    gen->genshaders2D[index].shader.uniforms[11] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "colorsizedest");
    gen->genshaders2D[index].shader.uniforms[12] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "fillcolor");

    gen->genshaders2D[index].id = id;
}