| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6448 人关注过本帖, 2 人收藏
标题:[开源] ★-----C语法高亮程序-------★
只看楼主 加入收藏
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
结帖率:100%
收藏(2)
 问题点数:0 回复次数:37 
[开源] ★-----C语法高亮程序-------★
见论坛里雨中飞燕和RockCarry都做了语法高亮程序,偶一时手痒也做了一个。

用了5天时间完成,一天时间查阅ANSI C资料,做总体设计,一天时间编码,三天时间测试,除虫,写文档。
今天解决了处理预编译指令时的一个BUG,没有再发现错误,移植到windows下编译出win32版。

软件以GPL协议发布,任何人有权向发布者索取源代码。
任何人有权做出修改并重新发布自己的版本,但也必须以GPL协议发布。
你可以从这里下载移植后的windows/dos版源码,以及原始的Unix版源码。
还可以向[email]vx.fish@[/email]发送邮件,报告bug或索取源码。

这是Unix版源码,提供最丰富完整的文档资料:
fish-src-beta-0.1.tar.gz (5.39 KB) Unix版源码


这是移植后的windows版源码:
fish-src-beta-0.1.rar (20.62 KB) windows/dos版源码


考虑到windows下编译不方便,这里提供编译后的win32版可执行程序:
fish_win32.rar (15.4 KB) win32版可执行程序

                      (17:28分修改配置文件bccn.conf后重新上传)

Unix类系统用户在下载源码后可以编译安装:
# make
# make install
详情请阅读附带的INSTALL文件,安装后可以使用命令man fish获取联机帮助

windows用户请使用fish -h获取帮助,也可以阅读楼下的使用示例。

《========================================================================》
                                       NEWS
2008.05.28  晚上19:30
       更新了所有版本中bccn.conf的小错误。之前在颜色设置中误删字符a,使得预处理不能着色,
全部重新修改后上传,真是一失手成千古恨。

《========================================================================》

[[it] 本帖最后由 VxWorks 于 2008-5-28 19:33 编辑 [/it]]
搜索更多相关主题的帖子: 高亮 语法 windows 源代码 BUG 
2008-05-28 16:56
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
windows下使用实例:
切换到fish.exe所在文件夹下在命令行下运行fish.exe
fish  -i bc.c  -c bccn.conf  -o bc.txt
bc.c是下面显示的c程序,用来做测试用的,使用选项-i指定要高亮的源程序输入
bccn.conf是为bccn.net论坛写的配置文件,你可以用记事本打开修改配色方案。
-o指定输出文件,这里输出文件是bc.txt

可以使用下面的命令获取帮助:
fish   -h
将输出的bc.txt直接贴上论坛就可以了。

生成的bc.txt内容是:
程序代码:
#include<assert.h>
#include<stdlib.h>
int get_tag(char *buf, int index,char opt)
{
        char *dest;
        const char *SectionName=sections[index];

        assert(opt=='s' || opt=='e');
        if(opt == 's')
                dest=tag_list[index].start;
        else 
                dest=tag_list[index].end;

        while(*buf != '!' && *buf != '\0')
                ++buf;

        if(*buf == '\0')
        {
                if(opt == 's')
                        fprintf(stderr,"配置文件错误:%s\nstart = \n",SectionName);
                else
                        fprintf(stderr,"配置文件错误:%s\nend = \n",SectionName);
                exit(1);
        }

        strncpy(dest,++buf,40);

        return 0;
}
将输出的bc.txt直接贴出来即可:


#include<assert.h>
#include<stdlib.h>
int get_tag(char *buf, int index,char opt)
{
        char *dest;
        const char *SectionName=sections[index];

        assert(opt=='s' || opt=='e');
        if(opt == 's')
                dest=tag_list[index].start;
        else
                dest=tag_list[index].end;

        while(*buf != '!' && *buf != '\0')
                ++buf;

        if(*buf == '\0')
        {
                if(opt == 's')
                        fprintf(stderr,"配置文件错误:%s\nstart = \n",SectionName);
                else
                        fprintf(stderr,"配置文件错误:%s\nend = \n",SectionName);
                exit(1);
        }

        strncpy(dest,++buf,40);

        return 0;
}

当然也可以向下面这样在bc.txt文件首尾加入添加边框。
添加后的内容是:
程序代码:
#include<assert.h> #include<stdlib.h> int get_tag(char *buf, int index,char opt) { char *dest; const char *SectionName=sections[index]; assert(opt=='s' || opt=='e'); if(opt == 's') dest=tag_list[index].start; else dest=tag_list[index].end; while(*buf != '!' && *buf != '\0') ++buf; if(*buf == '\0') { if(opt == 's') fprintf(stderr,"配置文件错误:%s\nstart = \n",SectionName); else fprintf(stderr,"配置文件错误:%s\nend = \n",SectionName); exit(1); } strncpy(dest,++buf,40); return 0; }
添加边框后的效果如下:

#include<assert.h>
#include<stdlib.h>
int get_tag(char *buf, int index,char opt)
{
        char *dest;
        const char *SectionName=sections[index];

        assert(opt=='s' || opt=='e');
        if(opt == 's')
                dest=tag_list[index].start;
        else
                dest=tag_list[index].end;

        while(*buf != '!' && *buf != '\0')
                ++buf;

        if(*buf == '\0')
        {
                if(opt == 's')
                        fprintf(stderr,"配置文件错误:%s\nstart = \n",SectionName);
                else
                        fprintf(stderr,"配置文件错误:%s\nend = \n",SectionName);
                exit(1);
        }

        strncpy(dest,++buf,40);

        return 0;
}


[[it] 本帖最后由 VxWorks 于 2008-5-28 18:13 编辑 [/it]]

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-05-28 17:05
Loli
Rank: 1
来 自:飞燕算法群46520219
等 级:新手上路
帖 子:348
专家分:0
注 册:2008-5-27
收藏
得分:0 
占个位置先。。。。。

[color=white]
2008-05-28 17:10
Loli
Rank: 1
来 自:飞燕算法群46520219
等 级:新手上路
帖 子:348
专家分:0
注 册:2008-5-27
收藏
得分:0 
非Win32图形界面啊。。。只好做插件了

/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) [url]http://[/url] **
*****************************************************************/
#include<assert.h>
#include<stdlib.h>
int get_tag(char *buf, int index,char opt)
{
   
char *dest;
    const char *SectionName=sections[index];
    int i=0;

    assert(opt=='s' || opt=='e');
    if (opt == 's')
        dest=tag_list[index].start;
    else
        
dest=tag_list[index].end;

    while (buf[i] != '!' && buf[i] != '\0')
        ++buf;

    if (buf[i] == '\0')
    {
        
if (opt == 's')
            fprintf(stderr,"配置文件错误:%s\nstart = \n",SectionName);
        else
            
fprintf(stderr,"配置文件错误:%s\nend = \n",SectionName);
        exit(1);
    }
   
strncpy(dest,++buf,40);
    return 0;
}


这个呢?
2008-05-28 17:19
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
sigh,3楼贴出来的着色又有问题,还是预处理。
不过还好,这次问题不在程序,是配置文件错了,修改方法:
用文本编辑器打开bccn.conf找到[preprocess]段,
将start =[color=020f0]修改为start =[color=a020f0]
附带的另一个html.conf没有问题,可以生成完整的html网页。

楼上的,我的着色是模仿大多数编辑器的方案,只对关键字,常量,注释,预处理指令进行处理。

[[it] 本帖最后由 VxWorks 于 2008-5-28 17:25 编辑 [/it]]

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-05-28 17:21
切忌浮躁
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-5-28
收藏
得分:0 
试下
#include <stdio.h>
#define  max(a,b) \
(a)>(b)?(a):(b);


int test1()
{
        int a=1;
        int b=0x2efd;

        double f1=0.2548;
        double f2=0.2e3;
        double f3=5.4E5;

        char *string="hello\n";         /*hello world*/        
        printf("hello wold");        //hello   你好  
        return 0;
}


int test2()
{
        
        char *string="hello\n\";     /*hello world*/
    
    printf(\"hello wold"
);        //hello world

        return 0;
}
2008-05-28 17:22
切忌浮躁
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-5-28
收藏
得分:0 
这个是怎么的
将start =修改为start =
这个是怎么改?
2008-05-28 17:27
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
看6楼
或者重新下载,我已经更新了fish_win32.rar文件

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-05-28 17:33
Loli
Rank: 1
来 自:飞燕算法群46520219
等 级:新手上路
帖 子:348
专家分:0
注 册:2008-5-27
收藏
得分:0 
请问一下楼主,有考虑过什么标签合并的问题么?

[color=white]
2008-05-28 17:37
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
大家可以使用下面的命令:
[VxWorks @ WinXP] D:\home\fish_win32#fish -i bc.c 
只指定输入,默认使用html.conf配置文件输出一个web网页,然后就可以将着色后的代码贴到自己博客或个人空间。
你也可以建立自己的配置文件,通过-c指示程序读取。

关于命令行选项的用法使用命令fish -h获取帮助。
Unix类用户man fish可以获取更详细的资料。

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-05-28 17:39
快速回复:[开源] ★-----C语法高亮程序-------★
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035680 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved