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

📄 refere~1.c

📁 一百个病毒的源代码 包括熊猫烧香等 极其具有研究价值
💻 C
📖 第 1 页 / 共 4 页
字号:
// Copyright 1999 Jose M. Vidal// Jose M. Vidal, vidal@multiagent.com, http://jmvidal.ece.sc.edu//// This program is free software.  You can redistribute it and/or modify// it under the terms of the GNU General Public License//// $Id: reference.C,v 1.76 2000/12/15 23:45:57 jmvidal Exp $#ifdef HAVE_CONFIG_H#include <config.h>#endif#include "reference.H"//Table to convert mac chars to ISO-8859-1, starts at 128.//const int MACCHAR[128] = {  196, 197, 199, 201, 209, 214, 220, 225, 224, 226, 228, 227, 229,  231, 233, 232, 234, 235, 237, 236, 238, 239, 241, 243, 242, 244,  246, 245, 250, 249, 251, 252, 43, 176, 162, 163, 167, 183, 182, 223,  174, 169, 32, 180, 168, 32, 198, 216, 32, 177, 32, 32, 165, 181,  240, 83, 80, 112, 83, 170, 186, 79, 230, 248, 191, 161, 172, 32,  102, 126, 68, 171, 187, 32, 160, 192, 195, 213, 32, 32, 32, 32,  32, 32, 96, 39, 247, 183, 255, 255, 47, 164, 60, 62, 32, 32, 32,  183, 44, 32, 32, 194, 202, 193, 203, 200, 205, 206, 207, 204,  211, 212, 183, 210, 218, 219, 217, 105, 94, 126, 175, 94, 183, 176,  184, 32, 184, 94};/*string eliminateAccents(const string & s){  string c;  string::iterator ci = c.begin();  for (string::const_iterator i = s.begin(); i != s.end(); ++ i, ++ci){    char temp = *i;    if (temp > 128)      *ci = '_';    else *ci = *i;  };  return c;}*//** Returns a copy of s where all the accented and other weird characters    have been replaced with conterparts */string replaceAccents(const string & s){  string res = "";  for (string::const_iterator i = s.begin(); i != s.end(); ++ i){    char c = *i;    unsigned short ascval = (unsigned short)c & (unsigned short)255;    if ((ascval >= 32 ) && (ascval <= 255)){      //      cout << ascval << "-" << c << " =" << EQUIVCHAR[ascval-32] << "=" << endl;      res += EQUIVCHAR[ascval-32];    }    else{      res += c;      //      cout << "not in range=" << ascval << "-" << c << endl;    }  }  return res;}	//remove all HTML, that is, everything between < and >void removeHTML(string & s){  string::size_type start = 0;  string::size_type end = 0;  while ( (start = s.find("<")) != string::npos){    end = s.find(">", start);    s.replace(start, end-start + 1, "");   }}//from Stroustrup bookint cmpNoCase(const string& s, const string &s2){  string::const_iterator p = s.begin();  string::const_iterator p2 = s2.begin();    while (p != s.end() && p2 != s2.end()) {    if (toupper(*p) != toupper(*p2))      return (toupper(*p) < toupper(*p2)) ? -1 : 1;    ++p;    ++p2;  }  return (s2.size() == s.size()) ? 0 : (s.size() < s2.size()) ? -1 : 1;}//replace all instances of s1 with s2 on sint replaceAll(string & s, string s1, string s2){  int c = 0;  string::size_type f1 = 0;  while ((f1 = s.find(s1,f1)) != string::npos) {    c++;    s.replace(f1,s1.size(), s2);    f1 += s2.size();  }  return c;}/** escape all funny characters */string javaScriptEscape(const string & s){  string res = "";  for (unsigned int i = 0; i < s.size(); ++i){    if (s[i] == '\\'){      res += '\\';      res += '\\';    }    else if (s[i] == '\'') {      res += '\\';      res += '\'';    }    else if (s[i] == '\"') {      res += '\\';      res += '\'';    }    else if (s[i] == '\n') {      res += '\\';      res += 'n';    }    else if (s[i] == '\t') {      res += '\\';      res += 't';    }    else if (s[i] == '\r') {      res += '\\';      res += 'n';    }    else      res += s[i];  }  return res;}// get the monthstring getMonth(int m){  switch (m) {  case 1: return "January"; break;  case 2: return "February"; break;  case 3: return "March"; break;  case 4: return "April"; break;  case 5: return "May"; break;  case 6: return "June"; break;  case 7: return "July"; break;  case 8: return "August"; break;  case 9: return "September"; break;  case 10: return "October"; break;  case 11: return "November"; break;  case 12: return "December"; break;  };  return "Bad Month";}string::size_type findNC(const string & source,                          const string & search,                          const string::size_type startPos){  string::size_type ssize = search.size();  if (ssize > source.size())    return string::npos; //because size_type cannot handle negatives!!  for (string::size_type i = startPos; i <= source.size() - ssize; i++){    string tu = source.substr(i, ssize);    if (cmpNoCase(tu, search) == 0)      return i;  }  return string::npos;  }//replace all instances of s1 with s2 on sint replaceAllNC(string & s, string s1, string s2){  int c = 0;  string::size_type f1 = 0;  while ((f1 = findNC(s,s1,f1)) != string::npos) {    c++;    s.replace(f1,s1.size(), s2);    f1 += s2.size();  }  return c;}string getArgumentValue(const string & str, const string & argument){  int l=0, r=0;  l = str.find(argument + "=");  if (l>=0) {    l = str.find("\"", l);    l++;    r = str.find("\"", l);    string t = str.substr(l,r-l);    replaceAll(t, "\n", "");    return t;  }  return string("");}string name2filename(string const & n){  string s = n;  string::size_type p = 0;  while ((p = s.find(" ")) != string::npos){    s.replace(p++,1,"_");  }  p = 0;  while ((p = s.find("/")) != string::npos){    s.replace(p++,1,"-");  }  p = 0;  while ((p = s.find("\"")) != string::npos){    s.replace(p++,1,"-");   }  // Escape 8bit characters.  string res = "";  char hexbuf[4];  for (unsigned int i = 0; i < s.size(); ++i){    if (s[i] & 0x80) {      ostrstream hexstr(hexbuf, 4);      hexstr << 'x' << setw(2) << setfill('0') << hex << (int)(s[i] & 0xff);      res += hexbuf[0];      res += hexbuf[1];      res += hexbuf[2];    }    else      res += s[i];  }  return res;}//make a string usable as urlstring name2url(string const & n){  string s = name2filename(n);  replaceAll(s, "?", "%3F");  return s;}//RETURN a string that is like s but without any leading or//  trailing whitespace.// We also get rid of any \nstring trim(const string & s) {  int l = s.length();  int left =0, right =l-1;  for (; left <= right; left++)     if (!(isspace(s[left]))) break;  for (; right >= left; right--)    if (!(isspace(s[right]))) break;  string t(s.substr(left, right+1-left));  replaceAll(t, "\n", "");  return t;}string myItoa (int n){  string         ret;  strstream      tmp;  tmp << n << ends;  ret = tmp.str ();  tmp.rdbuf()->freeze(0);  return ret;}/** Our time zone*/extern char *tzname[2];string padWithZero(string s){  if (s.length() == 1)    return "0" + s;  return s;}/** Returns the date and time (down to seconds) in ISO 8601 format as described by    http://www.w3.org/TR/NOTE-datetime-970915.html */string getISOTime (time_t li){  struct tm * t = localtime(&li);  int year = 1900 + t->tm_year;  string res = myItoa(year) + "-" + padWithZero(myItoa(t->tm_mon)) + "-" + padWithZero(myItoa(t->tm_mday)) +    "T" + padWithZero(myItoa(t->tm_hour)) + ":" + padWithZero(myItoa(t->tm_min)) + ":" + padWithZero(myItoa(t->tm_sec)) +    "+05:00";  return res;}//Autofill the comment, add \n's so that no line// is bigger than n characters, break only at spaces.//void autoFill(string & s, int n = 72){  int p = 0;  int last = 0;  bool set = false;  replaceAll(s, "\n", " ");  replaceAll(s, "\t", " ");  replaceAll(s, "\r", " ");  s = "    " + s; //indent parragraph  for (unsigned int i=0; i < s.size(); i++, p++){    if ((p >= n) && set) {      s[last] = '\n';      p = 0;      set = false;    };    if (s[i] == ' '){      last = i;      set = true;    };  }  //  cout << "O:" << s << endl;}reference::reference(const reference &r) : url(r.url), title(r.title), dirname(r.dirname),   comment(r.comment), creationTime(r.creationTime),   modifiedTime(r.modifiedTime), visitTime(r.visitTime), aliasDir(r.aliasDir),  aliasID(r.aliasID), aliasOf(r.aliasOf), children(0), priv(r.priv),  aliasof(r.aliasof), navBar(r.navBar), folder(r.folder), hits(r.hits){  if (r.children)    children = new referenceTree(*(r.children));  else    children = 0;}reference & reference::operator=(const reference & r){  url = r.url;  title = r.title;  dirname = r.dirname;  comment = r.comment;  creationTime = r.creationTime;  modifiedTime = r.modifiedTime;  visitTime = r.modifiedTime;  aliasDir = r.aliasDir;  aliasID = r.aliasID;  aliasOf = r.aliasOf;  priv = r.priv;  aliasof = r.aliasof;  navBar = r.navBar;  folder = r.folder;  hits = r.hits;  delete children;  if (r.children)    children = new referenceTree(*(r.children));  else    children = 0;  return *this;}// a < b iff a was created more recently than bint reference::operator<(const reference & r) const{  return creationTime > r.creationTime;}reference::~reference() {   if (!isAliasof())    delete children; }//given an HTML <H?></H?> or <A></A> it extracts the appropiate values and //  sets the reference to these values.//REQUIRES that value be a properly formed <H> or <A>void reference::setValues (const string & str){  int l, r;  //  cout << "setValues children=" << children << endl;  if (str[1] == 'H') { //folder    string addDateValue;    addDateValue = getArgumentValue(str, addDate);    creationTime = atoi(addDateValue.c_str());    l = str.find(">");    r = str.find("<",l);    title = str.substr(l+1, r-l-1);    return;  }  else if (str[1] == 'A') { //leaf (URL)    url = getArgumentValue(str, href);    aliasID = getArgumentValue(str, ALIASID);    aliasOf = getArgumentValue(str, ALIASOF);    if (aliasOf != "")      aliasof = true;    string addDateValue, lastModifiedValue, lastVisistValue;    addDateValue = getArgumentValue(str, addDate);    creationTime = atoi(addDateValue.c_str());    lastModifiedValue = getArgumentValue(str, lastModified);    modifiedTime = atoi(lastModifiedValue.c_str());    lastVisistValue = getArgumentValue(str, lastVisit);    visitTime = atoi(lastVisistValue.c_str());    l = str.find(">");    r = str.find("<",l);    title = str.substr(l+1, r-l-1);    return;  }}int reference::search(const string & s)  // returns the number of times s appears in   //    title and comment  // also adds <B> </B> around matches{  int c = 0;;  c += replaceAllNC(title, s, "<B>" + s + "</B>");  c += replaceAllNC(comment, s, "<B>" + s + "</B>");  return c;}bool reference::isPrivate() const{  return priv;}bool reference::isAliasof() const{  return aliasof;}bool reference::isFolder() const{  return folder;}// return length of first sentence until first occurance of p.// skip one letter abbreviations like in names, for example "O. Obst"string::size_type reference::fullstop(const string &s, const string &p) const {  string::size_type i, end;  i = 0;  end = 0;  string t;    while (end == 0) {    t = s.substr(i,s.length());    end = t.find(p); // search for an occurance of p    if (end != string::npos) {      i = i + end + 1;      if (end <= 1 ||          t[end - 2] == '.' ||          t[end - 2] == '!' ||          t[end - 2] == '?' ||          t[end - 2] == ' ' ||          t[end - 2] == '\t' ||          t[end - 2] == '\r' ||          t[end - 2] == '\n')         end = 0;    }    else i = s.length();  }  return i;}//this is not used anymore (except for debugging)void reference::sendAsHTML(ostream & out){  string t = title;  if (isFolder()){    out << navBar << " <A HREF=\"" << "../" << url << "\">"         << t << "</A><BR>" << endl;  }  else{    //    out << navBar << "<BR>" << endl    out << "<A HREF=\"" << url << "\">" << t << "</A>";    if (comment != "")      out << " - " << comment;    out << endl;  }}/**Format the reference in html and return it. Make sure all the %VARS are replaced by their values. templ is is template. */string reference::sendAsHTML(const string & templ,                              const string varValues []) const{  string outputString = templ;  time_t currentTime = time(0); //.tv_sec;  static int timeCutoff = atoi(varValues[TIMECUTOFF].c_str()) * 60 * 60 * 24;

⌨️ 快捷键说明

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