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

📄 bk2site.c

📁 一百个病毒的源代码 包括熊猫烧香等 极其具有研究价值
💻 C
📖 第 1 页 / 共 2 页
字号:
// bk2site by Jose M. Vidal// http://jmvidal.ece.sc.edu  vidal@sc.edu//// Converts the Netscape bookmark.html file into a yahoo-like// web site.//// 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//// CONTRIBUTORS://  See the AUTHORS file////// $Id: bk2site.C,v 1.49 2000/12/15 23:52:56 jmvidal Exp $// -*- mode:C++; tab-width:4; c-basic-offset:2; indent-tabs-mode:nil -*- //TO DO:// - Escape accented charactes in name2filename (name2url)// - Add ALIASID= and ALIASOF= options to directory comments, so as//   to allow more flexible directory aliasing.// - Add support for separators <HR>// - urllog should have "time url IP" and bk2site should count only one hit///   per IP.//// BUGS// - Make search.pl ignore html marking....how????#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <iostream>#include <fstream>#include <iomanip>#include <cstdlib>#include <string>// #if TIME_WITH_SYS_TIME// # include <sys/time.h>// # include <time.h>// #else// # if HAVE_SYS_TIME_H// #  include <sys/time.h>// # else// #  include <time.h>// # endif// #endif #include <ctime>#include "channel.H" //this include must appear before #include "reference.H"#include "reference.H"//defined in reference.Cextern string trim(const string & s);extern int cmpNoCase(const string& s, const string &s2);extern int replaceAllNC(string & s, string s1, string s2);extern int replaceAll(string & s, string s1, string s2);const string version = VERSION;using namespace std;void printUsage(const string & s){  cout << "Usage: " << s << ": [OPTIONS] [main-bookmark-file] [bookmarkfile]*" << endl        << "\t If main-bookmark-file is omitted we use ~/.netscape/bookmarks.html" << endl       << "\t Any extra bookmark files given are merged with main, see the README" << endl << endl;  cout << "Builds a yahoo-like website based on one or more Navigator bookmark files" << endl << endl       << "-nd\t\t - don't use a subdirectory hierachy. Use ugly long filenames" << endl       << "\t\t  it's useful for tree depth limited providers like geocities" << endl    //	 << "-bf <book file>\t - File with bookmarks (~/.netscape/bookmarks.html)" << endl       << "-f <config file> - Name of configuration file (~/.bk2siterc)" << endl       << "-d <dest dir>\t - Local directory for generated files." << endl       << "\t\t   Default is /home/httpd/html/" << endl       << "-t <name>\t - Name of top-level bookmark folder to use." << endl       << "\t\t   If ommited will convert whole bookmark file." << endl       << "-f1 <file>\t - Index template file for top index. " << endl       << "-f2 <file>\t - Template for the other pages. " << endl        << "-o <file>\t - Output bookmark file." << endl			 << "-xbel <file>\t - Output an xbel file." << endl        << "-ns\t\t - Do NOT generate the website. " << endl        << "-nc\t\t - Do NOT put HTML comments in the output." << endl       << "-old <int>\t - Number of days (30) after which a bookmark is no longer new." << endl << endl       << "Version " << version << endl << endl;  exit(1);}void readConfigStream(istream & configStream, string varValues[],											vector<string> & extraFileBase, vector<string> & extraFileName,											channelContainer & channels){	string curVarName;	string curVarValue;	string channelName ="";	string channelUrl;	string channelFile;	while (configStream >> curVarName) {		getline(configStream, curVarValue);		curVarValue = trim(curVarValue);		if (curVarName[0] == '#') continue;		if (curVarValue[0] == '"') //get rid of surrounding "'s	    curVarValue.erase(0,1);		if (curVarValue[curVarValue.size() -1] == '"')	    curVarValue.erase(curVarValue.size() - 1,1);		if (getenv("HOME") != NULL)			replaceAll(curVarValue,"$HOME", getenv("HOME"));		else			replaceAll(curVarValue,"$HOME", "");		if (getenv("USER") != NULL)			replaceAll(curVarValue,"$USER", getenv("USER"));		else			replaceAll(curVarValue,"$USER", "");		if (getenv("LOGNAME") != NULL)			replaceAll(curVarValue,"$LOGNAME", getenv("LOGNAME"));		else			replaceAll(curVarValue,"$LOGNAME", "");		int i, found = 0;		for (i = 0; i < NUMVARS; i++){	    if (cmpNoCase(varNames[i],curVarName) == 0){				varValues[i] = curVarValue;				//	cout << varNames[i] << ":" << varValues[i] << endl;				found = 1;				break;	    }		};		//these two are special, since they can appear many times.		if (cmpNoCase("EXTRAFILEBASE",curVarName) == 0){			extraFileBase.push_back(curVarValue);			found = 1;		}		else if (cmpNoCase("EXTRAFILENAME",curVarName) == 0){			extraFileName.push_back(curVarValue);			found = 1;		};		//these can also appear many times		if (cmpNoCase("CHANNELNAME",curVarName) == 0){			if (channelName != ""){ //push back old one				channels.addNewChannel(channelName, channelUrl, channelFile);			}			else				channelName = curVarValue;			found = 1;		}		else if (cmpNoCase("CHANNELURL",curVarName) == 0){			channelUrl = curVarValue;			found = 1;		}		else if (cmpNoCase("CHANNELFILE",curVarName) == 0){			channelFile = curVarValue;			channels.addNewChannel(channelName, channelUrl, channelFile);			channelName = channelFile = channelUrl = "";			found = 1;		};		if (found == 0)	    cerr << "ERROR: variable " << curVarName << " is not a recognized name." << endl;	}	if (extraFileName.size() != extraFileBase.size()){		cerr << "ERROR: the number of extrafilename declarations is not the same as the " << endl				 << "       number of extrafilebase declarations. Exiting." << endl;		exit(1);	}}int main (int argc, char **argv){	//initiallize default values.	string varValues[NUMVARS];	varValues[NEWGIF] = "<img src=\"/icons/new.gif\" alt=\"Added %MONTHCRE1/%DAYCRE/%YEARCRE\">";	varValues[DESTDIR] = "";	varValues[TOPFOLDER] = ""; 	varValues[BOOKMARKFILE] = "bookmarks.html";	varValues[INDEXFILENAME] = "indexbase.html";	varValues[OTHERFILENAME] = "otherbase.html";	varValues[TIMECUTOFF] = "30";	varValues[TOP] = "Top";	varValues[INDEX] = "index.html";	varValues[SEARCH] = "";	varValues[SEARCHTOROOTPATH] = "../";	varValues[URLLOGFILE] = "";	varValues[SUBDIRSEP] = "/";	varValues[BACKDIRSEP] ="../";	varValues[SEARCHURLTEMPLATE] = "<A HREF=\"%URL\">%TITLE</A> %NEW %CONDDASH %COMMENT";	varValues[NEWSTOPFOLDER] = "";	varValues[TITLE] = "My Bookmarks";	varValues[OUTPUTBOOKMARKFILE] = "";	varValues[COMMENTS] = "yes";	varValues[FOLDERCREATION] = "maxdescendants";	varValues[TOPHITSINCLUDENEWS] = "no";	string xbelFileName = "";	string homeDir = getenv("HOME");	vector<string> extraFileBase;	vector<string> extraFileName;	vector<string> bookmarkfiles;	int numBookmarkfiles = 0;	int generateSite = 1;    //read /etc/bk2site/dot.bk2siterc    //    string globalConfigFile("CONFIGFILE");    //    cout << "Checking " << "CONFIGFILE" << endl; //the -D on the compiler does not work. (egcs?)	string globalConfigFile(CONFIGFILE);	// cout << "Checking " << CONFIGFILE << endl;	//the -D on the compiler does not work. (egcs?)	// string globalConfigFile("/etc/bk2site/dot.bk2siterc");	//string globalConfigFile("/etc/bk2site/dot.bk2siterc");	ifstream globalConfigStream(globalConfigFile.c_str(), ios::in);	channelContainer channels;	if (globalConfigStream) 		readConfigStream(globalConfigStream, varValues, extraFileBase, extraFileName, channels);	int readHomeConfig = 1;	for (int i = 1; i < argc; i++){		string s(argv[i]);		if (s == "-f")			readHomeConfig = 0;	}	//read ~/.bk2siterc	string configFile = homeDir + "/.bk2siterc";	if (readHomeConfig == 1) {		cout << "Reading " << configFile << endl;		ifstream configStream(configFile.c_str(), ios::in);		if (configStream) 			readConfigStream(configStream, varValues, extraFileBase, extraFileName, channels);	};	//read the file  in -f	for (int i = 1; i < argc; i++){		string s(argv[i]);		if (s == "-f")	    if (++i < argc){				configFile = argv[i];				cout << "Reading " << configFile << endl;				ifstream configStream2(configFile.c_str(), ios::in);				if (configStream2)					readConfigStream(configStream2, varValues, extraFileBase, extraFileName, channels);				else {

⌨️ 快捷键说明

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