配色与Devc++ 的classic plus 相同

输入文件名即可,输出在out.htm中

#include<bits/stdc++.h>
#include<windows.h>
#define chek(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
#define col(co) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),co)
#define br BACKGROUND_RED
#define bg BACKGROUND_GREEN
#define bb BACKGROUND_BLUE
#define bi BACKGROUND_INTENSITY
#define fr FOREGROUND_RED
#define fg FOREGROUND_GREEN
#define fb FOREGROUND_BLUE
#define fi FOREGROUND_INTENSITY
using namespace std;
char hl[][]={"asm","do","if","return","typedef","auto","double",
"inline","short","typeid","bool","dynamic_cast","int",
"signed","typename","break","else","long","sizeof",
"union","case","enum","mutable","static","unsigned",
"catch","explicit","namespace","static_cast","using",
"char","export","new","struct","virtual","class",
"extern","operator","switch","void","const","false",
"private","template","volatile","const_cast","float",
"protected","this","wchar_t","continue","for","public",
"throw","while","default","friend","register","true",
"delete","goto","reinterpret_cast","try","in"};
int l=;
/*
theme:
0:Highlight Word
1:Normal Word
2:Definding Word
3:char,string Word
4:Numbers
5:Symbols
6:Notes
*/
int themePAS[]={bb+fr+fg+fb+fi,
bb+fg+fr+fi,
bb+fg+fi,
bb+fg+fb+fi,
bb+fg+fb+fi,
bb+fr+fi,bb+fi};
void init()
{
freopen("cppword.hl","r",stdin);
char c[];
while (cin>>c)
{
l++;
for (int i=;i<;i++)
hl[l][i]=c[i];
}
freopen("CON","r",stdin);
return;
}
int check(char p[],int pl)
{
int tt=;
/* for (int i=0;i<pl;i++)
{
if (!isdigit(p[i]))
{
tt=1;
break;
}
}
if (!tt) return 2;*/
for (int i=;i<=l;i++)
{
bool tmp=;
int q=strlen(hl[i]);
if (q!=pl) continue;
for (int j=;j<pl;j++)
if (hl[i][j]!=p[j])
{
tmp=;
break;
}
if (!tmp) return ;
}
return ;
}
int main()
{
system("color 1F");
char k[];
cout << "请输入文件名:";
cin>>k;
// init();
freopen(k,"r",stdin);
freopen("out.htm","w",stdout);
cout << "<div style=\"background-color:white;font-family:courier\">";
char c;
char g[],gl=;
while (scanf("%c",&c)!=EOF)
{
//system("pause");
if (((c>='A'&&c<='Z')||(c>='a'&&c<='z')||c=='_')||(c<=''&&c>=''&&gl!=))
{
g[gl]=c;
gl++;
}
else
{
if (c<=''&&c>=''&&gl==)
//////////////////////////////////////////////////////////////////////////////////Numbers
{
cout << "<font color=\"purple\">";
col(themePAS[]); cout << c;
cout << "</font>" ;
continue;
}
if (gl!=)
{
//////////////////////////////////////////////////////////////////////////////////Highlight
if (check(g,gl)==)
{
cout << "<strong><font color=\"black\">";
// col(themePAS[0]);
for(int i=;i<gl;i++)
{
cout<<g[i];
}
cout << "</font></strong>" ;
}
else
//////////////////////////////////////////////////////////////////////////////////Normal words
{
cout << "<font color=\"black\">";
col(themePAS[]);
for(int i=;i<gl;i++)
{
cout<<g[i];
}
cout << "</font>" ;
}
}
if (c=='#')
//////////////////////////////////////////////////////////////////////////////////Defining
{
cout << "<font color=\"green\">";
col(themePAS[]);
cout << c;
while ()
{
scanf("%c",&c);
if (c=='\n') break;
else if (c=='<') cout << "&lt;";
else if (c==' ') cout << "&nbsp;";
else if (c=='\t') cout << "&nbsp;&nbsp;&nbsp;&nbsp;";
else cout<<c;
}
cout << "</font> <br>";
}
else if (c=='\'')
//////////////////////////////////////////////////////////////////////////////////char
{
cout << "<font color=\"black\">";
col(themePAS[]);
cout << c;
while()
{
scanf("%c",&c);
if (c=='\'')
{
cout<<c;
break;
}
else if (c=='<') cout << "&lt;";
else
if (c=='\\')
{
cout << c;
scanf("%c",&c);
cout << c;
}
else cout<<c;
}
cout << "</font>" ;
}
else if (c=='\"')
//////////////////////////////////////////////////////////////////////////////////String
{
cout << "<strong><font color=\"blue\">";
col(themePAS[]);
cout << c;
while()
{
scanf("%c",&c);
if (c=='\"')
{
cout<<c;
break;
}
else if (c=='<') cout << "&lt;";
else
if (c=='\\')
{
cout << c;
scanf("%c",&c);
cout << c;
}
else cout<<c;
}
cout << "</font></strong>" ;
}
else if (c=='\n')
{
cout << "<br>\n" ;
}
else if (c=='\t')
{
cout << "<font color=\"red\">&nbsp;&nbsp;&nbsp;</font>" ;
}
else if (c=='<')
{
cout << "<strong><font color=\"red\">&lt;</font></strong>" ;
}
else if (c=='/')
{
//////////////////////////////////////////////////////////////////////////////////Notes
scanf("%c",&c);
if (c=='/')
{
cout << "<i><font color=\"#0099FF\">";
cout << "//";
while ()
{
scanf("%c",&c);
if (c=='\n') break;
else if (c=='<') cout << "&lt;";
else if (c==' ') cout << "&nbsp;";
else if (c=='\t') cout << "&nbsp;&nbsp;&nbsp;&nbsp;";
else cout<<c;
}
cout << "</font></i><br>\n" ;
}
else if (c=='*')
{
cout << "<i><font color=\"#0099FF\">";
cout << "/*";
while ()
{
scanf("%c",&c);
if (c=='*')
{
cout << c;
scanf("%c",&c);
if (c=='/')
{
cout << c;
break;
}
}
else if (c=='<') cout << "&lt;";
else if (c=='\n') cout << "<br>";
else if (c==' ') cout << "&nbsp;";
else if (c=='\t') cout << "&nbsp;&nbsp;&nbsp;&nbsp;";
else cout<<c;
}
cout << "</font></i><br>\n" ;
}
}
else if (c==' ')
{
cout << "<font color=\"red\">&nbsp;</font>" ;
}
//////////////////////////////////////////////////////////////////////////////////Symbols
if (c!='/'&&c!=' '&&c!='\''&&c!='\"'&&c!='#'&&c!='<'&&c!='\n')
cout << "<strong><font color=\"red\">"<<c<<"</font></strong>";
gl=;
}
}
cout << "</div>";
fclose(stdout);
system("out.htm");
return ;
}

最新文章

  1. 11大Java开源中文分词器的使用方法和分词效果对比
  2. Backbone.js学习之Backbone.View(视图)
  3. OD使用教程4
  4. IE6/IE7/IE8/Firefox/Chrome/Safari的CSS hack兼容一览表
  5. ASP页面-自动取回数据库中的值生成导航。
  6. 【转】GATK使用方法详解(包含bwa使用)
  7. Apple WatchKit 初探
  8. JS对Array进行自定制排序
  9. Web程序的桌面提醒
  10. html加强
  11. Working with Data &#187; Getting started with ASP.NET Core and Entity Framework Core using Visual Studio &#187; 创建复杂数据模型
  12. 删除sqlserver2008日记文件
  13. 18.python的异常处理
  14. jquery 书写全选反选功能
  15. http 与https 安全链接
  16. (转)resize扩展
  17. Alpha冲刺总结
  18. Sun SPARC Enterprise M5000 启动步骤
  19. C#面向对象之多态。
  20. [TJOI2015]线性代数(最小割)

热门文章

  1. Java基础语法-运算符
  2. Java数据结构之递归(Recursion)
  3. django项目学习之QQ登录
  4. python内存管理(通俗易懂,详细可靠)
  5. 字符串hash 模板
  6. jquery做一个小的轮播插件---有BUG,后续修改
  7. git LF will be replaced by CRLF in hellogit.txt
  8. 关于websocket 在生产环境中遇到的问题 及 解决办法
  9. 简单的物流项目实战,WPF的MVVM设计模式(四)
  10. 2018-8-10-VisualStudio-修改配色