static App * proxyApp(FD *f) { App *app; app = appAlloc(); app->html = proxyHTML; app->htmlAttributeName = proxyHTMLAttributeName; app->htmlAttributeValue = proxyHTMLAttributeValue; app->htmlDeclaration = proxyHTMLDeclaration; app->htmlProcessingInstruction = proxyHTMLProcessingInstruction; app->htmlTag = proxyHTMLTag; app->htmlText = proxyHTMLText; app->httpResponse = proxyHTTP; app->httpResponseBody = proxyHTTPBody; app->httpResponseHeaderName = proxyHTTPHeaderName; app->httpResponseHeaderValue = proxyHTTPHeaderValue; app->view.backslash = 1; app->view.out = f->logFile; return app; }
CrBool crAppInitialize() { char utf8[] = {0xEF, 0xBB, 0xBF, 0xE9, 0x80, 0x99, 0xE6, 0x98, 0xAF, 0x55, 0x54, 0x46, 0x38, 0x00}; app = appAlloc(); appInit(app); // label { label = Label_alloc(); Label_init(label, crAppContext.context->xres, crAppContext.context->yres); Label_setText(label, utf8); Label_commit(label); } // materials { const char* directives[] = {nullptr}; appLoadMaterialBegin(app, directives); mtlText = appLoadMaterial( "Common.Ui.Vertex", "Common.Text.Fragment", nullptr, nullptr, nullptr); appLoadMaterialEnd(app); } // mesh { meshBg = meshAlloc(); meshInitWithScreenQuad(meshBg); } return CrTrue; }
int main(int argc, char *argv[]) { char *ampersand; App *app; unsigned char *equals; HTTPNameValue *h; HTTPNameValue *headers; char *name; unsigned char *newURL; char *p; char *query; unsigned char *referer; URL *u; unsigned char *url; char *verbose; char *version; View *view; if (!netInit()) { return 1; } if (!threadInit()) { return 1; } referer = NULL; url = NULL; verbose = "?url="; query = getenv("QUERY_STRING"); app = appAlloc(); app->html = cgiviewHTML; app->htmlAttributeName = cgiviewHTMLAttributeName; app->htmlAttributeValue = cgiviewHTMLAttributeValue; app->htmlDeclaration = cgiviewHTMLDeclaration; app->htmlProcessingInstruction = cgiviewHTMLProcessingInstruction; app->htmlTag = cgiviewHTMLTag; app->htmlText = cgiviewHTMLText; app->httpRequest = cgiviewHTTPRequest; app->httpRequestHeaderName = cgiviewHTTPRequestHeaderName; app->httpRequestHeaderValue = cgiviewHTTPRequestHeaderValue; app->httpResponse = cgiviewHTTPResponse; app->httpResponseBody = cgiviewHTTPResponseBody; app->httpResponseHeaderName = cgiviewHTTPResponseHeaderName; app->httpResponseHeaderValue = cgiviewHTTPResponseHeaderValue; app->printHTML = cgiviewPrintHTML; view = &app->view; view->out = stdout; freopen("/dev/null", "w", stderr); fprintf(view->out, "Content-Type: text/html\n"); fprintf(view->out, "\n"); if (query) { p = query; do { name = p; ampersand = strchr(p, '&'); if (ampersand) { *ampersand = 0; p = ampersand + 1; } equals = (unsigned char *) strchr(name, '='); if (equals) { *equals = 0; if (!strcmp(name, "referer")) { referer = equals + 1; urlDecode(referer); } else if (!strcmp(name, "url")) { url = equals + 1; urlDecode(url); } else if (!strcmp(name, "verbose")) { verbose = "?verbose=on&url="; viewVerbose(); } } } while (ampersand); } else if (argc > 1) { url = (unsigned char *) argv[1]; } else { fprintf(view->out, "no environment variable QUERY_STRING<br>\n"); fprintf(view->out, "and no arg passed<br>\n"); return 1; } if (url && (*url)) { fprintf(view->out, "<html><head><title>View %s</title>", url); fprintf(view->out, "<link rel=stylesheet href=view.css>"); fprintf(view->out, "</head><body>\n"); viewReport(app, "input url:"); viewReport(app, (char *) url); viewReportHTML(app, "<hr>"); u = urlParse(url); if ( ((!u->scheme)||(!strcmp((char *) u->scheme, "http"))) && (!u->host) && (*url != '/') ) { newURL = calloc(strlen((char *) url) + 3, 1); if (!newURL) { viewReport(app, "calloc failed"); return 1; } strcpy((char *) newURL, "//"); strcat((char *) newURL, (char *) url); } else { newURL = copyString(url); } urlFree(u); u = urlParse(newURL); if ( ( (!u->scheme) || (!strcmp((char *) u->scheme, "http")) ) && (!*u->path) ) { url = newURL; newURL = calloc(strlen((char *) url) + 2, 1); if (!newURL) { viewReport(app, "calloc failed"); return 1; } strcpy((char *) newURL, (char *) url); free(url); strcat((char *) newURL, "/"); } urlFree(u); u = urlRelative( (unsigned char *) "http://www.mozilla.org/index.html", newURL); free(newURL); viewReport(app, "fully qualified url:"); viewReport(app, (char *) u->url); viewReportHTML(app, "<hr>"); if (!strcmp((char *) u->scheme, "http")) { version = NULL; headers = cgiviewGetEnv(app, (char *) referer, verbose, &version); if (!headers) { return 1; } httpFree(httpProcess(app, u, version, headers)); h = headers; while (h->name) { free(h->name); free(h->value); h++; } free(headers); } else { fprintf ( view->out, "Sorry, %s URLs are not supported yet. " "Only http URLs are supported.", u->scheme ); } fprintf(view->out, "</body></html>\n"); } else { fprintf(view->out, "<html><head><title>SniffURI Error</title>"); fprintf(view->out, "</head><body><h2>Please enter a URI</h2>"); fprintf(view->out, "<a href=index.html>Go Back</a>"); fprintf(view->out, "</body></html>"); } exit(0); return 1; }
XprBool xprAppInitialize() { app = appAlloc(); appInit(app); // remote config { RemoteVarDesc descs[] = { {"gravity", &settings.gravity, 1, 100}, {"airResistance", &settings.airResistance, 1, 20}, {"impact", &settings.impact, 1, 10}, {"shadowSlopScale", &settings.shadowSlopScale, 0, 8}, {nullptr, nullptr, 0, 0} }; config = remoteConfigAlloc(); remoteConfigInit(config, 8080, XprTrue); remoteConfigAddVars(config, descs); } // shadow map shadowMap = xprRenderTargetAcquireBuffer(app->renderTarget, shadowMapSize, shadowMapSize, XprGpuFormat_FloatR16); shadowMapZ = xprRenderTargetAcquireBuffer(app->renderTarget, shadowMapSize, shadowMapSize, XprGpuFormat_Depth16); // materials { const char* directives[] = {nullptr}; appLoadMaterialBegin(app, directives); sceneMtl = appLoadMaterial( "ClothSimulation.Scene.Vertex", "ClothSimulation.Scene.Fragment", nullptr, nullptr, nullptr); bgMtl = appLoadMaterial( "Common.Bg.Vertex", "Common.Bg.Fragment", nullptr, nullptr, nullptr); shadowMapMtl = appLoadMaterial( "ShadowMap.Create.Vertex", "ShadowMap.Create.Fragment", nullptr, nullptr, nullptr); appLoadMaterialEnd(app); } // textures { texture = Pvr_createTexture(red_tile_texture); } // cloth { XprVec3 offset = xprVec3(-1, 1.5f, 0); cloth = Cloth_new(2, 2, &offset, 32); } // balls { ball[0].center = xprVec3(-0.5f, 0.5f, 0); ball[0].radius = 0.25f; ball[1].center = xprVec3(0.5f, 0.5f, 0); ball[1].radius = 0.25f; ballMesh = meshAlloc(); meshInitWithUnitSphere(ballMesh, 32); } // floor { XprVec3 offset = xprVec3(-2.5f, -2.5f, 0); floorMesh = meshAlloc(); meshInitWithQuad(floorMesh, 5, 5, &offset, 1); } // bg { bgMesh = meshAlloc(); meshInitWithScreenQuad(bgMesh); } return XprTrue; }