15 memback(void *contents, size_t size, size_t nmemb, void *userp)
17 size_t realsize = size * nmemb;
18 struct MemoryStruct *mem = (struct MemoryStruct *)userp;
20 char *ptr = realloc(mem->memory, mem->size + realsize + 1);
23 printf("not enough memory (realloc returned NULL)\n");
28 memcpy(&(mem->memory[mem->size]), contents, realsize);
29 mem->size += realsize;
30 mem->memory[mem->size] = 0;
36 main(int argc, char *argv[])
44 XtSetLanguageProc (NULL, NULL, NULL);
45 toplevel = XtVaOpenApplication (&app, "Castle Menu", NULL, 0, &argc, argv,
46 NULL, sessionShellWidgetClass, NULL);
49 CURL *curl = curl_easy_init();
53 fprintf(stderr, "ERROR: Failed to initialize cURL\n");
57 struct MemoryStruct chunk;
58 chunk.memory = malloc(1); /* will be grown as needed by the realloc above */
59 chunk.size = 0; /* no data at this point */
61 curl_easy_setopt(curl, CURLOPT_URL,
62 "https://nobilis.nobles.edu/skyworld/castlemenu.php");
63 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, memback);
64 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
65 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
67 printf("INFO: Fetching wepage\n");
68 res = curl_easy_perform(curl);
70 if (res != CURLE_OK) {
71 fprintf(stderr,"ERROR: Could not fetch webpage\n%s\n",
72 curl_easy_strerror(res));
76 curl_easy_cleanup(curl);
79 printf("INFO: Parsing HTML\n");
81 char *outp = (char *) malloc(strlen(chunk.memory) + 1); // Realloc?
83 for (int i = 345; i < strlen(chunk.memory); i++) {
84 char c = chunk.memory[i];
85 if (c == '<') intag = true;
86 if (!intag) strncat(outp, &c, 1);
87 if (c == '>') intag = false;
89 strncat(outp, "\0", 1);
94 /* for (int i = 0; i < 255; i++) { */
95 /* if (old != 0 && i > 0) { */
96 /* for (int j = old; j <= i; j++) { */
97 /* strncat(nl, outp, i - old); */
100 /* if (outp[i] == '\n') */
106 XtSetArg(args[0], XmNvalue, outp); n++;
107 XtSetArg(args[1], XmNeditable, False); n++;
108 text_w = XmCreateText(toplevel, "text", args, n);
111 XtManageChild(text_w);
112 XtRealizeWidget(toplevel);