/* this not the way to parse xml but hey */ static char *rxmltext(const char *xml, char *tag, char *def) { static char *d = NULL; char *start; char *stop; char *s; if(d) { cc_xfree(d); d = NULL; } s = rconcat("<", tag, ">"); start = strstr(xml, s); if(!start) return def; start += strlen(s); stop = strstr(start, rconcat("</", tag, ">")); if(!stop) return def; s = strndup(start, stop - start); d = cc_xstream_xml_decode(s); free(s); return d; }
/* ccx seams to have no set abosulute path thingi so emulate it by * walking up ROOT_WALKUP_LEVELS levels and then walk down into each * dir component. i dont like this code */ static int cwd(const char *path) { char *s, *n; char *d = strdup(rconcat(opts.root, "/", path + 1)); /* skip first "/" */ s = d; if(s[0] == '/') s++; /* hopefully end up in root */ if(cc_xstream_client_upcwd(ccxconn, ROOT_WALKUP_LEVELS) != CC_XSTREAM_CLIENT_OK) { return 0; } /* while there are components left */ while(strlen(s) > 0) { /* find first / and terminate it */ n = strchr(s, '/'); if(n) *n = '\0'; /* if not empty, only happens for path="/"? */ if(strlen(s) > 0) if(cc_xstream_client_setcwd(ccxconn, s) != CC_XSTREAM_CLIENT_OK) { free(d); return 0; } /* no / was found */ if(!n) break; s = n + 1; } free(d); return 1; }
Tree concat (Tree l, Tree q) { return rconcat(reverse(l), q); }