⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qadm.c

📁 harvest是一个下载html网页得机器人
💻 C
📖 第 1 页 / 共 3 页
字号:
            putchar('+');          } else {            printf("%%%02X", c);          }          tmp++;        }        break;      case '%':        putchar('%');        break;      }    } else {      putchar(*format);    }    format++;  }  va_end(ap);}/* print mime headers */void printmime(void){  printf("Content-Type: text/html; charset=%s\r\n", enc);  printf("Cache-Control: no-cache, must-revalidate\r\n");  printf("Pragma: no-cache\r\n");  printf("\r\n");  fflush(stdout);}/* print the declarations of XHTML */void printdecl(void){  htmlprintf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", enc);  htmlprintf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "             "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");}/* print headers */void printhead(void){  htmlprintf("<head>\n");  htmlprintf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" />\n", enc);  htmlprintf("<meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />\n");  htmlprintf("<link rel=\"contents\" href=\"./\" />\n");  htmlprintf("<title>%@</title>\n", title);  htmlprintf("<style type=\"text/css\">\n");  htmlprintf("body { background-color: #eeeeee; color: #111111;"             " margin: 0em 0em; padding: 0em 1em; }\n");  htmlprintf(".note { margin: 0.5em 0.5em; text-align: right; }\n");  htmlprintf("h1,h2,p { margin: 0.5em 0.5em; }\n");  htmlprintf("hr { margin-top: 1.2em; margin-bottom: 0.8em; height: 1pt;");  htmlprintf(" color: #888888; background-color: #888888; border: none; }\n");  htmlprintf("a { color: #0022aa; text-decoration: none; }\n");  htmlprintf("a:hover { color: #1144ff; text-decoration: underline; }\n");  htmlprintf("a.head { color: #111111; text-decoration: none; }\n");  htmlprintf("em { font-weight: bold; font-style: normal; }\n");  htmlprintf("form { margin: 0em 0em; padding: 0em 0em; }\n");  htmlprintf("div,table { margin: 0em 1em; padding: 0em 0em;"             " border: none; border-collapse: collapse; }\n");  htmlprintf("th,td { margin: 0em 0em; padding: 0.2em 0.5em; vertical-align: top; }\n");  htmlprintf("th { font-size: smaller; font-weight: normal; text-align: left; }\n");  htmlprintf("td { background-color: #ddddee; border: solid 1pt #888888; }\n");  htmlprintf("td.str { text-align: left; }\n");  htmlprintf("td.num { text-align: right; }\n");  htmlprintf("td.raw { text-align: left; white-space: pre; font-family: monospace; }\n");  htmlprintf("</style>\n");  htmlprintf("</head>\n");}/* get the attributes of a database */const char *getdbattrs(const char *dbname, int *dbtp, int *rnump, int *fsizp, time_t *mtp){  static char name[PATHBUFSIZ], *tmp;  DEPOT *depot;  CURIA *curia;  VILLA *villa;  struct stat sbuf;  strcpy(name, dbname);  *dbtp = DBTERROR;  *fsizp = -1;  *rnump = -1;  *mtp = -1;  if((tmp = strrchr(name, '.')) != NULL){    *tmp = '\0';    tmp++;    if(!strcmp(tmp, "dp")){      *dbtp = DBTDEPOT;    } else if(!strcmp(tmp, "cr")){      *dbtp = DBTCURIA;    } else if(!strcmp(tmp, "vl")){      *dbtp = DBTVILLA;    }  }  switch(*dbtp){  case DBTDEPOT:    if((depot = dpopen(dbname, DP_OREADER, -1)) != NULL){      *fsizp = dpfsiz(depot);      *rnump = dprnum(depot);      dpclose(depot);    }    break;  case DBTCURIA:    if((curia = cropen(dbname, CR_OREADER, -1, -1)) != NULL){      *fsizp = crfsiz(curia);      *rnump = crrnum(curia);      crclose(curia);    }    break;  case DBTVILLA:    if((villa = vlopen(dbname, VL_OREADER, VL_CMPLEX)) != NULL){      *fsizp = vlfsiz(villa);      *rnump = vlrnum(villa);      vlclose(villa);    }    break;  default:    break;  }  if(stat(dbname, &sbuf) == 0){    *mtp = sbuf.st_mtime;  }  return name;}/* get the string of a database type */const char *dbtstr(int dbt){  switch(dbt){  case DBTDEPOT: return "Depot";  case DBTCURIA: return "Curia";  case DBTVILLA: return "Villa";  default: break;  }  return "ERROR";}/* get the string of the time */const char *timestr(time_t t){  static char str[TSTRBUFSIZ];  struct tm *tsp;  tsp = localtime(&t);  sprintf(str, "%04d/%02d/%02d %02d:%02d:%02d",          tsp->tm_year + 1900, tsp->tm_mon + 1, tsp->tm_mday,          tsp->tm_hour, tsp->tm_min, tsp->tm_sec);  return str;}/* list existing databases */void dodblist(){  CBLIST *files;  const char *tmp, *name;  int i, dbt, rnum, fsiz;  time_t mt;  if(!(files = cbdirlist("."))){    htmlprintf("<p>The data directory could not be scanned.</p>\n");    return;  }  cblistsort(files);  htmlprintf("<p>The following are existing database files."             "  Select a database file and its action.</p>\n");  htmlprintf("<form action=\"%@\" method=\"post\">\n", scriptname);  htmlprintf("<table summary=\"databases\">\n");  htmlprintf("<tr>\n");  htmlprintf("<th abbr=\"name\">Name</th>\n");  htmlprintf("<th abbr=\"dbt\">Type of Database</th>\n");  htmlprintf("<th abbr=\"fsiz\">Size</th>\n");  htmlprintf("<th abbr=\"rnum\">Records</th>\n");  htmlprintf("<th abbr=\"last\">Last Modified</th>\n");  htmlprintf("<th abbr=\"acts\">Actions</th>\n");  htmlprintf("</tr>\n");  for(i = 0; i < cblistnum(files); i++){    tmp = cblistval(files, i, NULL);    if(!strcmp(tmp, ".") || !strcmp(tmp, "..")) continue;    name = getdbattrs(tmp, &dbt, &rnum, &fsiz, &mt);    htmlprintf("<tr>\n");    htmlprintf("<td class=\"str\"><em>%@</em></td>\n", name);    htmlprintf("<td class=\"str\">%@</td>\n", dbtstr(dbt));    htmlprintf("<td class=\"num\">%d</td>\n", fsiz);    htmlprintf("<td class=\"num\">%d</td>\n", rnum);    htmlprintf("<td class=\"str\">%s</td>\n", timestr(mt));    htmlprintf("<td class=\"str\">");    htmlprintf("<a href=\"%s?act=%d&amp;dbname=%?\">[OPEN]</a>",               scriptname, ACTRECLIST, tmp);    htmlprintf(" <a href=\"%s?act=%d&amp;dbname=%?&amp;sure=0\">[REMOVE]</a>",               scriptname, ACTDBREMOVE, tmp);    if(dbt != DBTCURIA){      htmlprintf(" <a href=\"%s?act=%d&amp;dbname=%?\">[D/L]</a>",                 scriptname, ACTDBDOWN, tmp);    }    htmlprintf("</td>\n");    htmlprintf("</tr>\n");  }  htmlprintf("</table>\n");  htmlprintf("</form>\n");  htmlprintf("<hr />\n");  htmlprintf("<p>This form is used in order to create a new database.</p>\n");  htmlprintf("<form action=\"%@\" method=\"post\">\n", scriptname);  htmlprintf("<table summary=\"new database\">\n");  htmlprintf("<tr>\n");  htmlprintf("<th abbr=\"name\">Name</th>\n");  htmlprintf("<th abbr=\"dbt\">Type of Database</th>\n");  htmlprintf("<th abbr=\"act\">Action</th>\n");  htmlprintf("</tr>\n");  htmlprintf("<tr>\n");  htmlprintf("<td class=\"str\">"             "<input type=\"text\" name=\"dbname\" size=\"32\" /></td>\n");  htmlprintf("<td class=\"str\"><select name=\"dbt\">\n");  htmlprintf("<option value=\"%d\">%@</option>\n", DBTDEPOT, dbtstr(DBTDEPOT));  htmlprintf("<option value=\"%d\">%@</option>\n", DBTCURIA, dbtstr(DBTCURIA));  htmlprintf("<option value=\"%d\">%@</option>\n", DBTVILLA, dbtstr(DBTVILLA));  htmlprintf("</select></td>\n");  htmlprintf("<td class=\"str\"><input type=\"submit\" value=\"Create\" /></td>\n");  htmlprintf("</tr>\n");  htmlprintf("</table>\n");  htmlprintf("<div><input type=\"hidden\" name=\"act\" value=\"%d\" /></div>\n", ACTDBCREATE);  htmlprintf("</form>\n");  cblistclose(files);}/* create a new database */void dodbcreate(const char *dbname, int dbt){  CBLIST *files;  char path[PATHBUFSIZ];  int i, err;  DEPOT *depot;  CURIA *curia;  VILLA *villa;  if(!dbname || strlen(dbname) < 1){    htmlprintf("<p>The name of the database is not defined.</p>\n");    return;  }  if(strchr(dbname, '/')){    htmlprintf("<p>The name of the database includes invalid characters: `/'.</p>\n");    return;  }  if(dbt == DBTERROR){    htmlprintf("<p>The parameters are invalid.</p>\n");    return;  }  if(!(files = cbdirlist("."))){    htmlprintf("<p>The data directory could not be scanned.</p>\n");    return;  }  for(i = 0; i < cblistnum(files); i++){    sprintf(path, "%s.dp", dbname);    if(fwmatch(cblistval(files, i, NULL), path)){      cblistclose(files);      htmlprintf("<p>`%@' is duplicated.</p>\n", dbname);      return;    }    sprintf(path, "%s.cr", dbname);    if(fwmatch(cblistval(files, i, NULL), path)){      cblistclose(files);      htmlprintf("<p>`%@' is duplicated.</p>\n", dbname);      return;    }    sprintf(path, "%s.vl", dbname);    if(fwmatch(cblistval(files, i, NULL), path)){      cblistclose(files);      htmlprintf("<p>`%@' is duplicated.</p>\n", dbname);      return;    }  }  cblistclose(files);  sprintf(path, "%s.%s", dbname, dbt == DBTDEPOT ? "dp" : dbt == DBTCURIA ? "cr" : "vl");  err = FALSE;  switch(dbt){  case DBTDEPOT:    if(!(depot = dpopen(path, DP_OWRITER | DP_OCREAT | DP_OTRUNC, -1)) ||       !dpclose(depot)) err = TRUE;    break;  case DBTCURIA:    if(!(curia = cropen(path, CR_OWRITER | CR_OCREAT | CR_OTRUNC, -1, -1)) ||       !crclose(curia)) err = TRUE;    break;  case DBTVILLA:    if(!(villa = vlopen(path, VL_OWRITER | VL_OCREAT | VL_OTRUNC, VL_CMPLEX)) ||       !vlclose(villa)) err = TRUE;    break;  }  if(err){    htmlprintf("<p>`%@' could not be created.</p>\n", dbname);  } else {    htmlprintf("<p>`<em>%@</em>' was created successfully.</p>\n", dbname);  }}/* remove a database */void dodbremove(const char *dbname, int sure){  const char *name;  int dbt, rnum, fsiz, err;  time_t mt;  if(!dbname || strlen(dbname) < 1){    htmlprintf("<p>The name of the database is not defined.</p>\n");    return;  }  name = getdbattrs(dbname, &dbt, &rnum, &fsiz, &mt);  if(!sure){    htmlprintf("<p>Do you really remove `<em>%@</em>'?</p>\n", name);    htmlprintf("<div><a href=\"%s?act=%d&amp;dbname=%?&amp;sure=1\">[REMOVE]</a></div>\n",               scriptname, ACTDBREMOVE, dbname);    return;  }  err = FALSE;  switch(dbt){  case DBTDEPOT:    if(!dpremove(dbname)) err = TRUE;    break;  case DBTCURIA:    if(!crremove(dbname)) err = TRUE;    break;  case DBTVILLA:    if(!vlremove(dbname)) err = TRUE;    break;  default:    err = TRUE;    break;  }  if(err){    htmlprintf("<p>`%@' could not be removed.</p>\n", name);  } else {    htmlprintf("<p>`<em>%@</em>' was removed successfully.</p>\n", name);  }}/* open a database */void doreclist(const char *dbname, int act, const char *key, const char *val, int sure){  const char *name;  int dbt, rnum, fsiz;  time_t mt;  if(!dbname || strlen(dbname) < 1){    htmlprintf("<p>The name of the database is not defined.</p>\n");    return;  }  if(strchr(dbname, '/')){    htmlprintf("<p>The name of the database includes invalid characters: `/'.</p>\n");    return;  }  name = getdbattrs(dbname, &dbt, &rnum, &fsiz, &mt);  switch(dbt){  case DBTDEPOT:    updatedepot(dbname, act, key, val);    break;  case DBTCURIA:    updatecuria(dbname, act, key, val);    break;  case DBTVILLA:    updatevilla(dbname, act, key, val);    break;  default:    htmlprintf("<p>The type of the database is invalid.</p>\n");    break;  }  name = getdbattrs(dbname, &dbt, &rnum, &fsiz, &mt);  htmlprintf("<table summary=\"attributes\">\n");  htmlprintf("<tr>\n");  htmlprintf("<th abbr=\"name\">Name</th>\n");  htmlprintf("<th abbr=\"dbt\">Type of Database</th>\n");  htmlprintf("<th abbr=\"fsiz\">Size</th>\n");  htmlprintf("<th abbr=\"rnum\">Records</th>\n");  htmlprintf("<th abbr=\"last\">Last Modified</th>\n");  htmlprintf("<th abbr=\"acts\">Actions</th>\n");  htmlprintf("</tr>\n");  htmlprintf("<tr>\n");  htmlprintf("<td class=\"str\"><em>%@</em></td>\n", name);  htmlprintf("<td class=\"str\">%s</td>\n", dbtstr(dbt));  htmlprintf("<td class=\"num\">%d</td>\n", fsiz);  htmlprintf("<td class=\"num\">%d</td>\n", rnum);  htmlprintf("<td class=\"str\">%s</td>\n", timestr(mt));  htmlprintf("<td class=\"str\">");  htmlprintf(" <a href=\"%s?act=%d&amp;dbname=%?&amp;sure=0\">[REMOVE]</a>",             scriptname, ACTDBREMOVE, dbname);  if(dbt != DBTCURIA){    htmlprintf(" <a href=\"%s?act=%d&amp;dbname=%?\">[D/L]</a>",               scriptname, ACTDBDOWN, dbname);  }  htmlprintf("</td>\n");  htmlprintf("</tr>\n");  htmlprintf("</table>\n");  htmlprintf("<hr />\n");  htmlprintf("<p>This form is used in order to update the database.</p>\n");  htmlprintf("<form action=\"%@\" method=\"post\">\n", scriptname);  htmlprintf("<table summary=\"update\">\n");  htmlprintf("<tr>\n");  htmlprintf("<th abbr=\"act\">Action:</th>\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -