📄 qadm.c
字号:
htmlprintf("<td class=\"str\">\n"); htmlprintf("<select name=\"act\">\n"); htmlprintf("<option value=\"%d\"%s>PUT (over)</option>\n", ACTRECPUTOVER, act == ACTRECPUTOVER ? " selected=\"selected\"" : ""); htmlprintf("<option value=\"%d\"%s>PUT (keep)</option>\n", ACTRECPUTKEEP, act == ACTRECPUTKEEP ? " selected=\"selected\"" : ""); if(dbt == DBTVILLA){ htmlprintf("<option value=\"%d\"%s>PUT (dup)</option>\n", ACTRECPUTDUP, act == ACTRECPUTDUP ? " selected=\"selected\"" : ""); } else { htmlprintf("<option value=\"%d\"%s>PUT (cat)</option>\n", ACTRECPUTCAT, act == ACTRECPUTCAT ? " selected=\"selected\"" : ""); } if(dbt == DBTVILLA){ htmlprintf("<option value=\"%d\"%s>OUT (one)</option>\n", ACTRECOUTONE, act == ACTRECOUTONE ? " selected=\"selected\"" : ""); htmlprintf("<option value=\"%d\"%s>OUT (list)</option>\n", ACTRECOUTLIST, act == ACTRECOUTLIST ? " selected=\"selected\"" : ""); } else { htmlprintf("<option value=\"%d\"%s>OUT</option>\n", ACTRECOUTONE, act == ACTRECOUTONE ? " selected=\"selected\"" : ""); } htmlprintf("</select>\n"); htmlprintf("<input type=\"submit\" value=\"Submit\" />\n"); htmlprintf("<input type=\"reset\" value=\"Reset\" />\n"); htmlprintf("</td>\n"); htmlprintf("</tr>\n"); htmlprintf("<tr>\n"); htmlprintf("<th abbr=\"key\">Key:</th>\n"); htmlprintf("<td class=\"str\">\n"); if(keychop){ htmlprintf("<input type=\"text\" name=\"key\" size=\"48\" />\n"); } else { htmlprintf("<textarea name=\"key\" cols=\"48\" rows=\"3\"></textarea>\n"); } htmlprintf("</td>\n"); htmlprintf("</tr>\n"); htmlprintf("<tr>\n"); htmlprintf("<th abbr=\"val\">Value:</th>\n"); htmlprintf("<td class=\"str\">\n"); if(valchop){ htmlprintf("<input type=\"text\" name=\"val\" size=\"48\" />\n"); } else { htmlprintf("<textarea name=\"val\" cols=\"48\" rows=\"3\"></textarea>\n"); } htmlprintf("</td>\n"); htmlprintf("</tr>\n"); htmlprintf("</table>\n"); htmlprintf("<div><input type=\"hidden\" name=\"dbname\" value=\"%@\" /></div>\n", dbname); htmlprintf("<div><input type=\"hidden\" name=\"sure\" value=\"%d\" /></div>\n", sure); htmlprintf("</form>\n"); htmlprintf("<hr />\n"); if(sure){ htmlprintf("<p>The following are all records of the database." " : <a href=\"%s?act=%d&dbname=%?&sure=0\">" "[HIDE RECORDS]</a></p>\n", scriptname, ACTRECLIST); switch(dbt){ case DBTDEPOT: depotreclist(dbname); break; case DBTCURIA: curiareclist(dbname); break; case DBTVILLA: villareclist(dbname); break; default: break; } } else { htmlprintf("<p>The records are not shown now." " : <a href=\"%s?act=%d&dbname=%?&sure=1\">" "[SHOW RECORDS]</a></p>\n", scriptname, ACTRECLIST); }}/* chop the string */void strchop(char *str){ int i; for(i = strlen(str) - 1; i >= 0; i--){ if(strchr(" \r\n\t", str[i])){ str[i] = '\0'; } else { break; } }}/* update the database of Depot */void updatedepot(const char *dbname, int act, const char *key, const char *val){ int put, dmode; DEPOT *depot; char *kbuf, *vbuf; put = FALSE; dmode = DP_DOVER; switch(act){ case ACTRECPUTOVER: put = TRUE; dmode = DP_DOVER; break; case ACTRECPUTKEEP: put = TRUE; dmode = DP_DKEEP; break; case ACTRECPUTCAT: put = TRUE; dmode = DP_DCAT; break; case ACTRECOUTONE: break; default: return; } if(!key || !val){ htmlprintf("<p>Parameters are lack to update the database.</p>\n"); htmlprintf("<hr />\n"); return; } if(!(depot = dpopen(dbname, DP_OWRITER, -1))){ htmlprintf("<p>The database file could not open as a writer.</p>\n"); htmlprintf("<hr />\n"); return; } if(put){ kbuf = cbmemdup(key, -1); vbuf = cbmemdup(val, -1); if(keychop) strchop(kbuf); if(valchop) strchop(vbuf); if(dpput(depot, kbuf, -1, vbuf, -1, dmode)){ htmlprintf("<p>A record was stored.</p>\n"); } else if(dpecode == DP_EKEEP){ htmlprintf("<p>An existing record are kept.</p>\n"); } else { htmlprintf("<p>The database has a fatal error.</p>\n"); } free(vbuf); free(kbuf); } else { if(dpout(depot, key, -1)){ htmlprintf("<p>A record was deleted.</p>\n"); } else if(dpecode == DP_ENOITEM){ htmlprintf("<p>There is no such record.</p>\n"); } else { htmlprintf("<p>The database has a fatal error.</p>\n"); } } if(!dpclose(depot)) htmlprintf("<p>The database has a fatal error.</p>\n"); htmlprintf("<hr />\n");}/* update the database of Curia */void updatecuria(const char *dbname, int act, const char *key, const char *val){ int put, dmode; CURIA *curia; char *kbuf, *vbuf; put = FALSE; dmode = CR_DOVER; switch(act){ case ACTRECPUTOVER: put = TRUE; dmode = CR_DOVER; break; case ACTRECPUTKEEP: put = TRUE; dmode = CR_DKEEP; break; case ACTRECPUTCAT: put = TRUE; dmode = CR_DCAT; break; case ACTRECOUTONE: break; default: return; } if(!key || !val){ htmlprintf("<p>Parameters are lack to update the database.</p>\n"); htmlprintf("<hr />\n"); return; } if(!(curia = cropen(dbname, CR_OWRITER, -1, -1))){ htmlprintf("<p>The database file could not open as a writer.</p>\n"); htmlprintf("<hr />\n"); return; } if(put){ kbuf = cbmemdup(key, -1); vbuf = cbmemdup(val, -1); if(keychop) strchop(kbuf); if(valchop) strchop(vbuf); if(crput(curia, kbuf, -1, vbuf, -1, dmode)){ htmlprintf("<p>A record was stored.</p>\n"); } else if(dpecode == DP_EKEEP){ htmlprintf("<p>An existing record are kept.</p>\n"); } else { htmlprintf("<p>The database has a fatal error.</p>\n"); } free(vbuf); free(kbuf); } else { if(crout(curia, key, -1)){ htmlprintf("<p>A record was deleted.</p>\n"); } else if(dpecode == DP_ENOITEM){ htmlprintf("<p>There is no such record.</p>\n"); } else { htmlprintf("<p>The database has a fatal error.</p>\n"); } } if(!crclose(curia)) htmlprintf("<p>The database has a fatal error.</p>\n"); htmlprintf("<hr />\n");}/* update the database of Villa */void updatevilla(const char *dbname, int act, const char *key, const char *val){ int put, dmode, olist; VILLA *villa; char *kbuf, *vbuf; put = FALSE; dmode = VL_DOVER; olist = FALSE; switch(act){ case ACTRECPUTOVER: put = TRUE; dmode = VL_DOVER; break; case ACTRECPUTKEEP: put = TRUE; dmode = VL_DKEEP; break; case ACTRECPUTDUP: put = TRUE; dmode = VL_DDUP; break; case ACTRECOUTONE: olist = FALSE; break; case ACTRECOUTLIST: olist = TRUE; break; default: return; } if(!key || !val){ htmlprintf("<p>Parameters are lack to update the database.</p>\n"); htmlprintf("<hr />\n"); return; } if(!(villa = vlopen(dbname, VL_OWRITER, VL_CMPLEX))){ htmlprintf("<p>The database file could not open as a writer.</p>\n"); htmlprintf("<hr />\n"); return; } if(put){ kbuf = cbmemdup(key, -1); vbuf = cbmemdup(val, -1); if(keychop) strchop(kbuf); if(valchop) strchop(vbuf); if(vlput(villa, kbuf, -1, vbuf, -1, dmode)){ htmlprintf("<p>A record was stored.</p>\n"); } else if(dpecode == DP_EKEEP){ htmlprintf("<p>An existing record are kept.</p>\n"); } else { htmlprintf("<p>The database has a fatal error.</p>\n"); } free(vbuf); free(kbuf); } else { if(olist ? vloutlist(villa, key, -1) : vlout(villa, key, -1)){ if(olist){ htmlprintf("<p>Some records were deleted.</p>\n"); } else { htmlprintf("<p>A record was deleted.</p>\n"); } } else if(dpecode == DP_ENOITEM){ htmlprintf("<p>There is no such record.</p>\n"); } else { htmlprintf("<p>The database has a fatal error.</p>\n"); } } if(!vlclose(villa)) htmlprintf("<p>The database has a fatal error.</p>\n"); htmlprintf("<hr />\n");}/* list records of Depot */void depotreclist(const char *dbname){ DEPOT *depot; char *kbuf, *vbuf; int i, ksiz, vsiz; if(!(depot = dpopen(dbname, DP_OREADER, -1))){ htmlprintf("<p>The database file could not open as a reader.</p>\n"); return; } dpiterinit(depot); htmlprintf("<table summary=\"records\">\n"); htmlprintf("<tr>\n"); htmlprintf("<th abbr=\"number\">#</th>\n"); htmlprintf("<th abbr=\"keys\">Keys</th>\n"); htmlprintf("<th abbr=\"vals\">Values</th>\n"); htmlprintf("</tr>\n"); for(i = 1; (kbuf = dpiternext(depot, &ksiz)) != NULL; i++){ if(!(vbuf = dpget(depot, kbuf, ksiz, 0, -1, &vsiz))){ free(kbuf); continue; } htmlprintf("<tr>\n"); htmlprintf("<td class=\"num\"><var>%d</var></td>\n", i); htmlprintf("<td class=\"raw\">%@</td>\n", kbuf); htmlprintf("<td class=\"raw\">%@</td>\n", vbuf); htmlprintf("</tr>\n"); free(vbuf); free(kbuf); } htmlprintf("</table>\n"); dpclose(depot);}/* list records of Curia */void curiareclist(const char *dbname){ CURIA *curia; char *kbuf, *vbuf; int i, ksiz, vsiz; if(!(curia = cropen(dbname, CR_OREADER, -1, -1))){ htmlprintf("<p>The database file could not open as a reader.</p>\n"); return; } criterinit(curia); htmlprintf("<table summary=\"records\">\n"); htmlprintf("<tr>\n"); htmlprintf("<th abbr=\"number\">#</th>\n"); htmlprintf("<th abbr=\"keys\">Keys</th>\n"); htmlprintf("<th abbr=\"vals\">Values</th>\n"); htmlprintf("</tr>\n"); for(i = 1; (kbuf = criternext(curia, &ksiz)) != NULL; i++){ if(!(vbuf = crget(curia, kbuf, ksiz, 0, -1, &vsiz))){ free(kbuf); continue; } htmlprintf("<tr>\n"); htmlprintf("<td class=\"num\"><var>%d</var></td>\n", i); htmlprintf("<td class=\"raw\">%@</td>\n", kbuf); htmlprintf("<td class=\"raw\">%@</td>\n", vbuf); htmlprintf("</tr>\n"); free(vbuf); free(kbuf); } htmlprintf("</table>\n"); crclose(curia);}/* list records of Villa */void villareclist(const char *dbname){ VILLA *villa; char *kbuf, *vbuf; int i, ksiz, vsiz; if(!(villa = vlopen(dbname, VL_OREADER, VL_CMPLEX))){ htmlprintf("<p>The database file could not open as a reader.</p>\n"); return; } vlcurfirst(villa); htmlprintf("<table summary=\"records\">\n"); htmlprintf("<tr>\n"); htmlprintf("<th abbr=\"number\">#</th>\n"); htmlprintf("<th abbr=\"keys\">Keys</th>\n"); htmlprintf("<th abbr=\"vals\">Values</th>\n"); htmlprintf("</tr>\n"); for(i = 1; (kbuf = vlcurkey(villa, &ksiz)) != NULL; i++){ if(!(vbuf = vlcurval(villa, &vsiz))){ free(kbuf); vlcurnext(villa); continue; } htmlprintf("<tr>\n"); htmlprintf("<td class=\"num\"><var>%d</var></td>\n", i); htmlprintf("<td class=\"raw\">%@</td>\n", kbuf); htmlprintf("<td class=\"raw\">%@</td>\n", vbuf); htmlprintf("</tr>\n"); free(vbuf); free(kbuf); vlcurnext(villa); } htmlprintf("</table>\n"); vlclose(villa);}/* END OF FILE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -