asp inlcude 文件

'last update: 2008/6/12
 
'1/分别解析include的file和virtual属性
 
'2/删除运行在服务器端的object和script标签
 
'3/取消了ASPEncode对资源的消耗,直接用Mid来截取html字符串,并用Execute统一执行
 
 
 
'get file string data
 
Public Function GetFileString(ByVal strPath, ByVal strCharset)
 
    Dim objFile
 
    Set objFile = Server.CreateObject("ADODB.Stream")
 
    objFile.Type = 2'adTypeText
 
    objFile.Charset = strCharset
 
    objFile.Open
 
    objFile.LoadFromFile strPath
 
    GetFileString = objFile.ReadText(-1)
 
    objFile.Close
 
    Set objFile = Nothing
 
End Function
 
 
 
Public Sub ASPInclude(ByVal strPath, ByVal strCharset)
 
    Dim strData
 
    Dim reg, arr, ptr, pos
 
    Dim tmp, ret, i
 
    strData = GetFileString(Server.MapPath(strPath), strCharset)
 
    Set reg = New RegExp
 
    reg.Global = True
 
    reg.IgnoreCase = True
 
    'parse include file
 
    reg.Pattern = "<!--#include/s+file=""([^""]+)""-->"
 
    strData = reg.Replace(strData, "<" & "%ASPInclude """ & ASPPath(strPath) & "$1"", """ & strCharset & """%" & ">")
 
    'parse include virtual
 
    reg.Pattern = "<!--#include/s+virtual=""([^""]+)""-->"
 
    strData = reg.Replace(strData, "<" & "%ASPInclude ""$1"", """ & strCharset & """%" & ">")
 
    'clear object or script tag that runat server
 
    reg.Pattern = "<(object|script)/s[^>]*?runat=""server""[^>]*>[/s/S]*?<//1>"
 
    strData = reg.replace(strData, "")
 
    'parse asp tag
 
    reg.Pattern = "<" & "%([/s/S]*?)%" & ">"
 
    Set arr = reg.Execute(strData)
 
    If arr.Count > 0 Then
 
        ReDim tmp(arr.Count * 2)
 
        pos = 1
 
        i = 0
 
        For Each ptr In arr
 
            If ptr.FirstIndex + 1 - pos > 0 Then
 
                tmp(i) = "Response.Write Mid(strData, " & pos & ", " & ptr.FirstIndex + 1 - pos & ")"
 
                i = i + 1
 
            End If
 
            pos = ptr.FirstIndex + 1 + ptr.Length
 
            If Left(ptr.SubMatches(0), 1) = "=" Then'</%=*%/>
 
                tmp(i) = "Response.Write " & Mid(ptr.SubMatches(0), 2)
 
            Else
 
                tmp(i) = ptr.SubMatches(0)
 
            End If
 
            i = i + 1
 
        Next
 
        tmp(i) = "Response.Write Mid(strData, " & pos & ")"
 
        ReDim Preserve tmp(i)
 
        ret = Join(tmp, vbCrLf)
 
    Else
 
        ret = "Response.Write strData"
 
    End If
 
    'Response.Write "<h4>Debug</h4>"
 
    'Response.Write "<textarea cols=""90"" rows=""10"">" & Server.HTMLEncode(ret) & "</textarea>"
 
    Execute ret
 
    Set arr = Nothing
 
    Set reg = Nothing
 
End Sub
 
 
 
'Translate Current Path
 
Private Function ASPPath(ByVal strPath)
 
    Dim ret, tmp, pos
 
    tmp = Replace(strPath, "/", "/")
 
    pos = InStrRev(tmp, "/")
 
    If pos > 0 Then
 
        ret = Mid(tmp, 1, pos)
 
    End If
 
    ASPPath = ret
 
End Function
 
 
 
'Usage
 
ASPInclude "test/test.asp", "GBK"

 

#inlcude 问题

09-16

[code=c]//node.hrntemplate class SingList; //声明一个单链表类;rntemplate class node //定义一个节点类,(注意此语句后面没有分号)rnrn private:rn friend class SingList //声明SingList类为node类的友元类,SingList可以访问node的私有成员;rn T m_data; //node类的数据成员;rn node* m_pnext; //m_pnext是指向下一节点的指针;rn node():m_pnext(NULL); //构造函数初始化列表。rn node(const T item,node* next=0):m_data(item),m_pnext(next);//此函数时node的重载函数,也是构造函数。相当于:rn /*node(const T item,node* next=0)rn rn m_data=item;rn m_pnext=next;rn */rn public:rn T GetData();rn;rntemplate T node::GetData() //前面template 类的模板,后面的T是函数类型名,在后面的node是一个整体,表示带参数的类。rnrn return this->m_data;rnrn[/code]rnrn[code=c]//SingleList.hrn#include "node.h" //注意此句后面不要加分号;rntemplate rnclass SingleListrnrn private:rn node* phead; //头结点;rn public: //单链表的各种方法;rn void MakeEmpty(void);rn int Length();rn int Insert(T item,int i=0);rn T Remove(int i=0);rn T Get(int i);rn node* Find(T item); //找出元素为item的节点,返回的是这个节点的指针(地址)rn void print(void);rn public: //构造函数和析构函数rn SingleList():phead(new node()); //相当于phead=new node();动态申请一个节点,L=new SqList;这是动态申请一个顺序表;注意区别rn ~SingleList() //析构函数的特点就是清楚内存的数据rn rn MakeEmpty();rn delete phead;rn rn;rn//清空单链表rntemplate void SingleList::MakeEmpty() rnrn node* pdel=phead->m_pnext; //定义一个移动节点,开始指向头结点的下一个;rn while(pdel->m_pnext!=NULL)rn phead->n_pnext=pdel->m_pnext;rn delete pdel; //删除除头结点外的最后一个节点;rnrnrn//计算链表的长度rntemplate int SingleList::Length() //头结点算不算链表的一个元素?rnrn node* pmove=phead->m_pnext;//定义一个移动节点,开始指向头结点rn int n=0;rn while(pmove!=NULL)rn rn pmove++;rn n++;rn rn return n;rnrn//在第i个位置上插入元素itemrntemplate int SingleList::Insert(T item,int i)rn rn if(i<0) //注意插入的时候要判空。rn cout<<"illegal operate"<* pmove=phead;rn node* pnode=new node(item); //这个语句要记住,申请一个元素为item的节点pnode;rn for(j=0;jm_pnext=pmove->m_pnext;rn pmove->m_pnext=pnode;rn return 1;rnrn//删除第i个元素的节点,并且返回被删除的元素,使用两个临时指针,用于移动与删除rntemplate T SingleList::Remove(int i)rn node* pmove=phead; rn node* pdel; //要删除的元素;rn for(j=0;jm_pnext=pdel; //没有错吧?rn pmove->m_pnext=pdel->m_pnext;rn T temp=pdel->m_data; //把要删除的元素取出;rn delete pdel;rn return temp;rnrn//获取第一个元素rntemplate T SingleList::Get(int i)rn node* pmove=phead; rn node* pnode;rn if(i<0) //注意判断要取的位置是不是符合要求rn cout<<"illegal operate"<m_pnext=pnode;rn T temp=pnode->m_data;rn return temp;rnrn//找元素为item 的节点,返回这个节点rntemplate node* SingleList:: Find(T item)rnrn node* pmove=phead; rn for(j=0;j::Length();j++) //注意for循环里的语句rn if(pmove->m_data==item)rn rn cout<<"found"< void SingleList::print(void)rnrn cout<<"head";rn node* pnode=phead->m_pnext;rn while(pnode)rn cout<<"-->"<m_pdata;pnode++;rn cout<<"-->NULL"< //词句什么意思?rn#include "SingleList.h"rn#include rnusing namespace std;rnint main()rnrn SingleList list; //声明一个对象;rn for(int n=0;n<10;n++)rn list.Insert(3*n,n);rn list.Find(3);rn list.Get(5);rn list.Length();rn list.Remove();rn list.print();rn return 0;rnrnrnrn[/code]rn我新建了一个工程,把上面的三个文件放到工程里面去了,编译main.cpp时,没有问题,但就是不能运行。这是为何?注:工程里有StdAfx.h和StdAfx.cpp.这是这么回事? 论坛

没有更多推荐了,返回首页