void ajax_pager(tpl_t *tpl, double total, double slot, uint pos, uint limit[2]) { TCXSTR *str; uint n, i, cur; str = tcxstrnew(); n = (uint)ceil(total / slot); if(pos < 1) pos = 1; if(pos > n) pos = n; limit[1] = slot; limit[0] = (pos == 1) ? 0 : (pos-1) * limit[1]; for(i=0; i<n; i++) { cur = (i+1); if(cur == pos) tcxstrprintf(str, "<a class='page_link' href='javascript:void(0);'>%d</a> ", cur); else tcxstrprintf(str, "<a href='#' onclick='return loading(%d)'>%d</a> ", cur, cur); } tpl_set_field_global(tpl, "page", tcxstrptr(str), tcxstrsize(str)); tcxstrdel(str); }
static void do_mc_list(TTSOCK *sock, TASKARG *arg, TTREQ *req, char **tokens, int tnum){ ttservlog(g_serv, TTLOGDEBUG, "doing mc_list command"); TCADB *adb = arg->adb; if(tnum < 1){ ttsockprintf(sock, "CLIENT_ERROR error\r\n"); return; } TCXSTR *xstr = tcxstrnew(); TCXSTR * head = tcxstrnew(); pthread_cleanup_push((void (*)(void *))tcxstrdel, xstr); pthread_cleanup_push((void (*)(void *))tcxstrdel, head); tcadbiterinit(adb); char * key; int list_size; while((key=tcadbiternext2(adb))!=NULL){ tcxstrcat(xstr, key, strlen(key)); tcxstrcat(xstr,"\r\n",2); } list_size=tcxstrsize(xstr); tcxstrprintf(head,"LIST %d\r\n",list_size); tcxstrcat(xstr, "END\r\n",5); if( ttsocksend(sock, tcxstrptr(head), tcxstrsize(head)) && ttsocksend(sock,tcxstrptr(xstr),tcxstrsize(xstr)) ){ req->keep = true; } else { ttservlog(g_serv, TTLOGINFO, "do_mc_list: response failed"); return ; } pthread_cleanup_pop(1); pthread_cleanup_pop(1); }
static void bson_print_xstr(TCXSTR* xstr, const char *data, int depth) { bson_iterator i; const char *key; int temp; bson_timestamp_t ts; char oidhex[25]; bson scope; bson_iterator_from_buffer(&i, data); while (bson_iterator_next(&i)) { bson_type t = bson_iterator_type(&i); if (t == 0) break; key = bson_iterator_key(&i); for (temp = 0; temp <= depth; temp++) { tcxstrprintf(xstr, "."); } tcxstrprintf(xstr, "%s(%d)=", key, t); switch (t) { case BSON_DOUBLE: tcxstrprintf(xstr, "%f", bson_iterator_double(&i)); break; case BSON_STRING: tcxstrprintf(xstr, "%s", bson_iterator_string(&i)); break; case BSON_SYMBOL: tcxstrprintf(xstr, "SYMBOL: %s", bson_iterator_string(&i)); break; case BSON_OID: bson_oid_to_string(bson_iterator_oid(&i), oidhex); tcxstrprintf(xstr, "%s", oidhex); break; case BSON_BOOL: tcxstrprintf(xstr, "%s", bson_iterator_bool(&i) ? "true" : "false"); break; case BSON_DATE: tcxstrprintf(xstr, "%lld", (uint64_t) bson_iterator_long(&i)); break; case BSON_BINDATA: tcxstrprintf(xstr, "BSON_BINDATA"); break; case BSON_UNDEFINED: tcxstrprintf(xstr, "BSON_UNDEFINED"); break; case BSON_NULL: tcxstrprintf(xstr, "BSON_NULL"); break; case BSON_REGEX: tcxstrprintf(xstr, "BSON_REGEX: %s", bson_iterator_regex(&i)); break; case BSON_CODE: tcxstrprintf(xstr, "BSON_CODE: %s", bson_iterator_code(&i)); break; case BSON_CODEWSCOPE: tcxstrprintf(xstr, "BSON_CODE_W_SCOPE: %s", bson_iterator_code(&i)); /* bson_init( &scope ); */ /* review - stepped on by bson_iterator_code_scope? */ bson_iterator_code_scope(&i, &scope); tcxstrprintf(xstr, "\n SCOPE: "); bson_print_xstr(xstr, scope.data, 0); /* bson_destroy( &scope ); */ /* review - causes free error */ break; case BSON_INT: tcxstrprintf(xstr, "%d", bson_iterator_int(&i)); break; case BSON_LONG: tcxstrprintf(xstr, "%lld", (uint64_t) bson_iterator_long(&i)); break; case BSON_TIMESTAMP: ts = bson_iterator_timestamp(&i); tcxstrprintf(xstr, "i: %d, t: %d", ts.i, ts.t); break; case BSON_OBJECT: case BSON_ARRAY: tcxstrprintf(xstr, "\n"); bson_print_xstr(xstr, bson_iterator_value(&i), depth + 1); break; default: fprintf(stderr, "can't print type : %d\n", t); } tcxstrprintf(xstr, "\n"); } }
/* perform convert command */ static int procconvert(const char *ibuf, int isiz, int fmt, const char *buri, const char *duri, bool page){ TCMAP *cols = tcmapnew2(TINYBNUM); wikiload(cols, ibuf); if(fmt == FMTWIKI){ TCXSTR *rbuf = tcxstrnew3(IOBUFSIZ); wikidump(rbuf, cols); fwrite(tcxstrptr(rbuf), 1, tcxstrsize(rbuf), stdout); tcxstrdel(rbuf); } else if(fmt == FMTTEXT){ TCXSTR *rbuf = tcxstrnew3(IOBUFSIZ); if(page) tcxstrprintf(rbuf, "------------------------ Tokyo Promenade ------------------------\n"); wikidumptext(rbuf, cols); if(page) tcxstrprintf(rbuf, "-----------------------------------------------------------------\n"); fwrite(tcxstrptr(rbuf), 1, tcxstrsize(rbuf), stdout); tcxstrdel(rbuf); } else if(fmt == FMTHTML){ TCXSTR *rbuf = tcxstrnew3(IOBUFSIZ); if(page){ const char *name = tcmapget2(cols, "name"); tcxstrprintf(rbuf, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); tcxstrprintf(rbuf, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"); tcxstrprintf(rbuf, "<html xmlns=\"http://www.w3.org/1999/xhtml\"" " xml:lang=\"en\" lang=\"en\">\n"); tcxstrprintf(rbuf, "<head>\n"); tcxstrprintf(rbuf, "<meta http-equiv=\"Content-Type\"" " content=\"text/html; charset=UTF-8\" />\n"); tcxstrprintf(rbuf, "<link rel=\"contents\" href=\"%@\" />\n", buri); tcxstrprintf(rbuf, "<title>%@</title>\n", name ? name : "Tokyo Promenade"); tcxstrprintf(rbuf, "</head>\n"); tcxstrprintf(rbuf, "<body>\n"); } wikidumphtml(rbuf, cols, buri, 0, duri); if(page){ tcxstrprintf(rbuf, "</body>\n"); tcxstrprintf(rbuf, "</html>\n"); } fwrite(tcxstrptr(rbuf), 1, tcxstrsize(rbuf), stdout); tcxstrdel(rbuf); } tcmapdel(cols); return 0; }