-
test
please work.. apLEWORAasdasdf
'
damn wrinkly unplanned asdfwasd
Code:
/* main.c - main file for csyntax. this program highlights c/c++ sourcecode with vB codes */
#include <stdio.h>
#include <ctype.h>
#define COMMENT "<COLOR=RED>"
#define PP "<COLOR=GREEN>"
#define STRING "<COLOR=BLUE>"
#define uint unsigned int
#define uchar unsigned char
/* main program: let the garbled bag of hell mess begin */
int main()
{
uchar c,t; uint in_quote, in_squote, in_pp, ccomment, cppcomment, in_boardtag;
/* init the vars */
in_quote = 0;
in_squote = 0;
in_pp = 0;
in_boardtag = 0;
ccomment = 0;
cppcomment = 0;
printf("<CODE>");
/* start main input loop */
while(!feof(stdin))
{
c = fgetc(stdin);
/* prevent EOF char from appearing */
if(c == EOF)
break;
/* prepare to highlight */
switch (c)
{
/* work *sob* WORK!! please... ignore escape/control codes, whatever they are*/
case '\\':
t = fgetc(stdin);
fputc(c, stdout);
fputc(t, stdout);
break;
/* make the board shut up */
case '<':
t = fgetc(stdin);
if(!isdigit(t))
{
fputc('<', stdout);
in_boardtag = 1;
} else fputc(c, stdout);
ungetc(t, stdin);
break;
/* make the replacement on both ends */
case '>':
if(in_boardtag == 1)
c = '>';
fputc(c, stdout);
break;
/* check for the end of c-style comments */
case '*':
t = fgetc(stdin);
if(in_quote != 1)
{
if(t == '/' && ccomment == 1)
{
fputc(c, stdout);
fputc(t, stdout);
printf("</COLOR>");
ccomment = 0;
} else {
fputc(c, stdout);
ungetc(t, stdin);
};
};
break;
/* check for the start of c++ and c style comments */
case '/':
t = fgetc(stdin);
if(in_quote != 1)
{
if(ccomment != 1)
{
if(t == '/')
{
printf(COMMENT);
cppcomment = 1;
} else
if(t == '*')
{
printf(COMMENT);
ccomment = 1;
};
};
};
fputc(c, stdout);
ungetc(t, stdin);
break;
/* check for preprocessing directives */
case '#':
if(in_quote != 1 && in_squote != 1 && ccomment != 1 && cppcomment != 1)
{
printf(PP);
in_pp = 1;
};
fputc(c, stdout);
break;
/* check for string constants */
case '\"':
if(in_pp != 1 && ccomment != 1 && cppcomment != 1 && in_squote != 1)
{
if(in_quote == 0)
{
printf(STRING);
fputc(c, stdout);
in_quote = 1;
} else {
fputc(c, stdout);
printf("</COLOR>");
in_quote = 0;
};
} else fputc(c, stdout);
break;
/* check for small string constants */
case '\'':
if(in_pp != 1 && ccomment != 1 && cppcomment != 1 && in_quote != 1)
{
if(in_squote != 1)
{
printf(STRING);
fputc(c, stdout);
in_squote = 1;
} else {
fputc(c, stdout);
printf("</COLOR>");
in_squote = 0;
};
}; break;
/* pop any colors that should end at a newline */
case '\n':
if(cppcomment == 1)
{
printf("</COLOR>");
cppcomment = 0;
};
if(in_pp == 1)
{
printf("</COLOR>");
in_pp = 0;
};
fputc(c, stdout);
break;
default:
fputc(c, stdout);
};
};
printf("</CODE>");
return 0;
};
Ahah! It sort of works!
-
somehow
that was not worth the trouble. have to make a new one, nicer and planned... with keyword highlighting.
-
www.sunlightd.com offers a nice source highlighter, though you'll have to change it a bit.
BTW, do you really use red comments?!
-
Code:
I wonder if the colors will compile. Cool, this must be VS.NET and C# source code.