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

📄 html.c

📁 将HTML转换为TXT文件的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ------------------------------------------------------------------------- *//* * Copyright (c) 1999 *      GMRS Software GmbH, Innsbrucker Ring 159, 81669 Munich, Germany. *      http://www.gmrs.de *      All rights reserved. *      Author: Arno Unkrig (arno.unkrig@gmrs.de) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *      This product includes software developed by GMRS Software GmbH. * 4. The name of GMRS Software GmbH may not be used to endorse or promote *    products derived from this software without specific prior written *    permission. * * THIS SOFTWARE IS PROVIDED BY GMRS SOFTWARE GMBH ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GMRS SOFTWARE GMBH BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. *//* ------------------------------------------------------------------------- */#ident "$Id: html.C,v 1.10 1999/10/27 12:14:16 arno Exp $"#include <stdlib.h>#include <stdarg.h>#include <iostream.h>#include "html.h"#include "HTMLParser.h"#include "cmp_nocase.h"/* ------------------------------------------------------------------------- *//* * Define some helpers. */#define define_foreach(T, args, action) \void foreach args { \  for (T::const_iterator i = l.begin(); i != l.end(); ++i) { \    action; \  } \}#define pack(T) \define_foreach(list<auto_ptr<T> >, ( \  const list<auto_ptr<T> > &l, \  ostream                  &os, \  ostream_manipulator      separator \), (*i)->unparse(os, separator))static pack(Element)static pack(TableCell)static pack(TableRow)static pack(ListItem)static pack(Option)static pack(DefinitionListItem)static pack(Script)static pack(Style)#undef pack/* * Special helper for "const auto_ptr<list<TagAttribute> > &". */static ostream &operator<<(ostream &os, const auto_ptr<list<TagAttribute> > &a){  if (a.get()) {    const list<TagAttribute> &al(*a);    list<TagAttribute>::const_iterator i;    for (i = al.begin(); i != al.end(); ++i) {      os << " " << (*i).first << "=\"" << (*i).second << "\"";    }  }  return os;}/* ------------------------------------------------------------------------- *//* * Brothers of "endl". */static ostream &none(ostream &os) { return os; }/* ------------------------------------------------------------------------- *//* * Some C++ compilers (e.g. EGCS 2.91.66) have problems if all virtual * methods of a class are inline or pure virtual, so we define the virtual * "Element::~Element()", which is the only virtual method, non-inline, * although it is empty. */Element::~Element(){}/* ------------------------------------------------------------------------- */voidDocument::unparse(ostream &os, ostream_manipulator separator) const{  os << "<HTML" << attributes << ">" << separator;  head.unparse(os, separator);  body.unparse(os, separator);  os << "</HTML>" << separator;}voidHead::unparse(ostream &os, ostream_manipulator separator) const{  os << "<HEAD>" << separator;  if (title.get()) {    os << "<TITLE>" << separator;    title->unparse(os, separator);    os << "</TITLE>" << separator;  }  if (isindex_attributes.get()) {    os << "<ISINDEX"<< isindex_attributes << ">" << endl;  }  if (base_attributes.get()) os << "<BASE" << base_attributes << ">" << endl;  foreach(scripts, os, separator);  foreach(styles, os, separator);  if (meta_attributes.get()) os << "<META" << meta_attributes << ">" << endl;  if (link_attributes.get()) os << "<LINK" << link_attributes << ">" << endl;  os << "</HEAD>" << separator;}voidScript::unparse(ostream &os, ostream_manipulator separator) const{  os    << "<SCRIPT" << attributes << ">" << separator    << text    << "</SCRIPT>" << separator;}voidStyle::unparse(ostream &os, ostream_manipulator separator) const{  os    << "<STYLE" << attributes << ">" << separator    << text    << "</STYLE>" << separator;}voidBody::unparse(ostream &os, ostream_manipulator separator) const{  os << "<BODY" << attributes << ">" << separator;  if (content.get()) foreach(*content, os, separator);  os << "</BODY>" << separator;}voidPCData::unparse(ostream &os, ostream_manipulator separator) const{  for (string::size_type j = 0; j < text.length(); ++j) {    char c = text[j];    switch (((int) c) & 255) {    case LATIN1_nbsp: os << "&nbsp;"; break;    case '&':         os << "&amp;";  break;    case '<':         os << "&lt;";   break;    case '>':         os << "&gt;";   break;    case '"':         os << "&quot;"; break;    default:      if (c & 0x80) {        os << "&#" << (((int) c) & 255) << ";";      } else {        os << c;      }      break;    }  }  os << separator;}voidHeading::unparse(ostream &os, ostream_manipulator separator) const{  os << "<H" << level << attributes << ">" << separator;  if (content.get()) foreach(*content, os, separator);  os << "</H" << level << ">" << separator;}voidParagraph::unparse(ostream &os, ostream_manipulator separator) const{  os << "<P" << attributes << ">" << separator;  if (texts.get()) foreach(*texts, os, separator);  os << "</P>" << separator;}voidImage::unparse(ostream &os, ostream_manipulator separator) const{  os << "<IMG" << attributes << ">" << separator;}voidApplet::unparse(ostream &os, ostream_manipulator separator) const{  os << "<APPLET" << attributes << ">" << separator;  if (content.get()) foreach(*content, os, separator);  os << "</APPLET>" << separator;}voidParam::unparse(ostream &os, ostream_manipulator separator) const{  os << "<PARAM" << attributes << ">" << separator;}voidDivision::unparse(ostream &os, ostream_manipulator separator) const{  os << "<DIV" << attributes << ">" << separator;  if (body_content.get()) foreach(*body_content, os, separator);  os << "</DIV>" << separator;}voidCenter::unparse(ostream &os, ostream_manipulator separator) const{  os << "<CENTER>" << separator;  if (body_content.get()) foreach(*body_content, os, separator);  os << "</CENTER>" << separator;}voidBlockQuote::unparse(ostream &os, ostream_manipulator separator) const{  os << "<BLOCKQUOTE>" << separator;  if (content.get()) foreach(*content, os, separator);  os << "</BLOCKQUOTE>" << separator;}voidAddress::unparse(ostream &os, ostream_manipulator separator) const{  os << "<ADDRESS>" << separator;  if (content.get()) foreach(*content, os, separator);  os << "</ADDRESS>" << separator;}voidForm::unparse(ostream &os, ostream_manipulator separator) const{  os << "<FORM" << attributes << ">" << separator;  if (content.get()) foreach(*content, os, separator);  os << "</FORM>" << separator;}voidPreformatted::unparse(ostream &os, ostream_manipulator separator) const{  os << "<PRE" << attributes << ">" << separator;  if (texts.get()) { foreach(*texts, os, none); os << separator; }  os << "</PRE>" << separator;}voidHorizontalRule::unparse(ostream &os, ostream_manipulator separator) const{  os << "<HR" << attributes << ">" << separator;}voidInput::unparse(ostream &os, ostream_manipulator separator) const{  os << "<INPUT" << attributes << ">" << separator;}voidOption::unparse(ostream &os, ostream_manipulator separator) const{  os << "<OPTION" << attributes << ">" << separator;  if (pcdata.get()) pcdata->unparse(os, separator);  os << "</OPTION>" << endl;}voidSelect::unparse(ostream &os, ostream_manipulator separator) const{  os << "<SELECT" << attributes << ">" << separator;  if (content.get()) foreach(*content, os, separator);  os << "</SELECT>" << endl;}voidTextArea::unparse(ostream &os, ostream_manipulator separator) const{  os << "<TEXTAREA" << attributes << ">" << separator;  if (pcdata.get()) pcdata->unparse(os, separator);  os << "</TEXTAREA>" << endl;}/* ------------------------------------------------------------------------- */

⌨️ 快捷键说明

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